Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export const getSpline = (points: IPoint[]) => {
const data: number[] = [];
if (points.length < 2) {
console.warn(`point length must largn than 2, now it's ${points.length}`);
}
for (const point of points) {
const { x, y } = point;
data.push(x);
data.push(y);
}
const spliePath = catmullRom2Bezier(data);
spliePath.unshift(['M', points[0].x, points[0].y]);
return spliePath;
};
getLinePath() {
const crp = this.get('crp');
const axisStart = this.get('axisStart');
const path = pathUtil.catmullRom2Bezier(crp);
path.unshift([ 'M', axisStart.x, axisStart.y ]);
return path;
}
const pathMetaParser = _.memoize((path: string) => {
const segments = pathUtil.parsePathString(path);
const nums = _.flatten(segments).filter((num) => _.isNumber(num));
return {
range: Math.max.apply(null, nums) - Math.min.apply(null, nums),
segments,
};
});
parsePath(path: string, isLineToArc: boolean = true): PathCommand[] {
const coordinate = this.coordinate;
let parsedPath = parsePathString(path);
if (coordinate.isPolar && isLineToArc !== false) {
parsedPath = convertPolarPath(coordinate, parsedPath);
} else {
parsedPath = convertNormalPath(coordinate, parsedPath);
}
return parsedPath;
},
/**
function pathOut(shape, animateCfg) {
if (shape.get('type') !== 'path') {
return;
}
const path = pathUtil.path2Curve(shape.attr('path'));
const endState = {
path: [path[0]],
};
animateCfg.callback = () => shape.remove();
doAnimation(shape, endState, animateCfg);
}
function pathIn(shape, animateCfg) {
if (shape.get('type') !== 'path') {
return;
}
const path = pathUtil.path2Curve(shape.attr('path'));
shape.attr('path', [path[0]]);
const endState = {
path,
};
doAnimation(shape, endState, animateCfg);
}