mirror of
https://github.com/apache/superset.git
synced 2026-05-12 19:35:17 +00:00
feat: add sort legend to legend section (#34911)
This commit is contained in:
@@ -131,6 +131,7 @@ export default function transformProps(chartProps: EchartsGanttChartProps) {
|
||||
legendMargin,
|
||||
legendOrientation,
|
||||
legendType,
|
||||
legendSort,
|
||||
showLegend,
|
||||
yAxisTitle,
|
||||
yAxisTitleMargin,
|
||||
@@ -330,6 +331,18 @@ export default function transformProps(chartProps: EchartsGanttChartProps) {
|
||||
},
|
||||
);
|
||||
|
||||
const legendData = series
|
||||
.map(entry => {
|
||||
const { name } = entry;
|
||||
if (name === null || name === undefined) return '';
|
||||
return String(name);
|
||||
})
|
||||
.filter(name => name !== '')
|
||||
.sort((a, b) => {
|
||||
if (!legendSort) return 0;
|
||||
return legendSort === 'asc' ? a.localeCompare(b) : b.localeCompare(a);
|
||||
});
|
||||
|
||||
const tooltipFormatterMap = {
|
||||
[GenericDataType.Numeric]: tooltipValuesFormatter,
|
||||
[GenericDataType.String]: undefined,
|
||||
@@ -365,6 +378,7 @@ export default function transformProps(chartProps: EchartsGanttChartProps) {
|
||||
zoomable,
|
||||
legendState,
|
||||
),
|
||||
data: legendData,
|
||||
},
|
||||
grid: {
|
||||
...defaultGrid,
|
||||
|
||||
Reference in New Issue
Block a user