Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: update the position of lineXY with arrow #6442

Merged
merged 4 commits into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions __tests__/bugfix/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { issue6396 } from './issue-6396.spec';
85 changes: 85 additions & 0 deletions __tests__/bugfix/issue-6396.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import { Chart } from '../../src';

export function issue6396(context) {
const { container, canvas } = context;

const chart = new Chart({
container: container,
canvas,
autoFit: true,
});

let i = 1;

chart.data([
264, 417, 438, 887, 309, 397, 550, 575, 563, 430, 525, 592, 492, 467, 513,
546, 983, 340, 539, 243, 226, 192,
]);
chart.animate(false);

chart
.interval()
.encode('x', (_, idx) => idx)
.encode('y', (d) => d)
.axis(false);

const lineY = chart
.lineY()
.style('stroke', 'red')
.style('lineDash', [2, 2])
.style('arrow', true);

const lineY1 = chart
.lineY()
.style('stroke', 'green')
.style('lineDash', [2, 2])
.style('arrow', true);

lineY.data([i * 100]).label([
{
text: `value = ${i * 100}`,
position: 'right',
dx: -10,
textBaseline: 'bottom',
},
]);

lineY1.data([i * 200]).label([
{
text: `value = ${i * 200}`,
position: 'right',
dx: -10,
textBaseline: 'bottom',
},
]);

chart.interaction('tooltip', {
render: (e, { title, items }) => items[0].value,
});

const intervalId = setInterval(() => {
i++;
lineY.data([i * 100]).label([
{
text: `value = ${i * 100}`,
position: 'right',
dx: -10,
textBaseline: 'bottom',
},
]);
lineY1.data([i * 200]).label([
{
text: `value = ${i * 200}`,
position: 'right',
dx: -10,
textBaseline: 'bottom',
},
]);
chart.render();
}, 1000 * 5);
const finished = chart.render();
return {
chart,
finished,
};
}
2 changes: 2 additions & 0 deletions __tests__/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ import * as interactions from './plots/interaction';
import * as animations from './plots/animation';
import * as tooltips from './plots/tooltip';
import * as apis from './plots/api';
import * as bugfix from './bugfix';

const tests = {
...createSpecRender(namespace(statics, 'static')),
...createSpecRender(namespace(tooltips, 'tooltip')),
...createSpecRender(namespace(interactions, 'interaction')),
...createSpecRender(namespace(animations, 'animation')),
...createAPIRender(namespace(apis, 'api')),
...createAPIRender(namespace(bugfix, 'bugfix')),
};

const renderers = {
Expand Down
16 changes: 14 additions & 2 deletions src/animation/morphing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
Path,
Shape,
} from '@antv/g';
import { get } from '@antv/util';
import { AnimationComponent as AC } from '../runtime';
import { copyAttributes } from '../utils/helper';
import { Animation } from './types';
Expand Down Expand Up @@ -158,6 +159,15 @@ function shape2path(shape: DisplayObject): string {
if (hasSubPath(path)) return;
return path;
}
// Check if the path has a markerEnd | markerStart
function isHasMarker(shape: DisplayObject): boolean {
hustcc marked this conversation as resolved.
Show resolved Hide resolved
const { nodeName } = shape;
if (nodeName === 'path') {
const attributes = get(shape, 'attributes');
return attributes.markerEnd || attributes.markerStart;
}
return false;
}

function oneToOne(
shape: DisplayObject,
Expand All @@ -174,8 +184,10 @@ function oneToOne(
const toPath = shape2path(to);
const isSameNodes = fromName === toName && fromName !== 'path';
const hasNonPathNode = fromPath === undefined || toPath === undefined;
if (isSameNodes || hasNonPathNode) return shapeToShape(from, to, timeEffect);

// Path with mark can not use animate like ordinary path.
const isPathWithMarker = isHasMarker(from) || isHasMarker(to);
if (isSameNodes || hasNonPathNode || isPathWithMarker)
return shapeToShape(from, to, timeEffect);
const pathShape = maybePath(shape, fromPath);
// Convert Path will take transform, anchor, etc into account,
// so there is no need to specify these attributes in keyframes.
Expand Down
Loading