Skip to content

Commit f4193ed

Browse files
committed
Merge pull request #153 from GordonSmith/ECLWATCH_GRAPH
More support for ECL Watch Graphs:
2 parents 90a3382 + a7b7b80 commit f4193ed

File tree

3 files changed

+79
-11
lines changed

3 files changed

+79
-11
lines changed

build.sh

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
#!/usr/bin/env bash
2-
nodejs ./util/r.js -o ./util/build.js
3-
2+
if which node >/dev/null; then
3+
node ./util/r.js -o ./util/build.js
4+
else
5+
echo "node.js is required to build - see https://github.com/joyent/node/wiki/Installing-Node.js-via-package-manager"
6+
exit 1
7+
fi

widgets/src/graph/Graph.js

Lines changed: 72 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,52 @@
55
root.Graph = factory(root.d3, root.SVGWidget, root.IGraph, root.Vertex, root.GraphData, root.GraphLayouts);
66
}
77
}(this, function (d3, SVGWidget, IGraph, Vertex, GraphData, GraphLayouts) {
8+
function SelectionBag() {
9+
this.items = {};
10+
};
11+
12+
SelectionBag.prototype = {
13+
clear: function () {
14+
for (var key in this.items) {
15+
this.items[key].element().classed("selected", false);
16+
}
17+
this.items = {};
18+
},
19+
append: function (item) {
20+
this.items[item._id] = item;
21+
item.element().classed("selected", true);
22+
},
23+
remove: function (item) {
24+
this.items[item._id].element().classed("selected", false);
25+
delete this.items[item._id];
26+
},
27+
get: function () {
28+
var retVal = [];
29+
for (var key in this.items) {
30+
retVal.push(this.items[key]);
31+
}
32+
return retVal;
33+
},
34+
set: function (itemArray) {
35+
this.clear();
36+
itemArray.forEach(function (item, idx) {
37+
this.append(item);
38+
}, this);
39+
},
40+
click: function (item, d3Event) {
41+
if (d3Event.ctrlKey) {
42+
if (this.items[item._id]) {
43+
this.remove(item);
44+
} else {
45+
this.append(item);
46+
}
47+
} else {
48+
this.clear();
49+
this.append(item);
50+
}
51+
}
52+
};
53+
854
function Graph() {
955
SVGWidget.call(this);
1056
IGraph.call(this);
@@ -27,6 +73,7 @@
2773
this._hierarchyOptions = { };
2874
this._snapToGrid = 0;
2975
this._allowDragging = true;
76+
this._selection = new SelectionBag();
3077
};
3178
Graph.prototype = Object.create(SVGWidget.prototype);
3279
Graph.prototype.implements(IGraph.prototype);
@@ -49,6 +96,10 @@
4996
return retVal;
5097
};
5198

99+
Graph.prototype.clear = function () {
100+
this.data({ vertices: [], edges: [], hierarchy: [], merge: false });
101+
};
102+
52103
Graph.prototype.data = function (_) {
53104
var retVal = SVGWidget.prototype.data.apply(this, arguments);
54105
if (arguments.length) {
@@ -117,6 +168,12 @@
117168
return this;
118169
};
119170

171+
Graph.prototype.selection = function (_) {
172+
if (!arguments.length) return this._selection.get();
173+
this._selection.set(_);
174+
return this;
175+
};
176+
120177
Graph.prototype.setZoom = function (translation, scale, transitionDuration) {
121178
if (this.zoom) {
122179
this.zoom.translate(translation);
@@ -216,13 +273,15 @@
216273
.attr("y", -this._size.height / 2)
217274
.attr("width", this._size.width)
218275
.attr("height", this._size.height)
219-
.call(this.zoom)
220276
;
221277

222278
this.defs = element.append("defs");
223279
this.addMarkers();
224280

281+
element.call(this.zoom);
282+
225283
this.svg = element.append("g");
284+
this.svgC = this.svg.append("g").attr("id", this._id + "C");
226285
this.svgE = this.svg.append("g").attr("id", this._id + "E");
227286
this.svgV = this.svg.append("g").attr("id", this._id + "V");
228287
};
@@ -278,7 +337,7 @@
278337
this.setZoom(translate, 1, transitionDuration);
279338
};
280339

281-
Graph.prototype.layout = function (_) {
340+
Graph.prototype.layout = function (_, transitionDuration) {
282341
if (!arguments.length) return this._layout;
283342
this._layout = _;
284343
if (this._renderCount) {
@@ -322,18 +381,18 @@
322381
context._dragging = true;
323382
context.graphData.nodeValues().forEach(function (item) {
324383
var pos = layoutEngine.nodePos(item._id);
325-
item.move({ x: pos.x, y: pos.y }, context._transitionDuration);
384+
item.move({ x: pos.x, y: pos.y }, transitionDuration);
326385
if (pos.width && pos.height && !item.width() && !item.height()) {
327386
item
328-
.size({ width: pos.width, height: pos.height }, context._transitionDuration)
387+
.size({ width: pos.width, height: pos.height }, transitionDuration)
329388
.render()
330389
;
331390
}
332391
});
333392
context.graphData.edgeValues().forEach(function (item) {
334393
var points = layoutEngine.edgePoints({v: item._sourceVertex.id(), w: item._targetVertex.id()});
335394
item
336-
.points(points, context._transitionDuration)
395+
.points(points, transitionDuration)
337396
;
338397
});
339398

@@ -344,7 +403,7 @@
344403
this._fixIEMarkers();
345404
setTimeout(function() {
346405
context._dragging = false;
347-
}, context._transitionDuration + 50); // Prevents highlighting during morph ---
406+
}, transitionDuration ? transitionDuration + 50 : 50); // Prevents highlighting during morph ---
348407
}
349408
}
350409
return this;
@@ -361,11 +420,16 @@
361420
.attr("class", "graphVertex")
362421
.style("opacity", 1e-6)
363422
// TODO: Events need to be optional ---
423+
.on("click.selectionBag", function (d) {
424+
context._selection.click(d, d3.event);
425+
})
364426
.on("click", function (d) {
365-
context.vertex_click(d);
427+
d3.event.stopPropagation();
428+
context.vertex_click(d, d3.event);
366429
})
367430
.on("dblclick", function (d) {
368-
context.vertex_dblclick(d);
431+
d3.event.stopPropagation();
432+
context.vertex_dblclick(d, d3.event);
369433
})
370434
.on("mouseover", function (d) {
371435
if (context._dragging)

widgets/src/graph/GraphData.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
this.filterEdges(function (item) { return edgeIDs.indexOf(item.v + "_" + item.w) < 0; })
4848
.forEach(function (item) {
4949
try {
50-
context.delEdge(item);
50+
//TODO: context.delEdge(item);
5151
} catch (e) {
5252
var d = 0;
5353
}

0 commit comments

Comments
 (0)