manual js syntax updates

development
mcyph 2021-03-19 23:50:19 +11:00
parent c5e7813b34
commit a3b84ee3c9
3 changed files with 761 additions and 866 deletions

View File

@ -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
*

View File

@ -2,34 +2,8 @@
* Copyright (c) 2006-2015, JGraph Ltd
* Copyright (c) 2006-2015, Gaudenz Alder
*/
/**
* Class: mxRadialTreeLayout
*
* Extends <mxGraphLayout> to implement a radial tree 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 mxRadialTreeLayout(graph);
* layout.execute(graph.getDefaultParent());
* (end)
*
* Constructor: mxRadialTreeLayout
*
* Constructs a new radial tree layout for the specified graph
*/
function mxRadialTreeLayout(graph)
{
mxCompactTreeLayout.call(this, graph , false);
};
/**
* Extends mxGraphLayout.
*/
mxUtils.extend(mxRadialTreeLayout, mxCompactTreeLayout);
class mxRadialTreeLayout extends mxCompactTreeLayout {
/**
* Variable: angleOffset
*
@ -122,6 +96,28 @@ rowRadi = [];
*/
row = [];
/**
* Class: mxRadialTreeLayout
*
* Extends <mxGraphLayout> to implement a radial tree 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 mxRadialTreeLayout(graph);
* layout.execute(graph.getDefaultParent());
* (end)
*
* Constructor: mxRadialTreeLayout
*
* Constructs a new radial tree layout for the specified graph
*/
constructor(graph) {
super(graph, false);
};
/**
* Function: isVertexIgnored
*
@ -132,10 +128,9 @@ 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;
};
/**
@ -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,8 +174,7 @@ 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];
@ -191,14 +183,12 @@ execute = (parent, root)=>
}
// 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,35 +199,28 @@ 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)
{
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 )
{
} else if (averTheta < node.theta && j > 0) {
var lastTheta = row[j - 1].theta;
node.theta = Math.max(averTheta, lastTheta + Math.PI / 10);
}
@ -246,10 +229,8 @@ execute = (parent, root)=>
}
// 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);
@ -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;

View File

@ -2,41 +2,8 @@
* Copyright (c) 2006-2015, JGraph Ltd
* Copyright (c) 2006-2015, Gaudenz Alder
*/
/**
* Class: mxStackLayout
*
* Extends <mxGraphLayout> to create a horizontal or vertical stack of the
* child vertices. The children do not need to be connected for this layout
* to work.
*
* Example:
*
* (code)
* var layout = new mxStackLayout(graph, true);
* layout.execute(graph.getDefaultParent());
* (end)
*
* Constructor: mxStackLayout
*
* 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);
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;
class mxStackLayout extends mxGraphLayout {
/**
* Variable: horizontal
*
@ -168,13 +135,40 @@ allowGaps = false;
*/
gridSize = 0;
/**
* Class: mxStackLayout
*
* Extends <mxGraphLayout> to create a horizontal or vertical stack of the
* child vertices. The children do not need to be connected for this layout
* to work.
*
* Example:
*
* (code)
* var layout = new mxStackLayout(graph, true);
* layout.execute(graph.getDefaultParent());
* (end)
*
* Constructor: mxStackLayout
*
* Constructs a new stack layout layout for the specified graph,
* spacing, orientation and offset.
*/
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;
};
/**
* Function: isHorizontal
*
* Returns <horizontal>.
*/
isHorizontal = ()=>
{
isHorizontal = () => {
return this.horizontal;
};
@ -183,43 +177,36 @@ isHorizontal = ()=>
*
* 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;
}
@ -242,8 +229,7 @@ moveCell = (cell, x, y)=>
* 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,8 +237,7 @@ 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);
@ -266,26 +251,21 @@ getParentSize = (parent)=>
*
* 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);
@ -303,14 +283,11 @@ getLayoutCells = (parent)=>
*
* 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;
}
@ -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,37 +430,26 @@ 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();
}
}
@ -539,13 +465,11 @@ 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);
}
};
@ -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;