Skip to content

Commit

Permalink
Update ESLint
Browse files Browse the repository at this point in the history
  • Loading branch information
lutzroeder committed Feb 16, 2019
1 parent 5450627 commit 5c0f084
Show file tree
Hide file tree
Showing 24 changed files with 1,168 additions and 281 deletions.
13 changes: 13 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"env": {
"browser": true,
"node": true,
"mocha": true
},
"extends": "eslint:recommended",
"rules": {
"indent": [ "error", 2 ],
"linebreak-style": [ "error", "unix" ],
"semi": [ "error", "always" ]
}
}
6 changes: 0 additions & 6 deletions .jscsrc

This file was deleted.

8 changes: 6 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ NPM = npm
BROWSERIFY = ./node_modules/browserify/bin/cmd.js
ISTANBUL = ./node_modules/istanbul/lib/cli.js
JSHINT = ./node_modules/jshint/bin/jshint
JSCS = ./node_modules/jscs/bin/jscs
ESLINT = ./node_modules/eslint/bin/eslint.js
KARMA = ./node_modules/karma/bin/karma
MOCHA = ./node_modules/mocha/bin/_mocha
PHANTOMJS = ./node_modules/phantomjs-prebuilt/bin/phantomjs
Expand All @@ -30,21 +30,25 @@ DIRS = $(BUILD_DIR) $(BUILD_DIR)/dist $(BUILD_DIR)/dist/demo

.PHONY: all clean browser-test demo-test test dist

all: test
all: test lint

lib/version.js: package.json
@src/release/make-version.js > $@

$(DIRS):
@mkdir -p $@

lint:
@$(ESLINT) $(SRC_FILES)

test: browser-test demo-test node-test

browser-test: $(BUILD_FILES)
$(KARMA) start --single-run $(KARMA_OPTS)
$(KARMA) start karma.core.conf.js --single-run $(KARMA_OPTS)

demo-test: test/demo-test.js | $(BUILD_FILES)
echo $(PHANTOMJS) $<
$(PHANTOMJS) $<

node-test: test/node-test.js | $(BUILD_FILES)
Expand Down
31 changes: 15 additions & 16 deletions lib/create-clusters.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,31 @@
var util = require("./util"),
d3 = require("./d3"),
addLabel = require("./label/add-label");
var util = require("./util");
var d3 = require("./d3");
var addLabel = require("./label/add-label");

module.exports = createClusters;

