Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified outputs/charts/org/hiero-ledger/difficulty_by_repo_30_days.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified outputs/charts/org/hiero-ledger/gfi_pipeline.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified outputs/charts/org/hiero-ledger/gfi_yearly_state_line.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified outputs/charts/org/hiero-ledger/maintainer_pipeline_by_repo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified outputs/charts/org/hiero-ledger/maintainer_pipeline_yearly.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified outputs/charts/org/hiero-ledger/total_gfi_gfic_by_repo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 17 additions & 7 deletions src/hiero_analytics/plotting/bars.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,8 +337,6 @@ def plot_stacked_bar(
_annotate_bar_totals(ax, patches, totals, horizontal=True)
ax.margins(y=HORIZONTAL_Y_MARGIN, x=HORIZONTAL_X_MARGIN)
ax.set_xlim(0, _compute_horizontal_axis_limit(max_total, padding))
legend_anchor = (0.5, -0.04)
bottom_rect = 0.05
else:
if annotate_totals and len(df) <= 12:
_annotate_bar_totals(ax, patches, totals, horizontal=False)
Expand All @@ -347,14 +345,26 @@ def plot_stacked_bar(
if is_numeric_or_datetime(df[x_col]) and (df[x_col] % 1 == 0).all():
ax.set_xticks(df[x_col])
ax.set_xticklabels([str(int(v)) for v in df[x_col]])
legend_anchor = (0.5, -0.14)
bottom_rect = 0.14

## Adaptive Legend placement
labels_count = len(labels)
legend_loc = "lower center"
legend_anchor = (0.5, -0.14)
layout_rect = (0, 0.14, 1.0, 1.0)
legend_ncol = min(labels_count, 4)

if labels_count > 6:
legend_loc = "upper left"
legend_anchor = (1.02, 1.0)
layout_rect = (0, 0, 0.85, 1.0)
legend_ncol = 1

# Backward-compatible override.
if legend_inside_bottom_right:
legend_loc = "lower right"
legend_anchor = (0.985, 0.02)
bottom_rect = 0.0
layout_rect = (0, 0, 1.0, 1.0)
legend_ncol = min(labels_count, 4)

finalize_chart(
fig=fig,
Expand All @@ -370,7 +380,7 @@ def plot_stacked_bar(
legend_labels=labels,
legend_loc=legend_loc,
legend_bbox_to_anchor=legend_anchor,
legend_ncol=min(len(labels), 4),
legend_ncol=legend_ncol,
legend_kwargs={"borderaxespad": 0.0},
layout_rect=(0, bottom_rect, 1, 1.0),
layout_rect=layout_rect,
)
25 changes: 19 additions & 6 deletions src/hiero_analytics/plotting/lines.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,20 @@ def plot_multiline(
ax.set_xlim(float(pivot.index.min()) - 0.15, float(pivot.index.max()) + 0.45)
ax.margins(x=0.03, y=0.16)

legend_count = len(pivot.columns)

## Prefer Bottom legend, Right legend only when many items
if legend_count > 6:
legend_loc = "upper left"
legend_bbox_to_anchor = (1.02, 1.0)
legend_ncol = 1
layout_rect = (0, 0, 0.85, 1.0)
else:
legend_loc = "lower center"
legend_bbox_to_anchor = (0.5, -0.18)
legend_ncol = min(legend_count, 4)
layout_rect = (0, 0.12, 1.0, 1.0)

finalize_chart(
fig=fig,
ax=ax,
Expand All @@ -190,10 +204,9 @@ def plot_multiline(
legend=True,
rotate_x=rotate_x,
grid_axis="y",
# Keep the legend in the header whitespace instead of on top of data.
legend_loc="upper right",
legend_bbox_to_anchor=(1, 1.14),
legend_ncol=min(len(pivot.columns), 3),
legend_loc=legend_loc,
legend_bbox_to_anchor=legend_bbox_to_anchor,
legend_ncol=legend_ncol,
legend_kwargs={"borderaxespad": 0.0},
layout_rect=(0, 0, 1, 0.92),
)
layout_rect=layout_rect,
)