diff --git a/README.md b/README.md index baa1bf6b96..381747fe16 100644 --- a/README.md +++ b/README.md @@ -91,8 +91,6 @@ If all goes well, you can get the following lovely bar chart! - [ant-design-charts](https://github.com/ant-design/ant-design-charts) - The React chart library, based on [G2](https://github.com/antvis/G2), [G6](https://github.com/antvis/G6), [X6](https://github.com/antvis/X6), [L7Plot](https://github.com/antvis/L7Plot). - [More...](https://github.com/antvis/G2/discussions/5772) - - ## 📮 Contributing - [Issues](https://github.com/antvis/g2/issues) - report bugs or request features diff --git a/__tests__/integration/snapshots/tooltip/movies-interval-scale-key-scrollbar/step0.html b/__tests__/integration/snapshots/tooltip/movies-interval-scale-key-scrollbar/step0.html new file mode 100644 index 0000000000..7a50374140 --- /dev/null +++ b/__tests__/integration/snapshots/tooltip/movies-interval-scale-key-scrollbar/step0.html @@ -0,0 +1,46 @@ +
+
+ Adventure +
+ +
\ No newline at end of file diff --git a/__tests__/plots/tooltip/index.ts b/__tests__/plots/tooltip/index.ts index 95c5244784..4c9416964b 100644 --- a/__tests__/plots/tooltip/index.ts +++ b/__tests__/plots/tooltip/index.ts @@ -69,3 +69,4 @@ export { stateAgesIntervalCustomStyle } from './stateages-interval-custom-style' export { mockTooltipClosest } from './mock-tooltip-closest'; export { stateAgesIntervalScrollbar } from './stateages-interval-scrollbar'; export { aaplLineOverflow } from './aapl-line-overflow'; +export { moviesIntervalScaleKeyScrollbar } from './movies-interval-scale-key-scrollbar'; diff --git a/__tests__/plots/tooltip/movies-interval-scale-key-scrollbar.ts b/__tests__/plots/tooltip/movies-interval-scale-key-scrollbar.ts new file mode 100644 index 0000000000..7f5627ee06 --- /dev/null +++ b/__tests__/plots/tooltip/movies-interval-scale-key-scrollbar.ts @@ -0,0 +1,25 @@ +import { G2Spec } from '../../../src'; +import { seriesTooltipSteps } from './utils'; + +export async function moviesIntervalScaleKeyScrollbar(): Promise { + return { + type: 'line', + data: { + type: 'fetch', + value: 'data/movies.csv', + }, + encode: { + x: 'Major Genre', + y: 'Worldwide Gross', + series: () => 'Worldwide Gross', + color: () => 'Worldwide Gross', + }, + transform: [{ type: 'groupX', y: 'sum' }], + scale: { y: { key: 'left' } }, + axis: { y: { labelFormatter: '~s' }, x: { labelTransform: 'rotate(90)' } }, + tooltip: { items: [{ channel: 'y', valueFormatter: '~s' }] }, + slider: { x: true }, + }; +} + +moviesIntervalScaleKeyScrollbar.steps = seriesTooltipSteps([300, 100]); diff --git a/src/component/slider.ts b/src/component/slider.ts index 2f4ad07ac5..3f0a3034e0 100644 --- a/src/component/slider.ts +++ b/src/component/slider.ts @@ -37,7 +37,7 @@ export const Slider: GCC = (options) => { const { width, height } = bbox; const { slider: sliderTheme = {} } = theme; - const defaultFormatter = scale.getFormatter?.() || ((v) => v.toString()); + const defaultFormatter = scale.getFormatter?.() || ((v) => v + ''); const formatter = typeof labelFormatter === 'string' ? format(labelFormatter) diff --git a/src/runtime/scale.ts b/src/runtime/scale.ts index 025fee1d3c..17d3ffd232 100644 --- a/src/runtime/scale.ts +++ b/src/runtime/scale.ts @@ -174,22 +174,17 @@ export function assignScale( ): Record { const keys = Object.keys(target); for (const scale of Object.values(source)) { - const { name, key } = scale.getOptions(); - if (typeof key === 'string') { - if (!(key in target)) target[key] = scale; - } else { - // For scale.key = Symbol('independent') - if (!(name in target)) target[name] = scale; - else { - const I = keys - .filter((d) => d.startsWith(name)) - // Reg is for extract `1` from `x1`; - .map((d) => +(d.replace(name, '') || 0)); - const index = max(I) + 1; - const newKey = `${name}${index}`; - target[newKey] = scale; - scale.getOptions().key = newKey; - } + const { name } = scale.getOptions(); + if (!(name in target)) target[name] = scale; + else { + const I = keys + .filter((d) => d.startsWith(name)) + // Reg is for extract `1` from `x1`; + .map((d) => +(d.replace(name, '') || 0)); + const index = max(I) + 1; + const newKey = `${name}${index}`; + target[newKey] = scale; + scale.getOptions().key = newKey; } } return target;