Skip to content

Commit

Permalink
Polish Fine Performance Metrics plot (#7963)
Browse files Browse the repository at this point in the history
  • Loading branch information
crusaderky authored Jul 5, 2023
1 parent c6f451a commit fca4b35
Showing 1 changed file with 36 additions and 9 deletions.
45 changes: 36 additions & 9 deletions distributed/dashboard/components/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -3392,6 +3392,7 @@ class FinePerformanceMetrics(DashboardComponent):
substantial_change: bool
visible_functions: list[str]
visible_activities: list[str]
stacked_chart_visible_activities: list[str]
function_selector: MultiChoice
span_tag_selector: MultiChoice
unit_selector: Select
Expand All @@ -3409,6 +3410,7 @@ def __init__(self, scheduler: Scheduler, **kwargs: Any):
self.substantial_change = False
self.visible_functions = []
self.visible_activities = []
self.stacked_chart_visible_activities = []
self.task_exec_by_activity_chart = None
self.task_exec_by_prefix_chart = None
self.get_data_by_activity_chart = None
Expand Down Expand Up @@ -3651,7 +3653,6 @@ def _build_data_sources(self) -> None:
self.visible_functions = sorted(visible_functions)

if visible_activities != set(self.visible_activities):
self.substantial_change = True
self.visible_activities = sorted(visible_activities)

(
Expand All @@ -3668,18 +3669,29 @@ def _build_pie_data(self, data: defaultdict[str, float]) -> dict[str, list]:
--------
_build_pie_chart
"""
total_value = sum(data.values())
percent_k = 100.0 / total_value if total_value else 0.0
angle_k = 2.0 * math.pi / total_value if total_value else 0.0
activities = self.visible_activities
# Generate palette based on all visible activities to make sure that
# colors match between the plots
palette = self._get_palette()
values = [data[activity] for activity in activities]
total_text = self._format(sum(values))

# Sort by values from largest to smallest
# Hide activities that are missing in the current plot from the legend
idx = [i for i, v in sorted(enumerate(values), key=lambda el: -el[1]) if v]
activities = [activities[i] for i in idx]
palette = [palette[i] for i in idx]
values = [values[i] for i in idx]

total_value = sum(values)
total_text = self._format(total_value)
percent_k = 100.0 / total_value if total_value else 0.0
angle_k = 2.0 * math.pi / total_value if total_value else 0.0
return {
"activity": activities,
"value": values,
"text": [self._format(v) + f" ({v * percent_k:.0f}%)" for v in values],
"angle": [v * angle_k for v in values],
"color": self._get_palette(),
"color": palette,
"total_text": [total_text] * len(values),
}

Expand Down Expand Up @@ -3735,13 +3747,21 @@ def _build_task_execution_by_prefix_data(
"____total_text": [self._format(v) for v in func_totals],
}

sc_visible_activities = []
for activity in self.visible_activities:
values = [data[function, activity] for function in self.visible_functions]
if not any(values):
continue
sc_visible_activities.append(activity)
out[activity] = values
out[f"__{activity}_text"] = [
self._format(v) + f" ({v * perc_ki:.0f}%)"
for v, perc_ki in zip(values, perc_k)
]
if sc_visible_activities != self.stacked_chart_visible_activities:
self.substantial_change = True
self.stacked_chart_visible_activities[:] = sc_visible_activities

return out, max(func_totals, default=0.0)

def _build_task_execution_by_prefix_chart(self) -> figure:
Expand Down Expand Up @@ -3779,13 +3799,20 @@ def _update_task_execution_by_prefix_chart(self) -> None:
barchart = self.task_exec_by_prefix_chart
assert barchart is not None
barchart.x_range = FactorRange(*self.visible_functions)

palette = [
p
for p, a in zip(self._get_palette(), self.visible_activities)
if a in self.stacked_chart_visible_activities
]
assert len(palette) == len(self.stacked_chart_visible_activities)
renderers = barchart.vbar_stack(
self.visible_activities,
self.stacked_chart_visible_activities,
x="__functions",
width=0.9,
source=self.task_exec_by_prefix_src,
color=self._get_palette(),
legend_label=self.visible_activities,
color=palette,
legend_label=self.stacked_chart_visible_activities,
)

# Create or refresh hovertools on top of base tools
Expand Down

0 comments on commit fca4b35

Please sign in to comment.