diff --git a/__tests__/integration/snapshots/static/mockIntervalLine.png b/__tests__/integration/snapshots/static/mockIntervalLine.png new file mode 100644 index 0000000000..7305104e0c Binary files /dev/null and b/__tests__/integration/snapshots/static/mockIntervalLine.png differ diff --git a/__tests__/plots/static/index.ts b/__tests__/plots/static/index.ts index ef14049358..5f4f75e2df 100644 --- a/__tests__/plots/static/index.ts +++ b/__tests__/plots/static/index.ts @@ -283,3 +283,4 @@ export { settleWeatherCellLineXY } from './seattle-weather-cell-lineXY'; export { alphabetIntervalFunnelConnectorLabel } from './alphabet-interval-funnel-connector-label'; export { alphabetIntervalAxisOptions } from './alphabet-interval-axis-options'; export { profitIntervalAxisTransform } from './profit-interval-axis-transform'; +export { mockIntervalLine } from './mock-interval-line'; diff --git a/__tests__/plots/static/mock-interval-line.ts b/__tests__/plots/static/mock-interval-line.ts new file mode 100644 index 0000000000..04d29ce2d8 --- /dev/null +++ b/__tests__/plots/static/mock-interval-line.ts @@ -0,0 +1,39 @@ +import { G2Spec } from '../../../src'; + +export function mockIntervalLine(): G2Spec { + return { + type: 'view', + children: [ + { + type: 'interval', + data: [ + { time: '2019-03', value: 350, type: 'uv' }, + { time: '2019-04', value: 900, type: 'uv' }, + { time: '2019-05', value: 300, type: 'uv' }, + { time: '2019-06', value: 450, type: 'uv' }, + { time: '2019-07', value: 470, type: 'uv' }, + { time: '2019-03', value: 220, type: 'bill' }, + { time: '2019-04', value: 300, type: 'bill' }, + { time: '2019-05', value: 250, type: 'bill' }, + { time: '2019-06', value: 220, type: 'bill' }, + { time: '2019-07', value: 362, type: 'bill' }, + ], + encode: { x: 'time', y: 'value', color: 'type' }, + transform: [{ type: 'dodgeX' }], + axis: { y: { labelFormatter: '.0%' } }, + }, + { + type: 'line', + data: [ + { time: '2019-03', count: 800 }, + { time: '2019-04', count: 600 }, + { time: '2019-05', count: 400 }, + { time: '2019-06', count: 380 }, + { time: '2019-07', count: 220 }, + ], + encode: { x: 'time', y: 'count', color: () => 'line' }, + axis: { y: { labelFormatter: '.0%' } }, + }, + ], + }; +} diff --git a/src/interaction/tooltip.ts b/src/interaction/tooltip.ts index f23fa65dbc..e54d5221ec 100644 --- a/src/interaction/tooltip.ts +++ b/src/interaction/tooltip.ts @@ -2,7 +2,7 @@ import { Circle, DisplayObject, IElement, Line } from '@antv/g'; import { sort, group, mean, bisector, minIndex } from 'd3-array'; import { deepMix, lowerFirst, throttle } from '@antv/util'; import { Tooltip as TooltipComponent } from '@antv/gui'; -import { Constant, Identity } from '@antv/scale'; +import { Constant, Identity, Band } from '@antv/scale'; import { defined, subObject } from '../utils/helper'; import { isTranspose, isPolar } from '../utils/coordinate'; import { angle, sub } from '../utils/vector'; @@ -185,19 +185,26 @@ function singleItem(element) { } function groupNameOf(scale, datum) { - const { color: scaleColor, series: scaleSeries } = scale; + const { color: scaleColor, series: scaleSeries, facet = false } = scale; const { color, series } = datum; const invertAble = (scale) => { return ( scale && scale.invert && - !(scale instanceof Identity) && + !(scale instanceof Band) && !(scale instanceof Constant) ); }; // For non constant color channel. if (invertAble(scaleSeries)) return scaleSeries.invert(series); - if (series && series !== color) return series; + if ( + series && + scaleSeries instanceof Band && + scaleSeries.invert(series) !== color && + !facet + ) { + return scaleSeries.invert(series); + } if (invertAble(scaleColor)) { const name = scaleColor.invert(color); // For threshold scale. @@ -896,6 +903,7 @@ export function Tooltip(options) { const bbox = plotArea.getBounds(); const startX = bbox.min[0]; const startY = bbox.min[1]; + Object.assign(scale, { facet: true }); // @todo Nested structure rather than flat structure for facet? // Add listener to the root area. diff --git a/src/mark/area.ts b/src/mark/area.ts index 3e65ea21dd..9e35a83a17 100644 --- a/src/mark/area.ts +++ b/src/mark/area.ts @@ -85,7 +85,7 @@ Area.props = { { name: 'x', required: true }, { name: 'y', required: true }, { name: 'size' }, - { name: 'series', scale: 'identity' }, + { name: 'series', scale: 'band' }, ], preInference: [ ...basePreInference(), diff --git a/src/mark/line.ts b/src/mark/line.ts index 2a0f1bdd20..d7d96d2bbd 100644 --- a/src/mark/line.ts +++ b/src/mark/line.ts @@ -108,7 +108,7 @@ Line.props = { { name: 'y' }, { name: 'position', independent: true }, { name: 'size' }, - { name: 'series', scale: 'identity' }, + { name: 'series', scale: 'band' }, ], preInference: [ ...basePreInference(),