From 7eb02061b727da8d7339f043e69fe5a4c2b2bbdc Mon Sep 17 00:00:00 2001 From: mcyph <20507948+mcyph@users.noreply.github.com> Date: Sat, 27 Mar 2021 19:02:49 +1100 Subject: [PATCH] made it so all comparisons against mxConstants values use === or !== --- src/mxgraph/io/mxObjectCodec.js | 2 +- src/mxgraph/shape/mxImageShape.js | 6 ++--- src/mxgraph/shape/mxPolyline.js | 12 ++++----- src/mxgraph/shape/mxRectangleShape.js | 6 ++--- src/mxgraph/shape/mxStencil.js | 4 +-- src/mxgraph/shape/mxStencilRegistry.js | 2 +- src/mxgraph/shape/mxSwimlane.js | 34 +++++++++++++------------- src/mxgraph/util/mxUtils.js | 34 +++++++++++++------------- src/mxgraph/view/mxCellRenderer.js | 2 +- src/mxgraph/view/mxEdgeStyle.js | 4 +-- src/mxgraph/view/mxGraph.js | 16 ++++++------ 11 files changed, 60 insertions(+), 62 deletions(-) diff --git a/src/mxgraph/io/mxObjectCodec.js b/src/mxgraph/io/mxObjectCodec.js index 36be17212..a57be4d13 100644 --- a/src/mxgraph/io/mxObjectCodec.js +++ b/src/mxgraph/io/mxObjectCodec.js @@ -867,7 +867,7 @@ class mxObjectCodec { const tmp = child.nextSibling; if ( - child.nodeType == mxConstants.NODETYPE_ELEMENT && + child.nodeType === mxConstants.NODETYPE_ELEMENT && !this.processInclude(dec, child, obj) ) { this.decodeChild(dec, child, obj); diff --git a/src/mxgraph/shape/mxImageShape.js b/src/mxgraph/shape/mxImageShape.js index 6bbdebab7..1ae837cf0 100644 --- a/src/mxgraph/shape/mxImageShape.js +++ b/src/mxgraph/shape/mxImageShape.js @@ -82,13 +82,13 @@ class mxImageShape extends mxRectangleShape { if (this.style != null) { this.preserveImageAspect = - mxUtils.getNumber(this.style, mxConstants.STYLE_IMAGE_ASPECT, 1) === 1; + mxUtils.getNumber(this.style, mxConstants.STYLE_IMAGE_ASPECT, 1) == 1; // Legacy support for imageFlipH/V this.flipH = - this.flipH || mxUtils.getValue(this.style, 'imageFlipH', 0) === 1; + this.flipH || mxUtils.getValue(this.style, 'imageFlipH', 0) == 1; this.flipV = - this.flipV || mxUtils.getValue(this.style, 'imageFlipV', 0) === 1; + this.flipV || mxUtils.getValue(this.style, 'imageFlipV', 0) == 1; } } diff --git a/src/mxgraph/shape/mxPolyline.js b/src/mxgraph/shape/mxPolyline.js index b0f396b8f..6e600490d 100644 --- a/src/mxgraph/shape/mxPolyline.js +++ b/src/mxgraph/shape/mxPolyline.js @@ -107,22 +107,20 @@ class mxPolyline extends mxShape { const pt = pts[0]; const n = pts.length; - c.moveTo(pt.x, pt.y); for (let i = 1; i < n - 2; i += 1) { - var p0 = pts[i]; - var p1 = pts[i + 1]; + const p0 = pts[i]; + const p1 = pts[i + 1]; const ix = (p0.x + p1.x) / 2; const iy = (p0.y + p1.y) / 2; - c.quadTo(p0.x, p0.y, ix, iy); } - var p0 = pts[n - 2]; - var p1 = pts[n - 1]; - + const p0 = pts[n - 2]; + const p1 = pts[n - 1]; c.quadTo(p0.x, p0.y, p1.x, p1.y); + c.stroke(); } } diff --git a/src/mxgraph/shape/mxRectangleShape.js b/src/mxgraph/shape/mxRectangleShape.js index 596f7ecd5..40b89fd35 100644 --- a/src/mxgraph/shape/mxRectangleShape.js +++ b/src/mxgraph/shape/mxRectangleShape.js @@ -54,8 +54,8 @@ class mxRectangleShape extends mxShape { return ( !this.isRounded && !this.glass && - this.rotation == 0 && - (events || (this.fill != null && this.fill != mxConstants.NONE)) + this.rotation === 0 && + (events || (this.fill != null && this.fill !== mxConstants.NONE)) ); } @@ -138,7 +138,7 @@ class mxRectangleShape extends mxShape { this.glass && !this.outline && this.fill != null && - this.fill != mxConstants.NONE + this.fill !== mxConstants.NONE ) { this.paintGlassEffect( c, diff --git a/src/mxgraph/shape/mxStencil.js b/src/mxgraph/shape/mxStencil.js index 136ef9086..eda2f19de 100644 --- a/src/mxgraph/shape/mxStencil.js +++ b/src/mxgraph/shape/mxStencil.js @@ -486,7 +486,7 @@ class mxStencil extends mxShape { let tmp = node.firstChild; while (tmp != null) { - if (tmp.nodeType == mxConstants.NODETYPE_ELEMENT) { + if (tmp.nodeType === mxConstants.NODETYPE_ELEMENT) { this.drawNode(canvas, shape, tmp, aspect, disableShadow, paint); } @@ -627,7 +627,7 @@ class mxStencil extends mxShape { let childNode = node.firstChild; while (childNode != null) { - if (childNode.nodeType == mxConstants.NODETYPE_ELEMENT) { + if (childNode.nodeType === mxConstants.NODETYPE_ELEMENT) { this.drawNode( canvas, shape, diff --git a/src/mxgraph/shape/mxStencilRegistry.js b/src/mxgraph/shape/mxStencilRegistry.js index 17c4ba74b..4aee9a5aa 100644 --- a/src/mxgraph/shape/mxStencilRegistry.js +++ b/src/mxgraph/shape/mxStencilRegistry.js @@ -12,7 +12,7 @@ * * while (shape != null) * { - * if (shape.nodeType == mxConstants.NODETYPE_ELEMENT) + * if (shape.nodeType === mxConstants.NODETYPE_ELEMENT) * { * mxStencilRegistry.addStencil(shape.getAttribute('name'), new mxStencil(shape)); * } diff --git a/src/mxgraph/shape/mxSwimlane.js b/src/mxgraph/shape/mxSwimlane.js index 01911fefd..c1b774a05 100644 --- a/src/mxgraph/shape/mxSwimlane.js +++ b/src/mxgraph/shape/mxSwimlane.js @@ -258,7 +258,7 @@ class mxSwimlane extends mxShape { '1'; } - if (!events && (this.fill == null || this.fill == mxConstants.NONE)) { + if (!events && (this.fill == null || this.fill === mxConstants.NONE)) { c.pointerEvents = false; } @@ -270,11 +270,11 @@ class mxSwimlane extends mxShape { c.fillAndStroke(); if (start < h) { - if (fill == mxConstants.NONE || !events) { + if (fill === mxConstants.NONE || !events) { c.pointerEvents = false; } - if (fill != mxConstants.NONE) { + if (fill !== mxConstants.NONE) { c.setFillColor(fill); } @@ -284,7 +284,7 @@ class mxSwimlane extends mxShape { c.lineTo(w, h); c.lineTo(w, start); - if (fill == mxConstants.NONE) { + if (fill === mxConstants.NONE) { c.stroke(); } else { c.fillAndStroke(); @@ -298,11 +298,11 @@ class mxSwimlane extends mxShape { c.fillAndStroke(); if (start < w) { - if (fill == mxConstants.NONE || !events) { + if (fill === mxConstants.NONE || !events) { c.pointerEvents = false; } - if (fill != mxConstants.NONE) { + if (fill !== mxConstants.NONE) { c.setFillColor(fill); } @@ -312,7 +312,7 @@ class mxSwimlane extends mxShape { c.lineTo(w, h); c.lineTo(start, h); - if (fill == mxConstants.NONE) { + if (fill === mxConstants.NONE) { c.stroke(); } else { c.fillAndStroke(); @@ -321,7 +321,7 @@ class mxSwimlane extends mxShape { } if (swimlaneLine) { - this.paintDivider(c, x, y, w, h, start, fill == mxConstants.NONE); + this.paintDivider(c, x, y, w, h, start, fill === mxConstants.NONE); } } @@ -341,7 +341,7 @@ class mxSwimlane extends mxShape { '1'; } - if (!events && (this.fill == null || this.fill == mxConstants.NONE)) { + if (!events && (this.fill == null || this.fill === mxConstants.NONE)) { c.pointerEvents = false; } @@ -355,11 +355,11 @@ class mxSwimlane extends mxShape { c.fillAndStroke(); if (start < h) { - if (fill == mxConstants.NONE || !events) { + if (fill === mxConstants.NONE || !events) { c.pointerEvents = false; } - if (fill != mxConstants.NONE) { + if (fill !== mxConstants.NONE) { c.setFillColor(fill); } @@ -371,7 +371,7 @@ class mxSwimlane extends mxShape { c.quadTo(w, h, w, h - r); c.lineTo(w, start); - if (fill == mxConstants.NONE) { + if (fill === mxConstants.NONE) { c.stroke(); } else { c.fillAndStroke(); @@ -387,11 +387,11 @@ class mxSwimlane extends mxShape { c.fillAndStroke(); if (start < w) { - if (fill == mxConstants.NONE || !events) { + if (fill === mxConstants.NONE || !events) { c.pointerEvents = false; } - if (fill != mxConstants.NONE) { + if (fill !== mxConstants.NONE) { c.setFillColor(fill); } @@ -403,7 +403,7 @@ class mxSwimlane extends mxShape { c.quadTo(w, 0, w - r, 0); c.lineTo(start, 0); - if (fill == mxConstants.NONE) { + if (fill === mxConstants.NONE) { c.stroke(); } else { c.fillAndStroke(); @@ -412,7 +412,7 @@ class mxSwimlane extends mxShape { } if (swimlaneLine) { - this.paintDivider(c, x, y, w, h, start, fill == mxConstants.NONE); + this.paintDivider(c, x, y, w, h, start, fill === mxConstants.NONE); } } @@ -445,7 +445,7 @@ class mxSwimlane extends mxShape { * Paints the vertical or horizontal separator line between swimlanes. */ paintSeparator(c, x, y, w, h, start, color) { - if (color != mxConstants.NONE) { + if (color !== mxConstants.NONE) { c.setStrokeColor(color); c.setDashed(true); c.begin(); diff --git a/src/mxgraph/util/mxUtils.js b/src/mxgraph/util/mxUtils.js index d3131452e..65af2b1b1 100644 --- a/src/mxgraph/util/mxUtils.js +++ b/src/mxgraph/util/mxUtils.js @@ -1506,7 +1506,7 @@ const mxUtils = { if (value == null) { value = defaultValue; - } else if (value == mxConstants.NONE) { + } else if (value === mxConstants.NONE) { value = null; } @@ -2089,10 +2089,10 @@ const mxUtils = { if ( (flipV && - (d == mxConstants.DIRECTION_SOUTH || - d == mxConstants.DIRECTION_NORTH)) || + (d === mxConstants.DIRECTION_SOUTH || + d === mxConstants.DIRECTION_NORTH)) || (flipH && - (d == mxConstants.DIRECTION_EAST || d == mxConstants.DIRECTION_WEST)) + (d === mxConstants.DIRECTION_EAST || d === mxConstants.DIRECTION_WEST)) ) { const tmp = m.x; m.x = m.width; @@ -2101,10 +2101,10 @@ const mxUtils = { if ( (flipH && - (d == mxConstants.DIRECTION_SOUTH || - d == mxConstants.DIRECTION_NORTH)) || + (d === mxConstants.DIRECTION_SOUTH || + d === mxConstants.DIRECTION_NORTH)) || (flipV && - (d == mxConstants.DIRECTION_EAST || d == mxConstants.DIRECTION_WEST)) + (d === mxConstants.DIRECTION_EAST || d === mxConstants.DIRECTION_WEST)) ) { const tmp = m.y; m.y = m.height; @@ -2113,17 +2113,17 @@ const mxUtils = { const m2 = mxRectangle.fromRectangle(m); - if (d == mxConstants.DIRECTION_SOUTH) { + if (d === mxConstants.DIRECTION_SOUTH) { m2.y = m.x; m2.x = m.height; m2.width = m.y; m2.height = m.width; - } else if (d == mxConstants.DIRECTION_WEST) { + } else if (d === mxConstants.DIRECTION_WEST) { m2.y = m.height; m2.x = m.width; m2.width = m.x; m2.height = m.y; - } else if (d == mxConstants.DIRECTION_NORTH) { + } else if (d === mxConstants.DIRECTION_NORTH) { m2.y = m.width; m2.x = m.y; m2.width = m.height; @@ -3216,16 +3216,16 @@ const mxUtils = { let dy = -0.5; // Horizontal alignment - if (align == mxConstants.ALIGN_LEFT) { + if (align === mxConstants.ALIGN_LEFT) { dx = 0; - } else if (align == mxConstants.ALIGN_RIGHT) { + } else if (align === mxConstants.ALIGN_RIGHT) { dx = -1; } // Vertical alignment - if (valign == mxConstants.ALIGN_TOP) { + if (valign === mxConstants.ALIGN_TOP) { dy = 0; - } else if (valign == mxConstants.ALIGN_BOTTOM) { + } else if (valign === mxConstants.ALIGN_BOTTOM) { dy = -1; } @@ -3272,11 +3272,11 @@ const mxUtils = { // Sets the font style if (fontStyle != null) { - if ((fontStyle & mxConstants.FONT_BOLD) == mxConstants.FONT_BOLD) { + if ((fontStyle & mxConstants.FONT_BOLD) === mxConstants.FONT_BOLD) { div.style.fontWeight = 'bold'; } - if ((fontStyle & mxConstants.FONT_ITALIC) == mxConstants.FONT_ITALIC) { + if ((fontStyle & mxConstants.FONT_ITALIC) === mxConstants.FONT_ITALIC) { div.style.fontStyle = 'italic'; } @@ -3350,7 +3350,7 @@ const mxUtils = { const { drawPane } = view; const { overlayPane } = view; - if (graph.dialect == mxConstants.DIALECT_SVG) { + if (graph.dialect === mxConstants.DIALECT_SVG) { view.drawPane = document.createElementNS(mxConstants.NS_SVG, 'g'); view.canvas.appendChild(view.drawPane); diff --git a/src/mxgraph/view/mxCellRenderer.js b/src/mxgraph/view/mxCellRenderer.js index 087266e87..02c4e4dcc 100644 --- a/src/mxgraph/view/mxCellRenderer.js +++ b/src/mxgraph/view/mxCellRenderer.js @@ -539,7 +539,7 @@ class mxCellRenderer { if ( mxClient.IS_SVG && mxClient.NO_FO && - shape.dialect != mxConstants.DIALECT_SVG + shape.dialect !== mxConstants.DIALECT_SVG ) { shape.init(state.view.graph.container); } else { diff --git a/src/mxgraph/view/mxEdgeStyle.js b/src/mxgraph/view/mxEdgeStyle.js index 9b6f11120..21e80d91d 100644 --- a/src/mxgraph/view/mxEdgeStyle.js +++ b/src/mxgraph/view/mxEdgeStyle.js @@ -180,11 +180,11 @@ const mxEdgeStyle = { ); if ( - constraint != mxConstants.DIRECTION_MASK_NONE && + constraint !== mxConstants.DIRECTION_MASK_NONE && constraint != mxConstants.DIRECTION_MASK_WEST + mxConstants.DIRECTION_MASK_EAST ) { - isTargetLeft = constraint == mxConstants.DIRECTION_MASK_WEST; + isTargetLeft = constraint === mxConstants.DIRECTION_MASK_WEST; } } diff --git a/src/mxgraph/view/mxGraph.js b/src/mxgraph/view/mxGraph.js index 3ad4f693f..2aa020e90 100644 --- a/src/mxgraph/view/mxGraph.js +++ b/src/mxgraph/view/mxGraph.js @@ -1638,9 +1638,9 @@ class mxGraph extends mxEventSource { if (mxClient.IS_SVG) { this.dialect = mxConstants.DIALECT_SVG; - } else if (renderHint == mxConstants.RENDERING_HINT_FASTEST) { + } else if (renderHint === mxConstants.RENDERING_HINT_FASTEST) { this.dialect = mxConstants.DIALECT_STRICTHTML; - } else if (renderHint == mxConstants.RENDERING_HINT_FASTER) { + } else if (renderHint === mxConstants.RENDERING_HINT_FASTER) { this.dialect = mxConstants.DIALECT_PREFERHTML; } // default for VML else { @@ -2833,7 +2833,7 @@ class mxGraph extends mxEventSource { c.scrollTop += border - dy; if (old == c.scrollTop && extend) { - if (this.dialect == mxConstants.DIALECT_SVG) { + if (this.dialect === mxConstants.DIALECT_SVG) { const root = this.view.getDrawPane().ownerSVGElement; const height = this.container.scrollHeight + border - dy; @@ -3140,7 +3140,7 @@ class mxGraph extends mxEventSource { width = Math.ceil(width); height = Math.ceil(height); - if (this.dialect == mxConstants.DIALECT_SVG) { + if (this.dialect === mxConstants.DIALECT_SVG) { const root = this.view.getDrawPane().ownerSVGElement; if (root != null) { @@ -3665,7 +3665,7 @@ class mxGraph extends mxEventSource { * let style = this.getCurrentCellStyle(edge); * let elbow = mxUtils.getValue(style, mxConstants.STYLE_ELBOW, * mxConstants.ELBOW_HORIZONTAL); - * let value = (elbow == mxConstants.ELBOW_HORIZONTAL) ? + * let value = (elbow === mxConstants.ELBOW_HORIZONTAL) ? * mxConstants.ELBOW_VERTICAL : mxConstants.ELBOW_HORIZONTAL; * this.setCellStyles(mxConstants.STYLE_ELBOW, value, [edge]); * } @@ -6888,11 +6888,11 @@ class mxGraph extends mxEventSource { 1 ) == 1 ) { - if (direction == mxConstants.DIRECTION_NORTH) { + if (direction === mxConstants.DIRECTION_NORTH) { r1 += 270; - } else if (direction == mxConstants.DIRECTION_WEST) { + } else if (direction === mxConstants.DIRECTION_WEST) { r1 += 180; - } else if (direction == mxConstants.DIRECTION_SOUTH) { + } else if (direction === mxConstants.DIRECTION_SOUTH) { r1 += 90; }