diff --git a/.eslintrc.js b/.eslintrc.js index 62bc4a24c2..784397af6e 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -6,6 +6,8 @@ module.exports = { 'plugin:@typescript-eslint/recommended', 'plugin:@typescript-eslint/recommended-requiring-type-checking', 'airbnb/hooks', + 'prettier/@typescript-eslint', + 'plugin:prettier/recommended', 'plugin:eslint-comments/recommended', 'plugin:jest/recommended', 'plugin:promise/recommended', @@ -16,7 +18,18 @@ module.exports = { 'plugin:import/warnings', 'plugin:import/typescript', ], - plugins: ['@typescript-eslint', 'eslint-comments', 'jest', 'import', 'promise', 'unicorn', 'header', 'react-hooks', 'jsx-a11y'], + plugins: [ + '@typescript-eslint', + 'eslint-comments', + 'jest', + 'import', + 'promise', + 'unicorn', + 'header', + 'react-hooks', + 'jsx-a11y', + 'prettier', + ], rules: { /** * depricated to be deleted @@ -24,6 +37,25 @@ module.exports = { // https://github.com/typescript-eslint/typescript-eslint/issues/2077 '@typescript-eslint/camelcase': 0, + /** + ***************************************** + * Rules with high processing demand + ***************************************** + */ + 'import/no-restricted-paths': + process.env.NODE_ENV === 'production' + ? [ + 'error', + { + zones: [ + { target: './src', from: './src/index.ts' }, + { target: './src', from: './', except: ['./src', './node_modules/'] }, + ], + }, + ] + : 0, + 'import/namespace': process.env.NODE_ENV === 'production' ? 2 : 0, + /** ***************************************** * Rules to consider adding/fixing later @@ -99,14 +131,18 @@ module.exports = { ExportDeclaration: { consistent: true }, }, ], - quotes: ['error', 'single'], semi: ['error', 'always'], // https://github.com/typescript-eslint/typescript-eslint/issues/1824 - indent: ['error', 2, { - SwitchCase: 1, - MemberExpression: 1, - offsetTernaryExpressions: true, - }], + // TODO: Add back once indent ts rule is fixed + // indent: [ + // 'error', + // 2, + // { + // SwitchCase: 1, + // MemberExpression: 1, + // offsetTernaryExpressions: true, + // }, + // ], 'max-len': [ 'warn', { @@ -144,7 +180,6 @@ module.exports = { '@typescript-eslint/indent': 0, '@typescript-eslint/no-inferrable-types': 0, '@typescript-eslint/ban-ts-comment': 1, - '@typescript-eslint/space-before-function-paren': [2, 'never'], '@typescript-eslint/no-unused-vars': [ 'error', { @@ -166,22 +201,15 @@ module.exports = { /* * import plugin */ - 'import/order': ['error', { - 'newlines-between': 'always', - groups: [ - 'builtin', - 'external', - ['parent', 'sibling', 'index', 'internal'], - ], - alphabetize: { order: 'asc', caseInsensitive: true }, // todo replace with directory gradient ordering - }], - 'import/no-unresolved': ['error', { ignore: ['theme_dark.scss', 'theme_light.scss'] }], - 'import/no-restricted-paths': [ + 'import/order': [ 'error', { - zones: [{ target: './src', from: './src/index.ts' }, { target: './src', from: './', except: ['./src', './node_modules/'] }], + 'newlines-between': 'always', + groups: ['builtin', 'external', ['parent', 'sibling', 'index', 'internal']], + alphabetize: { order: 'asc', caseInsensitive: true }, // todo replace with directory gradient ordering }, ], + 'import/no-unresolved': ['error', { ignore: ['theme_dark.scss', 'theme_light.scss'] }], // https://basarat.gitbooks.io/typescript/docs/tips/defaultIsBad.html 'import/prefer-default-export': 0, // Limit usage in development directories @@ -192,6 +220,10 @@ module.exports = { */ 'react/jsx-curly-brace-presence': ['error', { props: 'never', children: 'never' }], 'react/prop-types': 0, + 'react/sort-comp': 0, + 'react/jsx-one-expression-per-line': 0, + 'react/jsx-curly-newline': 0, + 'react/jsx-indent': 0, // Too restrictive: https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/destructuring-assignment.md 'react/destructuring-assignment': 0, // No jsx extension: https://github.com/facebook/create-react-app/issues/87#issuecomment-234627904 @@ -347,6 +379,12 @@ module.exports = { ], }, }, + { + files: ['.playground/**/*.ts?(x)'], + rules: { + 'react/prefer-stateless-function': 0, + }, + }, { files: ['*.test.ts?(x)'], rules: { diff --git a/.prettierignore b/.prettierignore index 681cfc802b..c974fde9ad 100644 --- a/.prettierignore +++ b/.prettierignore @@ -1,9 +1,5 @@ *.md *.mdx -*.ts -*.tsx -*.js -*.jsx .out/ .idea/ .vscode/ diff --git a/.storybook-docs/webpack.config.js b/.storybook-docs/webpack.config.js index 3f4735625f..353dd2e190 100644 --- a/.storybook-docs/webpack.config.js +++ b/.storybook-docs/webpack.config.js @@ -36,7 +36,7 @@ const scssLoaders = [ 'sass-loader', ]; -module.exports = async({ config }) => { +module.exports = async ({ config }) => { // config.plugins.push(new webpack.EnvironmentPlugin({ RNG_SEED: null })); // Replace default css rules with nonce diff --git a/.storybook/webpack.config.js b/.storybook/webpack.config.js index 5afa19b3a8..024719f3fe 100644 --- a/.storybook/webpack.config.js +++ b/.storybook/webpack.config.js @@ -40,26 +40,28 @@ const scssLoaders = [ const MAX_CYCLES = 0; let numCyclesDetected = 0; -module.exports = async({ config }) => { +module.exports = async ({ config }) => { config.plugins.push(new webpack.EnvironmentPlugin({ RNG_SEED: null })); - config.plugins.push(new CircularDependencyPlugin({ - onStart() { - numCyclesDetected = 0; - }, - onDetected({ paths, compilation }) { - if (!/^node_modules\/.+/.test(paths[0])) { - numCyclesDetected++; - compilation.warnings.push(new Error(paths.join(' -> '))); - } - }, - onEnd({ compilation }) { - if (numCyclesDetected > MAX_CYCLES) { - compilation.errors.push(new Error( - `Detected ${numCyclesDetected} cycles which exceeds configured limit of ${MAX_CYCLES}` - )); - } - }, - })); + config.plugins.push( + new CircularDependencyPlugin({ + onStart() { + numCyclesDetected = 0; + }, + onDetected({ paths, compilation }) { + if (!/^node_modules\/.+/.test(paths[0])) { + numCyclesDetected++; + compilation.warnings.push(new Error(paths.join(' -> '))); + } + }, + onEnd({ compilation }) { + if (numCyclesDetected > MAX_CYCLES) { + compilation.errors.push( + new Error(`Detected ${numCyclesDetected} cycles which exceeds configured limit of ${MAX_CYCLES}`), + ); + } + }, + }), + ); config.module.rules.push({ test: /\.tsx?$/, diff --git a/browsers/browsers.test.ts b/browsers/browsers.test.ts index 8369b2491d..a0439ca0c4 100644 --- a/browsers/browsers.test.ts +++ b/browsers/browsers.test.ts @@ -27,7 +27,7 @@ jest.setTimeout(30000); let driver: webdriver.WebDriver; describe('smoke tests', () => { - beforeAll(async() => { + beforeAll(async () => { let capabilities: webdriver.Capabilities | null = null; switch (process.env.BROWSER || 'chrome') { case 'ie': @@ -59,11 +59,11 @@ describe('smoke tests', () => { } }); - afterAll(async() => { + afterAll(async () => { await driver.quit(); }); - test('elastic-chart element smoke test', async() => { + test('elastic-chart element smoke test', async () => { await driver.get('http://localhost:8080'); await driver.sleep(5000); diff --git a/browsers/setup.js b/browsers/setup.js index 15b6e6174f..c1574afe5a 100644 --- a/browsers/setup.js +++ b/browsers/setup.js @@ -24,17 +24,18 @@ const WebpackDevServer = require('webpack-dev-server'); const config = require(path.join(__dirname, '..', '.playground', 'webpack.config.js')); -module.exports = async() => await new Promise((resolve, reject) => { - const compiler = webpack(config); - const server = new WebpackDevServer(compiler); - compiler.hooks.done.tap('done', () => { - resolve(); - global.__WP_SERVER__ = server; - }); +module.exports = async () => + await new Promise((resolve, reject) => { + const compiler = webpack(config); + const server = new WebpackDevServer(compiler); + compiler.hooks.done.tap('done', () => { + resolve(); + global.__WP_SERVER__ = server; + }); - server.listen(8080, 'localhost', (err) => { - if (err) { - reject(err); - } + server.listen(8080, 'localhost', (err) => { + if (err) { + reject(err); + } + }); }); -}); diff --git a/browsers/teardown.js b/browsers/teardown.js index a776142d35..b72650a4d9 100644 --- a/browsers/teardown.js +++ b/browsers/teardown.js @@ -17,6 +17,6 @@ * under the License. */ -module.exports = async() => { +module.exports = async () => { await global.__WP_SERVER__.close(); }; diff --git a/integration/helpers.ts b/integration/helpers.ts index e933cbf849..babc5aab93 100644 --- a/integration/helpers.ts +++ b/integration/helpers.ts @@ -72,9 +72,7 @@ function encodeString(string: string) { */ const storiesToSkip: Record = { // Interactions: ['Some story name'], - Legend: [ - 'Actions', - ], + Legend: ['Actions'], }; /** diff --git a/integration/jest_puppeteer.config.js b/integration/jest_puppeteer.config.js index fdb35f5111..a2e1638846 100644 --- a/integration/jest_puppeteer.config.js +++ b/integration/jest_puppeteer.config.js @@ -52,7 +52,7 @@ const customConfig = { }, } : { - // https://github.com/gidztech/jest-puppeteer-docker/issues/24 + // https://github.com/gidztech/jest-puppeteer-docker/issues/24 chromiumFlags: [], // for docker chromium options connect: { ...sharedConfig, diff --git a/integration/page_objects/common.ts b/integration/page_objects/common.ts index f2e9483ada..9650769edd 100644 --- a/integration/page_objects/common.ts +++ b/integration/page_objects/common.ts @@ -332,7 +332,7 @@ class CommonPage { mousePosition: MousePosition, options?: Omit, ) { - const action = async() => await this.moveMouseRelativeToDOMElement(mousePosition, this.chartSelector); + const action = async () => await this.moveMouseRelativeToDOMElement(mousePosition, this.chartSelector); await this.expectChartAtUrlToMatchScreenshot(url, { ...options, action, @@ -353,7 +353,7 @@ class CommonPage { end: MousePosition, options?: Omit, ) { - const action = async() => await this.dragMouseRelativeToDOMElement(start, end, this.chartSelector); + const action = async () => await this.dragMouseRelativeToDOMElement(start, end, this.chartSelector); await this.expectChartAtUrlToMatchScreenshot(url, { ...options, action, diff --git a/integration/tests/all.test.ts b/integration/tests/all.test.ts index 1c365012c6..8a9658003d 100644 --- a/integration/tests/all.test.ts +++ b/integration/tests/all.test.ts @@ -30,7 +30,7 @@ const storyGroups = getStorybookInfo(); describe('Baseline Visual tests for all stories', () => { describe.each(storyGroups)('%s', (_group, encodedGroup, stories) => { describe.each(stories)('%s', (_title, encodedTitle, delay) => { - it('visually looks correct', async() => { + it('visually looks correct', async () => { const url = `http://localhost:9001?id=${encodedGroup}--${encodedTitle}`; await common.expectChartAtUrlToMatchScreenshot(url, { delay }); }); diff --git a/integration/tests/annotations_stories.test.ts b/integration/tests/annotations_stories.test.ts index 6b8f62b649..f2d9da4d54 100644 --- a/integration/tests/annotations_stories.test.ts +++ b/integration/tests/annotations_stories.test.ts @@ -21,22 +21,22 @@ import { common } from '../page_objects'; describe('Annotations stories', () => { describe('rotation', () => { - it('rotation - 0', async() => { + it('rotation - 0', async () => { await common.expectChartAtUrlToMatchScreenshot( 'http://localhost:9001/?path=/story/annotations-lines--single-bar-histogram&knob-debug=&knob-chartRotation=0', ); }); - it('rotation - 90', async() => { + it('rotation - 90', async () => { await common.expectChartAtUrlToMatchScreenshot( 'http://localhost:9001/?path=/story/annotations-lines--single-bar-histogram&knob-debug=&knob-chartRotation=90', ); }); - it('rotation - negative 90', async() => { + it('rotation - negative 90', async () => { await common.expectChartAtUrlToMatchScreenshot( 'http://localhost:9001/?path=/story/annotations-lines--single-bar-histogram&knob-debug=&knob-chartRotation=-90', ); }); - it('rotation - 180', async() => { + it('rotation - 180', async () => { await common.expectChartAtUrlToMatchScreenshot( 'http://localhost:9001/?path=/story/annotations-lines--single-bar-histogram&knob-debug=&knob-chartRotation=180', ); diff --git a/integration/tests/area_stories.test.ts b/integration/tests/area_stories.test.ts index 336ae1fbd6..09780779f5 100644 --- a/integration/tests/area_stories.test.ts +++ b/integration/tests/area_stories.test.ts @@ -20,14 +20,14 @@ import { common } from '../page_objects'; describe('Area series stories', () => { - it('stacked as NOT percentage', async() => { + it('stacked as NOT percentage', async () => { await common.expectChartAtUrlToMatchScreenshot( 'http://localhost:9001/?path=/story/area-chart--stacked-percentage&knob-stacked as percentage=', ); }); describe('accessorFormats', () => { - it('should show custom format', async() => { + it('should show custom format', async () => { await common.expectChartAtUrlToMatchScreenshot( 'http://localhost:9001/?path=/story/area-chart--band-area&knob-scale to extent=&knob-y0AccessorFormat= [min]&knob-y1AccessorFormat= [max]', ); @@ -37,7 +37,7 @@ describe('Area series stories', () => { describe('scale to extents', () => { describe('domain.fit is true', () => { const trueUrl = 'http://localhost:9001/?path=/story/area-chart--stacked-band&knob-fit Y domain=true'; - it('should show correct extents - Banded', async() => { + it('should show correct extents - Banded', async () => { await common.expectChartAtUrlToMatchScreenshot(trueUrl); }); }); @@ -45,7 +45,7 @@ describe('Area series stories', () => { describe('domain.fit is false', () => { const falseUrl = 'http://localhost:9001/?path=/story/area-chart--stacked-band&knob-fit Y domain=false'; - it('should show correct extents - Banded', async() => { + it('should show correct extents - Banded', async () => { await common.expectChartAtUrlToMatchScreenshot(falseUrl); }); }); diff --git a/integration/tests/axis_stories.test.ts b/integration/tests/axis_stories.test.ts index d30dbdf83c..bddc5c1504 100644 --- a/integration/tests/axis_stories.test.ts +++ b/integration/tests/axis_stories.test.ts @@ -20,52 +20,52 @@ import { common } from '../page_objects'; describe('Axis stories', () => { - it('should render proper tick count', async() => { + it('should render proper tick count', async () => { await common.expectChartAtUrlToMatchScreenshot( 'http://localhost:9001/?path=/story/axes--basic&knob-Tick Label Padding=0&knob-debug=&knob-Bottom overlap labels=&knob-Bottom overlap ticks=true&knob-Number of ticks on bottom=20&knob-Left overlap labels=&knob-Left overlap ticks=true&knob-Number of ticks on left=10', ); }); - it('should render proper tick count with showOverlappingLabels', async() => { + it('should render proper tick count with showOverlappingLabels', async () => { await common.expectChartAtUrlToMatchScreenshot( 'http://localhost:9001/?path=/story/axes--basic&knob-Tick Label Padding=0&knob-debug=&knob-Bottom overlap labels_Bottom Axis=true&knob-Bottom overlap ticks_Bottom Axis=true&knob-Number of ticks on bottom_Bottom Axis=20&knob-Left overlap labels_Left Axis=&knob-Left overlap ticks_Left Axis=true&knob-Number of ticks on left_Left Axis=10', ); }); - it('should render ticks with varied rotations', async() => { + it('should render ticks with varied rotations', async () => { await common.expectChartAtUrlToMatchScreenshot( 'http://localhost:9001/?path=/story/axes--tick-label-rotation&knob-Tick Label Padding=0&knob-bottom axis tick label rotation=47&knob-hide bottom axis=&knob-left axis tick label rotation=-56&knob-hide left axis=&knob-top axis tick label rotation=-59&knob-hide top axis=&knob-right axis tick label rotation=30&knob-hide right axis=&knob-debug=', ); }); - it('should hide bottom axis', async() => { + it('should hide bottom axis', async () => { await common.expectChartAtUrlToMatchScreenshot( 'http://localhost:9001/?path=/story/axes--tick-label-rotation&knob-Tick Label Padding=0&knob-bottom axis tick label rotation=47&knob-hide bottom axis=true&knob-left axis tick label rotation=-56&knob-hide left axis=&knob-top axis tick label rotation=-59&knob-hide top axis=&knob-right axis tick label rotation=30&knob-hide right axis=&knob-debug=', ); }); - it('should hide top axis', async() => { + it('should hide top axis', async () => { await common.expectChartAtUrlToMatchScreenshot( 'http://localhost:9001/?path=/story/axes--tick-label-rotation&knob-Tick Label Padding=0&knob-bottom axis tick label rotation=47&knob-hide bottom axis=&knob-left axis tick label rotation=-56&knob-hide left axis=&knob-top axis tick label rotation=-59&knob-hide top axis=true&knob-right axis tick label rotation=30&knob-hide right axis=&knob-debug=', ); }); - it('should hide left axis', async() => { + it('should hide left axis', async () => { await common.expectChartAtUrlToMatchScreenshot( 'http://localhost:9001/?path=/story/axes--tick-label-rotation&knob-Tick Label Padding=0&knob-bottom axis tick label rotation=47&knob-hide bottom axis=&knob-left axis tick label rotation=-56&knob-hide left axis=true&knob-top axis tick label rotation=-59&knob-hide top axis=&knob-right axis tick label rotation=30&knob-hide right axis=&knob-debug=', ); }); - it('should hide right axis', async() => { + it('should hide right axis', async () => { await common.expectChartAtUrlToMatchScreenshot( 'http://localhost:9001/?path=/story/axes--tick-label-rotation&knob-Tick Label Padding=0&knob-bottom axis tick label rotation=47&knob-hide bottom axis=&knob-left axis tick label rotation=-56&knob-hide left axis=&knob-top axis tick label rotation=-59&knob-hide top axis=&knob-right axis tick label rotation=30&knob-hide right axis=true&knob-debug=', ); }); - it('should render tick padding', async() => { + it('should render tick padding', async () => { await common.expectChartAtUrlToMatchScreenshot( 'http://localhost:9001/?path=/story/axes--many-tick-labels&knob-Tick Label Padding=60', ); }); - it('should render with domain constraints', async() => { + it('should render with domain constraints', async () => { await common.expectChartAtUrlToMatchScreenshot( 'http://localhost:9001/?path=/story/axes--custom-mixed&knob-left min=2&knob-xDomain max=2', ); }); - it('should hide consecutive duplicate ticks', async() => { + it('should hide consecutive duplicate ticks', async () => { await common.expectChartAtUrlToMatchScreenshot( 'http://localhost:9001/?path=/story/axes--duplicate-ticks&knob-formatter=hourly&knob-Show duplicate ticks in x axis=true', ); diff --git a/integration/tests/bar_stories.test.ts b/integration/tests/bar_stories.test.ts index e780de553a..f401d2b0c3 100644 --- a/integration/tests/bar_stories.test.ts +++ b/integration/tests/bar_stories.test.ts @@ -21,7 +21,7 @@ import { common } from '../page_objects'; describe('Bar series stories', () => { describe('[test] switch ordinal/linear x axis', () => { - it('using ordinal x axis', async() => { + it('using ordinal x axis', async () => { await common.expectChartAtUrlToMatchScreenshot( 'http://localhost:9001/?path=/story/bar-chart--test-switch-ordinal-linear-axis&knob-scaleType=ordinal', ); @@ -29,7 +29,7 @@ describe('Bar series stories', () => { }); describe('[test] discover', () => { - it('using no custom minInterval', async() => { + it('using no custom minInterval', async () => { await common.expectChartAtUrlToMatchScreenshot( 'http://localhost:9001/?path=/story/bar-chart--test-discover&knob-use custom minInterval of 30s=', ); @@ -38,22 +38,22 @@ describe('Bar series stories', () => { describe('[test] histogram mode (linear)', () => { describe('enableHistogramMode is true', () => { - it('rotation - 0', async() => { + it('rotation - 0', async () => { await common.expectChartAtUrlToMatchScreenshot( 'http://localhost:9001/?path=/story/bar-chart--test-histogram-mode-linear&knob-chartRotation=0&knob-bars padding=0.25&knob-histogram padding=0.05&knob-other series=line&knob-point series alignment=center&knob-hasHistogramBarSeries=&knob-debug=true&knob-bars-1 enableHistogramMode=true&knob-bars-2 enableHistogramMode=', ); }); - it('rotation - 90', async() => { + it('rotation - 90', async () => { await common.expectChartAtUrlToMatchScreenshot( 'http://localhost:9001/?path=/story/bar-chart--test-histogram-mode-linear&knob-chartRotation=90&knob-bars padding=0.25&knob-histogram padding=0.05&knob-other series=line&knob-point series alignment=center&knob-hasHistogramBarSeries=&knob-debug=true&knob-bars-1 enableHistogramMode=true&knob-bars-2 enableHistogramMode=', ); }); - it('rotation - negative 90', async() => { + it('rotation - negative 90', async () => { await common.expectChartAtUrlToMatchScreenshot( 'http://localhost:9001/?path=/story/bar-chart--test-histogram-mode-linear&knob-chartRotation=-90&knob-bars padding=0.25&knob-histogram padding=0.05&knob-other series=line&knob-point series alignment=center&knob-hasHistogramBarSeries=&knob-debug=true&knob-bars-1 enableHistogramMode=true&knob-bars-2 enableHistogramMode=', ); }); - it('rotation - 180', async() => { + it('rotation - 180', async () => { await common.expectChartAtUrlToMatchScreenshot( 'http://localhost:9001/?path=/story/bar-chart--test-histogram-mode-linear&knob-chartRotation=180&knob-bars padding=0.25&knob-histogram padding=0.05&knob-other series=line&knob-point series alignment=center&knob-hasHistogramBarSeries=&knob-debug=true&knob-bars-1 enableHistogramMode=true&knob-bars-2 enableHistogramMode=', ); @@ -61,22 +61,22 @@ describe('Bar series stories', () => { }); describe('enableHistogramMode is false', () => { - it('rotation - 0', async() => { + it('rotation - 0', async () => { await common.expectChartAtUrlToMatchScreenshot( 'http://localhost:9001/?path=/story/bar-chart--test-histogram-mode-linear&knob-chartRotation=0&knob-bars padding=0.25&knob-histogram padding=0.05&knob-other series=line&knob-point series alignment=center&knob-hasHistogramBarSeries=&knob-debug=true&knob-bars-1 enableHistogramMode=&knob-bars-2 enableHistogramMode=', ); }); - it('rotation - 90', async() => { + it('rotation - 90', async () => { await common.expectChartAtUrlToMatchScreenshot( 'http://localhost:9001/?path=/story/bar-chart--test-histogram-mode-linear&knob-chartRotation=90&knob-bars padding=0.25&knob-histogram padding=0.05&knob-other series=line&knob-point series alignment=center&knob-hasHistogramBarSeries=&knob-debug=true&knob-bars-1 enableHistogramMode=&knob-bars-2 enableHistogramMode=', ); }); - it('rotation - negative 90', async() => { + it('rotation - negative 90', async () => { await common.expectChartAtUrlToMatchScreenshot( 'http://localhost:9001/?path=/story/bar-chart--test-histogram-mode-linear&knob-chartRotation=-90&knob-bars padding=0.25&knob-histogram padding=0.05&knob-other series=line&knob-point series alignment=center&knob-hasHistogramBarSeries=&knob-debug=true&knob-bars-1 enableHistogramMode=&knob-bars-2 enableHistogramMode=', ); }); - it('rotation - 180', async() => { + it('rotation - 180', async () => { await common.expectChartAtUrlToMatchScreenshot( 'http://localhost:9001/?path=/story/bar-chart--test-histogram-mode-linear&knob-chartRotation=180&knob-bars padding=0.25&knob-histogram padding=0.05&knob-other series=line&knob-point series alignment=center&knob-hasHistogramBarSeries=&knob-debug=true&knob-bars-1 enableHistogramMode=&knob-bars-2 enableHistogramMode=', ); @@ -84,17 +84,17 @@ describe('Bar series stories', () => { }); describe('point alignment', () => { - it('start', async() => { + it('start', async () => { await common.expectChartAtUrlToMatchScreenshot( 'http://localhost:9001/?path=/story/bar-chart--test-histogram-mode-linear&knob-chartRotation=-90&knob-bars padding=0.25&knob-histogram padding=0.05&knob-other series=area&knob-point series alignment=start&knob-hasHistogramBarSeries=true&knob-debug=true&knob-bars-1 enableHistogramMode=&knob-bars-2 enableHistogramMode=', ); }); - it('center', async() => { + it('center', async () => { await common.expectChartAtUrlToMatchScreenshot( 'http://localhost:9001/?path=/story/bar-chart--test-histogram-mode-linear&knob-chartRotation=-90&knob-bars padding=0.25&knob-histogram padding=0.05&knob-other series=area&knob-point series alignment=center&knob-hasHistogramBarSeries=true&knob-debug=true&knob-bars-1 enableHistogramMode=&knob-bars-2 enableHistogramMode=', ); }); - it('end', async() => { + it('end', async () => { await common.expectChartAtUrlToMatchScreenshot( 'http://localhost:9001/?path=/story/bar-chart--test-histogram-mode-linear&knob-chartRotation=-90&knob-bars padding=0.25&knob-histogram padding=0.05&knob-other series=area&knob-point series alignment=end&knob-hasHistogramBarSeries=true&knob-debug=true&knob-bars-1 enableHistogramMode=&knob-bars-2 enableHistogramMode=', ); @@ -104,22 +104,22 @@ describe('Bar series stories', () => { describe('[test] histogram mode (ordinal)', () => { describe('enableHistogramMode is false, hasHistogramBarSeries is false', () => { - it('rotation - 0', async() => { + it('rotation - 0', async () => { await common.expectChartAtUrlToMatchScreenshot( 'http://localhost:9001/?path=/story/bar-chart--test-histogram-mode-ordinal&knob-chartRotation=0&knob-bars padding=0.25&knob-hasHistogramBarSeries=&knob-debug=true&knob-bars-1 enableHistogramMode=true&knob-bars-2 enableHistogramMode=', ); }); - it('rotation - 90', async() => { + it('rotation - 90', async () => { await common.expectChartAtUrlToMatchScreenshot( 'http://localhost:9001/?path=/story/bar-chart--test-histogram-mode-ordinal&knob-chartRotation=90&knob-bars padding=0.25&knob-hasHistogramBarSeries=&knob-debug=true&knob-bars-1 enableHistogramMode=true&knob-bars-2 enableHistogramMode=', ); }); - it('rotation - negative 90', async() => { + it('rotation - negative 90', async () => { await common.expectChartAtUrlToMatchScreenshot( 'http://localhost:9001/?path=/story/bar-chart--test-histogram-mode-ordinal&knob-chartRotation=-90&knob-bars padding=0.25&knob-hasHistogramBarSeries=&knob-debug=true&knob-bars-1 enableHistogramMode=true&knob-bars-2 enableHistogramMode=', ); }); - it('rotation - 180', async() => { + it('rotation - 180', async () => { await common.expectChartAtUrlToMatchScreenshot( 'http://localhost:9001/?path=/story/bar-chart--test-histogram-mode-ordinal&knob-chartRotation=180&knob-bars padding=0.25&knob-hasHistogramBarSeries=&knob-debug=true&knob-bars-1 enableHistogramMode=true&knob-bars-2 enableHistogramMode=', ); @@ -127,22 +127,22 @@ describe('Bar series stories', () => { }); describe('enableHistogramMode is true, hasHistogramBarSeries is true', () => { - it('rotation - 0', async() => { + it('rotation - 0', async () => { await common.expectChartAtUrlToMatchScreenshot( 'http://localhost:9001/?path=/story/bar-chart--test-histogram-mode-ordinal&knob-chartRotation=0&knob-bars padding=0.25&knob-hasHistogramBarSeries=true&knob-debug=true&knob-bars-1 enableHistogramMode=true&knob-bars-2 enableHistogramMode=', ); }); - it('rotation - 90', async() => { + it('rotation - 90', async () => { await common.expectChartAtUrlToMatchScreenshot( 'http://localhost:9001/?path=/story/bar-chart--test-histogram-mode-ordinal&knob-chartRotation=90&knob-bars padding=0.25&knob-hasHistogramBarSeries=true&knob-debug=true&knob-bars-1 enableHistogramMode=true&knob-bars-2 enableHistogramMode=', ); }); - it('rotation - negative 90', async() => { + it('rotation - negative 90', async () => { await common.expectChartAtUrlToMatchScreenshot( 'http://localhost:9001/?path=/story/bar-chart--test-histogram-mode-ordinal&knob-chartRotation=-90&knob-bars padding=0.25&knob-hasHistogramBarSeries=true&knob-debug=true&knob-bars-1 enableHistogramMode=true&knob-bars-2 enableHistogramMode=', ); }); - it('rotation - 180', async() => { + it('rotation - 180', async () => { await common.expectChartAtUrlToMatchScreenshot( 'http://localhost:9001/?path=/story/bar-chart--test-histogram-mode-ordinal&knob-chartRotation=180&knob-bars padding=0.25&knob-hasHistogramBarSeries=true&knob-debug=true&knob-bars-1 enableHistogramMode=true&knob-bars-2 enableHistogramMode=', ); diff --git a/integration/tests/interactions.test.ts b/integration/tests/interactions.test.ts index 487151b627..b32e3b0986 100644 --- a/integration/tests/interactions.test.ts +++ b/integration/tests/interactions.test.ts @@ -40,7 +40,7 @@ describe('Interactions', () => { (placement) => { const boundaryStr = boundary === 'default' ? '' : boundary; const url = `http://localhost:9001/?path=/story/bar-chart--test-tooltip-and-rotation&knob-Boundary Element=${boundaryStr}&knob-chartRotation=${rotation}&knob-Tooltip placement=${placement}`; - it('shows tooltip in top-left corner', async() => { + it('shows tooltip in top-left corner', async () => { await common.expectChartWithMouseAtUrlToMatchScreenshot( url, { left, top }, @@ -48,7 +48,7 @@ describe('Interactions', () => { ); }); - it('shows tooltip in top-right corner', async() => { + it('shows tooltip in top-right corner', async () => { await common.expectChartWithMouseAtUrlToMatchScreenshot( url, { right, top }, @@ -56,7 +56,7 @@ describe('Interactions', () => { ); }); - it('shows tooltip in bottom-left corner', async() => { + it('shows tooltip in bottom-left corner', async () => { await common.expectChartWithMouseAtUrlToMatchScreenshot( url, { left, bottom }, @@ -64,7 +64,7 @@ describe('Interactions', () => { ); }); - it('shows tooltip in bottom-right corner', async() => { + it('shows tooltip in bottom-right corner', async () => { await common.expectChartWithMouseAtUrlToMatchScreenshot( url, { right, bottom }, @@ -79,28 +79,28 @@ describe('Interactions', () => { describe('Hover over specific bars', () => { describe('rotation 0', () => { - it('shows tooltip on first bar group - top', async() => { + it('shows tooltip on first bar group - top', async () => { await common.expectChartWithMouseAtUrlToMatchScreenshot( 'http://localhost:9001/?path=/story/bar-chart--test-tooltip-and-rotation', { left: 50, top: 50 }, { screenshotSelector: 'body' }, ); }); - it('shows tooltip on last bar group - top', async() => { + it('shows tooltip on last bar group - top', async () => { await common.expectChartWithMouseAtUrlToMatchScreenshot( 'http://localhost:9001/?path=/story/bar-chart--test-tooltip-and-rotation', { right: 50, top: 50 }, { screenshotSelector: 'body' }, ); }); - it('shows tooltip on first bar group - bottom', async() => { + it('shows tooltip on first bar group - bottom', async () => { await common.expectChartWithMouseAtUrlToMatchScreenshot( 'http://localhost:9001/?path=/story/bar-chart--test-tooltip-and-rotation', { left: 50, bottom: 50 }, { screenshotSelector: 'body' }, ); }); - it('shows tooltip on last bar group - bottom', async() => { + it('shows tooltip on last bar group - bottom', async () => { await common.expectChartWithMouseAtUrlToMatchScreenshot( 'http://localhost:9001/?path=/story/bar-chart--test-tooltip-and-rotation', { left: 50, bottom: 50 }, @@ -110,28 +110,28 @@ describe('Interactions', () => { }); describe('rotation 90', () => { - it('shows tooltip on first bar group - top', async() => { + it('shows tooltip on first bar group - top', async () => { await common.expectChartWithMouseAtUrlToMatchScreenshot( 'http://localhost:9001/?path=/story/bar-chart--test-tooltip-and-rotation&knob-chartRotation=90', { left: 50, top: 50 }, { screenshotSelector: 'body' }, ); }); - it('shows tooltip on last bar group - top', async() => { + it('shows tooltip on last bar group - top', async () => { await common.expectChartWithMouseAtUrlToMatchScreenshot( 'http://localhost:9001/?path=/story/bar-chart--test-tooltip-and-rotation&knob-chartRotation=90', { left: 50, top: 50 }, { screenshotSelector: 'body' }, ); }); - it('shows tooltip on first bar group - bottom', async() => { + it('shows tooltip on first bar group - bottom', async () => { await common.expectChartWithMouseAtUrlToMatchScreenshot( 'http://localhost:9001/?path=/story/bar-chart--test-tooltip-and-rotation&knob-chartRotation=90', { left: 50, bottom: 50 }, { screenshotSelector: 'body' }, ); }); - it('shows tooltip on last bar group - bottom', async() => { + it('shows tooltip on last bar group - bottom', async () => { await common.expectChartWithMouseAtUrlToMatchScreenshot( 'http://localhost:9001/?path=/story/bar-chart--test-tooltip-and-rotation&knob-chartRotation=90', { right: 50, bottom: 50 }, @@ -141,14 +141,14 @@ describe('Interactions', () => { }); }); - it('should show tooltip on sunburst', async() => { + it('should show tooltip on sunburst', async () => { await common.expectChartWithMouseAtUrlToMatchScreenshot( 'http://localhost:9001/?path=/story/interactions--sunburst-slice-clicks', { left: 350, top: 100 }, ); }); - it('should render custom tooltip', async() => { + it('should render custom tooltip', async () => { await common.expectChartWithMouseAtUrlToMatchScreenshot( 'http://localhost:9001/?path=/story/bar-chart--test-tooltip-and-rotation&knob-Custom Tooltip=true&knob-Show Legend=true', { left: 330, top: 40 }, @@ -156,14 +156,14 @@ describe('Interactions', () => { ); }); - it('should render corrent tooltip for split and y accessors', async() => { + it('should render corrent tooltip for split and y accessors', async () => { await common.expectChartWithMouseAtUrlToMatchScreenshot( 'http://localhost:9001/iframe.html?id=bar-chart--bar-chart-2-y-2-g', { left: 330, top: 40 }, ); }); - it('should render corrent tooltip in dark theme', async() => { + it('should render corrent tooltip in dark theme', async () => { await common.expectChartWithMouseAtUrlToMatchScreenshot( 'http://localhost:9001/?path=/story/stylings--dark-theme', { left: 120, bottom: 80 }, @@ -172,21 +172,21 @@ describe('Interactions', () => { }); describe('brushing', () => { - it('show rectangular brush selection', async() => { + it('show rectangular brush selection', async () => { await common.expectChartWithDragAtUrlToMatchScreenshot( 'http://localhost:9001/?path=/story/interactions--brush-tool', { left: 100, top: 100 }, { left: 250, top: 250 }, ); }); - it('show y brush selection', async() => { + it('show y brush selection', async () => { await common.expectChartWithDragAtUrlToMatchScreenshot( 'http://localhost:9001/?path=/story/interactions--brush-tool&knob-brush axis=y&knob-chartRotation=0', { left: 100, top: 100 }, { left: 250, top: 250 }, ); }); - it('show x brush selection', async() => { + it('show x brush selection', async () => { await common.expectChartWithDragAtUrlToMatchScreenshot( 'http://localhost:9001/?path=/story/interactions--brush-tool&knob-brush axis=x&knob-chartRotation=0', { left: 100, top: 100 }, @@ -194,21 +194,21 @@ describe('Interactions', () => { ); }); - it('show rectangular brush selection -90 degree', async() => { + it('show rectangular brush selection -90 degree', async () => { await common.expectChartWithDragAtUrlToMatchScreenshot( 'http://localhost:9001/?path=/story/interactions--brush-tool&knob-brush axis=both&knob-chartRotation=-90', { left: 100, top: 100 }, { left: 250, top: 250 }, ); }); - it('show y brush selection -90 degree', async() => { + it('show y brush selection -90 degree', async () => { await common.expectChartWithDragAtUrlToMatchScreenshot( 'http://localhost:9001/?path=/story/interactions--brush-tool&knob-brush axis=y&knob-chartRotation=-90', { left: 100, top: 100 }, { left: 250, top: 250 }, ); }); - it('show x brush selection -90 degree', async() => { + it('show x brush selection -90 degree', async () => { await common.expectChartWithDragAtUrlToMatchScreenshot( 'http://localhost:9001/?path=/story/interactions--brush-tool&knob-brush axis=x&knob-chartRotation=-90', { left: 100, top: 100 }, @@ -218,13 +218,13 @@ describe('Interactions', () => { }); describe('Tooltip sync', () => { - it('show synced tooltips', async() => { + it('show synced tooltips', async () => { await common.expectChartWithMouseAtUrlToMatchScreenshot( 'http://localhost:9001/?path=/story/interactions--cursor-update-action', { left: 180, top: 80 }, { screenshotSelector: '#story-root', - } + }, ); }); }); diff --git a/integration/tests/legend_stories.test.ts b/integration/tests/legend_stories.test.ts index 630d78b465..5a1d684c98 100644 --- a/integration/tests/legend_stories.test.ts +++ b/integration/tests/legend_stories.test.ts @@ -20,29 +20,29 @@ import { common } from '../page_objects'; describe('Legend stories', () => { - it('should render non-split series', async() => { + it('should render non-split series', async () => { await common.expectChartAtUrlToMatchScreenshot( 'http://localhost:9001/?path=/story/legend--changing-specs&knob-split series=', ); }); - it('should hide line series legend item', async() => { + it('should hide line series legend item', async () => { await common.expectChartAtUrlToMatchScreenshot( 'http://localhost:9001/?path=/story/legend--hide-legend-items-by-series&knob-hide bar series in legend=&knob-hide line series in legend=true', ); }); - it('should hide bar series legend item', async() => { + it('should hide bar series legend item', async () => { await common.expectChartAtUrlToMatchScreenshot( 'http://localhost:9001/?path=/story/legend--hide-legend-items-by-series&knob-hide bar series in legend=true&knob-hide line series in legend=', ); }); - it('should 0 legend buffer', async() => { + it('should 0 legend buffer', async () => { await common.expectChartAtUrlToMatchScreenshot( 'http://localhost:9001/?path=/story/legend--legend-spacing-buffer&knob-legend buffer value=0', ); }); - it('should render color picker on mouse click', async() => { - const action = async() => + it('should render color picker on mouse click', async () => { + const action = async () => await common.clickMouseRelativeToDOMElement({ left: 0, top: 0 }, '.echLegendItem__color'); await common.expectElementAtUrlToMatchScreenshot( 'http://localhost:9001/?path=/story/legend--color-picker', @@ -55,15 +55,11 @@ describe('Legend stories', () => { ); }); - it('should render legend action on mouse hover', async() => { - const action = async() => - await common.moveMouseRelativeToDOMElement({ left: 30, top: 10 }, '.echLegendItem'); - await common.expectChartAtUrlToMatchScreenshot( - 'http://localhost:9001/?path=/story/legend--actions', - { - action, - delay: 200, // needed for icon to load - }, - ); + it('should render legend action on mouse hover', async () => { + const action = async () => await common.moveMouseRelativeToDOMElement({ left: 30, top: 10 }, '.echLegendItem'); + await common.expectChartAtUrlToMatchScreenshot('http://localhost:9001/?path=/story/legend--actions', { + action, + delay: 200, // needed for icon to load + }); }); }); diff --git a/integration/tests/line_stories.test.ts b/integration/tests/line_stories.test.ts index ca6c37ef89..5a690e5e50 100644 --- a/integration/tests/line_stories.test.ts +++ b/integration/tests/line_stories.test.ts @@ -21,22 +21,22 @@ import { common } from '../page_objects'; describe('Line series stories', () => { describe('rotation', () => { - it('rotation - 0', async() => { + it('rotation - 0', async () => { await common.expectChartAtUrlToMatchScreenshot( 'http://localhost:9001/?path=/story/line-chart--ordinal-with-axis&knob-chartRotation=0', ); }); - it('rotation - 90', async() => { + it('rotation - 90', async () => { await common.expectChartAtUrlToMatchScreenshot( 'http://localhost:9001/?path=/story/line-chart--ordinal-with-axis&knob-chartRotation=90', ); }); - it('rotation - negative 90', async() => { + it('rotation - negative 90', async () => { await common.expectChartAtUrlToMatchScreenshot( 'http://localhost:9001/?path=/story/line-chart--ordinal-with-axis&knob-chartRotation=-90', ); }); - it('rotation - 180', async() => { + it('rotation - 180', async () => { await common.expectChartAtUrlToMatchScreenshot( 'http://localhost:9001/?path=/story/line-chart--ordinal-with-axis&knob-chartRotation=180', ); diff --git a/integration/tests/mixed_stories.test.ts b/integration/tests/mixed_stories.test.ts index 35e719d8b6..b0715d805c 100644 --- a/integration/tests/mixed_stories.test.ts +++ b/integration/tests/mixed_stories.test.ts @@ -24,7 +24,7 @@ describe('Mixed series stories', () => { describe('Fitting functions', () => { describe('Area charts - no endValue', () => { Object.values(Fit).forEach((fitType) => { - it(`should display correct fit for type - ${fitType}`, async() => { + it(`should display correct fit for type - ${fitType}`, async () => { await common.expectChartAtUrlToMatchScreenshot( `http://localhost:9001/?path=/story/mixed-charts--fitting-functions-non-stacked-series&knob-seriesType=area&knob-dataset=all&knob-fitting function=${fitType}&knob-Curve=0&knob-End value=none&knob-Explicit value (using Fit.Explicit)=8`, ); @@ -34,7 +34,7 @@ describe('Mixed series stories', () => { describe('Area charts - endValue set to 2', () => { Object.values(Fit).forEach((fitType) => { - it(`should display correct fit for type - ${fitType}`, async() => { + it(`should display correct fit for type - ${fitType}`, async () => { await common.expectChartAtUrlToMatchScreenshot( `http://localhost:9001/?path=/story/mixed-charts--fitting-functions-non-stacked-series&knob-seriesType=area&knob-dataset=all&knob-fitting function=${fitType}&knob-Curve=0&knob-End value=2&knob-Explicit value (using Fit.Explicit)=8`, ); @@ -44,7 +44,7 @@ describe('Mixed series stories', () => { describe('Area charts - endValue set to "nearest"', () => { Object.values(Fit).forEach((fitType) => { - it(`should display correct fit for type - ${fitType}`, async() => { + it(`should display correct fit for type - ${fitType}`, async () => { await common.expectChartAtUrlToMatchScreenshot( `http://localhost:9001/?path=/story/mixed-charts--fitting-functions-non-stacked-series&knob-seriesType=area&knob-dataset=all&knob-fitting function=${fitType}&knob-Curve=0&knob-End value=nearest&knob-Explicit value (using Fit.Explicit)=8`, ); @@ -54,7 +54,7 @@ describe('Mixed series stories', () => { describe('Area charts - with curved - endValue set to 2', () => { Object.values(Fit).forEach((fitType) => { - it(`should display correct fit for type - ${fitType}`, async() => { + it(`should display correct fit for type - ${fitType}`, async () => { await common.expectChartAtUrlToMatchScreenshot( `http://localhost:9001/?path=/story/mixed-charts--fitting-functions-non-stacked-series&knob-seriesType=area&knob-dataset=all&knob-fitting function=${fitType}&knob-Curve=1&knob-End value=2&knob-Explicit value (using Fit.Explicit)=8`, ); @@ -64,7 +64,7 @@ describe('Mixed series stories', () => { describe('Area charts - Ordinal dataset - no endValue', () => { Object.values(Fit).forEach((fitType) => { - it(`should display correct fit for type - ${fitType}`, async() => { + it(`should display correct fit for type - ${fitType}`, async () => { await common.expectChartAtUrlToMatchScreenshot( `http://localhost:9001/?path=/story/mixed-charts--fitting-functions-non-stacked-series&knob-seriesType=area&knob-dataset=ordinal&knob-fitting function=${fitType}&knob-Curve=0&knob-End value=none&knob-Explicit value (using Fit.Explicit)=8`, ); @@ -74,7 +74,7 @@ describe('Mixed series stories', () => { describe('Line charts - no endValue', () => { Object.values(Fit).forEach((fitType) => { - it(`should display correct fit for type - ${fitType}`, async() => { + it(`should display correct fit for type - ${fitType}`, async () => { await common.expectChartAtUrlToMatchScreenshot( `http://localhost:9001/?path=/story/mixed-charts--fitting-functions-non-stacked-series&knob-seriesType=line&knob-dataset=all&knob-fitting function=${fitType}&knob-Curve=0&knob-End value=none&knob-Explicit value (using Fit.Explicit)=8`, ); @@ -84,7 +84,7 @@ describe('Mixed series stories', () => { describe('Line charts - endValue set to 2', () => { Object.values(Fit).forEach((fitType) => { - it(`should display correct fit for type - ${fitType}`, async() => { + it(`should display correct fit for type - ${fitType}`, async () => { await common.expectChartAtUrlToMatchScreenshot( `http://localhost:9001/?path=/story/mixed-charts--fitting-functions-non-stacked-series&knob-seriesType=line&knob-dataset=all&knob-fitting function=${fitType}&knob-Curve=0&knob-End value=2&knob-Explicit value (using Fit.Explicit)=8`, ); @@ -94,7 +94,7 @@ describe('Mixed series stories', () => { describe('Line charts - with curve - endValue set to 2', () => { Object.values(Fit).forEach((fitType) => { - it(`should display correct fit for type - ${fitType}`, async() => { + it(`should display correct fit for type - ${fitType}`, async () => { await common.expectChartAtUrlToMatchScreenshot( `http://localhost:9001/?path=/story/mixed-charts--fitting-functions-non-stacked-series&knob-seriesType=line&knob-dataset=all&knob-fitting function=${fitType}&knob-Curve=1&knob-End value=2&knob-Explicit value (using Fit.Explicit)=8`, ); @@ -103,11 +103,10 @@ describe('Mixed series stories', () => { }); }); - describe('Fitting functions - Stacked charts', () => { describe('Area charts - no endValue', () => { Object.values(Fit).forEach((fitType) => { - it(`should display correct fit for type - ${fitType}`, async() => { + it(`should display correct fit for type - ${fitType}`, async () => { await common.expectChartAtUrlToMatchScreenshot( `http://localhost:9001/?path=/story/mixed-charts--fitting-functions-stacked-series&knob-seriesType=area&knob-dataset=all&knob-fitting function=${fitType}&knob-Curve=0&knob-End value=none&knob-Explicit value (using Fit.Explicit)=8`, ); @@ -117,7 +116,7 @@ describe('Mixed series stories', () => { describe('Area charts - endValue set to 2', () => { Object.values(Fit).forEach((fitType) => { - it(`should display correct fit for type - ${fitType}`, async() => { + it(`should display correct fit for type - ${fitType}`, async () => { await common.expectChartAtUrlToMatchScreenshot( `http://localhost:9001/?path=/story/mixed-charts--fitting-functions-stacked-series&knob-seriesType=area&knob-dataset=all&knob-fitting function=${fitType}&knob-Curve=0&knob-End value=2&knob-Explicit value (using Fit.Explicit)=8`, ); @@ -127,7 +126,7 @@ describe('Mixed series stories', () => { describe('Area charts - endValue set to "nearest"', () => { Object.values(Fit).forEach((fitType) => { - it(`should display correct fit for type - ${fitType}`, async() => { + it(`should display correct fit for type - ${fitType}`, async () => { await common.expectChartAtUrlToMatchScreenshot( `http://localhost:9001/?path=/story/mixed-charts--fitting-functions-stacked-series&knob-seriesType=area&knob-dataset=all&knob-fitting function=${fitType}&knob-Curve=0&knob-End value=nearest&knob-Explicit value (using Fit.Explicit)=8`, ); @@ -137,7 +136,7 @@ describe('Mixed series stories', () => { describe('Area charts - with curved - endValue set to 2', () => { Object.values(Fit).forEach((fitType) => { - it(`should display correct fit for type - ${fitType}`, async() => { + it(`should display correct fit for type - ${fitType}`, async () => { await common.expectChartAtUrlToMatchScreenshot( `http://localhost:9001/?path=/story/mixed-charts--fitting-functions-stacked-series&knob-seriesType=area&knob-dataset=all&knob-fitting function=${fitType}&knob-Curve=1&knob-End value=2&knob-Explicit value (using Fit.Explicit)=8`, ); @@ -147,7 +146,7 @@ describe('Mixed series stories', () => { describe('Area charts - Ordinal dataset - no endValue', () => { Object.values(Fit).forEach((fitType) => { - it(`should display correct fit for type - ${fitType}`, async() => { + it(`should display correct fit for type - ${fitType}`, async () => { await common.expectChartAtUrlToMatchScreenshot( `http://localhost:9001/?path=/story/mixed-charts--fitting-functions-stacked-series&knob-seriesType=area&knob-dataset=ordinal&knob-fitting function=${fitType}&knob-Curve=0&knob-End value=none&knob-Explicit value (using Fit.Explicit)=8`, ); @@ -159,7 +158,7 @@ describe('Mixed series stories', () => { describe('Fitting functions - Stacked charts - as percentage', () => { describe('Area charts - no endValue', () => { Object.values(Fit).forEach((fitType) => { - it(`should display correct fit for type - ${fitType}`, async() => { + it(`should display correct fit for type - ${fitType}`, async () => { await common.expectChartAtUrlToMatchScreenshot( `http://localhost:9001/?path=/story/mixed-charts--fitting-functions-stacked-series&knob-seriesType=area&knob-dataset=all&knob-fitting function=${fitType}&knob-Curve=0&knob-End value=none&knob-Explicit value (using Fit.Explicit)=8&knob-stackMode=percentage`, ); @@ -169,7 +168,7 @@ describe('Mixed series stories', () => { describe('Area charts - endValue set to 2', () => { Object.values(Fit).forEach((fitType) => { - it(`should display correct fit for type - ${fitType}`, async() => { + it(`should display correct fit for type - ${fitType}`, async () => { await common.expectChartAtUrlToMatchScreenshot( `http://localhost:9001/?path=/story/mixed-charts--fitting-functions-stacked-series&knob-seriesType=area&knob-dataset=all&knob-fitting function=${fitType}&knob-Curve=0&knob-End value=2&knob-Explicit value (using Fit.Explicit)=8&knob-stackMode=percentage`, ); @@ -179,7 +178,7 @@ describe('Mixed series stories', () => { describe('Area charts - endValue set to "nearest"', () => { Object.values(Fit).forEach((fitType) => { - it(`should display correct fit for type - ${fitType}`, async() => { + it(`should display correct fit for type - ${fitType}`, async () => { await common.expectChartAtUrlToMatchScreenshot( `http://localhost:9001/?path=/story/mixed-charts--fitting-functions-stacked-series&knob-seriesType=area&knob-dataset=all&knob-fitting function=${fitType}&knob-Curve=0&knob-End value=nearest&knob-Explicit value (using Fit.Explicit)=8&knob-stackMode=percentage`, ); @@ -189,7 +188,7 @@ describe('Mixed series stories', () => { describe('Area charts - with curved - endValue set to 2', () => { Object.values(Fit).forEach((fitType) => { - it(`should display correct fit for type - ${fitType}`, async() => { + it(`should display correct fit for type - ${fitType}`, async () => { await common.expectChartAtUrlToMatchScreenshot( `http://localhost:9001/?path=/story/mixed-charts--fitting-functions-stacked-series&knob-seriesType=area&knob-dataset=all&knob-fitting function=${fitType}&knob-Curve=1&knob-End value=2&knob-Explicit value (using Fit.Explicit)=8&knob-stackMode=percentage`, ); @@ -199,7 +198,7 @@ describe('Mixed series stories', () => { describe('Area charts - Ordinal dataset - no endValue', () => { Object.values(Fit).forEach((fitType) => { - it(`should display correct fit for type - ${fitType}`, async() => { + it(`should display correct fit for type - ${fitType}`, async () => { await common.expectChartAtUrlToMatchScreenshot( `http://localhost:9001/?path=/story/mixed-charts--fitting-functions-stacked-series&knob-seriesType=area&knob-dataset=ordinal&knob-fitting function=${fitType}&knob-Curve=0&knob-End value=none&knob-Explicit value (using Fit.Explicit)=8&knob-stackMode=percentage`, ); diff --git a/scripts/concat_sass.js b/scripts/concat_sass.js index 0b34edb95b..d5ce4181d0 100644 --- a/scripts/concat_sass.js +++ b/scripts/concat_sass.js @@ -47,7 +47,5 @@ function recursiveReadSCSS(branchId, branch) { function removeImportsFromFile(fileContent) { const lines = fileContent.split(/\r\n|\r|\n/g); - return lines - .filter((line) => !line.match(/@import\s/i)) - .join('\n'); + return lines.filter((line) => !line.match(/@import\s/i)).join('\n'); } diff --git a/scripts/setup_enzyme.ts b/scripts/setup_enzyme.ts index 916f7291a1..01a49f41db 100644 --- a/scripts/setup_enzyme.ts +++ b/scripts/setup_enzyme.ts @@ -44,9 +44,9 @@ class ResizeObserverMock { this.callback([{ contentRect: { width: 200, height: 200 } }]); } - unobserve() { } + unobserve() {} - disconnect() { } + disconnect() {} } // @ts-ignore diff --git a/src/chart_types/goal_chart/renderer/canvas/canvas_renderers.ts b/src/chart_types/goal_chart/renderer/canvas/canvas_renderers.ts index 58fdc6b3cc..56f3d584b0 100644 --- a/src/chart_types/goal_chart/renderer/canvas/canvas_renderers.ts +++ b/src/chart_types/goal_chart/renderer/canvas/canvas_renderers.ts @@ -104,11 +104,12 @@ export function renderCanvas2d( const minSize = Math.min(config.width, config.height); - const referenceSize = Math.min( - circular ? referenceCircularSizeCap : referenceBulletSizeCap, - circular ? minSize : (vertical ? config.height : config.width), - ) - * (1 - 2 * marginRatio); + const referenceSize = + Math.min( + circular ? referenceCircularSizeCap : referenceBulletSizeCap, + circular ? minSize : vertical ? config.height : config.width, + ) * + (1 - 2 * marginRatio); const barThickness = Math.min( circular ? baselineArcThickness : baselineBarThickness, @@ -227,117 +228,118 @@ export function renderCanvas2d( // clear the canvas (ctx: CanvasRenderingContext2D) => clearCanvas(ctx, 200000, 200000), - (ctx: CanvasRenderingContext2D) => withContext(ctx, (ctx) => { - const fullSize = referenceSize; - const labelSize = fullSize / 2; - const pxRangeFrom = -fullSize / 2 + (circular || vertical ? 0 : labelSize); - const pxRangeTo = fullSize / 2 + (!circular && vertical ? -2 * labelFontSize : 0); - const pxRangeMid = (pxRangeFrom + pxRangeTo) / 2; - const pxRange = pxRangeTo - pxRangeFrom; + (ctx: CanvasRenderingContext2D) => + withContext(ctx, (ctx) => { + const fullSize = referenceSize; + const labelSize = fullSize / 2; + const pxRangeFrom = -fullSize / 2 + (circular || vertical ? 0 : labelSize); + const pxRangeTo = fullSize / 2 + (!circular && vertical ? -2 * labelFontSize : 0); + const pxRangeMid = (pxRangeFrom + pxRangeTo) / 2; + const pxRange = pxRangeTo - pxRangeFrom; - const domainExtent = domain[1] - domain[0]; + const domainExtent = domain[1] - domain[0]; - const linearScale = (x: number) => pxRangeFrom + (pxRange * (x - domain[0])) / domainExtent; + const linearScale = (x: number) => pxRangeFrom + (pxRange * (x - domain[0])) / domainExtent; - const { angleStart, angleEnd } = config; - const angleRange = angleEnd - angleStart; - const angleScale = (x: number) => angleStart + (angleRange * (x - domain[0])) / domainExtent; - const clockwise = angleStart > angleEnd; // todo refine this crude approach + const { angleStart, angleEnd } = config; + const angleRange = angleEnd - angleStart; + const angleScale = (x: number) => angleStart + (angleRange * (x - domain[0])) / domainExtent; + const clockwise = angleStart > angleEnd; // todo refine this crude approach - geoms - .slice() - .sort((a, b) => a.order - b.order) - .forEach(({ landmarks, aes }) => { - const at = get(landmarks, 'at', ''); - const from = get(landmarks, 'from', ''); - const to = get(landmarks, 'to', ''); - const textAlign = get(aes, 'textAlign', ''); - const textBaseline = get(aes, 'textBaseline', ''); - const fontShape = get(aes, 'fontShape', ''); - const axisNormalOffset = get(aes, 'axisNormalOffset', 0); - const axisTangentOffset = get(aes, 'axisTangentOffset', 0); - const lineWidth = get(aes, 'lineWidth', 0); - const strokeStyle = get(aes, 'fillColor', ''); - withContext(ctx, (ctx) => { - ctx.beginPath(); - if (circular) { - if (aes.shape === 'line') { - ctx.lineWidth = lineWidth; - ctx.strokeStyle = strokeStyle; - if (at) { - ctx.arc( - pxRangeMid, - 0, - r + axisNormalOffset, - angleScale(data[at].value) + Math.PI / 360, - angleScale(data[at].value) - Math.PI / 360, - true, - ); - } else { - const dataClockwise = data[from].value < data[to].value; - ctx.arc( - pxRangeMid, - 0, - r, - angleScale(data[from].value), - angleScale(data[to].value), - clockwise === dataClockwise, + geoms + .slice() + .sort((a, b) => a.order - b.order) + .forEach(({ landmarks, aes }) => { + const at = get(landmarks, 'at', ''); + const from = get(landmarks, 'from', ''); + const to = get(landmarks, 'to', ''); + const textAlign = get(aes, 'textAlign', ''); + const textBaseline = get(aes, 'textBaseline', ''); + const fontShape = get(aes, 'fontShape', ''); + const axisNormalOffset = get(aes, 'axisNormalOffset', 0); + const axisTangentOffset = get(aes, 'axisTangentOffset', 0); + const lineWidth = get(aes, 'lineWidth', 0); + const strokeStyle = get(aes, 'fillColor', ''); + withContext(ctx, (ctx) => { + ctx.beginPath(); + if (circular) { + if (aes.shape === 'line') { + ctx.lineWidth = lineWidth; + ctx.strokeStyle = strokeStyle; + if (at) { + ctx.arc( + pxRangeMid, + 0, + r + axisNormalOffset, + angleScale(data[at].value) + Math.PI / 360, + angleScale(data[at].value) - Math.PI / 360, + true, + ); + } else { + const dataClockwise = data[from].value < data[to].value; + ctx.arc( + pxRangeMid, + 0, + r, + angleScale(data[from].value), + angleScale(data[to].value), + clockwise === dataClockwise, + ); + } + } else if (aes.shape === 'text') { + const label = at.slice(0, 5) === 'label'; + const central = at.slice(0, 7) === 'central'; + ctx.textAlign = 'center'; + ctx.textBaseline = label || central ? textBaseline : 'middle'; + ctx.font = cssFontShorthand( + fontShape, + label ? labelFontSize : central ? centralFontSize : tickFontSize, ); + ctx.scale(1, -1); + const angle = angleScale(data[at].value); + if (label) { + ctx.translate(0, r); + } else if (!central) { + ctx.translate( + (r - GOLDEN_RATIO * barThickness) * Math.cos(angle), + -(r - GOLDEN_RATIO * barThickness) * Math.sin(angle), + ); + } + ctx.fillText(data[at].text, 0, 0); } - } else if (aes.shape === 'text') { - const label = at.slice(0, 5) === 'label'; - const central = at.slice(0, 7) === 'central'; - ctx.textAlign = 'center'; - ctx.textBaseline = label || central ? textBaseline : 'middle'; - ctx.font = cssFontShorthand( - fontShape, - label ? labelFontSize : (central ? centralFontSize : tickFontSize), + } else { + ctx.translate( + vertical ? axisNormalOffset : axisTangentOffset, + vertical ? axisTangentOffset : axisNormalOffset, ); - ctx.scale(1, -1); - const angle = angleScale(data[at].value); - if (label) { - ctx.translate(0, r); - } else if (!central) { - ctx.translate( - (r - GOLDEN_RATIO * barThickness) * Math.cos(angle), - -(r - GOLDEN_RATIO * barThickness) * Math.sin(angle), - ); - } - ctx.fillText(data[at].text, 0, 0); - } - } else { - ctx.translate( - vertical ? axisNormalOffset : axisTangentOffset, - vertical ? axisTangentOffset : axisNormalOffset, - ); - const atPx = data[at] && linearScale(data[at].value); - if (aes.shape === 'line') { - ctx.lineWidth = lineWidth; - ctx.strokeStyle = aes.fillColor; - if (at) { - const atFromPx = atPx - 1; - const atToPx = atPx + 1; - ctx.moveTo(vertical ? 0 : atFromPx, vertical ? atFromPx : 0); - ctx.lineTo(vertical ? 0 : atToPx, vertical ? atToPx : 0); - } else { - const fromPx = linearScale(data[from].value); - const toPx = linearScale(data[to].value); - ctx.moveTo(vertical ? 0 : fromPx, vertical ? fromPx : 0); - ctx.lineTo(vertical ? 0 : toPx, vertical ? toPx : 0); + const atPx = data[at] && linearScale(data[at].value); + if (aes.shape === 'line') { + ctx.lineWidth = lineWidth; + ctx.strokeStyle = aes.fillColor; + if (at) { + const atFromPx = atPx - 1; + const atToPx = atPx + 1; + ctx.moveTo(vertical ? 0 : atFromPx, vertical ? atFromPx : 0); + ctx.lineTo(vertical ? 0 : atToPx, vertical ? atToPx : 0); + } else { + const fromPx = linearScale(data[from].value); + const toPx = linearScale(data[to].value); + ctx.moveTo(vertical ? 0 : fromPx, vertical ? fromPx : 0); + ctx.lineTo(vertical ? 0 : toPx, vertical ? toPx : 0); + } + } else if (aes.shape === 'text') { + ctx.textAlign = textAlign; + ctx.textBaseline = textBaseline; + ctx.font = cssFontShorthand(fontShape, tickFontSize); + ctx.scale(1, -1); + ctx.translate(vertical ? 0 : atPx, vertical ? -atPx : 0); + ctx.fillText(data[at].text, 0, 0); } - } else if (aes.shape === 'text') { - ctx.textAlign = textAlign; - ctx.textBaseline = textBaseline; - ctx.font = cssFontShorthand(fontShape, tickFontSize); - ctx.scale(1, -1); - ctx.translate(vertical ? 0 : atPx, vertical ? -atPx : 0); - ctx.fillText(data[at].text, 0, 0); } - } - ctx.stroke(); + ctx.stroke(); + }); }); - }); - }), + }), ]); }); } diff --git a/src/chart_types/partition_chart/layout/config/config.ts b/src/chart_types/partition_chart/layout/config/config.ts index 995cfcf1ee..74fdae77a3 100644 --- a/src/chart_types/partition_chart/layout/config/config.ts +++ b/src/chart_types/partition_chart/layout/config/config.ts @@ -50,10 +50,10 @@ function defaultFormatter(d: number): string { return Math.abs(d) >= 10000000 || Math.abs(d) < 0.001 ? d.toExponential(Math.min(2, Math.max(0, significantDigitCount(d) - 1))) : d.toLocaleString(void 0, { - maximumSignificantDigits: 4, - maximumFractionDigits: 3, - useGrouping: true, - }); + maximumSignificantDigits: 4, + maximumFractionDigits: 3, + useGrouping: true, + }); } export function percentFormatter(d: number): string { diff --git a/src/chart_types/partition_chart/layout/types/types.ts b/src/chart_types/partition_chart/layout/types/types.ts index 31cbb7582d..9e27b6ed72 100644 --- a/src/chart_types/partition_chart/layout/types/types.ts +++ b/src/chart_types/partition_chart/layout/types/types.ts @@ -23,7 +23,24 @@ import { ArrayEntry } from '../utils/group_by_rollup'; export const FONT_VARIANTS = Object.freeze(['normal', 'small-caps'] as const); export type FontVariant = typeof FONT_VARIANTS[number]; -export const FONT_WEIGHTS = Object.freeze([100, 200, 300, 400, 500, 600, 700, 800, 900, 'normal', 'bold', 'lighter', 'bolder', 'inherit', 'initial', 'unset'] as const); +export const FONT_WEIGHTS = Object.freeze([ + 100, + 200, + 300, + 400, + 500, + 600, + 700, + 800, + 900, + 'normal', + 'bold', + 'lighter', + 'bolder', + 'inherit', + 'initial', + 'unset', +] as const); export type FontWeight = typeof FONT_WEIGHTS[number]; export type NumericFontWeight = number & typeof FONT_WEIGHTS[number]; diff --git a/src/chart_types/partition_chart/layout/utils/calcs.ts b/src/chart_types/partition_chart/layout/utils/calcs.ts index 7809d44e27..12f8548bce 100644 --- a/src/chart_types/partition_chart/layout/utils/calcs.ts +++ b/src/chart_types/partition_chart/layout/utils/calcs.ts @@ -39,8 +39,8 @@ export function addOpacity(hexColorString: string, opacity: Ratio) { // todo roll some proper utility that can handle "rgb(...)", "rgba(...)", "red", {r, g, b} etc. return opacity === 1 ? hexColorString - : hexColorString.slice(0, 7) - + (hexColorString.slice(7).length === 0 || parseInt(hexColorString.slice(7, 2), 16) === 255 + : hexColorString.slice(0, 7) + + (hexColorString.slice(7).length === 0 || parseInt(hexColorString.slice(7, 2), 16) === 255 ? `00${Math.round(opacity * 255).toString(16)}`.slice(-2) // color was of full opacity : `00${Math.round((parseInt(hexColorString.slice(7, 2), 16) / 255) * opacity * 255).toString(16)}`.slice(-2)); } @@ -153,21 +153,23 @@ export function getTextColorIfTextInvertible( const { r: tr, g: tg, b: tb, opacity: to } = stringToRGB(textColor); if (!textContrast) { return inverseForContrast - ? (to === undefined - ? `rgb(${255 - tr}, ${255 - tg}, ${255 - tb})` - : `rgba(${255 - tr}, ${255 - tg}, ${255 - tb}, ${to})`) + ? to === undefined + ? `rgb(${255 - tr}, ${255 - tg}, ${255 - tb})` + : `rgba(${255 - tr}, ${255 - tg}, ${255 - tb}, ${to})` : textColor; - } if (textContrast === true && typeof textContrast !== 'number') { + } + if (textContrast === true && typeof textContrast !== 'number') { return inverseForContrast - ? (to === undefined - ? makeHighContrastColor(`rgb(${255 - tr}, ${255 - tg}, ${255 - tb})`, backgroundColor) - : makeHighContrastColor(`rgba(${255 - tr}, ${255 - tg}, ${255 - tb}, ${to})`, backgroundColor)) + ? to === undefined + ? makeHighContrastColor(`rgb(${255 - tr}, ${255 - tg}, ${255 - tb})`, backgroundColor) + : makeHighContrastColor(`rgba(${255 - tr}, ${255 - tg}, ${255 - tb}, ${to})`, backgroundColor) : makeHighContrastColor(textColor, backgroundColor); - } if (typeof textContrast === 'number') { + } + if (typeof textContrast === 'number') { return inverseForContrast - ? (to === undefined - ? makeHighContrastColor(`rgb(${255 - tr}, ${255 - tg}, ${255 - tb})`, backgroundColor, textContrast) - : makeHighContrastColor(`rgba(${255 - tr}, ${255 - tg}, ${255 - tb}, ${to})`, backgroundColor, textContrast)) + ? to === undefined + ? makeHighContrastColor(`rgb(${255 - tr}, ${255 - tg}, ${255 - tb})`, backgroundColor, textContrast) + : makeHighContrastColor(`rgba(${255 - tr}, ${255 - tg}, ${255 - tb}, ${to})`, backgroundColor, textContrast) : makeHighContrastColor(textColor, backgroundColor, textContrast); } } diff --git a/src/chart_types/partition_chart/layout/viewmodel/fill_text_layout.test.ts b/src/chart_types/partition_chart/layout/viewmodel/fill_text_layout.test.ts index dfcb853ad2..0fcb6ee9a6 100644 --- a/src/chart_types/partition_chart/layout/viewmodel/fill_text_layout.test.ts +++ b/src/chart_types/partition_chart/layout/viewmodel/fill_text_layout.test.ts @@ -264,10 +264,10 @@ describe('Test that getRectangleRowGeometry works with:', () => { rowAnchorX: 0, rowAnchorY: -( ( - 100 - - smallLinePitch * (totalRowCount2 - 1 - rowIndex) - - padding.bottom - - smallFontSize * 0.05 + 100 - + smallLinePitch * (totalRowCount2 - 1 - rowIndex) - + padding.bottom - + smallFontSize * 0.05 ) /* 0.05 = 5%: default overhang multiplier */ ), }); diff --git a/src/chart_types/partition_chart/layout/viewmodel/fill_text_layout.ts b/src/chart_types/partition_chart/layout/viewmodel/fill_text_layout.ts index 4da4cf1a0d..ec696054f6 100644 --- a/src/chart_types/partition_chart/layout/viewmodel/fill_text_layout.ts +++ b/src/chart_types/partition_chart/layout/viewmodel/fill_text_layout.ts @@ -129,14 +129,15 @@ export function ringSectorConstruction(config: Config, innerRadius: Radius, ring outerCircline, ...(fullCircle ? [] : [sectorStartCircle, sectorEndCircle]), ]; - const rectangleCirclines = outerRadiusFromRectangleWidth === Infinity && outerRadiusFromRectanglHeight === Infinity - ? [] - : [ - { x: INFINITY_RADIUS - outerRadiusFromRectangleWidth, y: 0, r: INFINITY_RADIUS, inside: true }, - { x: -INFINITY_RADIUS + outerRadiusFromRectangleWidth, y: 0, r: INFINITY_RADIUS, inside: true }, - { x: 0, y: INFINITY_RADIUS - outerRadiusFromRectanglHeight, r: INFINITY_RADIUS, inside: true }, - { x: 0, y: -INFINITY_RADIUS + outerRadiusFromRectanglHeight, r: INFINITY_RADIUS, inside: true }, - ]; + const rectangleCirclines = + outerRadiusFromRectangleWidth === Infinity && outerRadiusFromRectanglHeight === Infinity + ? [] + : [ + { x: INFINITY_RADIUS - outerRadiusFromRectangleWidth, y: 0, r: INFINITY_RADIUS, inside: true }, + { x: -INFINITY_RADIUS + outerRadiusFromRectangleWidth, y: 0, r: INFINITY_RADIUS, inside: true }, + { x: 0, y: INFINITY_RADIUS - outerRadiusFromRectanglHeight, r: INFINITY_RADIUS, inside: true }, + { x: 0, y: -INFINITY_RADIUS + outerRadiusFromRectanglHeight, r: INFINITY_RADIUS, inside: true }, + ]; return [...sectorCirclines, ...rectangleCirclines]; }; } @@ -169,9 +170,7 @@ export const getSectorRowGeometry: GetShapeRowGeometry = fontSize, rotation, ) => { - const offset = (totalRowCount / 2) * fontSize - + fontSize / 2 - - linePitch * rowIndex; + const offset = (totalRowCount / 2) * fontSize + fontSize / 2 - linePitch * rowIndex; const topCircline = makeRowCircline(cx, cy, offset, rotation, fontSize, 1); const bottomCircline = makeRowCircline(cx, cy, offset, rotation, fontSize, -1); @@ -226,12 +225,13 @@ export const getRectangleRowGeometry: GetShapeRowGeometry padding, ) => { const defaultPad: Pixels = 2; - const { top, right, bottom, left } = typeof padding === 'number' - ? { top: padding, right: padding, bottom: padding, left: padding } - : { - ...{ top: defaultPad, right: defaultPad, bottom: defaultPad, left: defaultPad }, - ...padding, - }; + const { top, right, bottom, left } = + typeof padding === 'number' + ? { top: padding, right: padding, bottom: padding, left: padding } + : { + ...{ top: defaultPad, right: defaultPad, bottom: defaultPad, left: defaultPad }, + ...padding, + }; const overhang = 0.05; const topPaddingAdjustment = fontSize < 6 ? 0 : Math.max(1, Math.min(2, fontSize / 16)); @@ -263,8 +263,8 @@ export const getRectangleRowGeometry: GetShapeRowGeometry function rowSetComplete(rowSet: RowSet, measuredBoxes: RowBox[]) { return ( - !measuredBoxes.length - && !rowSet.rows.some( + !measuredBoxes.length && + !rowSet.rows.some( (r) => isNaN(r.length) || r.rowWords.length === 0 || r.rowWords.every((rw) => rw.text.length === 0), ) ); @@ -399,9 +399,9 @@ function fill( const layer = layers[node.depth - 1] || {}; const verticalAlignment = middleAlign ? VerticalAlignments.middle - : (node.depth < layers.length - ? VerticalAlignments.bottom - : VerticalAlignments.top); + : node.depth < layers.length + ? VerticalAlignments.bottom + : VerticalAlignments.top; const fontSizes = allFontSizes[Math.min(node.depth, allFontSizes.length) - 1]; const { textColor, @@ -633,7 +633,8 @@ function getRowSet( export function inSectorRotation(horizontalTextEnforcer: number, horizontalTextAngleThreshold: number) { return (node: ShapeTreeNode): Radian => { let rotation = trueBearingToStandardPositionAngle((node.x0 + node.x1) / 2); - if (Math.abs(node.x1 - node.x0) > horizontalTextAngleThreshold && horizontalTextEnforcer > 0) rotation *= 1 - horizontalTextEnforcer; + if (Math.abs(node.x1 - node.x0) > horizontalTextAngleThreshold && horizontalTextEnforcer > 0) + rotation *= 1 - horizontalTextEnforcer; if (TAU / 4 < rotation && rotation < (3 * TAU) / 4) rotation = wrapToTau(rotation - TAU / 2); return rotation; }; diff --git a/src/chart_types/partition_chart/layout/viewmodel/link_text_layout.ts b/src/chart_types/partition_chart/layout/viewmodel/link_text_layout.ts index 901969dfb5..893cd7406e 100644 --- a/src/chart_types/partition_chart/layout/viewmodel/link_text_layout.ts +++ b/src/chart_types/partition_chart/layout/viewmodel/link_text_layout.ts @@ -61,7 +61,9 @@ export function linkTextLayout( const yRelativeIncrement = Math.sin(linkLabel.stemAngle) * linkLabel.minimumStemLength; const rowPitch = linkLabel.fontSize + linkLabel.spacing; // determine the ideal contrast color for the link labels - const validBackgroundColor = isColorValid(containerBackgroundColor) ? containerBackgroundColor : 'rgba(255, 255, 255, 0)'; + const validBackgroundColor = isColorValid(containerBackgroundColor) + ? containerBackgroundColor + : 'rgba(255, 255, 255, 0)'; const contrastTextColor = containerBackgroundColor ? makeHighContrastColor(linkLabel.textColor, validBackgroundColor) : linkLabel.textColor; @@ -144,12 +146,13 @@ export function linkTextLayout( ? rectWidth - diskCenter.x - translateX - widthAdjustment : diskCenter.x + translateX - widthAdjustment, ); - const { text, width, verticalOffset } = linkLabel.fontSize / 2 <= cy + diskCenter.y && cy + diskCenter.y <= rectHeight - linkLabel.fontSize / 2 - ? fitText(measure, labelText, allottedLabelWidth, linkLabel.fontSize, { - ...labelFontSpec, - text: labelText, - }) - : { text: '', width: 0, verticalOffset: 0 }; + const { text, width, verticalOffset } = + linkLabel.fontSize / 2 <= cy + diskCenter.y && cy + diskCenter.y <= rectHeight - linkLabel.fontSize / 2 + ? fitText(measure, labelText, allottedLabelWidth, linkLabel.fontSize, { + ...labelFontSpec, + text: labelText, + }) + : { text: '', width: 0, verticalOffset: 0 }; const linkLabels: PointTuples = [ [x0, y0], [stemFromX, stemFromY], diff --git a/src/chart_types/partition_chart/layout/viewmodel/viewmodel.ts b/src/chart_types/partition_chart/layout/viewmodel/viewmodel.ts index 454fca2a30..d3f5fbc0a5 100644 --- a/src/chart_types/partition_chart/layout/viewmodel/viewmodel.ts +++ b/src/chart_types/partition_chart/layout/viewmodel/viewmodel.ts @@ -17,7 +17,6 @@ * under the License. */ - import { StrokeStyle, ValueFormatter, Color } from '../../../../utils/commons'; import { Layer } from '../../specs'; import { percentValueGetter } from '../config/config'; @@ -52,10 +51,16 @@ import { import { trueBearingToStandardPositionAngle } from '../utils/math'; import { sunburst } from '../utils/sunburst'; import { getTopPadding, treemap } from '../utils/treemap'; -import { fillTextLayout, getRectangleRowGeometry, ringSectorConstruction, getSectorRowGeometry, inSectorRotation, nodeId } from './fill_text_layout'; +import { + fillTextLayout, + getRectangleRowGeometry, + ringSectorConstruction, + getSectorRowGeometry, + inSectorRotation, + nodeId, +} from './fill_text_layout'; import { linkTextLayout } from './link_text_layout'; - function grooveAccessor(n: ArrayEntry) { return entryValue(n).depth > 1 ? 1 : [0, 2][entryValue(n).depth]; } @@ -79,10 +84,7 @@ function sectorFillOrigins(fillOutside: boolean) { const divider = 10; const innerBias = fillOutside ? 9 : 1; const outerBias = divider - innerBias; - const radius = (innerBias * ringSectorInnerRadius(node) - + outerBias * ringSectorOuterRadius(node) - ) - / divider; + const radius = (innerBias * ringSectorInnerRadius(node) + outerBias * ringSectorOuterRadius(node)) / divider; const cx = Math.cos(trueBearingToStandardPositionAngle(midAngle)) * radius; const cy = Math.sin(trueBearingToStandardPositionAngle(midAngle)) * radius; return [cx, cy]; @@ -265,11 +267,11 @@ export function shapeViewModel( containerBackgroundColor, ) : fillTextLayout( - ringSectorConstruction(config, innerRadius, ringThickness), - getSectorRowGeometry, - inSectorRotation(config.horizontalTextEnforcer, config.horizontalTextAngleThreshold), - containerBackgroundColor, - ); + ringSectorConstruction(config, innerRadius, ringThickness), + getSectorRowGeometry, + inSectorRotation(config.horizontalTextEnforcer, config.horizontalTextAngleThreshold), + containerBackgroundColor, + ); const rowSets: RowSet[] = getRowSets( textMeasure, @@ -290,14 +292,15 @@ export function shapeViewModel( // linked text const currentY = [-height, -height, -height, -height]; - const nodesWithoutRoom = fillOutside || treemapLayout - ? [] // outsideFillNodes and linkLabels are in inherent conflict due to very likely overlaps - : quadViewModel.filter((n: ShapeTreeNode) => { - const id = nodeId(n); - const foundInFillText = rowSets.find((r: RowSet) => r.id === id); - // successful text render if found, and has some row(s) - return !(foundInFillText && foundInFillText.rows.length !== 0); - }); + const nodesWithoutRoom = + fillOutside || treemapLayout + ? [] // outsideFillNodes and linkLabels are in inherent conflict due to very likely overlaps + : quadViewModel.filter((n: ShapeTreeNode) => { + const id = nodeId(n); + const foundInFillText = rowSets.find((r: RowSet) => r.id === id); + // successful text render if found, and has some row(s) + return !(foundInFillText && foundInFillText.rows.length !== 0); + }); const maxLinkedLabelTextLength = config.linkLabel.maxTextLength; const linkLabelViewModels = linkTextLayout( width, @@ -315,15 +318,16 @@ export function shapeViewModel( containerBackgroundColor, ); - const pickQuads: PickFunction = (x, y) => quadViewModel.filter( - treemapLayout - ? ({ x0, y0, x1, y1 }) => x0 <= x && x <= x1 && y0 <= y && y <= y1 - : ({ x0, y0px, x1, y1px }) => { - const angleX = (Math.atan2(y, x) + TAU / 4 + TAU) % TAU; - const yPx = Math.sqrt(x * x + y * y); - return x0 <= angleX && angleX <= x1 && y0px <= yPx && yPx <= y1px; - }, - ); + const pickQuads: PickFunction = (x, y) => + quadViewModel.filter( + treemapLayout + ? ({ x0, y0, x1, y1 }) => x0 <= x && x <= x1 && y0 <= y && y <= y1 + : ({ x0, y0px, x1, y1px }) => { + const angleX = (Math.atan2(y, x) + TAU / 4 + TAU) % TAU; + const yPx = Math.sqrt(x * x + y * y); + return x0 <= angleX && angleX <= x1 && y0px <= yPx && yPx <= y1px; + }, + ); // combined viewModel return { diff --git a/src/chart_types/partition_chart/renderer/canvas/canvas_renderers.ts b/src/chart_types/partition_chart/renderer/canvas/canvas_renderers.ts index 42995e8946..6834206f51 100644 --- a/src/chart_types/partition_chart/renderer/canvas/canvas_renderers.ts +++ b/src/chart_types/partition_chart/renderer/canvas/canvas_renderers.ts @@ -41,7 +41,7 @@ const TAPER_OFF_LIMIT = 50; // taper off within a radius of TAPER_OFF_LIMIT to a function renderTextRow( ctx: CanvasRenderingContext2D, { fontSize, fillTextColor, rotation, verticalAlignment, leftAlign }: RowSet, - linkLabelTextColor: string + linkLabelTextColor: string, ) { return (currentRow: TextRow) => { const crx = leftAlign diff --git a/src/chart_types/partition_chart/state/selectors/compute_legend.ts b/src/chart_types/partition_chart/state/selectors/compute_legend.ts index f49c0d9e62..6e015ef878 100644 --- a/src/chart_types/partition_chart/state/selectors/compute_legend.ts +++ b/src/chart_types/partition_chart/state/selectors/compute_legend.ts @@ -95,5 +95,7 @@ export const computeLegendSelector = createCachedSelector( )(getChartIdSelector); function findIndex(items: Array<[PrimitiveValue, number, PrimitiveValue]>, child: QuadViewModel) { - return items.findIndex(([dataName, depth, value]) => dataName === child.dataName && depth === child.depth && value === child.value); + return items.findIndex( + ([dataName, depth, value]) => dataName === child.dataName && depth === child.depth && value === child.value, + ); } diff --git a/src/chart_types/partition_chart/state/selectors/geometries.ts b/src/chart_types/partition_chart/state/selectors/geometries.ts index 20789f8a54..2ba3b017c4 100644 --- a/src/chart_types/partition_chart/state/selectors/geometries.ts +++ b/src/chart_types/partition_chart/state/selectors/geometries.ts @@ -38,8 +38,6 @@ export const partitionGeometries = createCachedSelector( (specs, parentDimensions, tree, { background }): ShapeViewModel => { const pieSpecs = getSpecsFromStore(specs, ChartTypes.Partition, SpecTypes.Series); - return pieSpecs.length === 1 - ? render(pieSpecs[0], parentDimensions, tree, background.color) - : nullShapeViewModel(); + return pieSpecs.length === 1 ? render(pieSpecs[0], parentDimensions, tree, background.color) : nullShapeViewModel(); }, )((state) => state.chartId); diff --git a/src/chart_types/partition_chart/state/selectors/scenegraph.ts b/src/chart_types/partition_chart/state/selectors/scenegraph.ts index 55f8660a7d..f0e7fcfdfb 100644 --- a/src/chart_types/partition_chart/state/selectors/scenegraph.ts +++ b/src/chart_types/partition_chart/state/selectors/scenegraph.ts @@ -33,7 +33,6 @@ import { measureText } from '../../layout/utils/measure'; import { shapeViewModel } from '../../layout/viewmodel/viewmodel'; import { PartitionSpec, Layer } from '../../specs'; - function rawTextGetter(layers: Layer[]): RawTextGetter { return (node: ShapeTreeNode) => { const accessorFn = layers[node[DEPTH_KEY] - 1].nodeLabel || identity; diff --git a/src/chart_types/xy_chart/annotations/line/dimensions.integration.test.ts b/src/chart_types/xy_chart/annotations/line/dimensions.integration.test.ts index a214f7b371..c511134cbc 100644 --- a/src/chart_types/xy_chart/annotations/line/dimensions.integration.test.ts +++ b/src/chart_types/xy_chart/annotations/line/dimensions.integration.test.ts @@ -33,11 +33,13 @@ function expectAnnotationAtPosition( ) { const store = MockStore.default(); const settings = MockGlobalSpec.settingsNoMargins(); - const specs = new Array(numOfSpecs).fill(0).map((d, i) => MockSeriesSpec.byTypePartial(type)({ - id: `spec_${i}`, - xScaleType, - data, - })); + const specs = new Array(numOfSpecs).fill(0).map((d, i) => + MockSeriesSpec.byTypePartial(type)({ + id: `spec_${i}`, + xScaleType, + data, + }), + ); const annotation = MockAnnotationSpec.line({ dataValues: [ { diff --git a/src/chart_types/xy_chart/annotations/line/dimensions.ts b/src/chart_types/xy_chart/annotations/line/dimensions.ts index 6d7b5b0da7..240628bd6a 100644 --- a/src/chart_types/xy_chart/annotations/line/dimensions.ts +++ b/src/chart_types/xy_chart/annotations/line/dimensions.ts @@ -243,23 +243,19 @@ function getAnchorPosition( isXDomain: boolean, isChartHorizontal: boolean, specMarkerPosition?: Position, - axisPosition?: Position + axisPosition?: Position, ): Position { const dflPositionFromAxis = getDefaultMarkerPositionFromAxis(isXDomain, isChartHorizontal, axisPosition); if (specMarkerPosition !== undefined) { - // validate specMarkerPosition against domain + // validate specMarkerPosition against domain const validatedPosFromMarkerPos = validateMarkerPosition(isXDomain, isChartHorizontal, specMarkerPosition); return validatedPosFromMarkerPos ?? dflPositionFromAxis; } return dflPositionFromAxis; } -function validateMarkerPosition( - isXDomain: boolean, - isHorizontal: boolean, - position: Position, -): Position | undefined { +function validateMarkerPosition(isXDomain: boolean, isHorizontal: boolean, position: Position): Position | undefined { if ((isXDomain && isHorizontal) || (!isXDomain && !isHorizontal)) { return position === Position.Top || position === Position.Bottom ? position : undefined; } @@ -269,7 +265,7 @@ function validateMarkerPosition( function getDefaultMarkerPositionFromAxis( isXDomain: boolean, isHorizontal: boolean, - axisPosition?: Position + axisPosition?: Position, ): Position { if (axisPosition) { return axisPosition; @@ -352,8 +348,9 @@ function getMarkerPositionForYAnnotation( position: Position, value: number, ): { - top: number, left: number, - } { + top: number; + left: number; +} { switch (position) { case Position.Right: return { @@ -364,13 +361,11 @@ function getMarkerPositionForYAnnotation( return { top: rotation === 180 ? height - value - mHeight / 2 : value - mHeight / 2, left: -mWidth, - }; case Position.Top: return { top: 0 - mHeight, left: rotation === 90 ? width - value - mWidth / 2 : value - mWidth / 2, - }; case Position.Bottom: default: diff --git a/src/chart_types/xy_chart/annotations/line/line.test.tsx b/src/chart_types/xy_chart/annotations/line/line.test.tsx index 415e00995c..8c6459050c 100644 --- a/src/chart_types/xy_chart/annotations/line/line.test.tsx +++ b/src/chart_types/xy_chart/annotations/line/line.test.tsx @@ -35,7 +35,10 @@ describe('annotation marker', () => { const spec = MockSeriesSpec.line({ xScaleType: ScaleType.Linear, yScaleType: ScaleType.Linear, - data: [{ x: 0, y: 0 }, { x: 10, y: 10 }], + data: [ + { x: 0, y: 0 }, + { x: 10, y: 10 }, + ], }); const lineYDomainAnnotation = MockAnnotationSpec.line({ id, @@ -59,12 +62,15 @@ describe('annotation marker', () => { }); test('should compute line annotation dimensions with marker if defined (y domain)', () => { - MockStore.addSpecs([ - spec, - MockGlobalSpec.settingsNoMargins(), - MockGlobalSpec.axis({ position: Position.Left, hide: true }), - lineYDomainAnnotation, - ], store); + MockStore.addSpecs( + [ + spec, + MockGlobalSpec.settingsNoMargins(), + MockGlobalSpec.axis({ position: Position.Left, hide: true }), + lineYDomainAnnotation, + ], + store, + ); const dimensions = computeAnnotationDimensionsSelector(store.getState()); @@ -94,12 +100,15 @@ describe('annotation marker', () => { }); test('should compute line annotation dimensions with marker if defined (y domain: 180 deg rotation)', () => { - MockStore.addSpecs([ - spec, - MockGlobalSpec.settingsNoMargins({ rotation: 180 }), - MockGlobalSpec.axis({ position: Position.Left, hide: true }), - lineYDomainAnnotation, - ], store); + MockStore.addSpecs( + [ + spec, + MockGlobalSpec.settingsNoMargins({ rotation: 180 }), + MockGlobalSpec.axis({ position: Position.Left, hide: true }), + lineYDomainAnnotation, + ], + store, + ); const dimensions = computeAnnotationDimensionsSelector(store.getState()); @@ -132,12 +141,15 @@ describe('annotation marker', () => { }); test('should compute line annotation dimensions with marker if defined (x domain)', () => { - MockStore.addSpecs([ - spec, - MockGlobalSpec.settingsNoMargins(), - MockGlobalSpec.axis({ position: Position.Bottom, hide: true }), - lineXDomainAnnotation, - ], store); + MockStore.addSpecs( + [ + spec, + MockGlobalSpec.settingsNoMargins(), + MockGlobalSpec.axis({ position: Position.Bottom, hide: true }), + lineXDomainAnnotation, + ], + store, + ); const dimensions = computeAnnotationDimensionsSelector(store.getState()); diff --git a/src/chart_types/xy_chart/annotations/rect/dimensions.integration.test.ts b/src/chart_types/xy_chart/annotations/rect/dimensions.integration.test.ts index 02542d16c3..46ef2f0b5c 100644 --- a/src/chart_types/xy_chart/annotations/rect/dimensions.integration.test.ts +++ b/src/chart_types/xy_chart/annotations/rect/dimensions.integration.test.ts @@ -39,11 +39,13 @@ function expectAnnotationAtPosition( ) { const store = MockStore.default(); const settings = MockGlobalSpec.settingsNoMargins(); - const specs = new Array(numOfSpecs).fill(0).map((d, i) => MockSeriesSpec.byTypePartial(type)({ - id: `spec_${i}`, - xScaleType, - data, - })); + const specs = new Array(numOfSpecs).fill(0).map((d, i) => + MockSeriesSpec.byTypePartial(type)({ + id: `spec_${i}`, + xScaleType, + data, + }), + ); const annotation = MockAnnotationSpec.rect({ dataValues, }); diff --git a/src/chart_types/xy_chart/annotations/utils.ts b/src/chart_types/xy_chart/annotations/utils.ts index 562ae166f7..ed1feb0aa8 100644 --- a/src/chart_types/xy_chart/annotations/utils.ts +++ b/src/chart_types/xy_chart/annotations/utils.ts @@ -47,7 +47,7 @@ export function getAnnotationAxis( const isHorizontalRotated = isHorizontalRotation(chartRotation); const isXDomainAnnotation = isXDomain(domainType); const annotationAxis = isXDomainAnnotation ? xAxis : yAxis; - const rotatedAnnotation = isHorizontalRotated ? annotationAxis : (isXDomainAnnotation ? yAxis : xAxis); + const rotatedAnnotation = isHorizontalRotated ? annotationAxis : isXDomainAnnotation ? yAxis : xAxis; return rotatedAnnotation ? rotatedAnnotation.position : undefined; } 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 6de3b25521..1e04d919f3 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 @@ -304,7 +304,7 @@ describe('Crosshair utils linear scale', () => { }); }); - test('changes on y mouse position doesn\'t change the band position', () => { + test("changes on y mouse position doesn't change the band position", () => { const bandPosition = getCursorBandPosition( chartRotation, chartDimensions, @@ -397,7 +397,7 @@ describe('Crosshair utils linear scale', () => { }); }); - test('changes on y mouse position doesn\'t change the band position', () => { + test("changes on y mouse position doesn't change the band position", () => { const bandPosition = getCursorBandPosition( chartRotation, chartDimensions, @@ -511,7 +511,7 @@ describe('Crosshair utils linear scale', () => { }); }); - test('changes on y mouse position doesn\'t change the band position', () => { + test("changes on y mouse position doesn't change the band position", () => { const bandPosition = getCursorBandPosition( chartRotation, chartDimensions, @@ -605,7 +605,7 @@ describe('Crosshair utils linear scale', () => { }); }); - test('changes on y mouse position doesn\'t change the band position', () => { + test("changes on y mouse position doesn't change the band position", () => { const bandPosition = getCursorBandPosition( chartRotation, chartDimensions, @@ -718,7 +718,7 @@ describe('Crosshair utils linear scale', () => { }); }); - test('changes on x mouse position doesn\'t change the band position', () => { + test("changes on x mouse position doesn't change the band position", () => { const bandPosition = getCursorBandPosition( chartRotation, chartDimensions, @@ -812,7 +812,7 @@ describe('Crosshair utils linear scale', () => { }); }); - test('changes on x mouse position doesn\'t change the band position', () => { + test("changes on x mouse position doesn't change the band position", () => { const bandPosition = getCursorBandPosition( chartRotation, chartDimensions, @@ -925,7 +925,7 @@ describe('Crosshair utils linear scale', () => { }); }); - test('changes on x mouse position doesn\'t change the band position', () => { + test("changes on x mouse position doesn't change the band position", () => { const bandPosition = getCursorBandPosition( chartRotation, chartDimensions, @@ -1019,7 +1019,7 @@ describe('Crosshair utils linear scale', () => { }); }); - test('changes on x mouse position doesn\'t change the band position', () => { + test("changes on x mouse position doesn't change the band position", () => { const bandPosition = getCursorBandPosition( chartRotation, chartDimensions, @@ -1135,7 +1135,7 @@ describe('Crosshair utils linear scale', () => { }); }); - test('changes on y mouse position doesn\'t change the band position', () => { + test("changes on y mouse position doesn't change the band position", () => { const bandPosition = getCursorBandPosition( chartRotation, chartDimensions, @@ -1245,7 +1245,7 @@ describe('Crosshair utils linear scale', () => { }); }); - test('changes on y mouse position doesn\'t change the band position', () => { + test("changes on y mouse position doesn't change the band position", () => { const bandPosition = getCursorBandPosition( chartRotation, chartDimensions, @@ -1339,7 +1339,7 @@ describe('Crosshair utils linear scale', () => { }); }); - test('changes on x mouse position doesn\'t change the band position', () => { + test("changes on x mouse position doesn't change the band position", () => { const bandPosition = getCursorBandPosition( chartRotation, chartDimensions, @@ -1433,7 +1433,7 @@ describe('Crosshair utils linear scale', () => { }); }); - test('changes on x mouse position doesn\'t change the band position', () => { + test("changes on x mouse position doesn't change the band position", () => { const bandPosition = getCursorBandPosition( chartRotation, chartDimensions, 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 b514a22511..c9236c36ea 100644 --- a/src/chart_types/xy_chart/domains/x_domain.test.ts +++ b/src/chart_types/xy_chart/domains/x_domain.test.ts @@ -475,21 +475,22 @@ describe('X Domain', () => { }; const { xValues } = getDataSeriesBySpecId(specDataSeries); - const getResult = () => mergeXDomain( - [ - { - seriesType: SeriesTypes.Bar, - xScaleType: ScaleType.Linear, - }, - { - seriesType: SeriesTypes.Bar, - xScaleType: ScaleType.Linear, - }, - ], - xValues, - customDomain, - ScaleType.Ordinal, - ); + const getResult = () => + mergeXDomain( + [ + { + seriesType: SeriesTypes.Bar, + xScaleType: ScaleType.Linear, + }, + { + seriesType: SeriesTypes.Bar, + xScaleType: ScaleType.Linear, + }, + ], + xValues, + customDomain, + ScaleType.Ordinal, + ); expect(getResult).not.toThrow(); 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 aaac194e0c..7402c714ff 100644 --- a/src/chart_types/xy_chart/domains/y_domain.test.ts +++ b/src/chart_types/xy_chart/domains/y_domain.test.ts @@ -26,10 +26,7 @@ import { Position } from '../../../utils/commons'; import { BARCHART_1Y0G } from '../../../utils/data_samples/test_dataset'; import { computeSeriesDomainsSelector } from '../state/selectors/compute_series_domains'; import { BasicSeriesSpec, SeriesTypes, DEFAULT_GLOBAL_ID, StackMode } from '../utils/specs'; -import { - coerceYScaleTypes, - splitSpecsByGroupId, -} from './y_domain'; +import { coerceYScaleTypes, splitSpecsByGroupId } from './y_domain'; const DEMO_AREA_SPEC_1 = { id: 'a', @@ -63,17 +60,20 @@ const DEMO_AREA_SPEC_2 = { describe('Y Domain', () => { test('Should merge Y domain for non zero baseline charts', () => { const store = MockStore.default(); - MockStore.addSpecs([ - MockGlobalSpec.axis({ - id: 'y', - position: Position.Left, - domain: { fit: true }, - }), - MockSeriesSpec.line({ - ...DEMO_AREA_SPEC_1, - groupId: DEFAULT_GLOBAL_ID, - }), - ], store); + MockStore.addSpecs( + [ + MockGlobalSpec.axis({ + id: 'y', + position: Position.Left, + domain: { fit: true }, + }), + MockSeriesSpec.line({ + ...DEMO_AREA_SPEC_1, + groupId: DEFAULT_GLOBAL_ID, + }), + ], + store, + ); const { yDomain } = computeSeriesDomainsSelector(store.getState()); expect(yDomain).toEqual([ @@ -88,17 +88,20 @@ describe('Y Domain', () => { }); test('Should merge Y domain for zero baseline charts', () => { const store = MockStore.default(); - MockStore.addSpecs([ - MockGlobalSpec.axis({ - id: 'y', - position: Position.Left, - domain: { fit: true }, - }), - MockSeriesSpec.area({ - ...DEMO_AREA_SPEC_1, - groupId: DEFAULT_GLOBAL_ID, - }), - ], store); + MockStore.addSpecs( + [ + MockGlobalSpec.axis({ + id: 'y', + position: Position.Left, + domain: { fit: true }, + }), + MockSeriesSpec.area({ + ...DEMO_AREA_SPEC_1, + groupId: DEFAULT_GLOBAL_ID, + }), + ], + store, + ); const { yDomain } = computeSeriesDomainsSelector(store.getState()); expect(yDomain).toEqual([ @@ -113,30 +116,30 @@ describe('Y Domain', () => { }); test('Should merge Y domain different group', () => { const store = MockStore.default(); - MockStore.addSpecs([ - MockGlobalSpec.axis({ - id: 'y a', - groupId: 'a', - position: Position.Left, - domain: { fit: true }, - }), - MockGlobalSpec.axis({ - id: 'y b', - groupId: 'b', - position: Position.Left, - domain: { fit: true }, - }), - MockSeriesSpec.line(DEMO_AREA_SPEC_1), - MockSeriesSpec.line({ - ...DEMO_AREA_SPEC_2, - groupId: 'b', - }), - - - ], store); + MockStore.addSpecs( + [ + MockGlobalSpec.axis({ + id: 'y a', + groupId: 'a', + position: Position.Left, + domain: { fit: true }, + }), + MockGlobalSpec.axis({ + id: 'y b', + groupId: 'b', + position: Position.Left, + domain: { fit: true }, + }), + MockSeriesSpec.line(DEMO_AREA_SPEC_1), + MockSeriesSpec.line({ + ...DEMO_AREA_SPEC_2, + groupId: 'b', + }), + ], + store, + ); const { yDomain } = computeSeriesDomainsSelector(store.getState()); - expect(yDomain).toEqual([ { groupId: 'a', @@ -156,20 +159,23 @@ describe('Y Domain', () => { }); test('Should merge Y domain same group all stacked', () => { const store = MockStore.default(); - MockStore.addSpecs([ - MockGlobalSpec.axis({ - id: 'y a', - groupId: 'a', - position: Position.Left, - domain: { fit: true }, - }), - MockSeriesSpec.area(DEMO_AREA_SPEC_1), - MockSeriesSpec.area({ - ...DEMO_AREA_SPEC_2, - groupId: 'a', - stackAccessors: ['x'], - }), - ], store); + MockStore.addSpecs( + [ + MockGlobalSpec.axis({ + id: 'y a', + groupId: 'a', + position: Position.Left, + domain: { fit: true }, + }), + MockSeriesSpec.area(DEMO_AREA_SPEC_1), + MockSeriesSpec.area({ + ...DEMO_AREA_SPEC_2, + groupId: 'a', + stackAccessors: ['x'], + }), + ], + store, + ); const { yDomain } = computeSeriesDomainsSelector(store.getState()); expect(yDomain).toEqual([ @@ -184,19 +190,22 @@ describe('Y Domain', () => { }); test('Should merge Y domain same group partially stacked', () => { const store = MockStore.default(); - MockStore.addSpecs([ - MockGlobalSpec.axis({ - id: 'y a', - groupId: 'a', - position: Position.Left, - domain: { fit: true }, - }), - MockSeriesSpec.area(DEMO_AREA_SPEC_1), - MockSeriesSpec.area({ - ...DEMO_AREA_SPEC_2, - groupId: 'a', - }), - ], store); + MockStore.addSpecs( + [ + MockGlobalSpec.axis({ + id: 'y a', + groupId: 'a', + position: Position.Left, + domain: { fit: true }, + }), + MockSeriesSpec.area(DEMO_AREA_SPEC_1), + MockSeriesSpec.area({ + ...DEMO_AREA_SPEC_2, + groupId: 'a', + }), + ], + store, + ); const { yDomain } = computeSeriesDomainsSelector(store.getState()); expect(yDomain).toEqual([ { @@ -372,18 +381,20 @@ describe('Y Domain', () => { expect(coerceYScaleTypes(specs)).toBe(ScaleType.Linear); }); - test('Should merge Y domain accounting for custom domain limits: complete bounded domain', () => { const store = MockStore.default(); - MockStore.addSpecs([ - MockGlobalSpec.axis({ - id: 'y a', - groupId: 'a', - position: Position.Left, - domain: { min: 0, max: 20, fit: true }, - }), - MockSeriesSpec.area(DEMO_AREA_SPEC_1), - ], store); + MockStore.addSpecs( + [ + MockGlobalSpec.axis({ + id: 'y a', + groupId: 'a', + position: Position.Left, + domain: { min: 0, max: 20, fit: true }, + }), + MockSeriesSpec.area(DEMO_AREA_SPEC_1), + ], + store, + ); const { yDomain } = computeSeriesDomainsSelector(store.getState()); expect(yDomain).toEqual([ @@ -398,15 +409,18 @@ describe('Y Domain', () => { }); test('Should merge Y domain accounting for custom domain limits: partial lower bounded domain', () => { const store = MockStore.default(); - MockStore.addSpecs([ - MockGlobalSpec.axis({ - id: 'y a', - groupId: 'a', - position: Position.Left, - domain: { min: 0, fit: true }, - }), - MockSeriesSpec.area(DEMO_AREA_SPEC_1), - ], store); + MockStore.addSpecs( + [ + MockGlobalSpec.axis({ + id: 'y a', + groupId: 'a', + position: Position.Left, + domain: { min: 0, fit: true }, + }), + MockSeriesSpec.area(DEMO_AREA_SPEC_1), + ], + store, + ); const { yDomain } = computeSeriesDomainsSelector(store.getState()); expect(yDomain).toEqual([ @@ -421,15 +435,18 @@ describe('Y Domain', () => { }); test('Should not merge Y domain with invalid custom domain limits: partial lower bounded domain', () => { const store = MockStore.default(); - MockStore.addSpecs([ - MockGlobalSpec.axis({ - id: 'y a', - groupId: 'a', - position: Position.Left, - domain: { min: 20, fit: true }, - }), - MockSeriesSpec.area(DEMO_AREA_SPEC_1), - ], store); + MockStore.addSpecs( + [ + MockGlobalSpec.axis({ + id: 'y a', + groupId: 'a', + position: Position.Left, + domain: { min: 20, fit: true }, + }), + MockSeriesSpec.area(DEMO_AREA_SPEC_1), + ], + store, + ); const attemptToMerge = () => { computeSeriesDomainsSelector(store.getState()); @@ -440,16 +457,18 @@ describe('Y Domain', () => { }); test('Should merge Y domain accounting for custom domain limits: partial upper bounded domain', () => { const store = MockStore.default(); - MockStore.addSpecs([ - MockGlobalSpec.axis({ - id: 'y a', - groupId: 'a', - position: Position.Left, - domain: { max: 20, fit: true }, - }), - MockSeriesSpec.line(DEMO_AREA_SPEC_1), - ], store); - + MockStore.addSpecs( + [ + MockGlobalSpec.axis({ + id: 'y a', + groupId: 'a', + position: Position.Left, + domain: { max: 20, fit: true }, + }), + MockSeriesSpec.line(DEMO_AREA_SPEC_1), + ], + store, + ); const { yDomain } = computeSeriesDomainsSelector(store.getState()); expect(yDomain).toEqual([ @@ -464,15 +483,18 @@ describe('Y Domain', () => { }); test('Should not merge Y domain with invalid custom domain limits: partial upper bounded domain', () => { const store = MockStore.default(); - MockStore.addSpecs([ - MockGlobalSpec.axis({ - id: 'y a', - groupId: 'a', - position: Position.Left, - domain: { max: -1, fit: true }, - }), - MockSeriesSpec.area(DEMO_AREA_SPEC_1), - ], store); + MockStore.addSpecs( + [ + MockGlobalSpec.axis({ + id: 'y a', + groupId: 'a', + position: Position.Left, + domain: { max: -1, fit: true }, + }), + MockSeriesSpec.area(DEMO_AREA_SPEC_1), + ], + store, + ); const attemptToMerge = () => { computeSeriesDomainsSelector(store.getState()); @@ -483,17 +505,19 @@ describe('Y Domain', () => { }); test('Should merge Y domain with stacked as percentage', () => { const store = MockStore.default(); - MockStore.addSpecs([ - MockSeriesSpec.area({ - ...DEMO_AREA_SPEC_1, - stackMode: StackMode.Percentage, - }), - MockSeriesSpec.area({ - ...DEMO_AREA_SPEC_2, - groupId: 'a', - }), - ], store); - + MockStore.addSpecs( + [ + MockSeriesSpec.area({ + ...DEMO_AREA_SPEC_1, + stackMode: StackMode.Percentage, + }), + MockSeriesSpec.area({ + ...DEMO_AREA_SPEC_2, + groupId: 'a', + }), + ], + store, + ); const { yDomain } = computeSeriesDomainsSelector(store.getState()); expect(yDomain).toEqual([ @@ -508,18 +532,21 @@ describe('Y Domain', () => { }); test('Should merge Y domain with as percentage regadless of custom domains', () => { const store = MockStore.default(); - MockStore.addSpecs([ - MockGlobalSpec.axis({ - id: 'y a', - groupId: 'a', - position: Position.Left, - domain: { min: 2, max: 20, fit: true }, - }), - MockSeriesSpec.area({ - ...DEMO_AREA_SPEC_1, - stackMode: StackMode.Percentage, - }), - ], store); + MockStore.addSpecs( + [ + MockGlobalSpec.axis({ + id: 'y a', + groupId: 'a', + position: Position.Left, + domain: { min: 2, max: 20, fit: true }, + }), + MockSeriesSpec.area({ + ...DEMO_AREA_SPEC_1, + stackMode: StackMode.Percentage, + }), + ], + store, + ); const { yDomain } = computeSeriesDomainsSelector(store.getState()); expect(yDomain).toEqual([ { diff --git a/src/chart_types/xy_chart/domains/y_domain.ts b/src/chart_types/xy_chart/domains/y_domain.ts index bf8f2f0e99..d08df5f7e9 100644 --- a/src/chart_types/xy_chart/domains/y_domain.ts +++ b/src/chart_types/xy_chart/domains/y_domain.ts @@ -41,9 +41,12 @@ interface GroupSpecs { /** @internal */ export function mergeYDomain( - { stacked, nonStacked }:{ - stacked: FormattedDataSeries[], - nonStacked: FormattedDataSeries[], + { + stacked, + nonStacked, + }: { + stacked: FormattedDataSeries[]; + nonStacked: FormattedDataSeries[]; }, specs: YBasicSeriesSpec[], domainsByGroupId: Map, @@ -60,10 +63,18 @@ export function mergeYDomain( groupId, counts: { area: 0, bubble: 0, bar: 0, line: 0 }, }; - const stackedDS = stacked.find((d) => (d.groupId === groupId)) ?? emptyDS; - const nonStackedDS = nonStacked.find((d) => (d.groupId === groupId)) ?? emptyDS; - const nonZeroBaselineSpecs = stackedDS.counts.bar + stackedDS.counts.area + nonStackedDS.counts.bar + nonStackedDS.counts.area; - return mergeYDomainForGroup(stackedDS.dataSeries, nonStackedDS.dataSeries, groupId, groupSpecs, nonZeroBaselineSpecs > 0, customDomain); + const stackedDS = stacked.find((d) => d.groupId === groupId) ?? emptyDS; + const nonStackedDS = nonStacked.find((d) => d.groupId === groupId) ?? emptyDS; + const nonZeroBaselineSpecs = + stackedDS.counts.bar + stackedDS.counts.area + nonStackedDS.counts.bar + nonStackedDS.counts.area; + return mergeYDomainForGroup( + stackedDS.dataSeries, + nonStackedDS.dataSeries, + groupId, + groupSpecs, + nonZeroBaselineSpecs > 0, + customDomain, + ); }); const globalGroupIds: Set = specs.reduce>((acc, { groupId, useDefaultGroupDomain }) => { @@ -107,8 +118,9 @@ function mergeYDomainForGroup( } else { // TODO remove when removing yScaleToDataExtent const newCustomDomain = customDomain ? { ...customDomain } : {}; - const shouldScaleToExtent = groupSpecs.stacked.some(({ yScaleToDataExtent }) => yScaleToDataExtent) - || groupSpecs.nonStacked.some(({ yScaleToDataExtent }) => yScaleToDataExtent); + const shouldScaleToExtent = + groupSpecs.stacked.some(({ yScaleToDataExtent }) => yScaleToDataExtent) || + groupSpecs.nonStacked.some(({ yScaleToDataExtent }) => yScaleToDataExtent); if (customDomain?.fit !== true && shouldScaleToExtent) { newCustomDomain.fit = true; } @@ -120,11 +132,7 @@ function mergeYDomainForGroup( const nonStackedDomain = computeYDomain(nonStacked, hasZeroBaselineSpecs); // merge stacked and non stacked domain together - domain = computeContinuousDataDomain( - [...stackedDomain, ...nonStackedDomain], - identity, - newCustomDomain, - ); + domain = computeContinuousDataDomain([...stackedDomain, ...nonStackedDomain], identity, newCustomDomain); const [computedDomainMin, computedDomainMax] = domain; @@ -180,10 +188,9 @@ export function splitSpecsByGroupId(specs: YBasicSeriesSpec[]) { // in MobX version, the stackAccessors was programmatically added to every histogram specs // in ReduX version, we left untouched the specs, so we have to manually check that const isHistogramEnabled = specs.some( - ({ seriesType, enableHistogramMode }) => - seriesType === SeriesTypes.Bar && enableHistogramMode + ({ seriesType, enableHistogramMode }) => seriesType === SeriesTypes.Bar && enableHistogramMode, ); - // split each specs by groupId and by stacked or not + // split each specs by groupId and by stacked or not specs.forEach((spec) => { const group = specsByGroupIds.get(spec.groupId) || { stackMode: undefined, @@ -193,8 +200,8 @@ export function splitSpecsByGroupId(specs: YBasicSeriesSpec[]) { // stack every bars if using histogram mode // independenyly from lines and areas if ( - (spec.seriesType === SeriesTypes.Bar && isHistogramEnabled) - || (spec.stackAccessors && spec.stackAccessors.length > 0) + (spec.seriesType === SeriesTypes.Bar && isHistogramEnabled) || + (spec.stackAccessors && spec.stackAccessors.length > 0) ) { group.stacked.push(spec); } else { diff --git a/src/chart_types/xy_chart/renderer/canvas/axes/line.ts b/src/chart_types/xy_chart/renderer/canvas/axes/line.ts index 29b9aab2a8..d0b09fc069 100644 --- a/src/chart_types/xy_chart/renderer/canvas/axes/line.ts +++ b/src/chart_types/xy_chart/renderer/canvas/axes/line.ts @@ -22,11 +22,10 @@ import { Position } from '../../../../../utils/commons'; import { isVerticalAxis } from '../../../utils/axis_type_utils'; /** @internal */ -export function renderLine(ctx: CanvasRenderingContext2D, { - axisSpec: { position }, - axisPosition, - axisStyle: { axisLine }, -}: AxisProps) { +export function renderLine( + ctx: CanvasRenderingContext2D, + { axisSpec: { position }, axisPosition, axisStyle: { axisLine } }: AxisProps, +) { if (!axisLine.visible) { return; } diff --git a/src/chart_types/xy_chart/renderer/canvas/axes/tick_label.ts b/src/chart_types/xy_chart/renderer/canvas/axes/tick_label.ts index 6af2b7d2f9..c4b646e61d 100644 --- a/src/chart_types/xy_chart/renderer/canvas/axes/tick_label.ts +++ b/src/chart_types/xy_chart/renderer/canvas/axes/tick_label.ts @@ -34,28 +34,10 @@ export function renderTickLabel(ctx: CanvasRenderingContext2D, tick: AxisTick, s axisStyle, } = props; const labelStyle = axisStyle.tickLabel; - const { - rotation: tickLabelRotation, - alignment, - offset, - } = labelStyle; + const { rotation: tickLabelRotation, alignment, offset } = labelStyle; - const { - maxLabelBboxWidth, - maxLabelBboxHeight, - maxLabelTextWidth, - maxLabelTextHeight, - } = axisTicksDimensions; - const { - x, - y, - offsetX, - offsetY, - textOffsetX, - textOffsetY, - align, - verticalAlign, - } = getTickLabelProps( + const { maxLabelBboxWidth, maxLabelBboxHeight, maxLabelTextWidth, maxLabelTextHeight } = axisTicksDimensions; + const { x, y, offsetX, offsetY, textOffsetX, textOffsetY, align, verticalAlign } = getTickLabelProps( axisStyle, tick.position, position, @@ -66,7 +48,6 @@ export function renderTickLabel(ctx: CanvasRenderingContext2D, tick: AxisTick, s alignment, ); - if (debug) { // full text container renderDebugRectCenterRotated( diff --git a/src/chart_types/xy_chart/renderer/canvas/axes/title.ts b/src/chart_types/xy_chart/renderer/canvas/axes/title.ts index 2287fc90cc..8cf282a903 100644 --- a/src/chart_types/xy_chart/renderer/canvas/axes/title.ts +++ b/src/chart_types/xy_chart/renderer/canvas/axes/title.ts @@ -30,9 +30,7 @@ import { renderDebugRect } from '../utils/debug'; export function renderTitle(ctx: CanvasRenderingContext2D, props: AxisProps) { const { axisSpec: { title, position }, - axisStyle: { - axisTitle, - }, + axisStyle: { axisTitle }, } = props; if (!title || !axisTitle.visible) { return null; @@ -48,11 +46,7 @@ function renderVerticalTitle(ctx: CanvasRenderingContext2D, props: AxisProps) { axisPosition: { height }, axisSpec: { title, position, hide: hideAxis }, axisTicksDimensions: { maxLabelBboxWidth }, - axisStyle: { - axisTitle, - tickLine, - tickLabel, - }, + axisStyle: { axisTitle, tickLine, tickLabel }, debug, } = props; if (!title) { @@ -93,11 +87,7 @@ function renderHorizontalTitle(ctx: CanvasRenderingContext2D, props: AxisProps) axisPosition: { width }, axisSpec: { title, position, hide: hideAxis }, axisTicksDimensions: { maxLabelBboxHeight }, - axisStyle: { - axisTitle, - tickLine, - tickLabel, - }, + axisStyle: { axisTitle, tickLine, tickLabel }, debug, } = props; diff --git a/src/chart_types/xy_chart/renderer/canvas/grids.ts b/src/chart_types/xy_chart/renderer/canvas/grids.ts index c4d0087bcb..22e056ca92 100644 --- a/src/chart_types/xy_chart/renderer/canvas/grids.ts +++ b/src/chart_types/xy_chart/renderer/canvas/grids.ts @@ -57,7 +57,8 @@ export function renderGrids(ctx: CanvasRenderingContext2D, props: GridProps) { return; } const strokeColor = stringToRGB(gridLine.stroke); - strokeColor.opacity = gridLine.opacity !== undefined ? strokeColor.opacity * gridLine.opacity : strokeColor.opacity; + strokeColor.opacity = + gridLine.opacity !== undefined ? strokeColor.opacity * gridLine.opacity : strokeColor.opacity; const stroke: Stroke = { color: strokeColor, width: gridLine.strokeWidth, diff --git a/src/chart_types/xy_chart/renderer/canvas/styles/bar.ts b/src/chart_types/xy_chart/renderer/canvas/styles/bar.ts index b18ff02c30..7705e73cc8 100644 --- a/src/chart_types/xy_chart/renderer/canvas/styles/bar.ts +++ b/src/chart_types/xy_chart/renderer/canvas/styles/bar.ts @@ -45,9 +45,8 @@ export function buildBarStyles( const fill: Fill = { color: fillColor, }; - const defaultStrokeOpacity = themeRectBorderStyle.strokeOpacity === undefined - ? themeRectStyle.opacity - : themeRectBorderStyle.strokeOpacity; + const defaultStrokeOpacity = + themeRectBorderStyle.strokeOpacity === undefined ? themeRectStyle.opacity : themeRectBorderStyle.strokeOpacity; const borderStrokeOpacity = defaultStrokeOpacity * geometryStateStyle.opacity; const strokeOpacity: OpacityFn = (opacity) => opacity * borderStrokeOpacity; const strokeColor = stringToRGB(getColorFromVariant(baseColor, themeRectBorderStyle.stroke), strokeOpacity); diff --git a/src/chart_types/xy_chart/renderer/dom/annotations/annotations.tsx b/src/chart_types/xy_chart/renderer/dom/annotations/annotations.tsx index 92546a95d9..2fb369842c 100644 --- a/src/chart_types/xy_chart/renderer/dom/annotations/annotations.tsx +++ b/src/chart_types/xy_chart/renderer/dom/annotations/annotations.tsx @@ -23,7 +23,10 @@ import { bindActionCreators, Dispatch } from 'redux'; import { onPointerMove as onPointerMoveAction } from '../../../../../state/actions/mouse'; import { GlobalChartState, BackwardRef } from '../../../../../state/chart_state'; -import { getInternalIsInitializedSelector, InitStatus } from '../../../../../state/selectors/get_internal_is_intialized'; +import { + getInternalIsInitializedSelector, + InitStatus, +} from '../../../../../state/selectors/get_internal_is_intialized'; import { Dimensions } from '../../../../../utils/dimensions'; import { AnnotationId } from '../../../../../utils/ids'; import { AnnotationLineProps } from '../../../annotations/line/types'; @@ -123,12 +126,7 @@ const AnnotationsComponent = ({ return ( <> {renderAnnotationMarkers()} - + ); }; diff --git a/src/chart_types/xy_chart/renderer/dom/annotations/tooltip_content.tsx b/src/chart_types/xy_chart/renderer/dom/annotations/tooltip_content.tsx index 65e23fa0f1..023fd1d7fe 100644 --- a/src/chart_types/xy_chart/renderer/dom/annotations/tooltip_content.tsx +++ b/src/chart_types/xy_chart/renderer/dom/annotations/tooltip_content.tsx @@ -30,12 +30,15 @@ export const TooltipContent = ({ customTooltip: CustomTooltip, customTooltipDetails, }: AnnotationTooltipState) => { - const renderLine = useCallback(() => ( -
-

{header}

-
{customTooltipDetails ? customTooltipDetails(details) : details}
-
- ), [header, details, customTooltipDetails]); + const renderLine = useCallback( + () => ( +
+

{header}

+
{customTooltipDetails ? customTooltipDetails(details) : details}
+
+ ), + [header, details, customTooltipDetails], + ); const renderRect = useCallback(() => { const tooltipContent = customTooltipDetails ? customTooltipDetails(details) : details; diff --git a/src/chart_types/xy_chart/rendering/constants.ts b/src/chart_types/xy_chart/rendering/constants.ts index 16a8df1493..48602a9ea9 100644 --- a/src/chart_types/xy_chart/rendering/constants.ts +++ b/src/chart_types/xy_chart/rendering/constants.ts @@ -1,4 +1,3 @@ - /* * Licensed to Elasticsearch B.V. under one or more contributor * license agreements. See the NOTICE file distributed with diff --git a/src/chart_types/xy_chart/rendering/rendering.ts b/src/chart_types/xy_chart/rendering/rendering.ts index f002b692c0..2033de1ccd 100644 --- a/src/chart_types/xy_chart/rendering/rendering.ts +++ b/src/chart_types/xy_chart/rendering/rendering.ts @@ -66,7 +66,7 @@ export const getYValue = ({ y1, filled }: DataSeriesDatum): number | null => { return y1; } - if (filled && (filled.y1 !== undefined)) { + if (filled && filled.y1 !== undefined) { return filled.y1; } @@ -273,16 +273,20 @@ function getDatumYValue( { y1, y0, initialY1, initialY0 }: DataSeriesDatum, lookingForY0: boolean, isBandChart: boolean, - stackMode?: StackMode + stackMode?: StackMode, ) { if (isBandChart) { return stackMode === StackMode.Percentage - // on band stacked charts in percentage mode, the values I'm looking for are the percentage value - // that are already computed and available on y0 and y1 - ? (lookingForY0 ? y0 : y1) - // in all other cases for band charts, I want to get back the original/initial value of y0 and y1 + ? // on band stacked charts in percentage mode, the values I'm looking for are the percentage value + // that are already computed and available on y0 and y1 + lookingForY0 + ? y0 + : y1 + : // in all other cases for band charts, I want to get back the original/initial value of y0 and y1 // not the computed value - : (lookingForY0 ? initialY0 : initialY1); + lookingForY0 + ? initialY0 + : initialY1; } // if not a band chart get use the original/initial value in every case except for stack as percentage // in this case, we should take the difference between the bottom position of the bar and the top position @@ -290,7 +294,6 @@ function getDatumYValue( return stackMode === StackMode.Percentage ? (y1 ?? 0) - (y0 ?? 0) : initialY1; } - /** @internal */ export function renderBars( orderIndex: number, @@ -373,33 +376,37 @@ export function renderBars( const x = xScaled + xScale.bandwidth * orderIndex; const width = xScale.bandwidth; - const originalY1Value = stackMode === StackMode.Percentage ? (y1 - (y0 ?? 0)) : initialY1; - const formattedDisplayValue = displayValueSettings && displayValueSettings.valueFormatter - ? displayValueSettings.valueFormatter(originalY1Value) - : undefined; + const originalY1Value = stackMode === StackMode.Percentage ? y1 - (y0 ?? 0) : initialY1; + const formattedDisplayValue = + displayValueSettings && displayValueSettings.valueFormatter + ? displayValueSettings.valueFormatter(originalY1Value) + : undefined; // only show displayValue for even bars if showOverlappingValue - const displayValueText = displayValueSettings && displayValueSettings.isAlternatingValueLabel - ? (barGeometries.length % 2 === 0 + const displayValueText = + displayValueSettings && displayValueSettings.isAlternatingValueLabel + ? barGeometries.length % 2 === 0 ? formattedDisplayValue - : undefined) - : formattedDisplayValue; + : undefined + : formattedDisplayValue; const computedDisplayValueWidth = bboxCalculator.compute(displayValueText || '', padding, fontSize, fontFamily) .width; - const displayValueWidth = displayValueSettings && displayValueSettings.isValueContainedInElement ? width : computedDisplayValueWidth; + const displayValueWidth = + displayValueSettings && displayValueSettings.isValueContainedInElement ? width : computedDisplayValueWidth; const hideClippedValue = displayValueSettings ? displayValueSettings.hideClippedValue : undefined; - const displayValue = displayValueSettings && displayValueSettings.showValueLabel - ? { - text: displayValueText, - width: displayValueWidth, - height: fontSize, - hideClippedValue, - isValueContainedInElement: displayValueSettings.isValueContainedInElement, - } - : undefined; + const displayValue = + displayValueSettings && displayValueSettings.showValueLabel + ? { + text: displayValueText, + width: displayValueWidth, + height: fontSize, + hideClippedValue, + isValueContainedInElement: displayValueSettings.isValueContainedInElement, + } + : undefined; const seriesIdentifier: XYChartSeriesIdentifier = { key: dataSeries.key, @@ -574,7 +581,6 @@ export function renderBubble( }; } - /** @internal */ export function renderArea( shift: number, @@ -590,7 +596,7 @@ export function renderArea( isStacked = false, pointStyleAccessor?: PointStyleAccessor, hasFit?: boolean, - stackMode?: StackMode + stackMode?: StackMode, ): { areaGeometry: AreaGeometry; indexedGeometryMap: IndexedGeometryMap; @@ -659,7 +665,7 @@ export function renderArea( markSizeOptions, pointStyleAccessor, false, - stackMode + stackMode, ); let areaPath: string; @@ -705,7 +711,7 @@ export function renderArea( * @param param0 * @internal */ -export function isDatumFilled({ filled, initialY1 } : DataSeriesDatum) { +export function isDatumFilled({ filled, initialY1 }: DataSeriesDatum) { return filled?.x !== undefined || filled?.y1 !== undefined || initialY1 === null || initialY1 === undefined; } diff --git a/src/chart_types/xy_chart/specs/axis.tsx b/src/chart_types/xy_chart/specs/axis.tsx index 02c2e1e0d9..ee224dbca7 100644 --- a/src/chart_types/xy_chart/specs/axis.tsx +++ b/src/chart_types/xy_chart/specs/axis.tsx @@ -42,11 +42,6 @@ type SpecOptionals = Partial = getConnect()( specComponentFactory< AxisSpec, - | 'groupId' - | 'hide' - | 'showOverlappingTicks' - | 'showOverlappingLabels' - | 'position' - | 'tickFormat' + 'groupId' | 'hide' | 'showOverlappingTicks' | 'showOverlappingLabels' | 'position' | 'tickFormat' >(defaultProps), ); diff --git a/src/chart_types/xy_chart/specs/rect_annotation.tsx b/src/chart_types/xy_chart/specs/rect_annotation.tsx index 6db6022501..9efc41082b 100644 --- a/src/chart_types/xy_chart/specs/rect_annotation.tsx +++ b/src/chart_types/xy_chart/specs/rect_annotation.tsx @@ -41,5 +41,5 @@ export const RectAnnotation: React.FunctionComponent >> = getConnect()( - specComponentFactory(defaultProps), - ); + specComponentFactory(defaultProps), +); 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 6fee601a6e..1ecd8d7d8c 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 @@ -805,15 +805,21 @@ function mouseOverTestSuite(scaleType: ScaleType) { }, onBrushEnd: brushEndListener, }; - MockStore.addSpecs([{ - ...spec, - data: [ - [0, 1], - [1, 1], - [2, 2], - [3, 3], + MockStore.addSpecs( + [ + { + ...spec, + data: [ + [0, 1], + [1, 1], + [2, 2], + [3, 3], + ], + } as BarSeriesSpec, + updatedSettings, ], - } as BarSeriesSpec, updatedSettings], store); + store, + ); const start1 = { x: 0, y: 0 }; const end1 = { x: 75, y: 0 }; @@ -957,15 +963,21 @@ function mouseOverTestSuite(scaleType: ScaleType) { }, onBrushEnd: brushEndListener, }; - MockStore.addSpecs([{ - ...spec, - data: [ - [0, 1], - [1, 1], - [2, 2], - [3, 3], + MockStore.addSpecs( + [ + { + ...spec, + data: [ + [0, 1], + [1, 1], + [2, 2], + [3, 3], + ], + } as BarSeriesSpec, + updatedSettings, ], - } as BarSeriesSpec, updatedSettings], store); + store, + ); const start1 = { x: 0, y: 0 }; const end1 = { x: 0, y: 75 }; @@ -1027,15 +1039,21 @@ function mouseOverTestSuite(scaleType: ScaleType) { }, onBrushEnd: brushEndListener, }; - MockStore.addSpecs([{ - ...spec, - data: [ - [0, 1], - [1, 1], - [2, 2], - [3, 3], + MockStore.addSpecs( + [ + { + ...spec, + data: [ + [0, 1], + [1, 1], + [2, 2], + [3, 3], + ], + } as BarSeriesSpec, + updatedSettings, ], - } as BarSeriesSpec, updatedSettings], store); + store, + ); const start1 = { x: 0, y: 0 }; const end1 = { x: 75, y: 75 }; diff --git a/src/chart_types/xy_chart/state/chart_state.specs.test.ts b/src/chart_types/xy_chart/state/chart_state.specs.test.ts index 111d5a81e5..af73c61911 100644 --- a/src/chart_types/xy_chart/state/chart_state.specs.test.ts +++ b/src/chart_types/xy_chart/state/chart_state.specs.test.ts @@ -38,73 +38,94 @@ describe('XYChart - specs ordering', () => { }); it('the legend respect the insert [A, B, C] order', () => { - MockStore.addSpecs([ - MockSeriesSpec.bar({ id: 'A', data }), - MockSeriesSpec.bar({ id: 'B', data }), - MockSeriesSpec.bar({ id: 'C', data }), - ], store); + MockStore.addSpecs( + [ + MockSeriesSpec.bar({ id: 'A', data }), + MockSeriesSpec.bar({ id: 'B', data }), + MockSeriesSpec.bar({ id: 'C', data }), + ], + store, + ); const legendItems = getLegendItemsSelector(store.getState()); const names = [...legendItems.values()].map((item) => item.label); expect(names).toEqual(['A', 'B', 'C']); }); it('the legend respect the insert order [B, A, C]', () => { - MockStore.addSpecs([ - MockSeriesSpec.bar({ id: 'B', data }), - MockSeriesSpec.bar({ id: 'A', data }), - MockSeriesSpec.bar({ id: 'C', data }), - ], store); + MockStore.addSpecs( + [ + MockSeriesSpec.bar({ id: 'B', data }), + MockSeriesSpec.bar({ id: 'A', data }), + MockSeriesSpec.bar({ id: 'C', data }), + ], + store, + ); const legendItems = getLegendItemsSelector(store.getState()); const names = [...legendItems.values()].map((item) => item.label); expect(names).toEqual(['B', 'A', 'C']); }); it('the legend respect the order when changing properties of existing specs', () => { - MockStore.addSpecs([ - MockSeriesSpec.bar({ id: 'A', data }), - MockSeriesSpec.bar({ id: 'B', data }), - MockSeriesSpec.bar({ id: 'C', data }), - ], store); + MockStore.addSpecs( + [ + MockSeriesSpec.bar({ id: 'A', data }), + MockSeriesSpec.bar({ id: 'B', data }), + MockSeriesSpec.bar({ id: 'C', data }), + ], + store, + ); let legendItems = getLegendItemsSelector(store.getState()); let names = [...legendItems.values()].map((item) => item.label); expect(names).toEqual(['A', 'B', 'C']); - MockStore.addSpecs([ - MockSeriesSpec.bar({ id: 'A', data }), - MockSeriesSpec.bar({ id: 'B', name: 'B updated', data }), - MockSeriesSpec.bar({ id: 'C', data }), - ], store); + MockStore.addSpecs( + [ + MockSeriesSpec.bar({ id: 'A', data }), + MockSeriesSpec.bar({ id: 'B', name: 'B updated', data }), + MockSeriesSpec.bar({ id: 'C', data }), + ], + store, + ); legendItems = getLegendItemsSelector(store.getState()); names = [...legendItems.values()].map((item) => item.label); expect(names).toEqual(['A', 'B updated', 'C']); }); it('the legend respect the order when changing the order of the specs', () => { - MockStore.addSpecs([ - MockSeriesSpec.bar({ id: 'A', data }), - MockSeriesSpec.bar({ id: 'B', data }), - MockSeriesSpec.bar({ id: 'C', data }), - ], store); + MockStore.addSpecs( + [ + MockSeriesSpec.bar({ id: 'A', data }), + MockSeriesSpec.bar({ id: 'B', data }), + MockSeriesSpec.bar({ id: 'C', data }), + ], + store, + ); let legendItems = getLegendItemsSelector(store.getState()); let names = [...legendItems.values()].map((item) => item.label); expect(names).toEqual(['A', 'B', 'C']); - MockStore.addSpecs([ - MockSeriesSpec.bar({ id: 'B', data }), - MockSeriesSpec.bar({ id: 'A', data }), - MockSeriesSpec.bar({ id: 'C', data }), - ], store); + MockStore.addSpecs( + [ + MockSeriesSpec.bar({ id: 'B', data }), + MockSeriesSpec.bar({ id: 'A', data }), + MockSeriesSpec.bar({ id: 'C', data }), + ], + store, + ); legendItems = getLegendItemsSelector(store.getState()); names = [...legendItems.values()].map((item) => item.label); expect(names).toEqual(['B', 'A', 'C']); }); it('The status should switch to not initialized removing a spec', () => { - MockStore.addSpecs([ - MockSeriesSpec.bar({ id: 'A', data }), - MockSeriesSpec.bar({ id: 'B', data }), - MockSeriesSpec.bar({ id: 'C', data }), - ], store); + MockStore.addSpecs( + [ + MockSeriesSpec.bar({ id: 'A', data }), + MockSeriesSpec.bar({ id: 'B', data }), + MockSeriesSpec.bar({ id: 'C', data }), + ], + store, + ); expect(getInternalIsInitializedSelector(store.getState())).toBe(InitStatus.Initialized); // check on remove store.dispatch(removeSpec('A')); @@ -115,11 +136,14 @@ describe('XYChart - specs ordering', () => { expect(getInternalIsInitializedSelector(store.getState())).toBe(InitStatus.Initialized); }); it('The status should switch to not initialized when upserting a spec', () => { - MockStore.addSpecs([ - MockSeriesSpec.bar({ id: 'A', data }), - MockSeriesSpec.bar({ id: 'B', data }), - MockSeriesSpec.bar({ id: 'C', data }), - ], store); + MockStore.addSpecs( + [ + MockSeriesSpec.bar({ id: 'A', data }), + MockSeriesSpec.bar({ id: 'B', data }), + MockSeriesSpec.bar({ id: 'C', data }), + ], + store, + ); expect(getInternalIsInitializedSelector(store.getState())).toBe(InitStatus.Initialized); // check on upsert 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 4f8d439426..e26a165a47 100644 --- a/src/chart_types/xy_chart/state/chart_state.test.ts +++ b/src/chart_types/xy_chart/state/chart_state.test.ts @@ -236,7 +236,7 @@ describe.skip('Chart Store', () => { expect(result).toBe(false); }); - it('should return false if can\'t find spec', () => { + it("should return false if can't find spec", () => { tickMap.set(AXIS_2_ID, axisTicksDimensions); const result = isDuplicateAxis(axis1, axisTicksDimensions, tickMap, specMap); diff --git a/src/chart_types/xy_chart/state/selectors/compute_annotations.ts b/src/chart_types/xy_chart/state/selectors/compute_annotations.ts index 170321c232..3d2c1ebda2 100644 --- a/src/chart_types/xy_chart/state/selectors/compute_annotations.ts +++ b/src/chart_types/xy_chart/state/selectors/compute_annotations.ts @@ -47,13 +47,14 @@ export const computeAnnotationDimensionsSelector = createCachedSelector( { scales: { yScales, xScale } }, axesSpecs, isHistogramMode, - ): Map => computeAnnotationDimensions( - annotationSpecs, - chartDimensions.chartDimensions, - settingsSpec.rotation, - yScales, - xScale, - axesSpecs, - isHistogramMode, - ), + ): Map => + computeAnnotationDimensions( + annotationSpecs, + chartDimensions.chartDimensions, + settingsSpec.rotation, + yScales, + xScale, + axesSpecs, + isHistogramMode, + ), )(getChartIdSelector); diff --git a/src/chart_types/xy_chart/state/selectors/compute_axis_ticks_dimensions.ts b/src/chart_types/xy_chart/state/selectors/compute_axis_ticks_dimensions.ts index 8eab26720f..d901f82290 100644 --- a/src/chart_types/xy_chart/state/selectors/compute_axis_ticks_dimensions.ts +++ b/src/chart_types/xy_chart/state/selectors/compute_axis_ticks_dimensions.ts @@ -69,8 +69,8 @@ export const computeAxisTicksDimensionsSelector = createCachedSelector( isHistogramMode, ); if ( - dimensions - && (!settingsSpec.hideDuplicateAxes || !isDuplicateAxis(axisSpec, dimensions, axesTicksDimensions, axesSpecs)) + dimensions && + (!settingsSpec.hideDuplicateAxes || !isDuplicateAxis(axisSpec, dimensions, axesTicksDimensions, axesSpecs)) ) { axesTicksDimensions.set(id, dimensions); } diff --git a/src/chart_types/xy_chart/state/selectors/compute_legend.ts b/src/chart_types/xy_chart/state/selectors/compute_legend.ts index ba130b3a30..7d790d39f3 100644 --- a/src/chart_types/xy_chart/state/selectors/compute_legend.ts +++ b/src/chart_types/xy_chart/state/selectors/compute_legend.ts @@ -40,19 +40,13 @@ export const computeLegendSelector = createCachedSelector( getAxisSpecsSelector, getDeselectedSeriesSelector, ], - ( - seriesSpecs, - seriesDomainsAndData, - chartTheme, - seriesColors, - axesSpecs, - deselectedDataSeries, - ): LegendItem[] => computeLegend( - seriesDomainsAndData.seriesCollection, - seriesColors, - seriesSpecs, - chartTheme.colors.defaultVizColor, - axesSpecs, - deselectedDataSeries, - ), + (seriesSpecs, seriesDomainsAndData, chartTheme, seriesColors, axesSpecs, deselectedDataSeries): LegendItem[] => + computeLegend( + seriesDomainsAndData.seriesCollection, + seriesColors, + seriesSpecs, + chartTheme.colors.defaultVizColor, + axesSpecs, + deselectedDataSeries, + ), )(getChartIdSelector); diff --git a/src/chart_types/xy_chart/state/selectors/get_annotation_tooltip_state.ts b/src/chart_types/xy_chart/state/selectors/get_annotation_tooltip_state.ts index 954e1c5e11..76c405ef6d 100644 --- a/src/chart_types/xy_chart/state/selectors/get_annotation_tooltip_state.ts +++ b/src/chart_types/xy_chart/state/selectors/get_annotation_tooltip_state.ts @@ -89,10 +89,10 @@ function getAnnotationTooltipState( // If there's a highlighted chart element tooltip value, don't show annotation tooltip const isChartTooltipDisplayed = tooltip.values.some(({ isHighlighted }) => isHighlighted); if ( - tooltipState - && tooltipState.isVisible - && tooltipState.annotationType === AnnotationTypes.Rectangle - && isChartTooltipDisplayed + tooltipState && + tooltipState.isVisible && + tooltipState.annotationType === AnnotationTypes.Rectangle && + isChartTooltipDisplayed ) { return null; } diff --git a/src/chart_types/xy_chart/state/selectors/get_bar_paddings.ts b/src/chart_types/xy_chart/state/selectors/get_bar_paddings.ts index cd96a5a8a8..a536fe2113 100644 --- a/src/chart_types/xy_chart/state/selectors/get_bar_paddings.ts +++ b/src/chart_types/xy_chart/state/selectors/get_bar_paddings.ts @@ -26,7 +26,6 @@ import { isHistogramModeEnabledSelector } from './is_histogram_mode_enabled'; /** @internal */ export const getBarPaddingsSelector = createCachedSelector( [isHistogramModeEnabledSelector, getChartThemeSelector], - (isHistogramMode, chartTheme): number => isHistogramMode - ? chartTheme.scales.histogramPadding - : chartTheme.scales.barsPadding, + (isHistogramMode, chartTheme): number => + isHistogramMode ? chartTheme.scales.histogramPadding : chartTheme.scales.barsPadding, )(getChartIdSelector); 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 6c7cfdc26f..2c8ac9e2ab 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 @@ -63,17 +63,18 @@ export const getCursorBandPositionSelector = createCachedSelector( totalBarsInCluster, isTooltipSnapEnabled, geometriesIndexKeys, - ) => getCursorBand( - orientedProjectedPointerPosition, - externalPointerEvent, - chartDimensions.chartDimensions, - settingsSpec, - seriesGeometries.scales.xScale, - seriesSpec, - totalBarsInCluster, - isTooltipSnapEnabled, - geometriesIndexKeys, - ), + ) => + getCursorBand( + orientedProjectedPointerPosition, + externalPointerEvent, + chartDimensions.chartDimensions, + settingsSpec, + seriesGeometries.scales.xScale, + seriesSpec, + totalBarsInCluster, + isTooltipSnapEnabled, + geometriesIndexKeys, + ), )(getChartIdSelector); function getCursorBand( @@ -86,7 +87,7 @@ function getCursorBand( totalBarsInCluster: number, isTooltipSnapEnabled: boolean, geometriesIndexKeys: (string | number)[], -): (Dimensions & { visible: boolean, fromExternalEvent: boolean }) | undefined { +): (Dimensions & { visible: boolean; fromExternalEvent: 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_cursor_line.ts b/src/chart_types/xy_chart/state/selectors/get_cursor_line.ts index b90b54de0f..9e19f6e98b 100644 --- a/src/chart_types/xy_chart/state/selectors/get_cursor_line.ts +++ b/src/chart_types/xy_chart/state/selectors/get_cursor_line.ts @@ -28,18 +28,7 @@ import { getProjectedPointerPositionSelector } from './get_projected_pointer_pos /** @internal */ export const getCursorLinePositionSelector = createCachedSelector( - [ - computeChartDimensionsSelector, - getSettingsSpecSelector, - getProjectedPointerPositionSelector, - ], - ( - chartDimensions, - settingsSpec, - projectedPointerPosition, - ): Dimensions | undefined => getCursorLinePosition( - settingsSpec.rotation, - chartDimensions.chartDimensions, - projectedPointerPosition, - ), + [computeChartDimensionsSelector, getSettingsSpecSelector, getProjectedPointerPositionSelector], + (chartDimensions, settingsSpec, projectedPointerPosition): Dimensions | undefined => + getCursorLinePosition(settingsSpec.rotation, chartDimensions.chartDimensions, projectedPointerPosition), )(getChartIdSelector); diff --git a/src/chart_types/xy_chart/state/selectors/get_legend_items_labels.ts b/src/chart_types/xy_chart/state/selectors/get_legend_items_labels.ts index af4054eba5..68c1dbea29 100644 --- a/src/chart_types/xy_chart/state/selectors/get_legend_items_labels.ts +++ b/src/chart_types/xy_chart/state/selectors/get_legend_items_labels.ts @@ -27,10 +27,11 @@ import { computeLegendSelector } from './compute_legend'; /** @internal */ export const getLegendItemsLabelsSelector = createCachedSelector( [computeLegendSelector, getSettingsSpecSelector], - (legendItems, { showLegendExtra }): LegendItemLabel[] => legendItems.map(({ label, defaultExtra }) => { - if (defaultExtra?.formatted != null) { - return { label: `${label}${showLegendExtra ? defaultExtra.formatted : ''}`, depth: 0 }; - } - return { label, depth: 0 }; - }), + (legendItems, { showLegendExtra }): LegendItemLabel[] => + legendItems.map(({ label, defaultExtra }) => { + if (defaultExtra?.formatted != null) { + return { label: `${label}${showLegendExtra ? defaultExtra.formatted : ''}`, depth: 0 }; + } + return { label, depth: 0 }; + }), )(getChartIdSelector); diff --git a/src/chart_types/xy_chart/state/selectors/get_projected_pointer_position.ts b/src/chart_types/xy_chart/state/selectors/get_projected_pointer_position.ts index 5b78af8bd2..b946d66724 100644 --- a/src/chart_types/xy_chart/state/selectors/get_projected_pointer_position.ts +++ b/src/chart_types/xy_chart/state/selectors/get_projected_pointer_position.ts @@ -30,7 +30,8 @@ const getCurrentPointerPosition = (state: GlobalChartState) => state.interaction /** @internal */ export const getProjectedPointerPositionSelector = createCachedSelector( [getCurrentPointerPosition, computeChartDimensionsSelector], - (currentPointerPosition, chartDimensions): Point => getProjectedPointerPosition(currentPointerPosition, chartDimensions.chartDimensions), + (currentPointerPosition, chartDimensions): Point => + getProjectedPointerPosition(currentPointerPosition, chartDimensions.chartDimensions), )(getChartIdSelector); /** 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 d3944c78a9..23e5c9cf62 100644 --- a/src/chart_types/xy_chart/state/selectors/get_specs.ts +++ b/src/chart_types/xy_chart/state/selectors/get_specs.ts @@ -29,7 +29,9 @@ import { AxisSpec, BasicSeriesSpec, AnnotationSpec } from '../../utils/specs'; const getSpecs = (state: GlobalChartState) => state.specs; /** @internal */ -export const getAxisSpecsSelector = createCachedSelector([getSpecs], (specs): AxisSpec[] => getSpecsFromStore(specs, ChartTypes.XYAxis, SpecTypes.Axis))(getChartIdSelector); +export const getAxisSpecsSelector = createCachedSelector([getSpecs], (specs): AxisSpec[] => + getSpecsFromStore(specs, ChartTypes.XYAxis, SpecTypes.Axis), +)(getChartIdSelector); /** @internal */ export const getSeriesSpecsSelector = createCachedSelector([getSpecs], (specs) => { @@ -38,4 +40,6 @@ export const getSeriesSpecsSelector = createCachedSelector([getSpecs], (specs) = })(getChartIdSelector); /** @internal */ -export const getAnnotationSpecsSelector = createCachedSelector([getSpecs], (specs) => getSpecsFromStore(specs, ChartTypes.XYAxis, SpecTypes.Annotation))(getChartIdSelector); +export const getAnnotationSpecsSelector = createCachedSelector([getSpecs], (specs) => + getSpecsFromStore(specs, ChartTypes.XYAxis, SpecTypes.Annotation), +)(getChartIdSelector); diff --git a/src/chart_types/xy_chart/state/selectors/get_tooltip_values_highlighted_geoms.ts b/src/chart_types/xy_chart/state/selectors/get_tooltip_values_highlighted_geoms.ts index 1b0f1b9a7f..240dc18fbd 100644 --- a/src/chart_types/xy_chart/state/selectors/get_tooltip_values_highlighted_geoms.ts +++ b/src/chart_types/xy_chart/state/selectors/get_tooltip_values_highlighted_geoms.ts @@ -154,8 +154,8 @@ function getTooltipAndHighlightFromValue( // check if the pointer is on the geometry (avoid checking if using external pointer event) let isHighlighted = false; if ( - (!externalPointerEvent || isPointerOutEvent(externalPointerEvent)) - && isPointOnGeometry(x, y, indexedGeometry, settings.pointBuffer) + (!externalPointerEvent || isPointerOutEvent(externalPointerEvent)) && + isPointOnGeometry(x, y, indexedGeometry, settings.pointBuffer) ) { isHighlighted = true; highlightedGeometries.push(indexedGeometry); 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 f90b1c5c80..cc0c7a2cd8 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 @@ -24,4 +24,6 @@ import { isAllSeriesDeselected } from '../utils/common'; import { computeLegendSelector } from './compute_legend'; /** @internal */ -export const isChartEmptySelector = createCachedSelector([computeLegendSelector], (legendItems): boolean => isAllSeriesDeselected(legendItems))(getChartIdSelector); +export const isChartEmptySelector = createCachedSelector([computeLegendSelector], (legendItems): boolean => + 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 5e1c4a82c3..aedd3f8c81 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 @@ -24,4 +24,6 @@ import { isHistogramModeEnabled } from '../utils/utils'; import { getSeriesSpecsSelector } from './get_specs'; /** @internal */ -export const isHistogramModeEnabledSelector = createCachedSelector([getSeriesSpecsSelector], (seriesSpecs): boolean => isHistogramModeEnabled(seriesSpecs))(getChartIdSelector); +export const isHistogramModeEnabledSelector = createCachedSelector([getSeriesSpecsSelector], (seriesSpecs): boolean => + isHistogramModeEnabled(seriesSpecs), +)(getChartIdSelector); diff --git a/src/chart_types/xy_chart/state/selectors/is_tooltip_visible.ts b/src/chart_types/xy_chart/state/selectors/is_tooltip_visible.ts index 8852bfe0b3..bdea4f0ab1 100644 --- a/src/chart_types/xy_chart/state/selectors/is_tooltip_visible.ts +++ b/src/chart_types/xy_chart/state/selectors/is_tooltip_visible.ts @@ -35,7 +35,6 @@ const getTooltipTypeSelector = (state: GlobalChartState): TooltipType => getTool const getPointerSelector = (state: GlobalChartState) => state.interactions.pointer; - /** @internal */ export const isTooltipVisibleSelector = createCachedSelector( [ @@ -57,14 +56,13 @@ function isTooltipVisible( isAnnotationTooltipVisible: boolean, externalTooltipVisible: boolean, ) { - const isLocalTooltop = ( - tooltipType !== TooltipType.None - && pointer.down === null - && projectedPointerPosition.x > -1 - && projectedPointerPosition.y > -1 - && tooltip.values.length > 0 - && !isAnnotationTooltipVisible - ); + const isLocalTooltop = + tooltipType !== TooltipType.None && + pointer.down === null && + projectedPointerPosition.x > -1 && + projectedPointerPosition.y > -1 && + tooltip.values.length > 0 && + !isAnnotationTooltipVisible; const isExternalTooltip = externalTooltipVisible && tooltip.values.length > 0; return { visible: isLocalTooltop || isExternalTooltip, diff --git a/src/chart_types/xy_chart/state/selectors/merge_y_custom_domains.ts b/src/chart_types/xy_chart/state/selectors/merge_y_custom_domains.ts index 9ee15ad379..b35b0643db 100644 --- a/src/chart_types/xy_chart/state/selectors/merge_y_custom_domains.ts +++ b/src/chart_types/xy_chart/state/selectors/merge_y_custom_domains.ts @@ -31,10 +31,8 @@ import { getAxisSpecsSelector } from './get_specs'; /** @internal */ export const mergeYCustomDomainsByGroupIdSelector = createCachedSelector( [getAxisSpecsSelector, getSettingsSpecSelector], - (axisSpecs, settingsSpec): Map => mergeYCustomDomainsByGroupId( - axisSpecs, - settingsSpec ? settingsSpec.rotation : 0, - ), + (axisSpecs, settingsSpec): Map => + mergeYCustomDomainsByGroupId(axisSpecs, settingsSpec ? settingsSpec.rotation : 0), )(getChartIdSelector); /** @internal */ diff --git a/src/chart_types/xy_chart/state/selectors/on_pointer_move_caller.ts b/src/chart_types/xy_chart/state/selectors/on_pointer_move_caller.ts index e5373972f4..ba3c8728f8 100644 --- a/src/chart_types/xy_chart/state/selectors/on_pointer_move_caller.ts +++ b/src/chart_types/xy_chart/state/selectors/on_pointer_move_caller.ts @@ -39,17 +39,8 @@ const getPointerEventSelector = createCachedSelector( computeSeriesGeometriesSelector, getGeometriesIndexKeysSelector, ], - ( - chartId, - orientedProjectedPointerPosition, - seriesGeometries, - geometriesIndexKeys, - ): PointerEvent => getPointerEvent( - chartId, - orientedProjectedPointerPosition, - seriesGeometries.scales.xScale, - geometriesIndexKeys, - ), + (chartId, orientedProjectedPointerPosition, seriesGeometries, geometriesIndexKeys): PointerEvent => + getPointerEvent(chartId, orientedProjectedPointerPosition, seriesGeometries.scales.xScale, geometriesIndexKeys), )(getChartIdSelector); function getPointerEvent( @@ -93,20 +84,20 @@ function hasPointerEventChanged(prevPointerEvent: PointerEvent, nextPointerEvent return true; } if ( - nextPointerEvent - && prevPointerEvent.type === nextPointerEvent.type - && prevPointerEvent.type === PointerEventType.Out + nextPointerEvent && + prevPointerEvent.type === nextPointerEvent.type && + prevPointerEvent.type === PointerEventType.Out ) { return false; } // if something changed in the pointerEvent than recompute if ( - nextPointerEvent - && prevPointerEvent.type === PointerEventType.Over - && nextPointerEvent.type === PointerEventType.Over - && (prevPointerEvent.value !== nextPointerEvent.value - || prevPointerEvent.scale !== nextPointerEvent.scale - || prevPointerEvent.unit !== nextPointerEvent.unit) + nextPointerEvent && + prevPointerEvent.type === PointerEventType.Over && + nextPointerEvent.type === PointerEventType.Over && + (prevPointerEvent.value !== nextPointerEvent.value || + prevPointerEvent.scale !== nextPointerEvent.scale || + prevPointerEvent.unit !== nextPointerEvent.unit) ) { return true; } diff --git a/src/chart_types/xy_chart/state/utils/common.test.ts b/src/chart_types/xy_chart/state/utils/common.test.ts index e8c04af0ae..30118589f2 100644 --- a/src/chart_types/xy_chart/state/utils/common.test.ts +++ b/src/chart_types/xy_chart/state/utils/common.test.ts @@ -31,7 +31,6 @@ import { isAllSeriesDeselected, } from './common'; - describe('Type Checks', () => { test('is horizontal chart rotation', () => { expect(isHorizontalRotation(0)).toBe(true); diff --git a/src/chart_types/xy_chart/state/utils/types.ts b/src/chart_types/xy_chart/state/utils/types.ts index dd88fcaf9f..9c2323a152 100644 --- a/src/chart_types/xy_chart/state/utils/types.ts +++ b/src/chart_types/xy_chart/state/utils/types.ts @@ -66,7 +66,6 @@ export interface Geometries { bubbles: BubbleGeometry[]; } - /** @internal */ export interface ComputedGeometries { scales: ComputedScales; diff --git a/src/chart_types/xy_chart/state/utils/utils.ts b/src/chart_types/xy_chart/state/utils/utils.ts index ee51783b2a..d31ce8a4b5 100644 --- a/src/chart_types/xy_chart/state/utils/utils.ts +++ b/src/chart_types/xy_chart/state/utils/utils.ts @@ -202,12 +202,10 @@ export function computeSeriesDomains( deselectedDataSeries: SeriesIdentifier[] = [], customXDomain?: DomainRange | Domain, ): SeriesDomainsAndData { - const { - dataSeriesBySpecId, - xValues, - seriesCollection, - fallbackScale, - } = getDataSeriesBySpecId(seriesSpecs, deselectedDataSeries); + const { dataSeriesBySpecId, xValues, seriesCollection, fallbackScale } = getDataSeriesBySpecId( + seriesSpecs, + deselectedDataSeries, + ); // compute the x domain merging any custom domain const specsArray = [...seriesSpecs.values()]; @@ -216,7 +214,6 @@ export function computeSeriesDomains( // fill series with missing x values const filledDataSeriesBySpecId = fillSeries(dataSeriesBySpecId, xValues); - const formattedDataSeries = getFormattedDataseries( specsArray, filledDataSeriesBySpecId, @@ -529,7 +526,7 @@ function renderGeometries( displayValueSettings, spec.styleAccessor, spec.minBarHeight, - stackMode + stackMode, ); indexedGeometryMap.merge(renderedBars.indexedGeometryMap); bars.push(...renderedBars.barGeometries); @@ -613,7 +610,7 @@ function renderGeometries( isStacked, spec.pointStyleAccessor, hasFitFnConfigured(spec.fit), - stackMode + stackMode, ); indexedGeometryMap.merge(renderedAreas.indexedGeometryMap); areas.push(renderedAreas.areaGeometry); diff --git a/src/chart_types/xy_chart/utils/axis_utils.test.ts b/src/chart_types/xy_chart/utils/axis_utils.test.ts index 1ddb0e7ddd..431b134f98 100644 --- a/src/chart_types/xy_chart/utils/axis_utils.test.ts +++ b/src/chart_types/xy_chart/utils/axis_utils.test.ts @@ -57,17 +57,18 @@ import { import { computeXScale } from './scales'; import { AxisSpec, DomainRange, DEFAULT_GLOBAL_ID, TickFormatter } from './specs'; -const getCustomStyle = (rotation = 0, padding = 10): AxisStyle => mergePartial(LIGHT_THEME.axes, { - tickLine: { - size: 10, - padding, - }, - tickLabel: { - fontSize: 16, - fontFamily: 'Arial', - rotation, - }, -}); +const getCustomStyle = (rotation = 0, padding = 10): AxisStyle => + mergePartial(LIGHT_THEME.axes, { + tickLine: { + size: 10, + padding, + }, + tickLabel: { + fontSize: 16, + fontFamily: 'Arial', + rotation, + }, + }); const style = getCustomStyle(); describe('Axis computational utils', () => { @@ -205,7 +206,17 @@ describe('Axis computational utils', () => { expect(axisDimensions).toEqual(axis1Dims); const ungroupedAxisSpec = { ...verticalAxisSpec, groupId: 'foo' }; - const result = computeAxisTicksDimensions(ungroupedAxisSpec, xDomain, [yDomain], 1, bboxCalculator, 0, axes, undefined, false); + const result = computeAxisTicksDimensions( + ungroupedAxisSpec, + xDomain, + [yDomain], + 1, + bboxCalculator, + 0, + axes, + undefined, + false, + ); expect(result).toBeNull(); @@ -752,7 +763,7 @@ describe('Axis computational utils', () => { { horizontal: 'center', vertical: 'bottom', - } + }, ); expect(unrotatedLabelProps).toEqual({ @@ -819,7 +830,7 @@ describe('Axis computational utils', () => { { horizontal: 'center', vertical: 'top', - } + }, ); expect(bottomUnrotatedLabelProps).toEqual({ @@ -1052,15 +1063,11 @@ describe('Axis computational utils', () => { 0, true, ); - const { - size: tickSize, - padding: tickPadding, - } = LIGHT_THEME.axes.tickLine; + const { size: tickSize, padding: tickPadding } = LIGHT_THEME.axes.tickLine; const expectedTopAxisPosition = { dimensions: { - height: - axis1Dims.maxLabelBboxHeight + axisTitleHeight + tickSize + tickPadding, + height: axis1Dims.maxLabelBboxHeight + axisTitleHeight + tickSize + tickPadding, width: 100, left: 0, top: cumTopSum + LIGHT_THEME.chartMargins.top, @@ -1481,7 +1488,8 @@ describe('Axis computational utils', () => { ]); }); test('should show unique consecutive ticks if duplicateTicks is set to false', () => { - const formatter: TickFormatter = (d, options = { timeZone: 'utc+1' }) => DateTime.fromMillis(d, { setZone: true, zone: options.timeZone }).toFormat('HH:mm'); + const formatter: TickFormatter = (d, options = { timeZone: 'utc+1' }) => + DateTime.fromMillis(d, { setZone: true, zone: options.timeZone }).toFormat('HH:mm'); const axisSpec: AxisSpec = { id: 'bottom', position: 'bottom', diff --git a/src/chart_types/xy_chart/utils/axis_utils.ts b/src/chart_types/xy_chart/utils/axis_utils.ts index 8a87c7c75f..2cf210cbdd 100644 --- a/src/chart_types/xy_chart/utils/axis_utils.ts +++ b/src/chart_types/xy_chart/utils/axis_utils.ts @@ -19,7 +19,15 @@ import { Scale } from '../../../scales'; import { BBox, BBoxCalculator } from '../../../utils/bbox/bbox_calculator'; -import { Position, Rotation, getUniqueValues, VerticalAlignment, HorizontalAlignment, getPercentageValue, mergePartial } from '../../../utils/commons'; +import { + Position, + Rotation, + getUniqueValues, + VerticalAlignment, + HorizontalAlignment, + getPercentageValue, + mergePartial, +} from '../../../utils/commons'; import { Dimensions, Margins, getSimplePadding } from '../../../utils/dimensions'; import { AxisId } from '../../../utils/ids'; import { Logger } from '../../../utils/logger'; @@ -181,11 +189,7 @@ export function computeRotatedLabelDimensions(unrotatedDims: BBox, degreesRotati /** @internal */ export const getMaxLabelDimensions = ( bboxCalculator: BBoxCalculator, - { - fontSize, - fontFamily, - rotation, - }: AxisStyle['tickLabel'], + { fontSize, fontFamily, rotation }: AxisStyle['tickLabel'], ) => ( acc: Record, tickLabel: string, @@ -226,10 +230,7 @@ function computeTickDimensions( const tickLabels = tickValues.map((d) => tickFormat(d, tickFormatOptions)); const defaultAcc = { maxLabelBboxWidth: 0, maxLabelBboxHeight: 0, maxLabelTextWidth: 0, maxLabelTextHeight: 0 }; const dimensions = tickLabelStyle.visible - ? tickLabels.reduce( - getMaxLabelDimensions(bboxCalculator, tickLabelStyle), - defaultAcc, - ) + ? tickLabels.reduce(getMaxLabelDimensions(bboxCalculator, tickLabelStyle), defaultAcc) : defaultAcc; return { @@ -264,7 +265,10 @@ function getUserTextOffsets(dimensions: AxisTicksDimensions, offset: TextOffset) }; } -function getHorizontalTextOffset(width: number, alignment: Extract): number { +function getHorizontalTextOffset( + width: number, + alignment: Extract, +): number { switch (alignment) { case 'left': return -width / 2; @@ -276,7 +280,10 @@ function getHorizontalTextOffset(width: number, alignment: Extract): number { +function getVerticalTextOffset( + height: number, + alignment: Extract, +): number { switch (alignment) { case 'top': return -height / 2; @@ -288,11 +295,14 @@ function getVerticalTextOffset(height: number, alignment: Extract { +function getHorizontalAlign( + position: Position, + alignment: HorizontalAlignment = HorizontalAlignment.Near, +): Exclude { if ( - alignment === HorizontalAlignment.Center - || alignment === HorizontalAlignment.Right - || alignment === HorizontalAlignment.Left + alignment === HorizontalAlignment.Center || + alignment === HorizontalAlignment.Right || + alignment === HorizontalAlignment.Left ) { return alignment; } @@ -309,11 +319,14 @@ function getHorizontalAlign(position: Position, alignment: HorizontalAlignment = return 'center'; } -function getVerticalAlign(position: Position, alignment: VerticalAlignment = VerticalAlignment.Middle): Exclude { +function getVerticalAlign( + position: Position, + alignment: VerticalAlignment = VerticalAlignment.Middle, +): Exclude { if ( - alignment === VerticalAlignment.Middle - || alignment === VerticalAlignment.Top - || alignment === VerticalAlignment.Bottom + alignment === VerticalAlignment.Middle || + alignment === VerticalAlignment.Top || + alignment === VerticalAlignment.Bottom ) { return alignment; } @@ -341,10 +354,7 @@ function getVerticalAlign(position: Position, alignment: VerticalAlignment = Ver * @internal */ export function getTickLabelProps( - { - tickLine, - tickLabel, - }: AxisStyle, + { tickLine, tickLabel }: AxisStyle, tickPosition: number, position: Position, axisPosition: Dimensions, @@ -383,7 +393,6 @@ export function getTickLabelProps( const offsetY = isAxisTop ? -maxLabelBboxHeight / 2 : maxLabelBboxHeight / 2; - return { x: tickPosition, y: isAxisTop ? axisPosition.height - tickDimension - labelPadding.inner : tickDimension + labelPadding.inner, @@ -616,7 +625,8 @@ export function getAxisPosition( showLabels: boolean, ) { const titlePadding = getSimplePadding(axisTitleStyle.padding); - const titleDimension = axisTitleStyle.visible && axisTitleHeight > 0 ? titlePadding.inner + axisTitleHeight + titlePadding.outer : 0; + const titleDimension = + axisTitleStyle.visible && axisTitleHeight > 0 ? titlePadding.inner + axisTitleHeight + titlePadding.outer : 0; const { position } = axisSpec; const { maxLabelBboxHeight, maxLabelBboxWidth } = axisDim; const { top, left, height, width } = chartDimensions; @@ -656,10 +666,7 @@ export function getAxisPosition( return { dimensions, topIncrement, bottomIncrement, leftIncrement, rightIncrement }; } -export function shouldShowTicks( - { visible, strokeWidth, size }: AxisStyle['tickLine'], - axisHidden: boolean, -): boolean { +export function shouldShowTicks({ visible, strokeWidth, size }: AxisStyle['tickLine'], axisHidden: boolean): boolean { return !axisHidden && visible && size > 0 && strokeWidth >= MIN_STROKE_WIDTH; } @@ -723,12 +730,7 @@ export function getAxisTicksPositions( const tickFormatOptions = { timeZone: xDomain.timeZone, }; - const { - axisTitle, - tickLine, - tickLabel, - gridLine, - } = axesStyles.get(id) ?? sharedAxesStyle; + const { axisTitle, tickLine, tickLabel, gridLine } = axesStyles.get(id) ?? sharedAxesStyle; const allTicks = getAvailableTicks(axisSpec, scale, totalGroupsCount, enableHistogramMode, tickFormatOptions); const visibleTicks = getVisibleTicks(allTicks, axisSpec, axisDim); const isVertical = isVerticalAxis(axisSpec.position); @@ -762,7 +764,7 @@ export function getAxisTicksPositions( cumRightSum, labelPaddingSum, tickDimension, - tickLabel.visible + tickLabel.visible, ); cumTopSum += axisPosition.topIncrement; @@ -808,11 +810,11 @@ export const isDuplicateAxis = ( let hasDuplicate = false; tickMap.forEach(({ tickLabels: axisTickLabels }, axisId) => { if ( - !hasDuplicate - && axisTickLabels - && tickLabels.length === axisTickLabels.length - && firstTickLabel === axisTickLabels[0] - && lastTickLabel === axisTickLabels.slice(-1)[0] + !hasDuplicate && + axisTickLabels && + tickLabels.length === axisTickLabels.length && + firstTickLabel === axisTickLabels[0] && + lastTickLabel === axisTickLabels.slice(-1)[0] ) { const spec = getSpecsById(specs, axisId); diff --git a/src/chart_types/xy_chart/utils/dimensions.ts b/src/chart_types/xy_chart/utils/dimensions.ts index 805e1278fe..9bc152d0f7 100644 --- a/src/chart_types/xy_chart/utils/dimensions.ts +++ b/src/chart_types/xy_chart/utils/dimensions.ts @@ -75,7 +75,8 @@ export function computeChartDimensions( const labelPaddingSum = tickLabel.visible ? labelPadding.inner + labelPadding.outer : 0; const tickDimension = showTicks ? tickLine.size + tickLine.padding : 0; - const titleHeight = title !== undefined && axisTitle.visible ? axisTitle.fontSize + titlePadding.outer + titlePadding.inner : 0; + const titleHeight = + title !== undefined && axisTitle.visible ? axisTitle.fontSize + titlePadding.outer + titlePadding.inner : 0; const axisDimension = labelPaddingSum + tickDimension + titleHeight; const maxAxisHeight = tickLabel.visible ? maxLabelBboxHeight + axisDimension : axisDimension; const maxAxisWidth = tickLabel.visible ? maxLabelBboxWidth + axisDimension : axisDimension; diff --git a/src/chart_types/xy_chart/utils/fill_series.ts b/src/chart_types/xy_chart/utils/fill_series.ts index 0ad4e8e8a8..81502dcd59 100644 --- a/src/chart_types/xy_chart/utils/fill_series.ts +++ b/src/chart_types/xy_chart/utils/fill_series.ts @@ -19,7 +19,6 @@ import { SpecId } from '../../../utils/ids'; import { DataSeries } from './series'; - /** * * @param series diff --git a/src/chart_types/xy_chart/utils/fit_function.test.ts b/src/chart_types/xy_chart/utils/fit_function.test.ts index fd3c3c8521..b21eb2699c 100644 --- a/src/chart_types/xy_chart/utils/fit_function.test.ts +++ b/src/chart_types/xy_chart/utils/fit_function.test.ts @@ -202,7 +202,7 @@ describe('Fit Function', () => { }); }); - describe('endValue is set to \'nearest\'', () => { + describe("endValue is set to 'nearest'", () => { it('should return current datum with value from next when previous is null', () => { const current = MockDataSeriesDatum.simple({ x: 3 }); const next = MockDataSeriesDatum.full({ x: 4, y1: 20 }); @@ -399,7 +399,7 @@ describe('Fit Function', () => { }); }); - describe('endValue is set to \'nearest\'', () => { + describe("endValue is set to 'nearest'", () => { it('should return current datum with value from next when previous is null', () => { const current = MockDataSeriesDatum.simple({ x: 'c' }); const next = MockDataSeriesDatum.full({ x: 'e', y1: 20, fittingIndex: 4 }); @@ -588,7 +588,11 @@ describe('Fit Function', () => { }); it('should set end values - Explicit', () => { - const actual = testModule.fitFunction(sortedDS.data, { type: Fit.Explicit, value: 20, endValue }, scaleType); + const actual = testModule.fitFunction( + sortedDS.data, + { type: Fit.Explicit, value: 20, endValue }, + scaleType, + ); const finalValues = getYResolvedData(actual); expect(finalValues[0]).toEqual(20); @@ -628,7 +632,7 @@ describe('Fit Function', () => { }); }); - describe('\'nearest\' value', () => { + describe("'nearest' value", () => { const endValue = 'nearest'; it('should set end values - None', () => { @@ -648,7 +652,11 @@ describe('Fit Function', () => { }); it('should set end values - Explicit', () => { - const actual = testModule.fitFunction(sortedDS.data, { type: Fit.Explicit, value: 20, endValue }, scaleType); + const actual = testModule.fitFunction( + sortedDS.data, + { type: Fit.Explicit, value: 20, endValue }, + scaleType, + ); const finalValues = getYResolvedData(actual); expect(finalValues[0]).toEqual(20); diff --git a/src/chart_types/xy_chart/utils/fit_function.ts b/src/chart_types/xy_chart/utils/fit_function.ts index dea33ebd6b..d18f5ddaca 100644 --- a/src/chart_types/xy_chart/utils/fit_function.ts +++ b/src/chart_types/xy_chart/utils/fit_function.ts @@ -47,7 +47,10 @@ export type WithIndex = T & { fittingIndex: number }; * Returns `[x, y1]` values for a given datum with `fittingIndex` * */ -const getXYValues = ({ x, y1, fittingIndex }: WithIndex): [number, number] => [typeof x === 'string' ? fittingIndex : x, y1]; +const getXYValues = ({ x, y1, fittingIndex }: WithIndex): [number, number] => [ + typeof x === 'string' ? fittingIndex : x, + y1, +]; /** @internal */ export const getValue = ( @@ -217,7 +220,8 @@ export const fitFunction = ( })); } - const sortedData = sorted || xScaleType === ScaleType.Ordinal ? data : data.slice().sort(datumXSortPredicate(xScaleType)); + const sortedData = + sorted || xScaleType === ScaleType.Ordinal ? data : data.slice().sort(datumXSortPredicate(xScaleType)); const newData: DataSeriesDatum[] = []; let previousNonNullDatum: WithIndex | null = null; let nextNonNullDatum: WithIndex | null = null; @@ -227,13 +231,13 @@ export const fitFunction = ( const currentValue = sortedData[i]; if ( - currentValue.y1 === null - && nextNonNullDatum === null - && (type === Fit.Lookahead - || type === Fit.Nearest - || type === Fit.Average - || type === Fit.Linear - || endValue === 'nearest') + currentValue.y1 === null && + nextNonNullDatum === null && + (type === Fit.Lookahead || + type === Fit.Nearest || + type === Fit.Average || + type === Fit.Linear || + endValue === 'nearest') ) { // Forward lookahead to get next non-null value for (j = i + 1; j < sortedData.length; j++) { @@ -249,7 +253,10 @@ export const fitFunction = ( } } - const newValue = currentValue.y1 === null ? getValue(currentValue, i, previousNonNullDatum, nextNonNullDatum, type, endValue) : currentValue; + const newValue = + currentValue.y1 === null + ? getValue(currentValue, i, previousNonNullDatum, nextNonNullDatum, type, endValue) + : currentValue; newData[i] = newValue; diff --git a/src/chart_types/xy_chart/utils/fit_function_utils.ts b/src/chart_types/xy_chart/utils/fit_function_utils.ts index cc1d77b904..d17dba29b8 100644 --- a/src/chart_types/xy_chart/utils/fit_function_utils.ts +++ b/src/chart_types/xy_chart/utils/fit_function_utils.ts @@ -23,7 +23,6 @@ import { fitFunction } from './fit_function'; import { DataSeries } from './series'; import { isAreaSeriesSpec, isLineSeriesSpec, SeriesSpecs, BasicSeriesSpec } from './specs'; - /** @internal */ export const applyFitFunctionToDataSeries = ( dataseries: DataSeries[], @@ -37,10 +36,10 @@ export const applyFitFunctionToDataSeries = ( const spec = getSpecsById(seriesSpecs, specId); if ( - spec !== null - && spec !== undefined - && (isAreaSeriesSpec(spec) || isLineSeriesSpec(spec)) - && spec.fit !== undefined + spec !== null && + spec !== undefined && + (isAreaSeriesSpec(spec) || isLineSeriesSpec(spec)) && + spec.fit !== undefined ) { const fittedData = fitFunction(data, spec.fit, xScaleType); diff --git a/src/chart_types/xy_chart/utils/interactions.ts b/src/chart_types/xy_chart/utils/interactions.ts index 40bf069667..dbd384954f 100644 --- a/src/chart_types/xy_chart/utils/interactions.ts +++ b/src/chart_types/xy_chart/utils/interactions.ts @@ -63,7 +63,7 @@ export function areIndexedGeometryArraysEquals(arr1: IndexedGeometry[], arr2: In if (arr1.length !== arr2.length) { return false; } - for (let i = arr1.length; i--;) { + for (let i = arr1.length; i--; ) { return areIndexedGeomsEquals(arr1[i], arr2[i]); } return true; @@ -82,22 +82,22 @@ export function areIndexedGeomsEquals(ig1: IndexedGeometry, ig2: IndexedGeometry function arePointsEqual(ig1: PointGeometry, ig2: PointGeometry) { return ( - ig1.seriesIdentifier.specId === ig2.seriesIdentifier.specId - && ig1.color === ig2.color - && ig1.x === ig2.x - && ig1.transform.x === ig2.transform.x - && ig1.transform.y === ig2.transform.y - && ig1.y === ig2.y - && ig1.radius === ig2.radius + ig1.seriesIdentifier.specId === ig2.seriesIdentifier.specId && + ig1.color === ig2.color && + ig1.x === ig2.x && + ig1.transform.x === ig2.transform.x && + ig1.transform.y === ig2.transform.y && + ig1.y === ig2.y && + ig1.radius === ig2.radius ); } function areBarEqual(ig1: BarGeometry, ig2: BarGeometry) { return ( - ig1.seriesIdentifier.specId === ig2.seriesIdentifier.specId - && ig1.color === ig2.color - && ig1.x === ig2.x - && ig1.y === ig2.y - && ig1.width === ig2.width - && ig1.height === ig2.height + ig1.seriesIdentifier.specId === ig2.seriesIdentifier.specId && + ig1.color === ig2.color && + ig1.x === ig2.x && + ig1.y === ig2.y && + ig1.width === ig2.width && + ig1.height === ig2.height ); } 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 b7d3692d38..b7d92d22ed 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 @@ -91,13 +91,19 @@ describe('Non-Stacked Series Utils', () => { test('empty data', () => { const store = MockStore.default(); MockStore.addSpecs(EMPTY_DATA_SET, store); - const { formattedDataSeries: { nonStacked } } = computeSeriesDomainsSelector(store.getState()); + const { + formattedDataSeries: { nonStacked }, + } = computeSeriesDomainsSelector(store.getState()); expect(nonStacked).toHaveLength(0); }); test('format data without nulls', () => { const store = MockStore.default(); MockStore.addSpecs(STANDARD_DATA_SET, store); - const { formattedDataSeries: { nonStacked: [{ dataSeries }] } } = computeSeriesDomainsSelector(store.getState()); + const { + formattedDataSeries: { + nonStacked: [{ dataSeries }], + }, + } = computeSeriesDomainsSelector(store.getState()); expect(dataSeries[0].data[0]).toMatchObject({ initialY0: null, @@ -127,8 +133,11 @@ describe('Non-Stacked Series Utils', () => { test('format data with nulls', () => { const store = MockStore.default(); MockStore.addSpecs(WITH_NULL_DATASET, store); - const { formattedDataSeries: { nonStacked: [{ dataSeries }] } } = computeSeriesDomainsSelector(store.getState()); - + const { + formattedDataSeries: { + nonStacked: [{ dataSeries }], + }, + } = computeSeriesDomainsSelector(store.getState()); expect(dataSeries[1].data[0]).toMatchObject({ initialY0: null, @@ -142,8 +151,11 @@ describe('Non-Stacked Series Utils', () => { test('format data without nulls with y0 values', () => { const store = MockStore.default(); MockStore.addSpecs(STANDARD_DATA_SET_WY0, store); - const { formattedDataSeries: { nonStacked: [{ dataSeries }] } } = computeSeriesDomainsSelector(store.getState()); - + const { + formattedDataSeries: { + nonStacked: [{ dataSeries }], + }, + } = computeSeriesDomainsSelector(store.getState()); expect(dataSeries[0].data[0]).toMatchObject({ initialY0: 2, @@ -173,7 +185,11 @@ describe('Non-Stacked Series Utils', () => { test('format data with nulls - fit functions', () => { const store = MockStore.default(); MockStore.addSpecs(WITH_NULL_DATASET_WY0, store); - const { formattedDataSeries: { nonStacked: [{ dataSeries }] } } = computeSeriesDomainsSelector(store.getState()); + const { + formattedDataSeries: { + nonStacked: [{ dataSeries }], + }, + } = computeSeriesDomainsSelector(store.getState()); expect(dataSeries[0].data[0]).toMatchObject({ initialY0: 2, @@ -203,8 +219,11 @@ describe('Non-Stacked Series Utils', () => { test('format data without nulls on second series', () => { const store = MockStore.default(); MockStore.addSpecs(DATA_SET_WITH_NULL_2, store); - const { formattedDataSeries: { nonStacked: [{ dataSeries }] } } = computeSeriesDomainsSelector(store.getState()); - + const { + formattedDataSeries: { + nonStacked: [{ dataSeries }], + }, + } = computeSeriesDomainsSelector(store.getState()); expect(dataSeries.length).toBe(2); expect(dataSeries[0].data.length).toBe(4); @@ -219,7 +238,6 @@ describe('Non-Stacked Series Utils', () => { mark: null, }); expect(dataSeries[0].data[1]).toMatchObject({ - initialY0: null, initialY1: 2, x: 2, @@ -236,7 +254,6 @@ describe('Non-Stacked Series Utils', () => { mark: null, }); expect(dataSeries[1].data[0]).toMatchObject({ - initialY0: null, initialY1: 21, x: 1, @@ -245,7 +262,6 @@ describe('Non-Stacked Series Utils', () => { mark: null, }); expect(dataSeries[1].data[2]).toMatchObject({ - initialY0: null, initialY1: 23, x: 3, @@ -260,7 +276,8 @@ describe('Non-Stacked Series Utils', () => { describe.each(['area', 'line'])('Spec type - %s', (specType) => { const dataSeries = [MockDataSeries.fitFunction({ shuffle: false })]; const dataSeriesData = MockDataSeries.fitFunction({ shuffle: false }).data; - const spec = specType === 'area' ? MockSeriesSpec.area({ fit: Fit.Linear }) : MockSeriesSpec.line({ fit: Fit.Linear }); + const spec = + specType === 'area' ? MockSeriesSpec.area({ fit: Fit.Linear }) : MockSeriesSpec.line({ fit: Fit.Linear }); const seriesSpecs = MockSeriesSpecs.fromSpecs([spec]); beforeAll(() => { @@ -274,7 +291,8 @@ describe('Non-Stacked Series Utils', () => { }); it('return not call fitFunction if no fit specified', () => { - const currentSpec = specType === 'area' ? MockSeriesSpec.area({ fit: undefined }) : MockSeriesSpec.line({ fit: undefined }); + const currentSpec = + specType === 'area' ? MockSeriesSpec.area({ fit: undefined }) : MockSeriesSpec.line({ fit: undefined }); const noFitSpec = MockSeriesSpecs.fromSpecs([currentSpec]); testModule.applyFitFunctionToDataSeries(dataSeries, noFitSpec, ScaleType.Linear); diff --git a/src/chart_types/xy_chart/utils/series.test.ts b/src/chart_types/xy_chart/utils/series.test.ts index 725295e96f..f278d189ff 100644 --- a/src/chart_types/xy_chart/utils/series.test.ts +++ b/src/chart_types/xy_chart/utils/series.test.ts @@ -108,22 +108,27 @@ describe('Series', () => { }); test('Can stack simple dataseries', () => { const store = MockStore.default(); - MockStore.addSpecs(MockSeriesSpec.area({ - id: 'spec1', - splitSeriesAccessors: ['g'], - yAccessors: ['y1'], - stackAccessors: ['x'], - xScaleType: ScaleType.Linear, - data: [ - { x: 1, y1: 1, g: 'a' }, - { x: 2, y1: 2, g: 'a' }, - { x: 4, y1: 4, g: 'a' }, - { x: 1, y1: 21, g: 'b' }, - { x: 3, y1: 23, g: 'b' }, - ], - }), store); + MockStore.addSpecs( + MockSeriesSpec.area({ + id: 'spec1', + splitSeriesAccessors: ['g'], + yAccessors: ['y1'], + stackAccessors: ['x'], + xScaleType: ScaleType.Linear, + data: [ + { x: 1, y1: 1, g: 'a' }, + { x: 2, y1: 2, g: 'a' }, + { x: 4, y1: 4, g: 'a' }, + { x: 1, y1: 21, g: 'b' }, + { x: 3, y1: 23, g: 'b' }, + ], + }), + store, + ); - const { formattedDataSeries: { stacked } } = computeSeriesDomainsSelector(store.getState()); + const { + formattedDataSeries: { stacked }, + } = computeSeriesDomainsSelector(store.getState()); expect(stacked[0].dataSeries).toMatchSnapshot(); }); @@ -188,21 +193,26 @@ describe('Series', () => { }); test('Can stack unsorted dataseries', () => { const store = MockStore.default(); - MockStore.addSpecs(MockSeriesSpec.area({ - id: 'spec1', - splitSeriesAccessors: ['g'], - yAccessors: ['y1'], - stackAccessors: ['x'], - xScaleType: ScaleType.Linear, - data: [ - { x: 1, y1: 1, g: 'a' }, - { x: 4, y1: 4, g: 'a' }, - { x: 2, y1: 2, g: 'a' }, - { x: 3, y1: 23, g: 'b' }, - { x: 1, y1: 21, g: 'b' }, - ], - }), store); - const { formattedDataSeries: { stacked } } = computeSeriesDomainsSelector(store.getState()); + MockStore.addSpecs( + MockSeriesSpec.area({ + id: 'spec1', + splitSeriesAccessors: ['g'], + yAccessors: ['y1'], + stackAccessors: ['x'], + xScaleType: ScaleType.Linear, + data: [ + { x: 1, y1: 1, g: 'a' }, + { x: 4, y1: 4, g: 'a' }, + { x: 2, y1: 2, g: 'a' }, + { x: 3, y1: 23, g: 'b' }, + { x: 1, y1: 21, g: 'b' }, + ], + }), + store, + ); + const { + formattedDataSeries: { stacked }, + } = computeSeriesDomainsSelector(store.getState()); expect(stacked[0].dataSeries).toMatchSnapshot(); }); @@ -215,7 +225,9 @@ describe('Series', () => { splitAccessors: new Map(), seriesKeys: ['a'], key: 'a', - data: new Array(maxArrayItems).fill(0).map((d, i) => ({ x: i, y1: i, mark: null, y0: null, initialY1: i, initialY0: null, datum: undefined })), + data: new Array(maxArrayItems) + .fill(0) + .map((d, i) => ({ x: i, y1: i, mark: null, y0: null, initialY1: i, initialY0: null, datum: undefined })), }, { specId: 'spec1', @@ -223,7 +235,9 @@ describe('Series', () => { splitAccessors: new Map(), seriesKeys: ['b'], key: 'b', - data: new Array(maxArrayItems).fill(0).map((d, i) => ({ x: i, y1: i, mark: null, y0: null, initialY1: i, initialY0: null, datum: undefined })), + data: new Array(maxArrayItems) + .fill(0) + .map((d, i) => ({ x: i, y1: i, mark: null, y0: null, initialY1: i, initialY0: null, datum: undefined })), }, ]; const xValues = new Set(new Array(maxArrayItems).fill(0).map((d, i) => i)); @@ -232,129 +246,137 @@ describe('Series', () => { }); test('Can stack simple dataseries with scale to extent', () => { const store = MockStore.default(); - MockStore.addSpecs([ - MockGlobalSpec.axis({ - id: 'y', - position: Position.Left, - domain: { fit: true }, - }), - MockSeriesSpec.bar({ - id: 'spec1', - yAccessors: ['y1'], - splitSeriesAccessors: ['g'], - stackAccessors: ['x'], - xScaleType: ScaleType.Linear, - data: [ - { x: 1, y1: 1, g: 'a' }, - { x: 2, y1: 2, g: 'a' }, - { x: 4, y1: 4, g: 'a' }, - { x: 1, y1: 21, g: 'b' }, - { x: 3, y1: 23, g: 'b' }, - ], - }), - ], - store); + MockStore.addSpecs( + [ + MockGlobalSpec.axis({ + id: 'y', + position: Position.Left, + domain: { fit: true }, + }), + MockSeriesSpec.bar({ + id: 'spec1', + yAccessors: ['y1'], + splitSeriesAccessors: ['g'], + stackAccessors: ['x'], + xScaleType: ScaleType.Linear, + data: [ + { x: 1, y1: 1, g: 'a' }, + { x: 2, y1: 2, g: 'a' }, + { x: 4, y1: 4, g: 'a' }, + { x: 1, y1: 21, g: 'b' }, + { x: 3, y1: 23, g: 'b' }, + ], + }), + ], + store, + ); const seriesDomains = computeSeriesDomainsSelector(store.getState()); expect(seriesDomains.formattedDataSeries.stacked[0].dataSeries).toMatchSnapshot(); }); test('Can stack multiple dataseries with scale to extent', () => { const store = MockStore.default(); - MockStore.addSpecs([ - MockGlobalSpec.axis({ - id: 'y', - position: Position.Left, - domain: { fit: true }, - }), - MockSeriesSpec.bar({ - id: 'spec1', - yAccessors: ['y1'], - splitSeriesAccessors: ['g'], - stackAccessors: ['x'], - xScaleType: ScaleType.Linear, - data: [ - { x: 1, y1: 1, g: 'a' }, - { x: 2, y1: 2, g: 'a' }, - { x: 3, y1: 3, g: 'a' }, - { x: 4, y1: 4, g: 'a' }, - { x: 1, y1: 1, g: 'b' }, - { x: 2, y1: 2, g: 'b' }, - { x: 3, y1: 3, g: 'b' }, - { x: 4, y1: 4, g: 'b' }, - { x: 1, y1: 1, g: 'c' }, - { x: 2, y1: 2, g: 'c' }, - { x: 3, y1: 3, g: 'c' }, - { x: 4, y1: 4, g: 'c' }, - { x: 1, y1: 1, g: 'd' }, - { x: 2, y1: 2, g: 'd' }, - { x: 3, y1: 3, g: 'd' }, - { x: 4, y1: 4, g: 'd' }, - ], - }), - ], - store); + MockStore.addSpecs( + [ + MockGlobalSpec.axis({ + id: 'y', + position: Position.Left, + domain: { fit: true }, + }), + MockSeriesSpec.bar({ + id: 'spec1', + yAccessors: ['y1'], + splitSeriesAccessors: ['g'], + stackAccessors: ['x'], + xScaleType: ScaleType.Linear, + data: [ + { x: 1, y1: 1, g: 'a' }, + { x: 2, y1: 2, g: 'a' }, + { x: 3, y1: 3, g: 'a' }, + { x: 4, y1: 4, g: 'a' }, + { x: 1, y1: 1, g: 'b' }, + { x: 2, y1: 2, g: 'b' }, + { x: 3, y1: 3, g: 'b' }, + { x: 4, y1: 4, g: 'b' }, + { x: 1, y1: 1, g: 'c' }, + { x: 2, y1: 2, g: 'c' }, + { x: 3, y1: 3, g: 'c' }, + { x: 4, y1: 4, g: 'c' }, + { x: 1, y1: 1, g: 'd' }, + { x: 2, y1: 2, g: 'd' }, + { x: 3, y1: 3, g: 'd' }, + { x: 4, y1: 4, g: 'd' }, + ], + }), + ], + store, + ); const seriesDomains = computeSeriesDomainsSelector(store.getState()); expect(seriesDomains.formattedDataSeries.stacked[0].dataSeries).toMatchSnapshot(); }); test('Can stack simple dataseries with y0', () => { const store = MockStore.default(); - MockStore.addSpecs([ - MockGlobalSpec.axis({ - id: 'y', - position: Position.Left, - domain: { fit: true }, - }), - MockSeriesSpec.bar({ - id: 'spec1', - yAccessors: ['y1'], - y0Accessors: ['y0'], - splitSeriesAccessors: ['g'], - stackAccessors: ['x'], - xScaleType: ScaleType.Linear, - data: [ - { x: 1, y1: 3, y0: 1, g: 'a' }, - { x: 2, y1: 3, y0: 2, g: 'a' }, - { x: 4, y1: 4, y0: 3, g: 'a' }, - { x: 1, y1: 2, y0: 1, g: 'b' }, - { x: 2, y1: 3, y0: 1, g: 'b' }, - { x: 3, y1: 23, y0: 4, g: 'b' }, - { x: 4, y1: 4, y0: 1, g: 'b' }, - ], - }), - ], - store); + MockStore.addSpecs( + [ + MockGlobalSpec.axis({ + id: 'y', + position: Position.Left, + domain: { fit: true }, + }), + MockSeriesSpec.bar({ + id: 'spec1', + yAccessors: ['y1'], + y0Accessors: ['y0'], + splitSeriesAccessors: ['g'], + stackAccessors: ['x'], + xScaleType: ScaleType.Linear, + data: [ + { x: 1, y1: 3, y0: 1, g: 'a' }, + { x: 2, y1: 3, y0: 2, g: 'a' }, + { x: 4, y1: 4, y0: 3, g: 'a' }, + { x: 1, y1: 2, y0: 1, g: 'b' }, + { x: 2, y1: 3, y0: 1, g: 'b' }, + { x: 3, y1: 23, y0: 4, g: 'b' }, + { x: 4, y1: 4, y0: 1, g: 'b' }, + ], + }), + ], + store, + ); const seriesDomains = computeSeriesDomainsSelector(store.getState()); expect(seriesDomains.formattedDataSeries.stacked[0].dataSeries).toMatchSnapshot(); }); test('Can stack simple dataseries with scale to extent with y0', () => { const store = MockStore.default(); - MockStore.addSpecs([ - MockGlobalSpec.axis({ - id: 'y', - position: Position.Left, - domain: { fit: true }, - }), - MockSeriesSpec.bar({ - id: 'spec1', - yAccessors: ['y1'], - y0Accessors: ['y0'], - splitSeriesAccessors: ['g'], - stackAccessors: ['x'], - xScaleType: ScaleType.Linear, - data: [ - { x: 1, y1: 3, y0: 1, g: 'a' }, - { x: 2, y1: 3, y0: 2, g: 'a' }, - { x: 4, y1: 4, y0: 3, g: 'a' }, - { x: 1, y1: 2, y0: 1, g: 'b' }, - { x: 2, y1: 3, y0: 1, g: 'b' }, - { x: 3, y1: 23, y0: 4, g: 'b' }, - { x: 4, y1: 4, y0: 1, g: 'b' }, - ], - }), - ], - store); + MockStore.addSpecs( + [ + MockGlobalSpec.axis({ + id: 'y', + position: Position.Left, + domain: { fit: true }, + }), + MockSeriesSpec.bar({ + id: 'spec1', + yAccessors: ['y1'], + y0Accessors: ['y0'], + splitSeriesAccessors: ['g'], + stackAccessors: ['x'], + xScaleType: ScaleType.Linear, + data: [ + { x: 1, y1: 3, y0: 1, g: 'a' }, + { x: 2, y1: 3, y0: 2, g: 'a' }, + { x: 4, y1: 4, y0: 3, g: 'a' }, + { x: 1, y1: 2, y0: 1, g: 'b' }, + { x: 2, y1: 3, y0: 1, g: 'b' }, + { x: 3, y1: 23, y0: 4, g: 'b' }, + { x: 4, y1: 4, y0: 1, g: 'b' }, + ], + }), + ], + store, + ); const seriesDomains = computeSeriesDomainsSelector(store.getState()); expect(seriesDomains.formattedDataSeries.stacked[0].dataSeries).toMatchSnapshot(); diff --git a/src/chart_types/xy_chart/utils/series.ts b/src/chart_types/xy_chart/utils/series.ts index 19a2afcdb8..1c9bb7c50a 100644 --- a/src/chart_types/xy_chart/utils/series.ts +++ b/src/chart_types/xy_chart/utils/series.ts @@ -85,7 +85,7 @@ export interface FormattedDataSeries { } /** @internal */ -export type DataSeriesCounts = {[key in SeriesTypes]: number}; +export type DataSeriesCounts = { [key in SeriesTypes]: number }; /** @internal */ export type SeriesCollectionValue = { @@ -127,7 +127,7 @@ export function splitSeriesDataByAccessors({ xValues: Array; } { const dataSeries = new Map(); - const xValues: Array = []; + const xValues: Array = []; const nonNumericValues: any[] = []; data.forEach((datum) => { @@ -183,8 +183,9 @@ export function splitSeriesDataByAccessors({ }); if (nonNumericValues.length > 0) { - Logger.warn(`Found non-numeric y value${nonNumericValues.length > 1 ? 's' : ''} in dataset for spec "${specId}"`, - `(${nonNumericValues.map((v) => JSON.stringify(v)).join(', ')})` + Logger.warn( + `Found non-numeric y value${nonNumericValues.length > 1 ? 's' : ''} in dataset for spec "${specId}"`, + `(${nonNumericValues.map((v) => JSON.stringify(v)).join(', ')})`, ); } @@ -238,12 +239,8 @@ export function extractYandMarkFromDatum( y0Accessor?: Accessor, markSizeAccessor?: Accessor | AccessorFn, ): Pick { - const mark = markSizeAccessor === undefined - ? null - : castToNumber( - getAccessorValue(datum, markSizeAccessor), - nonNumericValues - ); + const mark = + markSizeAccessor === undefined ? null : castToNumber(getAccessorValue(datum, markSizeAccessor), nonNumericValues); const y1 = castToNumber(datum[yAccessor], nonNumericValues); const y0 = y0Accessor ? castToNumber(datum[y0Accessor as keyof typeof datum], nonNumericValues) : null; return { y1, datum, y0, mark, initialY0: y0, initialY1: y1 }; @@ -293,11 +290,7 @@ export function getFormattedDataseries( // format stacked data series const stackedDataSeries = getDataSeriesBySpecGroup(groupSpecs.stacked, availableDataSeries); const fittedDataSeries = applyFitFunctionToDataSeries(stackedDataSeries.dataSeries, seriesSpecs, xScaleType); - const fittedAndStackedDataSeries = formatStackedDataSeriesValues( - fittedDataSeries, - xValues, - stackMode, - ); + const fittedAndStackedDataSeries = formatStackedDataSeriesValues(fittedDataSeries, xValues, stackMode); stackedFormattedDataSeries.push({ groupId, @@ -330,24 +323,27 @@ function getDataSeriesBySpecGroup( return seriesSpecs.reduce<{ dataSeries: DataSeries[]; counts: DataSeriesCounts; - }>((acc, { id, seriesType }) => { - const ds = dataSeries.get(id); - if (!ds) { - return acc; - } + }>( + (acc, { id, seriesType }) => { + const ds = dataSeries.get(id); + if (!ds) { + return acc; + } - acc.dataSeries.push(...ds); - acc.counts[seriesType] += ds.length; - return acc; - }, { - dataSeries: [], - counts: { - [SeriesTypes.Bar]: 0, - [SeriesTypes.Area]: 0, - [SeriesTypes.Line]: 0, - [SeriesTypes.Bubble]: 0, + acc.dataSeries.push(...ds); + acc.counts[seriesType] += ds.length; + return acc; }, - }); + { + dataSeries: [], + counts: { + [SeriesTypes.Bar]: 0, + [SeriesTypes.Area]: 0, + [SeriesTypes.Line]: 0, + [SeriesTypes.Bubble]: 0, + }, + }, + ); } /** @@ -387,10 +383,7 @@ export function getDataSeriesBySpecId( let filteredDataSeries: DataSeries[] = [...dataSeries.values()]; if (deselectedDataSeries.length > 0) { filteredDataSeries = filteredDataSeries.filter( - ({ key }) => - !deselectedDataSeries.some( - ({ key: deselectedKey }) => key === deselectedKey - ) + ({ key }) => !deselectedDataSeries.some(({ key: deselectedKey }) => key === deselectedKey), ); } @@ -422,14 +415,18 @@ export function getDataSeriesBySpecId( dataSeriesBySpecId, seriesCollection, // keep the user order for ordinal scales - xValues: (isOrdinalScale || !isNumberArray) ? globalXValues : new Set([...globalXValues] - .sort((a, b) => { - if (typeof a === 'string' || typeof b === 'string') { - return 0; - } - return a - b; - })), - fallbackScale: (!isOrdinalScale && !isNumberArray) ? ScaleType.Ordinal : undefined, + xValues: + isOrdinalScale || !isNumberArray + ? globalXValues + : new Set( + [...globalXValues].sort((a, b) => { + if (typeof a === 'string' || typeof b === 'string') { + return 0; + } + return a - b; + }), + ), + fallbackScale: !isOrdinalScale && !isNumberArray ? ScaleType.Ordinal : undefined, }; } @@ -488,7 +485,8 @@ export function getSeriesName( } let name = ''; - const nameKeys = spec && spec.yAccessors.length > 1 ? seriesIdentifier.seriesKeys : seriesIdentifier.seriesKeys.slice(0, -1); + const nameKeys = + spec && spec.yAccessors.length > 1 ? seriesIdentifier.seriesKeys : seriesIdentifier.seriesKeys.slice(0, -1); // there is one series, the is only one yAccessor, the first part is not null if (hasSingleSeries || nameKeys.length === 0 || nameKeys[0] == null) { @@ -517,7 +515,9 @@ export function getSortedDataSeriesColorsValuesMap( seriesCollection: Map, ): Map { const seriesColorsArray = [...seriesCollection]; - seriesColorsArray.sort(([, specA], [, specB]) => getSortIndex(specA, seriesCollection.size) - getSortIndex(specB, seriesCollection.size)); + seriesColorsArray.sort( + ([, specA], [, specB]) => getSortIndex(specA, seriesCollection.size) - getSortIndex(specB, seriesCollection.size), + ); return new Map([...seriesColorsArray]); } diff --git a/src/chart_types/xy_chart/utils/specs.ts b/src/chart_types/xy_chart/utils/specs.ts index 89788d6934..32d37ecfb5 100644 --- a/src/chart_types/xy_chart/utils/specs.ts +++ b/src/chart_types/xy_chart/utils/specs.ts @@ -60,7 +60,6 @@ export const SeriesTypes = Object.freeze({ /** @public */ export type SeriesTypes = $Values; - /** * The offset and mode applied when stacking values * @public @@ -89,10 +88,7 @@ export type StackMode = $Values; * - `null`: Keep existing bar style * @public */ -export type BarStyleAccessor = ( - datum: DataSeriesDatum, - seriesIdentifier: XYChartSeriesIdentifier, -) => BarStyleOverride; +export type BarStyleAccessor = (datum: DataSeriesDatum, seriesIdentifier: XYChartSeriesIdentifier) => BarStyleOverride; /** * Override for bar styles per datum * 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 67b74690a2..e9b314ad96 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 @@ -24,11 +24,27 @@ import { computeSeriesDomainsSelector } from '../state/selectors/compute_series_ import { StackMode } from './specs'; describe('Stacked Series Utils', () => { - const STANDARD_DATA_SET = [{ x: 0, y1: 10, g: 'a' }, { x: 0, y1: 20, g: 'b' }, { x: 0, y1: 70, g: 'c' }]; + const STANDARD_DATA_SET = [ + { x: 0, y1: 10, g: 'a' }, + { x: 0, y1: 20, g: 'b' }, + { x: 0, y1: 70, g: 'c' }, + ]; - const WITH_NULL_DATASET = [{ x: 0, y1: 10, g: 'a' }, { x: 0, y1: null, g: 'b' }, { x: 0, y1: 30, g: 'c' }]; - const STANDARD_DATA_SET_WY0 = [{ x: 0, y0: 2, y1: 10, g: 'a' }, { x: 0, y0: 4, y1: 20, g: 'b' }, { x: 0, y0: 6, y1: 70, g: 'c' }]; - const WITH_NULL_DATASET_WY0 = [{ x: 0, y0: 2, y1: 10, g: 'a' }, { x: 0, y1: null, g: 'b' }, { x: 0, y0: 6, y1: 90, mark: null, g: 'c' }]; + const WITH_NULL_DATASET = [ + { x: 0, y1: 10, g: 'a' }, + { x: 0, y1: null, g: 'b' }, + { x: 0, y1: 30, g: 'c' }, + ]; + const STANDARD_DATA_SET_WY0 = [ + { x: 0, y0: 2, y1: 10, g: 'a' }, + { x: 0, y0: 4, y1: 20, g: 'b' }, + { x: 0, y0: 6, y1: 70, g: 'c' }, + ]; + const WITH_NULL_DATASET_WY0 = [ + { x: 0, y0: 2, y1: 10, g: 'a' }, + { x: 0, y1: null, g: 'b' }, + { x: 0, y0: 6, y1: 90, mark: null, g: 'c' }, + ]; const DATA_SET_WITH_NULL_2 = [ { x: 1, y1: 10, g: 'a' }, { x: 2, y1: 20, g: 'a' }, @@ -40,16 +56,19 @@ describe('Stacked Series Utils', () => { describe('Format stacked dataset', () => { test('format data without nulls', () => { const store = MockStore.default(); - MockStore.addSpecs([ - MockSeriesSpec.area({ - xAccessor: 'x', - yAccessors: ['y1'], - splitSeriesAccessors: ['g'], - stackAccessors: ['x'], - stackMode: StackMode.Percentage, - data: STANDARD_DATA_SET, - }), - ], store); + MockStore.addSpecs( + [ + MockSeriesSpec.area({ + xAccessor: 'x', + yAccessors: ['y1'], + splitSeriesAccessors: ['g'], + stackAccessors: ['x'], + stackMode: StackMode.Percentage, + data: STANDARD_DATA_SET, + }), + ], + store, + ); const { formattedDataSeries } = computeSeriesDomainsSelector(store.getState()); const { stacked } = formattedDataSeries; const [data0] = stacked[0].dataSeries[0].data; @@ -69,16 +88,21 @@ describe('Stacked Series Utils', () => { }); test('format data with nulls', () => { const store = MockStore.default(); - MockStore.addSpecs([ - MockSeriesSpec.area({ - yAccessors: ['y1'], - splitSeriesAccessors: ['g'], - stackAccessors: ['x'], - stackMode: StackMode.Percentage, - data: WITH_NULL_DATASET, - }), - ], store); - const { formattedDataSeries: { stacked } } = computeSeriesDomainsSelector(store.getState()); + MockStore.addSpecs( + [ + MockSeriesSpec.area({ + yAccessors: ['y1'], + splitSeriesAccessors: ['g'], + stackAccessors: ['x'], + stackMode: StackMode.Percentage, + data: WITH_NULL_DATASET, + }), + ], + store, + ); + const { + formattedDataSeries: { stacked }, + } = computeSeriesDomainsSelector(store.getState()); const [data0] = stacked[0].dataSeries[0].data; expect(data0.initialY1).toBe(10); @@ -101,17 +125,22 @@ describe('Stacked Series Utils', () => { }); test('format data without nulls with y0 values', () => { const store = MockStore.default(); - MockStore.addSpecs([ - MockSeriesSpec.area({ - yAccessors: ['y1'], - y0Accessors: ['y0'], - splitSeriesAccessors: ['g'], - stackAccessors: ['x'], - stackMode: StackMode.Percentage, - data: STANDARD_DATA_SET_WY0, - }), - ], store); - const { formattedDataSeries: { stacked } } = computeSeriesDomainsSelector(store.getState()); + MockStore.addSpecs( + [ + MockSeriesSpec.area({ + yAccessors: ['y1'], + y0Accessors: ['y0'], + splitSeriesAccessors: ['g'], + stackAccessors: ['x'], + stackMode: StackMode.Percentage, + data: STANDARD_DATA_SET_WY0, + }), + ], + store, + ); + const { + formattedDataSeries: { stacked }, + } = computeSeriesDomainsSelector(store.getState()); const [data0] = stacked[0].dataSeries[0].data; expect(data0.initialY0).toBe(2); @@ -133,18 +162,22 @@ describe('Stacked Series Utils', () => { }); test('format data with nulls - missing points', () => { const store = MockStore.default(); - MockStore.addSpecs([ - MockSeriesSpec.area({ - yAccessors: ['y1'], - y0Accessors: ['y0'], - splitSeriesAccessors: ['g'], - stackAccessors: ['x'], - stackMode: StackMode.Percentage, - data: WITH_NULL_DATASET_WY0, - }), - ], store); - const { formattedDataSeries: { stacked } } = computeSeriesDomainsSelector(store.getState()); - + MockStore.addSpecs( + [ + MockSeriesSpec.area({ + yAccessors: ['y1'], + y0Accessors: ['y0'], + splitSeriesAccessors: ['g'], + stackAccessors: ['x'], + stackMode: StackMode.Percentage, + data: WITH_NULL_DATASET_WY0, + }), + ], + store, + ); + const { + formattedDataSeries: { stacked }, + } = computeSeriesDomainsSelector(store.getState()); const [data0] = stacked[0].dataSeries[0].data; expect(data0.initialY0).toBe(2); @@ -166,19 +199,23 @@ describe('Stacked Series Utils', () => { }); test('format data without nulls on second series', () => { const store = MockStore.default(); - MockStore.addSpecs([ - MockSeriesSpec.area({ - xScaleType: ScaleType.Linear, - yAccessors: ['y1'], - y0Accessors: ['y0'], - splitSeriesAccessors: ['g'], - stackAccessors: ['x'], - stackMode: StackMode.Percentage, - data: DATA_SET_WITH_NULL_2, - }), - ], store); - const { formattedDataSeries: { stacked } } = computeSeriesDomainsSelector(store.getState()); - + MockStore.addSpecs( + [ + MockSeriesSpec.area({ + xScaleType: ScaleType.Linear, + yAccessors: ['y1'], + y0Accessors: ['y0'], + splitSeriesAccessors: ['g'], + stackAccessors: ['x'], + stackMode: StackMode.Percentage, + data: DATA_SET_WITH_NULL_2, + }), + ], + store, + ); + const { + formattedDataSeries: { stacked }, + } = computeSeriesDomainsSelector(store.getState()); expect(stacked[0].dataSeries.length).toBe(2); expect(stacked[0].dataSeries[0].data.length).toBe(4); 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 4356efda8c..3d672578f2 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 @@ -97,13 +97,19 @@ describe('Stacked Series Utils', () => { test('with empty values', () => { const store = MockStore.default(); MockStore.addSpecs(EMPTY_DATA_SET, store); - const { formattedDataSeries: { stacked } } = computeSeriesDomainsSelector(store.getState()); + const { + formattedDataSeries: { stacked }, + } = computeSeriesDomainsSelector(store.getState()); expect(stacked).toHaveLength(0); }); test('with basic values', () => { const store = MockStore.default(); MockStore.addSpecs(STANDARD_DATA_SET, store); - const { formattedDataSeries: { stacked: [{ dataSeries }] } } = computeSeriesDomainsSelector(store.getState()); + const { + formattedDataSeries: { + stacked: [{ dataSeries }], + }, + } = computeSeriesDomainsSelector(store.getState()); const values = [ dataSeries[0].data[0].y0, @@ -121,8 +127,13 @@ describe('Stacked Series Utils', () => { ...STANDARD_DATA_SET, stackMode: StackMode.Percentage, }), - store); - const { formattedDataSeries: { stacked: [{ dataSeries }] } } = computeSeriesDomainsSelector(store.getState()); + store, + ); + const { + formattedDataSeries: { + stacked: [{ dataSeries }], + }, + } = computeSeriesDomainsSelector(store.getState()); const values = [ dataSeries[0].data[0].y0, @@ -135,7 +146,11 @@ describe('Stacked Series Utils', () => { test('with null values', () => { const store = MockStore.default(); MockStore.addSpecs(WITH_NULL_DATASET, store); - const { formattedDataSeries: { stacked: [{ dataSeries }] } } = computeSeriesDomainsSelector(store.getState()); + const { + formattedDataSeries: { + stacked: [{ dataSeries }], + }, + } = computeSeriesDomainsSelector(store.getState()); const values = [ dataSeries[0].data[0].y0, @@ -147,11 +162,18 @@ describe('Stacked Series Utils', () => { }); test('with null values as percentage', () => { const store = MockStore.default(); - MockStore.addSpecs(MockSeriesSpec.area({ - ...WITH_NULL_DATASET, - stackMode: StackMode.Percentage, - }), store); - const { formattedDataSeries: { stacked: [{ dataSeries }] } } = computeSeriesDomainsSelector(store.getState()); + MockStore.addSpecs( + MockSeriesSpec.area({ + ...WITH_NULL_DATASET, + stackMode: StackMode.Percentage, + }), + store, + ); + const { + formattedDataSeries: { + stacked: [{ dataSeries }], + }, + } = computeSeriesDomainsSelector(store.getState()); const values = [ dataSeries[0].data[0].y0, @@ -166,7 +188,11 @@ describe('Stacked Series Utils', () => { test('format data without nulls', () => { const store = MockStore.default(); MockStore.addSpecs(STANDARD_DATA_SET, store); - const { formattedDataSeries: { stacked: [{ dataSeries }] } } = computeSeriesDomainsSelector(store.getState()); + const { + formattedDataSeries: { + stacked: [{ dataSeries }], + }, + } = computeSeriesDomainsSelector(store.getState()); expect(dataSeries[0].data[0]).toMatchObject({ initialY0: null, @@ -196,10 +222,13 @@ describe('Stacked Series Utils', () => { test('format data with nulls', () => { const store = MockStore.default(); MockStore.addSpecs(WITH_NULL_DATASET, store); - const { formattedDataSeries: { stacked: [{ dataSeries }] } } = computeSeriesDomainsSelector(store.getState()); + const { + formattedDataSeries: { + stacked: [{ dataSeries }], + }, + } = computeSeriesDomainsSelector(store.getState()); expect(dataSeries[1].data[0]).toMatchObject({ - initialY0: null, initialY1: null, x: 0, @@ -211,7 +240,11 @@ describe('Stacked Series Utils', () => { test('format data without nulls with y0 values', () => { const store = MockStore.default(); MockStore.addSpecs(STANDARD_DATA_SET_WY0, store); - const { formattedDataSeries: { stacked: [{ dataSeries }] } } = computeSeriesDomainsSelector(store.getState()); + const { + formattedDataSeries: { + stacked: [{ dataSeries }], + }, + } = computeSeriesDomainsSelector(store.getState()); expect(dataSeries[0].data[0]).toMatchObject({ initialY0: 2, @@ -241,7 +274,11 @@ describe('Stacked Series Utils', () => { test('format data with nulls - missing points', () => { const store = MockStore.default(); MockStore.addSpecs(WITH_NULL_DATASET_WY0, store); - const { formattedDataSeries: { stacked: [{ dataSeries }] } } = computeSeriesDomainsSelector(store.getState()); + const { + formattedDataSeries: { + stacked: [{ dataSeries }], + }, + } = computeSeriesDomainsSelector(store.getState()); expect(dataSeries[0].data[0]).toMatchObject({ initialY0: 2, @@ -271,7 +308,11 @@ describe('Stacked Series Utils', () => { test('format data without nulls on second series', () => { const store = MockStore.default(); MockStore.addSpecs(DATA_SET_WITH_NULL_2, store); - const { formattedDataSeries: { stacked: [{ dataSeries }] } } = computeSeriesDomainsSelector(store.getState()); + const { + formattedDataSeries: { + stacked: [{ dataSeries }], + }, + } = computeSeriesDomainsSelector(store.getState()); expect(dataSeries.length).toBe(2); expect(dataSeries[0].data.length).toBe(4); @@ -321,17 +362,24 @@ describe('Stacked Series Utils', () => { }); test('Correctly handle 0 values on percentage stack', () => { const store = MockStore.default(); - MockStore.addSpecs(MockSeriesSpec.area({ - xScaleType: ScaleType.Linear, - yAccessors: ['y1'], - splitSeriesAccessors: ['g'], - stackAccessors: ['x'], - data: [ - { x: 1, y1: 0, g: 'a' }, - { x: 1, y1: 0, g: 'b' }, - ], - }), store); - const { formattedDataSeries: { stacked: [{ dataSeries }] } } = computeSeriesDomainsSelector(store.getState()); + MockStore.addSpecs( + MockSeriesSpec.area({ + xScaleType: ScaleType.Linear, + yAccessors: ['y1'], + splitSeriesAccessors: ['g'], + stackAccessors: ['x'], + data: [ + { x: 1, y1: 0, g: 'a' }, + { x: 1, y1: 0, g: 'b' }, + ], + }), + store, + ); + const { + formattedDataSeries: { + stacked: [{ dataSeries }], + }, + } = computeSeriesDomainsSelector(store.getState()); expect(dataSeries[0].data[0]).toMatchObject({ initialY0: null, diff --git a/src/chart_types/xy_chart/utils/stacked_series_utils.ts b/src/chart_types/xy_chart/utils/stacked_series_utils.ts index 305cdce620..7bc3bf1d6c 100644 --- a/src/chart_types/xy_chart/utils/stacked_series_utils.ts +++ b/src/chart_types/xy_chart/utils/stacked_series_utils.ts @@ -40,29 +40,22 @@ export interface StackedValues { } /** @internal */ -export const datumXSortPredicate = ( - xScaleType: ScaleType, - sortedXValues?: (string | number)[] -) => (a: { x: number | string }, b: { x: number | string }) => { - if ( - xScaleType === ScaleType.Ordinal - || typeof a.x === 'string' - || typeof b.x === 'string' - ) { - return sortedXValues - ? sortedXValues.indexOf(a.x) - sortedXValues.indexOf(b.x) - : 0; +export const datumXSortPredicate = (xScaleType: ScaleType, sortedXValues?: (string | number)[]) => ( + a: { x: number | string }, + b: { x: number | string }, +) => { + if (xScaleType === ScaleType.Ordinal || typeof a.x === 'string' || typeof b.x === 'string') { + return sortedXValues ? sortedXValues.indexOf(a.x) - sortedXValues.indexOf(b.x) : 0; } return a.x - b.x; }; - type D3StackArrayElement = Record; type D3UnionStack = Record< SeriesKey, { - y0: SeriesPoint[], - y1: SeriesPoint[], + y0: SeriesPoint[]; + y1: SeriesPoint[]; } >; @@ -79,10 +72,10 @@ export function formatStackedDataSeriesValues( const xValuesArray = [...xValues]; const reorderedArray: Array = []; - const xValueMap: Map> = new Map(); + const xValueMap: Map> = new Map(); // transforming the current set of series into the d3 stack required data structure dataSeries.forEach(({ data, key }) => { - const dsMap: Map = new Map(); + const dsMap: Map = new Map(); data.forEach((d) => { const { x, y0, y1 } = d; const xIndex = xValuesArray.indexOf(x); @@ -102,7 +95,7 @@ export function formatStackedDataSeriesValues( const stackOffset = getOffsetBasedOnStackMode(stackMode); - const keys = Object.keys(dataSeriesKeys).reduce((acc, key) => ([...acc, `${key}-y0`, `${key}-y1`]), []); + const keys = Object.keys(dataSeriesKeys).reduce((acc, key) => [...acc, `${key}-y0`, `${key}-y1`], []); const stack = D3Stack() .keys(keys) @@ -125,34 +118,35 @@ export function formatStackedDataSeriesValues( return acc; }, {}); - return Object.keys(unionedYStacks).map((stackedDataSeriesKey) => { const dataSeriesProps = dataSeriesKeys[stackedDataSeriesKey]; const dsMap = xValueMap.get(stackedDataSeriesKey); const { y0: y0StackArray, y1: y1StackArray } = unionedYStacks[stackedDataSeriesKey]; - const data = y1StackArray.map((y1Stack, index) => { - const { x } = y1Stack.data; - if (x === undefined || x === null) { - return null; - } - const originalData = dsMap?.get(x); - if (!originalData) { - return null; - } - const [,y0] = y0StackArray[index]; - const [,y1] = y1Stack; - const { initialY0, initialY1, mark, datum, filled } = originalData; - return { - x, - y1, - y0, - initialY0, - initialY1, - mark, - datum, - filled, - }; - }).filter((d) => d !== null) as DataSeriesDatum[]; + const data = y1StackArray + .map((y1Stack, index) => { + const { x } = y1Stack.data; + if (x === undefined || x === null) { + return null; + } + const originalData = dsMap?.get(x); + if (!originalData) { + return null; + } + const [, y0] = y0StackArray[index]; + const [, y1] = y1Stack; + const { initialY0, initialY1, mark, datum, filled } = originalData; + return { + x, + y1, + y0, + initialY0, + initialY1, + mark, + datum, + filled, + }; + }) + .filter((d) => d !== null) as DataSeriesDatum[]; return { ...dataSeriesProps, data, @@ -160,7 +154,6 @@ export function formatStackedDataSeriesValues( }); } - function getOffsetBasedOnStackMode(stackMode?: StackMode) { switch (stackMode) { case StackMode.Percentage: diff --git a/src/components/chart.test.tsx b/src/components/chart.test.tsx index 182e73244d..a5f0df89b3 100644 --- a/src/components/chart.test.tsx +++ b/src/components/chart.test.tsx @@ -24,12 +24,12 @@ import { Settings, BarSeries } from '../specs'; import { Chart } from './chart'; describe('Chart', () => { - it('should render \'No data to display\' without series', () => { + it("should render 'No data to display' without series", () => { const wrapper = mount(); expect(wrapper.text()).toContain('No data to display'); }); - it('should render \'No data to display\' with settings but without series', () => { + it("should render 'No data to display' with settings but without series", () => { const wrapper = mount( @@ -38,7 +38,7 @@ describe('Chart', () => { expect(wrapper.text()).toContain('No data to display'); }); - it('should render \'No data to display\' with an empty dataset', () => { + it("should render 'No data to display' with an empty dataset", () => { const wrapper = mount( diff --git a/src/components/chart.tsx b/src/components/chart.tsx index 195bdb80a9..b2e0902400 100644 --- a/src/components/chart.tsx +++ b/src/components/chart.tsx @@ -66,11 +66,10 @@ const getMiddlware = (id: string): StoreEnhancer => { if (typeof window !== 'undefined' && (window as any).__REDUX_DEVTOOLS_EXTENSION_COMPOSE__) { // eslint-disable-next-line @typescript-eslint/no-unsafe-call - return (window as any) - .__REDUX_DEVTOOLS_EXTENSION_COMPOSE__({ - trace: true, - name: `@elastic/charts (id: ${id})`, - })(applyMiddleware(...middlware)); + return (window as any).__REDUX_DEVTOOLS_EXTENSION_COMPOSE__({ + trace: true, + name: `@elastic/charts (id: ${id})`, + })(applyMiddleware(...middlware)); } return applyMiddleware(...middlware); diff --git a/src/components/chart_container.tsx b/src/components/chart_container.tsx index 6a87992484..bcd973a77f 100644 --- a/src/components/chart_container.tsx +++ b/src/components/chart_container.tsx @@ -145,9 +145,9 @@ class ChartContainerComponent extends React.Component { render() { const { initialized, isChartEmpty } = this.props; if ( - initialized === InitStatus.ParentSizeInvalid - || initialized === InitStatus.SpecNotInitialized - || initialized === InitStatus.ChartNotInitialized + initialized === InitStatus.ParentSizeInvalid || + initialized === InitStatus.SpecNotInitialized || + initialized === InitStatus.ChartNotInitialized ) { return null; } diff --git a/src/components/chart_resizer.tsx b/src/components/chart_resizer.tsx index e9330e2e16..e612fa1fa1 100644 --- a/src/components/chart_resizer.tsx +++ b/src/components/chart_resizer.tsx @@ -53,7 +53,7 @@ class Resizer extends React.Component { this.containerRef = React.createRef(); this.ro = new ResizeObserver(this.handleResize); this.animationFrameID = null; - this.onResizeDebounced = () => { }; + this.onResizeDebounced = () => {}; } componentDidMount() { @@ -107,8 +107,8 @@ const mapDispatchToProps = (dispatch: Dispatch): ResizerDispatchProps => const mapStateToProps = (state: GlobalChartState): ResizerStateProps => { const settings = getSettingsSpecSelector(state); - const resizeDebounce = settings.resizeDebounce === undefined || settings.resizeDebounce === null - ? 200 : settings.resizeDebounce; + const resizeDebounce = + settings.resizeDebounce === undefined || settings.resizeDebounce === null ? 200 : settings.resizeDebounce; return { resizeDebounce: !isDefined(resizeDebounce) || Number.isNaN(resizeDebounce) ? DEFAULT_RESIZE_DEBOUNCE : resizeDebounce, diff --git a/src/components/legend/legend.test.tsx b/src/components/legend/legend.test.tsx index 5ab1f5e65c..243706dde8 100644 --- a/src/components/legend/legend.test.tsx +++ b/src/components/legend/legend.test.tsx @@ -156,7 +156,7 @@ describe('Legend', () => { class LegendColorPickerMock extends Component< { onLegendItemClick: () => void; customColor: string }, { colors: string[] } - > { + > { state = { colors: ['red'], }; diff --git a/src/components/legend/legend_item.tsx b/src/components/legend/legend_item.tsx index 4480f35af1..a5ba3f4d3f 100644 --- a/src/components/legend/legend_item.tsx +++ b/src/components/legend/legend_item.tsx @@ -231,12 +231,11 @@ export class LegendListItem extends Component /> {showExtra && extra != null && renderExtra(extra, isSeriesHidden)} - {Action - && ( -
- -
- )} + {Action && ( +
+ +
+ )} {this.renderColorPicker()} diff --git a/src/components/legend/style_utils.ts b/src/components/legend/style_utils.ts index d8770d506f..c534329f5b 100644 --- a/src/components/legend/style_utils.ts +++ b/src/components/legend/style_utils.ts @@ -23,17 +23,19 @@ import { Margins } from '../../utils/dimensions'; import { LegendStyle as ThemeLegendStyle } from '../../utils/themes/theme'; /** @internal */ -export type LegendStyle = { - width?: string; - maxWidth?: string; - marginLeft?: number; - marginRight?: number; -} | { - height?: string; - maxHeight?: string; - marginTop?: number; - marginBottom?: number; -}; +export type LegendStyle = + | { + width?: string; + maxWidth?: string; + marginLeft?: number; + marginRight?: number; + } + | { + height?: string; + maxHeight?: string; + marginTop?: number; + marginBottom?: number; + }; /** @internal */ export interface LegendListStyle { diff --git a/src/components/portal/tooltip_portal.tsx b/src/components/portal/tooltip_portal.tsx index 6a7a98331f..91d1be3036 100644 --- a/src/components/portal/tooltip_portal.tsx +++ b/src/components/portal/tooltip_portal.tsx @@ -59,9 +59,10 @@ const TooltipPortalComponent = ({ anchor, scope, settings, children, visible, ch /** * Anchor element used to position tooltip */ - const anchorNode = useRef(isHTMLElement(anchor) - ? anchor - : getOrCreateNode(`echAnchor${scope}__${chartId}`, undefined, anchor?.ref ?? undefined), + const anchorNode = useRef( + isHTMLElement(anchor) + ? anchor + : getOrCreateNode(`echAnchor${scope}__${chartId}`, undefined, anchor?.ref ?? undefined), ); /** diff --git a/src/components/tooltip/tooltip.tsx b/src/components/tooltip/tooltip.tsx index de537dacdc..29b3922b4e 100644 --- a/src/components/tooltip/tooltip.tsx +++ b/src/components/tooltip/tooltip.tsx @@ -40,7 +40,6 @@ import { TooltipPortal, TooltipPortalSettings, AnchorPosition, Placement } from import { getTooltipSettings } from './get_tooltip_settings'; import { TooltipInfo, TooltipAnchorPosition } from './types'; - interface TooltipDispatchProps { onPointerMove: typeof onPointerMoveAction; } @@ -107,7 +106,7 @@ const TooltipComponent = ({ const classes = classNames('echTooltip__item', { echTooltip__rowHighlighted: isHighlighted, }); - const adjustedBGColor = (isColorValid(color) && chroma(color).alpha() === 0) ? 'transparent' : backgroundColor; + const adjustedBGColor = isColorValid(color) && chroma(color).alpha() === 0 ? 'transparent' : backgroundColor; return (
-
+
{label} {value} - {markValue && ( - -  ( - {markValue} - ) - - )} + {markValue &&  ({markValue})}
); @@ -188,8 +178,8 @@ const TooltipComponent = ({ ...rest, placement: placement ?? (rotation === 0 || rotation === 180 ? Placement.Right : Placement.Top), fallbackPlacements: - fallbackPlacements - ?? (rotation === 0 || rotation === 180 + fallbackPlacements ?? + (rotation === 0 || rotation === 180 ? [Placement.Right, Placement.Left, Placement.Top, Placement.Bottom] : [Placement.Top, Placement.Bottom, Placement.Right, Placement.Left]), boundary: boundary === 'chart' && chartRef.current ? chartRef.current : undefined, diff --git a/src/mocks/hierarchical/dimension_codes.ts b/src/mocks/hierarchical/dimension_codes.ts index b1d82b551e..8864c0079d 100644 --- a/src/mocks/hierarchical/dimension_codes.ts +++ b/src/mocks/hierarchical/dimension_codes.ts @@ -46,7 +46,7 @@ export const countryDimension = [ { continentCountry: 'afbfa', country: 'bfa', name: 'Burkina Faso' }, { continentCountry: 'afbwa', country: 'bwa', name: 'Botswana' }, { continentCountry: 'afcaf', country: 'caf', name: 'Central African Republic' }, - { continentCountry: 'afciv', country: 'civ', name: 'Cote d\'Ivoire' }, + { continentCountry: 'afciv', country: 'civ', name: "Cote d'Ivoire" }, { continentCountry: 'afcmr', country: 'cmr', name: 'Cameroon' }, { continentCountry: 'afcod', country: 'cod', name: 'Democratic Republic of the Congo' }, { continentCountry: 'afcog', country: 'cog', name: 'Republic of the Congo' }, diff --git a/src/mocks/series/series.ts b/src/mocks/series/series.ts index 333487eeb9..3351b38ea3 100644 --- a/src/mocks/series/series.ts +++ b/src/mocks/series/series.ts @@ -102,7 +102,9 @@ export class MockFormattedDataSeries { }; static default(partial?: Partial) { - return mergePartial(MockFormattedDataSeries.base, partial, { mergeOptionalPartialValues: true }); + return mergePartial(MockFormattedDataSeries.base, partial, { + mergeOptionalPartialValues: true, + }); } } @@ -119,7 +121,9 @@ export class MockDataSeriesDatum { }; static default(partial?: Partial): DataSeriesDatum { - const merged = mergePartial(MockDataSeriesDatum.base, partial, { mergeOptionalPartialValues: true }); + const merged = mergePartial(MockDataSeriesDatum.base, partial, { + mergeOptionalPartialValues: true, + }); if (merged.initialY1 === null) { merged.initialY1 = merged.y1; } diff --git a/src/mocks/series/utils.ts b/src/mocks/series/utils.ts index 06159dce6c..8484bca685 100644 --- a/src/mocks/series/utils.ts +++ b/src/mocks/series/utils.ts @@ -24,37 +24,24 @@ import { DataSeriesDatum } from '../../chart_types/xy_chart/utils/series'; * Helper function to return array of rendered y1 values * @internal */ -export const getFilledNullData = ( - data: DataSeriesDatum[] -): (number | undefined)[] => - data - .filter(({ filled }) => filled?.y1 !== undefined) - .map(({ filled }) => filled?.y1); +export const getFilledNullData = (data: DataSeriesDatum[]): (number | undefined)[] => + data.filter(({ filled }) => filled?.y1 !== undefined).map(({ filled }) => filled?.y1); /** * Helper function to return array of rendered y1 values * @internal */ -export const getFilledNonNullData = ( - data: DataSeriesDatum[] -): (number | undefined)[] => - data - .filter( - ({ y1, filled }) => - y1 !== null && (filled?.y1 === undefined) - ) - .map(({ filled }) => filled?.y1); +export const getFilledNonNullData = (data: DataSeriesDatum[]): (number | undefined)[] => + data.filter(({ y1, filled }) => y1 !== null && filled?.y1 === undefined).map(({ filled }) => filled?.y1); /** * Helper function to return array of rendered x values * @internal */ -export const getXValueData = (data: DataSeriesDatum[]): (number | string)[] => - data.map(({ x }) => x); +export const getXValueData = (data: DataSeriesDatum[]): (number | string)[] => data.map(({ x }) => x); /** * Returns value of `y1` or `filled.y1` or null * @internal */ -export const getYResolvedData = (data: DataSeriesDatum[]): (number | null)[] => - data.map(getYValue); +export const getYResolvedData = (data: DataSeriesDatum[]): (number | null)[] => data.map(getYValue); diff --git a/src/renderers/canvas/index.ts b/src/renderers/canvas/index.ts index 66804af8a8..4f1c462027 100644 --- a/src/renderers/canvas/index.ts +++ b/src/renderers/canvas/index.ts @@ -38,11 +38,7 @@ export function withContext(ctx: CanvasRenderingContext2D, fun: (ctx: CanvasRend } /** @internal */ -export function clearCanvas( - ctx: CanvasRenderingContext2D, - width: Coordinate, - height: Coordinate, -) { +export function clearCanvas(ctx: CanvasRenderingContext2D, width: Coordinate, height: Coordinate) { withContext(ctx, (ctx) => { // two steps, as the backgroundColor may have a non-one opacity // todo we should avoid `fillRect` by setting the element background via CSS diff --git a/src/scales/index.ts b/src/scales/index.ts index dfe58afe52..9f23b5645d 100644 --- a/src/scales/index.ts +++ b/src/scales/index.ts @@ -17,7 +17,6 @@ * under the License. */ - import { PrimitiveValue } from '../chart_types/partition_chart/layout/utils/group_by_rollup'; import { ScaleType } from './constants'; diff --git a/src/scales/scale_time.test.ts b/src/scales/scale_time.test.ts index 97fb6446be..ba4f8d5402 100644 --- a/src/scales/scale_time.test.ts +++ b/src/scales/scale_time.test.ts @@ -216,7 +216,7 @@ describe('[Scale Time] - timezones', () => { }); test('shall invert all timezones', () => { for (let i = -11; i <= 12; i++) { - const timezone = i === 0 ? 'utc' : (i > 0 ? `utc+${i}` : `utc${i}`); + const timezone = i === 0 ? 'utc' : i > 0 ? `utc+${i}` : `utc${i}`; const startTime = DateTime.fromISO('2019-01-01T00:00:00.000', { zone: timezone, }).toMillis(); diff --git a/src/specs/settings.test.tsx b/src/specs/settings.test.tsx index 37cefd7ed7..d003a021d9 100644 --- a/src/specs/settings.test.tsx +++ b/src/specs/settings.test.tsx @@ -33,15 +33,16 @@ import { TooltipType } from './constants'; import { Settings, SettingsSpec } from './settings'; import { SpecsParser } from './specs_parser'; -const getProxy = (chartStore: Store) => function SettingsProxy({ settings }: { settings?: Partial }) { - return ( - - - - - - ); -}; +const getProxy = (chartStore: Store) => + function SettingsProxy({ settings }: { settings?: Partial }) { + return ( + + + + + + ); + }; describe('Settings spec component', () => { let chartStore: Store; let SettingsProxy: ({ settings }: { settings?: Partial }) => JSX.Element; diff --git a/src/specs/settings.tsx b/src/specs/settings.tsx index e529896d86..9f100f238b 100644 --- a/src/specs/settings.tsx +++ b/src/specs/settings.tsx @@ -187,7 +187,7 @@ export interface ExternalPointerEventsSettings { * @defaultValue `false` */ visible?: boolean; - } + }; } /** @@ -344,8 +344,10 @@ export type DefaultSettingsProps = | 'minBrushDelta' | 'externalPointerEvents'; -export type SettingsSpecProps = Partial> & { - externalPointerEvents?: RecursivePartial +export type SettingsSpecProps = Partial< + Omit +> & { + externalPointerEvents?: RecursivePartial; }; export const Settings: React.FunctionComponent = getConnect()( @@ -401,12 +403,15 @@ export function getTooltipType(settings: SettingsSpec, externalTooltip = false): return defaultType; } - /** * Always return a Vertical Cursor for external pointer events or None if hidden * @internal * @param settings - the SettingsSpec */ -export function getExternalTooltipType({ externalPointerEvents: { tooltip: { visible } } }: SettingsSpec): TooltipType { +export function getExternalTooltipType({ + externalPointerEvents: { + tooltip: { visible }, + }, +}: SettingsSpec): TooltipType { return visible ? TooltipType.VerticalCursor : TooltipType.None; } diff --git a/src/state/actions/specs.ts b/src/state/actions/specs.ts index 5ee1786f7e..7d668c6b9a 100644 --- a/src/state/actions/specs.ts +++ b/src/state/actions/specs.ts @@ -70,8 +70,4 @@ export function specUnmounted(): SpecUnmountedAction { } /** @internal */ -export type SpecActions = - | SpecParsedAction - | SpecUnmountedAction - | UpsertSpecAction - | RemoveSpecAction; +export type SpecActions = SpecParsedAction | SpecUnmountedAction | UpsertSpecAction | RemoveSpecAction; diff --git a/src/state/chart_state.ts b/src/state/chart_state.ts index b09f5068af..7d9bbcbdc0 100644 --- a/src/state/chart_state.ts +++ b/src/state/chart_state.ts @@ -103,7 +103,7 @@ export interface InternalChartState { * Describe if the tooltip is visible and comes from an external source * @param globalState */ - isTooltipVisible(globalState: GlobalChartState): { visible: boolean, isExternal: boolean }; + isTooltipVisible(globalState: GlobalChartState): { visible: boolean; isExternal: boolean }; /** * Get the tooltip information to display * @param globalState the GlobalChartState diff --git a/src/state/selectors/get_chart_container_dimensions.ts b/src/state/selectors/get_chart_container_dimensions.ts index d4347dce0f..828873733b 100644 --- a/src/state/selectors/get_chart_container_dimensions.ts +++ b/src/state/selectors/get_chart_container_dimensions.ts @@ -39,7 +39,7 @@ export const getChartContainerDimensionsSelector = createCachedSelector( return { left: 0, top: 0, - width: parentDimensions.width - legendSize.width - (legendSize.margin * 2), + width: parentDimensions.width - legendSize.width - legendSize.margin * 2, height: parentDimensions.height, }; } @@ -47,7 +47,7 @@ export const getChartContainerDimensionsSelector = createCachedSelector( left: 0, top: 0, width: parentDimensions.width, - height: parentDimensions.height - legendSize.height - (legendSize.margin * 2), + height: parentDimensions.height - legendSize.height - legendSize.margin * 2, }; }, )(getChartIdSelector); diff --git a/src/state/selectors/get_internal_is_intialized.ts b/src/state/selectors/get_internal_is_intialized.ts index 45055b5d9f..45890ff9da 100644 --- a/src/state/selectors/get_internal_is_intialized.ts +++ b/src/state/selectors/get_internal_is_intialized.ts @@ -21,7 +21,6 @@ import { $Values } from 'utility-types'; import { GlobalChartState } from '../chart_state'; - export const InitStatus = Object.freeze({ ParentSizeInvalid: 'ParentSizeInvalid' as const, SpecNotInitialized: 'SpecNotInitialized' as const, diff --git a/src/state/selectors/get_internal_is_tooltip_visible.ts b/src/state/selectors/get_internal_is_tooltip_visible.ts index 659ac4aef8..ebe096478f 100644 --- a/src/state/selectors/get_internal_is_tooltip_visible.ts +++ b/src/state/selectors/get_internal_is_tooltip_visible.ts @@ -20,7 +20,9 @@ import { GlobalChartState } from '../chart_state'; /** @internal */ -export const getInternalIsTooltipVisibleSelector = (state: GlobalChartState): { visible: boolean, isExternal: boolean } => { +export const getInternalIsTooltipVisibleSelector = ( + state: GlobalChartState, +): { visible: boolean; isExternal: boolean } => { if (state.internalChartState) { return state.internalChartState.isTooltipVisible(state); } diff --git a/src/state/selectors/get_legend_size.ts b/src/state/selectors/get_legend_size.ts index 4ddd3fde1a..9cab78d71f 100644 --- a/src/state/selectors/get_legend_size.ts +++ b/src/state/selectors/get_legend_size.ts @@ -72,7 +72,8 @@ export const getLegendSizeSelector = createCachedSelector( if (!showLegend) { return { width: 0, height: 0, margin: 0 }; } - const legendItemWidth = MARKER_WIDTH + MARKER_LEFT_MARGIN + bbox.width + (showLegendDisplayValue ? VALUE_LEFT_MARGIN : 0); + const legendItemWidth = + MARKER_WIDTH + MARKER_LEFT_MARGIN + bbox.width + (showLegendDisplayValue ? VALUE_LEFT_MARGIN : 0); if (isVerticalAxis(legendPosition)) { const legendItemHeight = bbox.height + VERTICAL_PADDING * 2; return { diff --git a/src/state/selectors/is_external_tooltip_visible.ts b/src/state/selectors/is_external_tooltip_visible.ts index be96e16054..42d8f9e0a2 100644 --- a/src/state/selectors/is_external_tooltip_visible.ts +++ b/src/state/selectors/is_external_tooltip_visible.ts @@ -31,7 +31,13 @@ const getExternalEventPointer = ({ externalEvents: { pointer } }: GlobalChartSta /** @internal */ export const isExternalTooltipVisibleSelector = createCachedSelector( - [getSettingsSpecSelector, hasExternalEventSelector, getExternalEventPointer, getComputedScalesSelector, computeChartDimensionsSelector], + [ + getSettingsSpecSelector, + hasExternalEventSelector, + getExternalEventPointer, + getComputedScalesSelector, + computeChartDimensionsSelector, + ], ({ externalPointerEvents }, hasExternalEvent, pointer, { xScale }, { chartDimensions }): boolean => { if (!pointer || pointer.type !== PointerEventType.Over || externalPointerEvents.tooltip?.visible === false) { return false; @@ -42,5 +48,5 @@ export const isExternalTooltipVisibleSelector = createCachedSelector( return false; } return hasExternalEvent && externalPointerEvents.tooltip?.visible === true; - } + }, )(getChartIdSelector); diff --git a/src/utils/accessor.ts b/src/utils/accessor.ts index acc970a65d..1230d24abd 100644 --- a/src/utils/accessor.ts +++ b/src/utils/accessor.ts @@ -65,7 +65,8 @@ export type AccessorFormat = string | ((value: string) => string); * @internal */ export function getAccessorFn(accessor: Accessor): AccessorFn { - return (datum: Datum) => typeof datum === 'object' && datum !== null ? datum[accessor as keyof typeof datum] : undefined; + return (datum: Datum) => + typeof datum === 'object' && datum !== null ? datum[accessor as keyof typeof datum] : undefined; } /** diff --git a/src/utils/commons.ts b/src/utils/commons.ts index f0c9ee74f6..e82f32d59a 100644 --- a/src/utils/commons.ts +++ b/src/utils/commons.ts @@ -340,9 +340,10 @@ export function mergePartial( ); } } else if (!(key in baseClone)) { - baseClone[key] = (partial as any)[key] !== undefined - ? (partial as any)[key] - : (additionalPartials.find((v: any) => v[key] !== undefined) || ({} as any))[key]; + baseClone[key] = + (partial as any)[key] !== undefined + ? (partial as any)[key] + : (additionalPartials.find((v: any) => v[key] !== undefined) || ({} as any))[key]; } }); } @@ -466,7 +467,7 @@ export function isUniqueArray(arr: B[], extractor?: (value: B) => T) { values.add(value); return true; }); - }()); + })(); } /** @@ -518,11 +519,7 @@ export const round = (value: number, fractionDigits = 0): number => { * * i.e. `'90%'` with relative value of `100` returns `90` */ -export const getPercentageValue = ( - ratio: string | number, - relativeValue: number, - defaultValue: T, -): number | T => { +export const getPercentageValue = (ratio: string | number, relativeValue: number, defaultValue: T): number | T => { if (typeof ratio === 'number') { return ratio; } diff --git a/src/utils/data/formatters.ts b/src/utils/data/formatters.ts index 32bbcb42cb..98cf174de0 100644 --- a/src/utils/data/formatters.ts +++ b/src/utils/data/formatters.ts @@ -23,7 +23,8 @@ import { TickFormatter, TickFormatterOptions } from '../../chart_types/xy_chart/ import { getMomentWithTz } from './date_time'; export function timeFormatter(format: string): TickFormatter { - return (value: number, options?: TickFormatterOptions): string => getMomentWithTz(value, options && options.timeZone).format(format); + return (value: number, options?: TickFormatterOptions): string => + getMomentWithTz(value, options && options.timeZone).format(format); } export function niceTimeFormatter(domain: [number, number]): TickFormatter { diff --git a/src/utils/data_generators/data_generator.ts b/src/utils/data_generators/data_generator.ts index 1ddbdceba5..0669f5f2d9 100644 --- a/src/utils/data_generators/data_generator.ts +++ b/src/utils/data_generators/data_generator.ts @@ -66,7 +66,9 @@ export class DataGenerator { } generateGroupedSeries(totalPoints = 50, totalGroups = 2, groupPrefix = '') { - const groups = new Array(totalGroups).fill(0).map((group, i) => this.generateSimpleSeries(totalPoints, i, groupPrefix)); + const groups = new Array(totalGroups) + .fill(0) + .map((group, i) => this.generateSimpleSeries(totalPoints, i, groupPrefix)); return groups.reduce((acc, curr) => [...acc, ...curr]); } @@ -82,7 +84,9 @@ export class DataGenerator { } generateRandomGroupedSeries(totalPoints = 50, totalGroups = 2, groupPrefix = '') { - const groups = new Array(totalGroups).fill(0).map((group, i) => this.generateRandomSeries(totalPoints, i, groupPrefix)); + const groups = new Array(totalGroups) + .fill(0) + .map((group, i) => this.generateRandomSeries(totalPoints, i, groupPrefix)); return groups.reduce((acc, curr) => [...acc, ...curr]); } } diff --git a/src/utils/data_samples/babynames.ts b/src/utils/data_samples/babynames.ts index 0b0a76a454..a79e53443a 100644 --- a/src/utils/data_samples/babynames.ts +++ b/src/utils/data_samples/babynames.ts @@ -24,100 +24,100 @@ export const BABYNAME_DATA = [ [1880, 'F', 'Dorothy', 112, 0.00114749395516577], [1880, 'F', 'Linda', 27, 0.000276628007048891], [1880, 'F', 'Deborah', 12, 0.000122945780910618], - [1880, 'F', 'Jessica', 7, 7.17183721978607e-05], + [1880, 'F', 'Jessica', 7, 7.17183721978607e-5], [1881, 'F', 'Helen', 612, 0.00619088564058469], [1881, 'F', 'Amanda', 263, 0.0026604622932578], [1881, 'F', 'Betty', 112, 0.00113297253553184], [1881, 'F', 'Dorothy', 109, 0.00110262505690152], [1881, 'F', 'Linda', 38, 0.000384401395984017], [1881, 'F', 'Deborah', 14, 0.00014162156694148], - [1881, 'F', 'Jessica', 7, 7.081078347074e-05], + [1881, 'F', 'Jessica', 7, 7.081078347074e-5], [1882, 'F', 'Helen', 838, 0.00724311990042871], [1882, 'F', 'Amanda', 288, 0.00248928225694925], [1882, 'F', 'Betty', 123, 0.00106313096390541], [1882, 'F', 'Dorothy', 115, 0.000993984234545706], [1882, 'F', 'Linda', 36, 0.000311160282118656], [1882, 'F', 'Deborah', 15, 0.00012965011754944], - [1882, 'F', 'Jessica', 8, 6.91467293597013e-05], + [1882, 'F', 'Jessica', 8, 6.91467293597013e-5], [1883, 'F', 'Helen', 862, 0.0071798032633955], [1883, 'F', 'Amanda', 287, 0.00239049134175697], [1883, 'F', 'Dorothy', 141, 0.00117442257556701], [1883, 'F', 'Betty', 120, 0.000999508574950649], [1883, 'F', 'Linda', 49, 0.000408132668104848], [1883, 'F', 'Deborah', 16, 0.00013326780999342], - [1883, 'F', 'Jessica', 6, 4.99754287475325e-05], + [1883, 'F', 'Jessica', 6, 4.99754287475325e-5], [1884, 'F', 'Helen', 986, 0.00716642681668193], [1884, 'F', 'Amanda', 337, 0.00244937711685782], [1884, 'F', 'Dorothy', 163, 0.00118471356097277], [1884, 'F', 'Betty', 144, 0.00104661811521521], [1884, 'F', 'Linda', 33, 0.000239849984736819], [1884, 'F', 'Jessica', 14, 0.000101754538979257], - [1884, 'F', 'Deborah', 13, 9.44863576235954e-05], - [1884, 'F', 'Patricia', 6, 4.36090881339671e-05], + [1884, 'F', 'Deborah', 13, 9.44863576235954e-5], + [1884, 'F', 'Patricia', 6, 4.36090881339671e-5], [1885, 'F', 'Helen', 1134, 0.00798878470436565], [1885, 'F', 'Amanda', 339, 0.0023881816708818], [1885, 'F', 'Dorothy', 196, 0.00138077760322369], [1885, 'F', 'Betty', 155, 0.0010919414719371], [1885, 'F', 'Linda', 60, 0.000422687021395008], - [1885, 'F', 'Deborah', 10, 7.0447836899168e-05], - [1885, 'F', 'Jessica', 6, 4.22687021395008e-05], - [1885, 'F', 'Patricia', 5, 3.5223918449584e-05], + [1885, 'F', 'Deborah', 10, 7.0447836899168e-5], + [1885, 'F', 'Jessica', 6, 4.22687021395008e-5], + [1885, 'F', 'Patricia', 5, 3.5223918449584e-5], [1886, 'F', 'Helen', 1267, 0.00824140084300359], [1886, 'F', 'Amanda', 370, 0.0024067232138211], [1886, 'F', 'Dorothy', 230, 0.00149607118696987], [1886, 'F', 'Betty', 167, 0.00108627777488682], [1886, 'F', 'Linda', 49, 0.000318728209397929], - [1886, 'F', 'Jessica', 11, 7.15512306811677e-05], - [1886, 'F', 'Deborah', 10, 6.50465733465161e-05], - [1886, 'F', 'Patricia', 8, 5.20372586772129e-05], + [1886, 'F', 'Jessica', 11, 7.15512306811677e-5], + [1886, 'F', 'Deborah', 10, 6.50465733465161e-5], + [1886, 'F', 'Patricia', 8, 5.20372586772129e-5], [1887, 'F', 'Helen', 1405, 0.00903990426065808], [1887, 'F', 'Amanda', 338, 0.00217472429900529], [1887, 'F', 'Dorothy', 272, 0.00175007399209893], [1887, 'F', 'Betty', 178, 0.00114526900953533], [1887, 'F', 'Linda', 50, 0.000321704777959362], - [1887, 'F', 'Deborah', 15, 9.65114333878087e-05], - [1887, 'F', 'Patricia', 10, 6.43409555918724e-05], - [1887, 'F', 'Jessica', 8, 5.1472764473498e-05], + [1887, 'F', 'Deborah', 15, 9.65114333878087e-5], + [1887, 'F', 'Patricia', 10, 6.43409555918724e-5], + [1887, 'F', 'Jessica', 8, 5.1472764473498e-5], [1888, 'F', 'Helen', 1847, 0.0097494286000834], [1888, 'F', 'Amanda', 404, 0.0021325225524817], [1888, 'F', 'Dorothy', 373, 0.00196888839622691], [1888, 'F', 'Betty', 214, 0.00112960353027496], [1888, 'F', 'Linda', 77, 0.000406446130052205], [1888, 'F', 'Deborah', 26, 0.000137241550407238], - [1888, 'F', 'Jessica', 18, 9.50133810511647e-05], - [1888, 'F', 'Patricia', 12, 6.33422540341098e-05], + [1888, 'F', 'Jessica', 18, 9.50133810511647e-5], + [1888, 'F', 'Patricia', 12, 6.33422540341098e-5], [1889, 'F', 'Helen', 1909, 0.010088838858677], [1889, 'F', 'Amanda', 413, 0.00218265607576406], [1889, 'F', 'Dorothy', 377, 0.00199240034034637], [1889, 'F', 'Betty', 189, 0.000998842610942876], [1889, 'F', 'Linda', 74, 0.000391081233914142], - [1889, 'F', 'Patricia', 17, 8.9842986169465e-05], - [1889, 'F', 'Deborah', 12, 6.34185784725635e-05], - [1889, 'F', 'Jessica', 9, 4.75639338544226e-05], + [1889, 'F', 'Patricia', 17, 8.9842986169465e-5], + [1889, 'F', 'Deborah', 12, 6.34185784725635e-5], + [1889, 'F', 'Jessica', 9, 4.75639338544226e-5], [1890, 'F', 'Helen', 2312, 0.0114647849608997], [1890, 'F', 'Dorothy', 458, 0.00227113819727166], [1890, 'F', 'Amanda', 392, 0.00194385627364736], [1890, 'F', 'Betty', 216, 0.00107110447731589], [1890, 'F', 'Linda', 54, 0.000267776119328973], [1890, 'F', 'Deborah', 24, 0.000119011608590655], - [1890, 'F', 'Jessica', 18, 8.9258706442991e-05], - [1890, 'F', 'Patricia', 11, 5.45469872707167e-05], + [1890, 'F', 'Jessica', 18, 8.9258706442991e-5], + [1890, 'F', 'Patricia', 11, 5.45469872707167e-5], [1891, 'F', 'Helen', 2417, 0.0122960619025574], [1891, 'F', 'Dorothy', 566, 0.00287942533589056], [1891, 'F', 'Amanda', 371, 0.00188739717246537], [1891, 'F', 'Betty', 239, 0.00121587041568524], [1891, 'F', 'Linda', 78, 0.000396811265370077], - [1891, 'F', 'Deborah', 15, 7.63098587250149e-05], - [1891, 'F', 'Jessica', 14, 7.12225348100139e-05], - [1891, 'F', 'Patricia', 12, 6.10478869800119e-05], + [1891, 'F', 'Deborah', 15, 7.63098587250149e-5], + [1891, 'F', 'Jessica', 14, 7.12225348100139e-5], + [1891, 'F', 'Patricia', 12, 6.10478869800119e-5], [1892, 'F', 'Helen', 2936, 0.0130538203321255], [1892, 'F', 'Dorothy', 626, 0.00278327368116844], [1892, 'F', 'Amanda', 455, 0.00202298646155214], [1892, 'F', 'Betty', 255, 0.00113376164328746], [1892, 'F', 'Linda', 83, 0.000369028299579841], - [1892, 'F', 'Patricia', 21, 9.33686059177912e-05], - [1892, 'F', 'Deborah', 16, 7.11379854611742e-05], - [1892, 'F', 'Jessica', 14, 6.22457372785274e-05], + [1892, 'F', 'Patricia', 21, 9.33686059177912e-5], + [1892, 'F', 'Deborah', 16, 7.11379854611742e-5], + [1892, 'F', 'Jessica', 14, 6.22457372785274e-5], [1893, 'F', 'Helen', 3249, 0.0144251260922071], [1893, 'F', 'Dorothy', 821, 0.00364513035447894], [1893, 'F', 'Amanda', 387, 0.00171822831569226], @@ -125,175 +125,175 @@ export const BABYNAME_DATA = [ [1893, 'F', 'Linda', 82, 0.000364069048803012], [1893, 'F', 'Patricia', 28, 0.000124316260566882], [1893, 'F', 'Deborah', 24, 0.000106556794771613], - [1893, 'F', 'Jessica', 15, 6.65979967322583e-05], + [1893, 'F', 'Jessica', 15, 6.65979967322583e-5], [1894, 'F', 'Helen', 3676, 0.0155781194378994], [1894, 'F', 'Dorothy', 1052, 0.004458156052413], [1894, 'F', 'Amanda', 418, 0.00177139660637703], [1894, 'F', 'Betty', 298, 0.00126286169545539], [1894, 'F', 'Linda', 94, 0.000398352346888614], [1894, 'F', 'Patricia', 36, 0.00015256047327649], - [1894, 'F', 'Deborah', 18, 7.62802366382452e-05], - [1894, 'F', 'Jessica', 10, 4.23779092434696e-05], + [1894, 'F', 'Deborah', 18, 7.62802366382452e-5], + [1894, 'F', 'Jessica', 10, 4.23779092434696e-5], [1895, 'F', 'Helen', 4023, 0.0162803967512049], [1895, 'F', 'Dorothy', 1127, 0.00456077731509022], [1895, 'F', 'Amanda', 431, 0.00174418369370354], [1895, 'F', 'Betty', 350, 0.00141639047052491], [1895, 'F', 'Linda', 96, 0.000388495671915405], [1895, 'F', 'Patricia', 35, 0.000141639047052491], - [1895, 'F', 'Jessica', 19, 7.68897683999239e-05], - [1895, 'F', 'Deborah', 13, 5.26087889052111e-05], + [1895, 'F', 'Jessica', 19, 7.68897683999239e-5], + [1895, 'F', 'Deborah', 13, 5.26087889052111e-5], [1896, 'F', 'Helen', 4392, 0.0174290555690039], [1896, 'F', 'Dorothy', 1366, 0.00542078549800987], [1896, 'F', 'Amanda', 367, 0.00145638966161758], [1896, 'F', 'Betty', 342, 0.00135718055660276], [1896, 'F', 'Linda', 104, 0.000412709876861659], [1896, 'F', 'Patricia', 37, 0.000146829475421936], - [1896, 'F', 'Deborah', 18, 7.14305556106717e-05], - [1896, 'F', 'Jessica', 9, 3.57152778053359e-05], + [1896, 'F', 'Deborah', 18, 7.14305556106717e-5], + [1896, 'F', 'Jessica', 9, 3.57152778053359e-5], [1897, 'F', 'Helen', 4519, 0.0182015909777464], [1897, 'F', 'Dorothy', 1472, 0.00592890947538012], [1897, 'F', 'Betty', 367, 0.00147819957708186], [1897, 'F', 'Amanda', 354, 0.00142583828416071], [1897, 'F', 'Linda', 81, 0.000326251132816433], [1897, 'F', 'Patricia', 49, 0.000197361796395126], - [1897, 'F', 'Deborah', 23, 9.26392105528144e-05], - [1897, 'F', 'Jessica', 9, 3.62501258684926e-05], + [1897, 'F', 'Deborah', 23, 9.26392105528144e-5], + [1897, 'F', 'Jessica', 9, 3.62501258684926e-5], [1898, 'F', 'Helen', 5230, 0.0190774258971497], [1898, 'F', 'Dorothy', 1671, 0.00609529228950997], [1898, 'F', 'Betty', 421, 0.00153567806934991], [1898, 'F', 'Amanda', 371, 0.00135329350054351], [1898, 'F', 'Linda', 102, 0.000372064520365061], [1898, 'F', 'Patricia', 47, 0.000171441494678018], - [1898, 'F', 'Deborah', 21, 7.6601518898689e-05], - [1898, 'F', 'Jessica', 13, 4.74199878896646e-05], + [1898, 'F', 'Deborah', 21, 7.6601518898689e-5], + [1898, 'F', 'Jessica', 13, 4.74199878896646e-5], [1899, 'F', 'Helen', 5048, 0.0203967837084327], [1899, 'F', 'Dorothy', 1687, 0.0068164370277587], [1899, 'F', 'Betty', 410, 0.00165663259121581], [1899, 'F', 'Amanda', 326, 0.00131722493838135], [1899, 'F', 'Linda', 98, 0.000395975594973534], [1899, 'F', 'Patricia', 56, 0.000226271768556305], - [1899, 'F', 'Jessica', 14, 5.65679421390763e-05], - [1899, 'F', 'Deborah', 11, 4.44462402521314e-05], + [1899, 'F', 'Jessica', 14, 5.65679421390763e-5], + [1899, 'F', 'Deborah', 11, 4.44462402521314e-5], [1900, 'F', 'Helen', 6343, 0.0199606639918181], [1900, 'F', 'Dorothy', 2491, 0.00783887971048698], [1900, 'F', 'Betty', 664, 0.00208952875462198], [1900, 'F', 'Amanda', 377, 0.00118637400676579], [1900, 'F', 'Linda', 126, 0.000396506962473448], [1900, 'F', 'Patricia', 89, 0.000280072378255055], - [1900, 'F', 'Deborah', 26, 8.18188970183306e-05], - [1900, 'F', 'Jessica', 23, 7.2378255054677e-05], + [1900, 'F', 'Deborah', 26, 8.18188970183306e-5], + [1900, 'F', 'Jessica', 23, 7.2378255054677e-5], [1901, 'F', 'Helen', 5247, 0.0206386292834891], [1901, 'F', 'Dorothy', 2173, 0.00854731111740458], [1901, 'F', 'Betty', 474, 0.00186443878032663], [1901, 'F', 'Amanda', 317, 0.00124689260203279], [1901, 'F', 'Linda', 86, 0.000338273702759684], [1901, 'F', 'Patricia', 68, 0.000267472230089053], - [1901, 'F', 'Deborah', 21, 8.26017181157368e-05], - [1901, 'F', 'Jessica', 8, 3.14673211869474e-05], + [1901, 'F', 'Deborah', 21, 8.26017181157368e-5], + [1901, 'F', 'Jessica', 8, 3.14673211869474e-5], [1902, 'F', 'Helen', 5967, 0.0212853998637335], [1902, 'F', 'Dorothy', 2707, 0.00965637295644822], [1902, 'F', 'Betty', 580, 0.00206896797736977], [1902, 'F', 'Amanda', 301, 0.00107372303653155], [1902, 'F', 'Linda', 91, 0.000324613941276981], [1902, 'F', 'Patricia', 85, 0.000303210824269708], - [1902, 'F', 'Deborah', 21, 7.49109095254572e-05], - [1902, 'F', 'Jessica', 9, 3.21046755109102e-05], + [1902, 'F', 'Deborah', 21, 7.49109095254572e-5], + [1902, 'F', 'Jessica', 9, 3.21046755109102e-5], [1903, 'F', 'Helen', 6129, 0.0220310713951934], [1903, 'F', 'Dorothy', 3078, 0.0110640622865729], [1903, 'F', 'Betty', 596, 0.00214235903924543], [1903, 'F', 'Amanda', 247, 0.000887856850157082], [1903, 'F', 'Linda', 90, 0.000323510593174645], [1903, 'F', 'Patricia', 79, 0.000283970409564411], - [1903, 'F', 'Deborah', 21, 7.54858050740839e-05], - [1903, 'F', 'Jessica', 16, 5.75129943421592e-05], + [1903, 'F', 'Deborah', 21, 7.54858050740839e-5], + [1903, 'F', 'Jessica', 16, 5.75129943421592e-5], [1904, 'F', 'Helen', 6488, 0.0221858992333418], [1904, 'F', 'Dorothy', 3477, 0.0118896996970298], [1904, 'F', 'Betty', 707, 0.00241760646701181], [1904, 'F', 'Amanda', 294, 0.00100534130311382], [1904, 'F', 'Patricia', 124, 0.000424021501993585], [1904, 'F', 'Linda', 101, 0.000345372352430259], - [1904, 'F', 'Deborah', 23, 7.86491495633262e-05], - [1904, 'F', 'Jessica', 16, 5.471245187014e-05], + [1904, 'F', 'Deborah', 23, 7.86491495633262e-5], + [1904, 'F', 'Jessica', 16, 5.471245187014e-5], [1905, 'F', 'Helen', 6811, 0.0219801852389712], [1905, 'F', 'Dorothy', 3937, 0.0127053280407913], [1905, 'F', 'Betty', 807, 0.0026043179397812], [1905, 'F', 'Amanda', 311, 0.00100364669054765], [1905, 'F', 'Patricia', 121, 0.000390486332978346], [1905, 'F', 'Linda', 106, 0.000342078936328138], - [1905, 'F', 'Deborah', 18, 5.80888759802498e-05], - [1905, 'F', 'Jessica', 17, 5.48617162035692e-05], + [1905, 'F', 'Deborah', 18, 5.80888759802498e-5], + [1905, 'F', 'Jessica', 17, 5.48617162035692e-5], [1906, 'F', 'Helen', 7176, 0.0228942608018734], [1906, 'F', 'Dorothy', 4326, 0.013801640500126], [1906, 'F', 'Betty', 865, 0.00275969002140754], [1906, 'F', 'Amanda', 260, 0.000829502202966427], [1906, 'F', 'Patricia', 157, 0.000500891714868189], [1906, 'F', 'Linda', 98, 0.000312658522656576], - [1906, 'F', 'Deborah', 25, 7.97598272083103e-05], - [1906, 'F', 'Jessica', 18, 5.74270755899834e-05], + [1906, 'F', 'Deborah', 25, 7.97598272083103e-5], + [1906, 'F', 'Jessica', 18, 5.74270755899834e-5], [1907, 'F', 'Helen', 7579, 0.0224607551721379], [1907, 'F', 'Dorothy', 4967, 0.0147199592215343], [1907, 'F', 'Betty', 1018, 0.00301689520586309], [1907, 'F', 'Amanda', 285, 0.000844612115590354], [1907, 'F', 'Patricia', 177, 0.000524548577050852], [1907, 'F', 'Linda', 102, 0.000302282230842864], - [1907, 'F', 'Deborah', 21, 6.22345769382366e-05], - [1907, 'F', 'Jessica', 17, 5.03803718071439e-05], + [1907, 'F', 'Deborah', 21, 6.22345769382366e-5], + [1907, 'F', 'Jessica', 17, 5.03803718071439e-5], [1908, 'F', 'Helen', 8439, 0.0238031438540277], [1908, 'F', 'Dorothy', 5703, 0.0160859496859249], [1908, 'F', 'Betty', 1128, 0.00318165022720029], [1908, 'F', 'Amanda', 260, 0.000733359094922052], [1908, 'F', 'Patricia', 205, 0.000578225440227003], [1908, 'F', 'Linda', 93, 0.000262316907029811], - [1908, 'F', 'Deborah', 25, 7.05152975886589e-05], - [1908, 'F', 'Jessica', 17, 4.7950402360288e-05], + [1908, 'F', 'Deborah', 25, 7.05152975886589e-5], + [1908, 'F', 'Jessica', 17, 4.7950402360288e-5], [1909, 'F', 'Helen', 9250, 0.0251291775559769], [1909, 'F', 'Dorothy', 6253, 0.0169873240278404], [1909, 'F', 'Betty', 1082, 0.00293943460708833], [1909, 'F', 'Amanda', 271, 0.000736216985694027], [1909, 'F', 'Patricia', 233, 0.00063298360762623], [1909, 'F', 'Linda', 105, 0.000285250123608387], - [1909, 'F', 'Deborah', 26, 7.06333639411244e-05], - [1909, 'F', 'Jessica', 18, 4.89000211900092e-05], + [1909, 'F', 'Deborah', 26, 7.06333639411244e-5], + [1909, 'F', 'Jessica', 18, 4.89000211900092e-5], [1910, 'F', 'Helen', 10479, 0.0249781896712004], [1910, 'F', 'Dorothy', 7318, 0.0174434957547327], [1910, 'F', 'Betty', 1389, 0.00331087942106091], [1910, 'F', 'Patricia', 316, 0.000753231027397587], [1910, 'F', 'Amanda', 278, 0.000662652612710535], [1910, 'F', 'Linda', 137, 0.000326559021371739], - [1910, 'F', 'Deborah', 33, 7.8660202228229e-05], - [1910, 'F', 'Jessica', 28, 6.67419897694064e-05], + [1910, 'F', 'Deborah', 33, 7.8660202228229e-5], + [1910, 'F', 'Jessica', 28, 6.67419897694064e-5], [1911, 'F', 'Helen', 11802, 0.0267127194372267], [1911, 'F', 'Dorothy', 8869, 0.0200741491856265], [1911, 'F', 'Betty', 1456, 0.00329551936117625], [1911, 'F', 'Patricia', 325, 0.000735607000262555], [1911, 'F', 'Amanda', 280, 0.000633753723303124], [1911, 'F', 'Linda', 130, 0.000294242800105022], - [1911, 'F', 'Deborah', 36, 8.14826215675446e-05], - [1911, 'F', 'Jessica', 21, 4.75315292477343e-05], + [1911, 'F', 'Deborah', 36, 8.14826215675446e-5], + [1911, 'F', 'Jessica', 21, 4.75315292477343e-5], [1912, 'F', 'Helen', 16133, 0.0274974944947061], [1912, 'F', 'Dorothy', 12645, 0.0215524588040388], [1912, 'F', 'Betty', 2011, 0.00342759941913183], [1912, 'F', 'Patricia', 504, 0.000859030386495497], [1912, 'F', 'Amanda', 310, 0.000528371864709532], [1912, 'F', 'Linda', 189, 0.000322136394935811], - [1912, 'F', 'Jessica', 36, 6.13593133211069e-05], - [1912, 'F', 'Deborah', 32, 5.45416118409839e-05], + [1912, 'F', 'Jessica', 36, 6.13593133211069e-5], + [1912, 'F', 'Deborah', 32, 5.45416118409839e-5], [1913, 'F', 'Helen', 18889, 0.0288423952212843], [1913, 'F', 'Dorothy', 14674, 0.0224063374173925], [1913, 'F', 'Betty', 2239, 0.00341882168989653], [1913, 'F', 'Patricia', 588, 0.000897841515703065], [1913, 'F', 'Amanda', 346, 0.000528321708219831], [1913, 'F', 'Linda', 238, 0.000363412042070288], - [1913, 'F', 'Deborah', 42, 6.41315368359332e-05], - [1913, 'F', 'Jessica', 25, 3.81735338309126e-05], + [1913, 'F', 'Deborah', 42, 6.41315368359332e-5], + [1913, 'F', 'Jessica', 25, 3.81735338309126e-5], [1914, 'F', 'Helen', 23221, 0.0291498453442597], [1914, 'F', 'Dorothy', 18782, 0.0235774684662971], [1914, 'F', 'Betty', 2933, 0.00368186109102595], [1914, 'F', 'Patricia', 656, 0.000823491604402667], [1914, 'F', 'Amanda', 375, 0.000470745962882622], [1914, 'F', 'Linda', 219, 0.000274915642323451], - [1914, 'F', 'Deborah', 62, 7.78299991965936e-05], - [1914, 'F', 'Jessica', 42, 5.27235478428537e-05], + [1914, 'F', 'Deborah', 62, 7.78299991965936e-5], + [1914, 'F', 'Jessica', 42, 5.27235478428537e-5], [1915, 'F', 'Helen', 30866, 0.0301460519864594], [1915, 'F', 'Dorothy', 25154, 0.0245672841206311], [1915, 'F', 'Betty', 4182, 0.00408445504462428], @@ -301,104 +301,104 @@ export const BABYNAME_DATA = [ [1915, 'F', 'Amanda', 412, 0.000402390119173889], [1915, 'F', 'Linda', 290, 0.000283235763496184], [1915, 'F', 'Deborah', 106, 0.000103527554933088], - [1915, 'F', 'Jessica', 55, 5.37171275596211e-05], + [1915, 'F', 'Jessica', 55, 5.37171275596211e-5], [1916, 'F', 'Helen', 32661, 0.0300826741628504], [1916, 'F', 'Dorothy', 27415, 0.0252508040836026], [1916, 'F', 'Betty', 5136, 0.00473055370320565], [1916, 'F', 'Patricia', 1078, 0.000992900485213335], [1916, 'F', 'Amanda', 421, 0.000387765402852332], [1916, 'F', 'Linda', 297, 0.000273554215313878], - [1916, 'F', 'Deborah', 90, 8.28952167617813e-05], - [1916, 'F', 'Jessica', 53, 4.8816072093049e-05], + [1916, 'F', 'Deborah', 90, 8.28952167617813e-5], + [1916, 'F', 'Jessica', 53, 4.8816072093049e-5], [1917, 'F', 'Helen', 34249, 0.0304787212268021], [1917, 'F', 'Dorothy', 28853, 0.0256767363589279], [1917, 'F', 'Betty', 6639, 0.00590815002554058], [1917, 'F', 'Patricia', 1441, 0.00128236845711763], [1917, 'F', 'Amanda', 445, 0.000396012465938478], [1917, 'F', 'Linda', 291, 0.000258965455254151], - [1917, 'F', 'Deborah', 89, 7.92024931876957e-05], - [1917, 'F', 'Jessica', 55, 4.89453609586883e-05], - [1917, 'F', 'Ashley', 5, 4.44957826897167e-06], + [1917, 'F', 'Deborah', 89, 7.92024931876957e-5], + [1917, 'F', 'Jessica', 55, 4.89453609586883e-5], + [1917, 'F', 'Ashley', 5, 4.44957826897167e-6], [1918, 'F', 'Helen', 36150, 0.030065795437817], [1918, 'F', 'Dorothy', 32034, 0.026642536405395], [1918, 'F', 'Betty', 8802, 0.00732058454892574], [1918, 'F', 'Patricia', 1760, 0.0014637842315507], [1918, 'F', 'Amanda', 397, 0.000330183147685017], [1918, 'F', 'Linda', 322, 0.00026780597872689], - [1918, 'F', 'Deborah', 92, 7.65159939219687e-05], - [1918, 'F', 'Jessica', 56, 4.65749528220679e-05], + [1918, 'F', 'Deborah', 92, 7.65159939219687e-5], + [1918, 'F', 'Jessica', 56, 4.65749528220679e-5], [1919, 'F', 'Helen', 33705, 0.0286936534286809], [1919, 'F', 'Dorothy', 31734, 0.0270157068062827], [1919, 'F', 'Betty', 10107, 0.00860426510024262], [1919, 'F', 'Patricia', 2144, 0.00182522453496786], [1919, 'F', 'Amanda', 379, 0.000322649299791427], [1919, 'F', 'Linda', 282, 0.000240071510662751], - [1919, 'F', 'Deborah', 70, 5.95922189588388e-05], - [1919, 'F', 'Jessica', 40, 3.40526965479079e-05], + [1919, 'F', 'Deborah', 70, 5.95922189588388e-5], + [1919, 'F', 'Jessica', 40, 3.40526965479079e-5], [1920, 'F', 'Dorothy', 36645, 0.0294564957018998], [1920, 'F', 'Helen', 35098, 0.0282129645557451], [1920, 'F', 'Betty', 14017, 0.011267340708242], [1920, 'F', 'Patricia', 2502, 0.00201119258414936], [1920, 'F', 'Amanda', 379, 0.000304653073298404], [1920, 'F', 'Linda', 349, 0.000280538054303807], - [1920, 'F', 'Deborah', 82, 6.59143852518974e-05], - [1920, 'F', 'Jessica', 43, 3.45648605589218e-05], + [1920, 'F', 'Deborah', 82, 6.59143852518974e-5], + [1920, 'F', 'Jessica', 43, 3.45648605589218e-5], [1921, 'F', 'Dorothy', 39083, 0.0305412051909812], [1921, 'F', 'Helen', 34819, 0.0272091247740648], [1921, 'F', 'Betty', 17637, 0.013782341067813], [1921, 'F', 'Patricia', 3382, 0.00264284614681315], [1921, 'F', 'Amanda', 392, 0.000306326342268112], [1921, 'F', 'Linda', 367, 0.000286790223501013], - [1921, 'F', 'Deborah', 94, 7.34558065642922e-05], - [1921, 'F', 'Jessica', 48, 3.75093480328301e-05], + [1921, 'F', 'Deborah', 94, 7.34558065642922e-5], + [1921, 'F', 'Jessica', 48, 3.75093480328301e-5], [1922, 'F', 'Dorothy', 37711, 0.0302285073477132], [1922, 'F', 'Helen', 32507, 0.0260570679205567], [1922, 'F', 'Betty', 20893, 0.0167474796217489], [1922, 'F', 'Patricia', 3902, 0.00312777798708008], [1922, 'F', 'Linda', 365, 0.000292577899867819], [1922, 'F', 'Amanda', 341, 0.000273339900972401], - [1922, 'F', 'Deborah', 71, 5.69124133989456e-05], - [1922, 'F', 'Jessica', 40, 3.20633314923637e-05], + [1922, 'F', 'Deborah', 71, 5.69124133989456e-5], + [1922, 'F', 'Jessica', 40, 3.20633314923637e-5], [1923, 'F', 'Dorothy', 39045, 0.0311757435229189], [1923, 'F', 'Helen', 31492, 0.0251449997444938], [1923, 'F', 'Betty', 25990, 0.020751890745567], [1923, 'F', 'Patricia', 4800, 0.00383259236547601], [1923, 'F', 'Linda', 423, 0.000337747202207573], [1923, 'F', 'Amanda', 362, 0.000289041340896316], - [1923, 'F', 'Deborah', 118, 9.42178956512852e-05], - [1923, 'F', 'Jessica', 52, 4.15197506259901e-05], + [1923, 'F', 'Deborah', 118, 9.42178956512852e-5], + [1923, 'F', 'Jessica', 52, 4.15197506259901e-5], [1924, 'F', 'Dorothy', 39996, 0.0308678753677503], [1924, 'F', 'Helen', 31193, 0.0240739483034863], [1924, 'F', 'Betty', 30602, 0.0236178298330807], [1924, 'F', 'Patricia', 6958, 0.00537000392061223], [1924, 'F', 'Linda', 454, 0.000350385423966363], [1924, 'F', 'Amanda', 341, 0.000263174955005572], - [1924, 'F', 'Deborah', 125, 9.64717576999898e-05], - [1924, 'F', 'Jessica', 41, 3.16427365255967e-05], + [1924, 'F', 'Deborah', 125, 9.64717576999898e-5], + [1924, 'F', 'Jessica', 41, 3.16427365255967e-5], [1925, 'F', 'Dorothy', 38572, 0.030538871901736], [1925, 'F', 'Betty', 32817, 0.0259824266099572], [1925, 'F', 'Helen', 29168, 0.023093379021825], [1925, 'F', 'Patricia', 8095, 0.00640910940694163], [1925, 'F', 'Linda', 438, 0.000346780718992024], [1925, 'F', 'Amanda', 310, 0.000245438408419012], - [1925, 'F', 'Deborah', 82, 6.49224177108356e-05], - [1925, 'F', 'Jessica', 34, 2.69190512459562e-05], + [1925, 'F', 'Deborah', 82, 6.49224177108356e-5], + [1925, 'F', 'Jessica', 34, 2.69190512459562e-5], [1926, 'F', 'Dorothy', 36614, 0.0297646484033633], [1926, 'F', 'Betty', 32959, 0.026793386320163], [1926, 'F', 'Helen', 26884, 0.0218548316948713], [1926, 'F', 'Patricia', 8590, 0.0069830755936224], [1926, 'F', 'Linda', 479, 0.000389393854405719], [1926, 'F', 'Amanda', 310, 0.000252008548780319], - [1926, 'F', 'Deborah', 116, 9.42999730919904e-05], - [1926, 'F', 'Jessica', 35, 2.84525780881006e-05], + [1926, 'F', 'Deborah', 116, 9.42999730919904e-5], + [1926, 'F', 'Jessica', 35, 2.84525780881006e-5], [1927, 'F', 'Dorothy', 35987, 0.0291075004772119], [1927, 'F', 'Betty', 35422, 0.0286505094035013], [1927, 'F', 'Helen', 25316, 0.0204764354372717], [1927, 'F', 'Patricia', 10553, 0.00853562265640418], [1927, 'F', 'Linda', 516, 0.000417358219530423], [1927, 'F', 'Amanda', 234, 0.000189267099554494], - [1927, 'F', 'Deborah', 91, 7.360387204897e-05], - [1927, 'F', 'Jessica', 39, 3.15445165924157e-05], + [1927, 'F', 'Deborah', 91, 7.360387204897e-5], + [1927, 'F', 'Jessica', 39, 3.15445165924157e-5], [1928, 'F', 'Betty', 36078, 0.0301810713703117], [1928, 'F', 'Dorothy', 33728, 0.0282151775369442], [1928, 'F', 'Helen', 22936, 0.0191871238136667], @@ -406,7 +406,7 @@ export const BABYNAME_DATA = [ [1928, 'F', 'Linda', 554, 0.000463449014334294], [1928, 'F', 'Amanda', 247, 0.000206627990145434], [1928, 'F', 'Deborah', 130, 0.000108751573760755], - [1928, 'F', 'Jessica', 36, 3.01158204260552e-05], + [1928, 'F', 'Jessica', 36, 3.01158204260552e-5], [1929, 'F', 'Betty', 36669, 0.0316800016587745], [1929, 'F', 'Dorothy', 31477, 0.0271943988713422], [1929, 'F', 'Helen', 20983, 0.0181281593391166], @@ -414,7 +414,7 @@ export const BABYNAME_DATA = [ [1929, 'F', 'Linda', 509, 0.000439748039060684], [1929, 'F', 'Amanda', 209, 0.000180564518985625], [1929, 'F', 'Deborah', 161, 0.000139095155773615], - [1929, 'F', 'Jessica', 42, 3.62856928105083e-05], + [1929, 'F', 'Jessica', 42, 3.62856928105083e-5], [1930, 'F', 'Betty', 38239, 0.0327853532062582], [1930, 'F', 'Dorothy', 30404, 0.0260677810320111], [1930, 'F', 'Helen', 19914, 0.0170738650003772], @@ -422,7 +422,7 @@ export const BABYNAME_DATA = [ [1930, 'F', 'Linda', 493, 0.000422688332087274], [1930, 'F', 'Amanda', 196, 0.00016804647685417], [1930, 'F', 'Deborah', 165, 0.000141467697351725], - [1930, 'F', 'Jessica', 38, 3.25804393900942e-05], + [1930, 'F', 'Jessica', 38, 3.25804393900942e-5], [1931, 'F', 'Betty', 36102, 0.0327140362625423], [1931, 'F', 'Dorothy', 26521, 0.0240321576566086], [1931, 'F', 'Helen', 17657, 0.0159999927507537], @@ -430,7 +430,7 @@ export const BABYNAME_DATA = [ [1931, 'F', 'Linda', 534, 0.000483887190853626], [1931, 'F', 'Amanda', 209, 0.00018938655971612], [1931, 'F', 'Deborah', 158, 0.000143172614522234], - [1931, 'F', 'Jessica', 39, 3.53400757365008e-05], + [1931, 'F', 'Jessica', 39, 3.53400757365008e-5], [1932, 'F', 'Betty', 34411, 0.0311083227035339], [1932, 'F', 'Dorothy', 24968, 0.0225716370132177], [1932, 'F', 'Patricia', 17991, 0.0162642711272349], @@ -438,7 +438,7 @@ export const BABYNAME_DATA = [ [1932, 'F', 'Linda', 774, 0.000699713515228713], [1932, 'F', 'Amanda', 213, 0.00019255682008232], [1932, 'F', 'Deborah', 208, 0.000188036706934848], - [1932, 'F', 'Jessica', 44, 3.97769956977563e-05], + [1932, 'F', 'Jessica', 44, 3.97769956977563e-5], [1933, 'F', 'Betty', 31526, 0.0301434985810775], [1933, 'F', 'Dorothy', 22050, 0.0210830471265862], [1933, 'F', 'Patricia', 18625, 0.017808242754316], @@ -446,7 +446,7 @@ export const BABYNAME_DATA = [ [1933, 'F', 'Linda', 786, 0.000751531747913687], [1933, 'F', 'Deborah', 243, 0.000232343784660338], [1933, 'F', 'Amanda', 199, 0.000190273305133363], - [1933, 'F', 'Jessica', 43, 4.11143322649981e-05], + [1933, 'F', 'Jessica', 43, 4.11143322649981e-5], [1934, 'F', 'Betty', 31078, 0.0287181174191951], [1934, 'F', 'Dorothy', 21280, 0.0196641205573226], [1934, 'F', 'Patricia', 20847, 0.0192640000591402], @@ -454,7 +454,7 @@ export const BABYNAME_DATA = [ [1934, 'F', 'Linda', 1001, 0.000924989881479318], [1934, 'F', 'Deborah', 280, 0.000258738428385823], [1934, 'F', 'Amanda', 189, 0.000174648439160431], - [1934, 'F', 'Jessica', 46, 4.25070275205281e-05], + [1934, 'F', 'Jessica', 46, 4.25070275205281e-5], [1935, 'F', 'Betty', 28673, 0.0263859454097216], [1935, 'F', 'Patricia', 22876, 0.0210513335609385], [1935, 'F', 'Dorothy', 19400, 0.0178525909722944], @@ -462,7 +462,7 @@ export const BABYNAME_DATA = [ [1935, 'F', 'Linda', 1197, 0.00110152326772353], [1935, 'F', 'Deborah', 279, 0.00025674602480774], [1935, 'F', 'Amanda', 211, 0.000194169932739903], - [1935, 'F', 'Jessica', 47, 4.32511224586515e-05], + [1935, 'F', 'Jessica', 47, 4.32511224586515e-5], [1936, 'F', 'Betty', 25863, 0.0240043659489396], [1936, 'F', 'Patricia', 23912, 0.022193573776091], [1936, 'F', 'Dorothy', 17668, 0.0163982963146528], @@ -470,7 +470,7 @@ export const BABYNAME_DATA = [ [1936, 'F', 'Linda', 2439, 0.0022637222499116], [1936, 'F', 'Deborah', 299, 0.00027751248574152], [1936, 'F', 'Amanda', 192, 0.000178201997533016], - [1936, 'F', 'Jessica', 43, 3.99098223641651e-05], + [1936, 'F', 'Jessica', 43, 3.99098223641651e-5], [1937, 'F', 'Patricia', 26837, 0.0243591174914203], [1937, 'F', 'Betty', 25328, 0.0229894447152324], [1937, 'F', 'Dorothy', 16571, 0.0150409858013312], @@ -478,7 +478,7 @@ export const BABYNAME_DATA = [ [1937, 'F', 'Linda', 4380, 0.00397559096070428], [1937, 'F', 'Deborah', 323, 0.000293177141622713], [1937, 'F', 'Amanda', 176, 0.00015974977376346], - [1937, 'F', 'Jessica', 72, 6.53521801759607e-05], + [1937, 'F', 'Jessica', 72, 6.53521801759607e-5], [1938, 'F', 'Patricia', 27555, 0.0241429070846355], [1938, 'F', 'Betty', 25502, 0.0223441268906687], [1938, 'F', 'Dorothy', 16348, 0.0143236525138676], @@ -486,8 +486,8 @@ export const BABYNAME_DATA = [ [1938, 'F', 'Linda', 7047, 0.00617438091908643], [1938, 'F', 'Deborah', 410, 0.000359230335862841], [1938, 'F', 'Amanda', 192, 0.000168224937769916], - [1938, 'F', 'Jessica', 50, 4.38085775442489e-05], - [1938, 'F', 'Ashley', 7, 6.13320085619484e-06], + [1938, 'F', 'Jessica', 50, 4.38085775442489e-5], + [1938, 'F', 'Ashley', 7, 6.13320085619484e-6], [1939, 'F', 'Patricia', 29704, 0.0261941652197148], [1939, 'F', 'Betty', 23639, 0.0208458076901709], [1939, 'F', 'Dorothy', 15170, 0.0133775076212993], @@ -495,7 +495,7 @@ export const BABYNAME_DATA = [ [1939, 'F', 'Helen', 10417, 0.00918612372386778], [1939, 'F', 'Deborah', 443, 0.000390654968769648], [1939, 'F', 'Amanda', 185, 0.000163140336845113], - [1939, 'F', 'Jessica', 77, 6.79016537139118e-05], + [1939, 'F', 'Jessica', 77, 6.79016537139118e-5], [1940, 'F', 'Patricia', 32661, 0.027650413304301], [1940, 'F', 'Betty', 22074, 0.0186875852937491], [1940, 'F', 'Linda', 18368, 0.0155501298666116], @@ -503,7 +503,7 @@ export const BABYNAME_DATA = [ [1940, 'F', 'Helen', 10201, 0.00863604501139508], [1940, 'F', 'Deborah', 469, 0.000397049809856317], [1940, 'F', 'Amanda', 218, 0.000184556201596326], - [1940, 'F', 'Jessica', 61, 5.16418729237427e-05], + [1940, 'F', 'Jessica', 61, 5.16418729237427e-5], [1941, 'F', 'Patricia', 36901, 0.0296201340816562], [1941, 'F', 'Linda', 23715, 0.0190358385882897], [1941, 'F', 'Betty', 20900, 0.0167762608684484], @@ -511,8 +511,8 @@ export const BABYNAME_DATA = [ [1941, 'F', 'Helen', 9889, 0.00793782027407113], [1941, 'F', 'Deborah', 608, 0.000488036679809409], [1941, 'F', 'Amanda', 223, 0.000179000295390622], - [1941, 'F', 'Jessica', 81, 6.50180445140824e-05], - [1941, 'F', 'Ashley', 6, 4.81615144548759e-06], + [1941, 'F', 'Jessica', 81, 6.50180445140824e-5], + [1941, 'F', 'Ashley', 6, 4.81615144548759e-6], [1942, 'F', 'Patricia', 39454, 0.0283767212206867], [1942, 'F', 'Linda', 31611, 0.0227357564380576], [1942, 'F', 'Betty', 21654, 0.0155743276046218], @@ -520,8 +520,8 @@ export const BABYNAME_DATA = [ [1942, 'F', 'Helen', 10013, 0.00720170602683468], [1942, 'F', 'Deborah', 676, 0.000486203263171901], [1942, 'F', 'Amanda', 295, 0.000212174500940401], - [1942, 'F', 'Jessica', 127, 9.13429207438335e-05], - [1942, 'F', 'Ashley', 8, 5.7538847712651e-06], + [1942, 'F', 'Jessica', 127, 9.13429207438335e-5], + [1942, 'F', 'Ashley', 8, 5.7538847712651e-6], [1943, 'F', 'Patricia', 39620, 0.0276053892520138], [1943, 'F', 'Linda', 38437, 0.0267811293962558], [1943, 'F', 'Betty', 21595, 0.0150464003255234], @@ -529,8 +529,8 @@ export const BABYNAME_DATA = [ [1943, 'F', 'Helen', 9799, 0.00682749140031507], [1943, 'F', 'Deborah', 788, 0.000549042067909815], [1943, 'F', 'Amanda', 284, 0.000197878105693385], - [1943, 'F', 'Jessica', 121, 8.43072210876746e-05], - [1943, 'F', 'Ashley', 10, 6.96753893286567e-06], + [1943, 'F', 'Jessica', 121, 8.43072210876746e-5], + [1943, 'F', 'Ashley', 10, 6.96753893286567e-6], [1944, 'F', 'Linda', 38411, 0.0281104982403037], [1944, 'F', 'Patricia', 36872, 0.0269842048141543], [1944, 'F', 'Betty', 19757, 0.0144588558937201], @@ -538,8 +538,8 @@ export const BABYNAME_DATA = [ [1944, 'F', 'Helen', 8693, 0.00636183804647003], [1944, 'F', 'Deborah', 1293, 0.000946262118265933], [1944, 'F', 'Amanda', 238, 0.000174176631204402], - [1944, 'F', 'Jessica', 124, 9.07474885266633e-05], - [1944, 'F', 'Ashley', 12, 8.78201501870935e-06], + [1944, 'F', 'Jessica', 124, 9.07474885266633e-5], + [1944, 'F', 'Ashley', 12, 8.78201501870935e-6], [1945, 'F', 'Linda', 41464, 0.0308041820109342], [1945, 'F', 'Patricia', 35840, 0.0266260342290151], [1945, 'F', 'Betty', 18383, 0.0136569862508924], @@ -547,8 +547,8 @@ export const BABYNAME_DATA = [ [1945, 'F', 'Helen', 8300, 0.00616618538227749], [1945, 'F', 'Deborah', 1464, 0.00108762595176557], [1945, 'F', 'Amanda', 280, 0.00020801589241418], - [1945, 'F', 'Jessica', 132, 9.80646349952565e-05], - [1945, 'F', 'Ashley', 10, 7.42913901479216e-06], + [1945, 'F', 'Jessica', 132, 9.80646349952565e-5], + [1945, 'F', 'Ashley', 10, 7.42913901479216e-6], [1946, 'F', 'Linda', 52708, 0.0326804234293612], [1946, 'F', 'Patricia', 46295, 0.028704185373421], [1946, 'F', 'Betty', 19714, 0.012223227356121], @@ -557,7 +557,7 @@ export const BABYNAME_DATA = [ [1946, 'F', 'Deborah', 2470, 0.00153146857916297], [1946, 'F', 'Amanda', 274, 0.000169887607567067], [1946, 'F', 'Jessica', 240, 0.000148806663562394], - [1946, 'F', 'Ashley', 7, 4.34019435390317e-06], + [1946, 'F', 'Ashley', 7, 4.34019435390317e-6], [1947, 'F', 'Linda', 99680, 0.0548360886157353], [1947, 'F', 'Patricia', 51274, 0.0282069182151205], [1947, 'F', 'Betty', 18962, 0.0104313996020423], @@ -566,7 +566,7 @@ export const BABYNAME_DATA = [ [1947, 'F', 'Deborah', 5838, 0.00321160799898338], [1947, 'F', 'Jessica', 430, 0.000236552147921009], [1947, 'F', 'Amanda', 310, 0.000170537595012821], - [1947, 'F', 'Ashley', 11, 6.05133401658396e-06], + [1947, 'F', 'Ashley', 11, 6.05133401658396e-6], [1948, 'F', 'Linda', 96211, 0.0552115905834257], [1948, 'F', 'Patricia', 46135, 0.0264750052651604], [1948, 'F', 'Betty', 16622, 0.00953869161195395], @@ -575,7 +575,7 @@ export const BABYNAME_DATA = [ [1948, 'F', 'Helen', 8305, 0.00476590264933688], [1948, 'F', 'Jessica', 482, 0.000276600250087944], [1948, 'F', 'Amanda', 306, 0.000175600988645043], - [1948, 'F', 'Ashley', 13, 7.46017272021426e-06], + [1948, 'F', 'Ashley', 13, 7.46017272021426e-6], [1949, 'F', 'Linda', 91010, 0.0518428093664536], [1949, 'F', 'Patricia', 46337, 0.0263953440019049], [1949, 'F', 'Deborah', 19208, 0.0109416183090962], @@ -584,7 +584,7 @@ export const BABYNAME_DATA = [ [1949, 'F', 'Helen', 7709, 0.00439134399962632], [1949, 'F', 'Jessica', 406, 0.000231273273297222], [1949, 'F', 'Amanda', 333, 0.000189689655192056], - [1949, 'F', 'Ashley', 11, 6.26602464598385e-06], + [1949, 'F', 'Ashley', 11, 6.26602464598385e-6], [1950, 'F', 'Linda', 80439, 0.0457319621154536], [1950, 'F', 'Patricia', 47952, 0.0272621371145866], [1950, 'F', 'Deborah', 29073, 0.0165288645381293], @@ -593,7 +593,7 @@ export const BABYNAME_DATA = [ [1950, 'F', 'Helen', 7060, 0.0040138198204242], [1950, 'F', 'Jessica', 402, 0.000228548947281945], [1950, 'F', 'Amanda', 379, 0.000215472763730988], - [1950, 'F', 'Ashley', 15, 8.52794579410241e-06], + [1950, 'F', 'Ashley', 15, 8.52794579410241e-6], [1951, 'F', 'Linda', 73947, 0.0400434945769865], [1951, 'F', 'Patricia', 56433, 0.0305593807654547], [1951, 'F', 'Deborah', 42045, 0.0227680464317606], @@ -602,7 +602,7 @@ export const BABYNAME_DATA = [ [1951, 'F', 'Helen', 6945, 0.00376082964605963], [1951, 'F', 'Jessica', 466, 0.000252346524847198], [1951, 'F', 'Amanda', 409, 0.000221480104425974], - [1951, 'F', 'Ashley', 15, 8.12274221611151e-06], + [1951, 'F', 'Ashley', 15, 8.12274221611151e-6], [1952, 'F', 'Linda', 67092, 0.0352717589878795], [1952, 'F', 'Patricia', 53090, 0.0279105956696256], [1952, 'F', 'Deborah', 49809, 0.0261857008797962], @@ -611,7 +611,7 @@ export const BABYNAME_DATA = [ [1952, 'F', 'Helen', 6470, 0.00340142313020301], [1952, 'F', 'Jessica', 452, 0.000237626469065187], [1952, 'F', 'Amanda', 418, 0.000219751911657629], - [1952, 'F', 'Ashley', 24, 1.26173346406294e-05], + [1952, 'F', 'Ashley', 24, 1.26173346406294e-5], [1953, 'F', 'Linda', 61264, 0.0317575840515387], [1953, 'F', 'Deborah', 52196, 0.0270569805620611], [1953, 'F', 'Patricia', 51007, 0.0264406354419697], @@ -620,7 +620,7 @@ export const BABYNAME_DATA = [ [1953, 'F', 'Helen', 6120, 0.00317244081998265], [1953, 'F', 'Jessica', 495, 0.000256594478086832], [1953, 'F', 'Amanda', 428, 0.000221863508325584], - [1953, 'F', 'Ashley', 15, 7.7755902450555e-06], + [1953, 'F', 'Ashley', 15, 7.7755902450555e-6], [1954, 'F', 'Linda', 55371, 0.0278157891564086], [1954, 'F', 'Deborah', 54674, 0.0274656491003862], [1954, 'F', 'Patricia', 49133, 0.0246821110079613], @@ -629,7 +629,7 @@ export const BABYNAME_DATA = [ [1954, 'F', 'Helen', 5940, 0.00298397694802455], [1954, 'F', 'Amanda', 428, 0.000215007093224664], [1954, 'F', 'Jessica', 424, 0.000212997681138453], - [1954, 'F', 'Ashley', 21, 1.0549413452612e-05], + [1954, 'F', 'Ashley', 21, 1.0549413452612e-5], [1955, 'F', 'Deborah', 52314, 0.026099932497594], [1955, 'F', 'Linda', 51279, 0.0255835615426869], [1955, 'F', 'Patricia', 46210, 0.0230545911364801], @@ -638,7 +638,7 @@ export const BABYNAME_DATA = [ [1955, 'F', 'Helen', 5596, 0.00279189552044455], [1955, 'F', 'Amanda', 452, 0.000225506929099524], [1955, 'F', 'Jessica', 386, 0.000192578926177912], - [1955, 'F', 'Ashley', 8, 3.9912730814075e-06], + [1955, 'F', 'Ashley', 8, 3.9912730814075e-6], [1956, 'F', 'Linda', 48067, 0.0233410866641092], [1956, 'F', 'Deborah', 47829, 0.0232255150947153], [1956, 'F', 'Patricia', 43332, 0.0210417951469653], @@ -647,7 +647,7 @@ export const BABYNAME_DATA = [ [1956, 'F', 'Helen', 5279, 0.00256345510433005], [1956, 'F', 'Amanda', 643, 0.000312237475295363], [1956, 'F', 'Jessica', 406, 0.00019715150073082], - [1956, 'F', 'Ashley', 25, 1.21398707346564e-05], + [1956, 'F', 'Ashley', 25, 1.21398707346564e-5], [1957, 'F', 'Linda', 44495, 0.021213187408344], [1957, 'F', 'Deborah', 40065, 0.0191011653784763], [1957, 'F', 'Patricia', 39277, 0.0187254829045404], @@ -656,7 +656,7 @@ export const BABYNAME_DATA = [ [1957, 'F', 'Helen', 5015, 0.0023909233588683], [1957, 'F', 'Amanda', 667, 0.000317995190501527], [1957, 'F', 'Jessica', 476, 0.000226935098468856], - [1957, 'F', 'Ashley', 27, 1.28723690307964e-05], + [1957, 'F', 'Ashley', 27, 1.28723690307964e-5], [1958, 'F', 'Linda', 41898, 0.0202894802981679], [1958, 'F', 'Patricia', 37932, 0.0183689094150104], [1958, 'F', 'Deborah', 32936, 0.015949551842581], @@ -665,7 +665,7 @@ export const BABYNAME_DATA = [ [1958, 'F', 'Helen', 4763, 0.0023065252436912], [1958, 'F', 'Amanda', 796, 0.00038547010161205], [1958, 'F', 'Jessica', 529, 0.000256172969538661], - [1958, 'F', 'Ashley', 38, 1.84018390216808e-05], + [1958, 'F', 'Ashley', 38, 1.84018390216808e-5], [1959, 'F', 'Linda', 40409, 0.0194416392387311], [1959, 'F', 'Patricia', 35221, 0.0169455808267303], [1959, 'F', 'Deborah', 29552, 0.0142181029667396], @@ -674,7 +674,7 @@ export const BABYNAME_DATA = [ [1959, 'F', 'Helen', 4378, 0.00210634998607153], [1959, 'F', 'Amanda', 858, 0.000412802258576833], [1959, 'F', 'Jessica', 523, 0.000251626551556741], - [1959, 'F', 'Ashley', 37, 1.78014959992341e-05], + [1959, 'F', 'Ashley', 37, 1.78014959992341e-5], [1960, 'F', 'Linda', 37314, 0.0179400268278259], [1960, 'F', 'Patricia', 32107, 0.0154365771925017], [1960, 'F', 'Deborah', 25269, 0.012148966551759], @@ -683,7 +683,7 @@ export const BABYNAME_DATA = [ [1960, 'F', 'Helen', 4069, 0.00195631583755223], [1960, 'F', 'Amanda', 977, 0.000469727346593395], [1960, 'F', 'Jessica', 560, 0.000269239830186593], - [1960, 'F', 'Ashley', 57, 2.74047684297068e-05], + [1960, 'F', 'Ashley', 57, 2.74047684297068e-5], [1961, 'F', 'Linda', 35574, 0.0171339811436622], [1961, 'F', 'Patricia', 28867, 0.0139035990800612], [1961, 'F', 'Deborah', 24092, 0.0116037520018302], @@ -692,7 +692,7 @@ export const BABYNAME_DATA = [ [1961, 'F', 'Helen', 3855, 0.00185673518043565], [1961, 'F', 'Amanda', 1057, 0.0005090970390974], [1961, 'F', 'Jessica', 669, 0.000322219412635914], - [1961, 'F', 'Ashley', 80, 3.85314693735024e-05], + [1961, 'F', 'Ashley', 80, 3.85314693735024e-5], [1962, 'F', 'Linda', 31462, 0.015521322454956], [1962, 'F', 'Patricia', 26538, 0.0130921383036559], [1962, 'F', 'Deborah', 22893, 0.0112939302956363], @@ -701,7 +701,7 @@ export const BABYNAME_DATA = [ [1962, 'F', 'Helen', 3587, 0.00176959454726105], [1962, 'F', 'Amanda', 948, 0.000467682082744208], [1962, 'F', 'Jessica', 867, 0.000427721904788216], - [1962, 'F', 'Ashley', 95, 4.6866875380485e-05], + [1962, 'F', 'Ashley', 95, 4.6866875380485e-5], [1963, 'F', 'Linda', 27715, 0.0139419183153997], [1963, 'F', 'Patricia', 25363, 0.0127587542570263], [1963, 'F', 'Deborah', 21062, 0.0105951536553833], @@ -710,7 +710,7 @@ export const BABYNAME_DATA = [ [1963, 'F', 'Helen', 3340, 0.00168017345024121], [1963, 'F', 'Jessica', 1121, 0.000563914502311496], [1963, 'F', 'Amanda', 1035, 0.000520652551197501], - [1963, 'F', 'Ashley', 108, 5.4328961864087e-05], + [1963, 'F', 'Ashley', 108, 5.4328961864087e-5], [1964, 'F', 'Patricia', 26087, 0.013328857510441], [1964, 'F', 'Linda', 23633, 0.0120750139741731], [1964, 'F', 'Deborah', 19306, 0.00986418227839823], @@ -719,7 +719,7 @@ export const BABYNAME_DATA = [ [1964, 'F', 'Helen', 3095, 0.00158135523420918], [1964, 'F', 'Amanda', 1275, 0.000651446825078097], [1964, 'F', 'Jessica', 1172, 0.000598820140385513], - [1964, 'F', 'Ashley', 180, 9.19689635404372e-05], + [1964, 'F', 'Ashley', 180, 9.19689635404372e-5], [1965, 'F', 'Patricia', 23551, 0.0128881183708359], [1965, 'F', 'Linda', 19339, 0.0105831311270687], [1965, 'F', 'Deborah', 17083, 0.00934855106488003], @@ -1016,7 +1016,7 @@ export const BABYNAME_DATA = [ [1997, 'F', 'Helen', 812, 0.000425451426493573], [1997, 'F', 'Deborah', 638, 0.000334283263673522], [1997, 'F', 'Dorothy', 315, 0.000165045812001817], - [1997, 'F', 'Betty', 189, 9.90274872010902e-05], + [1997, 'F', 'Betty', 189, 9.90274872010902e-5], [1998, 'F', 'Ashley', 19871, 0.0102549361330773], [1998, 'F', 'Jessica', 18233, 0.00940960447458096], [1998, 'F', 'Amanda', 10908, 0.00562935148405249], @@ -1034,7 +1034,7 @@ export const BABYNAME_DATA = [ [1999, 'F', 'Helen', 841, 0.000432205863610014], [1999, 'F', 'Deborah', 524, 0.000269293546410995], [1999, 'F', 'Dorothy', 335, 0.000172162858869625], - [1999, 'F', 'Betty', 182, 9.35332546694679e-05], + [1999, 'F', 'Betty', 182, 9.35332546694679e-5], [2000, 'F', 'Ashley', 17997, 0.00902349055709788], [2000, 'F', 'Jessica', 15705, 0.00787430789571719], [2000, 'F', 'Amanda', 8550, 0.00428687249337039], @@ -1043,7 +1043,7 @@ export const BABYNAME_DATA = [ [2000, 'F', 'Linda', 849, 0.000425678917762744], [2000, 'F', 'Deborah', 545, 0.00027325678466513], [2000, 'F', 'Dorothy', 312, 0.000156433241863341], - [2000, 'F', 'Betty', 174, 8.72416156545553e-05], + [2000, 'F', 'Betty', 174, 8.72416156545553e-5], [2001, 'F', 'Ashley', 16524, 0.00834726311913036], [2001, 'F', 'Jessica', 13917, 0.00703031111286233], [2001, 'F', 'Amanda', 6963, 0.00351742877623485], @@ -1052,7 +1052,7 @@ export const BABYNAME_DATA = [ [2001, 'F', 'Linda', 837, 0.000422818883485361], [2001, 'F', 'Deborah', 489, 0.000247023218667075], [2001, 'F', 'Dorothy', 317, 0.00016013570617068], - [2001, 'F', 'Betty', 153, 7.72894733252811e-05], + [2001, 'F', 'Betty', 153, 7.72894733252811e-5], [2002, 'F', 'Ashley', 15339, 0.00777226488632702], [2002, 'F', 'Jessica', 11913, 0.00603631211883524], [2002, 'F', 'Amanda', 6132, 0.00310708183603607], @@ -1061,7 +1061,7 @@ export const BABYNAME_DATA = [ [2002, 'F', 'Linda', 769, 0.000389651978459187], [2002, 'F', 'Deborah', 474, 0.000240175601807093], [2002, 'F', 'Dorothy', 263, 0.000133261990032206], - [2002, 'F', 'Betty', 127, 6.43508468976811e-05], + [2002, 'F', 'Betty', 127, 6.43508468976811e-5], [2003, 'F', 'Ashley', 14512, 0.00723815072032368], [2003, 'F', 'Jessica', 10445, 0.00520965299571257], [2003, 'F', 'Amanda', 5339, 0.00266293320671225], @@ -1070,7 +1070,7 @@ export const BABYNAME_DATA = [ [2003, 'F', 'Linda', 739, 0.000368591054459702], [2003, 'F', 'Deborah', 421, 0.000209982183934418], [2003, 'F', 'Dorothy', 291, 0.000145142079631628], - [2003, 'F', 'Betty', 142, 7.08253446999699e-05], + [2003, 'F', 'Betty', 142, 7.08253446999699e-5], [2004, 'F', 'Ashley', 14370, 0.00712775344818093], [2004, 'F', 'Jessica', 9469, 0.00469677782886745], [2004, 'F', 'Amanda', 4677, 0.00231986798031609], @@ -1079,7 +1079,7 @@ export const BABYNAME_DATA = [ [2004, 'F', 'Linda', 727, 0.000360603810496001], [2004, 'F', 'Deborah', 427, 0.000211798936838779], [2004, 'F', 'Dorothy', 288, 0.000142852678710933], - [2004, 'F', 'Betty', 136, 6.7458209391274e-05], + [2004, 'F', 'Betty', 136, 6.7458209391274e-5], [2005, 'F', 'Ashley', 13270, 0.00654498034039816], [2005, 'F', 'Jessica', 8108, 0.00399899778447237], [2005, 'F', 'Amanda', 4088, 0.00201626824653713], @@ -1088,7 +1088,7 @@ export const BABYNAME_DATA = [ [2005, 'F', 'Linda', 745, 0.000367446145711879], [2005, 'F', 'Deborah', 425, 0.00020961692876181], [2005, 'F', 'Dorothy', 234, 0.000115412614894738], - [2005, 'F', 'Betty', 132, 6.51045519919034e-05], + [2005, 'F', 'Betty', 132, 6.51045519919034e-5], [2006, 'F', 'Ashley', 12340, 0.00590922303294464], [2006, 'F', 'Jessica', 6809, 0.00326060774970179], [2006, 'F', 'Amanda', 3355, 0.00160659994129086], @@ -1097,7 +1097,7 @@ export const BABYNAME_DATA = [ [2006, 'F', 'Linda', 698, 0.000334249406563643], [2006, 'F', 'Deborah', 423, 0.000202560886785704], [2006, 'F', 'Dorothy', 265, 0.000126899846331469], - [2006, 'F', 'Betty', 135, 6.46470915273522e-05], + [2006, 'F', 'Betty', 135, 6.46470915273522e-5], [2007, 'F', 'Ashley', 11423, 0.00540374075290008], [2007, 'F', 'Jessica', 5704, 0.00269832244196289], [2007, 'F', 'Amanda', 3038, 0.00143714999626284], @@ -1106,7 +1106,7 @@ export const BABYNAME_DATA = [ [2007, 'F', 'Linda', 659, 0.000311745176937858], [2007, 'F', 'Deborah', 371, 0.000175504492631177], [2007, 'F', 'Dorothy', 262, 0.000123941178084551], - [2007, 'F', 'Betty', 134, 6.33897628371366e-05], + [2007, 'F', 'Betty', 134, 6.33897628371366e-5], [2008, 'F', 'Ashley', 9402, 0.00452030531532519], [2008, 'F', 'Jessica', 4732, 0.00227505687642191], [2008, 'F', 'Amanda', 2439, 0.00117262546948289], @@ -1115,7 +1115,7 @@ export const BABYNAME_DATA = [ [2008, 'F', 'Linda', 611, 0.000293757343933598], [2008, 'F', 'Deborah', 355, 0.000170677343856673], [2008, 'F', 'Dorothy', 242, 0.000116349062572718], - [2008, 'F', 'Betty', 137, 6.58670312911669e-05], + [2008, 'F', 'Betty', 137, 6.58670312911669e-5], [2009, 'F', 'Ashley', 7811, 0.00386339097012116], [2009, 'F', 'Jessica', 3793, 0.00187605197153624], [2009, 'F', 'Amanda', 1952, 0.000965476785773462], @@ -1124,7 +1124,7 @@ export const BABYNAME_DATA = [ [2009, 'F', 'Linda', 550, 0.000272034955007891], [2009, 'F', 'Deborah', 346, 0.000171134717150419], [2009, 'F', 'Dorothy', 226, 0.000111781636057788], - [2009, 'F', 'Betty', 148, 7.32021333475781e-05], + [2009, 'F', 'Betty', 148, 7.32021333475781e-5], [2010, 'F', 'Ashley', 6306, 0.00322252105804575], [2010, 'F', 'Jessica', 3195, 0.00163272356175962], [2010, 'F', 'Amanda', 1655, 0.000845745694745594], @@ -1133,7 +1133,7 @@ export const BABYNAME_DATA = [ [2010, 'F', 'Linda', 476, 0.00024324770434979], [2010, 'F', 'Deborah', 354, 0.000180902704495432], [2010, 'F', 'Dorothy', 240, 0.000122645901352835], - [2010, 'F', 'Betty', 132, 6.74552457440595e-05], + [2010, 'F', 'Betty', 132, 6.74552457440595e-5], [2011, 'F', 'Ashley', 5398, 0.00279205644940212], [2011, 'F', 'Jessica', 2620, 0.00135516633890952], [2011, 'F', 'Amanda', 1409, 0.000728789836459354], @@ -1142,7 +1142,7 @@ export const BABYNAME_DATA = [ [2011, 'F', 'Patricia', 427, 0.000220861078898612], [2011, 'F', 'Deborah', 332, 0.000171723368136626], [2011, 'F', 'Dorothy', 276, 0.000142757980740086], - [2011, 'F', 'Betty', 167, 8.63789231289653e-05], + [2011, 'F', 'Betty', 167, 8.63789231289653e-5], [2012, 'F', 'Ashley', 4696, 0.00242806420306393], [2012, 'F', 'Jessica', 2327, 0.00120317406314518], [2012, 'F', 'Amanda', 1228, 0.00063493672090343], @@ -1151,7 +1151,7 @@ export const BABYNAME_DATA = [ [2012, 'F', 'Patricia', 394, 0.000203717482113967], [2012, 'F', 'Deborah', 336, 0.000173728614188561], [2012, 'F', 'Dorothy', 277, 0.000143222696816165], - [2012, 'F', 'Betty', 140, 7.2386922578567e-05], + [2012, 'F', 'Betty', 140, 7.2386922578567e-5], [2013, 'F', 'Ashley', 3936, 0.00204898297876106], [2013, 'F', 'Jessica', 1946, 0.00101303884061713], [2013, 'F', 'Amanda', 1064, 0.000553891740193539], @@ -1160,7 +1160,7 @@ export const BABYNAME_DATA = [ [2013, 'F', 'Patricia', 419, 0.000218120901448396], [2013, 'F', 'Dorothy', 334, 0.000173872031226167], [2013, 'F', 'Deborah', 329, 0.000171269156507213], - [2013, 'F', 'Betty', 174, 9.05800402196202e-05], + [2013, 'F', 'Betty', 174, 9.05800402196202e-5], [2014, 'F', 'Ashley', 3547, 0.00182125980653672], [2014, 'F', 'Jessica', 1790, 0.000919102073217006], [2014, 'F', 'Amanda', 1048, 0.000538111157950515], @@ -1169,7 +1169,7 @@ export const BABYNAME_DATA = [ [2014, 'F', 'Dorothy', 382, 0.000196143570932344], [2014, 'F', 'Patricia', 377, 0.000193576246705481], [2014, 'F', 'Deborah', 369, 0.0001894685279425], - [2014, 'F', 'Betty', 193, 9.90987151569174e-05], + [2014, 'F', 'Betty', 193, 9.90987151569174e-5], [2015, 'F', 'Ashley', 3409, 0.00176165787043521], [2015, 'F', 'Jessica', 1577, 0.000814941173856356], [2015, 'F', 'Amanda', 1013, 0.000523484723599549], @@ -1178,5 +1178,5 @@ export const BABYNAME_DATA = [ [2015, 'F', 'Dorothy', 395, 0.00020412286853092], [2015, 'F', 'Deborah', 346, 0.00017880129749797], [2015, 'F', 'Patricia', 346, 0.00017880129749797], - [2015, 'F', 'Betty', 186, 9.61186165740535e-05], + [2015, 'F', 'Betty', 186, 9.61186165740535e-5], ]; diff --git a/src/utils/domain.test.ts b/src/utils/domain.test.ts index 7f19adde5a..0f3a3233cf 100644 --- a/src/utils/domain.test.ts +++ b/src/utils/domain.test.ts @@ -18,11 +18,7 @@ */ import { AccessorFn } from './accessor'; -import { - computeContinuousDataDomain, - computeDomainExtent, - computeOrdinalDataDomain, -} from './domain'; +import { computeContinuousDataDomain, computeDomainExtent, computeOrdinalDataDomain } from './domain'; describe('utils/domain', () => { test('should return [0] domain if no data', () => { @@ -182,7 +178,10 @@ describe('utils/domain', () => { }); it('should allow max past baseline as 0, even if original domain is less than zero', () => { - expect(computeDomainExtent([-65, -5], { fit: true, padding: 15, constrainPadding: false })).toEqual([-80, 10]); + expect(computeDomainExtent([-65, -5], { fit: true, padding: 15, constrainPadding: false })).toEqual([ + -80, + 10, + ]); }); }); }); diff --git a/src/utils/domain.ts b/src/utils/domain.ts index 160a8eded4..f3f21277fb 100644 --- a/src/utils/domain.ts +++ b/src/utils/domain.ts @@ -39,9 +39,7 @@ export function computeOrdinalDataDomain( const domain = data.map(accessor).filter((d) => (removeNull ? d !== null : true)); const uniqueValues = [...new Set(domain)]; - return sorted - ? uniqueValues.sort((a, b) => `${a}`.localeCompare(`${b}`)) - : uniqueValues; + return sorted ? uniqueValues.sort((a, b) => `${a}`.localeCompare(`${b}`)) : uniqueValues; } function getPaddedRange(start: number, end: number, domainOptions?: YDomainRange): [number, number] { @@ -66,10 +64,7 @@ function getPaddedRange(start: number, end: number, domainOptions?: YDomainRange const newEnd = end + computedPadding; if (domainOptions.constrainPadding ?? true) { - return [ - start >= 0 && newStart < 0 ? 0 : newStart, - end <= 0 && newEnd > 0 ? 0 : newEnd, - ]; + return [start >= 0 && newStart < 0 ? 0 : newStart, end <= 0 && newEnd > 0 ? 0 : newEnd]; } return [newStart, newEnd]; diff --git a/src/utils/fast_deep_equal.ts b/src/utils/fast_deep_equal.ts index c78c53bc8f..553b685756 100644 --- a/src/utils/fast_deep_equal.ts +++ b/src/utils/fast_deep_equal.ts @@ -41,7 +41,7 @@ export function deepEqual(a: any, b: any): boolean { if (Array.isArray(a)) { length = a.length; if (length != b.length) return false; - for (i = length; i-- !== 0;) if (!deepEqual(a[i], b[i])) return false; + for (i = length; i-- !== 0; ) if (!deepEqual(a[i], b[i])) return false; return true; } if (a instanceof Map && b instanceof Map) { @@ -68,9 +68,9 @@ export function deepEqual(a: any, b: any): boolean { length = keys.length; if (length !== Object.keys(b).length) return false; - for (i = length; i-- !== 0;) if (!Object.prototype.hasOwnProperty.call(b, keys[i])) return false; + for (i = length; i-- !== 0; ) if (!Object.prototype.hasOwnProperty.call(b, keys[i])) return false; - for (i = length; i-- !== 0;) { + for (i = length; i-- !== 0; ) { const key = keys[i]; if (key === '_owner' && a.$$typeof) { // React-specific: avoid traversing React elements' _owner. diff --git a/src/utils/logger.ts b/src/utils/logger.ts index 327f2d3655..c1ab696cd3 100644 --- a/src/utils/logger.ts +++ b/src/utils/logger.ts @@ -45,10 +45,13 @@ export class Logger { */ static expected(message: any, expected: any, received: any) { if (Logger.isDevelopment() && !Logger.isTest()) { - console.warn(`${Logger.namespace} ${message}`, `\n + console.warn( + `${Logger.namespace} ${message}`, + `\n Expected: ${expected} Received: ${received} -`); +`, + ); } } diff --git a/src/utils/themes/theme.ts b/src/utils/themes/theme.ts index 6552735d12..ad87e556bb 100644 --- a/src/utils/themes/theme.ts +++ b/src/utils/themes/theme.ts @@ -17,7 +17,14 @@ * under the License. */ -import { mergePartial, RecursivePartial, Color, ColorVariant, HorizontalAlignment, VerticalAlignment } from '../commons'; +import { + mergePartial, + RecursivePartial, + Color, + ColorVariant, + HorizontalAlignment, + VerticalAlignment, +} from '../commons'; import { Margins, SimplePadding } from '../dimensions'; import { LIGHT_THEME } from './light_theme'; @@ -102,16 +109,17 @@ export interface StrokeStyle { } /** @public */ -export type TickStyle = StrokeStyle & Visible & { - /** - * Amount of padding between tick line and labels - */ - padding: number; - /** - * length of tick line - */ - size: number; -}; +export type TickStyle = StrokeStyle & + Visible & { + /** + * Amount of padding between tick line and labels + */ + padding: number; + /** + * length of tick line + */ + size: number; + }; /** * The dash array for a stroke @@ -133,17 +141,18 @@ export interface Opacity { export interface AxisStyle { axisTitle: TextStyle & Visible; axisLine: StrokeStyle & Visible; - tickLabel: TextStyle & Visible & { - /** The degrees of rotation of the tick labels */ - rotation: number; - /** - * Offset in pixels to render text relative to anchor - * - * **Note:** rotation aligns to global cartesian coordinates - */ - offset: TextOffset; - alignment: TextAlignment - }; + tickLabel: TextStyle & + Visible & { + /** The degrees of rotation of the tick labels */ + rotation: number; + /** + * Offset in pixels to render text relative to anchor + * + * **Note:** rotation aligns to global cartesian coordinates + */ + offset: TextOffset; + alignment: TextAlignment; + }; tickLine: TickStyle; gridLine: { horizontal: GridLineStyle; diff --git a/stories/annotations/lines/1_x_continuous.tsx b/stories/annotations/lines/1_x_continuous.tsx index 3cb4f9e0f7..1d94826f6e 100644 --- a/stories/annotations/lines/1_x_continuous.tsx +++ b/stories/annotations/lines/1_x_continuous.tsx @@ -40,13 +40,11 @@ function generateAnnotationData(values: any[]): LineAnnotationDatum[] { export const Example = () => { const debug = boolean('debug', false); - const markerPosition = select('marker position', [ - Position.Top, - Position.Left, - Position.Bottom, - Position.Right, + const markerPosition = select( + 'marker position', + [Position.Top, Position.Left, Position.Bottom, Position.Right, 'undefined'], 'undefined', - ], 'undefined'); + ); const rotation = getChartRotationKnob(); const data = arrayKnobs('data values', [2.5, 7.2]); const dataValues = generateAnnotationData(data); diff --git a/stories/annotations/lines/2_x_ordinal.tsx b/stories/annotations/lines/2_x_ordinal.tsx index c3486ab8b4..6df7c21a8d 100644 --- a/stories/annotations/lines/2_x_ordinal.tsx +++ b/stories/annotations/lines/2_x_ordinal.tsx @@ -40,13 +40,12 @@ function generateAnnotationData(values: any[]): LineAnnotationDatum[] { export const Example = () => { const debug = boolean('debug', false); - const markerPosition = select('marker position', [ - Position.Top, - Position.Left, - Position.Bottom, - Position.Right, + const markerPosition = select( + 'marker position', + [Position.Top, Position.Left, Position.Bottom, Position.Right, 'undefined'], 'undefined', - ], 'undefined'); const rotation = getChartRotationKnob(); + ); + const rotation = getChartRotationKnob(); const dataValues = generateAnnotationData(arrayKnobs('annotation values', ['a', 'c'])); return ( diff --git a/stories/annotations/lines/3_x_time.tsx b/stories/annotations/lines/3_x_time.tsx index fb2e4f2e16..feec28b8db 100644 --- a/stories/annotations/lines/3_x_time.tsx +++ b/stories/annotations/lines/3_x_time.tsx @@ -48,13 +48,12 @@ function generateTimeAnnotationData(values: any[]): LineAnnotationDatum[] { export const Example = () => { const debug = boolean('debug', false); - const markerPosition = select('marker position', [ - Position.Top, - Position.Left, - Position.Bottom, - Position.Right, + const markerPosition = select( + 'marker position', + [Position.Top, Position.Left, Position.Bottom, Position.Right, 'undefined'], 'undefined', - ], 'undefined'); const rotation = getChartRotationKnob(); + ); + const rotation = getChartRotationKnob(); const dataValues = generateTimeAnnotationData([ 1551438150000, diff --git a/stories/annotations/lines/4_y_domain.tsx b/stories/annotations/lines/4_y_domain.tsx index ed4f6ddd87..2d05193c28 100644 --- a/stories/annotations/lines/4_y_domain.tsx +++ b/stories/annotations/lines/4_y_domain.tsx @@ -41,13 +41,11 @@ function generateAnnotationData(values: any[]): LineAnnotationDatum[] { export const Example = () => { const debug = boolean('debug', false); const rotation = getChartRotationKnob(); - const markerPosition = select('marker position', [ - Position.Top, - Position.Left, - Position.Bottom, - Position.Right, + const markerPosition = select( + 'marker position', + [Position.Top, Position.Left, Position.Bottom, Position.Right, 'undefined'], 'undefined', - ], 'undefined'); + ); const data = arrayKnobs('data values', [1.5, 7.2]); const dataValues = generateAnnotationData(data); diff --git a/stories/annotations/lines/7_tooltip_options.tsx b/stories/annotations/lines/7_tooltip_options.tsx index 2d94b16085..c45a240ec6 100644 --- a/stories/annotations/lines/7_tooltip_options.tsx +++ b/stories/annotations/lines/7_tooltip_options.tsx @@ -27,7 +27,9 @@ import { Chart, ScaleType, Settings, - LineAnnotation, AnnotationDomainTypes, LineAnnotationDatum, + LineAnnotation, + AnnotationDomainTypes, + LineAnnotationDatum, } from '../../../src'; import { CustomAnnotationTooltip } from '../../../src/chart_types/xy_chart/annotations/types'; import { Icon } from '../../../src/components/icons/icon'; @@ -55,22 +57,22 @@ export const Example = () => { const dataValues = generateAnnotationData(arrayKnobs('annotation values', ['a', 'c'])); - const customTooltip: CustomAnnotationTooltip | undefined = showCustomTooltip ? ({ header, details }) => ( -
-

- custom tooltip - - {' '} - {header} -

-

{details}

-
- ) : undefined; - const customTooltipDetails: AnnotationTooltipFormatter | undefined = showCustomDetails ? (details) => ( -
-

custom Details

-

{details}

-
- ) : undefined; + const customTooltip: CustomAnnotationTooltip | undefined = showCustomTooltip + ? ({ header, details }) => ( +
+

custom tooltip -{header}

+

{details}

+
+ ) + : undefined; + const customTooltipDetails: AnnotationTooltipFormatter | undefined = showCustomDetails + ? (details) => ( +
+

custom Details

+

{details}

+
+ ) + : undefined; return ( diff --git a/stories/annotations/rects/4_styling.tsx b/stories/annotations/rects/4_styling.tsx index 202e232595..a30ac72b30 100644 --- a/stories/annotations/rects/4_styling.tsx +++ b/stories/annotations/rects/4_styling.tsx @@ -84,7 +84,7 @@ export const Example = () => { const hasCustomTooltip = boolean('has custom tooltip render', false); - const customTooltip = ({ details } : { details?: string }) => ( + const customTooltip = ({ details }: { details?: string }) => (
{details} diff --git a/stories/annotations/rects/5_tooltip_options.tsx b/stories/annotations/rects/5_tooltip_options.tsx index 822bfb27c2..517f40d33d 100644 --- a/stories/annotations/rects/5_tooltip_options.tsx +++ b/stories/annotations/rects/5_tooltip_options.tsx @@ -23,12 +23,7 @@ import React from 'react'; import { AnnotationTooltipFormatter, Axis, BarSeries, Chart, ScaleType, RectAnnotation, Settings } from '../../../src'; import { CustomAnnotationTooltip } from '../../../src/chart_types/xy_chart/annotations/types'; import { Position } from '../../../src/utils/commons'; -import { - getBoundaryKnob, - getChartRotationKnob, - getFallbackPlacementsKnob, - getPlacementKnob, -} from '../../utils/knobs'; +import { getBoundaryKnob, getChartRotationKnob, getFallbackPlacementsKnob, getPlacementKnob } from '../../utils/knobs'; export const Example = () => { const boundary = getBoundaryKnob(); @@ -37,10 +32,14 @@ export const Example = () => { const rotation = getChartRotationKnob(); const showCustomTooltip = boolean('custom tooltip', false); const showCustomDetails = boolean('custom tooltip details', false); - const details = select('details value', { - foo: 'foo', - undefined, - }, 'foo'); + const details = select( + 'details value', + { + foo: 'foo', + undefined, + }, + 'foo', + ); const dataValues = [ { @@ -54,20 +53,22 @@ export const Example = () => { }, ]; - const customTooltip: CustomAnnotationTooltip | undefined = showCustomTooltip ? ({ details }) => ( -
-

- custom tooltip -

-

{details}

-
- ) : undefined; - const customTooltipDetails: AnnotationTooltipFormatter | undefined = showCustomDetails ? (details) => ( -
-

custom Details

-

{details}

-
- ) : undefined; + const customTooltip: CustomAnnotationTooltip | undefined = showCustomTooltip + ? ({ details }) => ( +
+

custom tooltip

+

{details}

+
+ ) + : undefined; + const customTooltipDetails: AnnotationTooltipFormatter | undefined = showCustomDetails + ? (details) => ( +
+

custom Details

+

{details}

+
+ ) + : undefined; return ( diff --git a/stories/area/4_with_log.tsx b/stories/area/4_with_log.tsx index 3c22d29924..194aed6876 100644 --- a/stories/area/4_with_log.tsx +++ b/stories/area/4_with_log.tsx @@ -26,7 +26,7 @@ import { SB_SOURCE_PANEL } from '../utils/storybook'; const dateFormatter = timeFormatter('HH:mm'); export const Example = () => { - const data = KIBANA_METRICS.metrics.kibana_os_load[0].data.map((d) => d[1] < 7 ? [d[0], null] : [d[0], d[1] - 10]); + const data = KIBANA_METRICS.metrics.kibana_os_load[0].data.map((d) => (d[1] < 7 ? [d[0], null] : [d[0], d[1] - 10])); return ( diff --git a/stories/area/7_stacked.tsx b/stories/area/7_stacked.tsx index df00917db2..74e3b60163 100644 --- a/stories/area/7_stacked.tsx +++ b/stories/area/7_stacked.tsx @@ -27,13 +27,16 @@ const dateFormatter = timeFormatter('HH:mm'); export const Example = () => { const data1 = KIBANA_METRICS.metrics.kibana_os_load[0].data.map((d) => [ - ...d, KIBANA_METRICS.metrics.kibana_os_load[0].metric.label, + ...d, + KIBANA_METRICS.metrics.kibana_os_load[0].metric.label, ]); const data2 = KIBANA_METRICS.metrics.kibana_os_load[1].data.map((d) => [ - ...d, KIBANA_METRICS.metrics.kibana_os_load[1].metric.label, + ...d, + KIBANA_METRICS.metrics.kibana_os_load[1].metric.label, ]); const data3 = KIBANA_METRICS.metrics.kibana_os_load[2].data.map((d) => [ - ...d, KIBANA_METRICS.metrics.kibana_os_load[2].metric.label, + ...d, + KIBANA_METRICS.metrics.kibana_os_load[2].metric.label, ]); const allMetrics = [...data3, ...data2, ...data1]; return ( diff --git a/stories/area/8_stacked_percentage_zeros.tsx b/stories/area/8_stacked_percentage_zeros.tsx index 5145f811cf..2be3911977 100644 --- a/stories/area/8_stacked_percentage_zeros.tsx +++ b/stories/area/8_stacked_percentage_zeros.tsx @@ -30,12 +30,7 @@ export const Example = () => ( title="Bottom axis" tickFormat={niceTimeFormatter([1585234800000, 1585836000000])} /> - `${Number(d * 100).toFixed(0)} %`} - /> + `${Number(d * 100).toFixed(0)} %`} /> { const fourDays = moment.duration(4, 'd'); const fiveDays = moment.duration(5, 'd'); const formatters: Record = { - daily: niceTimeFormatter([now, moment.duration(31, 'd').add(now).asMilliseconds()]), + daily: niceTimeFormatter([ + now, + moment + .duration(31, 'd') + .add(now) + .asMilliseconds(), + ]), hourly: (d) => moment(d).format('HH:mm'), }; const formatterSelect = select('formatter', ['daily', 'hourly'], 'daily'); diff --git a/stories/axes/1_basic.tsx b/stories/axes/1_basic.tsx index 99a9f6b9d3..4805909da5 100644 --- a/stories/axes/1_basic.tsx +++ b/stories/axes/1_basic.tsx @@ -20,7 +20,17 @@ import { boolean, number } from '@storybook/addon-knobs'; import React from 'react'; -import { AreaSeries, Axis, Chart, Position, ScaleType, Settings, niceTimeFormatter, RecursivePartial, AxisStyle } from '../../src'; +import { + AreaSeries, + Axis, + Chart, + Position, + ScaleType, + Settings, + niceTimeFormatter, + RecursivePartial, + AxisStyle, +} from '../../src'; import { KIBANA_METRICS } from '../../src/utils/data_samples/test_dataset_kibana'; export const Example = () => { diff --git a/stories/axes/2_tick_label_rotation.tsx b/stories/axes/2_tick_label_rotation.tsx index f7da8104bf..e747631487 100644 --- a/stories/axes/2_tick_label_rotation.tsx +++ b/stories/axes/2_tick_label_rotation.tsx @@ -20,7 +20,18 @@ import { boolean, number, select } from '@storybook/addon-knobs'; import React from 'react'; -import { AreaSeries, Axis, Chart, Position, ScaleType, Settings, AxisStyle, RecursivePartial, DEFAULT_CHART_MARGINS, DEFAULT_CHART_PADDING } from '../../src'; +import { + AreaSeries, + Axis, + Chart, + Position, + ScaleType, + Settings, + AxisStyle, + RecursivePartial, + DEFAULT_CHART_MARGINS, + DEFAULT_CHART_PADDING, +} from '../../src'; import { getVerticalTextAlignmentKnob, getHorizontalTextAlignmentKnob, getPositiveNumberKnob } from '../utils/knobs'; const getAxisKnobs = (group?: string, gridLines = false): RecursivePartial => ({ @@ -41,33 +52,53 @@ const getAxisKnobs = (group?: string, gridLines = false): RecursivePartial { position={Position.Bottom} title="Bottom axis" showOverlappingTicks - gridLine={onlyGlobal ? { - visible: boolean('show gridLines', false, Position.Bottom), - } : undefined} + gridLine={ + onlyGlobal + ? { + visible: boolean('show gridLines', false, Position.Bottom), + } + : undefined + } style={onlyGlobal ? bottomAxisStyles : undefined} /> { title="Left axis" position={Position.Left} style={onlyGlobal ? leftAxisStyles : undefined} - gridLine={onlyGlobal ? { - visible: boolean('show gridLines', false, Position.Left), - } : undefined} + gridLine={ + onlyGlobal + ? { + visible: boolean('show gridLines', false, Position.Left), + } + : undefined + } tickFormat={(d) => Number(d).toFixed(2)} /> { title="Top axis" position={Position.Top} style={onlyGlobal ? topAxisStyles : undefined} - gridLine={onlyGlobal ? { - visible: boolean('show gridLines', false, Position.Top), - } : undefined} + gridLine={ + onlyGlobal + ? { + visible: boolean('show gridLines', false, Position.Top), + } + : undefined + } tickFormat={(d) => Number(d).toFixed(2)} /> { title="Right axis" position={Position.Right} style={onlyGlobal ? rightAxisStyles : undefined} - gridLine={onlyGlobal ? { - visible: boolean('show gridLines', false, Position.Right), - } : undefined} + gridLine={ + onlyGlobal + ? { + visible: boolean('show gridLines', false, Position.Right), + } + : undefined + } tickFormat={(d) => Number(d).toFixed(2)} domain={{ min: 0, max: 10 }} /> diff --git a/stories/bar/2_label_value.tsx b/stories/bar/2_label_value.tsx index 54159bfb3b..42f049f8fe 100644 --- a/stories/bar/2_label_value.tsx +++ b/stories/bar/2_label_value.tsx @@ -57,7 +57,7 @@ export const Example = () => { barSeriesStyle: { displayValue: { fontSize: number('value font size', 10), - fontFamily: '\'Open Sans\', Helvetica, Arial, sans-serif', + fontFamily: "'Open Sans', Helvetica, Arial, sans-serif", fontStyle: 'normal', padding: 0, fill: color('value color', '#000'), diff --git a/stories/bar/30_stacked_to_extent.tsx b/stories/bar/30_stacked_to_extent.tsx index 1570d90033..0c65434f49 100644 --- a/stories/bar/30_stacked_to_extent.tsx +++ b/stories/bar/30_stacked_to_extent.tsx @@ -29,7 +29,13 @@ export const Example = () => { return ( - Number(d).toFixed(2)} /> + Number(d).toFixed(2)} + /> { const pointAlignment = select('point series alignment', HistogramModeAlignments, HistogramModeAlignments.Center); const pointData = TestDatasets.BARCHART_1Y0G; - const otherSeries = otherSeriesSelection === 'line' ? ( - - ) : ( - - ); + const otherSeries = + otherSeriesSelection === 'line' ? ( + + ) : ( + + ); const hasHistogramBarSeries = boolean('hasHistogramBarSeries', false); return ( diff --git a/stories/bar/8_with_log_yaxis.tsx b/stories/bar/8_with_log_yaxis.tsx index 4edaed4523..4a23807e10 100644 --- a/stories/bar/8_with_log_yaxis.tsx +++ b/stories/bar/8_with_log_yaxis.tsx @@ -26,7 +26,13 @@ export const Example = () => ( - Number(d).toFixed(2)} /> + Number(d).toFixed(2)} + /> ( - Number(d).toFixed(2)} /> + Number(d).toFixed(2)} + /> ( Example.story = { parameters: { info: { - text: 'Sends an event every time the chart render state changes. This is provided to bind attributes to the chart for visulaization loading checks.', + text: + 'Sends an event every time the chart render state changes. This is provided to bind attributes to the chart for visulaization loading checks.', }, }, }; diff --git a/stories/interactions/16_cursor_update_action.tsx b/stories/interactions/16_cursor_update_action.tsx index 74705e7c72..f26439fd49 100644 --- a/stories/interactions/16_cursor_update_action.tsx +++ b/stories/interactions/16_cursor_update_action.tsx @@ -20,7 +20,17 @@ import { action } from '@storybook/addon-actions'; import React from 'react'; -import { Axis, BarSeries, Chart, Position, ScaleType, Settings, PointerEvent, Placement, niceTimeFormatter } from '../../src'; +import { + Axis, + BarSeries, + Chart, + Position, + ScaleType, + Settings, + PointerEvent, + Placement, + niceTimeFormatter, +} from '../../src'; import { KIBANA_METRICS } from '../../src/utils/data_samples/test_dataset_kibana'; import { palettes } from '../../src/utils/themes/colors'; import { SB_SOURCE_PANEL } from '../utils/storybook'; @@ -74,7 +84,6 @@ export const Example = () => { position={Position.Bottom} title="External tooltip VISIBLE - boundary => chart" tickFormat={niceTimeFormatter([data[0][0], data[data.length - 1][0]])} - /> { return ( - + { groupByRollup: (d: Datum) => countryLookup[d.dest].continentCountry.slice(0, 2), nodeLabel: (d: any) => regionLookup[d].regionName, shape: { - fillColor: (d: ShapeTreeNode) => categoricalFillColor(colorBrewerCategoricalStark9, 0.5)(d.parent.sortIndex), + fillColor: (d: ShapeTreeNode) => + categoricalFillColor(colorBrewerCategoricalStark9, 0.5)(d.parent.sortIndex), }, }, { groupByRollup: (d: Datum) => d.dest, nodeLabel: (d: any) => countryLookup[d].name, shape: { - fillColor: (d: ShapeTreeNode) => categoricalFillColor(colorBrewerCategoricalStark9, 0.3)(d.parent.parent.sortIndex), + fillColor: (d: ShapeTreeNode) => + categoricalFillColor(colorBrewerCategoricalStark9, 0.3)(d.parent.parent.sortIndex), }, }, ]} diff --git a/stories/legend/11_legend_actions.tsx b/stories/legend/11_legend_actions.tsx index 55a43d44c9..955042f068 100644 --- a/stories/legend/11_legend_actions.tsx +++ b/stories/legend/11_legend_actions.tsx @@ -17,11 +17,30 @@ * under the License. */ -import { EuiIcon, EuiPopover, EuiContextMenu, EuiContextMenuPanelDescriptor, EuiWrappingPopover, EuiColorPicker, EuiSpacer, EuiButton } from '@elastic/eui'; +import { + EuiIcon, + EuiPopover, + EuiContextMenu, + EuiContextMenuPanelDescriptor, + EuiWrappingPopover, + EuiColorPicker, + EuiSpacer, + EuiButton, +} from '@elastic/eui'; import { boolean } from '@storybook/addon-knobs'; import React, { useState } from 'react'; -import { Axis, BarSeries, Chart, Position, ScaleType, Settings, LegendAction, XYChartSeriesIdentifier, LegendColorPicker } from '../../src'; +import { + Axis, + BarSeries, + Chart, + Position, + ScaleType, + Settings, + LegendAction, + XYChartSeriesIdentifier, + LegendColorPicker, +} from '../../src'; import * as TestDatasets from '../../src/utils/data_samples/test_dataset'; import { getPositionKnob } from '../utils/knobs'; @@ -103,21 +122,13 @@ const getAction = (hideActions: boolean): LegendAction => ({ series }) => { withTitle anchorPosition="upLeft" > - + ); }; const renderColorPicker: LegendColorPicker = ({ anchor, color, onClose, onChange }) => ( - + diff --git a/stories/legend/2_legend_bottom.tsx b/stories/legend/2_legend_bottom.tsx index 58cff63f8d..fe627b1305 100644 --- a/stories/legend/2_legend_bottom.tsx +++ b/stories/legend/2_legend_bottom.tsx @@ -25,11 +25,7 @@ import { SB_SOURCE_PANEL } from '../utils/storybook'; export const Example = () => ( - + Number(d).toFixed(2)} /> diff --git a/stories/mixed/6_fitting_stacked.tsx b/stories/mixed/6_fitting_stacked.tsx index 1f92856316..d33400c90b 100644 --- a/stories/mixed/6_fitting_stacked.tsx +++ b/stories/mixed/6_fitting_stacked.tsx @@ -20,22 +20,12 @@ import { select, number } from '@storybook/addon-knobs'; import React from 'react'; -import { - AreaSeries, - Axis, - Chart, - CurveType, - Position, - ScaleType, - Settings, - Fit, - StackMode, -} from '../../src'; +import { AreaSeries, Axis, Chart, CurveType, Position, ScaleType, Settings, Fit, StackMode } from '../../src'; import { getRandomNumberGenerator } from '../../src/mocks/utils'; import { SB_KNOBS_PANEL } from '../utils/storybook'; export const Example = () => { - const dataTypes: Record> = { + const dataTypes: Record> = { isolated: [ { x: 0, y: 3 }, { x: 1, y: 5 }, diff --git a/stories/scales/1_different_timezones.tsx b/stories/scales/1_different_timezones.tsx index 8a97739bdf..23ad0d594b 100644 --- a/stories/scales/1_different_timezones.tsx +++ b/stories/scales/1_different_timezones.tsx @@ -32,18 +32,12 @@ const UTC_MINUS8_DATE = DateTime.fromISO('2019-01-01T00:00:00.000-08:00', { setZone: true, }).toMillis(); const DAY_INCREMENT_1 = 1000 * 60 * 60 * 24; -const UTC_DATASET = new Array(10).fill(0).map((d, i) => [ - UTC_DATE + DAY_INCREMENT_1 * i, i % 5, -]); -const CURRENT_TIMEZONE_DATASET = new Array(10).fill(0).map((d, i) => [ - today + DAY_INCREMENT_1 * i, i % 5, -]); -const OTHER_PLUS8_TIMEZONE_DATASET = new Array(10).fill(0).map((d, i) => [ - UTC_PLUS8_DATE + DAY_INCREMENT_1 * i, i % 5, -]); -const OTHER_MINUS8_TIMEZONE_DATASET = new Array(10).fill(0).map((d, i) => [ - UTC_MINUS8_DATE + DAY_INCREMENT_1 * i, i % 5, -]); +const UTC_DATASET = new Array(10).fill(0).map((d, i) => [UTC_DATE + DAY_INCREMENT_1 * i, i % 5]); +const CURRENT_TIMEZONE_DATASET = new Array(10).fill(0).map((d, i) => [today + DAY_INCREMENT_1 * i, i % 5]); +const OTHER_PLUS8_TIMEZONE_DATASET = new Array(10).fill(0).map((d, i) => [UTC_PLUS8_DATE + DAY_INCREMENT_1 * i, i % 5]); +const OTHER_MINUS8_TIMEZONE_DATASET = new Array(10) + .fill(0) + .map((d, i) => [UTC_MINUS8_DATE + DAY_INCREMENT_1 * i, i % 5]); export const Example = () => { const timezones = { @@ -84,9 +78,10 @@ export const Example = () => { break; default: case 'utc': - tooltipFn = (d: number) => DateTime.fromMillis(d) - .toUTC() - .toFormat('yyyy-MM-dd HH:mm:ss'); + tooltipFn = (d: number) => + DateTime.fromMillis(d) + .toUTC() + .toFormat('yyyy-MM-dd HH:mm:ss'); break; } return ( diff --git a/stories/scales/3_utc_tooltip.tsx b/stories/scales/3_utc_tooltip.tsx index 5c37ee2a44..1eb0f59820 100644 --- a/stories/scales/3_utc_tooltip.tsx +++ b/stories/scales/3_utc_tooltip.tsx @@ -32,9 +32,11 @@ export const Example = () => ( DateTime.fromMillis(d) - .toUTC() - .toFormat('yyyy-MM-dd HH:mm:ss')} + tickFormat={(d) => + DateTime.fromMillis(d) + .toUTC() + .toFormat('yyyy-MM-dd HH:mm:ss') + } /> ( - DateTime.fromMillis(d, { zone: 'utc-6' }).toISO()} - /> + DateTime.fromMillis(d, { zone: 'utc-6' }).toISO()} /> { Example.story = { parameters: { info: { - text: 'Using string values with a `Linear` scale will attempt to fallback to an `Ordinal` scale. Notice how the custom `xDomain` is ignored when the scale falls back to `Ordinal`.', + text: + 'Using string values with a `Linear` scale will attempt to fallback to an `Ordinal` scale. Notice how the custom `xDomain` is ignored when the scale falls back to `Ordinal`.', }, }, }; diff --git a/stories/streamgraph/1_basic.tsx b/stories/streamgraph/1_basic.tsx index a68bfd6cc4..ec46075f41 100644 --- a/stories/streamgraph/1_basic.tsx +++ b/stories/streamgraph/1_basic.tsx @@ -56,12 +56,10 @@ export const Example = () => { }, }} /> - ); }; - // storybook configuration Example.story = { parameters: { diff --git a/stories/stylings/15_tick_label.tsx b/stories/stylings/15_tick_label.tsx index 2db16264ef..9d6f5d4d00 100644 --- a/stories/stylings/15_tick_label.tsx +++ b/stories/stylings/15_tick_label.tsx @@ -52,7 +52,7 @@ export const Example = () => { tickLabel: { fill: color('tickFill', '#333', 'Tick Label'), fontSize: range('tickFontSize', 0, 40, 10, 'Tick Label'), - fontFamily: '\'Open Sans\', Helvetica, Arial, sans-serif', + fontFamily: "'Open Sans', Helvetica, Arial, sans-serif", fontStyle: 'normal', padding: number('Tick Label Padding Theme', 1, {}, 'Tick Label'), }, diff --git a/stories/stylings/20_partition_background.tsx b/stories/stylings/20_partition_background.tsx index 9982a9f0fe..bccab7e430 100644 --- a/stories/stylings/20_partition_background.tsx +++ b/stories/stylings/20_partition_background.tsx @@ -62,14 +62,16 @@ export const Example = () => { groupByRollup: (d: Datum) => countryLookup[d.dest].continentCountry.slice(0, 2), nodeLabel: (d: any) => regionLookup[d].regionName, shape: { - fillColor: (d: ShapeTreeNode) => categoricalFillColor(colorBrewerCategoricalStark9, 0.5)(d.parent.sortIndex), + fillColor: (d: ShapeTreeNode) => + categoricalFillColor(colorBrewerCategoricalStark9, 0.5)(d.parent.sortIndex), }, }, { groupByRollup: (d: Datum) => d.dest, nodeLabel: (d: any) => countryLookup[d].name, shape: { - fillColor: (d: ShapeTreeNode) => categoricalFillColor(colorBrewerCategoricalStark9, 0.3)(d.parent.parent.sortIndex), + fillColor: (d: ShapeTreeNode) => + categoricalFillColor(colorBrewerCategoricalStark9, 0.3)(d.parent.parent.sortIndex), }, }, ]} diff --git a/stories/stylings/3_axis.tsx b/stories/stylings/3_axis.tsx index d4ad13d890..0ffc27e536 100644 --- a/stories/stylings/3_axis.tsx +++ b/stories/stylings/3_axis.tsx @@ -43,7 +43,7 @@ export const Example = () => { fill: color('titleFill', '#333', 'Axis Title'), fontSize: range('titleFontSize', 0, 40, 12, 'Axis Title'), fontStyle: 'bold', - fontFamily: '\'Open Sans\', Helvetica, Arial, sans-serif', + fontFamily: "'Open Sans', Helvetica, Arial, sans-serif", padding: range('titlePadding', 0, 40, 5, 'Axis Title'), }, axisLine: { @@ -53,7 +53,7 @@ export const Example = () => { tickLabel: { fill: color('tickFill', '#333', 'Tick Label'), fontSize: range('tickFontSize', 0, 40, 10, 'Tick Label'), - fontFamily: '\'Open Sans\', Helvetica, Arial, sans-serif', + fontFamily: "'Open Sans', Helvetica, Arial, sans-serif", fontStyle: 'normal', padding: number('tickLabelPadding', 1, {}, 'Tick Label'), }, diff --git a/stories/stylings/9_custom_series_colors_function.tsx b/stories/stylings/9_custom_series_colors_function.tsx index 5d69fb2f58..280a6d0c3d 100644 --- a/stories/stylings/9_custom_series_colors_function.tsx +++ b/stories/stylings/9_custom_series_colors_function.tsx @@ -27,10 +27,10 @@ export const Example = () => { const barColor = color('barSeriesColor', '#000'); const barSeriesColorAccessor: SeriesColorAccessor = ({ specId, yAccessor, splitAccessors }) => { if ( - specId === 'bars' - && yAccessor === 'y1' - && splitAccessors.get('g1') === 'cloudflare.com' - && splitAccessors.get('g2') === 'direct-cdn' + specId === 'bars' && + yAccessor === 'y1' && + splitAccessors.get('g1') === 'cloudflare.com' && + splitAccessors.get('g2') === 'direct-cdn' ) { return barColor; } diff --git a/stories/sunburst/15_single_sunburst.tsx b/stories/sunburst/15_single_sunburst.tsx index da5d37dd4a..124ac6d25f 100644 --- a/stories/sunburst/15_single_sunburst.tsx +++ b/stories/sunburst/15_single_sunburst.tsx @@ -52,14 +52,16 @@ export const Example = () => ( groupByRollup: (d: Datum) => countryLookup[d.dest].continentCountry.slice(0, 2), nodeLabel: (d: any) => regionLookup[d].regionName.replace(/\s/g, '\u00A0'), shape: { - fillColor: (d: ShapeTreeNode) => categoricalFillColor(colorBrewerCategoricalStark9, 0.5)(d.parent.sortIndex), + fillColor: (d: ShapeTreeNode) => + categoricalFillColor(colorBrewerCategoricalStark9, 0.5)(d.parent.sortIndex), }, }, { groupByRollup: (d: Datum) => d.dest, nodeLabel: (d: any) => countryLookup[d].name.replace(/\s/g, '\u00A0'), shape: { - fillColor: (d: ShapeTreeNode) => categoricalFillColor(colorBrewerCategoricalStark9, 0.3)(d.parent.parent.sortIndex), + fillColor: (d: ShapeTreeNode) => + categoricalFillColor(colorBrewerCategoricalStark9, 0.3)(d.parent.parent.sortIndex), }, }, ]} diff --git a/stories/sunburst/26_percentage.tsx b/stories/sunburst/26_percentage.tsx index 4eaaea72fd..5c7dd3add4 100644 --- a/stories/sunburst/26_percentage.tsx +++ b/stories/sunburst/26_percentage.tsx @@ -54,14 +54,16 @@ export const Example = () => ( groupByRollup: (d: Datum) => countryLookup[d.dest].continentCountry.slice(0, 2), nodeLabel: (d: any) => regionLookup[d].regionName, shape: { - fillColor: (d: ShapeTreeNode) => categoricalFillColor(colorBrewerCategoricalStark9, 0.5)(d.parent.sortIndex), + fillColor: (d: ShapeTreeNode) => + categoricalFillColor(colorBrewerCategoricalStark9, 0.5)(d.parent.sortIndex), }, }, { groupByRollup: (d: Datum) => d.dest, nodeLabel: (d: any) => countryLookup[d].name, shape: { - fillColor: (d: ShapeTreeNode) => categoricalFillColor(colorBrewerCategoricalStark9, 0.3)(d.parent.parent.sortIndex), + fillColor: (d: ShapeTreeNode) => + categoricalFillColor(colorBrewerCategoricalStark9, 0.3)(d.parent.parent.sortIndex), }, }, ]} diff --git a/stories/sunburst/27_heterogeneous_depth.tsx b/stories/sunburst/27_heterogeneous_depth.tsx index a31ee7ebb6..a12411cfb0 100644 --- a/stories/sunburst/27_heterogeneous_depth.tsx +++ b/stories/sunburst/27_heterogeneous_depth.tsx @@ -53,7 +53,8 @@ export const Example = () => ( groupByRollup: (d: Datum) => countryLookup[d.dest].continentCountry.slice(0, 2), nodeLabel: (d: PrimitiveValue) => d !== null && regionLookup[d].regionName, shape: { - fillColor: (d: ShapeTreeNode) => categoricalFillColor(colorBrewerCategoricalStark9, 0.5)(d.parent.sortIndex), + fillColor: (d: ShapeTreeNode) => + categoricalFillColor(colorBrewerCategoricalStark9, 0.5)(d.parent.sortIndex), }, }, { @@ -61,7 +62,8 @@ export const Example = () => ( nodeLabel: (d: PrimitiveValue) => d !== null && countryLookup[d].name, showAccessor: (d: PrimitiveValue) => !(['chn', 'hkg', 'jpn', 'kor'] as PrimitiveValue[]).includes(d), shape: { - fillColor: (d: ShapeTreeNode) => categoricalFillColor(colorBrewerCategoricalStark9, 0.3)(d.parent.parent.sortIndex), + fillColor: (d: ShapeTreeNode) => + categoricalFillColor(colorBrewerCategoricalStark9, 0.3)(d.parent.parent.sortIndex), }, }, ]} diff --git a/stories/sunburst/8_sunburst_two_layers.tsx b/stories/sunburst/8_sunburst_two_layers.tsx index ff8a66ec5e..b2f96affd7 100644 --- a/stories/sunburst/8_sunburst_two_layers.tsx +++ b/stories/sunburst/8_sunburst_two_layers.tsx @@ -44,8 +44,7 @@ export const Example = () => ( shape: { fillColor: (d) => // pick color from color palette based on mean angle - rather distinct colors in the inner ring - indexInterpolatedFillColor(interpolatorCET2s)(d, (d.x0 + d.x1) / 2 / (2 * Math.PI), []) - , + indexInterpolatedFillColor(interpolatorCET2s)(d, (d.x0 + d.x1) / 2 / (2 * Math.PI), []), }, }, { @@ -54,8 +53,7 @@ export const Example = () => ( shape: { fillColor: (d) => // pick color from color palette based on mean angle - related yet distinct colors in the outer ring - indexInterpolatedFillColor(interpolatorCET2s)(d, (d.x0 + d.x1) / 2 / (2 * Math.PI), []) - , + indexInterpolatedFillColor(interpolatorCET2s)(d, (d.x0 + d.x1) / 2 / (2 * Math.PI), []), }, }, ]} diff --git a/stories/sunburst/9_sunburst_three_layers.tsx b/stories/sunburst/9_sunburst_three_layers.tsx index 4118018234..8a8b0b8aae 100644 --- a/stories/sunburst/9_sunburst_three_layers.tsx +++ b/stories/sunburst/9_sunburst_three_layers.tsx @@ -55,7 +55,8 @@ export const Example = () => ( nodeLabel: (d: any) => regionLookup[d].regionName, fillLabel: { maximizeFontSize: boolean('Maximize font size layer 2', true) }, shape: { - fillColor: (d: ShapeTreeNode) => categoricalFillColor(colorBrewerCategoricalStark9, 0.5)(d.parent.sortIndex), + fillColor: (d: ShapeTreeNode) => + categoricalFillColor(colorBrewerCategoricalStark9, 0.5)(d.parent.sortIndex), }, }, { @@ -63,7 +64,8 @@ export const Example = () => ( nodeLabel: (d: any) => countryLookup[d].name, fillLabel: { maximizeFontSize: boolean('Maximize font size layer 3', true) }, shape: { - fillColor: (d: ShapeTreeNode) => categoricalFillColor(colorBrewerCategoricalStark9, 0.3)(d.parent.parent.sortIndex), + fillColor: (d: ShapeTreeNode) => + categoricalFillColor(colorBrewerCategoricalStark9, 0.3)(d.parent.parent.sortIndex), }, }, ]} diff --git a/stories/treemap/10_three_layers.tsx b/stories/treemap/10_three_layers.tsx index fad509a225..c4c7aa2b06 100644 --- a/stories/treemap/10_three_layers.tsx +++ b/stories/treemap/10_three_layers.tsx @@ -90,8 +90,7 @@ export const Example = () => ( shape: { fillColor: (d: ShapeTreeNode) => // pick color by country - interpolator(countries.indexOf(d.dataName) / countryCount) - , + interpolator(countries.indexOf(d.dataName) / countryCount), }, fillLabel: { maximizeFontSize: boolean('Maximize font size layer 3', true) }, }, diff --git a/stories/treemap/3_mid_two.tsx b/stories/treemap/3_mid_two.tsx index 6cfdacf349..b668073f81 100644 --- a/stories/treemap/3_mid_two.tsx +++ b/stories/treemap/3_mid_two.tsx @@ -71,8 +71,7 @@ export const Example = () => ( // primarily, pick color based on parent's index, but then perturb by the index within the parent interpolatorTurbo( (d.parent.sortIndex + d.sortIndex / d.parent.children.length) / (d.parent.parent.children.length + 1), - ) - , + ), }, }, ]} diff --git a/stories/treemap/4_two_layer_stress.tsx b/stories/treemap/4_two_layer_stress.tsx index f919b1baad..12c38466cc 100644 --- a/stories/treemap/4_two_layer_stress.tsx +++ b/stories/treemap/4_two_layer_stress.tsx @@ -75,8 +75,7 @@ export const Example = () => ( // primarily, pick color based on parent's index, but then perturb by the index within the parent interpolatorTurbo( (d.parent.sortIndex + d.sortIndex / d.parent.children.length) / (d.parent.parent.children.length + 1), - ) - , + ), }, }, ]} diff --git a/stories/treemap/7_percentage.tsx b/stories/treemap/7_percentage.tsx index e9130f7b4d..7e2c5abbc7 100644 --- a/stories/treemap/7_percentage.tsx +++ b/stories/treemap/7_percentage.tsx @@ -78,8 +78,7 @@ export const Example = () => ( // primarily, pick color based on parent's index, but then perturb by the index within the parent interpolatorTurbo( (d.parent.sortIndex + d.sortIndex / d.parent.children.length) / (d.parent.parent.children.length + 1), - ) - , + ), }, }, ]} diff --git a/stories/treemap/8_groove_text.tsx b/stories/treemap/8_groove_text.tsx index 4b8b80fef0..dd1d9bc49b 100644 --- a/stories/treemap/8_groove_text.tsx +++ b/stories/treemap/8_groove_text.tsx @@ -35,9 +35,7 @@ const countryLookup = arrayToLookup((d: Datum) => d.country, countryDimension); const interpolatorTurbo = hueInterpolator(palettes.turbo.map(([r, g, b]) => [r, g, b, 0.7])); export const Example = () => ( - + ( // primarily, pick color based on parent's index, but then perturb by the index within the parent interpolatorTurbo( (d.parent.sortIndex + d.sortIndex / d.parent.children.length) / (d.parent.parent.children.length + 1), - ) - , + ), }, }, ]} diff --git a/stories/utils/knobs.ts b/stories/utils/knobs.ts index fa460b13bf..2d369b4b7b 100644 --- a/stories/utils/knobs.ts +++ b/stories/utils/knobs.ts @@ -23,11 +23,8 @@ import { Rotation, Position, Placement, TooltipProps } from '../../src'; import { TooltipType } from '../../src/specs/constants'; import { VerticalAlignment, HorizontalAlignment } from '../../src/utils/commons'; -export const getPositiveNumberKnob = ( - name: string, - value: number, - groupId?: string, -) => number(name, value, { min: 0 }, groupId); +export const getPositiveNumberKnob = (name: string, value: number, groupId?: string) => + number(name, value, { min: 0 }, groupId); export const numberSelect = ( name: string, @@ -101,7 +98,9 @@ export const getPlacementKnob = (name = 'placement', defaultValue?: Placement) = export function arrayKnobs(name: string, values: (string | number)[]): (string | number)[] { const stringifiedValues = values.map((d) => `${d}`); - return array(name, stringifiedValues).map((value: string) => !isNaN(parseFloat(value)) ? parseFloat(value) : value); + return array(name, stringifiedValues).map((value: string) => + !isNaN(parseFloat(value)) ? parseFloat(value) : value, + ); } export const getFallbackPlacementsKnob = (): Placement[] | undefined => { @@ -143,16 +142,17 @@ export const getFallbackPlacementsKnob = (): Placement[] | undefined => { return knob; }; -// @ts-ignore -export const getBoundaryKnob = () => select( - 'Boundary Element', - { - Chart: 'chart', - 'Document Body': document.body, - Default: undefined, - }, - undefined, -); +export const getBoundaryKnob = () => + // @ts-ignore + select( + 'Boundary Element', + { + Chart: 'chart', + 'Document Body': document.body, + Default: undefined, + }, + undefined, + ); export const getVerticalTextAlignmentKnob = (group?: string) => select( diff --git a/stories/utils/utils.ts b/stories/utils/utils.ts index c1d7fbfe35..975526d58f 100644 --- a/stories/utils/utils.ts +++ b/stories/utils/utils.ts @@ -38,11 +38,47 @@ type RGBStrings = [string, string, string][]; const colorBrewerExportMatcher = /rgb\((\d{1,3}),(\d{1,3}),(\d{1,3})\)/; const colorStringToTuple = (s: string) => (colorBrewerExportMatcher.exec(s) as string[]).slice(1); -export const colorBrewerCategorical12: RGBStrings = ['rgb(166,206,227)', 'rgb(31,120,180)', 'rgb(178,223,138)', 'rgb(51,160,44)', 'rgb(251,154,153)', 'rgb(227,26,28)', 'rgb(253,191,111)', 'rgb(255,127,0)', 'rgb(202,178,214)', 'rgb(106,61,154)', 'rgb(255,255,153)', 'rgb(177,89,40)'].map(colorStringToTuple) as RGBStrings; +export const colorBrewerCategorical12: RGBStrings = [ + 'rgb(166,206,227)', + 'rgb(31,120,180)', + 'rgb(178,223,138)', + 'rgb(51,160,44)', + 'rgb(251,154,153)', + 'rgb(227,26,28)', + 'rgb(253,191,111)', + 'rgb(255,127,0)', + 'rgb(202,178,214)', + 'rgb(106,61,154)', + 'rgb(255,255,153)', + 'rgb(177,89,40)', +].map(colorStringToTuple) as RGBStrings; -export const colorBrewerCategoricalPastel12: RGBStrings = ['rgb(166,206,227)', 'rgb(31,120,180)', 'rgb(178,223,138)', 'rgb(51,160,44)', 'rgb(251,154,153)', 'rgb(227,26,28)', 'rgb(253,191,111)', 'rgb(255,127,0)', 'rgb(202,178,214)', 'rgb(106,61,154)', 'rgb(255,255,153)', 'rgb(177,89,40)'].map(colorStringToTuple) as RGBStrings; +export const colorBrewerCategoricalPastel12: RGBStrings = [ + 'rgb(166,206,227)', + 'rgb(31,120,180)', + 'rgb(178,223,138)', + 'rgb(51,160,44)', + 'rgb(251,154,153)', + 'rgb(227,26,28)', + 'rgb(253,191,111)', + 'rgb(255,127,0)', + 'rgb(202,178,214)', + 'rgb(106,61,154)', + 'rgb(255,255,153)', + 'rgb(177,89,40)', +].map(colorStringToTuple) as RGBStrings; -export const colorBrewerCategoricalStark9: RGBStrings = ['rgb(228,26,28)', 'rgb(55,126,184)', 'rgb(77,175,74)', 'rgb(152,78,163)', 'rgb(255,127,0)', 'rgb(255,255,51)', 'rgb(166,86,40)', 'rgb(247,129,191)', 'rgb(153,153,153)'].map(colorStringToTuple) as RGBStrings; +export const colorBrewerCategoricalStark9: RGBStrings = [ + 'rgb(228,26,28)', + 'rgb(55,126,184)', + 'rgb(77,175,74)', + 'rgb(152,78,163)', + 'rgb(255,127,0)', + 'rgb(255,255,51)', + 'rgb(166,86,40)', + 'rgb(247,129,191)', + 'rgb(153,153,153)', +].map(colorStringToTuple) as RGBStrings; export const categoricalFillColor = (categoricalColors: RGBStrings, opacity = 1) => (i: number) => `rgba(${categoricalColors[i % categoricalColors.length].concat([opacity.toString()]).join(',')})`;