跳到主要内容

Adding snippets

代码片段 should be stored in the snippets key of the object passed to your part's draft method. The constructor for snippets is available in the 代码片段 key. You can destructure them for easy access.

function draftPart = ({ 
Point,
Path,
paths,
Snippet,
snippets,
part
}) {

snippets.logo = new Snippet('logo', new Point(50,50))
.attr('data-scale', 0.5)
.attr('data-rotate', 180)

// prevent clipping
paths.demo = new Path()
.move(new Point(0,0))
.move(new Point(100,100))

return part
}

An example of adding a snippet

You can scale and rotate a snippet by setting the data-scale and data-rotate attributes respectively.

  • data-scale : Either a single scale factor, or a set of 2 scale factors for the X and Y axis respectively. See the SVG scale transform for details.
  • data-rotate: A rotation in degrees. The center of the rotation will be the snippet's anchor point
提示

See Using attributes for details on how to set attributes.