function createClusters(selection, g) {
var clusters = g.nodes().filter(function(v) { return util.isSubgraph(g, v); }),
svgClusters = selection.selectAll("g.cluster")
.data(clusters, function(v) { return v; });
var clusters = g.nodes().filter(function(v) { return util.isSubgraph(g, v); });
var svgClusters = selection.selectAll("g.cluster")
.data(clusters, function(v) { return v; });

svgClusters.selectAll("*").remove();
svgClusters.enter()
.append("g")
.attr("class", "cluster")
.attr("id",function(v){
var node = g.node(v);
return node.id;
})
.style("opacity", 0);
svgClusters.enter().append("g")
.attr("class", "cluster")
.attr("id",function(v){
var node = g.node(v);
return node.id;
})
.style("opacity", 0);

svgClusters = selection.selectAll("g.cluster");

util.applyTransition(svgClusters, g)
.style("opacity", 1);

svgClusters.each(function(v) {
var node = g.node(v),
thisGroup = d3.select(this);
var node = g.node(v);
var thisGroup = d3.select(this);
d3.select(this).append("rect");
var labelGroup = thisGroup.append("g").attr("class", "label");
addLabel(labelGroup, node, node.clusterLabelPos);
Expand Down
23 changes: 11 additions & 12 deletions lib/create-edge-labels.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"use strict";

var _ = require("./lodash"),
addLabel = require("./label/add-label"),
util = require("./util"),
d3 = require("./d3");
var _ = require("./lodash");
var addLabel = require("./label/add-label");
var util = require("./util");
var d3 = require("./d3");

module.exports = createEdgeLabels;

Expand All @@ -13,19 +13,18 @@ function createEdgeLabels(selection, g) {
.classed("update", true);

svgEdgeLabels.exit().remove();
svgEdgeLabels.enter()
.append("g")
.classed("edgeLabel", true)
.style("opacity", 0);
svgEdgeLabels.enter().append("g")
.classed("edgeLabel", true)
.style("opacity", 0);

svgEdgeLabels = selection.selectAll("g.edgeLabel");

svgEdgeLabels.each(function(e) {
var root = d3.select(this);
root.select('.label').remove();
var edge = g.edge(e),
label = addLabel(root, g.edge(e), 0, 0).classed("label", true),
bbox = label.node().getBBox();
root.select(".label").remove();
var edge = g.edge(e);
var label = addLabel(root, g.edge(e), 0, 0).classed("label", true);
var bbox = label.node().getBBox();

if (edge.labelId) { label.attr("id", edge.labelId); }
if (!_.has(edge, "width")) { edge.width = bbox.width; }
Expand Down
45 changes: 22 additions & 23 deletions lib/create-edge-paths.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"use strict";

var _ = require("./lodash"),
intersectNode = require("./intersect/intersect-node"),
util = require("./util"),
d3 = require("./d3");
var _ = require("./lodash");
var intersectNode = require("./intersect/intersect-node");
var util = require("./util");
var d3 = require("./d3");
module.exports = createEdgePaths;

function createEdgePaths(selection, g, arrows) {
Expand Down Expand Up @@ -39,7 +39,7 @@ function createEdgePaths(selection, g, arrows) {

var domEdge = d3.select(this)
.attr("marker-end", function() {
return "url(" + makeFragmentRef(location.href, edge.arrowheadId) + ")";
return "url(" + makeFragmentRef(location.href, edge.arrowheadId) + ")";
})
.style("fill", "none");

Expand All @@ -52,8 +52,8 @@ function createEdgePaths(selection, g, arrows) {
svgPaths.selectAll("defs *").remove();
svgPaths.selectAll("defs")
.each(function(e) {
var edge = g.edge(e),
arrowhead = arrows[edge.arrowhead];
var edge = g.edge(e);
var arrowhead = arrows[edge.arrowhead];
arrowhead(d3.select(this), edge.arrowheadId, edge, "arrowhead");
});

Expand All @@ -66,10 +66,10 @@ function makeFragmentRef(url, fragmentId) {
}

function calcPoints(g, e) {
var edge = g.edge(e),
tail = g.node(e.v),
head = g.node(e.w),
points = edge.points.slice(1, edge.points.length - 1);
var edge = g.edge(e);
var tail = g.node(e.v);
var head = g.node(e.w);
var points = edge.points.slice(1, edge.points.length - 1);
points.unshift(intersectNode(tail, points[0]));
points.push(intersectNode(head, points[points.length - 1]));

Expand All @@ -87,25 +87,24 @@ function createLine(edge, points) {
}

function getCoords(elem) {
var bbox = elem.getBBox(),
matrix = elem.ownerSVGElement.getScreenCTM()
.inverse()
.multiply(elem.getScreenCTM())
.translate(bbox.width / 2, bbox.height / 2);
var bbox = elem.getBBox();
var matrix = elem.ownerSVGElement.getScreenCTM()
.inverse()
.multiply(elem.getScreenCTM())
.translate(bbox.width / 2, bbox.height / 2);
return { x: matrix.e, y: matrix.f };
}

function enter(svgPaths, g) {
var svgPathsEnter = svgPaths.enter()
.append("g")
.attr("class", "edgePath")
.style("opacity", 0);
var svgPathsEnter = svgPaths.enter().append("g")
.attr("class", "edgePath")
.style("opacity", 0);
svgPathsEnter.append("path")
.attr("class", "path")
.attr("d", function(e) {
var edge = g.edge(e),
sourceElem = g.node(e.v).elem,
points = _.range(edge.points.length).map(function() { return getCoords(sourceElem); });
var edge = g.edge(e);
var sourceElem = g.node(e.v).elem;
var points = _.range(edge.points.length).map(function() { return getCoords(sourceElem); });
return createLine(edge, points);
});
svgPathsEnter.append("defs");
Expand Down
27 changes: 13 additions & 14 deletions lib/create-nodes.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"use strict";

var _ = require("./lodash"),
addLabel = require("./label/add-label"),
util = require("./util"),
d3 = require("./d3");
var _ = require("./lodash");
var addLabel = require("./label/add-label");
var util = require("./util");
var d3 = require("./d3");

module.exports = createNodes;

Expand All @@ -15,24 +15,23 @@ function createNodes(selection, g, shapes) {

svgNodes.exit().remove();

svgNodes.enter()
.append("g")
.attr("class", "node")
.style("opacity", 0);
svgNodes.enter().append("g")
.attr("class", "node")
.style("opacity", 0);

svgNodes = selection.selectAll("g.node");

svgNodes.each(function(v) {
var node = g.node(v),
thisGroup = d3.select(this);
var node = g.node(v);
var thisGroup = d3.select(this);
util.applyClass(thisGroup, node["class"],
(thisGroup.classed("update") ? "update " : "") + "node");

thisGroup.select("g.label").remove();
var labelGroup = thisGroup.append("g").attr("class", "label"),
labelDom = addLabel(labelGroup, node),
shape = shapes[node.shape],
bbox = _.pick(labelDom.node().getBBox(), "width", "height");
var labelGroup = thisGroup.append("g").attr("class", "label");
var labelDom = addLabel(labelGroup, node);
var shape = shapes[node.shape];
var bbox = _.pick(labelDom.node().getBBox(), "width", "height");

node.elem = this;

Expand Down
1 change: 1 addition & 0 deletions lib/d3.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ if (!d3) {
d3 = require("d3");
}
catch (e) {
// continue regardless of error
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion lib/dagre.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ var dagre;
if (typeof require === "function") {
try {
dagre = require("dagre");
} catch (e) {}
} catch (e) {
// continue regardless of error
}
}

if (!dagre) {
Expand Down
5 changes: 4 additions & 1 deletion lib/graphlib.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ var graphlib;
if (typeof require === "function") {
try {
graphlib = require("graphlib");
} catch (e) {}
}
catch (e) {
// continue regardless of error
}
}

if (!graphlib) {
Expand Down
18 changes: 10 additions & 8 deletions lib/intersect/intersect-polygon.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint "no-console": off */

var intersectLine = require("./intersect-line");

module.exports = intersectPolygon;
Expand All @@ -12,8 +14,8 @@ function intersectPolygon(node, polyPoints, point) {

var intersections = [];

var minX = Number.POSITIVE_INFINITY,
minY = Number.POSITIVE_INFINITY;
var minX = Number.POSITIVE_INFINITY;
var minY = Number.POSITIVE_INFINITY;
polyPoints.forEach(function(entry) {
minX = Math.min(minX, entry.x);
minY = Math.min(minY, entry.y);
Expand All @@ -40,13 +42,13 @@ function intersectPolygon(node, polyPoints, point) {
if (intersections.length > 1) {
// More intersections, find the one nearest to edge end point
intersections.sort(function(p, q) {
var pdx = p.x - point.x,
pdy = p.y - point.y,
distp = Math.sqrt(pdx * pdx + pdy * pdy),
var pdx = p.x - point.x;
var pdy = p.y - point.y;
var distp = Math.sqrt(pdx * pdx + pdy * pdy);

qdx = q.x - point.x,
qdy = q.y - point.y,
distq = Math.sqrt(qdx * qdx + qdy * qdy);
var qdx = q.x - point.x;
var qdy = q.y - point.y;
var distq = Math.sqrt(qdx * qdx + qdy * qdy);

return (distp < distq) ? -1 : (distp === distq ? 0 : 1);
});
Expand Down
18 changes: 9 additions & 9 deletions lib/label/add-html-label.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,22 @@ module.exports = addHtmlLabel;
function addHtmlLabel(root, node) {
var fo = root
.append("foreignObject")
.attr("width", "100000");
.attr("width", "100000");

var div = fo
.append("xhtml:div");
div.attr("xmlns", "http://www.w3.org/1999/xhtml");

var label = node.label;
switch(typeof label) {
case "function":
div.insert(label);
break;
case "object":
// Currently we assume this is a DOM object.
div.insert(function() { return label; });
break;
default: div.html(label);
case "function":
div.insert(label);
break;
case "object":
// Currently we assume this is a DOM object.
div.insert(function() { return label; });
break;
default: div.html(label);
}

util.applyStyle(div, node.labelStyle);
Expand Down
Loading

0 comments on commit 5c0f084

Please sign in to comment.