Skip to content

Commit

Permalink
chore: fix various code quality issues (#2852)
Browse files Browse the repository at this point in the history
  • Loading branch information
kumilingus authored Jan 13, 2025
1 parent 12b0c32 commit ba52ca3
Show file tree
Hide file tree
Showing 43 changed files with 337 additions and 312 deletions.
4 changes: 2 additions & 2 deletions examples/dwdm/src/shapes/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import { dia } from '@joint/core';

export function isCellHidden(cell: dia.Cell): boolean {
return Boolean(cell.get('hidden'));
};
}

export function setCellVisibility(cell: dia.Cell, visible: boolean): void {
cell.set('hidden', !visible);
};
}

export function getPortLinks(graph: dia.Graph, element: dia.Element, portId: dia.Cell.ID): dia.Link[] {
const outboundLinks = graph.getConnectedLinks(element, { outbound: true }).filter((link) => {
Expand Down
2 changes: 1 addition & 1 deletion examples/isometric/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<div id="canvas"></div>
<button id="toggle">Toggle 2D / Isometric View</button>
<a rel="noopener" target="_blank" href="https://www.jointjs.com">
<img title="JointJS Logo" id="logo" src="assets/jj-logo.svg" width="200" height="50"></img>
<img alt="JointJS logo" id="logo" src="assets/jj-logo.svg" width="200" height="50"></img>
</a>
<script src="dist/bundle.js"></script>
</body>
Expand Down
3 changes: 1 addition & 2 deletions examples/isometric/src/shapes/isometric-shape.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@ export default class IsometricShape extends dia.Element<IsometricElementAttribut
}
});
}

};
}

