Skip to content

Commit

Permalink
fix: reduce global scale correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
markov00 committed Apr 6, 2021
1 parent 5aa72fc commit 6ec6b3e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 36 deletions.
46 changes: 16 additions & 30 deletions src/chart_types/xy_chart/state/selectors/get_api_scale_configs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,7 @@ import { X_SCALE_DEFAULT, Y_SCALE_DEFAULT } from '../../scales/scale_defaults';
import { APIScale } from '../../scales/types';
import { isHorizontalAxis, isVerticalAxis } from '../../utils/axis_type_utils';
import { groupBy } from '../../utils/group_data_series';
import {
AxisSpec,
BasicSeriesSpec,
CustomXDomain,
DEFAULT_GLOBAL_ID,
XScaleType,
YDomainRange,
} from '../../utils/specs';
import { AxisSpec, BasicSeriesSpec, CustomXDomain, XScaleType, YDomainRange } from '../../utils/specs';
import { isHorizontalRotation } from '../utils/common';
import { getAxisSpecsSelector, getSeriesSpecsSelector } from './get_specs';
import { mergeYCustomDomainsByGroupId } from './merge_y_custom_domains';
Expand Down Expand Up @@ -99,27 +92,20 @@ export function getAPIScaleConfigs(
const customDomainByGroupId = mergeYCustomDomainsByGroupId(axisSpecs, settingsSpec.rotation);

const yAxes = axisSpecs.filter((d) => isHorizontalChart === isVerticalAxis(d.position));
const y = Object.keys(scaleTypeByGroupId).reduce<APIScaleConfigs['y']>(
(acc, groupId) => {
const axis = yAxes.find((yAxis) => yAxis.groupId === groupId);
const ticks = axis?.ticks ?? Y_SCALE_DEFAULT.ticks;
const apiScale = scaleTypeByGroupId[groupId];
const customDomain = customDomainByGroupId.get(groupId);
if (!acc[groupId]) {
acc[groupId] = {
customDomain,
...apiScale,
ticks,
};
}
acc[groupId].ticks = Math.min(acc[groupId].ticks, ticks);
acc[groupId].customDomain = customDomain;
return acc;
},
{
[DEFAULT_GLOBAL_ID]: Y_SCALE_DEFAULT,
},
);

const y = Object.keys(scaleTypeByGroupId).reduce<APIScaleConfigs['y']>((acc, groupId) => {
const axis = yAxes.find((yAxis) => yAxis.groupId === groupId);
const ticks = axis?.ticks ?? Y_SCALE_DEFAULT.ticks;
const apiScale = scaleTypeByGroupId[groupId];
const customDomain = customDomainByGroupId.get(groupId);
if (!acc[groupId]) {
acc[groupId] = {
customDomain,
...apiScale,
ticks,
};
}
acc[groupId].ticks = Math.min(acc[groupId].ticks, ticks);
return acc;
}, {});
return { x, y };
}
7 changes: 1 addition & 6 deletions stories/line/2_w_axis.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,7 @@ export const Example = () => (
yScaleType={ScaleType.Linear}
xAccessor={0}
yAccessors={[1]}
data={[
[0, 0],
[1, 1],
[2, 10],
[3, 3],
]}
data={KIBANA_METRICS.metrics.kibana_os_load[0].data.slice(0, 5)}
/>
</Chart>
);
Expand Down

0 comments on commit 6ec6b3e

Please sign in to comment.