mirror of
https://github.com/apache/superset.git
synced 2026-05-12 19:35:17 +00:00
fix(echarts): prevent plain legend clipping in dashboards (#38675)
This commit is contained in:
committed by
GitHub
parent
3fb903fdc6
commit
12aca72074
@@ -55,6 +55,7 @@ import {
|
||||
import {
|
||||
EchartsTimeseriesSeriesType,
|
||||
ForecastSeriesEnum,
|
||||
LegendOrientation,
|
||||
Refs,
|
||||
} from '../types';
|
||||
import { parseAxisBound } from '../utils/controls';
|
||||
@@ -67,10 +68,12 @@ import {
|
||||
extractTooltipKeys,
|
||||
getAxisType,
|
||||
getColtypesMapping,
|
||||
getHorizontalLegendAvailableWidth,
|
||||
getLegendProps,
|
||||
getMinAndMaxFromBounds,
|
||||
getOverMaxHiddenFormatter,
|
||||
} from '../utils/series';
|
||||
import { resolveLegendLayout } from '../utils/legendLayout';
|
||||
import {
|
||||
extractAnnotationLabels,
|
||||
getAnnotationData,
|
||||
@@ -583,13 +586,57 @@ export default function transformProps(
|
||||
convertInteger(yAxisTitleMargin) !== 0;
|
||||
const addXAxisTitleOffset =
|
||||
!!xAxisTitle && convertInteger(xAxisTitleMargin) !== 0;
|
||||
const baseChartPadding = getPadding(
|
||||
showLegend,
|
||||
legendOrientation,
|
||||
addYAxisTitleOffset,
|
||||
zoomable,
|
||||
legendMargin,
|
||||
addXAxisTitleOffset,
|
||||
yAxisTitlePosition,
|
||||
convertInteger(yAxisTitleMargin),
|
||||
convertInteger(xAxisTitleMargin),
|
||||
);
|
||||
const legendData = series
|
||||
.filter(
|
||||
entry =>
|
||||
extractForecastSeriesContext((entry.name || '') as string).type ===
|
||||
ForecastSeriesEnum.Observation,
|
||||
)
|
||||
.map(entry => entry.name)
|
||||
.filter((name): name is string => Boolean(name))
|
||||
.concat(extractAnnotationLabels(annotationLayers))
|
||||
.sort((a: string, b: string) => {
|
||||
if (!legendSort) return 0;
|
||||
return legendSort === 'asc' ? a.localeCompare(b) : b.localeCompare(a);
|
||||
});
|
||||
const { effectiveLegendMargin, effectiveLegendType } = resolveLegendLayout({
|
||||
availableWidth:
|
||||
legendOrientation === LegendOrientation.Top ||
|
||||
legendOrientation === LegendOrientation.Bottom
|
||||
? getHorizontalLegendAvailableWidth({
|
||||
chartWidth: width,
|
||||
orientation: legendOrientation,
|
||||
padding: baseChartPadding,
|
||||
zoomable,
|
||||
})
|
||||
: undefined,
|
||||
chartHeight: height,
|
||||
chartWidth: width,
|
||||
legendItems: legendData,
|
||||
legendMargin,
|
||||
orientation: legendOrientation,
|
||||
show: showLegend,
|
||||
theme,
|
||||
type: legendType,
|
||||
});
|
||||
|
||||
const chartPadding = getPadding(
|
||||
showLegend,
|
||||
legendOrientation,
|
||||
addYAxisTitleOffset,
|
||||
zoomable,
|
||||
legendMargin,
|
||||
effectiveLegendMargin,
|
||||
addXAxisTitleOffset,
|
||||
yAxisTitlePosition,
|
||||
convertInteger(yAxisTitleMargin),
|
||||
@@ -753,7 +800,7 @@ export default function transformProps(
|
||||
},
|
||||
legend: {
|
||||
...getLegendProps(
|
||||
legendType,
|
||||
effectiveLegendType,
|
||||
legendOrientation,
|
||||
showLegend,
|
||||
theme,
|
||||
@@ -761,18 +808,7 @@ export default function transformProps(
|
||||
legendState,
|
||||
chartPadding,
|
||||
),
|
||||
data: series
|
||||
.filter(
|
||||
entry =>
|
||||
extractForecastSeriesContext((entry.name || '') as string).type ===
|
||||
ForecastSeriesEnum.Observation,
|
||||
)
|
||||
.map(entry => entry.id || entry.name || '')
|
||||
.concat(extractAnnotationLabels(annotationLayers))
|
||||
.sort((a: string, b: string) => {
|
||||
if (!legendSort) return 0;
|
||||
return legendSort === 'asc' ? a.localeCompare(b) : b.localeCompare(a);
|
||||
}),
|
||||
data: legendData,
|
||||
},
|
||||
series: dedupSeries(reorderForecastSeries(series) as SeriesOption[]),
|
||||
toolbox: {
|
||||
|
||||
Reference in New Issue
Block a user