Skip to content

Commit

Permalink
update basic chat types
Browse files Browse the repository at this point in the history
  • Loading branch information
jdvelasq committed Dec 11, 2024
1 parent 34d34d4 commit 081f1b2
Show file tree
Hide file tree
Showing 14 changed files with 404 additions and 432 deletions.
14 changes: 14 additions & 0 deletions sphinx/_generated/visualize/basic_charts/line_chart.html

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions sphinx/_generated/visualize/basic_charts/pie_chart.html

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions sphinx/_generated/visualize/basic_charts/ranking_chart.html

Large diffs are not rendered by default.

Binary file removed sphinx/images/report/word_cloud.png
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 4 additions & 4 deletions sphinx/visualize/basic_charts/__index__.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ Basic Charts
.. toctree::
:hidden:

column_chart
bar_chart
pie_chart
cleveland_dot_chart
column_chart
line_chart
pie_chart
ranking_chart
word_cloud
world_map
cleveland_dot_chart
ranking_chart



Expand Down
2 changes: 1 addition & 1 deletion sphinx/visualize/basic_charts/line_chart.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
.. automodule:: techminer2.report.line_chart
.. automodule:: techminer2.visualize.basic_charts.line_chart
:members:

2 changes: 1 addition & 1 deletion sphinx/visualize/basic_charts/pie_chart.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
.. automodule:: techminer2.report.pie_chart
.. automodule:: techminer2.visualize.basic_charts.pie_chart
:members:

2 changes: 1 addition & 1 deletion sphinx/visualize/basic_charts/ranking_chart.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
.. automodule:: techminer2.report.ranking_chart
.. automodule:: techminer2.visualize.basic_charts.ranking_chart
:members:

2 changes: 1 addition & 1 deletion sphinx/visualize/basic_charts/word_cloud.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
.. automodule:: techminer2.report.word_cloud
.. automodule:: techminer2.visualize.basic_charts.word_cloud
:members:

208 changes: 97 additions & 111 deletions techminer2/visualize/basic_charts/line_chart.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,38 +9,38 @@
Line Chart
===============================================================================
>>> from techminer2.report import line_chart
>>> plot = line_chart(
... #
... # ITEMS PARAMS:
... field='author_keywords',
... top_n=20,
... occ_range=(None, None),
... gc_range=(None, None),
... custom_terms=None,
... #
... metric="OCC",
... #
... # CHART PARAMS:
... title="Most Frequent Author Keywords",
... metric_label=None,
... field_label=None,
... #
... # DATABASE PARAMS:
... root_dir="example/",
... database="main",
... year_filter=(None, None),
... cited_by_filter=(None, None),
>>> from techminer2.visualize.basic_charts.line_chart import LineChart
>>> plot = (
... LineChart()
... .set_item_params(
... field="author_keywords",
... top_n=20,
... occ_range=(None, None),
... gc_range=(None, None),
... custom_terms=None,
... ).set_chart_params(
... title_text="Most Frequent Author Keywords",
... metric_label=None,
... field_label=None,
... ).set_database_params(
... root_dir="example/",
... database="main",
... year_filter=(None, None),
... cited_by_filter=(None, None),
... ).build(metric="OCC")
... )
>>> # plot.write_html("sphinx/_generated/visualize/basic_charts/line_chart.html")
.. raw:: html
<iframe src="../_static/report/line_chart.html"
<iframe src="../../_generated/visualize/basic_charts/line_chart.html"
height="600px" width="100%" frameBorder="0"></iframe>
"""
from dataclasses import dataclass
from typing import Optional

import plotly.express as px # type: ignore

from ...internals.params.database_params import DatabaseParams, DatabaseParamsMixin
Expand All @@ -50,102 +50,88 @@
MARKER_COLOR = "#7793a5"
MARKER_LINE_COLOR = "#465c6b"


@dataclass
class ChartParams:
""":meta private:"""

title_text: Optional[str] = None
metric_label: Optional[str] = None
field_label: Optional[str] = None


class LineChart(
ItemParamsMixin,
DatabaseParamsMixin,
):
"""Line chart."""
""":meta private:"""

def __init__(self):
self.chart_params = ChartParams()
self.database_params = DatabaseParams()
self.item_params = ItemParams()

def build(self, metric: str = "OCC"):


def set_chart_params(self, **kwars):
for key, value in kwars.items():
if hasattr(self.chart_params, key):
setattr(self.chart_params, key, value)
else:
raise ValueError(f"Invalid parameter for ChartParams: {key}")
return self

def line_chart(
#
# ITEMS PARAMS:
field,
top_n=None,
occ_range=(None, None),
gc_range=(None, None),
custom_terms=None,
#
metric="OCC",
#
# CHART PARAMS:
title=None,
field_label=None,
metric_label=None,
#
# DATABASE PARAMS:
root_dir="./",
database="main",
year_filter=(None, None),
cited_by_filter=(None, None),
**filters,
):
""":meta private:"""
def build(self, metric: str = "OCC"):

items = performance_metrics_frame(
#
# ITEMS PARAMS:
field=field,
top_n=top_n,
occ_range=occ_range,
gc_range=gc_range,
custom_terms=custom_terms,
#
metric=metric,
#
# DATABASE PARAMS:
root_dir=root_dir,
database=database,
year_filter=year_filter,
cited_by_filter=cited_by_filter,
**filters,
)

metric_label = metric.replace("_", " ").upper() if metric_label is None else metric_label

field_label = field.replace("_", " ").upper() if field_label is None else field_label

data_frame = items.copy()

fig = px.line(
data_frame,
x=None,
y=metric,
hover_data=data_frame.columns.to_list(),
markers=True,
)

fig.update_layout(
paper_bgcolor="white",
plot_bgcolor="white",
title_text=title,
)
fig.update_traces(
marker=dict(size=9, line={"color": "#465c6b", "width": 2}),
marker_color=MARKER_COLOR,
line={"color": MARKER_LINE_COLOR},
)
fig.update_xaxes(
linecolor="gray",
linewidth=2,
gridcolor="lightgray",
griddash="dot",
tickangle=270,
title_text=field_label,
)
fig.update_yaxes(
linecolor="gray",
linewidth=2,
gridcolor="lightgray",
griddash="dot",
title_text=metric_label,
)

return fig
metric_label = self.chart_params.metric_label
field_label = self.chart_params.field_label
title_text = self.chart_params.title_text

data_frame = performance_metrics_frame(
metric=metric,
**self.item_params.__dict__,
**self.database_params.__dict__,
)

if metric_label is None:
metric_label = metric.replace("_", " ").upper()

if field_label is None:
field_label = self.item_params.field.replace("_", " ").upper()

if title_text is None:
title_text = ""

fig = px.line(
data_frame,
x=None,
y=metric,
hover_data=data_frame.columns.to_list(),
markers=True,
)

fig.update_layout(
paper_bgcolor="white",
plot_bgcolor="white",
title_text=title_text,
)
fig.update_traces(
marker=dict(size=9, line={"color": "#465c6b", "width": 2}),
marker_color=MARKER_COLOR,
line={"color": MARKER_LINE_COLOR},
)
fig.update_xaxes(
linecolor="gray",
linewidth=2,
gridcolor="lightgray",
griddash="dot",
tickangle=270,
title_text=field_label,
)
fig.update_yaxes(
linecolor="gray",
linewidth=2,
gridcolor="lightgray",
griddash="dot",
title_text=metric_label,
)

return fig
Loading

0 comments on commit 081f1b2

Please sign in to comment.