This is an automated email from the ASF dual-hosted git repository. elizabeth pushed a commit to branch elizabeth/fix-legend-overflow in repository https://gitbox.apache.org/repos/asf/superset.git
commit b3b0cc2f02bcfa59d19fcab7b9607651b7e833fb Author: Elizabeth Thompson <[email protected]> AuthorDate: Wed Jan 29 16:13:03 2025 -0800 adjust legend width by padding --- .../packages/superset-ui-chart-controls/src/types.ts | 7 +++++++ .../plugin-chart-echarts/src/Timeseries/transformProps.ts | 1 + .../plugins/plugin-chart-echarts/src/utils/series.ts | 9 +++++++-- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/superset-frontend/packages/superset-ui-chart-controls/src/types.ts b/superset-frontend/packages/superset-ui-chart-controls/src/types.ts index e9606c6ba4..07eb17f31e 100644 --- a/superset-frontend/packages/superset-ui-chart-controls/src/types.ts +++ b/superset-frontend/packages/superset-ui-chart-controls/src/types.ts @@ -508,6 +508,13 @@ export enum SortSeriesType { Avg = 'avg', } +export type LegendPaddingType = { + top?: number; + bottom?: number; + left?: number; + right?: number; +}; + export type SortSeriesData = { sort_series_type: SortSeriesType; sort_series_ascending: boolean; diff --git a/superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/transformProps.ts b/superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/transformProps.ts index 10f57fb8d8..e2e8f64bc3 100644 --- a/superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/transformProps.ts +++ b/superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/transformProps.ts @@ -621,6 +621,7 @@ export default function transformProps( theme, zoomable, legendState, + padding, ), data: legendData as string[], }, diff --git a/superset-frontend/plugins/plugin-chart-echarts/src/utils/series.ts b/superset-frontend/plugins/plugin-chart-echarts/src/utils/series.ts index 0aa0ae988e..edec65dc99 100644 --- a/superset-frontend/plugins/plugin-chart-echarts/src/utils/series.ts +++ b/superset-frontend/plugins/plugin-chart-echarts/src/utils/series.ts @@ -33,7 +33,7 @@ import { TimeFormatter, ValueFormatter, } from '@superset-ui/core'; -import { SortSeriesType } from '@superset-ui/chart-controls'; +import { SortSeriesType, LegendPaddingType } from '@superset-ui/chart-controls'; import { format } from 'echarts/core'; import type { LegendComponentOption } from 'echarts/components'; import type { SeriesOption } from 'echarts'; @@ -425,6 +425,7 @@ export function getLegendProps( theme: SupersetTheme, zoomable = false, legendState?: LegendState, + padding?: LegendPaddingType, ): LegendComponentOption | LegendComponentOption[] { const legend: LegendComponentOption | LegendComponentOption[] = { orient: [LegendOrientation.Top, LegendOrientation.Bottom].includes( @@ -446,6 +447,10 @@ export function getLegendProps( switch (orientation) { case LegendOrientation.Left: legend.left = 0; + legend.textStyle = { + overflow: 'truncate', + width: Math.max((padding?.left || 205) - 45, 10), + }; break; case LegendOrientation.Right: legend.right = 0; @@ -467,7 +472,7 @@ export function getChartPadding( show: boolean, orientation: LegendOrientation, margin?: string | number | null, - padding?: { top?: number; bottom?: number; left?: number; right?: number }, + padding?: LegendPaddingType, isHorizontal?: boolean, ): { bottom: number;
