From 6a48be848b8c71ad68d697f78d9945391903b113 Mon Sep 17 00:00:00 2001 From: sbosse Date: Mon, 21 Jul 2025 23:41:41 +0200 Subject: [PATCH] Mon 21 Jul 22:43:21 CEST 2025 --- .../src/js/layout/mxCompositeLayout.js | 101 ++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 js/ui/mxgraph/src/js/layout/mxCompositeLayout.js diff --git a/js/ui/mxgraph/src/js/layout/mxCompositeLayout.js b/js/ui/mxgraph/src/js/layout/mxCompositeLayout.js new file mode 100644 index 0000000..8e3e116 --- /dev/null +++ b/js/ui/mxgraph/src/js/layout/mxCompositeLayout.js @@ -0,0 +1,101 @@ +/** + * Copyright (c) 2006-2015, JGraph Ltd + * Copyright (c) 2006-2015, Gaudenz Alder + */ +/** + * Class: mxCompositeLayout + * + * Allows to compose multiple layouts into a single layout. The master layout + * is the layout that handles move operations if another layout than the first + * element in should be used. The layout is not executed as + * the code assumes that it is part of . + * + * Example: + * (code) + * var first = new mxFastOrganicLayout(graph); + * var second = new mxParallelEdgeLayout(graph); + * var layout = new mxCompositeLayout(graph, [first, second], first); + * layout.execute(graph.getDefaultParent()); + * (end) + * + * Constructor: mxCompositeLayout + * + * Constructs a new layout using the given layouts. The graph instance is + * required for creating the transaction that contains all layouts. + * + * Arguments: + * + * graph - Reference to the enclosing . + * layouts - Array of . + * master - Optional layout that handles moves. If no layout is given then + * the first layout of the above array is used to handle moves. + */ +function mxCompositeLayout(graph, layouts, master) +{ + mxGraphLayout.call(this, graph); + this.layouts = layouts; + this.master = master; +}; + +/** + * Extends mxGraphLayout. + */ +mxCompositeLayout.prototype = new mxGraphLayout(); +mxCompositeLayout.prototype.constructor = mxCompositeLayout; + +/** + * Variable: layouts + * + * Holds the array of that this layout contains. + */ +mxCompositeLayout.prototype.layouts = null; + +/** + * Variable: layouts + * + * Reference to the that handles moves. If this is null + * then the first layout in is used. + */ +mxCompositeLayout.prototype.master = null; + +/** + * Function: moveCell + * + * Implements by calling move on or the first + * layout in . + */ +mxCompositeLayout.prototype.moveCell = function(cell, x, y) +{ + if (this.master != null) + { + this.master.move.apply(this.master, arguments); + } + else + { + this.layouts[0].move.apply(this.layouts[0], arguments); + } +}; + +/** + * Function: execute + * + * Implements by executing all in a + * single transaction. + */ +mxCompositeLayout.prototype.execute = function(parent) +{ + var model = this.graph.getModel(); + + model.beginUpdate(); + try + { + for (var i = 0; i < this.layouts.length; i++) + { + this.layouts[i].execute.apply(this.layouts[i], arguments); + } + } + finally + { + model.endUpdate(); + } +};