From a2a9194b1e51589be5dcbe7dc2984c71df060564 Mon Sep 17 00:00:00 2001 From: Michael Hackstein Date: Fri, 31 May 2013 18:27:10 +0200 Subject: [PATCH] GraphViewer: Fixed several tests that did fail --- html/admin/css/graphView.css | 3 +-- .../js/graphViewer/graph/eventDispatcher.js | 2 +- html/admin/js/graphViewer/graph/nodeShaper.js | 10 +++++---- .../specEvents/eventDispatcherUISpec.js | 21 +++++++++++-------- .../specNodeShaper/nodeShaperSpec.js | 17 +++++++++++++++ .../graphViewer/ui/eventDispatcherControls.js | 4 ++-- .../js/graphViewer/ui/modalDialogHelper.js | 18 ++++++++++------ 7 files changed, 51 insertions(+), 24 deletions(-) diff --git a/html/admin/css/graphView.css b/html/admin/css/graphView.css index be29b16aa0..49cbae79dd 100644 --- a/html/admin/css/graphView.css +++ b/html/admin/css/graphView.css @@ -28,9 +28,8 @@ } svg.graphViewer text { - font: 11px Arial; + font: 12px Arial; pointer-events: none; - stroke: #000; } .capitalize { diff --git a/html/admin/js/graphViewer/graph/eventDispatcher.js b/html/admin/js/graphViewer/graph/eventDispatcher.js index 818320008d..f28348a445 100644 --- a/html/admin/js/graphViewer/graph/eventDispatcher.js +++ b/html/admin/js/graphViewer/graph/eventDispatcher.js @@ -1,5 +1,5 @@ /*jslint indent: 2, nomen: true, maxlen: 100, sloppy: true, vars: true, white: true, plusplus: true */ -/*global _, $, window*/ +/*global _, $, window, d3*/ /*global EventLibrary*/ //////////////////////////////////////////////////////////////////////////////// /// @brief Graph functionality diff --git a/html/admin/js/graphViewer/graph/nodeShaper.js b/html/admin/js/graphViewer/graph/nodeShaper.js index 35ed29eca0..1a4b87ca70 100644 --- a/html/admin/js/graphViewer/graph/nodeShaper.js +++ b/html/admin/js/graphViewer/graph/nodeShaper.js @@ -214,14 +214,14 @@ function NodeShaper(parent, flags, idfunc) { if (_.isFunction(width)) { translateX = function(d) { return -(width(d) / 2); - } + }; } else { translateX = -(width / 2); } if (_.isFunction(height)) { translateY = function(d) { return -(height(d) / 2); - } + }; } else { translateY = -(height / 2); } @@ -245,14 +245,16 @@ function NodeShaper(parent, flags, idfunc) { addLabel = function (node) { node.append("text") // Append a label for the node .attr("text-anchor", "middle") // Define text-anchor - .attr("stroke", "black") // Foce a black color20*75) + .attr("fill", "black") // Force a black color + .attr("stroke", "none") // Make it readable .text(label); }; } else { addLabel = function (node) { node.append("text") // Append a label for the node .attr("text-anchor", "middle") // Define text-anchor - .attr("stroke", "black") // Foce a black color20*75) + .attr("fill", "black") // Force a black color + .attr("stroke", "none") // Make it readable .text(function(d) { return d._data[label] !== undefined ? d._data[label] : ""; }); diff --git a/html/admin/js/graphViewer/jasmine_test/specEvents/eventDispatcherUISpec.js b/html/admin/js/graphViewer/jasmine_test/specEvents/eventDispatcherUISpec.js index f10ad66e0d..ee7390b96d 100644 --- a/html/admin/js/graphViewer/jasmine_test/specEvents/eventDispatcherUISpec.js +++ b/html/admin/js/graphViewer/jasmine_test/specEvents/eventDispatcherUISpec.js @@ -291,8 +291,6 @@ expect(adapter.patchEdge).toHaveBeenCalledWith( edges[0], { - _from: "1", - _to: "2", label: "newLabel" }, jasmine.any(Function)); @@ -425,22 +423,27 @@ helper.simulateMouseEvent("mousedown", "2"); expect(edgeShaper.addAnEdgeFollowingTheCursor).toHaveBeenCalledWith( - 0, 0 + -$("svg").offset().left, -$("svg").offset().top ); }); it('the cursor-line should follow the cursor on mousemove over svg', function() { dispatcherUI.addControlConnect(); + var x = 40, + y= 50, + line; + helper.simulateMouseEvent("click", "control_event_connect"); helper.simulateMouseEvent("mousedown", "2"); - helper.simulateMouseMoveEvent("svg", 40, 50); + helper.simulateMouseMoveEvent("svg", x, y); - var line = $("#connectionLine"); - expect(line.attr("x1")).toEqual(String(nodes[1].x)); - expect(line.attr("y1")).toEqual(String(nodes[1].y)); - expect(line.attr("x2")).toEqual("40"); - expect(line.attr("y2")).toEqual("50"); + line = $("#connectionLine"); + //The Helper event triggers at (0,0) no matter where the node is. + expect(line.attr("x1")).toEqual(String(- $("svg").offset().left)); + expect(line.attr("y1")).toEqual(String(- $("svg").offset().top)); + expect(line.attr("x2")).toEqual(String(x - $("svg").offset().left)); + expect(line.attr("y2")).toEqual(String(y - $("svg").offset().top)); }); it('the cursor-line should disappear on mouseup on svg', function() { diff --git a/html/admin/js/graphViewer/jasmine_test/specNodeShaper/nodeShaperSpec.js b/html/admin/js/graphViewer/jasmine_test/specNodeShaper/nodeShaperSpec.js index 76dcf7a3eb..02fdfa7769 100644 --- a/html/admin/js/graphViewer/jasmine_test/specNodeShaper/nodeShaperSpec.js +++ b/html/admin/js/graphViewer/jasmine_test/specNodeShaper/nodeShaperSpec.js @@ -679,6 +679,23 @@ expect($("svg .node text")[0].textContent).toEqual("MyLabel"); }); + it('should set up the text element correctly', function() { + var node = [{ + _id: 1, + _data: { + "label": "MyLabel" + } + }], + textEl; + shaper.drawNodes(node); + textEl = $("svg .node text"); + expect(textEl.attr("fill")).toEqual("black"); + expect(textEl.attr("stroke")).toEqual("none"); + + + + }); + it('should ignore other attributes', function () { var nodes = [ { diff --git a/html/admin/js/graphViewer/ui/eventDispatcherControls.js b/html/admin/js/graphViewer/ui/eventDispatcherControls.js index a272432ed8..02675b8ef1 100644 --- a/html/admin/js/graphViewer/ui/eventDispatcherControls.js +++ b/html/admin/js/graphViewer/ui/eventDispatcherControls.js @@ -225,8 +225,8 @@ function EventDispatcherControls(list, cursorIconBox, nodeShaper, edgeShaper, di setCursorIcon(icon); rebindNodes({ mousedown: dispatcher.events.STARTCREATEEDGE(function(startNode, ev) { - var pos = getCursorPositionInSVG(ev); - var moveCB = edgeShaper.addAnEdgeFollowingTheCursor(pos.x, pos.y); + var pos = getCursorPositionInSVG(ev), + moveCB = edgeShaper.addAnEdgeFollowingTheCursor(pos.x, pos.y); dispatcher.bind("svg", "mousemove", function(ev) { var pos = getCursorPositionInSVG(ev); moveCB(pos.x, pos.y); diff --git a/html/admin/js/graphViewer/ui/modalDialogHelper.js b/html/admin/js/graphViewer/ui/modalDialogHelper.js index 4989a2e351..c5ebc64090 100644 --- a/html/admin/js/graphViewer/ui/modalDialogHelper.js +++ b/html/admin/js/graphViewer/ui/modalDialogHelper.js @@ -169,20 +169,26 @@ var modalDialogHelper = modalDialogHelper || {}; tableToJSON = function() { var result = {}; + _.each($("#" + idprefix + "table tr"), function(tr) { var key = tr.children[0].children[0].value, value = tr.children[1].children[0].value; + result[key] = value; }); return result; }; _.each(object, function(value, key) { - var tr = document.createElement("tr"), - keyTh = document.createElement("th"), - valueTh = document.createElement("th"), - keyInput, - valueInput; - + var internalRegex = /^_(id|rev|key|from|to)/, + tr = document.createElement("tr"), + keyTh = document.createElement("th"), + valueTh = document.createElement("th"), + keyInput, + valueInput; + + if (internalRegex.test(key)) { + return; + } table.appendChild(tr); tr.appendChild(keyTh); keyTh.className = "collectionTh";