From 577398ca21d3b5966e7abcdf167a85a0a8ff0498 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Fri, 11 Jan 2013 11:53:05 -0800 Subject: [PATCH] Fix .shared classing Now that Graph#parentWays is cached, the specialized Graph#parentStructure method is no longer necessary. This commit also demonstrates that it's relatively easy to write specs for rendering now! --- js/id/graph/graph.js | 12 ------------ js/id/svg/vertices.js | 4 +--- test/index.html | 1 + test/index_packaged.html | 1 + test/spec/svg/vertices.js | 25 +++++++++++++++++++++++++ 5 files changed, 28 insertions(+), 15 deletions(-) create mode 100644 test/spec/svg/vertices.js diff --git a/js/id/graph/graph.js b/js/id/graph/graph.js index 86fa337a4..868c17de5 100644 --- a/js/id/graph/graph.js +++ b/js/id/graph/graph.js @@ -35,17 +35,6 @@ iD.Graph.prototype = { return transients[key] = fn.call(entity); }, - parentStructure: function(ways) { - var nodes = {}; - ways.forEach(function(w) { - _.uniq(w.nodes).forEach(function(n) { - if (typeof nodes[n.id] === 'undefined') nodes[n.id] = 0; - nodes[n.id]++; - }); - }); - return nodes; - }, - parentWays: function(entity) { var graph = this; return this.transient(entity, 'parentWays', @@ -63,7 +52,6 @@ iD.Graph.prototype = { }, parentRelations: function(entity) { - // This is slow and a bad hack. var graph = this; return this.transient(entity, 'parentRelations', function generateParentRelations() { diff --git a/js/id/svg/vertices.js b/js/id/svg/vertices.js index f263dc1bf..424b3b793 100644 --- a/js/id/svg/vertices.js +++ b/js/id/svg/vertices.js @@ -9,8 +9,6 @@ iD.svg.Vertices = function() { } } - var parentStructure = graph.parentStructure(vertices); - var groups = surface.select('.layer-hit').selectAll('g.vertex') .filter(filter) .data(vertices, iD.Entity.key); @@ -28,7 +26,7 @@ iD.svg.Vertices = function() { .attr('r', 4); groups.attr('transform', iD.svg.PointTransform(projection)) - .classed('shared', function(d) { return parentStructure[d.id] > 1; }); + .classed('shared', function(entity) { return graph.parentWays(entity).length > 1; }); // Selecting the following implicitly // sets the data (vertix entity) on the elements diff --git a/test/index.html b/test/index.html index 473c2327c..455608ce0 100644 --- a/test/index.html +++ b/test/index.html @@ -139,6 +139,7 @@ + diff --git a/test/index_packaged.html b/test/index_packaged.html index 2d53e41b9..e01a08bc5 100644 --- a/test/index_packaged.html +++ b/test/index_packaged.html @@ -57,6 +57,7 @@ + diff --git a/test/spec/svg/vertices.js b/test/spec/svg/vertices.js new file mode 100644 index 000000000..661baf543 --- /dev/null +++ b/test/spec/svg/vertices.js @@ -0,0 +1,25 @@ +describe("iD.svg.Vertices", function () { + var surface, + projection = d3.geo.mercator(), + filter = d3.functor(true); + + beforeEach(function () { + surface = d3.select(document.createElementNS('http://www.w3.org/2000/svg', 'svg')); + + surface.append('g') + .attr('class', 'layer-hit'); + }); + + // TODO: fill out + + it("adds the .shared class to vertices that are members of two or more ways", function () { + var node = iD.Node({loc: [0, 0]}), + way1 = iD.Way({nodes: [node.id]}), + way2 = iD.Way({nodes: [node.id]}), + graph = iD.Graph([node, way1, way2]); + + surface.call(iD.svg.Vertices(), graph, [node], filter, projection); + + expect(surface.select('.vertex').classed('shared')).to.equal(true); + }); +});