BATU
March 1, 2021, 10:08am
1
On the DrawCommandHandler.js align function is simple and efficient, below↓,
But can i align with location object ? not the whole node outer bound.
DrawCommandHandler.prototype.alignLeft = function() {
var diagram = this.diagram;
diagram.startTransaction("aligning left");
var minPosition = Infinity;
diagram.selection.each(function(current) {
if (current instanceof go.Link) return; // skips over go.Link
minPosition = Math.min(current.position.x, minPosition);
});
diagram.selection.each(function(current) {
if (current instanceof go.Link) return; // skips over go.Link
current.move(new go.Point(minPosition, current.position.y));
});
diagram.commitTransaction("aligning left");
};
walter
March 1, 2021, 1:52pm
2
diagram.startTransaction("aligning left");
var minLocation = Infinity;
diagram.selection.each(function(current) {
if (current instanceof go.Link) return; // skips over go.Link
minLocation = Math.min(current.location.x, minLocation);
});
diagram.selection.each(function(current) {
if (current instanceof go.Link) return; // skips over go.Link
current.moveTo(minLocation, current.location.y, true);
});
diagram.commitTransaction("aligning left");
BATU
March 2, 2021, 1:03am
3
Yes, good, this works when the Location spot is top left, but went Nodes have rotation it did not work,
but Ok, I will do it myself, more one thing, could you tell me how I get location object width ?
walter
March 2, 2021, 4:45am
4
Depends on which coordinate system you want the result to be in.
Maybe actualBounds .
https://gojs.net/latest/intro/sizing.html#MeasuredAndActualSizes
Or call getDocumentBounds .
GraphObject | GoJS API
BATU
March 2, 2021, 6:48am
5
thank you I will research it.