Skip to content

Commit

Permalink
fix(dual): set series of line to band scale (#5528)
Browse files Browse the repository at this point in the history
  • Loading branch information
pearmini authored Sep 11, 2023
1 parent 88fdb41 commit 1446b1a
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 6 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions __tests__/plots/static/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
39 changes: 39 additions & 0 deletions __tests__/plots/static/mock-interval-line.ts
Original file line number Diff line number Diff line change
@@ -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%' } },
},
],
};
}
16 changes: 12 additions & 4 deletions src/interaction/tooltip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/mark/area.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
2 changes: 1 addition & 1 deletion src/mark/line.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ Line.props = {
{ name: 'y' },
{ name: 'position', independent: true },
{ name: 'size' },
{ name: 'series', scale: 'identity' },
{ name: 'series', scale: 'band' },
],
preInference: [
...basePreInference(),
Expand Down

0 comments on commit 1446b1a

Please sign in to comment.