From ea76be157932d7fb814aad137c3bf4242069bf2b Mon Sep 17 00:00:00 2001 From: Nick Partridge Date: Thu, 27 May 2021 19:09:56 -0500 Subject: [PATCH] refactor: remove yScaleToDataExtent option (#1146) --- packages/osd-charts/api/charts.api.md | 2 -- .../osd-charts/docs/0-Intro/1-Overview.mdx | 5 --- .../docs/1-Typesofchart/3-Stacked.mdx | 32 +++++++------------ .../docs/2-ChartPropTables/13-AreaProps.md | 11 +++---- .../docs/2-ChartPropTables/14-LineProps.md | 3 +- .../xy_chart/domains/x_domain.test.ts | 2 -- .../chart_types/xy_chart/domains/y_domain.ts | 7 +--- .../xy_chart/specs/area_series.tsx | 2 -- .../chart_types/xy_chart/specs/bar_series.tsx | 2 -- .../xy_chart/specs/bubble_series.tsx | 10 +----- .../xy_chart/specs/histogram_bar_series.tsx | 2 -- .../xy_chart/specs/line_series.tsx | 2 -- .../src/chart_types/xy_chart/utils/specs.ts | 6 ---- .../__snapshots__/chart.test.tsx.snap | 2 +- .../stories/bar/32_scale_to_extent.tsx | 6 ---- 15 files changed, 21 insertions(+), 73 deletions(-) diff --git a/packages/osd-charts/api/charts.api.md b/packages/osd-charts/api/charts.api.md index 55ab92780454..b5e2b3c648ee 100644 --- a/packages/osd-charts/api/charts.api.md +++ b/packages/osd-charts/api/charts.api.md @@ -1693,8 +1693,6 @@ export interface SeriesScales { xNice?: boolean; xScaleType: XScaleType; yNice?: boolean; - // @deprecated - yScaleToDataExtent?: boolean; yScaleType: ScaleContinuousType; } diff --git a/packages/osd-charts/docs/0-Intro/1-Overview.mdx b/packages/osd-charts/docs/0-Intro/1-Overview.mdx index 387bbcb7db58..e93cfcf8618c 100644 --- a/packages/osd-charts/docs/0-Intro/1-Overview.mdx +++ b/packages/osd-charts/docs/0-Intro/1-Overview.mdx @@ -187,11 +187,6 @@ export interface SeriesScales { * @default ScaleType.Linear */ yScaleType: ScaleContinuousType; - /** - * if true, the min y value is set to the minimum domain value, 0 otherwise - * @default false - */ - yScaleToDataExtent: boolean; } ``` diff --git a/packages/osd-charts/docs/1-Typesofchart/3-Stacked.mdx b/packages/osd-charts/docs/1-Typesofchart/3-Stacked.mdx index 424246f84b20..49162be3b2ad 100644 --- a/packages/osd-charts/docs/1-Typesofchart/3-Stacked.mdx +++ b/packages/osd-charts/docs/1-Typesofchart/3-Stacked.mdx @@ -19,13 +19,13 @@ import { KIBANA_METRICS } from '../../src/utils/data_samples/test_dataset_kibana -# Stacked charts -### Stacked line/bar/area charts include a stackAccessors prop within their seriesSpec. +# Stacked charts +### Stacked line/bar/area charts include a stackAccessors prop within their seriesSpec. The stackAccessors prop is an array of fields that indicates the stack membership. *** -## Stacked bar chart examples +## Stacked bar chart examples @@ -56,7 +56,7 @@ The stackAccessors prop is an array of fields that indicates the stack membershi /> -The code for the chart above can be found below. +The code for the chart above can be found below.
```js @@ -109,7 +109,7 @@ The code for the chart above can be found below. title={KIBANA_METRICS.metrics.kibana_os_load[0].metric.title} position={Position.Left} tickFormat={(d) => Number(d).toFixed(2)} - /> + /> Number(d).toFixed(2)} - /> + /> Number(d).toFixed(2)} @@ -212,7 +213,6 @@ The code for the chart above can be found below. y0Accessors={[2]} data={KIBANA_METRICS.metrics.kibana_os_load[0].data} stackAccessors={[0]} - yScaleToDataExtent={boolean('scale to extent', false)} /> [d[0], 20, 10])} stackAccessors={[0]} - yScaleToDataExtent={boolean('scale to extent', false)} /> @@ -235,6 +234,7 @@ The code for the chart above can be found below. Number(d).toFixed(2)} /> @@ -247,7 +247,6 @@ The code for the chart above can be found below. y0Accessors={[2]} data={KIBANA_METRICS.metrics.kibana_os_load[0].data} stackAccessors={[0]} - yScaleToDataExtent={boolean('scale to extent', false)} /> [d[0], 20, 10])} stackAccessors={[0]} - yScaleToDataExtent={boolean('scale to extent', false)} /> ``` @@ -290,7 +288,6 @@ The code for the chart above can be found below. [8, 2], [9, 1], ]} - yScaleToDataExtent={false} /> @@ -362,7 +357,6 @@ The code for the chart above can be found below. [8, 2], [9, 1], ]} - yScaleToDataExtent={false} /> ``` @@ -409,9 +401,9 @@ The code for the chart above can be found below. *** -## Stacked line charts +## Stacked line charts -This chart shows multiple line series with an axis and legend. +This chart shows multiple line series with an axis and legend. @@ -456,7 +448,7 @@ This chart shows multiple line series with an axis and legend. /> -Compare the above chart with the following below. The difference between the two charts is the addition of `stackAccessors={[0]}` in the `` components. +Compare the above chart with the following below. The difference between the two charts is the addition of `stackAccessors={[0]}` in the `` components. @@ -553,4 +545,4 @@ Compare the above chart with the following below. The difference between the two /> ``` -
\ No newline at end of file + diff --git a/packages/osd-charts/docs/2-ChartPropTables/13-AreaProps.md b/packages/osd-charts/docs/2-ChartPropTables/13-AreaProps.md index ee1f748d32ae..343608fa0d25 100644 --- a/packages/osd-charts/docs/2-ChartPropTables/13-AreaProps.md +++ b/packages/osd-charts/docs/2-ChartPropTables/13-AreaProps.md @@ -1,5 +1,5 @@ -### Area component props table -Default props are set in the area_series.tsx file +### Area component props table +Default props are set in the area_series.tsx file | Prop | Type | Default | Note | |:------|:------:|:---------:|:------| @@ -11,11 +11,10 @@ Default props are set in the area_series.tsx file | yAccessors `(required)`| Accessor[] | | An array of field names one per y metric value | | data `(required)` | datum[] | | An array of data | | chartType | `typeof ChartType.XYAxis` | ChartType.XYAxis | | -| specType | `typeof SpecType.Series` | SpecType.Series | | +| specType | `typeof SpecType.Series` | SpecType.Series | | | seriesType| `typeof SeriesType.Area` | SeriesType.Area | | -| groupId | string | DEFAULT_GLOBAL_ID | | -| yScaleToDataExtent | boolean | false | | -| hideInLegend | boolean | false | hide the series in the legend | +| groupId | string | DEFAULT_GLOBAL_ID | | +| hideInLegend | boolean | false | hide the series in the legend | | histogramModeAlignment | `Start or Center or End` | histogramModeAlignment.Center | Determines how points in the series will align to bands in histogram mode | *** diff --git a/packages/osd-charts/docs/2-ChartPropTables/14-LineProps.md b/packages/osd-charts/docs/2-ChartPropTables/14-LineProps.md index 2dd6febc72de..ed15fffadd7b 100644 --- a/packages/osd-charts/docs/2-ChartPropTables/14-LineProps.md +++ b/packages/osd-charts/docs/2-ChartPropTables/14-LineProps.md @@ -4,14 +4,13 @@ |:------|:------:|:---------:|:------| | id `(required)`|`string` ||The id of the spec | | chartType | `typeof ChartType.XYAxis` | ChartType.XYAxis | | -| specType | `typeof SpecType.Series` | SpecType.Series | | +| specType | `typeof SpecType.Series` | SpecType.Series | | | seriesTypes | | SeriesType.Line | | | groupId || DEFAULT_GROUP_ID |The ID of the line | | xScaleType `(required)`| `ScaleType (ScaleType.Ordinal or ScaleType.Linear or ScaleType.Time)`|ScaleType.Ordinal | The x axis scale type | | yScaleType `(required)`| `ScaleType (ScaleType.Ordinal or ScaleType.Linear or ScaleType.Time)`| ScaleType.Linear | The y axis scale type | | xAccessor `(required)` | Accessor | 'x' | the field name of the x value on the Datum object| | yAccessors `(required)`||['y'] | An array of field names one per y metric value | -| yScaleToDataExtent || false || | hideInLegend | boolean | false | If the series should appear in the legend| | histogramModeAlignment | `Start or Center or End` | histogramModeAlignment.Center | Determines how points in the series will align to bands in histogram mode | | data `(required)` | datum[] | | An array of data | diff --git a/packages/osd-charts/src/chart_types/xy_chart/domains/x_domain.test.ts b/packages/osd-charts/src/chart_types/xy_chart/domains/x_domain.test.ts index 6ab4bd962a1b..af4b008105ee 100644 --- a/packages/osd-charts/src/chart_types/xy_chart/domains/x_domain.test.ts +++ b/packages/osd-charts/src/chart_types/xy_chart/domains/x_domain.test.ts @@ -409,7 +409,6 @@ describe('X Domain', () => { yAccessors: ['y'], xScaleType: ScaleType.Linear, yScaleType: ScaleType.Linear, - yScaleToDataExtent: false, data: [ { x: 0, y: 0 }, { x: 'a', y: 0 }, @@ -427,7 +426,6 @@ describe('X Domain', () => { yAccessors: ['y'], xScaleType: ScaleType.Linear, yScaleType: ScaleType.Linear, - yScaleToDataExtent: false, data: [ { x: 0, y: 0 }, { x: 7, y: 0 }, diff --git a/packages/osd-charts/src/chart_types/xy_chart/domains/y_domain.ts b/packages/osd-charts/src/chart_types/xy_chart/domains/y_domain.ts index 8053adf3ed0e..2b05e1c8bdcc 100644 --- a/packages/osd-charts/src/chart_types/xy_chart/domains/y_domain.ts +++ b/packages/osd-charts/src/chart_types/xy_chart/domains/y_domain.ts @@ -35,7 +35,7 @@ import { YDomain } from './types'; /** @internal */ export type YBasicSeriesSpec = Pick< BasicSeriesSpec, - 'id' | 'seriesType' | 'yScaleType' | 'groupId' | 'stackAccessors' | 'yScaleToDataExtent' | 'useDefaultGroupDomain' + 'id' | 'seriesType' | 'yScaleType' | 'groupId' | 'stackAccessors' | 'useDefaultGroupDomain' > & { stackMode?: StackMode; enableHistogramMode?: boolean }; /** @internal */ @@ -75,12 +75,7 @@ function mergeYDomainForGroup( if (stackMode === StackMode.Percentage) { domain = computeContinuousDataDomain([0, 1], identity, type, customDomain); } else { - // TODO remove when removing yScaleToDataExtent const newCustomDomain = customDomain ? { ...customDomain } : {}; - const shouldScaleToExtent = dataSeries.some(({ spec: { yScaleToDataExtent } }) => yScaleToDataExtent); - if (customDomain?.fit !== true && shouldScaleToExtent) { - newCustomDomain.fit = true; - } // compute stacked domain const stackedDomain = computeYDomain(stacked, hasZeroBaselineSpecs, type, newCustomDomain); diff --git a/packages/osd-charts/src/chart_types/xy_chart/specs/area_series.tsx b/packages/osd-charts/src/chart_types/xy_chart/specs/area_series.tsx index b1fc9b2e65c0..6151140da646 100644 --- a/packages/osd-charts/src/chart_types/xy_chart/specs/area_series.tsx +++ b/packages/osd-charts/src/chart_types/xy_chart/specs/area_series.tsx @@ -34,7 +34,6 @@ const defaultProps = { yScaleType: ScaleType.Linear, xAccessor: 'x', yAccessors: ['y'], - yScaleToDataExtent: false, hideInLegend: false, histogramModeAlignment: HistogramModeAlignments.Center, }; @@ -52,7 +51,6 @@ export const AreaSeries: React.FunctionComponent(defaultProps), diff --git a/packages/osd-charts/src/chart_types/xy_chart/specs/bar_series.tsx b/packages/osd-charts/src/chart_types/xy_chart/specs/bar_series.tsx index 034449fe8959..b0862fdd6d47 100644 --- a/packages/osd-charts/src/chart_types/xy_chart/specs/bar_series.tsx +++ b/packages/osd-charts/src/chart_types/xy_chart/specs/bar_series.tsx @@ -34,7 +34,6 @@ const defaultProps = { yScaleType: ScaleType.Linear, xAccessor: 'x', yAccessors: ['y'], - yScaleToDataExtent: false, hideInLegend: false, enableHistogramMode: false, }; @@ -52,7 +51,6 @@ export const BarSeries: React.FunctionComponent(defaultProps), diff --git a/packages/osd-charts/src/chart_types/xy_chart/specs/bubble_series.tsx b/packages/osd-charts/src/chart_types/xy_chart/specs/bubble_series.tsx index 99f23470005c..9fc7e2cb44b5 100644 --- a/packages/osd-charts/src/chart_types/xy_chart/specs/bubble_series.tsx +++ b/packages/osd-charts/src/chart_types/xy_chart/specs/bubble_series.tsx @@ -35,7 +35,6 @@ const defaultProps = { xAccessor: 'x', yAccessors: ['y'], hideInLegend: false, - yScaleToDataExtent: false, }; type SpecRequiredProps = Pick; type SpecOptionalProps = Partial>; @@ -53,13 +52,6 @@ type SpecOptionalProps = Partial = getConnect()( specComponentFactory< BubbleSeriesSpec, - | 'seriesType' - | 'groupId' - | 'xScaleType' - | 'yScaleType' - | 'xAccessor' - | 'yAccessors' - | 'hideInLegend' - | 'yScaleToDataExtent' + 'seriesType' | 'groupId' | 'xScaleType' | 'yScaleType' | 'xAccessor' | 'yAccessors' | 'hideInLegend' >(defaultProps), ); diff --git a/packages/osd-charts/src/chart_types/xy_chart/specs/histogram_bar_series.tsx b/packages/osd-charts/src/chart_types/xy_chart/specs/histogram_bar_series.tsx index 6ef72d4a720c..5724a49c8ffa 100644 --- a/packages/osd-charts/src/chart_types/xy_chart/specs/histogram_bar_series.tsx +++ b/packages/osd-charts/src/chart_types/xy_chart/specs/histogram_bar_series.tsx @@ -34,7 +34,6 @@ const defaultProps = { yScaleType: ScaleType.Linear, xAccessor: 'x', yAccessors: ['y'], - yScaleToDataExtent: false, hideInLegend: false, enableHistogramMode: true as const, }; @@ -52,7 +51,6 @@ export const HistogramBarSeries: React.FunctionComponent(defaultProps), diff --git a/packages/osd-charts/src/chart_types/xy_chart/specs/line_series.tsx b/packages/osd-charts/src/chart_types/xy_chart/specs/line_series.tsx index 97a25b810529..950b9ddc032f 100644 --- a/packages/osd-charts/src/chart_types/xy_chart/specs/line_series.tsx +++ b/packages/osd-charts/src/chart_types/xy_chart/specs/line_series.tsx @@ -34,7 +34,6 @@ const defaultProps = { yScaleType: ScaleType.Linear, xAccessor: 'x', yAccessors: ['y'], - yScaleToDataExtent: false, hideInLegend: false, histogramModeAlignment: HistogramModeAlignments.Center, }; @@ -51,7 +50,6 @@ export const LineSeries: React.FunctionComponent(defaultProps), diff --git a/packages/osd-charts/src/chart_types/xy_chart/utils/specs.ts b/packages/osd-charts/src/chart_types/xy_chart/utils/specs.ts index c8817ed487ab..4ee93c475e2c 100644 --- a/packages/osd-charts/src/chart_types/xy_chart/utils/specs.ts +++ b/packages/osd-charts/src/chart_types/xy_chart/utils/specs.ts @@ -489,12 +489,6 @@ export interface SeriesScales { * @defaultValue `false` */ yNice?: boolean; - /** - * if true, the min y value is set to the minimum domain value, 0 otherwise - * @deprecated use `domain.fit` instead - * @defaultValue `false` - */ - yScaleToDataExtent?: boolean; } /** @public */ diff --git a/packages/osd-charts/src/components/__snapshots__/chart.test.tsx.snap b/packages/osd-charts/src/components/__snapshots__/chart.test.tsx.snap index e86c6226e422..3e5550b59338 100644 --- a/packages/osd-charts/src/components/__snapshots__/chart.test.tsx.snap +++ b/packages/osd-charts/src/components/__snapshots__/chart.test.tsx.snap @@ -57,7 +57,7 @@ exports[`Chart should render the legend name test 1`] = ` - + diff --git a/packages/osd-charts/stories/bar/32_scale_to_extent.tsx b/packages/osd-charts/stories/bar/32_scale_to_extent.tsx index 1bdcad59ba1b..92b9c788d88d 100644 --- a/packages/osd-charts/stories/bar/32_scale_to_extent.tsx +++ b/packages/osd-charts/stories/bar/32_scale_to_extent.tsx @@ -36,7 +36,6 @@ const logDomains = (data: any[], customDomain: any) => { }; export const Example = () => { - const yScaleToDataExtent = boolean('yScaleDataToExtent', false); const fit = boolean('fit Y domain to data', true); const constrainPadding = boolean('constrain padding', true); const padding = text('domain padding', '0'); @@ -97,7 +96,6 @@ export const Example = () => { yAccessors={['y']} stackAccessors={['x']} data={data} - yScaleToDataExtent={yScaleToDataExtent} /> ); @@ -106,9 +104,5 @@ export const Example = () => { Example.story = { parameters: { options: { selectedPanel: SB_SOURCE_PANEL }, - info: { - text: - '`yScaleToDataExtent` has been **depricated** in favor of `domain.fit`. The functionality is identical between the two.', - }, }, };