Skip to content

Commit

Permalink
add checkbox to display or not ALL/INV button
Browse files Browse the repository at this point in the history
  • Loading branch information
Romain GREFFIER committed Feb 21, 2025
1 parent 093135f commit 7ace9b2
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import {
D3_FORMAT_DOCS,
D3_NUMBER_FORMAT_DESCRIPTION_VALUES_TEXT,
} from '@superset-ui/chart-controls';
import { showLegendControl, showValueControl } from '../controls';
import { showLegendControl, showLegendToggleControl, showValueControl } from '../controls';

const config: ControlPanelConfig = {
controlPanelSections: [
Expand Down Expand Up @@ -114,6 +114,7 @@ const config: ControlPanelConfig = {
['color_scheme'],
[showValueControl],
[showLegendControl],
[showLegendToggleControl],
[
{
name: 'x_axis_title',
Expand Down Expand Up @@ -172,3 +173,4 @@ const config: ControlPanelConfig = {
};

export default config;
console.log('✅ controlPanel.tsx is loaded! Test');
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export default function transformProps(
groupby = [],
normalize,
showLegend,
showLegendToggle,
showValue,
sliceId,
xAxisFormat,
Expand Down Expand Up @@ -152,6 +153,8 @@ export default function transformProps(

type EChartsOption = ComposeOption<GridComponentOption | BarSeriesOption>;

console.log('🚀 DEBUG transformProps.ts - Avant envoi à getLegendProps:', { showLegend, showLegendToggle });

const echartOptions: EChartsOption = {
grid: {
...defaultGrid,
Expand Down Expand Up @@ -186,6 +189,8 @@ export default function transformProps(
theme,
false,
legendState,
undefined,
showLegendToggle,
),
data: legendOptions,
},
Expand All @@ -195,7 +200,7 @@ export default function transformProps(
formatter: tooltipFormatter,
},
};

console.log('🚀 transformProps.ts - Après envoi à getLegendProps:', { showLegend, showLegendToggle });
return {
refs,
formData,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export type HistogramFormData = QueryFormData & {
xAxisTitle: string;
yAxisFormat: string;
yAxisTitle: string;
showLegendToggle: boolean; // ✅ Ajout de l'option ici
};

export interface HistogramChartProps extends BaseChartProps<HistogramFormData> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ function Echart(
chartRef.current?.getZr().on(name, handler);
});

console.log('Test Echart options:', echartOptions.legend);

chartRef.current.setOption(echartOptions, true);
}, [echartOptions, eventHandlers, zrEventHandlers]);

Expand Down
12 changes: 12 additions & 0 deletions superset-frontend/plugins/plugin-chart-echarts/src/controls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,18 @@ export const showLegendControl: ControlSetItem = {
},
};

export const showLegendToggleControl: ControlSetItem = {
name: 'show_legend_toggle',
config: {
type: 'CheckboxControl',
label: t('Show All/Invert buttons in legend'),
renderTrigger: true,
default: true, // ✅ Par défaut, les boutons sont affichés
description: t('Toggle to show/hide the "All/Invert" buttons in the legend.'),
visibility: ({ controls }: ControlPanelsContainerProps) =>
Boolean(controls?.show_legend?.value), // ✅ S'affiche seulement si la légende est activée
},
};
const legendMarginControl: ControlSetItem = {
name: 'legendMargin',
config: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,9 @@ export function getLegendProps(
zoomable = false,
legendState?: LegendState,
padding?: LegendPaddingType,
showLegendToggle?: boolean, // ✅ Ajout de l'option ici
): LegendComponentOption | LegendComponentOption[] {
console.log('📌 LEGEND PROPS:', { show, showLegendToggle });
const legend: LegendComponentOption | LegendComponentOption[] = {
orient: [LegendOrientation.Top, LegendOrientation.Bottom].includes(
orientation,
Expand All @@ -436,7 +438,7 @@ export function getLegendProps(
show,
type,
selected: legendState,
selector: ['all', 'inverse'],
selector: showLegendToggle === false ? [] : ['all', 'inverse'], // ✅ Activation conditionnelle
selectorLabel: {
fontFamily: theme.typography.families.sansSerif,
fontSize: theme.typography.sizes.s,
Expand Down

0 comments on commit 7ace9b2

Please sign in to comment.