Skip to content

Commit

Permalink
Makes Network, DataSet and DataView eslint compliant (almende#3304)
Browse files Browse the repository at this point in the history
* Makes network eslint compliant
Unused variables in private functions, who were never called internally with those arguments were removed.
lint rule was disabled for public functions, and in private functions which were called internally with those unused arguments

* Disables linting for unused args passed into DataSet and DataView
  • Loading branch information
macleodbroad-wf authored and Primoz Susa committed Jan 3, 2019
1 parent dff0ce1 commit c9e038c
Show file tree
Hide file tree
Showing 21 changed files with 49 additions and 52 deletions.
2 changes: 1 addition & 1 deletion lib/DataSet.js
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ DataSet.prototype.update = function (data, senderId) {
* {String | function} [order] Order the items by a field name or custom sort function.
* @throws Error
*/
DataSet.prototype.get = function (args) {
DataSet.prototype.get = function (args) { // eslint-disable-line no-unused-vars
var me = this;

// parse the arguments
Expand Down
2 changes: 1 addition & 1 deletion lib/DataView.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ DataView.prototype.refresh = function () {
* DataTable.
* @param args
*/
DataView.prototype.get = function (args) {
DataView.prototype.get = function (args) { // eslint-disable-line no-unused-vars
var me = this;

// parse the arguments
Expand Down
3 changes: 2 additions & 1 deletion lib/network/CachedImage.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
* for svg, but the mipmapping may not be necessary.
*/
class CachedImage {
// eslint-disable-next-line no-unused-vars
constructor(image) {
this.NUM_ITERATIONS = 4; // Number of items in the coordinates array

Expand Down Expand Up @@ -138,7 +139,7 @@ class CachedImage {
*
* @private
*/
_isImageOk(img) {
_isImageOk() {
var img = this.image;

// During the onload event, IE correctly identifies any images that
Expand Down
2 changes: 1 addition & 1 deletion lib/network/Images.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class Images {
* @param {string} brokenUrl Url of an image to use if the url image is not found
* @return {Image} img The image object
*/
load (url, brokenUrl, id) {
load (url, brokenUrl, id) { // eslint-disable-line no-unused-vars
//Try and get the image from the cache, if successful then return the cached image
var cachedImage = this.images[url];
if (cachedImage) return cachedImage;
Expand Down
2 changes: 0 additions & 2 deletions lib/network/Network.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ require('./shapes');

let Emitter = require('emitter-component');
let util = require('../util');
let DataSet = require('../DataSet');
let DataView = require('../DataView');
let dotparser = require('./dotparser');
let gephiParser = require('./gephiParser');
let Activator = require('../shared/Activator');
Expand Down
4 changes: 2 additions & 2 deletions lib/network/gephiParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ function parseGephi(gephiJSON, optionsObj) {
edges.push(edge);
}

for (var i = 0; i < gNodes.length; i++) {
for (var j = 0; j < gNodes.length; j++) {
var node = {};
var gNode = gNodes[i];
var gNode = gNodes[j];
node['id'] = gNode.id;
node['attributes'] = gNode.attributes;
node['x'] = gNode.x;
Expand Down
2 changes: 1 addition & 1 deletion lib/network/modules/Canvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ class Canvas {
// set initialized so the get and set camera will work from now on.
this.initialized = true;
return emitEvent;
};
}


getContext() {
Expand Down
2 changes: 1 addition & 1 deletion lib/network/modules/Clustering.js
Original file line number Diff line number Diff line change
Expand Up @@ -902,7 +902,7 @@ class ClusterEngine {
}

return hubThreshold;
};
}


/**
Expand Down
1 change: 0 additions & 1 deletion lib/network/modules/EdgesHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ var DataView = require('../../DataView');

var Edge = require("./components/Edge").default;
var Label = require("./components/shared/Label").default;
var LayoutEngine = require("./LayoutEngine").default; // For access to LayoutEngine.getStaticType()

class EdgesHandler {
constructor(body, images, groups) {
Expand Down
19 changes: 10 additions & 9 deletions lib/network/modules/LayoutEngine.js
Original file line number Diff line number Diff line change
Expand Up @@ -616,17 +616,13 @@ class LayoutEngine {
// get the size of the largest hubs and check if the user has defined a level for a node.
let node, nodeId;
let definedLevel = false;
let definedPositions = true;
let undefinedLevel = false;
this.lastNodeOnLevel = {};
this.hierarchical = new HierarchicalStatus();

for (nodeId in this.body.nodes) {
if (this.body.nodes.hasOwnProperty(nodeId)) {
node = this.body.nodes[nodeId];
if (node.options.x === undefined && node.options.y === undefined) {
definedPositions = false;
}
if (node.options.level !== undefined) {
definedLevel = true;
this.hierarchical.levels[nodeId] = node.options.level;
Expand Down Expand Up @@ -779,7 +775,7 @@ class LayoutEngine {
}

return [min, max, minSpace, maxSpace];
};
}


// check what the maximum level is these nodes have in common.
Expand Down Expand Up @@ -832,8 +828,11 @@ class LayoutEngine {

// check the largest distance between the branches
let maxLevel = getCollisionLevel(node1, node2);
let [min1,max1, minSpace1, maxSpace1] = getBranchBoundary(branchNodes1, maxLevel);
let [min2,max2, minSpace2, maxSpace2] = getBranchBoundary(branchNodes2, maxLevel);
let branchNodeBoundary1 = getBranchBoundary(branchNodes1, maxLevel);
let branchNodeBoundary2 = getBranchBoundary(branchNodes2, maxLevel);
let max1 = branchNodeBoundary1[1];
let min2 = branchNodeBoundary2[0];
let minSpace2 = branchNodeBoundary2[2];

//console.log(node1.id, getBranchBoundary(branchNodes1, maxLevel), node2.id,
// getBranchBoundary(branchNodes2, maxLevel), maxLevel);
Expand Down Expand Up @@ -935,7 +934,9 @@ class LayoutEngine {
getBranchNodes(node, branchNodes);
branches[node.id] = branchNodes;
}
let [minBranch, maxBranch, minSpaceBranch, maxSpaceBranch] = getBranchBoundary(branches[node.id]);
let branchBoundary = getBranchBoundary(branches[node.id]);
let minSpaceBranch = branchBoundary[2];
let maxSpaceBranch = branchBoundary[3];

let diff = guess - nodePosition;

Expand Down Expand Up @@ -1389,7 +1390,7 @@ class LayoutEngine {
let minLevel = 100000;

// TODO: this should come from options.
let customCallback = function(nodeA, nodeB, edge) {
let customCallback = function(nodeA, nodeB, edge) { // eslint-disable-line no-unused-vars

};

Expand Down
7 changes: 4 additions & 3 deletions lib/network/modules/ManipulationSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -696,10 +696,11 @@ class ManipulationSystem {
}

_createDeleteButton(locale) {
var deleteBtnClass;
if (this.options.rtl) {
var deleteBtnClass = 'vis-button vis-delete-rtl';
deleteBtnClass = 'vis-button vis-delete-rtl';
} else {
var deleteBtnClass = 'vis-button vis-delete';
deleteBtnClass = 'vis-button vis-delete';
}
let button = this._createButton('delete', deleteBtnClass, locale['del'] || this.options.locales['en']['del']);
this.manipulationDiv.appendChild(button);
Expand Down Expand Up @@ -840,7 +841,7 @@ class ManipulationSystem {
* @param event
* @private
*/
_controlNodeDragStart(event) {
_controlNodeDragStart(event) { // eslint-disable-line no-unused-vars
let pointer = this.lastTouch;
let pointerObj = this.selectionHandler._pointerToPositionObject(pointer);
let from = this.body.nodes[this.temporaryIds.nodes[0]];
Expand Down
2 changes: 1 addition & 1 deletion lib/network/modules/View.js
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ class View {
}
this.body.emitter.emit("animationFinished");
}
};
}


getScale() {
Expand Down
1 change: 0 additions & 1 deletion lib/network/modules/components/NavigationHandler.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
var util = require('../../../util');
var Hammer = require('../../../module/hammer');
var hammerUtil = require('../../../hammerUtil');
var keycharm = require('keycharm');
Expand Down
1 change: 0 additions & 1 deletion lib/network/modules/components/Node.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ var Star = require('./nodes/shapes/Star').default;
var Text = require('./nodes/shapes/Text').default;
var Triangle = require('./nodes/shapes/Triangle').default;
var TriangleDown = require('./nodes/shapes/TriangleDown').default;
var Validator = require("../../../shared/Validator").default;
var { printStyle } = require("../../../shared/Validator");


Expand Down
10 changes: 6 additions & 4 deletions lib/network/modules/components/edges/util/EdgeBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class EdgeBase {
}
}

_drawDashedLine(ctx, values, viaNode, fromPoint, toPoint) {
_drawDashedLine(ctx, values, viaNode, fromPoint, toPoint) { // eslint-disable-line no-unused-vars
ctx.lineCap = 'round';
let pattern = [5,5];
if (Array.isArray(values.dashes) === true) {
Expand Down Expand Up @@ -129,7 +129,7 @@ class EdgeBase {
to = this._findBorderPosition(this.to, ctx);
}
else {
let [x,y,radius] = this._getCircleData(ctx);
let [x,y] = this._getCircleData(ctx).slice(0, 2);

from = this._findBorderPositionCircle(this.from, ctx, {x, y, low:0.25, high:0.6, direction:-1});
to = this._findBorderPositionCircle(this.from, ctx, {x, y, low:0.6, high:0.8, direction:1});
Expand Down Expand Up @@ -255,7 +255,7 @@ class EdgeBase {
}


getColor(ctx, values, selected, hover) {
getColor(ctx, values, selected, hover) { // eslint-disable-line no-unused-vars
if (values.inheritsColor !== false) {
// when this is a loop edge, just use the 'from' method
if ((values.inheritsColor === 'both') && (this.from.id !== this.to.id)) {
Expand Down Expand Up @@ -316,16 +316,18 @@ class EdgeBase {
/**
* Calculate the distance between a point (x3,y3) and a line segment from
* (x1,y1) to (x2,y2).
* x3,y3 is the point.
* http://stackoverflow.com/questions/849211/shortest-distancae-between-a-point-and-a-line-segment
* @param {number} x1
* @param {number} y1
* @param {number} x2
* @param {number} y2
* @param {number} x3
* @param {number} y3
* @param via
* @private
*/
getDistanceToEdge(x1, y1, x2, y2, x3, y3, via, values) { // x3,y3 is the point
getDistanceToEdge(x1, y1, x2, y2, x3, y3, via, values) { // eslint-disable-line no-unused-vars
let returnValue = 0;
if (this.from != this.to) {
returnValue = this._getDistanceToEdge(x1, y1, x2, y2, x3, y3, via)
Expand Down
4 changes: 2 additions & 2 deletions lib/network/modules/components/nodes/shapes/Circle.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import CircleImageBase from '../util/CircleImageBase'

class Circle extends CircleImageBase {
constructor(options, body, labelModule) {
super(options, body, labelModule)
super(options, body, labelModule);
this._setMargins(labelModule);
}

Expand Down Expand Up @@ -40,7 +40,7 @@ class Circle extends CircleImageBase {
this.boundingBox.bottom = y + this.options.size;
}

distanceToBorder(ctx, angle) {
distanceToBorder(ctx, angle) { // eslint-disable-line no-unused-vars
this.resize(ctx);
return this.width * 0.5;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class CircularImage extends CircleImageBase {
}


distanceToBorder(ctx, angle) {
distanceToBorder(ctx, angle) { // eslint-disable-line no-unused-vars
this.resize(ctx);
return this.width * 0.5;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/network/modules/components/nodes/shapes/Dot.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Dot extends ShapeBase {
this._drawShape(ctx, 'circle', 2, x, y, selected, hover, values);
}

distanceToBorder(ctx, angle) {
distanceToBorder(ctx, angle) { // eslint-disable-line no-unused-vars
this.resize(ctx);
return this.options.size;
}
Expand Down
8 changes: 3 additions & 5 deletions lib/network/modules/components/nodes/util/CircleImageBase.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import NodeBase from './NodeBase';
import CachedImage from '../../../../CachedImage';


/**
* NOTE: This is a bad base class
Expand Down Expand Up @@ -86,11 +84,11 @@ class CircleImageBase extends NodeBase {

// Only calculate the proper ratio if both width and height not zero
if (this.imageObj.width && this.imageObj.height) {
if (this.imageObj.width > this.imageObj.height) {
ratio_width = this.imageObj.width / this.imageObj.height;
if (this.imageObj.width > this.imageObj.height) {
ratio_width = this.imageObj.width / this.imageObj.height;
}
else {
ratio_height = this.imageObj.height / this.imageObj.width;
ratio_height = this.imageObj.height / this.imageObj.width;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class HierarchicalSpringSolver {
}

// normalize spring forces
var springForce = 1;
springForce = 1;
var springFx, springFy;
for (let i = 0; i < nodeIndices.length; i++) {
let nodeId = nodeIndices[i];
Expand Down Expand Up @@ -101,7 +101,6 @@ class HierarchicalSpringSolver {
forces[nodeId].y -= correctionFy;
}
}

}

export default HierarchicalSpringSolver;
export default HierarchicalSpringSolver;
20 changes: 10 additions & 10 deletions lib/network/modules/components/shared/Label.js
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,7 @@ class Label {
};
s.mod = function() {
return (this.modStack.length === 0) ? 'normal' : this.modStack[0];
}
};
s.modName = function() {
if (this.modStack.length === 0)
return 'normal';
Expand All @@ -678,8 +678,8 @@ class Label {
return 'ital';
}
}
}
s.emitBlock = function(override = false) {
};
s.emitBlock = function(override=false) { // eslint-disable-line no-unused-vars
if (this.spacing) {
this.add(" ");
this.spacing = false;
Expand All @@ -688,7 +688,7 @@ class Label {
blocks.push({ text: this.buffer, mod: this.modName() });
this.buffer = "";
}
}
};
s.add = function(text) {
if (text === " ") {
s.spacing = true;
Expand All @@ -700,7 +700,7 @@ class Label {
if (text != " ") {
this.buffer += text;
}
}
};
while (s.position < text.length) {
let ch = text.charAt(s.position);
if (/[ \t]/.test(ch)) {
Expand Down Expand Up @@ -780,7 +780,7 @@ class Label {
};
s.mod = function() {
return (this.modStack.length === 0) ? 'normal' : this.modStack[0];
}
};
s.modName = function() {
if (this.modStack.length === 0)
return 'normal';
Expand All @@ -795,8 +795,8 @@ class Label {
return 'ital';
}
}
}
s.emitBlock = function(override = false) {
};
s.emitBlock = function(override=false) { // eslint-disable-line no-unused-vars
if (this.spacing) {
this.add(" ");
this.spacing = false;
Expand All @@ -805,7 +805,7 @@ class Label {
blocks.push({ text: this.buffer, mod: this.modName() });
this.buffer = "";
}
}
};
s.add = function(text) {
if (text === " ") {
s.spacing = true;
Expand All @@ -817,7 +817,7 @@ class Label {
if (text != " ") {
this.buffer += text;
}
}
};
while (s.position < text.length) {
let ch = text.charAt(s.position);
if (/[ \t]/.test(ch)) {
Expand Down

0 comments on commit c9e038c

Please sign in to comment.