mirror of https://github.com/buster-so/buster.git
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:
commit
085e47fb19
|
@ -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;
|
||||||
};
|
};
|
||||||
|
|
|
@ -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(() => {
|
||||||
|
|
Loading…
Reference in New Issue