export class CuboidShape extends IsometricShape {
constructor(...args: any[]) {
Expand Down
2 changes: 1 addition & 1 deletion examples/isometric/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { g, V, dia, util } from '@joint/core';
import { V, dia } from '@joint/core';
import IsometricShape, { View } from './shapes/isometric-shape';
import { GRID_COUNT, GRID_SIZE, SCALE, ISOMETRIC_SCALE, ROTATION_DEGREES } from './theme';
import { Link } from './shapes';
Expand Down
4 changes: 2 additions & 2 deletions packages/joint-core/demo/archive/joint.dia.LegacyLinkView.js
Original file line number Diff line number Diff line change
Expand Up @@ -839,7 +839,7 @@
if (this._V.markerSource) {

cache.sourceBBox = cache.sourceBBox || this._V.markerSource.getBBox();
sourceMarkerPoint = Point(sourcePoint).move(
sourceMarkerPoint = (new Point(sourcePoint)).move(
firstWaypoint || targetPoint,
cache.sourceBBox.width * this._V.markerSource.scale().sx * -1
).round();
Expand All @@ -848,7 +848,7 @@
if (this._V.markerTarget) {

cache.targetBBox = cache.targetBBox || this._V.markerTarget.getBBox();
targetMarkerPoint = Point(targetPoint).move(
targetMarkerPoint = (new Point(targetPoint)).move(
lastWaypoint || sourcePoint,
cache.targetBBox.width * this._V.markerTarget.scale().sx * -1
).round();
Expand Down
4 changes: 2 additions & 2 deletions packages/joint-core/demo/archive/pipes/src/pipes.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ var PatternLinkView = joint.dia.LegacyLinkView.extend({

var angle = g.toRad(from.theta(to) - 90);
var center = g.line(from, to).midpoint();
var start = new g.Point.fromPolar(width / 2, angle, center);
var end = new g.Point.fromPolar(width / 2, Math.PI + angle, center);
var start = g.Point.fromPolar(width / 2, angle, center);
var end = g.Point.fromPolar(width / 2, Math.PI + angle, center);

return [start.x, start.y, end.x, end.y];
},
Expand Down
2 changes: 2 additions & 0 deletions packages/joint-core/demo/requirejs/index.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>JointJS Core | require.js | test suite</title>
<style>
#app { position: relative; }
</style>
Expand Down
1 change: 1 addition & 0 deletions packages/joint-core/demo/vuejs/index.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
Expand Down
2 changes: 1 addition & 1 deletion packages/joint-core/src/V/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -472,8 +472,8 @@ const V = (function() {
case 'bottom':
dy = -(0.25 * llMaxFont) - rLineHeights;
break;
default:
case 'top':
default:
dy = (0.8 * flMaxFont);
break;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/joint-core/src/dia/ElementView.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ export const ElementView = CellView.extend({
* @abstract
*/
_initializePorts: function() {

// implemented in ports.js
},

update: function(_, renderingOnlyAttrs) {
Expand Down
10 changes: 5 additions & 5 deletions packages/joint-core/src/dia/HighlighterView.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ export const HighlighterView = mvc.View.extend({
// The cellView is now rendered/updated since it has a higher update priority.
this.updateRequested = false;
const { cellView, nodeSelector } = this;
if (!cellView.isMounted()) {
if (cellView.isMounted()) {
this.update(cellView, nodeSelector);
this.mount();
this.transform();
} else {
this.postponedUpdate = true;
return 0;
}
this.update(cellView, nodeSelector);
this.mount();
this.transform();
return 0;
},

Expand Down
8 changes: 6 additions & 2 deletions packages/joint-core/src/mvc/Collection.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,15 @@ assign(Collection.prototype, Events, {

// preinitialize is an empty function by default. You can override it with a function
// or object. preinitialize will run before any instantiation logic is run in the Collection.
preinitialize: function(){},
preinitialize: function(){
// No implementation.
},

// Initialize is an empty function by default. Override it with your own
// initialization logic.
initialize: function(){},
initialize: function(){
// No implementation.
},

// The JSON representation of a Collection is an array of the
// models' attributes.
Expand Down
4 changes: 2 additions & 2 deletions packages/joint-core/src/mvc/Dom/Dom.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ $.fn.find = function(selector) {
return ret;
};

$.fn.add = function(selector, context) {
const newElements = $(selector, context).toArray();
$.fn.add = function(selector) {
const newElements = $(selector).toArray();
const prevElements = this.toArray();
const ret = this.pushStack([]);
$.merge(ret, uniq(prevElements.concat(newElements)));
Expand Down
16 changes: 9 additions & 7 deletions packages/joint-core/src/mvc/Dom/methods.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export function html(html) {
if (!el) return null;
if (arguments.length === 0) return el.innerHTML;
if (html === undefined) return this; // do nothing
cleanNodesData(dataPriv, el.getElementsByTagName('*'));
cleanNodesData(el.getElementsByTagName('*'));
if (typeof html === 'string' || typeof html === 'number') {
el.innerHTML = html;
} else {
Expand Down Expand Up @@ -336,17 +336,19 @@ export function position() {
// when a statically positioned element is identified
doc = el.ownerDocument;
offsetParent = el.offsetParent || doc.documentElement;
const $parentOffset = $(offsetParent);
const parentOffsetElementPosition = $parentOffset.css('position') || 'static';
while ( offsetParent && (offsetParent === doc.body || offsetParent === doc.documentElement) && parentOffsetElementPosition === 'static') {
offsetParent = offsetParent.parentNode;
const isStaticallyPositioned = (el) => {
const { position } = el.style;
return !position || position === 'static';
};
while (offsetParent && offsetParent !== doc.documentElement && isStaticallyPositioned(offsetParent)) {
offsetParent = offsetParent.offsetParent || doc.documentElement;
}
if (offsetParent && offsetParent !== el && offsetParent.nodeType === 1) {
if (offsetParent && offsetParent !== el && offsetParent.nodeType === 1 && !isStaticallyPositioned(offsetParent)) {
// Incorporate borders into its offset, since they are outside its content origin
const offsetParentStyles = window.getComputedStyle(offsetParent);
const borderTopWidth = parseFloat(offsetParentStyles.borderTopWidth) || 0;
const borderLeftWidth = parseFloat(offsetParentStyles.borderLeftWidth) || 0;
parentOffset = $parentOffset.offset();
parentOffset = $(offsetParent).offset();
parentOffset.top += borderTopWidth;
parentOffset.left += borderLeftWidth;
}
Expand Down
8 changes: 6 additions & 2 deletions packages/joint-core/src/mvc/Model.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,15 @@ assign(Model.prototype, Events, {

// preinitialize is an empty function by default. You can override it with a function
// or object. preinitialize will run before any instantiation logic is run in the Model.
preinitialize: function(){},
preinitialize: function(){
// No implementation.
},

// Initialize is an empty function by default. Override it with your own
// initialization logic.
initialize: function(){},
initialize: function(){
// No implementation.
},

// Return a copy of the model's `attributes` object.
toJSON: function(options) {
Expand Down
8 changes: 6 additions & 2 deletions packages/joint-core/src/mvc/ViewBase.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,15 @@ assign(ViewBase.prototype, Events, {

// preinitialize is an empty function by default. You can override it with a function
// or object. preinitialize will run before any instantiation logic is run in the View
preinitialize: function(){},
preinitialize: function(){
// No implementation.
},

// Initialize is an empty function by default. Override it with your own
// initialization logic.
initialize: function(){},
initialize: function(){
// No implementation.
},

// **render** is the core function that your view should override, in order
// to populate its element (`this.el`), with the appropriate HTML. The
Expand Down
9 changes: 5 additions & 4 deletions packages/joint-core/src/util/util.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,10 @@ export const parseDOMJSON = function(json, namespace) {
const groupSelectors = {};
const svgNamespace = V.namespace.svg;

const ns = namespace || svgNamespace;
const initialNS = namespace || svgNamespace;
const fragment = document.createDocumentFragment();

const parseNode = function(siblingsDef, parentNode, ns) {
const parseNode = function(siblingsDef, parentNode, parentNS) {
for (let i = 0; i < siblingsDef.length; i++) {
const nodeDef = siblingsDef[i];

Expand All @@ -100,7 +100,7 @@ export const parseDOMJSON = function(json, namespace) {
let node;

// Namespace URI
if (nodeDef.hasOwnProperty('namespaceURI')) ns = nodeDef.namespaceURI;
const ns = (nodeDef.hasOwnProperty('namespaceURI')) ? nodeDef.namespaceURI : parentNS;
node = document.createElementNS(ns, tagName);
const svg = (ns === svgNamespace);

Expand Down Expand Up @@ -152,7 +152,7 @@ export const parseDOMJSON = function(json, namespace) {
}
}
};
parseNode(json, fragment, ns);
parseNode(json, fragment, initialNS);
return {
fragment: fragment,
selectors: selectors,
Expand Down Expand Up @@ -1790,4 +1790,5 @@ export {
};

export const noop = function() {
// Do nothing.
};
4 changes: 2 additions & 2 deletions packages/joint-core/src/util/utilHelpers.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ const initCloneByTag = (object, tag, isDeep) => {
const Constructor = object.constructor;
switch(tag) {
case arrayBufferTag:
return cloneArrayBuffer(object, isDeep);
return cloneArrayBuffer(object);
case boolTag:
case dateTag:
return new Constructor(+object);
Expand Down Expand Up @@ -1281,7 +1281,7 @@ function last(array) {

const createSet = (Set && (1 / setToArray(new Set([undefined,-0]))[1]) == 1 / 0)
? (values) => new Set(values)
: () => {};
: () => { /* no-op */ };

function customDefaultsMerge(objValue, srcValue, key, object, source, stack) {
if (isObject(objValue) && isObject(srcValue)) {
Expand Down
10 changes: 5 additions & 5 deletions packages/joint-core/test/geometry/bezier.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@
QUnit.module('bezier', function() {

QUnit.module('curveThroughPoints(points)', function() {

// TODO: implement
});

QUnit.module('getCurveControlPoints(knots)', function() {

// TODO: implement
});

QUnit.module('getCurveDivider(p0, p1, p2, p3)', function() {

// TODO: implement
});

QUnit.module('getFirstControlPoints(rhs)', function() {

// TODO: implement
});

QUnit.module('getInversionSolver(p0, p1, p2, p3)', function() {

// TODO: implement
});
});
10 changes: 5 additions & 5 deletions packages/joint-core/test/geometry/ellipse.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,19 +133,19 @@ QUnit.module('ellipse', function() {
QUnit.module('prototype', function() {

QUnit.module('bbox()', function() {

// TODO: implement
});

QUnit.module('clone()', function() {

// TODO: implement
});

QUnit.module('equals(ellipse)', function() {

// TODO: implement
});

QUnit.module('intersectionWithLineFromCenterToPoint(point, angle)', function() {

// TODO: implement
});

QUnit.module('round()', function() {
Expand Down Expand Up @@ -180,7 +180,7 @@ QUnit.module('ellipse', function() {
});

QUnit.module('toString()', function() {

// TODO: implement
});
});
});
2 changes: 1 addition & 1 deletion packages/joint-core/test/geometry/index.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html>
<html>
<html lang="en">
<head>
<title>Geometry | Tests</title>
<link rel="stylesheet" href="../../node_modules/qunit/qunit/qunit.css">
Expand Down
8 changes: 4 additions & 4 deletions packages/joint-core/test/geometry/line.js
Original file line number Diff line number Diff line change
Expand Up @@ -460,11 +460,11 @@ QUnit.module('line', function() {
});

QUnit.module('length()', function() {

// TODO: implement
});

QUnit.module('midpoint()', function() {

// TODO: implement
});

QUnit.module('pointAt()', function() {
Expand Down Expand Up @@ -773,7 +773,7 @@ QUnit.module('line', function() {
});

QUnit.module('squaredLength()', function() {

// TODO: implement
});

QUnit.module('tangentAt()', function() {
Expand Down Expand Up @@ -873,7 +873,7 @@ QUnit.module('line', function() {
});

QUnit.module('toString()', function() {

// TODO: implement
});

QUnit.module('serialize()', function() {
Expand Down
4 changes: 2 additions & 2 deletions packages/joint-core/test/geometry/path.js
Original file line number Diff line number Diff line change
Expand Up @@ -2774,7 +2774,7 @@ QUnit.module('path', function(hooks) {
});

QUnit.module('lengthAtT()', function() {

// TODO: implement
});

QUnit.module('pointAt()', function() {
Expand Down Expand Up @@ -3151,7 +3151,7 @@ QUnit.module('path', function(hooks) {
});

QUnit.module('pointAtT()', function() {

// TODO: implement
});

QUnit.module('removeSegment()', function() {
Expand Down
Loading

0 comments on commit ba52ca3

Please sign in to comment.