Skip to content

Commit

Permalink
Merge pull request #223 from antvis/feat-path-typedefine
Browse files Browse the repository at this point in the history
feat: add path array type define
  • Loading branch information
诸岳 authored Oct 22, 2019
2 parents 688057a + 5ef5bf7 commit ce23774
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
16 changes: 16 additions & 0 deletions packages/g-base/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,3 +163,19 @@ export type Animation = AnimateCfg & {
_paused?: boolean;
_pauseTime?: number;
};

type A = ['a' | 'A', number, number, number, number, number, number, number];
type C = ['c' | 'C', number, number, number, number, number, number];
type O = ['o' | 'O', number, number];
type H = ['h' | 'h', number];
type L = ['l' | 'l', number, number];
type M = ['m' | 'm', number, number];
type R = ['r' | 'R', number, number, number, number];
type Q = ['q' | 'Q', number, number, number, number];
type S = ['s' | 'S', number, number, number, number, number, number, number];
type T = ['t' | 'T', number, number];
type V = ['v' | 'V', number];
type U = ['u' | 'U', number, number, number];
type Z = ['z' | 'Z'];

export type PathCommand = A | C | O | H | L | M | R | Q | S | T | V | U | Z;
7 changes: 4 additions & 3 deletions packages/g-base/src/util/path.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { each, isArray } from '@antv/util';
import { PathCommand } from '../types';

const SPACES =
'\x09\x0a\x0b\x0c\x0d\x20\xa0\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000\u2028\u2029';
Expand All @@ -9,13 +10,13 @@ const PATH_COMMAND = new RegExp(
const PATH_VALUES = new RegExp(`(-?\\d*\\.?\\d*(?:e[\\-+]?\\d+)?)[${SPACES}]*,?[${SPACES}]*`, 'ig');

// Parse given path string into an array of arrays of path segments
const parsePathString = function(pathString) {
const parsePathString = function(pathString: string): PathCommand[] {
if (!pathString) {
return null;
}

if (typeof pathString === typeof []) {
return pathString;
if (isArray(pathString)) {
return (pathString as unknown) as PathCommand[];
}
const paramCounts = {
a: 7,
Expand Down

0 comments on commit ce23774

Please sign in to comment.