logic for auto show with color by

This commit is contained in:
Nate Kelley 2025-09-30 16:01:28 -06:00
parent db2744f93d
commit 352cf62f2c
No known key found for this signature in database
GPG Key ID: FD90372AB8D98B4F
2 changed files with 17 additions and 2 deletions

View File

@ -7,12 +7,14 @@ export const useLegendAutoShow = ({
selectedChartType,
showLegendProp = null,
categoryAxisColumnNames,
colorByColumnNames,
allYAxisColumnNames,
}: {
selectedChartType: BusterChartProps['selectedChartType'];
showLegendProp: BusterChartProps['showLegend'];
categoryAxisColumnNames: string[] | null | undefined;
allYAxisColumnNames: string[];
colorByColumnNames: string[];
}) => {
const showLegend = useMemo(() => {
if (UNSUPPORTED_CHART_TYPES.includes(selectedChartType)) {
@ -38,10 +40,16 @@ export const useLegendAutoShow = ({
return true;
}
const defaultShowLegend = !!categoryAxisColumnNames?.length;
const defaultShowLegend = !!categoryAxisColumnNames?.length || !!colorByColumnNames?.length;
return defaultShowLegend;
}, [selectedChartType, allYAxisColumnNames, categoryAxisColumnNames, showLegendProp]);
}, [
selectedChartType,
allYAxisColumnNames,
categoryAxisColumnNames,
showLegendProp,
colorByColumnNames,
]);
return showLegend;
};

View File

@ -1,4 +1,5 @@
import type {
BarAndLineAxis,
ChartEncodes,
ChartType,
ComboChartAxis,
@ -52,11 +53,17 @@ export const useBusterChartLegend = ({
[(selectedAxis as ScatterAxis)?.category?.join('')]
);
const colorByColumnNames = useMemo(
() => (selectedAxis as BarAndLineAxis)?.colorBy ?? [],
[(selectedAxis as BarAndLineAxis)?.colorBy?.join('')]
);
const showLegend = useLegendAutoShow({
selectedChartType,
showLegendProp,
categoryAxisColumnNames,
allYAxisColumnNames,
colorByColumnNames,
});
const renderLegend = useMemo(() => {