Merge pull request #1228 from buster-so/big-nate-bus-1985-colorby-tooltip-and-legend-defaults

logic for auto show with color by
This commit is contained in:
Nate Kelley 2025-09-30 16:03:50 -06:00 committed by GitHub
commit 085e47fb19
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 17 additions and 2 deletions

View File

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

View File

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