From 6ec6b3e9c60b62df92b6245066cfdb5a5e8607be Mon Sep 17 00:00:00 2001 From: Marco Vettorello Date: Tue, 6 Apr 2021 15:04:51 +0200 Subject: [PATCH] fix: reduce global scale correctly --- .../state/selectors/get_api_scale_configs.ts | 46 +++++++------------ stories/line/2_w_axis.tsx | 7 +-- 2 files changed, 17 insertions(+), 36 deletions(-) diff --git a/src/chart_types/xy_chart/state/selectors/get_api_scale_configs.ts b/src/chart_types/xy_chart/state/selectors/get_api_scale_configs.ts index 276c845b00..c0205d1579 100644 --- a/src/chart_types/xy_chart/state/selectors/get_api_scale_configs.ts +++ b/src/chart_types/xy_chart/state/selectors/get_api_scale_configs.ts @@ -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'; @@ -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( - (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((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 }; } diff --git a/stories/line/2_w_axis.tsx b/stories/line/2_w_axis.tsx index de32940c61..36c4c67cac 100644 --- a/stories/line/2_w_axis.tsx +++ b/stories/line/2_w_axis.tsx @@ -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)} /> );