diff --git a/__tests__/integration/issue-6020.spec.ts b/__tests__/integration/issue-6020.spec.ts new file mode 100644 index 0000000000..ba10767c6c --- /dev/null +++ b/__tests__/integration/issue-6020.spec.ts @@ -0,0 +1,24 @@ +import { issue6020 as render } from '../plots/bugfix/issue-6020'; +import { createNodeGCanvas } from './utils/createNodeGCanvas'; +import { sleep } from './utils/sleep'; +import './utils/useSnapshotMatchers'; +import './utils/useCustomFetch'; + +describe('issue6020', () => { + const canvas = createNodeGCanvas(800, 500); + + it('issue6020.render() should render expected line chart with log scale', async () => { + const { chart } = render({ + canvas, + container: document.createElement('div'), + }); + await chart.render(); + await sleep(20); + const dir = `${__dirname}/snapshots/bugfix`; + await expect(canvas).toMatchDOMSnapshot(dir, render.name); + }); + + afterAll(() => { + canvas?.destroy(); + }); +}); diff --git a/__tests__/integration/snapshots/bugfix/issue6020.svg b/__tests__/integration/snapshots/bugfix/issue6020.svg new file mode 100644 index 0000000000..4d5178b274 --- /dev/null +++ b/__tests__/integration/snapshots/bugfix/issue6020.svg @@ -0,0 +1,1738 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + AAPL + + + + + + + + + + + + + + + + + + + + AMZN + + + + + + + + + + + + + + + + + + + + GOOG + + + + + + + + + + + + + + + + + + + + IBM + + + + + + + + + + + + + + + + + + + + MSFT + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 2014 + + + + + + + 2015 + + + + + + + 2016 + + + + + + + 2017 + + + + + + + 2018 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 0.6 + + + + + + + 0.7 + + + + + + + 0.8 + + + + + + + 0.9 + + + + + + + 1 + + + + + + + 2 + + + + + + + 3 + + + + + + + 4 + + + + + + + 5 + + + + + + + 6 + + + + + + + + + ↑ Change in price (%) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + AAPL + + + + + + + + + + + + + AMZN + + + + + + + + + + + + + GOOG + + + + + + + + + + + + + IBM + + + + + + + + + + + + + MSFT + + + + + + + + + + + + \ No newline at end of file diff --git a/__tests__/plots/bugfix/index.ts b/__tests__/plots/bugfix/index.ts index ab37e63670..8e2caa72e2 100644 --- a/__tests__/plots/bugfix/index.ts +++ b/__tests__/plots/bugfix/index.ts @@ -1,3 +1,4 @@ export { issue6396 } from './issue-6396'; export { issue6399 } from './issue-6399'; export { issueChart2719 } from './issue-chart-2719'; +export { issue6020 } from './issue-6020'; diff --git a/__tests__/plots/bugfix/issue-6020.ts b/__tests__/plots/bugfix/issue-6020.ts new file mode 100644 index 0000000000..7108ccdd75 --- /dev/null +++ b/__tests__/plots/bugfix/issue-6020.ts @@ -0,0 +1,45 @@ +import { Chart } from '../../../src'; + +export function issue6020(context) { + const { container, canvas } = context; + + const chart = new Chart({ + container: container, + autoFit: true, + insetRight: 10, + canvas, + }); + + let i = 0; + + chart + .line() + .data({ + type: 'fetch', + value: 'data/indices.csv', + }) + .transform({ type: 'normalizeY', basis: 'first', groupBy: 'color' }) + .encode('x', (d) => new Date(d.Date)) + .encode('y', 'Close') + .encode('color', 'Symbol') + .scale('y', { type: 'log' }) + .axis('y', { title: '↑ Change in price (%)' }) + .label({ + text: 'Symbol', + selector: (data) => { + if (data.length) { + return data.filter((d, index) => index === 500); + } + return data; + }, + fontSize: 10, + }) + .tooltip({ channel: 'y', valueFormatter: '.1f' }); + + chart.render().then(() => { + console.log(i); + i = 0; + }); + + return { chart }; +} diff --git a/src/runtime/plot.ts b/src/runtime/plot.ts index 2ec5314f29..a5ee20e6be 100644 --- a/src/runtime/plot.ts +++ b/src/runtime/plot.ts @@ -1364,6 +1364,7 @@ function createLabelShapeFunction( transform, style: abstractStyle, render, + selector, ...abstractOptions } = options; const visualOptions = mapObject(