manual js syntax updates
parent
c5e7813b34
commit
a3b84ee3c9
|
@ -4,33 +4,9 @@
|
|||
*/
|
||||
|
||||
import mxDictionary from "FIXME";
|
||||
import mxPoint from "FIXME";
|
||||
|
||||
class mxCompactTreeLayout extends mxGraphLayout {
|
||||
/**
|
||||
* Class: mxCompactTreeLayout
|
||||
*
|
||||
* Extends <mxGraphLayout> to implement a compact tree (Moen) algorithm. This
|
||||
* layout is suitable for graphs that have no cycles (trees). Vertices that are
|
||||
* not connected to the tree will be ignored by this layout.
|
||||
*
|
||||
* Example:
|
||||
*
|
||||
* (code)
|
||||
* var layout = new mxCompactTreeLayout(graph);
|
||||
* layout.execute(graph.getDefaultParent());
|
||||
* (end)
|
||||
*
|
||||
* Constructor: mxCompactTreeLayout
|
||||
*
|
||||
* Constructs a new compact tree layout for the specified graph
|
||||
* and orientation.
|
||||
*/
|
||||
constructor(graph, horizontal, invert) {
|
||||
super(graph);
|
||||
this.horizontal = (horizontal != null) ? horizontal : true;
|
||||
this.invert = (invert != null) ? invert : false;
|
||||
};
|
||||
|
||||
/**
|
||||
* Variable: horizontal
|
||||
*
|
||||
|
@ -218,6 +194,31 @@ class mxCompactTreeLayout extends mxGraphLayout {
|
|||
*/
|
||||
node = null;
|
||||
|
||||
/**
|
||||
* Class: mxCompactTreeLayout
|
||||
*
|
||||
* Extends <mxGraphLayout> to implement a compact tree (Moen) algorithm. This
|
||||
* layout is suitable for graphs that have no cycles (trees). Vertices that are
|
||||
* not connected to the tree will be ignored by this layout.
|
||||
*
|
||||
* Example:
|
||||
*
|
||||
* (code)
|
||||
* var layout = new mxCompactTreeLayout(graph);
|
||||
* layout.execute(graph.getDefaultParent());
|
||||
* (end)
|
||||
*
|
||||
* Constructor: mxCompactTreeLayout
|
||||
*
|
||||
* Constructs a new compact tree layout for the specified graph
|
||||
* and orientation.
|
||||
*/
|
||||
constructor(graph, horizontal, invert) {
|
||||
super(graph);
|
||||
this.horizontal = (horizontal != null) ? horizontal : true;
|
||||
this.invert = (invert != null) ? invert : false;
|
||||
};
|
||||
|
||||
/**
|
||||
* Function: isVertexIgnored
|
||||
*
|
||||
|
|
|
@ -2,7 +2,101 @@
|
|||
* Copyright (c) 2006-2015, JGraph Ltd
|
||||
* Copyright (c) 2006-2015, Gaudenz Alder
|
||||
*/
|
||||
/**
|
||||
|
||||
class mxRadialTreeLayout extends mxCompactTreeLayout {
|
||||
/**
|
||||
* Variable: angleOffset
|
||||
*
|
||||
* The initial offset to compute the angle position.
|
||||
*/
|
||||
angleOffset = 0.5;
|
||||
|
||||
/**
|
||||
* Variable: rootx
|
||||
*
|
||||
* The X co-ordinate of the root cell
|
||||
*/
|
||||
rootx = 0;
|
||||
|
||||
/**
|
||||
* Variable: rooty
|
||||
*
|
||||
* The Y co-ordinate of the root cell
|
||||
*/
|
||||
rooty = 0;
|
||||
|
||||
/**
|
||||
* Variable: levelDistance
|
||||
*
|
||||
* Holds the levelDistance. Default is 120.
|
||||
*/
|
||||
levelDistance = 120;
|
||||
|
||||
/**
|
||||
* Variable: nodeDistance
|
||||
*
|
||||
* Holds the nodeDistance. Default is 10.
|
||||
*/
|
||||
nodeDistance = 10;
|
||||
|
||||
/**
|
||||
* Variable: autoRadius
|
||||
*
|
||||
* Specifies if the radios should be computed automatically
|
||||
*/
|
||||
autoRadius = false;
|
||||
|
||||
/**
|
||||
* Variable: sortEdges
|
||||
*
|
||||
* Specifies if edges should be sorted according to the order of their
|
||||
* opposite terminal cell in the model.
|
||||
*/
|
||||
sortEdges = false;
|
||||
|
||||
/**
|
||||
* Variable: rowMinX
|
||||
*
|
||||
* Array of leftmost x coordinate of each row
|
||||
*/
|
||||
rowMinX = [];
|
||||
|
||||
/**
|
||||
* Variable: rowMaxX
|
||||
*
|
||||
* Array of rightmost x coordinate of each row
|
||||
*/
|
||||
rowMaxX = [];
|
||||
|
||||
/**
|
||||
* Variable: rowMinCenX
|
||||
*
|
||||
* Array of x coordinate of leftmost vertex of each row
|
||||
*/
|
||||
rowMinCenX = [];
|
||||
|
||||
/**
|
||||
* Variable: rowMaxCenX
|
||||
*
|
||||
* Array of x coordinate of rightmost vertex of each row
|
||||
*/
|
||||
rowMaxCenX = [];
|
||||
|
||||
/**
|
||||
* Variable: rowRadi
|
||||
*
|
||||
* Array of y deltas of each row behind root vertex, also the radius in the tree
|
||||
*/
|
||||
rowRadi = [];
|
||||
|
||||
/**
|
||||
* Variable: row
|
||||
*
|
||||
* Array of vertices on each row
|
||||
*/
|
||||
row = [];
|
||||
|
||||
/**
|
||||
* Class: mxRadialTreeLayout
|
||||
*
|
||||
* Extends <mxGraphLayout> to implement a radial tree algorithm. This
|
||||
|
@ -20,109 +114,11 @@
|
|||
*
|
||||
* Constructs a new radial tree layout for the specified graph
|
||||
*/
|
||||
function mxRadialTreeLayout(graph)
|
||||
{
|
||||
mxCompactTreeLayout.call(this, graph , false);
|
||||
};
|
||||
constructor(graph) {
|
||||
super(graph, false);
|
||||
};
|
||||
|
||||
/**
|
||||
* Extends mxGraphLayout.
|
||||
*/
|
||||
mxUtils.extend(mxRadialTreeLayout, mxCompactTreeLayout);
|
||||
|
||||
/**
|
||||
* Variable: angleOffset
|
||||
*
|
||||
* The initial offset to compute the angle position.
|
||||
*/
|
||||
angleOffset = 0.5;
|
||||
|
||||
/**
|
||||
* Variable: rootx
|
||||
*
|
||||
* The X co-ordinate of the root cell
|
||||
*/
|
||||
rootx = 0;
|
||||
|
||||
/**
|
||||
* Variable: rooty
|
||||
*
|
||||
* The Y co-ordinate of the root cell
|
||||
*/
|
||||
rooty = 0;
|
||||
|
||||
/**
|
||||
* Variable: levelDistance
|
||||
*
|
||||
* Holds the levelDistance. Default is 120.
|
||||
*/
|
||||
levelDistance = 120;
|
||||
|
||||
/**
|
||||
* Variable: nodeDistance
|
||||
*
|
||||
* Holds the nodeDistance. Default is 10.
|
||||
*/
|
||||
nodeDistance = 10;
|
||||
|
||||
/**
|
||||
* Variable: autoRadius
|
||||
*
|
||||
* Specifies if the radios should be computed automatically
|
||||
*/
|
||||
autoRadius = false;
|
||||
|
||||
/**
|
||||
* Variable: sortEdges
|
||||
*
|
||||
* Specifies if edges should be sorted according to the order of their
|
||||
* opposite terminal cell in the model.
|
||||
*/
|
||||
sortEdges = false;
|
||||
|
||||
/**
|
||||
* Variable: rowMinX
|
||||
*
|
||||
* Array of leftmost x coordinate of each row
|
||||
*/
|
||||
rowMinX = [];
|
||||
|
||||
/**
|
||||
* Variable: rowMaxX
|
||||
*
|
||||
* Array of rightmost x coordinate of each row
|
||||
*/
|
||||
rowMaxX = [];
|
||||
|
||||
/**
|
||||
* Variable: rowMinCenX
|
||||
*
|
||||
* Array of x coordinate of leftmost vertex of each row
|
||||
*/
|
||||
rowMinCenX = [];
|
||||
|
||||
/**
|
||||
* Variable: rowMaxCenX
|
||||
*
|
||||
* Array of x coordinate of rightmost vertex of each row
|
||||
*/
|
||||
rowMaxCenX = [];
|
||||
|
||||
/**
|
||||
* Variable: rowRadi
|
||||
*
|
||||
* Array of y deltas of each row behind root vertex, also the radius in the tree
|
||||
*/
|
||||
rowRadi = [];
|
||||
|
||||
/**
|
||||
* Variable: row
|
||||
*
|
||||
* Array of vertices on each row
|
||||
*/
|
||||
row = [];
|
||||
|
||||
/**
|
||||
/**
|
||||
* Function: isVertexIgnored
|
||||
*
|
||||
* Returns a boolean indicating if the given <mxCell> should be ignored as a
|
||||
|
@ -132,13 +128,12 @@ row = [];
|
|||
*
|
||||
* vertex - <mxCell> whose ignored state should be returned.
|
||||
*/
|
||||
isVertexIgnored = (vertex)=>
|
||||
{
|
||||
return isVertexIgnored.apply(this, arguments) ||
|
||||
this.graph.getConnections(vertex).length == 0;
|
||||
};
|
||||
isVertexIgnored = (vertex) => {
|
||||
return super.isVertexIgnored(vertex) ||
|
||||
this.graph.getConnections(vertex).length === 0;
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* Function: execute
|
||||
*
|
||||
* Implements <mxGraphLayout.execute>.
|
||||
|
@ -152,8 +147,7 @@ isVertexIgnored = (vertex)=>
|
|||
* parent - <mxCell> whose children should be laid out.
|
||||
* root - Optional <mxCell> that will be used as the root of the tree.
|
||||
*/
|
||||
execute = (parent, root)=>
|
||||
{
|
||||
execute = (parent, root) => {
|
||||
this.parent = parent;
|
||||
|
||||
this.useBoundingBox = false;
|
||||
|
@ -168,8 +162,7 @@ execute = (parent, root)=>
|
|||
this.centerY = rootBounds.y + rootBounds.height / 2;
|
||||
|
||||
// Calculate the bounds of the involved vertices directly from the values set in the compact tree
|
||||
for (var vertex in this.visited)
|
||||
{
|
||||
for (var vertex in this.visited) {
|
||||
var vertexBounds = this.getVertexBounds(this.visited[vertex]);
|
||||
bounds = (bounds != null) ? bounds : vertexBounds.clone();
|
||||
bounds.add(vertexBounds);
|
||||
|
@ -181,24 +174,21 @@ execute = (parent, root)=>
|
|||
var maxRightGrad = 0;
|
||||
|
||||
// Find the steepest left and right gradients
|
||||
for (var i = 0; i < this.row.length; i++)
|
||||
{
|
||||
for (var i = 0; i < this.row.length; i++) {
|
||||
var leftGrad = (this.centerX - this.rowMinX[i] - this.nodeDistance) / this.rowRadi[i];
|
||||
var rightGrad = (this.rowMaxX[i] - this.centerX - this.nodeDistance) / this.rowRadi[i];
|
||||
|
||||
maxLeftGrad = Math.max (maxLeftGrad, leftGrad);
|
||||
maxRightGrad = Math.max (maxRightGrad, rightGrad);
|
||||
maxLeftGrad = Math.max(maxLeftGrad, leftGrad);
|
||||
maxRightGrad = Math.max(maxRightGrad, rightGrad);
|
||||
}
|
||||
|
||||
// Extend out row so they meet the maximum gradient and convert to polar co-ords
|
||||
for (var i = 0; i < this.row.length; i++)
|
||||
{
|
||||
for (var i = 0; i < this.row.length; i++) {
|
||||
var xLeftLimit = this.centerX - this.nodeDistance - maxLeftGrad * this.rowRadi[i];
|
||||
var xRightLimit = this.centerX + this.nodeDistance + maxRightGrad * this.rowRadi[i];
|
||||
var fullWidth = xRightLimit - xLeftLimit;
|
||||
|
||||
for (var j = 0; j < this.row[i].length; j ++)
|
||||
{
|
||||
for (var j = 0; j < this.row[i].length; j++) {
|
||||
var row = this.row[i];
|
||||
var node = row[j];
|
||||
var vertexBounds = this.getVertexBounds(node.cell);
|
||||
|
@ -209,47 +199,38 @@ execute = (parent, root)=>
|
|||
}
|
||||
|
||||
// Post-process from outside inwards to try to align parents with children
|
||||
for (var i = this.row.length - 2; i >= 0; i--)
|
||||
{
|
||||
for (var i = this.row.length - 2; i >= 0; i--) {
|
||||
var row = this.row[i];
|
||||
|
||||
for (var j = 0; j < row.length; j++)
|
||||
{
|
||||
for (var j = 0; j < row.length; j++) {
|
||||
var node = row[j];
|
||||
var child = node.child;
|
||||
var counter = 0;
|
||||
var totalTheta = 0;
|
||||
|
||||
while (child != null)
|
||||
{
|
||||
while (child != null) {
|
||||
totalTheta += child.theta;
|
||||
counter++;
|
||||
child = child.next;
|
||||
}
|
||||
|
||||
if (counter > 0)
|
||||
{
|
||||
if (counter > 0) {
|
||||
var averTheta = totalTheta / counter;
|
||||
|
||||
if (averTheta > node.theta && j < row.length - 1)
|
||||
{
|
||||
var nextTheta = row[j+1].theta;
|
||||
node.theta = Math.min (averTheta, nextTheta - Math.PI/10);
|
||||
}
|
||||
else if (averTheta < node.theta && j > 0 )
|
||||
{
|
||||
var lastTheta = row[j-1].theta;
|
||||
node.theta = Math.max (averTheta, lastTheta + Math.PI/10);
|
||||
if (averTheta > node.theta && j < row.length - 1) {
|
||||
var nextTheta = row[j + 1].theta;
|
||||
node.theta = Math.min(averTheta, nextTheta - Math.PI / 10);
|
||||
} else if (averTheta < node.theta && j > 0) {
|
||||
var lastTheta = row[j - 1].theta;
|
||||
node.theta = Math.max(averTheta, lastTheta + Math.PI / 10);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Set locations
|
||||
for (var i = 0; i < this.row.length; i++)
|
||||
{
|
||||
for (var j = 0; j < this.row[i].length; j ++)
|
||||
{
|
||||
for (var i = 0; i < this.row.length; i++) {
|
||||
for (var j = 0; j < this.row[i].length; j++) {
|
||||
var row = this.row[i];
|
||||
var node = row[j];
|
||||
var vertexBounds = this.getVertexBounds(node.cell);
|
||||
|
@ -258,9 +239,9 @@ execute = (parent, root)=>
|
|||
this.centerY - vertexBounds.height / 2 + this.rowRadi[i] * Math.sin(node.theta));
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* Function: calcRowDims
|
||||
*
|
||||
* Recursive function to calculate the dimensions of each row
|
||||
|
@ -270,10 +251,8 @@ execute = (parent, root)=>
|
|||
* row - Array of internal nodes, the children of which are to be processed.
|
||||
* rowNum - Integer indicating which row is being processed.
|
||||
*/
|
||||
calcRowDims = (row, rowNum)=>
|
||||
{
|
||||
if (row == null || row.length == 0)
|
||||
{
|
||||
calcRowDims = (row, rowNum) => {
|
||||
if (row == null || row.length == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -286,12 +265,10 @@ calcRowDims = (row, rowNum)=>
|
|||
|
||||
var rowHasChildren = false;
|
||||
|
||||
for (var i = 0; i < row.length; i++)
|
||||
{
|
||||
for (var i = 0; i < row.length; i++) {
|
||||
var child = row[i] != null ? row[i].child : null;
|
||||
|
||||
while (child != null)
|
||||
{
|
||||
while (child != null) {
|
||||
var cell = child.cell;
|
||||
var vertexBounds = this.getVertexBounds(cell);
|
||||
|
||||
|
@ -301,8 +278,7 @@ calcRowDims = (row, rowNum)=>
|
|||
this.rowMaxCenX[rowNum] = Math.max(vertexBounds.x + vertexBounds.width / 2, this.rowMaxCenX[rowNum]);
|
||||
this.rowRadi[rowNum] = vertexBounds.y - this.getVertexBounds(this.root).y;
|
||||
|
||||
if (child.child != null)
|
||||
{
|
||||
if (child.child != null) {
|
||||
rowHasChildren = true;
|
||||
}
|
||||
|
||||
|
@ -311,8 +287,10 @@ calcRowDims = (row, rowNum)=>
|
|||
}
|
||||
}
|
||||
|
||||
if (rowHasChildren)
|
||||
{
|
||||
if (rowHasChildren) {
|
||||
this.calcRowDims(this.row[rowNum], rowNum + 1);
|
||||
}
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
export default mxRadialTreeLayout;
|
||||
|
|
|
@ -2,7 +2,140 @@
|
|||
* Copyright (c) 2006-2015, JGraph Ltd
|
||||
* Copyright (c) 2006-2015, Gaudenz Alder
|
||||
*/
|
||||
/**
|
||||
|
||||
class mxStackLayout extends mxGraphLayout {
|
||||
/**
|
||||
* Variable: horizontal
|
||||
*
|
||||
* Specifies the orientation of the layout. Default is true.
|
||||
*/
|
||||
horizontal = null;
|
||||
|
||||
/**
|
||||
* Variable: spacing
|
||||
*
|
||||
* Specifies the spacing between the cells. Default is 0.
|
||||
*/
|
||||
spacing = null;
|
||||
|
||||
/**
|
||||
* Variable: x0
|
||||
*
|
||||
* Specifies the horizontal origin of the layout. Default is 0.
|
||||
*/
|
||||
x0 = null;
|
||||
|
||||
/**
|
||||
* Variable: y0
|
||||
*
|
||||
* Specifies the vertical origin of the layout. Default is 0.
|
||||
*/
|
||||
y0 = null;
|
||||
|
||||
/**
|
||||
* Variable: border
|
||||
*
|
||||
* Border to be added if fill is true. Default is 0.
|
||||
*/
|
||||
border = 0;
|
||||
|
||||
/**
|
||||
* Variable: marginTop
|
||||
*
|
||||
* Top margin for the child area. Default is 0.
|
||||
*/
|
||||
marginTop = 0;
|
||||
|
||||
/**
|
||||
* Variable: marginLeft
|
||||
*
|
||||
* Top margin for the child area. Default is 0.
|
||||
*/
|
||||
marginLeft = 0;
|
||||
|
||||
/**
|
||||
* Variable: marginRight
|
||||
*
|
||||
* Top margin for the child area. Default is 0.
|
||||
*/
|
||||
marginRight = 0;
|
||||
|
||||
/**
|
||||
* Variable: marginBottom
|
||||
*
|
||||
* Top margin for the child area. Default is 0.
|
||||
*/
|
||||
marginBottom = 0;
|
||||
|
||||
/**
|
||||
* Variable: keepFirstLocation
|
||||
*
|
||||
* Boolean indicating if the location of the first cell should be
|
||||
* kept, that is, it will not be moved to x0 or y0. Default is false.
|
||||
*/
|
||||
keepFirstLocation = false;
|
||||
|
||||
/**
|
||||
* Variable: fill
|
||||
*
|
||||
* Boolean indicating if dimension should be changed to fill out the parent
|
||||
* cell. Default is false.
|
||||
*/
|
||||
fill = false;
|
||||
|
||||
/**
|
||||
* Variable: resizeParent
|
||||
*
|
||||
* If the parent should be resized to match the width/height of the
|
||||
* stack. Default is false.
|
||||
*/
|
||||
resizeParent = false;
|
||||
|
||||
/**
|
||||
* Variable: resizeParentMax
|
||||
*
|
||||
* Use maximum of existing value and new value for resize of parent.
|
||||
* Default is false.
|
||||
*/
|
||||
resizeParentMax = false;
|
||||
|
||||
/**
|
||||
* Variable: resizeLast
|
||||
*
|
||||
* If the last element should be resized to fill out the parent. Default is
|
||||
* false. If <resizeParent> is true then this is ignored.
|
||||
*/
|
||||
resizeLast = false;
|
||||
|
||||
/**
|
||||
* Variable: wrap
|
||||
*
|
||||
* Value at which a new column or row should be created. Default is null.
|
||||
*/
|
||||
wrap = null;
|
||||
|
||||
/**
|
||||
* Variable: borderCollapse
|
||||
*
|
||||
* If the strokeWidth should be ignored. Default is true.
|
||||
*/
|
||||
borderCollapse = true;
|
||||
|
||||
/**
|
||||
* Variable: allowGaps
|
||||
*
|
||||
* If gaps should be allowed in the stack. Default is false.
|
||||
*/
|
||||
allowGaps = false;
|
||||
|
||||
/**
|
||||
* Variable: gridSize
|
||||
*
|
||||
* Grid size for alignment of position and size. Default is 0.
|
||||
*/
|
||||
gridSize = 0;
|
||||
|
||||
/**
|
||||
* Class: mxStackLayout
|
||||
*
|
||||
* Extends <mxGraphLayout> to create a horizontal or vertical stack of the
|
||||
|
@ -21,205 +154,59 @@
|
|||
* Constructs a new stack layout layout for the specified graph,
|
||||
* spacing, orientation and offset.
|
||||
*/
|
||||
function mxStackLayout(graph, horizontal, spacing, x0, y0, border)
|
||||
{
|
||||
mxGraphLayout.call(this, graph);
|
||||
constructor(graph, horizontal, spacing, x0, y0, border) {
|
||||
super(graph);
|
||||
this.horizontal = (horizontal != null) ? horizontal : true;
|
||||
this.spacing = (spacing != null) ? spacing : 0;
|
||||
this.x0 = (x0 != null) ? x0 : 0;
|
||||
this.y0 = (y0 != null) ? y0 : 0;
|
||||
this.border = (border != null) ? border : 0;
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* Extends mxGraphLayout.
|
||||
*/
|
||||
mxStackLayout.prototype = new mxGraphLayout();
|
||||
constructor = mxStackLayout;
|
||||
|
||||
/**
|
||||
* Variable: horizontal
|
||||
*
|
||||
* Specifies the orientation of the layout. Default is true.
|
||||
*/
|
||||
horizontal = null;
|
||||
|
||||
/**
|
||||
* Variable: spacing
|
||||
*
|
||||
* Specifies the spacing between the cells. Default is 0.
|
||||
*/
|
||||
spacing = null;
|
||||
|
||||
/**
|
||||
* Variable: x0
|
||||
*
|
||||
* Specifies the horizontal origin of the layout. Default is 0.
|
||||
*/
|
||||
x0 = null;
|
||||
|
||||
/**
|
||||
* Variable: y0
|
||||
*
|
||||
* Specifies the vertical origin of the layout. Default is 0.
|
||||
*/
|
||||
y0 = null;
|
||||
|
||||
/**
|
||||
* Variable: border
|
||||
*
|
||||
* Border to be added if fill is true. Default is 0.
|
||||
*/
|
||||
border = 0;
|
||||
|
||||
/**
|
||||
* Variable: marginTop
|
||||
*
|
||||
* Top margin for the child area. Default is 0.
|
||||
*/
|
||||
marginTop = 0;
|
||||
|
||||
/**
|
||||
* Variable: marginLeft
|
||||
*
|
||||
* Top margin for the child area. Default is 0.
|
||||
*/
|
||||
marginLeft = 0;
|
||||
|
||||
/**
|
||||
* Variable: marginRight
|
||||
*
|
||||
* Top margin for the child area. Default is 0.
|
||||
*/
|
||||
marginRight = 0;
|
||||
|
||||
/**
|
||||
* Variable: marginBottom
|
||||
*
|
||||
* Top margin for the child area. Default is 0.
|
||||
*/
|
||||
marginBottom = 0;
|
||||
|
||||
/**
|
||||
* Variable: keepFirstLocation
|
||||
*
|
||||
* Boolean indicating if the location of the first cell should be
|
||||
* kept, that is, it will not be moved to x0 or y0. Default is false.
|
||||
*/
|
||||
keepFirstLocation = false;
|
||||
|
||||
/**
|
||||
* Variable: fill
|
||||
*
|
||||
* Boolean indicating if dimension should be changed to fill out the parent
|
||||
* cell. Default is false.
|
||||
*/
|
||||
fill = false;
|
||||
|
||||
/**
|
||||
* Variable: resizeParent
|
||||
*
|
||||
* If the parent should be resized to match the width/height of the
|
||||
* stack. Default is false.
|
||||
*/
|
||||
resizeParent = false;
|
||||
|
||||
/**
|
||||
* Variable: resizeParentMax
|
||||
*
|
||||
* Use maximum of existing value and new value for resize of parent.
|
||||
* Default is false.
|
||||
*/
|
||||
resizeParentMax = false;
|
||||
|
||||
/**
|
||||
* Variable: resizeLast
|
||||
*
|
||||
* If the last element should be resized to fill out the parent. Default is
|
||||
* false. If <resizeParent> is true then this is ignored.
|
||||
*/
|
||||
resizeLast = false;
|
||||
|
||||
/**
|
||||
* Variable: wrap
|
||||
*
|
||||
* Value at which a new column or row should be created. Default is null.
|
||||
*/
|
||||
wrap = null;
|
||||
|
||||
/**
|
||||
* Variable: borderCollapse
|
||||
*
|
||||
* If the strokeWidth should be ignored. Default is true.
|
||||
*/
|
||||
borderCollapse = true;
|
||||
|
||||
/**
|
||||
* Variable: allowGaps
|
||||
*
|
||||
* If gaps should be allowed in the stack. Default is false.
|
||||
*/
|
||||
allowGaps = false;
|
||||
|
||||
/**
|
||||
* Variable: gridSize
|
||||
*
|
||||
* Grid size for alignment of position and size. Default is 0.
|
||||
*/
|
||||
gridSize = 0;
|
||||
|
||||
/**
|
||||
/**
|
||||
* Function: isHorizontal
|
||||
*
|
||||
* Returns <horizontal>.
|
||||
*/
|
||||
isHorizontal = ()=>
|
||||
{
|
||||
isHorizontal = () => {
|
||||
return this.horizontal;
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* Function: moveCell
|
||||
*
|
||||
* Implements <mxGraphLayout.moveCell>.
|
||||
*/
|
||||
moveCell = (cell, x, y)=>
|
||||
{
|
||||
moveCell = (cell, x, y) => {
|
||||
var model = this.graph.getModel();
|
||||
var parent = model.getParent(cell);
|
||||
var horizontal = this.isHorizontal();
|
||||
|
||||
if (cell != null && parent != null)
|
||||
{
|
||||
if (cell != null && parent != null) {
|
||||
var i = 0;
|
||||
var last = 0;
|
||||
var childCount = model.getChildCount(parent);
|
||||
var value = (horizontal) ? x : y;
|
||||
var pstate = this.graph.getView().getState(parent);
|
||||
|
||||
if (pstate != null)
|
||||
{
|
||||
if (pstate != null) {
|
||||
value -= (horizontal) ? pstate.x : pstate.y;
|
||||
}
|
||||
|
||||
value /= this.graph.view.scale;
|
||||
|
||||
for (i = 0; i < childCount; i++)
|
||||
{
|
||||
for (i = 0; i < childCount; i++) {
|
||||
var child = model.getChildAt(parent, i);
|
||||
|
||||
if (child != cell)
|
||||
{
|
||||
if (child != cell) {
|
||||
var bounds = model.getGeometry(child);
|
||||
|
||||
if (bounds != null)
|
||||
{
|
||||
if (bounds != null) {
|
||||
var tmp = (horizontal) ?
|
||||
bounds.x + bounds.width / 2 :
|
||||
bounds.y + bounds.height / 2;
|
||||
|
||||
if (last <= value && tmp > value)
|
||||
{
|
||||
if (last <= value && tmp > value) {
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -234,16 +221,15 @@ moveCell = (cell, x, y)=>
|
|||
|
||||
model.add(parent, cell, idx);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* Function: getParentSize
|
||||
*
|
||||
* Returns the size for the parent container or the size of the graph
|
||||
* container if the parent is a layer or the root of the model.
|
||||
*/
|
||||
getParentSize = (parent)=>
|
||||
{
|
||||
getParentSize = (parent) => {
|
||||
var model = this.graph.getModel();
|
||||
var pgeo = model.getGeometry(parent);
|
||||
|
||||
|
@ -251,41 +237,35 @@ getParentSize = (parent)=>
|
|||
// geometry or the current root of the view in which case the size
|
||||
// of the graph's container will be used.
|
||||
if (this.graph.container != null && ((pgeo == null &&
|
||||
model.isLayer(parent)) || parent == this.graph.getView().currentRoot))
|
||||
{
|
||||
model.isLayer(parent)) || parent == this.graph.getView().currentRoot)) {
|
||||
var width = this.graph.container.offsetWidth - 1;
|
||||
var height = this.graph.container.offsetHeight - 1;
|
||||
pgeo = new mxRectangle(0, 0, width, height);
|
||||
}
|
||||
|
||||
return pgeo;
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* Function: getLayoutCells
|
||||
*
|
||||
* Returns the cells to be layouted.
|
||||
*/
|
||||
getLayoutCells = (parent)=>
|
||||
{
|
||||
getLayoutCells = (parent) => {
|
||||
var model = this.graph.getModel();
|
||||
var childCount = model.getChildCount(parent);
|
||||
var cells = [];
|
||||
|
||||
for (var i = 0; i < childCount; i++)
|
||||
{
|
||||
for (var i = 0; i < childCount; i++) {
|
||||
var child = model.getChildAt(parent, i);
|
||||
|
||||
if (!this.isVertexIgnored(child) && this.isVertexMovable(child))
|
||||
{
|
||||
if (!this.isVertexIgnored(child) && this.isVertexMovable(child)) {
|
||||
cells.push(child);
|
||||
}
|
||||
}
|
||||
|
||||
if (this.allowGaps)
|
||||
{
|
||||
cells.sort(mxUtils.bind(this, (c1, c2)=>
|
||||
{
|
||||
if (this.allowGaps) {
|
||||
cells.sort(mxUtils.bind(this, (c1, c2) => {
|
||||
var geo1 = this.graph.getCellGeometry(c1);
|
||||
var geo2 = this.graph.getCellGeometry(c2);
|
||||
|
||||
|
@ -296,30 +276,27 @@ getLayoutCells = (parent)=>
|
|||
}
|
||||
|
||||
return cells;
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* Function: snap
|
||||
*
|
||||
* Snaps the given value to the grid size.
|
||||
*/
|
||||
snap = (value)=>
|
||||
{
|
||||
if (this.gridSize != null && this.gridSize > 0)
|
||||
{
|
||||
snap = (value) => {
|
||||
if (this.gridSize != null && this.gridSize > 0) {
|
||||
value = Math.max(value, this.gridSize);
|
||||
|
||||
if (value / this.gridSize > 1)
|
||||
{
|
||||
if (value / this.gridSize > 1) {
|
||||
var mod = value % this.gridSize;
|
||||
value += mod > this.gridSize / 2 ? (this.gridSize - mod) : -mod;
|
||||
}
|
||||
}
|
||||
|
||||
return value;
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* Function: execute
|
||||
*
|
||||
* Implements <mxGraphLayout.execute>.
|
||||
|
@ -327,17 +304,14 @@ snap = (value)=>
|
|||
* Only children where <isVertexIgnored> returns false are taken into
|
||||
* account.
|
||||
*/
|
||||
execute = (parent)=>
|
||||
{
|
||||
if (parent != null)
|
||||
{
|
||||
execute = (parent) => {
|
||||
if (parent != null) {
|
||||
var pgeo = this.getParentSize(parent);
|
||||
var horizontal = this.isHorizontal();
|
||||
var model = this.graph.getModel();
|
||||
var fillValue = null;
|
||||
|
||||
if (pgeo != null)
|
||||
{
|
||||
if (pgeo != null) {
|
||||
fillValue = (horizontal) ? pgeo.height - this.marginTop - this.marginBottom :
|
||||
pgeo.width - this.marginLeft - this.marginRight;
|
||||
}
|
||||
|
@ -347,73 +321,56 @@ execute = (parent)=>
|
|||
var y0 = this.y0 + this.border + this.marginTop;
|
||||
|
||||
// Handles swimlane start size
|
||||
if (this.graph.isSwimlane(parent))
|
||||
{
|
||||
if (this.graph.isSwimlane(parent)) {
|
||||
// Uses computed style to get latest
|
||||
var style = this.graph.getCellStyle(parent);
|
||||
var start = mxUtils.getNumber(style, mxConstants.STYLE_STARTSIZE, mxConstants.DEFAULT_STARTSIZE);
|
||||
var horz = mxUtils.getValue(style, mxConstants.STYLE_HORIZONTAL, true) == 1;
|
||||
|
||||
if (pgeo != null)
|
||||
{
|
||||
if (horz)
|
||||
{
|
||||
if (pgeo != null) {
|
||||
if (horz) {
|
||||
start = Math.min(start, pgeo.height);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
start = Math.min(start, pgeo.width);
|
||||
}
|
||||
}
|
||||
|
||||
if (horizontal == horz)
|
||||
{
|
||||
if (horizontal == horz) {
|
||||
fillValue -= start;
|
||||
}
|
||||
|
||||
if (horz)
|
||||
{
|
||||
if (horz) {
|
||||
y0 += start;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
x0 += start;
|
||||
}
|
||||
}
|
||||
|
||||
model.beginUpdate();
|
||||
try
|
||||
{
|
||||
try {
|
||||
var tmp = 0;
|
||||
var last = null;
|
||||
var lastValue = 0;
|
||||
var lastChild = null;
|
||||
var cells = this.getLayoutCells(parent);
|
||||
|
||||
for (var i = 0; i < cells.length; i++)
|
||||
{
|
||||
for (var i = 0; i < cells.length; i++) {
|
||||
var child = cells[i];
|
||||
var geo = model.getGeometry(child);
|
||||
|
||||
if (geo != null)
|
||||
{
|
||||
if (geo != null) {
|
||||
geo = geo.clone();
|
||||
|
||||
if (this.wrap != null && last != null)
|
||||
{
|
||||
if (this.wrap != null && last != null) {
|
||||
if ((horizontal && last.x + last.width +
|
||||
geo.width + 2 * this.spacing > this.wrap) ||
|
||||
(!horizontal && last.y + last.height +
|
||||
geo.height + 2 * this.spacing > this.wrap))
|
||||
{
|
||||
geo.height + 2 * this.spacing > this.wrap)) {
|
||||
last = null;
|
||||
|
||||
if (horizontal)
|
||||
{
|
||||
if (horizontal) {
|
||||
y0 += tmp + this.spacing;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
x0 += tmp + this.spacing;
|
||||
}
|
||||
|
||||
|
@ -424,68 +381,48 @@ execute = (parent)=>
|
|||
tmp = Math.max(tmp, (horizontal) ? geo.height : geo.width);
|
||||
var sw = 0;
|
||||
|
||||
if (!this.borderCollapse)
|
||||
{
|
||||
if (!this.borderCollapse) {
|
||||
var childStyle = this.graph.getCellStyle(child);
|
||||
sw = mxUtils.getNumber(childStyle, mxConstants.STYLE_STROKEWIDTH, 1);
|
||||
}
|
||||
|
||||
if (last != null)
|
||||
{
|
||||
if (last != null) {
|
||||
var temp = lastValue + this.spacing + Math.floor(sw / 2);
|
||||
|
||||
if (horizontal)
|
||||
{
|
||||
if (horizontal) {
|
||||
geo.x = this.snap(((this.allowGaps) ? Math.max(temp, geo.x) :
|
||||
temp) - this.marginLeft) + this.marginLeft;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
geo.y = this.snap(((this.allowGaps) ? Math.max(temp, geo.y) :
|
||||
temp) - this.marginTop) + this.marginTop;
|
||||
}
|
||||
}
|
||||
else if (!this.keepFirstLocation)
|
||||
{
|
||||
if (horizontal)
|
||||
{
|
||||
} else if (!this.keepFirstLocation) {
|
||||
if (horizontal) {
|
||||
geo.x = (this.allowGaps && geo.x > x0) ? Math.max(this.snap(geo.x -
|
||||
this.marginLeft) + this.marginLeft, x0) : x0;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
geo.y = (this.allowGaps && geo.y > y0) ? Math.max(this.snap(geo.y -
|
||||
this.marginTop) + this.marginTop, y0) : y0;
|
||||
}
|
||||
}
|
||||
|
||||
if (horizontal)
|
||||
{
|
||||
if (horizontal) {
|
||||
geo.y = y0;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
geo.x = x0;
|
||||
}
|
||||
|
||||
if (this.fill && fillValue != null)
|
||||
{
|
||||
if (horizontal)
|
||||
{
|
||||
if (this.fill && fillValue != null) {
|
||||
if (horizontal) {
|
||||
geo.height = fillValue;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
geo.width = fillValue;
|
||||
}
|
||||
}
|
||||
|
||||
if (horizontal)
|
||||
{
|
||||
if (horizontal) {
|
||||
geo.width = this.snap(geo.width);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
geo.height = this.snap(geo.height);
|
||||
}
|
||||
|
||||
|
@ -493,43 +430,32 @@ execute = (parent)=>
|
|||
lastChild = child;
|
||||
last = geo;
|
||||
|
||||
if (horizontal)
|
||||
{
|
||||
if (horizontal) {
|
||||
lastValue = last.x + last.width + Math.floor(sw / 2);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
lastValue = last.y + last.height + Math.floor(sw / 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (this.resizeParent && pgeo != null && last != null && !this.graph.isCellCollapsed(parent))
|
||||
{
|
||||
if (this.resizeParent && pgeo != null && last != null && !this.graph.isCellCollapsed(parent)) {
|
||||
this.updateParentGeometry(parent, pgeo, last);
|
||||
}
|
||||
else if (this.resizeLast && pgeo != null && last != null && lastChild != null)
|
||||
{
|
||||
if (horizontal)
|
||||
{
|
||||
} else if (this.resizeLast && pgeo != null && last != null && lastChild != null) {
|
||||
if (horizontal) {
|
||||
last.width = pgeo.width - last.x - this.spacing - this.marginRight - this.marginLeft;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
last.height = pgeo.height - last.y - this.spacing - this.marginBottom;
|
||||
}
|
||||
|
||||
this.setChildGeometry(lastChild, last);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
} finally {
|
||||
model.endUpdate();
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* Function: setChildGeometry
|
||||
*
|
||||
* Sets the specific geometry to the given child cell.
|
||||
|
@ -539,18 +465,16 @@ execute = (parent)=>
|
|||
* child - The given child of <mxCell>.
|
||||
* geo - The specific geometry of <mxGeometry>.
|
||||
*/
|
||||
setChildGeometry = (child, geo)=>
|
||||
{
|
||||
setChildGeometry = (child, geo) => {
|
||||
var geo2 = this.graph.getCellGeometry(child);
|
||||
|
||||
if (geo2 == null || geo.x != geo2.x || geo.y != geo2.y ||
|
||||
geo.width != geo2.width || geo.height != geo2.height)
|
||||
{
|
||||
geo.width != geo2.width || geo.height != geo2.height) {
|
||||
this.graph.getModel().setGeometry(child, geo);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* Function: updateParentGeometry
|
||||
*
|
||||
* Updates the geometry of the given parent cell.
|
||||
|
@ -561,43 +485,35 @@ setChildGeometry = (child, geo)=>
|
|||
* pgeo - The new <mxGeometry> for parent.
|
||||
* last - The last <mxGeometry>.
|
||||
*/
|
||||
updateParentGeometry = (parent, pgeo, last)=>
|
||||
{
|
||||
updateParentGeometry = (parent, pgeo, last) => {
|
||||
var horizontal = this.isHorizontal();
|
||||
var model = this.graph.getModel();
|
||||
|
||||
var pgeo2 = pgeo.clone();
|
||||
|
||||
if (horizontal)
|
||||
{
|
||||
if (horizontal) {
|
||||
var tmp = last.x + last.width + this.marginRight + this.border;
|
||||
|
||||
if (this.resizeParentMax)
|
||||
{
|
||||
if (this.resizeParentMax) {
|
||||
pgeo2.width = Math.max(pgeo2.width, tmp);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
pgeo2.width = tmp;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
var tmp = last.y + last.height + this.marginBottom + this.border;
|
||||
|
||||
if (this.resizeParentMax)
|
||||
{
|
||||
if (this.resizeParentMax) {
|
||||
pgeo2.height = Math.max(pgeo2.height, tmp);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
pgeo2.height = tmp;
|
||||
}
|
||||
}
|
||||
|
||||
if (pgeo.x != pgeo2.x || pgeo.y != pgeo2.y ||
|
||||
pgeo.width != pgeo2.width || pgeo.height != pgeo2.height)
|
||||
{
|
||||
pgeo.width != pgeo2.width || pgeo.height != pgeo2.height) {
|
||||
model.setGeometry(parent, pgeo2);
|
||||
}
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
export default mxStackLayout;
|
||||
|
|
Loading…
Reference in New Issue