Skip to content

JavaScript API

thednp edited this page Jan 7, 2021 · 25 revisions

Instance Methods

The SVGPathCommander construct comes with instance methods you can call, intuitive and easy to use:

  • .toAbsolute() - will convert all path commands of a SVGPathElement with or without sub-path to absolute values; the absolute path is used by all other tools for specific processing;
  • .toRelative() - will convert all path commands of a shape with or without sub-path to relative values;
  • .reverse(onlySubpath) - will reverse the shape draw direction by changing the order of all path segments and their coordinates; when the onlySubpath option is true, it will only reverse the draw direction of subpath shapes
  • .normalize() - will convert path command values to absolute and convert shorthand S, T, H, V to C, Q and L respectivelly;
  • .optimize() - will compute two pathArrays one with absolute and the other with relative values, then update the pathArray segments using the values that convert to shortest string;
  • .transform(transformObject) - will normalize all path commands and apply a 2D transformation matrix to all path commands;
  • .flipX() - will call the above transform() method to apply a 180deg rotation on the X axis;
  • .flipY() - will call the above transform() method to apply a 180deg rotation on the Y axis;
  • .toString() - will return the pathString of the current pathArray stored in the instance.segments object.
Clone this wiki locally