Closed kumilingus closed 4 months ago
The PR aim to improve the current transformation API.
Remove outdated method:
origin
setOrigin()
rotate()
It introduces a new transform event which is triggered after both scale and translate are finished.
transform
scale
translate
It allows passing custom data along with transformation events (similarly to mvc.Events).
mvc.Events
scale(sx, sy, [data])
translate(tx, ty, [data])
matrix(matrix, [data])
paper.on('scale', (sx, sy, data) => console.log(sx, sy, data.foo)); paper.on('translate', (tx, ty, data) => console.log(tx, ty, data.foo)); paper.on('transform', (matrix, data) => console.log(matrix, data.foo)); paper.matrix({ a: 2, b: 0, c: 0, d: 2, e: 10, f: 10 }, { foo: 'bar' }); // will trigger all events
resize
paper.on('resize', (width, height, data) => console.log(width, height, data.foo)); paper.setDimensions(100, 200, { foo: 'bar' });
scaleUniformAtPoint(scale, { x, y }, [data])
scale()
dia.Paper.prototype.options.origin
Note that passing origin to the dia.Paper constructor had no effect in version 3.7. If you read the values of origin from the paper options, use paper.translate() (or paper.matrix()) instead.
dia.Paper
paper.translate()
paper.matrix()
Before:
const { x, y } = paper.option.origin;
Now:
const { tx: x, ty: y } = paper.translate();
paper.on('scale', (sx, sy, ox, oy) => {});
paper.on('scale', (sx, sy, data) => { const { tx: ox, ty: oy } = paper.translate(); });
dia.Paper.prototype.setOrigin
paper.setOrigin(100, 200);
paper.translate(100, 200);
// Zoom at center of the paper const center = paper.getArea.center(); paper.translate(0,0); paper.scale(zoomLevel, zoomLevel, center.x, center.y);
// Zoom at center of the paper const center = paper.getArea.center(); paper.scaleUniformAtPoint(zoomLevel, center);
Paper panning and zooming can be implemented as simple as shown below:
paper.on('paper:pinch', function(evt, x, y, sx) { const { sx: sx0 } = paper.scale(); paper.scaleUniformAtPoint(sx0 * sx, { x, y }); }); paper.on('paper:pan', function(evt, tx, ty) { evt.preventDefault(); const { tx: tx0, ty: ty0 } = paper.translate(); paper.translate(tx0 - tx, ty0 - ty); });
Description
The PR aim to improve the current transformation API.
Remove outdated method:
origin
option removedsetOrigin()
method removedrotate()
(experimental) method removedIt introduces a new
transform
event which is triggered after bothscale
andtranslate
are finished.It allows passing custom data along with transformation events (similarly to
mvc.Events
).scale(sx, sy, [data])
translate(tx, ty, [data])
matrix(matrix, [data])
resize
eventscaleUniformAtPoint(scale, { x, y }, [data])
scale()
no longer accepts scaling originscale
into account) as per https://github.com/clientIO/joint/pull/1375Migration guide
dia.Paper.prototype.options.origin
option removedNote that passing
origin
to thedia.Paper
constructor had no effect in version 3.7. If you read the values of origin from the paper options, usepaper.translate()
(orpaper.matrix()
) instead.Before:
Now:
Paper
scale
event handler arguments changedBefore:
Now:
dia.Paper.prototype.setOrigin
option removedBefore:
Now:
scale()
no longer accepts scaling originBefore:
Now:
Paper panning and zooming can be implemented as simple as shown below: