Skip to content

Commit 1599253

Browse files
[IGNORE] TimeSeriesChart: small refactor (#536)
Signed-off-by: AntoineThebaud <[email protected]>
1 parent 0dc365c commit 1599253

File tree

3 files changed

+11
-17
lines changed

3 files changed

+11
-17
lines changed

timeserieschart/src/TimeSeriesChartPanel.tsx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ import {
5454
DEFAULT_VISUAL,
5555
THRESHOLD_PLOT_INTERVAL,
5656
QuerySettingsOptions,
57-
LOG_BASE,
5857
} from './time-series-chart-model';
5958
import {
6059
getTimeSeries,
@@ -122,13 +121,10 @@ export function TimeSeriesChartPanel(props: TimeSeriesChartProps): ReactElement
122121
return merge({}, DEFAULT_VISUAL, props.spec.visual);
123122
}, [props.spec.visual]);
124123

125-
// Use the logBase from yAxis options, defaulting to 'none' if not set
126-
const useLogarithmicBase: LOG_BASE = yAxis?.logBase;
127-
128124
// convert Perses dashboard format to be ECharts compatible
129125
const echartsYAxis = useMemo(() => {
130-
return convertPanelYAxis(yAxis, useLogarithmicBase);
131-
}, [yAxis, useLogarithmicBase]);
126+
return convertPanelYAxis(yAxis);
127+
}, [yAxis]);
132128

133129
const [selectedLegendItems, setSelectedLegendItems] = useState<SelectedLegendItemState>('ALL');
134130
const [legendSorting, setLegendSorting] = useState<NonNullable<LegendProps['tableProps']>['sorting']>();

timeserieschart/src/utils/data-transform.test.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ describe('convertPanelYAxis', () => {
5454
min: 0.1,
5555
max: 1,
5656
};
57-
const echartsAxis = convertPanelYAxis(persesAxis, undefined);
57+
const echartsAxis = convertPanelYAxis(persesAxis);
5858
// Axis label is handled outside of echarts since it is built with a custom React component.
5959
expect(echartsAxis).toEqual({
6060
show: true,
@@ -75,8 +75,9 @@ describe('convertPanelYAxis', () => {
7575
},
7676
min: 0.1,
7777
max: 1,
78+
logBase: 2,
7879
};
79-
const actualAxisLog2 = convertPanelYAxis(persesAxis, 2);
80+
const actualAxisLog2 = convertPanelYAxis(persesAxis);
8081
// Axis label is handled outside of echarts since it is built with a custom React component.
8182
expect(actualAxisLog2).toEqual({
8283
show: true,
@@ -88,7 +89,8 @@ describe('convertPanelYAxis', () => {
8889
show: true,
8990
},
9091
});
91-
const actualAxisLog10 = convertPanelYAxis(persesAxis, 10);
92+
persesAxis.logBase = 10;
93+
const actualAxisLog10 = convertPanelYAxis(persesAxis);
9294
// Axis label is handled outside of echarts since it is built with a custom React component.
9395
expect(actualAxisLog10).toEqual({
9496
show: true,

timeserieschart/src/utils/data-transform.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ import {
4040
TimeSeriesChartVisualOptions,
4141
TimeSeriesChartYAxisOptions,
4242
LineStyleType,
43-
LOG_BASE,
4443
} from '../time-series-chart-model';
4544

4645
export type RunningQueriesState = ReturnType<typeof useTimeSeriesQueries>;
@@ -232,13 +231,10 @@ function findMax(data: LegacyTimeSeries[] | TimeSeries[]): number {
232231
* Converts Perses panel yAxis from dashboard spec to ECharts supported yAxis options.
233232
* Handles both linear and logarithmic scales with appropriate min/max calculations.
234233
*/
235-
export function convertPanelYAxis(
236-
inputAxis: TimeSeriesChartYAxisOptions = {},
237-
useLogarithmicBase: LOG_BASE | undefined
238-
): YAXisComponentOption {
234+
export function convertPanelYAxis(inputAxis: TimeSeriesChartYAxisOptions = {}): YAXisComponentOption {
239235
// Determine the appropriate min value based on scale type and user input
240236
let minValue: YAXisComponentOption['min'];
241-
if (useLogarithmicBase !== undefined) {
237+
if (inputAxis.logBase !== undefined) {
242238
// For logarithmic scales without explicit min:
243239
// Let ECharts auto-calculate the range based on data to avoid issues with
244240
// function-based calculations which can result in improper ranges (e.g., 1-10)
@@ -277,11 +273,11 @@ export function convertPanelYAxis(
277273
};
278274

279275
// Apply logarithmic scale settings if requested
280-
if (useLogarithmicBase !== undefined) {
276+
if (inputAxis.logBase !== undefined) {
281277
return {
282278
...yAxis,
283279
type: 'log',
284-
logBase: useLogarithmicBase,
280+
logBase: inputAxis.logBase,
285281
};
286282
}
287283

0 commit comments

Comments
 (0)