jointjs
Version:
JavaScript diagramming library
20 lines (17 loc) • 1.3 kB
HTML
<p><i>alias:</i> <b>refPoints</b></p>
<p>Set the <code>points</code> attribute of the <code><polygon></code> or <code><polyline></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 not 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 subelement is translated so that this gap disappears. The rendered subelement then fits perfectly into the reference element's bounding box.</p>
<pre><code>var Polygon = joint.dia.Element.define('examples.Polygon', {
attrs: {
polygon: {
refPoints: '10,10 30,10 30,30', // points offset of 10,10 will be discarded
fill: 'red',
stroke: 'black'
}
}
}, {
markup: 'polygon'
});
var p = (new Polygon()).resize(40, 40).addTo(graph);
// the rendered polygon's `points` attribute will be '0,0 40,0 40,40'
// can be obtained by `p.findView(paper).vel.findOne('polygon').attr('d');`</code></pre>