Skip to content

Commit

Permalink
feat: unify the color list for line plot of all properties in reporte…
Browse files Browse the repository at this point in the history
…r to default plotly color cycle
  • Loading branch information
ZLI-afk committed Jan 8, 2024
1 parent f846e24 commit 54ca345
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
25 changes: 24 additions & 1 deletion apex/reporter/DashReportApp.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,25 @@ def __init__(self, datasets):
[Input('confs-radio', 'value')]
)(self.update_dropdown_options)

@staticmethod
def plotly_color_cycle():
# https://plotly.com/python/discrete-color/
colors = [
'#636EFA', # blue
'#EF553B', # red
'#00CC96', # green
'#AB63FA', # purple
'#FFA15A', # orange
'#19D3F3', # cyan
'#FF6692', # pink
'#B6E880', # lime
'#FF97FF', # magenta
'#FECB52', # yellow
]
while True:
for color in colors:
yield color

def generate_layout(self):
for w in self.datasets.values():
self.all_dimensions.update(w.keys())
Expand Down Expand Up @@ -170,6 +189,7 @@ def update_dropdown_options(self, selected_confs):
def update_graph(self, selected_prop, selected_confs):
fig = go.Figure()
prop_type = return_prop_type(selected_prop)
color_generator = self.plotly_color_cycle()
if prop_type not in NO_GRAPH_LIST:
for w_dimension, dataset in self.datasets.items():
try:
Expand All @@ -180,7 +200,10 @@ def update_graph(self, selected_prop, selected_confs):
propCls = return_prop_class(prop_type)
# trace_name = f"{w_dimension} - {selected_confs} - {selected_prop}"
trace_name = w_dimension
traces, layout = propCls.plotly_graph(data, trace_name)
traces, layout = propCls.plotly_graph(
data, trace_name,
color=next(color_generator)
)
fig.add_traces(traces)
fig.layout = layout
fig.update_layout(autotypenumbers='convert types')
Expand Down
6 changes: 3 additions & 3 deletions apex/reporter/property_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,8 @@ def plotly_graph(res_data: dict, name: str, **kwargs) -> [list[go], go.layout]:
pd_dict['Band %02d' % (ii + 1)] = band_list[ii]
df = pd.DataFrame(pd_dict)
traces = []
color = random_color()


for ii in range(len(band_list)):
trace = go.Scatter(
x=df['Band Path'],
Expand All @@ -502,7 +503,7 @@ def plotly_graph(res_data: dict, name: str, **kwargs) -> [list[go], go.layout]:
legendgroup=name,
legendgrouptitle_text=name,
mode='lines+markers',
line=dict(color=color)
line=dict(color=kwargs["color"])
)
traces.append(trace)

Expand All @@ -517,7 +518,6 @@ def plotly_graph(res_data: dict, name: str, **kwargs) -> [list[go], go.layout]:
for point in seg:
k = list(point.keys())[0]
if connect_seg:
#pre_k = list(x_label_list[-1].keys())[0]
new_k = f'{pre_k}/{k}'
x_label_list[-1][0] = new_k
connect_seg = False
Expand Down

0 comments on commit 54ca345

Please sign in to comment.