Skip to content

Commit

Permalink
fix(interval): fix interval render funnel (#4868)
Browse files Browse the repository at this point in the history
  • Loading branch information
shield2018 committed Apr 7, 2023
1 parent 3c7a060 commit 3834599
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 2 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
38 changes: 38 additions & 0 deletions __tests__/plots/static/alphabet-interval-funnel.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { G2Spec } from '../../../src';

export function alphabetIntervalFunnel(): G2Spec {
return {
type: 'interval',
coordinate: {
transform: [{ type: 'transpose' }],
},
data: [
{ text: '页面', value: 1000 },
{ text: '页面1', value: 900 },
{ text: '页面2', value: 800 },
{ text: '页面3', value: 700 },
],
transform: [
{
type: 'symmetryY',
},
],
axis: {
x: false,
y: false,
},
style: {
radius: 6,
stroke: '#ff0000',
},
encode: {
x: 'text',
y: 'value',
color: 'steelblue',
shape: 'funnel',
},
scale: {
x: { paddingOuter: 0, paddingInner: 0 },
},
};
}
1 change: 1 addition & 0 deletions __tests__/plots/static/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export { alphabetInterval } from './alphabet-interval';
export { alphabetIntervalFunnel } from './alphabet-interval-funnel';
export { alphabetIntervalTitle } from './alphabet-interval-title';
export { alphabetIntervalLabelOverflowHide } from './alphabet-interval-label-overflow-hide';
export { alphabetIntervalLabelContrastReverse } from './alphabet-interval-label-contrast-reverse';
Expand Down
12 changes: 10 additions & 2 deletions src/shape/interval/color.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Path, Rect } from '@antv/g';
import { arc } from 'd3-shape';
import { arc, line, curveLinearClosed } from 'd3-shape';
import { Vector2, ShapeComponent as SC } from '../../runtime';
import { isPolar, isHelix, isTranspose } from '../../utils/coordinate';
import { select } from '../../utils/selection';
Expand Down Expand Up @@ -40,7 +40,7 @@ export function rect(
if (!isPolar(coordinate) && !isHelix(coordinate)) {
const tpShape = !!isTranspose(coordinate);

const [p0, , p2] = tpShape ? reorder(points) : points;
const [p0, p1, p2, p3] = tpShape ? reorder(points) : points;
const [x, y] = p0;
const [width, height] = sub(p2, p0);
// Deal with width or height is negative.
Expand All @@ -52,7 +52,15 @@ export function rect(
const finalY = absY + insetTop;
const finalWidth = absWidth - (insetLeft + insetRight);
const finalHeight = absHeight - (insetTop + insetBottom);
const { shape } = value;

if (shape === 'funnel' || shape === 'pyramid') {
const b = line().curve(curveLinearClosed)([p0, p1, p2, p3]);
return select(new Path({}))
.style('path', b)
.call(applyStyle, rest)
.node();
}
return select(new Rect({}))
.style('x', finalX)
.style('y', finalY)
Expand Down

0 comments on commit 3834599

Please sign in to comment.