Skip to content

Commit

Permalink
Fix 634 (antvis#642)
Browse files Browse the repository at this point in the history
* fix: getPointAtLength failed on an empty path

* fix: add test case for antvis#634
  • Loading branch information
xiaoiver authored Oct 26, 2020
1 parent d02aa6c commit 26a8cc2
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/g-svg/src/shape/path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ class Path extends ShapeBase {
getPoint(ratio: number): Point {
const el = this.get('el');
const totalLength = this.getTotalLength();
// @see https://github.com/antvis/g/issues/634
if (totalLength === 0) {
return null;
}
const point = el ? el.getPointAtLength(ratio * totalLength) : null;
return point
? {
Expand Down
30 changes: 30 additions & 0 deletions packages/g-svg/tests/bugs/issue-634-spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const expect = require('chai').expect;
import Canvas from '../../../g-svg/src/canvas';
import Path from '../../../g-svg/src/shape/path';

const dom = document.createElement('div');
document.body.appendChild(dom);
dom.id = 'c1';

describe('#634', () => {
const canvas = new Canvas({
container: dom,
width: 400,
height: 400,
});

it('should get null point on an empty path', () => {
const path = new Path({
attrs: {
path: [
['M', 0, 0],
['L', 0, 0],
],
lineWidth: 1,
stroke: 'red',
},
});
canvas.add(path);
expect(path.getPoint(0)).eqls(null);
});
});
1 change: 1 addition & 0 deletions packages/g-svg/tests/mocha.opts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
--require source-map-support/register
--recursive
tests/unit
tests/bugs

0 comments on commit 26a8cc2

Please sign in to comment.