From 78aee5b6aa62f4c186dbddc0a68a30db4ae7b1a4 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Tue, 23 Apr 2013 20:09:36 -0700 Subject: [PATCH] Fix tests --- js/id/renderer/map.js | 10 +++++++--- js/id/svg/midpoints.js | 1 - js/id/svg/vertices.js | 3 +-- test/spec/svg/midpoints.js | 14 ++++++++------ test/spec/svg/vertices.js | 7 +++---- 5 files changed, 19 insertions(+), 16 deletions(-) diff --git a/js/id/renderer/map.js b/js/id/renderer/map.js index df832c0b3..bd3f405c0 100644 --- a/js/id/renderer/map.js +++ b/js/id/renderer/map.js @@ -26,6 +26,10 @@ iD.Map = function(context) { tail = iD.ui.Tail(), surface, layergroup; + function visibleEntities() { + return context.intersects(map.extent()); + } + function map(selection) { context.history() .on('change.map', redraw); @@ -57,14 +61,14 @@ iD.Map = function(context) { surface.on('mouseover.vertices', function() { vertices.hover(d3.event.target.__data__); if (map.editable() && !isTransformed()) { - surface.call(vertices, context.graph(), map.zoom()); + surface.call(vertices, context.graph(), visibleEntities(), map.zoom()); } }); surface.on('mouseout.vertices', function() { vertices.hover(d3.event.relatedTarget && d3.event.relatedTarget.__data__); if (map.editable() && !isTransformed()) { - surface.call(vertices, context.graph(), map.zoom()); + surface.call(vertices, context.graph(), visibleEntities(), map.zoom()); } }); @@ -122,7 +126,7 @@ iD.Map = function(context) { } else { surface .call(points, graph, all, filter) - .call(vertices, graph, map.zoom()) + .call(vertices, graph, visibleEntities(), map.zoom()) .call(lines, graph, all, filter, dimensions) .call(areas, graph, all, filter) .call(midpoints, graph, all, filter, extent) diff --git a/js/id/svg/midpoints.js b/js/id/svg/midpoints.js index eb776a2da..50caf61e0 100644 --- a/js/id/svg/midpoints.js +++ b/js/id/svg/midpoints.js @@ -8,7 +8,6 @@ iD.svg.Midpoints = function(projection, context) { if (entity.type !== 'way') continue; if (context.selection().indexOf(entity.id) < 0) continue; - var nodes = graph.childNodes(entity); // skip the last node because it is always repeated diff --git a/js/id/svg/vertices.js b/js/id/svg/vertices.js index e8fd774a9..22a9f0b5d 100644 --- a/js/id/svg/vertices.js +++ b/js/id/svg/vertices.js @@ -58,9 +58,8 @@ iD.svg.Vertices = function(projection, context) { }).length > 1; } - function drawVertices(surface, graph, zoom) { + function drawVertices(surface, graph, entities, zoom) { var visible = visibleVertices(), - entities = context.intersects(context.map().extent()), vertices = []; for (var i = 0; i < entities.length; i++) { diff --git a/test/spec/svg/midpoints.js b/test/spec/svg/midpoints.js index e11318b6b..39b14e677 100644 --- a/test/spec/svg/midpoints.js +++ b/test/spec/svg/midpoints.js @@ -1,11 +1,13 @@ describe("iD.svg.Midpoints", function () { var surface, projection = Object, - filter = d3.functor(true); + filter = d3.functor(true), + context; beforeEach(function () { + context = iD(); surface = d3.select(document.createElementNS('http://www.w3.org/2000/svg', 'svg')) - .call(iD.svg.Surface(iD())); + .call(iD.svg.Surface(context)); }); it("finds the location of the midpoints", function () { @@ -15,9 +17,8 @@ describe("iD.svg.Midpoints", function () { graph = iD.Graph([a, b, line]), extent = iD.geo.Extent([0, 0], [100, 100]); - // If no vertices are drawn, no midpoints are drawn. This dependence needs to be removed - surface.call(iD.svg.Vertices(projection), graph, [a], filter, 16); - surface.call(iD.svg.Midpoints(projection), graph, [line], filter, extent); + context.selection = function() { return [line.id]; }; + surface.call(iD.svg.Midpoints(projection, context), graph, [line], filter, extent); expect(surface.select('.midpoint').datum().loc).to.eql([25, 0]); }); @@ -29,7 +30,8 @@ describe("iD.svg.Midpoints", function () { graph = iD.Graph([a, b, line]), extent = iD.geo.Extent([0, 0], [100, 100]); - surface.call(iD.svg.Midpoints(projection), graph, [line], filter, extent); + context.selection = function() { return [line.id]; }; + surface.call(iD.svg.Midpoints(projection, context), graph, [line], filter, extent); expect(surface.selectAll('.midpoint')[0]).to.have.length(0); }); diff --git a/test/spec/svg/vertices.js b/test/spec/svg/vertices.js index eb2441228..4b29949c4 100644 --- a/test/spec/svg/vertices.js +++ b/test/spec/svg/vertices.js @@ -1,13 +1,12 @@ describe("iD.svg.Vertices", function () { var surface, projection = Object, - filter = d3.functor(true), context; beforeEach(function () { context = iD(); surface = d3.select(document.createElementNS('http://www.w3.org/2000/svg', 'svg')) - .call(iD.svg.Surface(iD())); + .call(iD.svg.Surface(context)); }); it("adds tag classes", function () { @@ -15,7 +14,7 @@ describe("iD.svg.Vertices", function () { way = iD.Way({nodes: [node.id]}), graph = iD.Graph([node, way]); - surface.call(iD.svg.Vertices(projection, context), graph, [node], filter); + surface.call(iD.svg.Vertices(projection, context), graph, [node], 17); expect(surface.select('.vertex')).to.be.classed('tag-highway'); expect(surface.select('.vertex')).to.be.classed('tag-highway-traffic_signals'); @@ -27,7 +26,7 @@ describe("iD.svg.Vertices", function () { way2 = iD.Way({nodes: [node.id]}), graph = iD.Graph([node, way1, way2]); - surface.call(iD.svg.Vertices(projection, context), graph, [node], filter); + surface.call(iD.svg.Vertices(projection, context), graph, [node], 17); expect(surface.select('.vertex')).to.be.classed('shared'); });