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: path elements are drawn incorrectly #1761

Merged
merged 2 commits into from
Aug 27, 2024
Merged
Changes from all commits
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
5 changes: 5 additions & 0 deletions .changeset/two-parrots-film.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@antv/g-plugin-canvas-path-generator': patch
---

fix: `path` elements are drawn incorrectly after using `markerStartOffset` (#1760)
92 changes: 92 additions & 0 deletions demo/issues/issue-1760.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta
name="viewport"
content="width=device-width,user-scalable=no,initial-scale=1,shrink-to-fit=no"
/>
<title>issue-1760</title>
<style>
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}

html,
body {
height: 100vh;
}

#container {
width: 100%;
height: 100%;
}
</style>
</head>

<body>
<div id="container"></div>
<script
src="../../packages/g/dist/index.umd.min.js"
type="application/javascript"
></script>
<script
src="../../packages/g-canvas/dist/index.umd.min.js"
type="application/javascript"
></script>
<script type="module">
// @see https://github.com/antvis/G/issues/1760
const { Canvas, Path, Line, Canvas2D } = window.G;

const canvasRenderer = new Canvas2D.Renderer();

const canvas = new Canvas({
container: 'container',
width: 600,
height: 500,
renderer: canvasRenderer,
});

const arrowMarker = new Path({
style: {
d: 'M 10,10 L -10,0 L 10,-10 Z',
stroke: '#1890FF',
transformOrigin: 'center',
},
});

const path = new Path({
style: {
lineWidth: 1,
stroke: '#54BECC',
// d: 'M 0,40 L 100,100',
d: 'M 10,100 L 100,100',
markerStart: arrowMarker,
markerStartOffset: 30,
markerEnd: arrowMarker,
markerEndOffset: 30,
},
});

const line = new Line({
style: {
x1: 10,
y1: 150,
x2: 100,
y2: 150,
lineWidth: 1,
stroke: '#54BECC',
markerStart: arrowMarker,
markerStartOffset: 30,
markerEnd: arrowMarker,
markerEndOffset: 30,
},
});

canvas.appendChild(path);
canvas.appendChild(line);
</script>
</body>
</html>
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -71,7 +71,6 @@
"get-pixels": "3.3.3",
"git-contributor": "~1.0.11",
"hammerjs": "^2.0.8",
"http-server": "^14.1.1",
"husky": "^7.0.4",
"is-ci": "2.0.0",
"jest": "^29.7.0",
1 change: 0 additions & 1 deletion packages/g-plugin-canvas-path-generator/src/paths/Path.ts
Original file line number Diff line number Diff line change
@@ -54,7 +54,6 @@ export function generatePath(
// Use start marker offset
if (useStartOffset) {
context.moveTo(params[1] + startOffsetX, params[2] + startOffsetY);
context.lineTo(params[1], params[2]);
} else {
context.moveTo(params[1], params[2]);
}