diff --git a/integration/tests/__image_snapshots__/all-test-ts-baseline-visual-tests-for-all-stories-axis-fit-domain-to-extent-in-y-axis-visually-looks-correct-1-snap.png b/integration/tests/__image_snapshots__/all-test-ts-baseline-visual-tests-for-all-stories-axis-fit-domain-to-extent-in-y-axis-visually-looks-correct-1-snap.png new file mode 100644 index 0000000000..3fc056beaf Binary files /dev/null and b/integration/tests/__image_snapshots__/all-test-ts-baseline-visual-tests-for-all-stories-axis-fit-domain-to-extent-in-y-axis-visually-looks-correct-1-snap.png differ diff --git a/package.json b/package.json index 2399882d59..f86de9761c 100644 --- a/package.json +++ b/package.json @@ -98,10 +98,10 @@ "enzyme": "^3.9.0", "enzyme-adapter-react-16": "^1.10.0", "eslint": "^6.7.1", - "eslint-config-prettier": "^6.7.0", + "eslint-config-prettier": "^6.9.0", "eslint-plugin-import": "^2.17.3", "eslint-plugin-jest": "^23.0.4", - "eslint-plugin-prettier": "^3.1.0", + "eslint-plugin-prettier": "^3.1.2", "eslint-plugin-react": "^7.13.0", "husky": "^3.1.0", "jest": "^24.9.0", @@ -117,7 +117,7 @@ "moment-timezone": "^0.5.27", "node-sass": "^4.11.0", "postcss-cli": "^6.1.3", - "prettier": "1.16.4", + "prettier": "^1.19.1", "pretty-quick": "^2.0.0", "puppeteer": "^1.20.0", "react": "16.10.x", diff --git a/src/chart_types/xy_chart/crosshair/crosshair_utils.linear_snap.test.ts b/src/chart_types/xy_chart/crosshair/crosshair_utils.linear_snap.test.ts index 9617ebe45f..edb86e02be 100644 --- a/src/chart_types/xy_chart/crosshair/crosshair_utils.linear_snap.test.ts +++ b/src/chart_types/xy_chart/crosshair/crosshair_utils.linear_snap.test.ts @@ -19,7 +19,11 @@ describe('Crosshair utils linear scale', () => { id: barSeries1SpecId, groupId: getGroupId('group1'), seriesType: SeriesTypes.Bar, - data: [[0, 0], [1, 0], [2, 0]], + data: [ + [0, 0], + [1, 0], + [2, 0], + ], xAccessor: 0, yAccessors: [1], xScaleType: ScaleType.Linear, @@ -32,7 +36,11 @@ describe('Crosshair utils linear scale', () => { id: barSeries2SpecId, groupId: getGroupId('group1'), seriesType: SeriesTypes.Bar, - data: [[0, 2], [1, 2], [2, 2]], + data: [ + [0, 2], + [1, 2], + [2, 2], + ], xAccessor: 0, yAccessors: [1], xScaleType: ScaleType.Linear, @@ -45,7 +53,11 @@ describe('Crosshair utils linear scale', () => { id: lineSeries1SpecId, groupId: getGroupId('group1'), seriesType: SeriesTypes.Line, - data: [[0, 0], [1, 0], [2, 0]], + data: [ + [0, 0], + [1, 0], + [2, 0], + ], xAccessor: 0, yAccessors: [1], xScaleType: ScaleType.Linear, @@ -58,7 +70,11 @@ describe('Crosshair utils linear scale', () => { id: lineSeries2SpecId, groupId: getGroupId('group1'), seriesType: SeriesTypes.Line, - data: [[0, 2], [1, 2], [2, 2]], + data: [ + [0, 2], + [1, 2], + [2, 2], + ], xAccessor: 0, yAccessors: [1], xScaleType: ScaleType.Linear, diff --git a/src/chart_types/xy_chart/crosshair/crosshair_utils.ordinal_snap.test.ts b/src/chart_types/xy_chart/crosshair/crosshair_utils.ordinal_snap.test.ts index d0480af837..672141af12 100644 --- a/src/chart_types/xy_chart/crosshair/crosshair_utils.ordinal_snap.test.ts +++ b/src/chart_types/xy_chart/crosshair/crosshair_utils.ordinal_snap.test.ts @@ -18,7 +18,11 @@ describe('Crosshair utils ordinal scales', () => { id: barSeries1SpecId, groupId: getGroupId('group1'), seriesType: SeriesTypes.Bar, - data: [['a', 0], ['b', 0], ['c', 0]], + data: [ + ['a', 0], + ['b', 0], + ['c', 0], + ], xAccessor: 0, yAccessors: [1], xScaleType: ScaleType.Ordinal, @@ -31,7 +35,11 @@ describe('Crosshair utils ordinal scales', () => { id: barSeries2SpecId, groupId: getGroupId('group1'), seriesType: SeriesTypes.Bar, - data: [['a', 2], ['b', 2], ['c', 2]], + data: [ + ['a', 2], + ['b', 2], + ['c', 2], + ], xAccessor: 0, yAccessors: [1], xScaleType: ScaleType.Ordinal, @@ -44,7 +52,11 @@ describe('Crosshair utils ordinal scales', () => { id: lineSeries1SpecId, groupId: getGroupId('group1'), seriesType: SeriesTypes.Line, - data: [['a', 0], ['b', 0], ['c', 0]], + data: [ + ['a', 0], + ['b', 0], + ['c', 0], + ], xAccessor: 0, yAccessors: [1], xScaleType: ScaleType.Ordinal, @@ -57,7 +69,11 @@ describe('Crosshair utils ordinal scales', () => { id: lineSeries2SpecId, groupId: getGroupId('group1'), seriesType: SeriesTypes.Line, - data: [['a', 2], ['b', 2], ['c', 2]], + data: [ + ['a', 2], + ['b', 2], + ['c', 2], + ], xAccessor: 0, yAccessors: [1], xScaleType: ScaleType.Ordinal, diff --git a/src/chart_types/xy_chart/domains/x_domain.test.ts b/src/chart_types/xy_chart/domains/x_domain.test.ts index f63ddc0a61..782b6afc5f 100644 --- a/src/chart_types/xy_chart/domains/x_domain.test.ts +++ b/src/chart_types/xy_chart/domains/x_domain.test.ts @@ -179,7 +179,12 @@ describe('X Domain', () => { xScaleType: ScaleType.Linear, yScaleType: ScaleType.Linear, yScaleToDataExtent: false, - data: [{ x: 0, y: 0 }, { x: 1, y: 0 }, { x: 2, y: 0 }, { x: 5, y: 0 }], + data: [ + { x: 0, y: 0 }, + { x: 1, y: 0 }, + { x: 2, y: 0 }, + { x: 5, y: 0 }, + ], }; const ds2: BasicSeriesSpec = { chartType: ChartTypes.XYAxis, @@ -192,7 +197,10 @@ describe('X Domain', () => { xScaleType: ScaleType.Linear, yScaleType: ScaleType.Linear, yScaleToDataExtent: false, - data: [{ x: 0, y: 0 }, { x: 7, y: 0 }], + data: [ + { x: 0, y: 0 }, + { x: 7, y: 0 }, + ], }; const specDataSeries: BasicSeriesSpec[] = [ds1, ds2]; const { xValues } = getSplittedSeries(specDataSeries); @@ -219,7 +227,12 @@ describe('X Domain', () => { xScaleType: ScaleType.Linear, yScaleType: ScaleType.Linear, yScaleToDataExtent: false, - data: [{ x: 0, y: 0 }, { x: 1, y: 0 }, { x: 2, y: 0 }, { x: 5, y: 0 }], + data: [ + { x: 0, y: 0 }, + { x: 1, y: 0 }, + { x: 2, y: 0 }, + { x: 5, y: 0 }, + ], }; const ds2: BasicSeriesSpec = { chartType: ChartTypes.XYAxis, @@ -232,7 +245,10 @@ describe('X Domain', () => { xScaleType: ScaleType.Linear, yScaleType: ScaleType.Linear, yScaleToDataExtent: false, - data: [{ x: 0, y: 0 }, { x: 7, y: 0 }], + data: [ + { x: 0, y: 0 }, + { x: 7, y: 0 }, + ], }; const specDataSeries = [ds1, ds2]; @@ -260,7 +276,12 @@ describe('X Domain', () => { xScaleType: ScaleType.Linear, yScaleType: ScaleType.Linear, yScaleToDataExtent: false, - data: [{ x: 0, y: 0 }, { x: 1, y: 0 }, { x: 2, y: 0 }, { x: 5, y: 0 }], + data: [ + { x: 0, y: 0 }, + { x: 1, y: 0 }, + { x: 2, y: 0 }, + { x: 5, y: 0 }, + ], }; const ds2: BasicSeriesSpec = { chartType: ChartTypes.XYAxis, @@ -273,7 +294,10 @@ describe('X Domain', () => { xScaleType: ScaleType.Linear, yScaleType: ScaleType.Linear, yScaleToDataExtent: false, - data: [{ x: 0, y: 0 }, { x: 7, y: 0 }], + data: [ + { x: 0, y: 0 }, + { x: 7, y: 0 }, + ], }; const specDataSeries = [ds1, ds2]; @@ -305,7 +329,12 @@ describe('X Domain', () => { xScaleType: ScaleType.Linear, yScaleType: ScaleType.Linear, yScaleToDataExtent: false, - data: [{ x: 0, y: 0 }, { x: 1, y: 0 }, { x: 2, y: 0 }, { x: 5, y: 0 }], + data: [ + { x: 0, y: 0 }, + { x: 1, y: 0 }, + { x: 2, y: 0 }, + { x: 5, y: 0 }, + ], }; const ds2: BasicSeriesSpec = { chartType: ChartTypes.XYAxis, @@ -318,7 +347,10 @@ describe('X Domain', () => { xScaleType: ScaleType.Linear, yScaleType: ScaleType.Linear, yScaleToDataExtent: false, - data: [{ x: 0, y: 0 }, { x: 7, y: 0 }], + data: [ + { x: 0, y: 0 }, + { x: 7, y: 0 }, + ], }; const specDataSeries = [ds1, ds2]; @@ -350,7 +382,12 @@ describe('X Domain', () => { xScaleType: ScaleType.Linear, yScaleType: ScaleType.Linear, yScaleToDataExtent: false, - data: [{ x: 0, y: 0 }, { x: 1, y: 0 }, { x: 2, y: 0 }, { x: 5, y: 0 }], + data: [ + { x: 0, y: 0 }, + { x: 1, y: 0 }, + { x: 2, y: 0 }, + { x: 5, y: 0 }, + ], }; const ds2: BasicSeriesSpec = { chartType: ChartTypes.XYAxis, @@ -363,7 +400,10 @@ describe('X Domain', () => { xScaleType: ScaleType.Ordinal, yScaleType: ScaleType.Linear, yScaleToDataExtent: false, - data: [{ x: 0, y: 0 }, { x: 7, y: 0 }], + data: [ + { x: 0, y: 0 }, + { x: 7, y: 0 }, + ], }; const specDataSeries = [ds1, ds2]; @@ -395,7 +435,12 @@ describe('X Domain', () => { xScaleType: ScaleType.Linear, yScaleType: ScaleType.Linear, yScaleToDataExtent: false, - data: [{ x: 0, y: 0 }, { x: 1, y: 0 }, { x: 2, y: 0 }, { x: 5, y: 0 }], + data: [ + { x: 0, y: 0 }, + { x: 1, y: 0 }, + { x: 2, y: 0 }, + { x: 5, y: 0 }, + ], }; const ds2: BasicSeriesSpec = { chartType: ChartTypes.XYAxis, @@ -408,7 +453,10 @@ describe('X Domain', () => { xScaleType: ScaleType.Ordinal, yScaleType: ScaleType.Linear, yScaleToDataExtent: false, - data: [{ x: 0, y: 0 }, { x: 7, y: 0 }], + data: [ + { x: 0, y: 0 }, + { x: 7, y: 0 }, + ], }; const specDataSeries = [ds1, ds2]; @@ -440,7 +488,12 @@ describe('X Domain', () => { xScaleType: ScaleType.Ordinal, yScaleType: ScaleType.Linear, yScaleToDataExtent: false, - data: [{ x: 0, y: 0 }, { x: 1, y: 0 }, { x: 2, y: 0 }, { x: 5, y: 0 }], + data: [ + { x: 0, y: 0 }, + { x: 1, y: 0 }, + { x: 2, y: 0 }, + { x: 5, y: 0 }, + ], }; const ds2: BasicSeriesSpec = { chartType: ChartTypes.XYAxis, @@ -453,7 +506,10 @@ describe('X Domain', () => { xScaleType: ScaleType.Time, yScaleType: ScaleType.Linear, yScaleToDataExtent: false, - data: [{ x: 0, y: 0 }, { x: 7, y: 0 }], + data: [ + { x: 0, y: 0 }, + { x: 7, y: 0 }, + ], }; const specDataSeries = [ds1, ds2]; @@ -485,7 +541,12 @@ describe('X Domain', () => { xScaleType: ScaleType.Ordinal, yScaleType: ScaleType.Linear, yScaleToDataExtent: false, - data: [{ x: 0, y: 0 }, { x: 1, y: 0 }, { x: 2, y: 0 }, { x: 5, y: 0 }], + data: [ + { x: 0, y: 0 }, + { x: 1, y: 0 }, + { x: 2, y: 0 }, + { x: 5, y: 0 }, + ], }; const ds2: BasicSeriesSpec = { chartType: ChartTypes.XYAxis, @@ -498,7 +559,10 @@ describe('X Domain', () => { xScaleType: ScaleType.Linear, yScaleType: ScaleType.Linear, yScaleToDataExtent: false, - data: [{ x: 0, y: 0 }, { x: 7, y: 0 }], + data: [ + { x: 0, y: 0 }, + { x: 7, y: 0 }, + ], }; const specDataSeries = [ds1, ds2]; diff --git a/src/chart_types/xy_chart/domains/y_domain.test.ts b/src/chart_types/xy_chart/domains/y_domain.test.ts index 2ae041c187..95c8622dc0 100644 --- a/src/chart_types/xy_chart/domains/y_domain.test.ts +++ b/src/chart_types/xy_chart/domains/y_domain.test.ts @@ -21,7 +21,12 @@ describe('Y Domain', () => { splitAccessors: new Map(), seriesKeys: [''], key: '', - data: [{ x: 1, y1: 2 }, { x: 2, y1: 2 }, { x: 3, y1: 2 }, { x: 4, y1: 5 }], + data: [ + { x: 1, y1: 2 }, + { x: 2, y1: 2 }, + { x: 3, y1: 2 }, + { x: 4, y1: 5 }, + ], }, { specId: 'a', @@ -29,7 +34,10 @@ describe('Y Domain', () => { splitAccessors: new Map(), seriesKeys: [''], key: '', - data: [{ x: 1, y1: 2 }, { x: 4, y1: 7 }], + data: [ + { x: 1, y1: 2 }, + { x: 4, y1: 7 }, + ], }, ]; const specDataSeries = new Map(); @@ -66,7 +74,12 @@ describe('Y Domain', () => { splitAccessors: new Map(), seriesKeys: [''], key: '', - data: [{ x: 1, y1: 2 }, { x: 2, y1: 2 }, { x: 3, y1: 2 }, { x: 4, y1: 5 }], + data: [ + { x: 1, y1: 2 }, + { x: 2, y1: 2 }, + { x: 3, y1: 2 }, + { x: 4, y1: 5 }, + ], }, { specId: 'a', @@ -74,7 +87,10 @@ describe('Y Domain', () => { splitAccessors: new Map(), seriesKeys: [''], key: '', - data: [{ x: 1, y1: 2 }, { x: 4, y1: 7 }], + data: [ + { x: 1, y1: 2 }, + { x: 4, y1: 7 }, + ], }, ]; const dataSeries2: RawDataSeries[] = [ @@ -84,7 +100,12 @@ describe('Y Domain', () => { splitAccessors: new Map(), seriesKeys: [''], key: '', - data: [{ x: 1, y1: 10 }, { x: 2, y1: 10 }, { x: 3, y1: 2 }, { x: 4, y1: 5 }], + data: [ + { x: 1, y1: 10 }, + { x: 2, y1: 10 }, + { x: 3, y1: 2 }, + { x: 4, y1: 5 }, + ], }, ]; const specDataSeries = new Map(); @@ -137,7 +158,12 @@ describe('Y Domain', () => { splitAccessors: new Map(), seriesKeys: [''], key: '', - data: [{ x: 1, y1: 2 }, { x: 2, y1: 2 }, { x: 3, y1: 2 }, { x: 4, y1: 5 }], + data: [ + { x: 1, y1: 2 }, + { x: 2, y1: 2 }, + { x: 3, y1: 2 }, + { x: 4, y1: 5 }, + ], }, { specId: 'a', @@ -145,7 +171,10 @@ describe('Y Domain', () => { splitAccessors: new Map(), seriesKeys: [''], key: '', - data: [{ x: 1, y1: 2 }, { x: 4, y1: 7 }], + data: [ + { x: 1, y1: 2 }, + { x: 4, y1: 7 }, + ], }, ]; const dataSeries2: RawDataSeries[] = [ @@ -155,7 +184,12 @@ describe('Y Domain', () => { splitAccessors: new Map(), seriesKeys: [''], key: '', - data: [{ x: 1, y1: 10 }, { x: 2, y1: 10 }, { x: 3, y1: 2 }, { x: 4, y1: 5 }], + data: [ + { x: 1, y1: 10 }, + { x: 2, y1: 10 }, + { x: 3, y1: 2 }, + { x: 4, y1: 5 }, + ], }, ]; const specDataSeries = new Map(); @@ -201,7 +235,12 @@ describe('Y Domain', () => { splitAccessors: new Map(), seriesKeys: [''], key: '', - data: [{ x: 1, y1: 2 }, { x: 2, y1: 2 }, { x: 3, y1: 2 }, { x: 4, y1: 5 }], + data: [ + { x: 1, y1: 2 }, + { x: 2, y1: 2 }, + { x: 3, y1: 2 }, + { x: 4, y1: 5 }, + ], }, { specId: 'a', @@ -209,7 +248,10 @@ describe('Y Domain', () => { splitAccessors: new Map(), seriesKeys: [''], key: '', - data: [{ x: 1, y1: 2 }, { x: 4, y1: 7 }], + data: [ + { x: 1, y1: 2 }, + { x: 4, y1: 7 }, + ], }, ]; const dataSeries2: RawDataSeries[] = [ @@ -219,7 +261,12 @@ describe('Y Domain', () => { splitAccessors: new Map(), seriesKeys: [''], key: '', - data: [{ x: 1, y1: 10 }, { x: 2, y1: 10 }, { x: 3, y1: 2 }, { x: 4, y1: 5 }], + data: [ + { x: 1, y1: 10 }, + { x: 2, y1: 10 }, + { x: 3, y1: 2 }, + { x: 4, y1: 5 }, + ], }, ]; const specDataSeries = new Map(); @@ -492,7 +539,12 @@ describe('Y Domain', () => { splitAccessors: new Map(), seriesKeys: [''], key: '', - data: [{ x: 1, y1: 2 }, { x: 2, y1: 2 }, { x: 3, y1: 2 }, { x: 4, y1: 5 }], + data: [ + { x: 1, y1: 2 }, + { x: 2, y1: 2 }, + { x: 3, y1: 2 }, + { x: 4, y1: 5 }, + ], }, { specId: 'a', @@ -500,7 +552,10 @@ describe('Y Domain', () => { splitAccessors: new Map(), seriesKeys: [''], key: '', - data: [{ x: 1, y1: 2 }, { x: 4, y1: 7 }], + data: [ + { x: 1, y1: 2 }, + { x: 4, y1: 7 }, + ], }, ]; const specDataSeries = new Map(); @@ -530,7 +585,12 @@ describe('Y Domain', () => { splitAccessors: new Map(), seriesKeys: [''], key: '', - data: [{ x: 1, y1: 2 }, { x: 2, y1: 2 }, { x: 3, y1: 2 }, { x: 4, y1: 5 }], + data: [ + { x: 1, y1: 2 }, + { x: 2, y1: 2 }, + { x: 3, y1: 2 }, + { x: 4, y1: 5 }, + ], }, { specId: 'a', @@ -538,7 +598,10 @@ describe('Y Domain', () => { splitAccessors: new Map(), seriesKeys: [''], key: '', - data: [{ x: 1, y1: 2 }, { x: 4, y1: 7 }], + data: [ + { x: 1, y1: 2 }, + { x: 4, y1: 7 }, + ], }, ]; const specDataSeries = new Map(); @@ -580,7 +643,12 @@ describe('Y Domain', () => { splitAccessors: new Map(), seriesKeys: [''], key: '', - data: [{ x: 1, y1: 2 }, { x: 2, y1: 2 }, { x: 3, y1: 2 }, { x: 4, y1: 5 }], + data: [ + { x: 1, y1: 2 }, + { x: 2, y1: 2 }, + { x: 3, y1: 2 }, + { x: 4, y1: 5 }, + ], }, { specId: 'a', @@ -588,7 +656,10 @@ describe('Y Domain', () => { splitAccessors: new Map(), seriesKeys: [''], key: '', - data: [{ x: 1, y1: 2 }, { x: 4, y1: 7 }], + data: [ + { x: 1, y1: 2 }, + { x: 4, y1: 7 }, + ], }, ]; const specDataSeries = new Map(); @@ -630,7 +701,12 @@ describe('Y Domain', () => { splitAccessors: new Map(), seriesKeys: [''], key: '', - data: [{ x: 1, y1: 2 }, { x: 2, y1: 2 }, { x: 3, y1: 2 }, { x: 4, y1: 5 }], + data: [ + { x: 1, y1: 2 }, + { x: 2, y1: 2 }, + { x: 3, y1: 2 }, + { x: 4, y1: 5 }, + ], }, { specId: 'a', @@ -638,7 +714,10 @@ describe('Y Domain', () => { splitAccessors: new Map(), seriesKeys: [''], key: '', - data: [{ x: 1, y1: 2 }, { x: 4, y1: 7 }], + data: [ + { x: 1, y1: 2 }, + { x: 4, y1: 7 }, + ], }, ]; const specDataSeries = new Map(); @@ -676,7 +755,12 @@ describe('Y Domain', () => { splitAccessors: new Map(), seriesKeys: [''], key: '', - data: [{ x: 1, y1: 2 }, { x: 2, y1: 2 }, { x: 3, y1: 2 }, { x: 4, y1: 5 }], + data: [ + { x: 1, y1: 2 }, + { x: 2, y1: 2 }, + { x: 3, y1: 2 }, + { x: 4, y1: 5 }, + ], }, { specId: 'a', @@ -684,7 +768,10 @@ describe('Y Domain', () => { splitAccessors: new Map(), seriesKeys: [''], key: '', - data: [{ x: 1, y1: 2 }, { x: 4, y1: 7 }], + data: [ + { x: 1, y1: 2 }, + { x: 4, y1: 7 }, + ], }, ]; const specDataSeries = new Map(); @@ -726,7 +813,12 @@ describe('Y Domain', () => { splitAccessors: new Map(), seriesKeys: [''], key: '', - data: [{ x: 1, y1: 2 }, { x: 2, y1: 2 }, { x: 3, y1: 2 }, { x: 4, y1: 5 }], + data: [ + { x: 1, y1: 2 }, + { x: 2, y1: 2 }, + { x: 3, y1: 2 }, + { x: 4, y1: 5 }, + ], }, { specId: 'a', @@ -734,7 +826,10 @@ describe('Y Domain', () => { splitAccessors: new Map(), seriesKeys: [''], key: '', - data: [{ x: 1, y1: 2 }, { x: 4, y1: 7 }], + data: [ + { x: 1, y1: 2 }, + { x: 4, y1: 7 }, + ], }, ]; const specDataSeries = new Map(); @@ -770,7 +865,12 @@ describe('Y Domain', () => { splitAccessors: new Map(), seriesKeys: [''], key: '', - data: [{ x: 1, y1: 2 }, { x: 2, y1: 2 }, { x: 3, y1: 2 }, { x: 4, y1: 5 }], + data: [ + { x: 1, y1: 2 }, + { x: 2, y1: 2 }, + { x: 3, y1: 2 }, + { x: 4, y1: 5 }, + ], }, { specId: 'a', @@ -778,7 +878,10 @@ describe('Y Domain', () => { splitAccessors: new Map(), seriesKeys: [''], key: '', - data: [{ x: 1, y1: 2 }, { x: 4, y1: 7 }], + data: [ + { x: 1, y1: 2 }, + { x: 4, y1: 7 }, + ], }, ]; const dataSeries2: RawDataSeries[] = [ @@ -788,7 +891,12 @@ describe('Y Domain', () => { splitAccessors: new Map(), seriesKeys: [''], key: '', - data: [{ x: 1, y1: 10 }, { x: 2, y1: 10 }, { x: 3, y1: 2 }, { x: 4, y1: 5 }], + data: [ + { x: 1, y1: 10 }, + { x: 2, y1: 10 }, + { x: 3, y1: 2 }, + { x: 4, y1: 5 }, + ], }, ]; const specDataSeries = new Map(); @@ -836,7 +944,12 @@ describe('Y Domain', () => { splitAccessors: new Map(), seriesKeys: [''], key: '', - data: [{ x: 1, y1: 2 }, { x: 2, y1: 2 }, { x: 3, y1: 2 }, { x: 4, y1: 5 }], + data: [ + { x: 1, y1: 2 }, + { x: 2, y1: 2 }, + { x: 3, y1: 2 }, + { x: 4, y1: 5 }, + ], }, { specId: 'a', @@ -844,7 +957,10 @@ describe('Y Domain', () => { splitAccessors: new Map(), seriesKeys: [''], key: '', - data: [{ x: 1, y1: 2 }, { x: 4, y1: 7 }], + data: [ + { x: 1, y1: 2 }, + { x: 4, y1: 7 }, + ], }, ]; const specDataSeries = new Map(); diff --git a/src/chart_types/xy_chart/domains/y_domain.ts b/src/chart_types/xy_chart/domains/y_domain.ts index 5e0fd2a232..cd630c1ed8 100644 --- a/src/chart_types/xy_chart/domains/y_domain.ts +++ b/src/chart_types/xy_chart/domains/y_domain.ts @@ -75,27 +75,32 @@ function mergeYDomainForGroup( let domain: number[]; if (isPercentageStack) { - domain = computeContinuousDataDomain([0, 1], identity); + domain = computeContinuousDataDomain([0, 1], identity, customDomain?.fit); } else { // compute stacked domain const isStackedScaleToExtent = groupSpecs.stacked.some((spec) => { return spec.yScaleToDataExtent; }); const stackedDataSeries = getDataSeriesOnGroup(dataSeries, groupSpecs.stacked); - const stackedDomain = computeYStackedDomain(stackedDataSeries, isStackedScaleToExtent); + const stackedDomain = computeYStackedDomain(stackedDataSeries, isStackedScaleToExtent, customDomain?.fit); // compute non stacked domain const isNonStackedScaleToExtent = groupSpecs.nonStacked.some((spec) => { return spec.yScaleToDataExtent; }); const nonStackedDataSeries = getDataSeriesOnGroup(dataSeries, groupSpecs.nonStacked); - const nonStackedDomain = computeYNonStackedDomain(nonStackedDataSeries, isNonStackedScaleToExtent); + const nonStackedDomain = computeYNonStackedDomain( + nonStackedDataSeries, + isNonStackedScaleToExtent, + customDomain?.fit, + ); // merge stacked and non stacked domain together domain = computeContinuousDataDomain( [...stackedDomain, ...nonStackedDomain], identity, isStackedScaleToExtent || isNonStackedScaleToExtent, + customDomain?.fit, ); const [computedDomainMin, computedDomainMax] = domain; @@ -130,16 +135,17 @@ export function getDataSeriesOnGroup( dataSeries: Map, specs: YBasicSeriesSpec[], ): RawDataSeries[] { - return specs.reduce( - (acc, spec) => { - const ds = dataSeries.get(spec.id) || []; - return [...acc, ...ds]; - }, - [] as RawDataSeries[], - ); + return specs.reduce((acc, spec) => { + const ds = dataSeries.get(spec.id) || []; + return [...acc, ...ds]; + }, [] as RawDataSeries[]); } -function computeYStackedDomain(dataseries: RawDataSeries[], scaleToExtent: boolean): number[] { +function computeYStackedDomain( + dataseries: RawDataSeries[], + scaleToExtent: boolean, + fitToExtent: boolean = false, +): number[] { const stackMap = new Map(); dataseries.forEach((ds, index) => { ds.data.forEach((datum) => { @@ -158,10 +164,10 @@ function computeYStackedDomain(dataseries: RawDataSeries[], scaleToExtent: boole if (dataValues.length === 0) { return []; } - return computeContinuousDataDomain(dataValues, identity, scaleToExtent); + return computeContinuousDataDomain(dataValues, identity, scaleToExtent, fitToExtent); } -function computeYNonStackedDomain(dataseries: RawDataSeries[], scaleToExtent: boolean) { +function computeYNonStackedDomain(dataseries: RawDataSeries[], scaleToExtent: boolean, fitToExtent: boolean = false) { const yValues = new Set(); dataseries.forEach((ds) => { ds.data.forEach((datum) => { @@ -174,7 +180,7 @@ function computeYNonStackedDomain(dataseries: RawDataSeries[], scaleToExtent: bo if (yValues.size === 0) { return []; } - return computeContinuousDataDomain([...yValues.values()], identity, scaleToExtent); + return computeContinuousDataDomain([...yValues.values()], identity, scaleToExtent, fitToExtent); } export function splitSpecsByGroupId(specs: YBasicSeriesSpec[]) { diff --git a/src/chart_types/xy_chart/renderer/canvas/reactive_chart.tsx b/src/chart_types/xy_chart/renderer/canvas/reactive_chart.tsx index c790d5b838..51fd2546f3 100644 --- a/src/chart_types/xy_chart/renderer/canvas/reactive_chart.tsx +++ b/src/chart_types/xy_chart/renderer/canvas/reactive_chart.tsx @@ -353,7 +353,4 @@ const mapStateToProps = (state: GlobalChartState): ReactiveChartStateProps => { }; }; -export const ReactiveChart = connect( - mapStateToProps, - mapDispatchToProps, -)(Chart); +export const ReactiveChart = connect(mapStateToProps, mapDispatchToProps)(Chart); diff --git a/src/chart_types/xy_chart/renderer/canvas/utils/rendering_props_utils.test.ts b/src/chart_types/xy_chart/renderer/canvas/utils/rendering_props_utils.test.ts index 5bf10a1a52..6ed5cd1264 100644 --- a/src/chart_types/xy_chart/renderer/canvas/utils/rendering_props_utils.test.ts +++ b/src/chart_types/xy_chart/renderer/canvas/utils/rendering_props_utils.test.ts @@ -985,7 +985,13 @@ describe('[canvas] Bar Geometries', () => { }); describe('clipRanges', () => { - const clippedRanges: ClippedRanges = [[0, 1], [2, 4], [4, 6], [7, 11], [11, 12]]; + const clippedRanges: ClippedRanges = [ + [0, 1], + [2, 4], + [4, 6], + [7, 11], + [11, 12], + ]; const singleRange: ClippedRanges = [[0, 1]]; const clippings: Clippings = { clipHeight: 111, diff --git a/src/chart_types/xy_chart/rendering/rendering.areas.test.ts b/src/chart_types/xy_chart/rendering/rendering.areas.test.ts index 109bce79ae..f1a6a707ba 100644 --- a/src/chart_types/xy_chart/rendering/rendering.areas.test.ts +++ b/src/chart_types/xy_chart/rendering/rendering.areas.test.ts @@ -20,7 +20,10 @@ describe('Rendering points - areas', () => { groupId: GROUP_ID, seriesType: SeriesTypes.Area, yScaleToDataExtent: false, - data: [[0, 10], [1, 5]], + data: [ + [0, 10], + [1, 5], + ], xAccessor: 0, yAccessors: [1], xScaleType: ScaleType.Ordinal, @@ -75,7 +78,10 @@ describe('Rendering points - areas', () => { groupId: GROUP_ID, seriesType: SeriesTypes.Area, yScaleToDataExtent: false, - data: [[0, 10], [1, 5]], + data: [ + [0, 10], + [1, 5], + ], xAccessor: 0, yAccessors: [1], xScaleType: ScaleType.Ordinal, @@ -184,7 +190,10 @@ describe('Rendering points - areas', () => { groupId: GROUP_ID, seriesType: SeriesTypes.Area, yScaleToDataExtent: false, - data: [[0, 10], [1, 5]], + data: [ + [0, 10], + [1, 5], + ], xAccessor: 0, yAccessors: [1], xScaleType: ScaleType.Ordinal, @@ -197,7 +206,10 @@ describe('Rendering points - areas', () => { groupId: GROUP_ID, seriesType: SeriesTypes.Area, yScaleToDataExtent: false, - data: [[0, 20], [1, 10]], + data: [ + [0, 20], + [1, 10], + ], xAccessor: 0, yAccessors: [1], xScaleType: ScaleType.Ordinal, @@ -378,7 +390,10 @@ describe('Rendering points - areas', () => { groupId: GROUP_ID, seriesType: SeriesTypes.Area, yScaleToDataExtent: false, - data: [[0, 10], [1, 5]], + data: [ + [0, 10], + [1, 5], + ], xAccessor: 0, yAccessors: [1], xScaleType: ScaleType.Linear, @@ -483,7 +498,10 @@ describe('Rendering points - areas', () => { groupId: GROUP_ID, seriesType: SeriesTypes.Area, yScaleToDataExtent: false, - data: [[0, 10], [1, 5]], + data: [ + [0, 10], + [1, 5], + ], xAccessor: 0, yAccessors: [1], xScaleType: ScaleType.Linear, @@ -496,7 +514,10 @@ describe('Rendering points - areas', () => { groupId: GROUP_ID, seriesType: SeriesTypes.Area, yScaleToDataExtent: false, - data: [[0, 20], [1, 10]], + data: [ + [0, 20], + [1, 10], + ], xAccessor: 0, yAccessors: [1], xScaleType: ScaleType.Linear, @@ -676,7 +697,10 @@ describe('Rendering points - areas', () => { groupId: GROUP_ID, seriesType: SeriesTypes.Area, yScaleToDataExtent: false, - data: [[1546300800000, 10], [1546387200000, 5]], + data: [ + [1546300800000, 10], + [1546387200000, 5], + ], xAccessor: 0, yAccessors: [1], xScaleType: ScaleType.Time, @@ -781,7 +805,10 @@ describe('Rendering points - areas', () => { groupId: GROUP_ID, seriesType: SeriesTypes.Area, yScaleToDataExtent: false, - data: [[1546300800000, 10], [1546387200000, 5]], + data: [ + [1546300800000, 10], + [1546387200000, 5], + ], xAccessor: 0, yAccessors: [1], xScaleType: ScaleType.Time, @@ -794,7 +821,10 @@ describe('Rendering points - areas', () => { groupId: GROUP_ID, seriesType: SeriesTypes.Area, yScaleToDataExtent: false, - data: [[1546300800000, 20], [1546387200000, 10]], + data: [ + [1546300800000, 20], + [1546387200000, 10], + ], xAccessor: 0, yAccessors: [1], xScaleType: ScaleType.Time, @@ -959,7 +989,17 @@ describe('Rendering points - areas', () => { groupId: GROUP_ID, seriesType: SeriesTypes.Area, yScaleToDataExtent: false, - data: [[0, 10], [1, 5], [2, null], [3, 5], [4, 5], [5, 0], [6, 10], [7, 10], [8, 10]], + data: [ + [0, 10], + [1, 5], + [2, null], + [3, 5], + [4, 5], + [5, 0], + [6, 10], + [7, 10], + [8, 10], + ], xAccessor: 0, yAccessors: [1], xScaleType: ScaleType.Linear, diff --git a/src/chart_types/xy_chart/rendering/rendering.bands.test.ts b/src/chart_types/xy_chart/rendering/rendering.bands.test.ts index d7036467a7..d9348c4fd3 100644 --- a/src/chart_types/xy_chart/rendering/rendering.bands.test.ts +++ b/src/chart_types/xy_chart/rendering/rendering.bands.test.ts @@ -20,7 +20,10 @@ describe('Rendering bands - areas', () => { groupId: GROUP_ID, seriesType: SeriesTypes.Area, yScaleToDataExtent: false, - data: [[0, 2, 10], [1, 3, 5]], + data: [ + [0, 2, 10], + [1, 3, 5], + ], xAccessor: 0, y0Accessors: [1], yAccessors: [2], @@ -73,7 +76,10 @@ describe('Rendering bands - areas', () => { groupId: GROUP_ID, seriesType: SeriesTypes.Area, yScaleToDataExtent: false, - data: [[0, 2, 10], [1, 3, 5]], + data: [ + [0, 2, 10], + [1, 3, 5], + ], xAccessor: 0, y0Accessors: [1], yAccessors: [2], @@ -228,7 +234,12 @@ describe('Rendering bands - areas', () => { groupId: GROUP_ID, seriesType: SeriesTypes.Area, yScaleToDataExtent: false, - data: [[0, 2, 10], [1, 2, null], [2, 3, 5], [3, 3, 5]], + data: [ + [0, 2, 10], + [1, 2, null], + [2, 3, 5], + [3, 3, 5], + ], xAccessor: 0, y0Accessors: [1], yAccessors: [2], @@ -424,7 +435,12 @@ describe('Rendering bands - areas', () => { groupId: GROUP_ID, seriesType: SeriesTypes.Bar, yScaleToDataExtent: false, - data: [[0, 2, 10], [1, 3, null], [2, 3, 5], [3, 4, 8]], + data: [ + [0, 2, 10], + [1, 3, null], + [2, 3, 5], + [3, 4, 8], + ], xAccessor: 0, y0Accessors: [1], yAccessors: [2], diff --git a/src/chart_types/xy_chart/rendering/rendering.bars.test.ts b/src/chart_types/xy_chart/rendering/rendering.bars.test.ts index 4032752088..685df20461 100644 --- a/src/chart_types/xy_chart/rendering/rendering.bars.test.ts +++ b/src/chart_types/xy_chart/rendering/rendering.bars.test.ts @@ -20,7 +20,11 @@ describe('Rendering bars', () => { groupId: GROUP_ID, seriesType: SeriesTypes.Bar, yScaleToDataExtent: false, - data: [[-200, 0], [0, 10], [1, 5]], // first datum should be skipped as it's out of domain + data: [ + [-200, 0], + [0, 10], + [1, 5], + ], // first datum should be skipped as it's out of domain xAccessor: 0, yAccessors: [1], xScaleType: ScaleType.Ordinal, @@ -190,7 +194,10 @@ describe('Rendering bars', () => { groupId: GROUP_ID, seriesType: SeriesTypes.Bar, yScaleToDataExtent: false, - data: [[0, 10], [1, 5]], + data: [ + [0, 10], + [1, 5], + ], xAccessor: 0, yAccessors: [1], xScaleType: ScaleType.Ordinal, @@ -203,7 +210,10 @@ describe('Rendering bars', () => { groupId: GROUP_ID, seriesType: SeriesTypes.Bar, yScaleToDataExtent: false, - data: [[0, 20], [1, 10]], + data: [ + [0, 20], + [1, 10], + ], xAccessor: 0, yAccessors: [1], xScaleType: ScaleType.Ordinal, @@ -401,7 +411,10 @@ describe('Rendering bars', () => { groupId: GROUP_ID, seriesType: SeriesTypes.Bar, yScaleToDataExtent: false, - data: [[0, 10], [1, 5]], + data: [ + [0, 10], + [1, 5], + ], xAccessor: 0, yAccessors: [1], xScaleType: ScaleType.Linear, @@ -511,7 +524,14 @@ describe('Rendering bars', () => { groupId: GROUP_ID, seriesType: SeriesTypes.Bar, yScaleToDataExtent: false, - data: [[1, 0], [2, 1], [3, 2], [4, 3], [5, 4], [6, 5]], + data: [ + [1, 0], + [2, 1], + [3, 2], + [4, 3], + [5, 4], + [6, 5], + ], xAccessor: 0, yAccessors: [1], xScaleType: ScaleType.Linear, @@ -551,7 +571,10 @@ describe('Rendering bars', () => { groupId: GROUP_ID, seriesType: SeriesTypes.Bar, yScaleToDataExtent: false, - data: [[0, 10], [1, 5]], + data: [ + [0, 10], + [1, 5], + ], xAccessor: 0, yAccessors: [1], xScaleType: ScaleType.Linear, @@ -564,7 +587,10 @@ describe('Rendering bars', () => { groupId: GROUP_ID, seriesType: SeriesTypes.Bar, yScaleToDataExtent: false, - data: [[0, 20], [1, 10]], + data: [ + [0, 20], + [1, 10], + ], xAccessor: 0, yAccessors: [1], xScaleType: ScaleType.Linear, @@ -764,7 +790,10 @@ describe('Rendering bars', () => { groupId: GROUP_ID, seriesType: SeriesTypes.Bar, yScaleToDataExtent: false, - data: [[1546300800000, 10], [1546387200000, 5]], + data: [ + [1546300800000, 10], + [1546387200000, 5], + ], xAccessor: 0, yAccessors: [1], xScaleType: ScaleType.Time, @@ -777,7 +806,10 @@ describe('Rendering bars', () => { groupId: GROUP_ID, seriesType: SeriesTypes.Bar, yScaleToDataExtent: false, - data: [[1546300800000, 20], [1546387200000, 10]], + data: [ + [1546300800000, 20], + [1546387200000, 10], + ], xAccessor: 0, yAccessors: [1], xScaleType: ScaleType.Time, @@ -975,7 +1007,12 @@ describe('Rendering bars', () => { groupId: GROUP_ID, seriesType: SeriesTypes.Bar, yScaleToDataExtent: false, - data: [[0, 0], [1, 1], [2, 10], [3, 3]], + data: [ + [0, 0], + [1, 1], + [2, 10], + [3, 3], + ], xAccessor: 0, yAccessors: [1], xScaleType: ScaleType.Linear, diff --git a/src/chart_types/xy_chart/rendering/rendering.lines.test.ts b/src/chart_types/xy_chart/rendering/rendering.lines.test.ts index 85ecc37b8d..c8035bfdc5 100644 --- a/src/chart_types/xy_chart/rendering/rendering.lines.test.ts +++ b/src/chart_types/xy_chart/rendering/rendering.lines.test.ts @@ -21,7 +21,10 @@ describe('Rendering points - line', () => { groupId: GROUP_ID, seriesType: SeriesTypes.Line, yScaleToDataExtent: false, - data: [[0, 10], [1, 5]], + data: [ + [0, 10], + [1, 5], + ], xAccessor: 0, yAccessors: [1], xScaleType: ScaleType.Ordinal, @@ -70,7 +73,10 @@ describe('Rendering points - line', () => { groupId: GROUP_ID, seriesType: SeriesTypes.Line, yScaleToDataExtent: false, - data: [[0, 10], [1, 5]], + data: [ + [0, 10], + [1, 5], + ], xAccessor: 0, yAccessors: [1], xScaleType: ScaleType.Ordinal, @@ -174,7 +180,10 @@ describe('Rendering points - line', () => { groupId: GROUP_ID, seriesType: SeriesTypes.Line, yScaleToDataExtent: false, - data: [[0, 10], [1, 5]], + data: [ + [0, 10], + [1, 5], + ], xAccessor: 0, yAccessors: [1], xScaleType: ScaleType.Ordinal, @@ -187,7 +196,10 @@ describe('Rendering points - line', () => { groupId: GROUP_ID, seriesType: SeriesTypes.Line, yScaleToDataExtent: false, - data: [[0, 20], [1, 10]], + data: [ + [0, 20], + [1, 10], + ], xAccessor: 0, yAccessors: [1], xScaleType: ScaleType.Ordinal, @@ -362,7 +374,10 @@ describe('Rendering points - line', () => { groupId: GROUP_ID, seriesType: SeriesTypes.Line, yScaleToDataExtent: false, - data: [[0, 10], [1, 5]], + data: [ + [0, 10], + [1, 5], + ], xAccessor: 0, yAccessors: [1], xScaleType: ScaleType.Linear, @@ -464,7 +479,10 @@ describe('Rendering points - line', () => { groupId: GROUP_ID, seriesType: SeriesTypes.Line, yScaleToDataExtent: false, - data: [[0, 10], [1, 5]], + data: [ + [0, 10], + [1, 5], + ], xAccessor: 0, yAccessors: [1], xScaleType: ScaleType.Linear, @@ -477,7 +495,10 @@ describe('Rendering points - line', () => { groupId: GROUP_ID, seriesType: SeriesTypes.Line, yScaleToDataExtent: false, - data: [[0, 20], [1, 10]], + data: [ + [0, 20], + [1, 10], + ], xAccessor: 0, yAccessors: [1], xScaleType: ScaleType.Linear, @@ -651,7 +672,10 @@ describe('Rendering points - line', () => { groupId: GROUP_ID, seriesType: SeriesTypes.Line, yScaleToDataExtent: false, - data: [[1546300800000, 10], [1546387200000, 5]], + data: [ + [1546300800000, 10], + [1546387200000, 5], + ], xAccessor: 0, yAccessors: [1], xScaleType: ScaleType.Time, @@ -753,7 +777,10 @@ describe('Rendering points - line', () => { groupId: GROUP_ID, seriesType: SeriesTypes.Line, yScaleToDataExtent: false, - data: [[1546300800000, 10], [1546387200000, 5]], + data: [ + [1546300800000, 10], + [1546387200000, 5], + ], xAccessor: 0, yAccessors: [1], xScaleType: ScaleType.Time, @@ -766,7 +793,10 @@ describe('Rendering points - line', () => { groupId: GROUP_ID, seriesType: SeriesTypes.Line, yScaleToDataExtent: false, - data: [[1546300800000, 20], [1546387200000, 10]], + data: [ + [1546300800000, 20], + [1546387200000, 10], + ], xAccessor: 0, yAccessors: [1], xScaleType: ScaleType.Time, @@ -927,7 +957,17 @@ describe('Rendering points - line', () => { groupId: GROUP_ID, seriesType: SeriesTypes.Line, yScaleToDataExtent: false, - data: [[0, 10], [1, 5], [2, null], [3, 5], [4, 5], [5, 0], [6, 10], [7, 10], [8, 10]], + data: [ + [0, 10], + [1, 5], + [2, null], + [3, 5], + [4, 5], + [5, 0], + [6, 10], + [7, 10], + [8, 10], + ], xAccessor: 0, yAccessors: [1], xScaleType: ScaleType.Linear, @@ -997,7 +1037,12 @@ describe('Rendering points - line', () => { groupId: GROUP_ID, seriesType: SeriesTypes.Line, yScaleToDataExtent: false, - data: [[0, 0], [1, 1], [2, 10], [3, 3]], + data: [ + [0, 0], + [1, 1], + [2, 10], + [3, 3], + ], xAccessor: 0, yAccessors: [1], xScaleType: ScaleType.Linear, diff --git a/src/chart_types/xy_chart/rendering/rendering.test.ts b/src/chart_types/xy_chart/rendering/rendering.test.ts index 1280e22ad3..3cd4abc0ef 100644 --- a/src/chart_types/xy_chart/rendering/rendering.test.ts +++ b/src/chart_types/xy_chart/rendering/rendering.test.ts @@ -367,7 +367,13 @@ describe('Rendering utils', () => { it('should return array pairs of non-null x regions with null end values', () => { const actual = getClippedRanges(dataSeries.data, xScale, 0); - expect(actual).toEqual([[0, 1], [2, 4], [4, 6], [7, 11], [11, 12]]); + expect(actual).toEqual([ + [0, 1], + [2, 4], + [4, 6], + [7, 11], + [11, 12], + ]); }); it('should return array pairs of non-null x regions with valid end values', () => { @@ -378,7 +384,11 @@ describe('Rendering utils', () => { }); const actual = getClippedRanges(data, xScale, 0); - expect(actual).toEqual([[2, 4], [4, 6], [7, 11]]); + expect(actual).toEqual([ + [2, 4], + [4, 6], + [7, 11], + ]); }); it('should account for bandwidth', () => { @@ -390,13 +400,23 @@ describe('Rendering utils', () => { }); const actual = getClippedRanges(dataSeries.data, xScale, 0); - expect(actual).toEqual([[0, 2], [3, 5], [5, 7], [8, 12]]); + expect(actual).toEqual([ + [0, 2], + [3, 5], + [5, 7], + [8, 12], + ]); }); it('should account for xScaleOffset', () => { const actual = getClippedRanges(dataSeries.data, xScale, 2); - expect(actual).toEqual([[0, -1], [0, 2], [2, 4], [5, 9]]); + expect(actual).toEqual([ + [0, -1], + [0, 2], + [2, 4], + [5, 9], + ]); }); it('should call scale to get x value for each datum', () => { diff --git a/src/chart_types/xy_chart/rendering/rendering.ts b/src/chart_types/xy_chart/rendering/rendering.ts index 6a387c64b8..a30aae9bef 100644 --- a/src/chart_types/xy_chart/rendering/rendering.ts +++ b/src/chart_types/xy_chart/rendering/rendering.ts @@ -101,68 +101,65 @@ function renderPoints( } { const indexedGeometries: Map = new Map(); const isLogScale = isLogarithmicScale(yScale); - const pointGeometries = dataSeries.data.reduce( - (acc, datum) => { - const { x: xValue, y0, y1, initialY0, initialY1, filled } = datum; - // don't create the point if not within the xScale domain or it that point was filled - if (!xScale.isValueInDomain(xValue) || (filled && filled.y1 !== undefined)) { - return acc; + const pointGeometries = dataSeries.data.reduce((acc, datum) => { + const { x: xValue, y0, y1, initialY0, initialY1, filled } = datum; + // don't create the point if not within the xScale domain or it that point was filled + if (!xScale.isValueInDomain(xValue) || (filled && filled.y1 !== undefined)) { + return acc; + } + const x = xScale.scale(xValue); + const points: PointGeometry[] = []; + const yDatums = hasY0Accessors ? [y0, y1] : [y1]; + + yDatums.forEach((yDatum, index) => { + // skip rendering point if y1 is null + if (y1 === null) { + return; } - const x = xScale.scale(xValue); - const points: PointGeometry[] = []; - const yDatums = hasY0Accessors ? [y0, y1] : [y1]; - - yDatums.forEach((yDatum, index) => { - // skip rendering point if y1 is null - if (y1 === null) { - return; - } - let y; - let radius = 10; - // we fix 0 and negative values at y = 0 - if (yDatum === null || (isLogScale && yDatum <= 0)) { - y = yScale.range[0]; - radius = 0; - } else { - y = yScale.scale(yDatum); - } - const originalY = hasY0Accessors && index === 0 ? initialY0 : initialY1; - const seriesIdentifier: SeriesIdentifier = { - key: dataSeries.key, - specId: dataSeries.specId, - yAccessor: dataSeries.yAccessor, - splitAccessors: dataSeries.splitAccessors, - seriesKeys: dataSeries.seriesKeys, - }; - const styleOverrides = getPointStyleOverrides(datum, seriesIdentifier, styleAccessor); - const pointGeometry: PointGeometry = { - radius, - x, - y, - color, - value: { - x: xValue, - y: originalY, - accessor: hasY0Accessors && index === 0 ? BandedAccessorType.Y0 : BandedAccessorType.Y1, - }, - transform: { - x: shift, - y: 0, - }, - seriesIdentifier, - styleOverrides, - }; - mutableIndexedGeometryMapUpsert(indexedGeometries, xValue, pointGeometry); - // use the geometry only if the yDatum in contained in the current yScale domain - const isHidden = yDatum === null || (isLogScale && yDatum <= 0); - if (!isHidden && yScale.isValueInDomain(yDatum)) { - points.push(pointGeometry); - } - }); - return [...acc, ...points]; - }, - [] as PointGeometry[], - ); + let y; + let radius = 10; + // we fix 0 and negative values at y = 0 + if (yDatum === null || (isLogScale && yDatum <= 0)) { + y = yScale.range[0]; + radius = 0; + } else { + y = yScale.scale(yDatum); + } + const originalY = hasY0Accessors && index === 0 ? initialY0 : initialY1; + const seriesIdentifier: SeriesIdentifier = { + key: dataSeries.key, + specId: dataSeries.specId, + yAccessor: dataSeries.yAccessor, + splitAccessors: dataSeries.splitAccessors, + seriesKeys: dataSeries.seriesKeys, + }; + const styleOverrides = getPointStyleOverrides(datum, seriesIdentifier, styleAccessor); + const pointGeometry: PointGeometry = { + radius, + x, + y, + color, + value: { + x: xValue, + y: originalY, + accessor: hasY0Accessors && index === 0 ? BandedAccessorType.Y0 : BandedAccessorType.Y1, + }, + transform: { + x: shift, + y: 0, + }, + seriesIdentifier, + styleOverrides, + }; + mutableIndexedGeometryMapUpsert(indexedGeometries, xValue, pointGeometry); + // use the geometry only if the yDatum in contained in the current yScale domain + const isHidden = yDatum === null || (isLogScale && yDatum <= 0); + if (!isHidden && yScale.isValueInDomain(yDatum)) { + points.push(pointGeometry); + } + }); + return [...acc, ...points]; + }, [] as PointGeometry[]); return { pointGeometries, indexedGeometries, diff --git a/src/chart_types/xy_chart/state/chart_state.interactions.test.ts b/src/chart_types/xy_chart/state/chart_state.interactions.test.ts index dcdb0954e6..b36cc440f8 100644 --- a/src/chart_types/xy_chart/state/chart_state.interactions.test.ts +++ b/src/chart_types/xy_chart/state/chart_state.interactions.test.ts @@ -32,7 +32,10 @@ const ordinalBarSeries: BarSeriesSpec = { groupId: GROUP_ID, seriesType: SeriesTypes.Bar, yScaleToDataExtent: false, - data: [[0, 10], [1, 5]], + data: [ + [0, 10], + [1, 5], + ], xAccessor: 0, yAccessors: [1], xScaleType: ScaleType.Ordinal, @@ -46,7 +49,10 @@ const linearBarSeries: BarSeriesSpec = { groupId: GROUP_ID, seriesType: SeriesTypes.Bar, yScaleToDataExtent: false, - data: [[0, 10], [1, 5]], + data: [ + [0, 10], + [1, 5], + ], xAccessor: 0, yAccessors: [1], xScaleType: ScaleType.Linear, diff --git a/src/chart_types/xy_chart/state/chart_state.test.ts b/src/chart_types/xy_chart/state/chart_state.test.ts index 76e8584e6a..e12ceda857 100644 --- a/src/chart_types/xy_chart/state/chart_state.test.ts +++ b/src/chart_types/xy_chart/state/chart_state.test.ts @@ -36,7 +36,11 @@ describe.skip('Chart Store', () => { groupId: GROUP_ID, seriesType: SeriesTypes.Bar, yScaleToDataExtent: false, - data: [{ x: 1, y: 1, g: 0 }, { x: 2, y: 2, g: 1 }, { x: 3, y: 3, g: 3 }], + data: [ + { x: 1, y: 1, g: 0 }, + { x: 2, y: 2, g: 1 }, + { x: 3, y: 3, g: 3 }, + ], xAccessor: 'x', yAccessors: ['y'], xScaleType: ScaleType.Linear, @@ -286,7 +290,10 @@ describe.skip('Chart Store', () => { }); test.skip('can get highlighted legend item', () => { - store.legendItems = new Map([[firstLegendItem.key, firstLegendItem], [secondLegendItem.key, secondLegendItem]]); + store.legendItems = new Map([ + [firstLegendItem.key, firstLegendItem], + [secondLegendItem.key, secondLegendItem], + ]); store.highlightedLegendItemKey.set(null); expect(store.highlightedLegendItem.get()).toBe(null); @@ -296,13 +303,14 @@ describe.skip('Chart Store', () => { }); test.skip('can respond to legend item mouseover event', () => { - const legendListener = jest.fn( - (): void => { - return; - }, - ); + const legendListener = jest.fn((): void => { + return; + }); - store.legendItems = new Map([[firstLegendItem.key, firstLegendItem], [secondLegendItem.key, secondLegendItem]]); + store.legendItems = new Map([ + [firstLegendItem.key, firstLegendItem], + [secondLegendItem.key, secondLegendItem], + ]); store.highlightedLegendItemKey.set(null); store.onLegendItemOver(firstLegendItem.key); @@ -337,14 +345,15 @@ describe.skip('Chart Store', () => { }); test.skip('do nothing when mouseover an hidden series', () => { - const legendListener = jest.fn( - (): void => { - return; - }, - ); + const legendListener = jest.fn((): void => { + return; + }); store.setOnLegendItemOverListener(legendListener); - store.legendItems = new Map([[firstLegendItem.key, firstLegendItem], [secondLegendItem.key, secondLegendItem]]); + store.legendItems = new Map([ + [firstLegendItem.key, firstLegendItem], + [secondLegendItem.key, secondLegendItem], + ]); store.deselectedDataSeries = []; store.highlightedLegendItemKey.set(null); @@ -365,13 +374,14 @@ describe.skip('Chart Store', () => { }); test.skip('can respond to legend item click event', () => { - const legendListener = jest.fn( - (): void => { - return; - }, - ); + const legendListener = jest.fn((): void => { + return; + }); - store.legendItems = new Map([[firstLegendItem.key, firstLegendItem], [secondLegendItem.key, secondLegendItem]]); + store.legendItems = new Map([ + [firstLegendItem.key, firstLegendItem], + [secondLegendItem.key, secondLegendItem], + ]); store.selectedLegendItemKey.set(null); store.onLegendItemClickListener = undefined; @@ -393,13 +403,14 @@ describe.skip('Chart Store', () => { }); test.skip('can respond to a legend item plus click event', () => { - const legendListener = jest.fn( - (): void => { - return; - }, - ); + const legendListener = jest.fn((): void => { + return; + }); - store.legendItems = new Map([[firstLegendItem.key, firstLegendItem], [secondLegendItem.key, secondLegendItem]]); + store.legendItems = new Map([ + [firstLegendItem.key, firstLegendItem], + [secondLegendItem.key, secondLegendItem], + ]); store.selectedLegendItemKey.set(null); store.onLegendItemPlusClickListener = undefined; @@ -416,13 +427,14 @@ describe.skip('Chart Store', () => { }); test.skip('can respond to a legend item minus click event', () => { - const legendListener = jest.fn( - (): void => { - return; - }, - ); + const legendListener = jest.fn((): void => { + return; + }); - store.legendItems = new Map([[firstLegendItem.key, firstLegendItem], [secondLegendItem.key, secondLegendItem]]); + store.legendItems = new Map([ + [firstLegendItem.key, firstLegendItem], + [secondLegendItem.key, secondLegendItem], + ]); store.selectedLegendItemKey.set(null); store.onLegendItemMinusClickListener = undefined; @@ -439,13 +451,14 @@ describe.skip('Chart Store', () => { }); test.skip('can toggle series visibility', () => { - const computeChart = jest.fn( - (): void => { - return; - }, - ); + const computeChart = jest.fn((): void => { + return; + }); - store.legendItems = new Map([[firstLegendItem.key, firstLegendItem], [secondLegendItem.key, secondLegendItem]]); + store.legendItems = new Map([ + [firstLegendItem.key, firstLegendItem], + [secondLegendItem.key, secondLegendItem], + ]); store.deselectedDataSeries = []; store.computeChart = computeChart; @@ -464,13 +477,14 @@ describe.skip('Chart Store', () => { }); test.skip('can toggle single series visibility', () => { - const computeChart = jest.fn( - (): void => { - return; - }, - ); + const computeChart = jest.fn((): void => { + return; + }); - store.legendItems = new Map([[firstLegendItem.key, firstLegendItem], [secondLegendItem.key, secondLegendItem]]); + store.legendItems = new Map([ + [firstLegendItem.key, firstLegendItem], + [secondLegendItem.key, secondLegendItem], + ]); store.deselectedDataSeries = []; store.computeChart = computeChart; @@ -566,11 +580,9 @@ describe.skip('Chart Store', () => { }); test.skip('can respond to a brush end event', () => { - const brushEndListener = jest.fn( - (): void => { - return; - }, - ); + const brushEndListener = jest.fn((): void => { + return; + }); const start1 = { x: 0, y: 0 }; const start2 = { x: 100, y: 0 }; @@ -611,11 +623,9 @@ describe.skip('Chart Store', () => { }); test.skip('can update parent dimensions', () => { - const computeChart = jest.fn( - (): void => { - return; - }, - ); + const computeChart = jest.fn((): void => { + return; + }); store.computeChart = computeChart; store.parentDimensions = { @@ -756,7 +766,10 @@ describe.skip('Chart Store', () => { test.skip('can set the color for a series', () => { beforeEach(() => { store.computeChart = jest.fn(); - store.legendItems = new Map([[firstLegendItem.key, firstLegendItem], [secondLegendItem.key, secondLegendItem]]); + store.legendItems = new Map([ + [firstLegendItem.key, firstLegendItem], + [secondLegendItem.key, secondLegendItem], + ]); }); it('should set color override', () => { @@ -885,13 +898,14 @@ describe.skip('Chart Store', () => { }); test.skip('should update cursor postion with hover event', () => { - const legendListener = jest.fn( - (): void => { - return; - }, - ); + const legendListener = jest.fn((): void => { + return; + }); - store.legendItems = new Map([[firstLegendItem.key, firstLegendItem], [secondLegendItem.key, secondLegendItem]]); + store.legendItems = new Map([ + [firstLegendItem.key, firstLegendItem], + [secondLegendItem.key, secondLegendItem], + ]); store.selectedLegendItemKey.set(null); store.onCursorUpdateListener = undefined; @@ -1004,11 +1018,9 @@ describe.skip('Chart Store', () => { height: 0, seriesStyle: barStyle, }; - const clickListener = jest.fn( - (): void => { - return; - }, - ); + const clickListener = jest.fn((): void => { + return; + }); store.setOnElementClickListener(clickListener); store.highlightedGeometries.replace([]); diff --git a/src/chart_types/xy_chart/state/chart_state.timescales.test.ts b/src/chart_types/xy_chart/state/chart_state.timescales.test.ts index a6fbc1368c..58daa52a46 100644 --- a/src/chart_types/xy_chart/state/chart_state.timescales.test.ts +++ b/src/chart_types/xy_chart/state/chart_state.timescales.test.ts @@ -34,7 +34,11 @@ describe('Render chart', () => { yScaleType: ScaleType.Linear, xAccessor: 0, yAccessors: [1], - data: [[day1, 10], [day2, 22], [day3, 6]], + data: [ + [day1, 10], + [day2, 22], + [day3, 6], + ], yScaleToDataExtent: false, }; store.dispatch(upsertSpec(lineSeries)); @@ -100,7 +104,11 @@ describe('Render chart', () => { yScaleType: ScaleType.Linear, xAccessor: 0, yAccessors: [1], - data: [[date1, 10], [date2, 22], [date3, 6]], + data: [ + [date1, 10], + [date2, 22], + [date3, 6], + ], yScaleToDataExtent: false, }; store.dispatch(upsertSpec(lineSeries)); @@ -164,7 +172,11 @@ describe('Render chart', () => { yScaleType: ScaleType.Linear, xAccessor: 0, yAccessors: [1], - data: [[date1, 10], [date2, 22], [date3, 6]], + data: [ + [date1, 10], + [date2, 22], + [date3, 6], + ], yScaleToDataExtent: false, }; store.dispatch(upsertSpec(lineSeries)); diff --git a/src/chart_types/xy_chart/state/chart_state.tooltip.test.ts b/src/chart_types/xy_chart/state/chart_state.tooltip.test.ts index a1d27bbf3d..b03d06915e 100644 --- a/src/chart_types/xy_chart/state/chart_state.tooltip.test.ts +++ b/src/chart_types/xy_chart/state/chart_state.tooltip.test.ts @@ -12,7 +12,16 @@ describe('XYChart - State tooltips', () => { beforeEach(() => { const storeReducer = chartStoreReducer('chartId'); store = createStore(storeReducer); - store.dispatch(upsertSpec(MockSeriesSpec.bar({ data: [{ x: 1, y: 10 }, { x: 2, y: 5 }] }))); + store.dispatch( + upsertSpec( + MockSeriesSpec.bar({ + data: [ + { x: 1, y: 10 }, + { x: 2, y: 5 }, + ], + }), + ), + ); store.dispatch(upsertSpec(MockGlobalSpec.settings())); store.dispatch(specParsed()); store.dispatch(updateParentDimensions({ width: 100, height: 100, top: 0, left: 0 })); diff --git a/src/chart_types/xy_chart/state/selectors/get_cursor_band.ts b/src/chart_types/xy_chart/state/selectors/get_cursor_band.ts index 48d57d64a8..d708da0ab6 100644 --- a/src/chart_types/xy_chart/state/selectors/get_cursor_band.ts +++ b/src/chart_types/xy_chart/state/selectors/get_cursor_band.ts @@ -67,7 +67,7 @@ function getCursorBand( totalBarsInCluster: number, isTooltipSnapEnabled: boolean, geometriesIndexKeys: any[], -): Dimensions & { visible: boolean } | undefined { +): (Dimensions & { visible: boolean }) | undefined { // update che cursorBandPosition based on chart configuration const isLineAreaOnly = isLineAreaOnlyChart(seriesSpecs); if (!xScale) { diff --git a/src/chart_types/xy_chart/state/selectors/get_specs.ts b/src/chart_types/xy_chart/state/selectors/get_specs.ts index 2d7eb779bc..b53016a6f5 100644 --- a/src/chart_types/xy_chart/state/selectors/get_specs.ts +++ b/src/chart_types/xy_chart/state/selectors/get_specs.ts @@ -7,12 +7,9 @@ import { ChartTypes } from '../../..'; const getSpecs = (state: GlobalChartState) => state.specs; -export const getAxisSpecsSelector = createCachedSelector( - [getSpecs], - (specs): AxisSpec[] => { - return getSpecsFromStore(specs, ChartTypes.XYAxis, SpecTypes.Axis); - }, -)(getChartIdSelector); +export const getAxisSpecsSelector = createCachedSelector([getSpecs], (specs): AxisSpec[] => { + return getSpecsFromStore(specs, ChartTypes.XYAxis, SpecTypes.Axis); +})(getChartIdSelector); export const getSeriesSpecsSelector = createCachedSelector([getSpecs], (specs) => { const seriesSpec = getSpecsFromStore(specs, ChartTypes.XYAxis, SpecTypes.Series); diff --git a/src/chart_types/xy_chart/state/selectors/get_tooltip_snap.ts b/src/chart_types/xy_chart/state/selectors/get_tooltip_snap.ts index 341f27284c..534ec2b033 100644 --- a/src/chart_types/xy_chart/state/selectors/get_tooltip_snap.ts +++ b/src/chart_types/xy_chart/state/selectors/get_tooltip_snap.ts @@ -5,9 +5,10 @@ import { SettingsSpec } from '../../../../specs/settings'; import { DEFAULT_TOOLTIP_SNAP } from '../../../../specs/settings'; import { getChartIdSelector } from '../../../../state/selectors/get_chart_id'; -export const getTooltipSnapSelector = createCachedSelector([getSettingsSpecSelector], getTooltipSnap)( - getChartIdSelector, -); +export const getTooltipSnapSelector = createCachedSelector( + [getSettingsSpecSelector], + getTooltipSnap, +)(getChartIdSelector); function getTooltipSnap(settings: SettingsSpec): boolean { const { tooltip } = settings; diff --git a/src/chart_types/xy_chart/state/selectors/get_tooltip_type.ts b/src/chart_types/xy_chart/state/selectors/get_tooltip_type.ts index 4069cb0c83..95a6e0570e 100644 --- a/src/chart_types/xy_chart/state/selectors/get_tooltip_type.ts +++ b/src/chart_types/xy_chart/state/selectors/get_tooltip_type.ts @@ -4,9 +4,10 @@ import { getSettingsSpecSelector } from '../../../../state/selectors/get_setting import { SettingsSpec } from '../../../../specs/settings'; import { getChartIdSelector } from '../../../../state/selectors/get_chart_id'; -export const getTooltipTypeSelector = createCachedSelector([getSettingsSpecSelector], getTooltipType)( - getChartIdSelector, -); +export const getTooltipTypeSelector = createCachedSelector( + [getSettingsSpecSelector], + getTooltipType, +)(getChartIdSelector); function getTooltipType(settings: SettingsSpec): TooltipType { const { tooltip } = settings; diff --git a/src/chart_types/xy_chart/state/selectors/is_chart_empty.ts b/src/chart_types/xy_chart/state/selectors/is_chart_empty.ts index f77ad9a15f..062fec3966 100644 --- a/src/chart_types/xy_chart/state/selectors/is_chart_empty.ts +++ b/src/chart_types/xy_chart/state/selectors/is_chart_empty.ts @@ -2,9 +2,6 @@ import createCachedSelector from 're-reselect'; import { isAllSeriesDeselected } from '../utils'; import { computeLegendSelector } from './compute_legend'; import { getChartIdSelector } from '../../../../state/selectors/get_chart_id'; -export const isChartEmptySelector = createCachedSelector( - [computeLegendSelector], - (legendItems): boolean => { - return isAllSeriesDeselected(legendItems); - }, -)(getChartIdSelector); +export const isChartEmptySelector = createCachedSelector([computeLegendSelector], (legendItems): boolean => { + return isAllSeriesDeselected(legendItems); +})(getChartIdSelector); diff --git a/src/chart_types/xy_chart/state/selectors/is_histogram_mode_enabled.ts b/src/chart_types/xy_chart/state/selectors/is_histogram_mode_enabled.ts index db92e8992e..f4089fcb82 100644 --- a/src/chart_types/xy_chart/state/selectors/is_histogram_mode_enabled.ts +++ b/src/chart_types/xy_chart/state/selectors/is_histogram_mode_enabled.ts @@ -3,9 +3,6 @@ import { getSeriesSpecsSelector } from './get_specs'; import { isHistogramModeEnabled } from '../utils'; import { getChartIdSelector } from '../../../../state/selectors/get_chart_id'; -export const isHistogramModeEnabledSelector = createCachedSelector( - [getSeriesSpecsSelector], - (seriesSpecs): boolean => { - return isHistogramModeEnabled(seriesSpecs); - }, -)(getChartIdSelector); +export const isHistogramModeEnabledSelector = createCachedSelector([getSeriesSpecsSelector], (seriesSpecs): boolean => { + return isHistogramModeEnabled(seriesSpecs); +})(getChartIdSelector); diff --git a/src/chart_types/xy_chart/state/utils.test.ts b/src/chart_types/xy_chart/state/utils.test.ts index b26ac95eb0..e7f8b96d38 100644 --- a/src/chart_types/xy_chart/state/utils.test.ts +++ b/src/chart_types/xy_chart/state/utils.test.ts @@ -1343,7 +1343,10 @@ describe('Chart State utils', () => { yScaleToDataExtent: false, data: BARCHART_1Y1G, }; - const seriesMap = new Map([[area.id, area], [line.id, line]]); + const seriesMap = new Map([ + [area.id, area], + [line.id, line], + ]); // should not affect area or line series setBarSeriesAccessors(isHistogramEnabled, seriesMap); expect(seriesMap).toEqual(seriesMap); diff --git a/src/chart_types/xy_chart/utils/axis_utils.ts b/src/chart_types/xy_chart/utils/axis_utils.ts index 37a1f78abf..d1f2b2c1dd 100644 --- a/src/chart_types/xy_chart/utils/axis_utils.ts +++ b/src/chart_types/xy_chart/utils/axis_utils.ts @@ -224,7 +224,12 @@ function computeTickDimensions( tickLabelStyle: { fontFamily, fontSize }, } = axisConfig; - const { maxLabelBboxWidth, maxLabelBboxHeight, maxLabelTextWidth, maxLabelTextHeight } = tickLabels.reduce( + const { + maxLabelBboxWidth, + maxLabelBboxHeight, + maxLabelTextWidth, + maxLabelTextHeight, + } = tickLabels.reduce( getMaxBboxDimensions(bboxCalculator, fontSize, fontFamily, tickLabelRotation, tickLabelPadding), { maxLabelBboxWidth: 0, maxLabelBboxHeight: 0, maxLabelTextWidth: 0, maxLabelTextHeight: 0 }, ); diff --git a/src/chart_types/xy_chart/utils/nonstacked_series_utils.test.ts b/src/chart_types/xy_chart/utils/nonstacked_series_utils.test.ts index c016e82977..8ede0992d1 100644 --- a/src/chart_types/xy_chart/utils/nonstacked_series_utils.test.ts +++ b/src/chart_types/xy_chart/utils/nonstacked_series_utils.test.ts @@ -193,7 +193,11 @@ const DATA_SET_WITH_NULL_2: RawDataSeries[] = [ splitAccessors: new Map(), seriesKeys: ['a'], key: 'a', - data: [{ x: 1, y1: 1 }, { x: 2, y1: 2 }, { x: 4, y1: 4 }], + data: [ + { x: 1, y1: 1 }, + { x: 2, y1: 2 }, + { x: 4, y1: 4 }, + ], }, { specId: 'spec1', @@ -201,7 +205,10 @@ const DATA_SET_WITH_NULL_2: RawDataSeries[] = [ splitAccessors: new Map(), seriesKeys: ['b'], key: 'b', - data: [{ x: 1, y1: 21 }, { x: 3, y1: 23 }], + data: [ + { x: 1, y1: 21 }, + { x: 3, y1: 23 }, + ], }, ]; describe('Non-Stacked Series Utils', () => { diff --git a/src/chart_types/xy_chart/utils/series.test.ts b/src/chart_types/xy_chart/utils/series.test.ts index e49b424620..dde67e5b7f 100644 --- a/src/chart_types/xy_chart/utils/series.test.ts +++ b/src/chart_types/xy_chart/utils/series.test.ts @@ -84,7 +84,11 @@ describe('Series', () => { splitAccessors: new Map(), seriesKeys: ['a'], key: 'a', - data: [{ x: 1, y1: 1 }, { x: 2, y1: 2 }, { x: 4, y1: 4 }], + data: [ + { x: 1, y1: 1 }, + { x: 2, y1: 2 }, + { x: 4, y1: 4 }, + ], }, { specId: 'spec1', @@ -92,7 +96,10 @@ describe('Series', () => { splitAccessors: new Map(), seriesKeys: ['b'], key: 'b', - data: [{ x: 1, y1: 21 }, { x: 3, y1: 23 }], + data: [ + { x: 1, y1: 21 }, + { x: 3, y1: 23 }, + ], }, ]; const xValues = new Set([1, 2, 3, 4]); @@ -107,7 +114,12 @@ describe('Series', () => { splitAccessors: new Map(), seriesKeys: ['a'], key: 'a', - data: [{ x: 1, y1: 1 }, { x: 2, y1: 2 }, { x: 3, y1: 3 }, { x: 4, y1: 4 }], + data: [ + { x: 1, y1: 1 }, + { x: 2, y1: 2 }, + { x: 3, y1: 3 }, + { x: 4, y1: 4 }, + ], }, { specId: 'spec1', @@ -115,7 +127,12 @@ describe('Series', () => { splitAccessors: new Map(), seriesKeys: ['b'], key: 'b', - data: [{ x: 1, y1: 1 }, { x: 2, y1: 2 }, { x: 3, y1: 3 }, { x: 4, y1: 4 }], + data: [ + { x: 1, y1: 1 }, + { x: 2, y1: 2 }, + { x: 3, y1: 3 }, + { x: 4, y1: 4 }, + ], }, { specId: 'spec1', @@ -123,7 +140,12 @@ describe('Series', () => { splitAccessors: new Map(), seriesKeys: ['b'], key: 'b', - data: [{ x: 1, y1: 1 }, { x: 2, y1: 2 }, { x: 3, y1: 3 }, { x: 4, y1: 4 }], + data: [ + { x: 1, y1: 1 }, + { x: 2, y1: 2 }, + { x: 3, y1: 3 }, + { x: 4, y1: 4 }, + ], }, { specId: 'spec1', @@ -131,7 +153,12 @@ describe('Series', () => { splitAccessors: new Map(), seriesKeys: ['b'], key: 'b', - data: [{ x: 1, y1: 1 }, { x: 2, y1: 2 }, { x: 3, y1: 3 }, { x: 4, y1: 4 }], + data: [ + { x: 1, y1: 1 }, + { x: 2, y1: 2 }, + { x: 3, y1: 3 }, + { x: 4, y1: 4 }, + ], }, ]; const xValues = new Set([1, 2, 3, 4]); @@ -146,7 +173,11 @@ describe('Series', () => { splitAccessors: new Map(), seriesKeys: ['a'], key: 'a', - data: [{ x: 1, y1: 1 }, { x: 4, y1: 4 }, { x: 2, y1: 2 }], + data: [ + { x: 1, y1: 1 }, + { x: 4, y1: 4 }, + { x: 2, y1: 2 }, + ], }, { specId: 'spec1', @@ -154,7 +185,10 @@ describe('Series', () => { splitAccessors: new Map(), seriesKeys: ['b'], key: 'b', - data: [{ x: 3, y1: 23 }, { x: 1, y1: 21 }], + data: [ + { x: 3, y1: 23 }, + { x: 1, y1: 21 }, + ], }, ]; const xValues = new Set([1, 2, 3, 4]); @@ -193,7 +227,11 @@ describe('Series', () => { splitAccessors: new Map(), seriesKeys: ['a'], key: 'a', - data: [{ x: 1, y1: 1 }, { x: 2, y1: 2 }, { x: 4, y1: 4 }], + data: [ + { x: 1, y1: 1 }, + { x: 2, y1: 2 }, + { x: 4, y1: 4 }, + ], }, { specId: 'spec1', @@ -201,7 +239,10 @@ describe('Series', () => { splitAccessors: new Map(), seriesKeys: ['b'], key: 'b', - data: [{ x: 1, y1: 21 }, { x: 3, y1: 23 }], + data: [ + { x: 1, y1: 21 }, + { x: 3, y1: 23 }, + ], }, ]; const xValues = new Set([1, 2, 3, 4]); @@ -218,7 +259,12 @@ describe('Series', () => { splitAccessors: new Map(), seriesKeys: ['a'], key: 'a', - data: [{ x: 1, y1: 1 }, { x: 2, y1: 2 }, { x: 3, y1: 3 }, { x: 4, y1: 4 }], + data: [ + { x: 1, y1: 1 }, + { x: 2, y1: 2 }, + { x: 3, y1: 3 }, + { x: 4, y1: 4 }, + ], }, { specId: 'spec1', @@ -226,7 +272,12 @@ describe('Series', () => { splitAccessors: new Map(), seriesKeys: ['b'], key: 'b', - data: [{ x: 1, y1: 1 }, { x: 2, y1: 2 }, { x: 3, y1: 3 }, { x: 4, y1: 4 }], + data: [ + { x: 1, y1: 1 }, + { x: 2, y1: 2 }, + { x: 3, y1: 3 }, + { x: 4, y1: 4 }, + ], }, { specId: 'spec1', @@ -234,7 +285,12 @@ describe('Series', () => { splitAccessors: new Map(), seriesKeys: ['b'], key: 'b', - data: [{ x: 1, y1: 1 }, { x: 2, y1: 2 }, { x: 3, y1: 3 }, { x: 4, y1: 4 }], + data: [ + { x: 1, y1: 1 }, + { x: 2, y1: 2 }, + { x: 3, y1: 3 }, + { x: 4, y1: 4 }, + ], }, { specId: 'spec1', @@ -242,7 +298,12 @@ describe('Series', () => { splitAccessors: new Map(), seriesKeys: ['b'], key: 'b', - data: [{ x: 1, y1: 1 }, { x: 2, y1: 2 }, { x: 3, y1: 3 }, { x: 4, y1: 4 }], + data: [ + { x: 1, y1: 1 }, + { x: 2, y1: 2 }, + { x: 3, y1: 3 }, + { x: 4, y1: 4 }, + ], }, ]; const xValues = new Set([1, 2, 3, 4]); @@ -259,7 +320,11 @@ describe('Series', () => { splitAccessors: new Map(), seriesKeys: ['a'], key: 'a', - data: [{ x: 1, y1: 3, y0: 1 }, { x: 2, y1: 3, y0: 2 }, { x: 4, y1: 4, y0: 3 }], + data: [ + { x: 1, y1: 3, y0: 1 }, + { x: 2, y1: 3, y0: 2 }, + { x: 4, y1: 4, y0: 3 }, + ], }, { specId: 'spec1', @@ -267,7 +332,12 @@ describe('Series', () => { splitAccessors: new Map(), seriesKeys: ['b'], key: 'b', - data: [{ x: 1, y1: 2, y0: 1 }, { x: 2, y1: 3, y0: 1 }, { x: 3, y1: 23, y0: 4 }, { x: 4, y1: 4, y0: 1 }], + data: [ + { x: 1, y1: 2, y0: 1 }, + { x: 2, y1: 3, y0: 1 }, + { x: 3, y1: 23, y0: 4 }, + { x: 4, y1: 4, y0: 1 }, + ], }, ]; const xValues = new Set([1, 2, 3, 4]); @@ -295,7 +365,11 @@ describe('Series', () => { splitAccessors: new Map(), seriesKeys: ['a'], key: 'a', - data: [{ x: 1, y1: 3, y0: 1 }, { x: 2, y1: 3, y0: 2 }, { x: 4, y1: 4, y0: 3 }], + data: [ + { x: 1, y1: 3, y0: 1 }, + { x: 2, y1: 3, y0: 2 }, + { x: 4, y1: 4, y0: 3 }, + ], }, { specId: 'spec1', @@ -303,7 +377,12 @@ describe('Series', () => { splitAccessors: new Map(), seriesKeys: ['b'], key: 'b', - data: [{ x: 1, y1: 2, y0: 1 }, { x: 2, y1: 3, y0: 1 }, { x: 3, y1: 23, y0: 4 }, { x: 4, y1: 4, y0: 1 }], + data: [ + { x: 1, y1: 2, y0: 1 }, + { x: 2, y1: 3, y0: 1 }, + { x: 3, y1: 23, y0: 4 }, + { x: 4, y1: 4, y0: 1 }, + ], }, ]; const xValues = new Set([1, 2, 3, 4]); diff --git a/src/chart_types/xy_chart/utils/specs.ts b/src/chart_types/xy_chart/utils/specs.ts index f0b518fca1..cc4dc6ddb5 100644 --- a/src/chart_types/xy_chart/utils/specs.ts +++ b/src/chart_types/xy_chart/utils/specs.ts @@ -70,18 +70,6 @@ export type SubSeriesStringPredicate = ( isTooltip: boolean, ) => string | number | null; -interface DomainMinInterval { - /** Custom minInterval for the domain which will affect data bucket size. - * The minInterval cannot be greater than the computed minimum interval between any two adjacent data points. - * Further, if you specify a custom numeric minInterval for a timeseries, please note that due to the restriction - * above, the specified numeric minInterval will be interpreted as a fixed interval. - * This means that, for example, if you have yearly timeseries data that ranges from 2016 to 2019 and you manually - * compute the interval between 2016 and 2017, you'll have 366 days due to 2016 being a leap year. This will not - * be a valid interval because it is greater than the computed minInterval of 365 days betwen the other years. - */ - minInterval?: number; -} - /** * The fit function type */ @@ -166,20 +154,43 @@ export const Fit = Object.freeze({ export type Fit = $Values; +interface DomainBase { + /** + * Custom minInterval for the domain which will affect data bucket size. + * The minInterval cannot be greater than the computed minimum interval between any two adjacent data points. + * Further, if you specify a custom numeric minInterval for a timeseries, please note that due to the restriction + * above, the specified numeric minInterval will be interpreted as a fixed interval. + * This means that, for example, if you have yearly timeseries data that ranges from 2016 to 2019 and you manually + * compute the interval between 2016 and 2017, you'll have 366 days due to 2016 being a leap year. This will not + * be a valid interval because it is greater than the computed minInterval of 365 days betwen the other years. + */ + minInterval?: number; + /** + * Whether to fit the domain to the data. ONLY applies to `yDomains` + * + * Setting `max` or `min` will override this functionality. + */ + fit?: boolean; +} + interface LowerBound { - /** Lower bound of domain range */ + /** + * Lower bound of domain range + */ min: number; } interface UpperBound { - /** Upper bound of domain range */ + /** + * Upper bound of domain range + */ max: number; } -export type LowerBoundedDomain = DomainMinInterval & LowerBound; -export type UpperBoundedDomain = DomainMinInterval & UpperBound; -export type CompleteBoundedDomain = DomainMinInterval & LowerBound & UpperBound; -export type UnboundedDomainWithInterval = DomainMinInterval; +export type LowerBoundedDomain = DomainBase & LowerBound; +export type UpperBoundedDomain = DomainBase & UpperBound; +export type CompleteBoundedDomain = DomainBase & LowerBound & UpperBound; +export type UnboundedDomainWithInterval = DomainBase; export type DomainRange = LowerBoundedDomain | UpperBoundedDomain | CompleteBoundedDomain | UnboundedDomainWithInterval; diff --git a/src/chart_types/xy_chart/utils/stacked_percent_series_utils.test.ts b/src/chart_types/xy_chart/utils/stacked_percent_series_utils.test.ts index fa9b89f1c7..b288a4730b 100644 --- a/src/chart_types/xy_chart/utils/stacked_percent_series_utils.test.ts +++ b/src/chart_types/xy_chart/utils/stacked_percent_series_utils.test.ts @@ -179,7 +179,11 @@ describe('Stacked Series Utils', () => { splitAccessors: new Map(), seriesKeys: ['a'], key: 'a', - data: [{ x: 1, y1: 10 }, { x: 2, y1: 20 }, { x: 4, y1: 40 }], + data: [ + { x: 1, y1: 10 }, + { x: 2, y1: 20 }, + { x: 4, y1: 40 }, + ], }, { specId: 'spec1', @@ -187,7 +191,10 @@ describe('Stacked Series Utils', () => { splitAccessors: new Map(), seriesKeys: ['b'], key: 'b', - data: [{ x: 1, y1: 90 }, { x: 3, y1: 30 }], + data: [ + { x: 1, y1: 90 }, + { x: 3, y1: 30 }, + ], }, ]; const xValues = new Set([0]); diff --git a/src/chart_types/xy_chart/utils/stacked_series_utils.test.ts b/src/chart_types/xy_chart/utils/stacked_series_utils.test.ts index a9be8d2007..85fd02ed96 100644 --- a/src/chart_types/xy_chart/utils/stacked_series_utils.test.ts +++ b/src/chart_types/xy_chart/utils/stacked_series_utils.test.ts @@ -189,7 +189,11 @@ describe('Stacked Series Utils', () => { splitAccessors: new Map(), seriesKeys: ['a'], key: 'a', - data: [{ x: 1, y1: 1 }, { x: 2, y1: 2 }, { x: 4, y1: 4 }], + data: [ + { x: 1, y1: 1 }, + { x: 2, y1: 2 }, + { x: 4, y1: 4 }, + ], }, { specId: 'spec1', @@ -197,7 +201,10 @@ describe('Stacked Series Utils', () => { splitAccessors: new Map(), seriesKeys: ['b'], key: 'b', - data: [{ x: 1, y1: 21 }, { x: 3, y1: 23 }], + data: [ + { x: 1, y1: 21 }, + { x: 3, y1: 23 }, + ], }, ]; const xValues = new Set([0]); diff --git a/src/components/chart_container.tsx b/src/components/chart_container.tsx index 5405c5ce29..8f87aa8131 100644 --- a/src/components/chart_container.tsx +++ b/src/components/chart_container.tsx @@ -171,7 +171,4 @@ const mapStateToProps = (state: GlobalChartState): ReactiveChartStateProps => { }; }; -export const ChartContainer = connect( - mapStateToProps, - mapDispatchToProps, -)(ChartContainerComponent); +export const ChartContainer = connect(mapStateToProps, mapDispatchToProps)(ChartContainerComponent); diff --git a/src/components/chart_resizer.tsx b/src/components/chart_resizer.tsx index b486471eb4..7804648857 100644 --- a/src/components/chart_resizer.tsx +++ b/src/components/chart_resizer.tsx @@ -92,7 +92,4 @@ const mapStateToProps = (state: GlobalChartState): ResizerStateProps => { }; }; -export const ChartResizer = connect( - mapStateToProps, - mapDispatchToProps, -)(Resizer); +export const ChartResizer = connect(mapStateToProps, mapDispatchToProps)(Resizer); diff --git a/src/components/legend/legend.test.tsx b/src/components/legend/legend.test.tsx index 348596e722..fee9a175cf 100644 --- a/src/components/legend/legend.test.tsx +++ b/src/components/legend/legend.test.tsx @@ -20,7 +20,12 @@ describe('Legend', () => { xAccessor={0} yAccessors={[1]} splitSeriesAccessors={[2]} - data={[[0, 123, 'group0'], [0, 123, 'group1'], [0, 123, 'group2'], [0, 123, 'group3']]} + data={[ + [0, 123, 'group0'], + [0, 123, 'group1'], + [0, 123, 'group2'], + [0, 123, 'group3'], + ]} /> , ); @@ -46,7 +51,12 @@ describe('Legend', () => { xAccessor={0} yAccessors={[1]} splitSeriesAccessors={[2]} - data={[[0, 123, 'group0'], [0, 123, 'group1'], [0, 123, 'group2'], [0, 123, 'group3']]} + data={[ + [0, 123, 'group0'], + [0, 123, 'group1'], + [0, 123, 'group2'], + [0, 123, 'group3'], + ]} /> , ); diff --git a/src/components/legend/legend.tsx b/src/components/legend/legend.tsx index 9c8caff0e2..27b7c910d1 100644 --- a/src/components/legend/legend.tsx +++ b/src/components/legend/legend.tsx @@ -215,7 +215,4 @@ const mapStateToProps = (state: GlobalChartState): LegendStateProps => { }; }; -export const Legend = connect( - mapStateToProps, - mapDispatchToProps, -)(LegendComponent); +export const Legend = connect(mapStateToProps, mapDispatchToProps)(LegendComponent); diff --git a/src/specs/specs_parser.test.tsx b/src/specs/specs_parser.test.tsx index 44a4c7a316..65489d2f41 100644 --- a/src/specs/specs_parser.test.tsx +++ b/src/specs/specs_parser.test.tsx @@ -30,9 +30,33 @@ describe('Specs parser', () => { const component = ( - - - + + + ); @@ -51,7 +75,15 @@ describe('Specs parser', () => { const component = ( - + ); @@ -60,7 +92,15 @@ describe('Specs parser', () => { wrapper.setProps({ children: ( - + ), }); diff --git a/src/specs/specs_parser.tsx b/src/specs/specs_parser.tsx index 7fe38ede6b..8c4ae957e0 100644 --- a/src/specs/specs_parser.tsx +++ b/src/specs/specs_parser.tsx @@ -31,7 +31,4 @@ const mapDispatchToProps = (dispatch: Dispatch): DispatchProps => dispatch, ); -export const SpecsParser = connect( - null, - mapDispatchToProps, -)(SpecsParserComponent); +export const SpecsParser = connect(null, mapDispatchToProps)(SpecsParserComponent); diff --git a/src/state/spec_factory.ts b/src/state/spec_factory.ts index 3cda252391..a27d9a2214 100644 --- a/src/state/spec_factory.ts +++ b/src/state/spec_factory.ts @@ -51,8 +51,5 @@ const mapDispatchToProps = (dispatch: Dispatch): DispatchProps => ); export function getConnect() { - return connect( - null, - mapDispatchToProps, - ); + return connect(null, mapDispatchToProps); } diff --git a/src/utils/commons.test.ts b/src/utils/commons.test.ts index 17fc78b596..8b3d5bd2f4 100644 --- a/src/utils/commons.test.ts +++ b/src/utils/commons.test.ts @@ -582,7 +582,7 @@ describe('commons utilities', () => { test('should merge optional params from partials', () => { type PartialTestTypeOverride = PartialTestType & any; const partial: PartialTestTypeOverride = { nick: 'test', number: 6 }; - const partials: (PartialTestTypeOverride)[] = [{ string: 'test', foo: 'bar' }, { array3: [3, 3, 3] }]; + const partials: PartialTestTypeOverride[] = [{ string: 'test', foo: 'bar' }, { array3: [3, 3, 3] }]; const newBase = mergePartial(base, partial, { mergeOptionalPartialValues: true }, partials); expect(newBase).toEqual({ ...newBase, diff --git a/src/utils/commons.ts b/src/utils/commons.ts index e84a4406fb..ed35146e58 100644 --- a/src/utils/commons.ts +++ b/src/utils/commons.ts @@ -50,7 +50,7 @@ export type RecursivePartial = { ? RecursivePartial[] : T[P] extends ReadonlyArray // eslint-disable-line @typescript-eslint/array-type ? ReadonlyArray> // eslint-disable-line @typescript-eslint/array-type - : RecursivePartial + : RecursivePartial; }; export interface MergeOptions { diff --git a/src/utils/data_generators/data_generator.ts b/src/utils/data_generators/data_generator.ts index 7126f3efd7..9f49b1c536 100644 --- a/src/utils/data_generators/data_generator.ts +++ b/src/utils/data_generators/data_generator.ts @@ -7,6 +7,15 @@ export class DataGenerator { this.generator = new Simple1DNoise(randomNumberGenerator); this.frequency = frequency; } + generateBasicSeries(totalPoints = 50, offset = 0, amplitude = 1) { + const dataPoints = new Array(totalPoints).fill(0).map((_, i) => { + return { + x: i, + y: (this.generator.getValue(i) + offset) * amplitude, + }; + }); + return dataPoints; + } generateSimpleSeries(totalPoints = 50, groupIndex = 1, groupPrefix = '') { const group = String.fromCharCode(97 + groupIndex); const dataPoints = new Array(totalPoints).fill(0).map((_, i) => { diff --git a/src/utils/data_samples/test_dataset.ts b/src/utils/data_samples/test_dataset.ts index 8ef4e9bef6..7a40b89046 100644 --- a/src/utils/data_samples/test_dataset.ts +++ b/src/utils/data_samples/test_dataset.ts @@ -1,6 +1,16 @@ -export const BARCHART_1Y0G = [{ x: 0, y: 1 }, { x: 1, y: 2 }, { x: 2, y: 10 }, { x: 3, y: 6 }]; +export const BARCHART_1Y0G = [ + { x: 0, y: 1 }, + { x: 1, y: 2 }, + { x: 2, y: 10 }, + { x: 3, y: 6 }, +]; -export const BARCHART_1Y0G_LINEAR = [{ x: 0, y: 1 }, { x: 1, y: 2 }, { x: 2.5, y: 10 }, { x: 3.5, y: 6 }]; +export const BARCHART_1Y0G_LINEAR = [ + { x: 0, y: 1 }, + { x: 1, y: 2 }, + { x: 2.5, y: 10 }, + { x: 3.5, y: 6 }, +]; export const BARCHART_1Y1G = [ { x: 0, g: 'a', y: 1 }, { x: 0, g: 'b', y: 2 }, diff --git a/src/utils/domain.test.ts b/src/utils/domain.test.ts index b301a21c8a..bcbab252a5 100644 --- a/src/utils/domain.test.ts +++ b/src/utils/domain.test.ts @@ -94,7 +94,11 @@ describe('utils/domain', () => { }); test('should compute stacked data domain: data scaled to extent', () => { - const data = [{ y: 12, x: 'a' }, { y: 6, x: 'b' }, { y: 8, x: 'a' }]; + const data = [ + { y: 12, x: 'a' }, + { y: 6, x: 'b' }, + { y: 8, x: 'a' }, + ]; const yAccessor: AccessorFn = (datum: any) => datum.y; const xAccessor: AccessorFn = (datum: any) => datum.x; const scaleToExtent = true; @@ -107,7 +111,11 @@ describe('utils/domain', () => { }); test('should compute stacked data domain: data not scaled to extent', () => { - const data = [{ y: 12, x: 'a' }, { y: 6, x: 'b' }, { y: 8, x: 'a' }]; + const data = [ + { y: 12, x: 'a' }, + { y: 6, x: 'b' }, + { y: 8, x: 'a' }, + ]; const yAccessor: AccessorFn = (datum: any) => datum.y; const xAccessor: AccessorFn = (datum: any) => datum.x; @@ -118,17 +126,55 @@ describe('utils/domain', () => { expect(stackedDataDomain).toEqual(expectedStackedDomain); }); - test('should compute domain based on scaleToExtent', () => { - // start & end are positive - expect(computeDomainExtent([5, 10], true)).toEqual([5, 10]); - expect(computeDomainExtent([5, 10], false)).toEqual([0, 10]); - - // start & end are negative - expect(computeDomainExtent([-15, -10], true)).toEqual([-15, -10]); - expect(computeDomainExtent([-15, -10], false)).toEqual([-15, 0]); + describe('scaleToExtent', () => { + describe('true', () => { + it('should find domain when start & end are positive', () => { + expect(computeDomainExtent([5, 10], true)).toEqual([5, 10]); + }); + it('should find domain when start & end are negative', () => { + expect(computeDomainExtent([-15, -10], true)).toEqual([-15, -10]); + }); + it('should find domain when start is negative, end is positive', () => { + expect(computeDomainExtent([-15, 10], true)).toEqual([-15, 10]); + }); + }); + describe('false', () => { + it('should find domain when start & end are positive', () => { + expect(computeDomainExtent([5, 10], false)).toEqual([0, 10]); + }); + it('should find domain when start & end are negative', () => { + expect(computeDomainExtent([-15, -10], false)).toEqual([-15, 0]); + }); + it('should find domain when start is negative, end is positive', () => { + expect(computeDomainExtent([-15, 10], false)).toEqual([-15, 10]); + }); + }); + }); - // start is negative, end is positive - expect(computeDomainExtent([-15, 10], true)).toEqual([-15, 10]); - expect(computeDomainExtent([-15, 10], false)).toEqual([-15, 10]); + describe('fitToExtent', () => { + it('should not effect domain when scaleToExtent is true', () => { + expect(computeDomainExtent([5, 10], true)).toEqual([5, 10]); + }); + + describe('baseline far from zero', () => { + it('should get domain from positive domain', () => { + expect(computeDomainExtent([10, 70], false, true)).toEqual([5, 75]); + }); + it('should get domain from positive & negative domain', () => { + expect(computeDomainExtent([-30, 30], false, true)).toEqual([-35, 35]); + }); + it('should get domain from negative domain', () => { + expect(computeDomainExtent([-70, -10], false, true)).toEqual([-75, -5]); + }); + }); + + describe('baseline near zero', () => { + it('should set min baseline as 0 if original domain is less than zero', () => { + expect(computeDomainExtent([5, 65], false, true)).toEqual([0, 70]); + }); + it('should set max baseline as 0 if original domain is less than zero', () => { + expect(computeDomainExtent([-65, -5], false, true)).toEqual([-70, 0]); + }); + }); }); }); diff --git a/src/utils/domain.ts b/src/utils/domain.ts index 1194d39db7..9d15e2f834 100644 --- a/src/utils/domain.ts +++ b/src/utils/domain.ts @@ -45,17 +45,31 @@ export function computeOrdinalDataDomain( : uniqueValues; } +function computeFittedDomain(start?: number, end?: number) { + if (start === undefined || end === undefined) { + return [start, end]; + } + + const delta = Math.abs(end - start); + const padding = (delta === 0 ? end - 0 : delta) / 12; + const newStart = start - padding; + const newEnd = end + padding; + + return [start >= 0 && newStart < 0 ? 0 : newStart, end <= 0 && newEnd > 0 ? 0 : newEnd]; +} + export function computeDomainExtent( computedDomain: [number, number] | [undefined, undefined], scaleToExtent: boolean, + fitToExtent: boolean = false, ): [number, number] { - const [start, end] = computedDomain; + const [start, end] = fitToExtent && !scaleToExtent ? computeFittedDomain(...computedDomain) : computedDomain; if (start != null && end != null) { if (start >= 0 && end >= 0) { - return scaleToExtent ? [start, end] : [0, end]; + return scaleToExtent || fitToExtent ? [start, end] : [0, end]; } else if (start < 0 && end < 0) { - return scaleToExtent ? [start, end] : [start, 0]; + return scaleToExtent || fitToExtent ? [start, end] : [start, 0]; } return [start, end]; } @@ -64,11 +78,18 @@ export function computeDomainExtent( return [0, 0]; } -export function computeContinuousDataDomain(data: any[], accessor: AccessorFn, scaleToExtent = false): number[] { +export function computeContinuousDataDomain( + data: any[], + accessor: AccessorFn, + scaleToExtent = false, + fitToExtent = false, +): number[] { const range = extent(data, accessor); - return computeDomainExtent(range, scaleToExtent); + + return computeDomainExtent(range, scaleToExtent, fitToExtent); } +// TODO: remove or incorporate this function export function computeStackedContinuousDomain( data: any[], xAccessor: AccessorFn, diff --git a/src/utils/ids.test.ts b/src/utils/ids.test.ts index ae3cbcec78..79c1e53e74 100644 --- a/src/utils/ids.test.ts +++ b/src/utils/ids.test.ts @@ -13,7 +13,10 @@ describe('IDs', () => { const groupSeries: Map = new Map(); groupSeries.set(groupId1, 'data1'); groupSeries.set(groupId2, 'data2'); - const expectedAxisSeries = [['axisId1', 'data1'], ['axisId2', 'data2']]; + const expectedAxisSeries = [ + ['axisId1', 'data1'], + ['axisId2', 'data2'], + ]; const expectedGroupSeries = [['groupId', 'data2']]; expect(expectedAxisSeries).toEqual([...axisSeries]); expect(expectedGroupSeries).toEqual([...groupSeries]); @@ -26,7 +29,10 @@ describe('IDs', () => { annotations.set(annotationId1, 'annotations 1'); annotations.set(annotationId2, 'annotations 2'); - const expectedAnnotations = [['anno1', 'annotations 1'], ['anno2', 'annotations 2']]; + const expectedAnnotations = [ + ['anno1', 'annotations 1'], + ['anno2', 'annotations 2'], + ]; expect(expectedAnnotations).toEqual([...annotations]); }); }); diff --git a/stories/annotations.tsx b/stories/annotations.tsx index c733297d41..715044d34a 100644 --- a/stories/annotations.tsx +++ b/stories/annotations.tsx @@ -79,7 +79,11 @@ storiesOf('Annotations', module) yScaleType={ScaleType.Linear} xAccessor="x" yAccessors={['y']} - data={[{ x: 0, y: 2 }, { x: 1, y: 7 }, { x: 3, y: 6 }]} + data={[ + { x: 0, y: 2 }, + { x: 1, y: 7 }, + { x: 3, y: 6 }, + ]} /> ); @@ -105,7 +109,12 @@ storiesOf('Annotations', module) yScaleType={ScaleType.Linear} xAccessor="x" yAccessors={['y']} - data={[{ x: 'a', y: 2 }, { x: 'b', y: 7 }, { x: 'c', y: 3 }, { x: 'd', y: 6 }]} + data={[ + { x: 'a', y: 2 }, + { x: 'b', y: 7 }, + { x: 'c', y: 3 }, + { x: 'd', y: 6 }, + ]} /> ); @@ -135,7 +144,12 @@ storiesOf('Annotations', module) yScaleType={ScaleType.Linear} xAccessor="x" yAccessors={['y']} - data={[{ x: 0, y: 2 }, { x: 1, y: 7 }, { x: 2, y: 3 }, { x: 3, y: 6 }]} + data={[ + { x: 0, y: 2 }, + { x: 1, y: 7 }, + { x: 2, y: 3 }, + { x: 3, y: 6 }, + ]} /> ); @@ -227,7 +241,11 @@ storiesOf('Annotations', module) yScaleType={ScaleType.Linear} xAccessor="x" yAccessors={['y']} - data={[{ x: 0, y: 2 }, { x: 1, y: 7 }, { x: 3, y: 6 }]} + data={[ + { x: 0, y: 2 }, + { x: 1, y: 7 }, + { x: 3, y: 6 }, + ]} /> ); @@ -257,7 +275,11 @@ storiesOf('Annotations', module) yScaleType={ScaleType.Linear} xAccessor={'x'} yAccessors={['y']} - data={[{ x: 0, y: 2 }, { x: 1, y: 7 }, { x: 3, y: 6 }]} + data={[ + { x: 0, y: 2 }, + { x: 1, y: 7 }, + { x: 3, y: 6 }, + ]} /> ); @@ -285,7 +307,12 @@ storiesOf('Annotations', module) yScaleType={ScaleType.Linear} xAccessor={'x'} yAccessors={['y']} - data={[{ x: 'a', y: 2 }, { x: 'b', y: 7 }, { x: 'c', y: 0 }, { x: 'd', y: 6 }]} + data={[ + { x: 'a', y: 2 }, + { x: 'b', y: 7 }, + { x: 'c', y: 0 }, + { x: 'd', y: 6 }, + ]} /> ); @@ -352,7 +379,11 @@ storiesOf('Annotations', module) yScaleType={ScaleType.Linear} xAccessor={'x'} yAccessors={['y']} - data={[{ x: 0, y: 2 }, { x: 1, y: 7 }, { x: 3, y: 6 }]} + data={[ + { x: 0, y: 2 }, + { x: 1, y: 7 }, + { x: 3, y: 6 }, + ]} /> ); @@ -448,7 +479,11 @@ storiesOf('Annotations', module) yScaleType={ScaleType.Linear} xAccessor={'x'} yAccessors={['y']} - data={[{ x: 0, y: 2 }, { x: 1, y: 7 }, { x: 3, y: 6 }]} + data={[ + { x: 0, y: 2 }, + { x: 1, y: 7 }, + { x: 3, y: 6 }, + ]} /> ); @@ -552,7 +587,11 @@ storiesOf('Annotations', module) yScaleType={ScaleType.Linear} xAccessor={'x'} yAccessors={['y']} - data={[{ x: 0, y: 2 }, { x: 1, y: 7 }, { x: 3, y: 6 }]} + data={[ + { x: 0, y: 2 }, + { x: 1, y: 7 }, + { x: 3, y: 6 }, + ]} /> ); diff --git a/stories/area_chart.tsx b/stories/area_chart.tsx index 1e06189f34..eec5e40ace 100644 --- a/stories/area_chart.tsx +++ b/stories/area_chart.tsx @@ -369,7 +369,17 @@ storiesOf('Area Chart', module) ); }) .add('[test] - linear', () => { - const data = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 4], [7, 3], [8, 2], [9, 1]]; + const data = [ + [1, 1], + [2, 2], + [3, 3], + [4, 4], + [5, 5], + [6, 4], + [7, 3], + [8, 2], + [9, 1], + ]; return ( @@ -530,9 +540,39 @@ storiesOf('Area Chart', module) ); }) .add('stacked only grouped areas', () => { - const data1 = [[1, 2], [2, 2], [3, 3], [4, 5], [5, 5], [6, 3], [7, 8], [8, 2], [9, 1]]; - const data2 = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 4], [7, 3], [8, 2], [9, 4]]; - const data3 = [[1, 6], [2, 6], [3, 3], [4, 2], [5, 1], [6, 1], [7, 5], [8, 6], [9, 7]]; + const data1 = [ + [1, 2], + [2, 2], + [3, 3], + [4, 5], + [5, 5], + [6, 3], + [7, 8], + [8, 2], + [9, 1], + ]; + const data2 = [ + [1, 1], + [2, 2], + [3, 3], + [4, 4], + [5, 5], + [6, 4], + [7, 3], + [8, 2], + [9, 4], + ]; + const data3 = [ + [1, 6], + [2, 6], + [3, 3], + [4, 2], + [5, 1], + [6, 1], + [7, 5], + [8, 6], + [9, 7], + ]; return ( diff --git a/stories/axis.tsx b/stories/axis.tsx index 54afaa2d30..b703ab7b62 100644 --- a/stories/axis.tsx +++ b/stories/axis.tsx @@ -1,4 +1,4 @@ -import { boolean, number } from '@storybook/addon-knobs'; +import { boolean, number, select } from '@storybook/addon-knobs'; import { storiesOf } from '@storybook/react'; import React from 'react'; @@ -191,7 +191,12 @@ storiesOf('Axis', module) yScaleType={ScaleType.Linear} xAccessor="x" yAccessors={['y']} - data={[{ x: 0, y: 2 }, { x: 1, y: 7 }, { x: 2, y: 3 }, { x: 3, y: 6 }]} + data={[ + { x: 0, y: 2 }, + { x: 1, y: 7 }, + { x: 2, y: 3 }, + { x: 3, y: 6 }, + ]} /> @@ -235,7 +240,12 @@ storiesOf('Axis', module) yScaleType={ScaleType.Linear} xAccessor="x" yAccessors={['y']} - data={[{ x: 0, y: 2 }, { x: 1, y: 7 }, { x: 2, y: 3 }, { x: 3, y: 6 }]} + data={[ + { x: 0, y: 2 }, + { x: 1, y: 7 }, + { x: 2, y: 3 }, + { x: 3, y: 6 }, + ]} /> ); @@ -276,7 +286,12 @@ storiesOf('Axis', module) yScaleType={ScaleType.Linear} xAccessor="x" yAccessors={['y']} - data={[{ x: 0, y: 1 }, { x: 1, y: 2 }, { x: 2, y: 3 }, { x: 3, y: 4 }]} + data={[ + { x: 0, y: 1 }, + { x: 1, y: 2 }, + { x: 2, y: 3 }, + { x: 3, y: 4 }, + ]} /> ); @@ -305,7 +320,12 @@ storiesOf('Axis', module) yScaleType={ScaleType.Linear} xAccessor="x" yAccessors={['y']} - data={[{ x: 0, y: 2 }, { x: 1, y: 7 }, { x: 2, y: 3 }, { x: 3, y: 6 }]} + data={[ + { x: 0, y: 2 }, + { x: 1, y: 7 }, + { x: 2, y: 3 }, + { x: 3, y: 6 }, + ]} /> ); @@ -349,7 +374,12 @@ storiesOf('Axis', module) yAccessors={['y']} stackAccessors={['x']} splitSeriesAccessors={['g']} - data={[{ x: 0, y: 5 }, { x: 1, y: 4 }, { x: 2, y: 3 }, { x: 3, y: 2 }]} + data={[ + { x: 0, y: 5 }, + { x: 1, y: 4 }, + { x: 2, y: 3 }, + { x: 3, y: 2 }, + ]} /> ); @@ -447,7 +482,12 @@ storiesOf('Axis', module) yScaleType={ScaleType.Linear} xAccessor="x" yAccessors={['y']} - data={[{ x: 0, y: 2 }, { x: 1, y: 7 }, { x: 2, y: 3 }, { x: 3, y: 6 }]} + data={[ + { x: 0, y: 2 }, + { x: 1, y: 7 }, + { x: 2, y: 3 }, + { x: 3, y: 6 }, + ]} /> ); @@ -508,7 +553,12 @@ storiesOf('Axis', module) yScaleType={ScaleType.Linear} xAccessor="x" yAccessors={['y']} - data={[{ x: 'a', y: 2 }, { x: 'b', y: 7 }, { x: 'c', y: 3 }, { x: 'd', y: 6 }]} + data={[ + { x: 'a', y: 2 }, + { x: 'b', y: 7 }, + { x: 'c', y: 3 }, + { x: 'd', y: 6 }, + ]} /> ); @@ -550,7 +605,59 @@ storiesOf('Axis', module) yScaleType={ScaleType.Linear} xAccessor="x" yAccessors={['y']} - data={[{ x: 0, y: 2 }, { x: 1, y: 7 }, { x: 2, y: 3 }, { x: 3, y: 6 }]} + data={[ + { x: 0, y: 2 }, + { x: 1, y: 7 }, + { x: 2, y: 3 }, + { x: 3, y: 6 }, + ]} + /> + + ); + }) + .add('fit domain to extent in y axis', () => { + const dg = new SeededDataGenerator(); + const base = dg.generateBasicSeries(100, 0, 50); + const positive = base.map(({ x, y }) => ({ x, y: y + 1000 })); + const both = base.map(({ x, y }) => ({ x, y: y - 100 })); + const negative = base.map(({ x, y }) => ({ x, y: y - 1000 })); + + const dataTypes = { + positive, + both, + negative, + }; + const dataKey = select( + 'dataset', + { + 'Positive values only': 'positive', + 'Positive and negative': 'both', + 'Negtive values only': 'negative', + }, + 'both', + ); + // @ts-ignore + const dataset = dataTypes[dataKey]; + const fit = boolean('fit domain to data', true); + + return ( + + + Number(d).toFixed(2)} + /> + + ); diff --git a/stories/bar_chart.tsx b/stories/bar_chart.tsx index f5245c688e..4b3e2a70fb 100644 --- a/stories/bar_chart.tsx +++ b/stories/bar_chart.tsx @@ -54,7 +54,12 @@ storiesOf('Bar Chart', module) const darkmode = boolean('darkmode', false); const className = darkmode ? 'story-chart-dark' : 'story-chart'; const toggleSpec = boolean('toggle bar spec', true); - const data1 = [{ x: 0, y: 2 }, { x: 1, y: 7 }, { x: 2, y: 3 }, { x: 3, y: 6 }]; + const data1 = [ + { x: 0, y: 2 }, + { x: 1, y: 7 }, + { x: 2, y: 3 }, + { x: 3, y: 6 }, + ]; const data2 = data1.map((datum) => ({ ...datum, y: datum.y - 1 })); const data = toggleSpec ? data1 : data2; const specId = toggleSpec ? 'bars1' : 'bars2'; @@ -185,7 +190,12 @@ storiesOf('Bar Chart', module) yScaleType={ScaleType.Linear} xAccessor="x" yAccessors={['y']} - data={[{ x: 0, y: 2 }, { x: 1, y: 7 }, { x: 2, y: 3 }, { x: 3, y: 6 }]} + data={[ + { x: 0, y: 2 }, + { x: 1, y: 7 }, + { x: 2, y: 3 }, + { x: 3, y: 6 }, + ]} /> ); @@ -207,7 +217,12 @@ storiesOf('Bar Chart', module) yScaleType={ScaleType.Linear} xAccessor="x" yAccessors={['y']} - data={[{ x: 'a', y: 2 }, { x: 'b', y: 7 }, { x: 'c', y: 3 }, { x: 'd', y: 6 }]} + data={[ + { x: 'a', y: 2 }, + { x: 'b', y: 7 }, + { x: 'c', y: 3 }, + { x: 'd', y: 6 }, + ]} /> ); @@ -247,7 +262,12 @@ storiesOf('Bar Chart', module) yScaleType={ScaleType.Linear} xAccessor="x" yAccessors={['y']} - data={[{ x: 1, y: 2 }, { x: 2, y: 7 }, { x: 4, y: 3 }, { x: 9, y: 6 }]} + data={[ + { x: 1, y: 2 }, + { x: 2, y: 7 }, + { x: 4, y: 3 }, + { x: 9, y: 6 }, + ]} /> ); @@ -407,7 +427,12 @@ storiesOf('Bar Chart', module) yScaleType={ScaleType.Linear} xAccessor="x" yAccessors={['y']} - data={[{ x: 0, y: 2 }, { x: 1, y: 7 }, { x: 2, y: 3 }, { x: 3, y: 6 }]} + data={[ + { x: 0, y: 2 }, + { x: 1, y: 7 }, + { x: 2, y: 3 }, + { x: 3, y: 6 }, + ]} /> ); @@ -553,7 +578,12 @@ storiesOf('Bar Chart', module) yScaleType={ScaleType.Linear} xAccessor="x" yAccessors={['y']} - data={[{ x: 0, y: 2 }, { x: 1, y: 7 }, { x: 2, y: 3 }, { x: 3, y: 6 }]} + data={[ + { x: 0, y: 2 }, + { x: 1, y: 7 }, + { x: 2, y: 3 }, + { x: 3, y: 6 }, + ]} /> ); @@ -1020,7 +1060,12 @@ storiesOf('Bar Chart', module) yAccessors={['y']} splitSeriesAccessors={['g']} stackAccessors={['x']} - data={[{ x: 1, y: 10, g: 'a' }, { x: 1, y: 5, g: 'b' }, { x: 1, y: 3, g: 'c' }, { x: 1, y: 10, g: 'd' }]} + data={[ + { x: 1, y: 10, g: 'a' }, + { x: 1, y: 5, g: 'b' }, + { x: 1, y: 3, g: 'c' }, + { x: 1, y: 10, g: 'd' }, + ]} /> ); @@ -1044,7 +1089,11 @@ storiesOf('Bar Chart', module) yAccessors={['y']} splitSeriesAccessors={['g']} stackAccessors={['x']} - data={[{ x: 0, y: 10, g: 'a' }, { x: 0, y: 20, g: 'b' }, { x: 0, y: 30, g: 'c' }]} + data={[ + { x: 0, y: 10, g: 'a' }, + { x: 0, y: 20, g: 'b' }, + { x: 0, y: 30, g: 'c' }, + ]} yScaleToDataExtent={true} /> @@ -1068,7 +1117,11 @@ storiesOf('Bar Chart', module) xAccessor="x" yAccessors={['y']} splitSeriesAccessors={['g']} - data={[{ x: 0, y: 10, g: 'a' }, { x: 0, y: 20, g: 'b' }, { x: 0, y: 30, g: 'c' }]} + data={[ + { x: 0, y: 10, g: 'a' }, + { x: 0, y: 20, g: 'b' }, + { x: 0, y: 30, g: 'c' }, + ]} yScaleToDataExtent={true} /> @@ -1108,7 +1161,12 @@ storiesOf('Bar Chart', module) }) .add('scale to extent', () => { const yScaleToDataExtent = boolean('yScaleDataToExtent', true); - const mixed = [{ x: 0, y: -4 }, { x: 1, y: -3 }, { x: 2, y: 2 }, { x: 3, y: 1 }]; + const mixed = [ + { x: 0, y: -4 }, + { x: 1, y: -3 }, + { x: 2, y: 2 }, + { x: 3, y: 1 }, + ]; const allPositive = mixed.map((datum) => ({ x: datum.x, y: Math.abs(datum.y) })); const allNegative = mixed.map((datum) => ({ x: datum.x, y: Math.abs(datum.y) * -1 })); @@ -1211,7 +1269,17 @@ storiesOf('Bar Chart', module) ); }) .add('[test] - linear', () => { - const data = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 4], [7, 3], [8, 2], [9, 1]]; + const data = [ + [1, 1], + [2, 2], + [3, 3], + [4, 4], + [5, 5], + [6, 4], + [7, 3], + [8, 2], + [9, 1], + ]; return ( @@ -1266,7 +1334,17 @@ storiesOf('Bar Chart', module) ); }) .add('[test] - linear clustered', () => { - const data = [[1, 1, 3], [2, 2, 4], [3, 3, 5], [4, 4, 6], [5, 5, 7], [6, 4, 6], [7, 3, 5], [8, 2, 4], [9, 1, 3]]; + const data = [ + [1, 1, 3], + [2, 2, 4], + [3, 3, 5], + [4, 4, 6], + [5, 5, 7], + [6, 4, 6], + [7, 3, 5], + [8, 2, 4], + [9, 1, 3], + ]; return ( @@ -1409,7 +1487,12 @@ storiesOf('Bar Chart', module) yScaleType={ScaleType.Linear} xAccessor="x" yAccessors={['y']} - data={[{ x: 0, y: 2 }, { x: 1, y: 7 }, { x: 2, y: 3 }, { x: 3, y: 6 }]} + data={[ + { x: 0, y: 2 }, + { x: 1, y: 7 }, + { x: 2, y: 3 }, + { x: 3, y: 6 }, + ]} /> ); @@ -1544,7 +1627,12 @@ storiesOf('Bar Chart', module) ); }) .add('[test] histogram mode (ordinal)', () => { - const data = [{ x: 'a', y: 2 }, { x: 'b', y: 7 }, { x: 'c', y: 0 }, { x: 'd', y: 6 }]; + const data = [ + { x: 'a', y: 2 }, + { x: 'b', y: 7 }, + { x: 'c', y: 0 }, + { x: 'd', y: 6 }, + ]; const theme = { scales: { barsPadding: number('bars padding', 0.25, { @@ -1670,7 +1758,17 @@ storiesOf('Bar Chart', module) }) .add('Min Height', () => { const minBarHeight = number('minBarHeight', 5); - const data = [[1, 100000], [2, 10000], [3, 1000], [4, 100], [5, 10], [6, 1], [7, 0], [8, 1], [9, 0]]; + const data = [ + [1, 100000], + [2, 10000], + [3, 1000], + [4, 100], + [5, 10], + [6, 1], + [7, 0], + [8, 1], + [9, 0], + ]; return ( @@ -1726,11 +1824,61 @@ storiesOf('Bar Chart', module) ); }) .add('stacked only grouped areas', () => { - const data1 = [[1, 2], [2, 2], [3, 3], [4, 5], [5, 5], [6, 3], [7, 8], [8, 2], [9, 1]]; - const data2 = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 4], [7, 3], [8, 2], [9, 4]]; - const data3 = [[1, 6], [2, 6], [3, 3], [4, 2], [5, 1], [6, 1], [7, 5], [8, 6], [9, 7]]; - const data4 = [[1, 2], [2, 6], [3, 2], [4, 9], [5, 2], [6, 3], [7, 1], [8, 2], [9, 7]]; - const data5 = [[1, 1], [2, 7], [3, 5], [4, 6], [5, 5], [6, 4], [7, 2], [8, 4], [9, 8]]; + const data1 = [ + [1, 2], + [2, 2], + [3, 3], + [4, 5], + [5, 5], + [6, 3], + [7, 8], + [8, 2], + [9, 1], + ]; + const data2 = [ + [1, 1], + [2, 2], + [3, 3], + [4, 4], + [5, 5], + [6, 4], + [7, 3], + [8, 2], + [9, 4], + ]; + const data3 = [ + [1, 6], + [2, 6], + [3, 3], + [4, 2], + [5, 1], + [6, 1], + [7, 5], + [8, 6], + [9, 7], + ]; + const data4 = [ + [1, 2], + [2, 6], + [3, 2], + [4, 9], + [5, 2], + [6, 3], + [7, 1], + [8, 2], + [9, 7], + ]; + const data5 = [ + [1, 1], + [2, 7], + [3, 5], + [4, 6], + [5, 5], + [6, 4], + [7, 2], + [8, 4], + [9, 8], + ]; return ( diff --git a/stories/grid.tsx b/stories/grid.tsx index b2b00531e3..7a1620c5a3 100644 --- a/stories/grid.tsx +++ b/stories/grid.tsx @@ -131,7 +131,12 @@ storiesOf('Grids', module) yScaleType={ScaleType.Linear} xAccessor="x" yAccessors={['y']} - data={[{ x: 0, y: 2 }, { x: 1, y: 7 }, { x: 2, y: 3 }, { x: 3, y: 6 }]} + data={[ + { x: 0, y: 2 }, + { x: 1, y: 7 }, + { x: 2, y: 3 }, + { x: 3, y: 6 }, + ]} /> ); @@ -177,7 +187,12 @@ storiesOf('Grids', module) yScaleType={ScaleType.Linear} xAccessor="x" yAccessors={['y']} - data={[{ x: 0, y: 2 }, { x: 1, y: 7 }, { x: 2, y: 3 }, { x: 3, y: 6 }]} + data={[ + { x: 0, y: 2 }, + { x: 1, y: 7 }, + { x: 2, y: 3 }, + { x: 3, y: 6 }, + ]} /> ); diff --git a/stories/interactions.tsx b/stories/interactions.tsx index b0632757ee..3d31fb1474 100644 --- a/stories/interactions.tsx +++ b/stories/interactions.tsx @@ -84,7 +84,12 @@ storiesOf('Interactions', module) yScaleType={ScaleType.Linear} xAccessor="x" yAccessors={['y']} - data={[{ x: 0, y: 2 }, { x: 1, y: 7 }, { x: 2, y: 3 }, { x: 3, y: 6 }]} + data={[ + { x: 0, y: 2 }, + { x: 1, y: 7 }, + { x: 2, y: 3 }, + { x: 3, y: 6 }, + ]} /> ); @@ -107,7 +112,12 @@ storiesOf('Interactions', module) yScaleType={ScaleType.Linear} xAccessor="x" yAccessors={['y']} - data={[{ x: 0, y: 2 }, { x: 1, y: 7 }, { x: 2, y: 3 }, { x: 3, y: 6 }]} + data={[ + { x: 0, y: 2 }, + { x: 1, y: 7 }, + { x: 2, y: 3 }, + { x: 3, y: 6 }, + ]} /> ); @@ -130,7 +140,12 @@ storiesOf('Interactions', module) yScaleType={ScaleType.Linear} xAccessor="x" yAccessors={['y']} - data={[{ x: 0, y: 2 }, { x: 1, y: 7 }, { x: 2, y: 3 }, { x: 3, y: 6 }]} + data={[ + { x: 0, y: 2 }, + { x: 1, y: 7 }, + { x: 2, y: 3 }, + { x: 3, y: 6 }, + ]} /> ); @@ -154,7 +169,12 @@ storiesOf('Interactions', module) xAccessor="x" yAccessors={['y']} splitSeriesAccessors={['g']} - data={[{ x: 0, y: 2.3 }, { x: 1, y: 2 }, { x: 2, y: 4 }, { x: 3, y: 8 }]} + data={[ + { x: 0, y: 2.3 }, + { x: 1, y: 2 }, + { x: 2, y: 4 }, + { x: 3, y: 8 }, + ]} /> ); @@ -302,7 +332,12 @@ storiesOf('Interactions', module) xAccessor="x" yAccessors={['y']} curve={CurveType.CURVE_MONOTONE_X} - data={[{ x: 0, y: 2 }, { x: 1, y: 7 }, { x: 2, y: 3 }, { x: 3, y: 6 }]} + data={[ + { x: 0, y: 2 }, + { x: 1, y: 7 }, + { x: 2, y: 3 }, + { x: 3, y: 6 }, + ]} /> ); @@ -376,7 +436,12 @@ storiesOf('Interactions', module) yScaleType={ScaleType.Linear} xAccessor="x" yAccessors={['y']} - data={[{ x: 0, y: 2 }, { x: 1, y: 7 }, { x: 2, y: 3 }, { x: 3, y: 6 }]} + data={[ + { x: 0, y: 2 }, + { x: 1, y: 7 }, + { x: 2, y: 3 }, + { x: 3, y: 6 }, + ]} /> ); @@ -411,7 +481,12 @@ storiesOf('Interactions', module) yScaleType={ScaleType.Linear} xAccessor="x" yAccessors={['y']} - data={[{ x: 0, y: 2 }, { x: 1, y: 7 }, { x: 2, y: 3 }, { x: 3, y: 6 }]} + data={[ + { x: 0, y: 2 }, + { x: 1, y: 7 }, + { x: 2, y: 3 }, + { x: 3, y: 6 }, + ]} /> ); @@ -436,7 +511,11 @@ storiesOf('Interactions', module) yScaleType={ScaleType.Linear} xAccessor="x" yAccessors={['y']} - data={[{ x: 1, y: 2 }, { x: 2, y: 7 }, { x: 3, y: 3 }]} + data={[ + { x: 1, y: 2 }, + { x: 2, y: 7 }, + { x: 3, y: 3 }, + ]} /> ); @@ -549,7 +628,12 @@ storiesOf('Interactions', module) yScaleType={ScaleType.Linear} xAccessor="x" yAccessors={['y']} - data={[{ x: 'a', y: 2 }, { x: 'b', y: 7 }, { x: 'c', y: 3 }, { x: 'd', y: 6 }]} + data={[ + { x: 'a', y: 2 }, + { x: 'b', y: 7 }, + { x: 'c', y: 3 }, + { x: 'd', y: 6 }, + ]} /> ); @@ -654,7 +738,12 @@ storiesOf('Interactions', module) yScaleType={ScaleType.Linear} xAccessor="x" yAccessors={['y']} - data={[{ x: 0, y: 2 }, { x: 1, y: 7 }, { x: 2, y: 3 }, { x: 3, y: 6 }]} + data={[ + { x: 0, y: 2 }, + { x: 1, y: 7 }, + { x: 2, y: 3 }, + { x: 3, y: 6 }, + ]} /> ); @@ -686,7 +775,12 @@ storiesOf('Interactions', module) yScaleType={ScaleType.Linear} xAccessor="x" yAccessors={['y']} - data={[{ x: 0, y: 2 }, { x: 1, y: 7 }, { x: 2, y: 3 }, { x: 3, y: 6 }]} + data={[ + { x: 0, y: 2 }, + { x: 1, y: 7 }, + { x: 2, y: 3 }, + { x: 3, y: 6 }, + ]} /> ); diff --git a/stories/legend.tsx b/stories/legend.tsx index 00ced7c96f..4cc4cf9e49 100644 --- a/stories/legend.tsx +++ b/stories/legend.tsx @@ -166,7 +166,12 @@ storiesOf('Legend', module) yScaleType={ScaleType.Linear} xAccessor="x" yAccessors={['y']} - data={[{ x: 0, y: 2 }, { x: 1, y: 7 }, { x: 2, y: 3 }, { x: 3, y: 6 }]} + data={[ + { x: 0, y: 2 }, + { x: 1, y: 7 }, + { x: 2, y: 3 }, + { x: 3, y: 6 }, + ]} hideInLegend={hideBarSeriesInLegend} /> @@ -261,7 +271,12 @@ storiesOf('Legend', module) yScaleType={ScaleType.Linear} xAccessor="x" yAccessors={['y']} - data={[{ x: 0, y: 2 }, { x: 1, y: 100000000 }, { x: 2, y: 3 }, { x: 3, y: 6 }]} + data={[ + { x: 0, y: 2 }, + { x: 1, y: 100000000 }, + { x: 2, y: 3 }, + { x: 3, y: 6 }, + ]} /> ); diff --git a/stories/mixed.tsx b/stories/mixed.tsx index 73a4557f19..2c16000621 100644 --- a/stories/mixed.tsx +++ b/stories/mixed.tsx @@ -38,7 +38,12 @@ storiesOf('Mixed Charts', module) yScaleType={ScaleType.Linear} xAccessor="x" yAccessors={['y']} - data={[{ x: 0, y: 2 }, { x: 1, y: 7 }, { x: 2, y: 3 }, { x: 3, y: 6 }]} + data={[ + { x: 0, y: 2 }, + { x: 1, y: 7 }, + { x: 2, y: 3 }, + { x: 3, y: 6 }, + ]} /> ); @@ -69,7 +79,12 @@ storiesOf('Mixed Charts', module) yScaleType={ScaleType.Linear} xAccessor="x" yAccessors={['y']} - data={[{ x: 0, y: 2.5 }, { x: 1, y: 7 }, { x: 2, y: 3 }, { x: 3, y: 6 }]} + data={[ + { x: 0, y: 2.5 }, + { x: 1, y: 7 }, + { x: 2, y: 3 }, + { x: 3, y: 6 }, + ]} /> ); @@ -109,7 +129,12 @@ storiesOf('Mixed Charts', module) yAccessors={['y']} splitSeriesAccessors={['g']} stackAccessors={['x']} - data={[{ x: 0, y: 2 }, { x: 1, y: 7 }, { x: 2, y: 3 }, { x: 3, y: 6 }]} + data={[ + { x: 0, y: 2 }, + { x: 1, y: 7 }, + { x: 2, y: 3 }, + { x: 3, y: 6 }, + ]} yScaleToDataExtent={false} /> ); }) .add('[test] - bar/lines linear', () => { - const data1 = [[1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 4], [7, 3], [8, 2], [9, 1]]; - const data2 = [[1, 5], [2, 4], [3, 3], [4, 2], [5, 1], [6, 2], [7, 3], [8, 4], [9, 5]]; + const data1 = [ + [1, 1], + [2, 2], + [3, 3], + [4, 4], + [5, 5], + [6, 4], + [7, 3], + [8, 2], + [9, 1], + ]; + const data2 = [ + [1, 5], + [2, 4], + [3, 3], + [4, 2], + [5, 1], + [6, 2], + [7, 3], + [8, 4], + [9, 5], + ]; return ( diff --git a/stories/rotations.tsx b/stories/rotations.tsx index d24c764cd0..09a3664432 100644 --- a/stories/rotations.tsx +++ b/stories/rotations.tsx @@ -52,7 +52,12 @@ storiesOf('Rotations', module) yScaleType={ScaleType.Linear} xAccessor="x" yAccessors={['y']} - data={[{ x: 'a', y: 1 }, { x: 'b', y: 2 }, { x: 'c', y: 3 }, { x: 'd', y: 4 }]} + data={[ + { x: 'a', y: 1 }, + { x: 'b', y: 2 }, + { x: 'c', y: 3 }, + { x: 'd', y: 4 }, + ]} /> ); @@ -71,7 +76,12 @@ storiesOf('Rotations', module) yScaleType={ScaleType.Linear} xAccessor="x" yAccessors={['y']} - data={[{ x: 'a', y: 1 }, { x: 'b', y: 2 }, { x: 'c', y: 3 }, { x: 'd', y: 4 }]} + data={[ + { x: 'a', y: 1 }, + { x: 'b', y: 2 }, + { x: 'c', y: 3 }, + { x: 'd', y: 4 }, + ]} /> ); @@ -90,7 +100,12 @@ storiesOf('Rotations', module) yScaleType={ScaleType.Linear} xAccessor="x" yAccessors={['y']} - data={[{ x: 'a', y: 1 }, { x: 'b', y: 2 }, { x: 'c', y: 3 }, { x: 'd', y: 4 }]} + data={[ + { x: 'a', y: 1 }, + { x: 'b', y: 2 }, + { x: 'c', y: 3 }, + { x: 'd', y: 4 }, + ]} /> ); @@ -109,7 +124,12 @@ storiesOf('Rotations', module) yScaleType={ScaleType.Linear} xAccessor="x" yAccessors={['y']} - data={[{ x: 'a', y: 1 }, { x: 'b', y: 2 }, { x: 'c', y: 3 }, { x: 'd', y: 4 }]} + data={[ + { x: 'a', y: 1 }, + { x: 'b', y: 2 }, + { x: 'c', y: 3 }, + { x: 'd', y: 4 }, + ]} /> ); @@ -128,7 +148,12 @@ storiesOf('Rotations', module) yScaleType={ScaleType.Linear} xAccessor="x" yAccessors={['y']} - data={[{ x: 'a', y: 1 }, { x: 'b', y: 2 }, { x: 'c', y: 3 }, { x: 'd', y: 4 }]} + data={[ + { x: 'a', y: 1 }, + { x: 'b', y: 2 }, + { x: 'c', y: 3 }, + { x: 'd', y: 4 }, + ]} /> ); @@ -147,7 +172,12 @@ storiesOf('Rotations', module) yScaleType={ScaleType.Linear} xAccessor="x" yAccessors={['y']} - data={[{ x: 0, y: 1 }, { x: 1, y: 2 }, { x: 2, y: 3 }, { x: 3, y: 4 }]} + data={[ + { x: 0, y: 1 }, + { x: 1, y: 2 }, + { x: 2, y: 3 }, + { x: 3, y: 4 }, + ]} /> ); @@ -166,7 +196,12 @@ storiesOf('Rotations', module) yScaleType={ScaleType.Linear} xAccessor="x" yAccessors={['y']} - data={[{ x: 0, y: 1 }, { x: 1, y: 2 }, { x: 2, y: 3 }, { x: 3, y: 4 }]} + data={[ + { x: 0, y: 1 }, + { x: 1, y: 2 }, + { x: 2, y: 3 }, + { x: 3, y: 4 }, + ]} /> ); @@ -185,7 +220,12 @@ storiesOf('Rotations', module) yScaleType={ScaleType.Linear} xAccessor="x" yAccessors={['y']} - data={[{ x: 0, y: 1 }, { x: 1, y: 2 }, { x: 2, y: 3 }, { x: 3, y: 4 }]} + data={[ + { x: 0, y: 1 }, + { x: 1, y: 2 }, + { x: 2, y: 3 }, + { x: 3, y: 4 }, + ]} /> ); @@ -204,7 +244,12 @@ storiesOf('Rotations', module) yScaleType={ScaleType.Linear} xAccessor="x" yAccessors={['y']} - data={[{ x: 0, y: 1 }, { x: 1, y: 2 }, { x: 2, y: 3 }, { x: 3, y: 4 }]} + data={[ + { x: 0, y: 1 }, + { x: 1, y: 2 }, + { x: 2, y: 3 }, + { x: 3, y: 4 }, + ]} /> ); diff --git a/stories/scales.tsx b/stories/scales.tsx index e1f73a1f30..765f700ddb 100644 --- a/stories/scales.tsx +++ b/stories/scales.tsx @@ -226,7 +226,13 @@ storiesOf('Scales', module) xAccessor={0} yAccessors={[1]} timeZone={'utc-6'} - data={[[1, 62], [2, 56], [3, 41], [4, 62], [5, 90]]} + data={[ + [1, 62], + [2, 56], + [3, 41], + [4, 62], + [5, 90], + ]} /> ); diff --git a/stories/styling.tsx b/stories/styling.tsx index d6c5d4646d..c14ee4aa66 100644 --- a/stories/styling.tsx +++ b/stories/styling.tsx @@ -245,7 +245,12 @@ storiesOf('Stylings', module) yScaleType={ScaleType.Linear} xAccessor="x" yAccessors={['y']} - data={[{ x: 0, y: 2 }, { x: 1, y: 7 }, { x: 2, y: 3 }, { x: 3, y: 6 }]} + data={[ + { x: 0, y: 2 }, + { x: 1, y: 7 }, + { x: 2, y: 3 }, + { x: 3, y: 6 }, + ]} /> ); @@ -299,7 +304,12 @@ storiesOf('Stylings', module) yScaleType={ScaleType.Linear} xAccessor="x" yAccessors={['y']} - data={[{ x: 0, y: 2 }, { x: 1, y: 7 }, { x: 2, y: 3 }, { x: 3, y: 6 }]} + data={[ + { x: 0, y: 2 }, + { x: 1, y: 7 }, + { x: 2, y: 3 }, + { x: 3, y: 6 }, + ]} /> ); @@ -664,7 +674,12 @@ storiesOf('Stylings', module) xAccessor="x" yAccessors={['y']} customSeriesColors={lineSeriesColorAccessor} - data={[{ x: 0, y: 3 }, { x: 1, y: 2 }, { x: 2, y: 4 }, { x: 3, y: 10 }]} + data={[ + { x: 0, y: 3 }, + { x: 1, y: 2 }, + { x: 2, y: 4 }, + { x: 3, y: 10 }, + ]} /> ); @@ -741,7 +756,12 @@ storiesOf('Stylings', module) lineSeriesStyle: generateLineSeriesStyleKnobs('Chart Global Theme', 'chartTheme'), }; - const dataset1 = [{ x: 0, y: 3 }, { x: 1, y: 2 }, { x: 2, y: 4 }, { x: 3, y: 10 }]; + const dataset1 = [ + { x: 0, y: 3 }, + { x: 1, y: 2 }, + { x: 2, y: 4 }, + { x: 3, y: 10 }, + ]; const dataset2 = dataset1.map((datum) => ({ ...datum, y: datum.y - 1 })); const dataset3 = dataset1.map((datum) => ({ ...datum, y: datum.y - 2 })); @@ -794,7 +814,12 @@ storiesOf('Stylings', module) areaSeriesStyle: generateAreaSeriesStyleKnobs('Chart Global Theme', 'chartTheme'), }; - const dataset1 = [{ x: 0, y: 3 }, { x: 1, y: 6 }, { x: 2, y: 4 }, { x: 3, y: 10 }]; + const dataset1 = [ + { x: 0, y: 3 }, + { x: 1, y: 6 }, + { x: 2, y: 4 }, + { x: 3, y: 10 }, + ]; const dataset2 = dataset1.map((datum) => ({ ...datum, y: datum.y - 1 })); const dataset3 = dataset1.map((datum) => ({ ...datum, y: datum.y - 2 })); @@ -996,7 +1021,12 @@ storiesOf('Stylings', module) yScaleType={ScaleType.Linear} xAccessor="x" yAccessors={['y']} - data={[{ x: 0, y: 2 }, { x: 1, y: 7 }, { x: 2, y: 3 }, { x: 3, y: 6 }]} + data={[ + { x: 0, y: 2 }, + { x: 1, y: 7 }, + { x: 2, y: 3 }, + { x: 3, y: 6 }, + ]} /> ); @@ -1045,7 +1075,12 @@ storiesOf('Stylings', module) xAccessor="x" yAccessors={['y']} styleAccessor={hasThreshold ? barStyleAccessor : undefined} - data={[{ x: 0, y: 2 }, { x: 1, y: 7 }, { x: 2, y: 3 }, { x: 3, y: 6 }]} + data={[ + { x: 0, y: 2 }, + { x: 1, y: 7 }, + { x: 2, y: 3 }, + { x: 3, y: 6 }, + ]} /> ); diff --git a/yarn.lock b/yarn.lock index 893f5e9490..3f9297f7b2 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7039,10 +7039,10 @@ escodegen@^1.11.0, escodegen@^1.9.1: optionalDependencies: source-map "~0.6.1" -eslint-config-prettier@^6.7.0: - version "6.7.0" - resolved "https://registry.yarnpkg.com/eslint-config-prettier/-/eslint-config-prettier-6.7.0.tgz#9a876952e12df2b284adbd3440994bf1f39dfbb9" - integrity sha512-FamQVKM3jjUVwhG4hEMnbtsq7xOIDm+SY5iBPfR8gKsJoAB2IQnNF+bk1+8Fy44Nq7PPJaLvkRxILYdJWoguKQ== +eslint-config-prettier@^6.9.0: + version "6.9.0" + resolved "https://registry.yarnpkg.com/eslint-config-prettier/-/eslint-config-prettier-6.9.0.tgz#430d24822e82f7deb1e22a435bfa3999fae4ad64" + integrity sha512-k4E14HBtcLv0uqThaI6I/n1LEqROp8XaPu6SO9Z32u5NlGRC07Enu1Bh2KEFw4FNHbekH8yzbIU9kUGxbiGmCA== dependencies: get-stdin "^6.0.0" @@ -7086,10 +7086,10 @@ eslint-plugin-jest@^23.0.4: dependencies: "@typescript-eslint/experimental-utils" "^2.5.0" -eslint-plugin-prettier@^3.1.0: - version "3.1.1" - resolved "https://registry.yarnpkg.com/eslint-plugin-prettier/-/eslint-plugin-prettier-3.1.1.tgz#507b8562410d02a03f0ddc949c616f877852f2ba" - integrity sha512-A+TZuHZ0KU0cnn56/9mfR7/KjUJ9QNVXUhwvRFSR7PGPe0zQR6PTkmyqg1AtUUEOzTqeRsUwyKFh0oVZKVCrtA== +eslint-plugin-prettier@^3.1.2: + version "3.1.2" + resolved "https://registry.yarnpkg.com/eslint-plugin-prettier/-/eslint-plugin-prettier-3.1.2.tgz#432e5a667666ab84ce72f945c72f77d996a5c9ba" + integrity sha512-GlolCC9y3XZfv3RQfwGew7NnuFDKsfI4lbvRK+PIIo23SFH+LemGs4cKwzAaRa+Mdb+lQO/STaIayno8T5sJJA== dependencies: prettier-linter-helpers "^1.0.0" @@ -13157,12 +13157,7 @@ prettier-linter-helpers@^1.0.0: dependencies: fast-diff "^1.1.2" -prettier@1.16.4: - version "1.16.4" - resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.16.4.tgz#73e37e73e018ad2db9c76742e2647e21790c9717" - integrity sha512-ZzWuos7TI5CKUeQAtFd6Zhm2s6EpAD/ZLApIhsF9pRvRtM1RFo61dM/4MSRUA0SuLugA/zgrZD8m0BaY46Og7g== - -prettier@^1.16.4: +prettier@^1.16.4, prettier@^1.19.1: version "1.19.1" resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.19.1.tgz#f7d7f5ff8a9cd872a7be4ca142095956a60797cb" integrity sha512-s7PoyDv/II1ObgQunCbB9PdLmUcBZcnWOcxDh7O0N/UwDEsHyqkW+Qh28jW+mVuCdx7gLB0BotYI1Y6uI9iyew==