Skip to content

Commit 6ec6b3e

Browse files
committed
fix: reduce global scale correctly
1 parent 5aa72fc commit 6ec6b3e

2 files changed

Lines changed: 17 additions & 36 deletions

File tree

src/chart_types/xy_chart/state/selectors/get_api_scale_configs.ts

Lines changed: 16 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,7 @@ import { X_SCALE_DEFAULT, Y_SCALE_DEFAULT } from '../../scales/scale_defaults';
3131
import { APIScale } from '../../scales/types';
3232
import { isHorizontalAxis, isVerticalAxis } from '../../utils/axis_type_utils';
3333
import { groupBy } from '../../utils/group_data_series';
34-
import {
35-
AxisSpec,
36-
BasicSeriesSpec,
37-
CustomXDomain,
38-
DEFAULT_GLOBAL_ID,
39-
XScaleType,
40-
YDomainRange,
41-
} from '../../utils/specs';
34+
import { AxisSpec, BasicSeriesSpec, CustomXDomain, XScaleType, YDomainRange } from '../../utils/specs';
4235
import { isHorizontalRotation } from '../utils/common';
4336
import { getAxisSpecsSelector, getSeriesSpecsSelector } from './get_specs';
4437
import { mergeYCustomDomainsByGroupId } from './merge_y_custom_domains';
@@ -99,27 +92,20 @@ export function getAPIScaleConfigs(
9992
const customDomainByGroupId = mergeYCustomDomainsByGroupId(axisSpecs, settingsSpec.rotation);
10093

10194
const yAxes = axisSpecs.filter((d) => isHorizontalChart === isVerticalAxis(d.position));
102-
const y = Object.keys(scaleTypeByGroupId).reduce<APIScaleConfigs['y']>(
103-
(acc, groupId) => {
104-
const axis = yAxes.find((yAxis) => yAxis.groupId === groupId);
105-
const ticks = axis?.ticks ?? Y_SCALE_DEFAULT.ticks;
106-
const apiScale = scaleTypeByGroupId[groupId];
107-
const customDomain = customDomainByGroupId.get(groupId);
108-
if (!acc[groupId]) {
109-
acc[groupId] = {
110-
customDomain,
111-
...apiScale,
112-
ticks,
113-
};
114-
}
115-
acc[groupId].ticks = Math.min(acc[groupId].ticks, ticks);
116-
acc[groupId].customDomain = customDomain;
117-
return acc;
118-
},
119-
{
120-
[DEFAULT_GLOBAL_ID]: Y_SCALE_DEFAULT,
121-
},
122-
);
123-
95+
const y = Object.keys(scaleTypeByGroupId).reduce<APIScaleConfigs['y']>((acc, groupId) => {
96+
const axis = yAxes.find((yAxis) => yAxis.groupId === groupId);
97+
const ticks = axis?.ticks ?? Y_SCALE_DEFAULT.ticks;
98+
const apiScale = scaleTypeByGroupId[groupId];
99+
const customDomain = customDomainByGroupId.get(groupId);
100+
if (!acc[groupId]) {
101+
acc[groupId] = {
102+
customDomain,
103+
...apiScale,
104+
ticks,
105+
};
106+
}
107+
acc[groupId].ticks = Math.min(acc[groupId].ticks, ticks);
108+
return acc;
109+
}, {});
124110
return { x, y };
125111
}

stories/line/2_w_axis.tsx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,7 @@ export const Example = () => (
4141
yScaleType={ScaleType.Linear}
4242
xAccessor={0}
4343
yAccessors={[1]}
44-
data={[
45-
[0, 0],
46-
[1, 1],
47-
[2, 10],
48-
[3, 3],
49-
]}
44+
data={KIBANA_METRICS.metrics.kibana_os_load[0].data.slice(0, 5)}
5045
/>
5146
</Chart>
5247
);

0 commit comments

Comments
 (0)