Skip to content

Commit 41e7dbb

Browse files
committed
comments
Signed-off-by: Qxisylolo <[email protected]>
1 parent 5c4ea13 commit 41e7dbb

File tree

4 files changed

+48
-58
lines changed

4 files changed

+48
-58
lines changed

src/plugins/explore/public/components/visualizations/bar_gauge/bar_gauge_exclusive_vis_options.test.tsx

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,11 @@ describe('BarGaugeExclusiveVisOptions', () => {
3030

3131
it('should call onChange when orientation is changed', () => {
3232
const { getByText } = render(
33-
<BarGaugeExclusiveVisOptions styles={defaultStyles} onChange={mockOnChange} />
33+
<BarGaugeExclusiveVisOptions
34+
styles={defaultStyles}
35+
onChange={mockOnChange}
36+
isXaxisNumerical={false}
37+
/>
3438
);
3539

3640
fireEvent.click(getByText('Horizontal'));
@@ -43,7 +47,11 @@ describe('BarGaugeExclusiveVisOptions', () => {
4347

4448
it('should call onChange when display mode is changed', () => {
4549
const { getByText } = render(
46-
<BarGaugeExclusiveVisOptions styles={defaultStyles} onChange={mockOnChange} />
50+
<BarGaugeExclusiveVisOptions
51+
styles={defaultStyles}
52+
onChange={mockOnChange}
53+
isXaxisNumerical={false}
54+
/>
4755
);
4856

4957
fireEvent.click(getByText('Stack'));
@@ -56,7 +64,11 @@ describe('BarGaugeExclusiveVisOptions', () => {
5664

5765
it('should call onChange when value display is changed', () => {
5866
const { getByText } = render(
59-
<BarGaugeExclusiveVisOptions styles={defaultStyles} onChange={mockOnChange} />
67+
<BarGaugeExclusiveVisOptions
68+
styles={defaultStyles}
69+
onChange={mockOnChange}
70+
isXaxisNumerical={false}
71+
/>
6072
);
6173

6274
fireEvent.click(getByText('Text Color'));
@@ -69,7 +81,11 @@ describe('BarGaugeExclusiveVisOptions', () => {
6981

7082
it('should call onChange when unfilled area switch is toggled', () => {
7183
const { getByRole } = render(
72-
<BarGaugeExclusiveVisOptions styles={defaultStyles} onChange={mockOnChange} />
84+
<BarGaugeExclusiveVisOptions
85+
styles={defaultStyles}
86+
onChange={mockOnChange}
87+
isXaxisNumerical={false}
88+
/>
7389
);
7490

7591
const switchElement = getByRole('switch');
@@ -83,7 +99,11 @@ describe('BarGaugeExclusiveVisOptions', () => {
8399

84100
it('should handle undefined styles with defaults', () => {
85101
const { getByText } = render(
86-
<BarGaugeExclusiveVisOptions styles={undefined as any} onChange={mockOnChange} />
102+
<BarGaugeExclusiveVisOptions
103+
styles={undefined as any}
104+
onChange={mockOnChange}
105+
isXaxisNumerical={false}
106+
/>
87107
);
88108

89109
fireEvent.click(getByText('Horizontal'));
@@ -92,20 +112,4 @@ describe('BarGaugeExclusiveVisOptions', () => {
92112
orientation: 'horizontal',
93113
});
94114
});
95-
96-
it('should show correct selected values', () => {
97-
const customStyles: ExclusiveBarGaugeConfig = {
98-
orientation: 'horizontal',
99-
displayMode: 'basic',
100-
valueDisplay: 'textColor',
101-
showUnfilledArea: false,
102-
};
103-
104-
const { container } = render(
105-
<BarGaugeExclusiveVisOptions styles={customStyles} onChange={mockOnChange} />
106-
);
107-
108-
// Check that the correct buttons are selected by looking for active state
109-
expect(container).toBeInTheDocument();
110-
});
111115
});

src/plugins/explore/public/components/visualizations/bar_gauge/bar_gauge_exclusive_vis_options.tsx

Lines changed: 19 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -62,37 +62,25 @@ export const BarGaugeExclusiveVisOptions = ({
6262
onChange,
6363
isXaxisNumerical,
6464
}: BarGaugeVisOptionsProps) => {
65-
const orientationOption = [
66-
isXaxisNumerical
67-
? {
68-
id: 'vertical',
69-
label: i18n.translate('explore.vis.barGauge.orientation.vertical.isXaxisNumerical', {
70-
defaultMessage: 'Horizontal',
71-
}),
72-
}
73-
: {
74-
id: 'vertical',
75-
label: i18n.translate('explore.vis.barGauge.orientation.vertical', {
76-
defaultMessage: 'Vertical',
77-
}),
78-
},
79-
isXaxisNumerical
80-
? {
81-
id: 'horizontal',
82-
label: i18n.translate(
83-
'explore.vis.barGauge.orientation.threshold.horizontal.isXaxisNumerical',
84-
{
85-
defaultMessage: 'Vertical',
86-
}
87-
),
88-
}
89-
: {
90-
id: 'horizontal',
91-
label: i18n.translate('explore.vis.barGauge.orientation.threshold.horizontal', {
92-
defaultMessage: 'Horizontal',
93-
}),
94-
},
95-
];
65+
const getOrientationOptions = () => {
66+
const horizontalLabel = i18n.translate('explore.vis.barGauge.orientation.horizontal', {
67+
defaultMessage: 'Horizontal',
68+
});
69+
const verticalLabel = i18n.translate('explore.vis.barGauge.orientation.vertical', {
70+
defaultMessage: 'Vertical',
71+
});
72+
73+
// When X-axis is numerical, the labels are swapped
74+
const verticalOptionLabel = isXaxisNumerical ? horizontalLabel : verticalLabel;
75+
const horizontalOptionLabel = isXaxisNumerical ? verticalLabel : horizontalLabel;
76+
77+
return [
78+
{ id: 'vertical', label: verticalOptionLabel },
79+
{ id: 'horizontal', label: horizontalOptionLabel },
80+
];
81+
};
82+
83+
const orientationOption = getOrientationOptions();
9684

9785
const updateExclusiveOption = (key: keyof BarGaugeChartStyle['exclusive'], value: any) => {
9886
onChange({

src/plugins/explore/public/components/visualizations/bar_gauge/bar_gauge_utils.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@ export const getBarOrientation = (
2020
};
2121
const nullStyle = { axis: null };
2222

23-
const shouldSwapAxes = (isXNumerical && isHorizontal) || (!isXNumerical && isHorizontal);
24-
25-
if (shouldSwapAxes) {
23+
if (isHorizontal) {
2624
return {
2725
xAxis: yAxis,
2826
xAxisStyle: isXNumerical ? axisStyle : nullStyle,
@@ -118,7 +116,8 @@ export const processThresholds = (thresholds: Threshold[]) => {
118116
return result;
119117
};
120118

121-
export const NormalizeData = (data: number, start: number, end: number) => {
119+
export const normalizeData = (data: number, start: number, end: number) => {
120+
if (start === end) return null;
122121
// normalize data value between start and end into 0–1 range
123122
return (data - start) / (end - start);
124123
};
@@ -159,7 +158,7 @@ export const generateParams = (
159158

160159
// collect stops up to current threshold
161160
const stops = thresholds.slice(0, i + 1).map((threshold) => {
162-
const offset = NormalizeData(threshold.value, start, end);
161+
const offset = normalizeData(threshold.value, start, end);
163162
return { offset, color: threshold.color };
164163
});
165164

src/plugins/explore/public/components/visualizations/bar_gauge/bar_gauge_vis_config.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ export interface ExclusiveBarGaugeConfig {
1414
orientation: 'vertical' | 'horizontal';
1515
displayMode: 'gradient' | 'stack' | 'basic';
1616
valueDisplay: 'valueColor' | 'textColor' | 'hidden';
17-
// namePlacement: 'auto' | 'hidden';
1817
showUnfilledArea: boolean;
1918
}
2019

0 commit comments

Comments
 (0)