UNPKG

jointjs

Version:

JavaScript diagramming library

19 lines (16 loc) 1.19 kB
<p>Set the <code>points</code> attribute of the <code>&lt;polygon&gt;</code> or <code>&lt;polyline&gt;</code> subelement relatively to the dimensions and position of the element referenced by the selector in the <code>ref</code> attribute. The <code>refPoints</code> are scaled so that the subelement's dimensions match the reference element's dimensions, and translated so that the their origin matches the origin of the reference element.</p> <p>The original points offset is preserved. This means that if the top-left corner of the <code>refPoints</code> bounding box does not lie at <code>0,0</code>, the gap between the points and origin is preserved in the rendered shape, as well.</p> <pre><code>var Polygon = joint.dia.Element.define('examples.Polygon', { attrs: { polygon: { refPoints: '10,10 30,10 30,30', // points offset is 10,10 fill: 'red', stroke: 'black' } } }, { markup: 'polygon' }); var p = (new Polygon()).resize(40, 40).addTo(graph); // the rendered polygon's `points` attribute will be '10,10 50,10 50,50' // can be obtained by `p.findView(paper).vel.findOne('polygon').attr('points');`</code></pre>