From 20962074ba10755b7c558ab8337bbf2f80d99c78 Mon Sep 17 00:00:00 2001 From: Tom MacWright Date: Tue, 6 Sep 2016 10:58:07 -0400 Subject: [PATCH] Fix vertices areas midlines --- modules/core/context.js | 5 ++++- modules/index.js | 2 +- modules/svg/areas.js | 1 - modules/svg/lines.js | 28 +++++++++++++++++----------- modules/svg/midpoints.js | 9 ++++++++- modules/svg/vertices.js | 8 +++++++- test/spec/svg/areas.js | 13 +++++++++---- test/spec/svg/lines.js | 16 ++++++++-------- test/spec/svg/midpoints.js | 6 +++--- 9 files changed, 57 insertions(+), 31 deletions(-) diff --git a/modules/core/context.js b/modules/core/context.js index 41661493a..2d0dbf5ef 100644 --- a/modules/core/context.js +++ b/modules/core/context.js @@ -17,6 +17,10 @@ import * as services from '../services/index'; export var areaKeys = {}; +export function setAreaKeys(value) { + areaKeys = value; +} + export function Context(root) { if (!root.locale) { root.locale = { @@ -403,4 +407,3 @@ export function Context(root) { return rebind(context, dispatch, 'on'); } - diff --git a/modules/index.js b/modules/index.js index f1db5a8c5..6880c1cee 100644 --- a/modules/index.js +++ b/modules/index.js @@ -16,7 +16,7 @@ export { Detect } from './util/detect'; // core export { Connection } from './core/connection'; -export { Context } from './core/context'; +export { Context, setAreaKeys } from './core/context'; export { Difference } from './core/difference'; export { Entity } from './core/entity'; export { Graph } from './core/graph'; diff --git a/modules/svg/areas.js b/modules/svg/areas.js index 9c5dd8f08..f50276416 100644 --- a/modules/svg/areas.js +++ b/modules/svg/areas.js @@ -92,7 +92,6 @@ export function Areas(projection) { var areagroup = surface - .selectAll('.layer-areas') .selectAll('g.areagroup') .data(['fill', 'shadow', 'stroke']); diff --git a/modules/svg/lines.js b/modules/svg/lines.js index 55f39e690..1a7e308bd 100644 --- a/modules/svg/lines.js +++ b/modules/svg/lines.js @@ -56,8 +56,15 @@ export function Lines(projection) { .valueOf(); }); - var layergroup = surface + var layer = surface .selectAll('.layer-lines') + .data([0]) + + layer = layer.enter() + .append('g').attr('class', 'layer-lines') + .merge(layer); + + var layergroup = layer .selectAll('g.layergroup') .data(d3.range(-10, 11)); @@ -106,9 +113,10 @@ export function Lines(projection) { .selectAll('g.onewaygroup') .data(['oneway']); - onewaygroup.enter() + onewaygroup = onewaygroup.enter() .append('g') - .attr('class', 'layer onewaygroup'); + .attr('class', 'layer onewaygroup') + .merge(onewaygroup); var oneways = onewaygroup @@ -119,20 +127,18 @@ export function Lines(projection) { function(d) { return [d.id, d.index]; } ); - oneways.enter() + oneways.exit() + .remove(); + + oneways = oneways.enter() .append('path') .attr('class', 'oneway') - .attr('marker-mid', 'url(#oneway-marker)'); - - oneways + .attr('marker-mid', 'url(#oneway-marker)') + .merge(oneways) .attr('d', function(d) { return d.d; }); if (Detect().ie) { oneways.each(function() { this.parentNode.insertBefore(this, this); }); } - - oneways.exit() - .remove(); - }; } diff --git a/modules/svg/midpoints.js b/modules/svg/midpoints.js index 2e8f58811..ca4fee6cc 100644 --- a/modules/svg/midpoints.js +++ b/modules/svg/midpoints.js @@ -71,7 +71,14 @@ export function Midpoints(projection, context) { return false; } - var groups = surface.selectAll('.layer-hit').selectAll('g.midpoint') + var layer = surface.selectAll('.layer-hit') + .data([0]); + + layer = layer.enter().append('g').attr('class', 'layer-hit') + .merge(layer); + + var groups = layer + .selectAll('g.midpoint') .filter(midpointFilter) .data(_.values(midpoints), function(d) { return d.id; }); diff --git a/modules/svg/vertices.js b/modules/svg/vertices.js index 49f097d26..0558effac 100644 --- a/modules/svg/vertices.js +++ b/modules/svg/vertices.js @@ -125,6 +125,7 @@ export function Vertices(projection, context) { .each(setClass('fill')); groups + .merge(enter) .attr('transform', PointTransform(projection)) .classed('shared', function(entity) { return graph.isShared(entity); }) .call(setAttributes); @@ -157,7 +158,12 @@ export function Vertices(projection, context) { } } - surface.selectAll('.layer-hit').selectAll('g.vertex.vertex-persistent') + var layer = surface.selectAll('.layer-hit') + .data([0]); + layer = layer.enter().append('g').attr('class', 'layer-hit') + .merge(layer); + + layer.selectAll('g.vertex.vertex-persistent') .filter(filter) .call(draw, vertices, 'vertex-persistent', graph, zoom); diff --git a/test/spec/svg/areas.js b/test/spec/svg/areas.js index 1771da4cc..2d9b49b69 100644 --- a/test/spec/svg/areas.js +++ b/test/spec/svg/areas.js @@ -8,6 +8,11 @@ describe('iD.svg.Areas', function () { beforeEach(function () { surface = d3.select(document.createElementNS('http://www.w3.org/2000/svg', 'svg')) .call(iD.svg.Layers(projection, iD.Context(window))); + iD.setAreaKeys({ + building: {}, + landuse: {}, + natural: {} + }); }); it('adds way and area classes', function () { @@ -127,7 +132,7 @@ describe('iD.svg.Areas', function () { surface.call(iD.svg.Areas(projection), graph, areas, none); - expect(surface.selectAll('.stroke')[0].length).to.equal(0); + expect(surface.selectAll('.stroke').size()).to.equal(0); }); it('renders fill for a multipolygon with tags on the outer way', function() { @@ -140,8 +145,8 @@ describe('iD.svg.Areas', function () { surface.call(iD.svg.Areas(projection), graph, [w, r], none); - expect(surface.selectAll('.way.fill')[0].length).to.equal(0); - expect(surface.selectAll('.relation.fill')[0].length).to.equal(1); + expect(surface.selectAll('.way.fill').size()).to.equal(0); + expect(surface.selectAll('.relation.fill').size()).to.equal(1); expect(surface.select('.relation.fill')).to.be.classed('tag-natural-wood'); }); @@ -155,6 +160,6 @@ describe('iD.svg.Areas', function () { surface.call(iD.svg.Areas(projection), graph, [w, r], none); - expect(surface.selectAll('.stroke')[0].length).to.equal(0); + expect(surface.selectAll('.stroke').size()).to.equal(0); }); }); diff --git a/test/spec/svg/lines.js b/test/spec/svg/lines.js index 44ba961dd..bf848f1d4 100644 --- a/test/spec/svg/lines.js +++ b/test/spec/svg/lines.js @@ -87,16 +87,16 @@ describe('iD.svg.Lines', function () { surface.call(iD.svg.Lines(projection), graph, [graph.entity('lo'), graph.entity('hi')], none); var selection = surface.selectAll('g.line-stroke > path.line'); - expect(selection[0][0].__data__.id).to.eql('lo'); - expect(selection[0][1].__data__.id).to.eql('hi'); + expect(selection.nodes()[0].__data__.id).to.eql('lo'); + expect(selection.nodes()[1].__data__.id).to.eql('hi'); }); it('stacks higher lines above lower ones in a single render (reverse)', function () { surface.call(iD.svg.Lines(projection), graph, [graph.entity('hi'), graph.entity('lo')], none); var selection = surface.selectAll('g.line-stroke > path.line'); - expect(selection[0][0].__data__.id).to.eql('lo'); - expect(selection[0][1].__data__.id).to.eql('hi'); + expect(selection.nodes()[0].__data__.id).to.eql('lo'); + expect(selection.nodes()[1].__data__.id).to.eql('hi'); }); it('stacks higher lines above lower ones in separate renders', function () { @@ -104,8 +104,8 @@ describe('iD.svg.Lines', function () { surface.call(iD.svg.Lines(projection), graph, [graph.entity('hi')], none); var selection = surface.selectAll('g.line-stroke > path.line'); - expect(selection[0][0].__data__.id).to.eql('lo'); - expect(selection[0][1].__data__.id).to.eql('hi'); + expect(selection.nodes()[0].__data__.id).to.eql('lo'); + expect(selection.nodes()[1].__data__.id).to.eql('hi'); }); it('stacks higher lines above lower in separate renders (reverse)', function () { @@ -113,8 +113,8 @@ describe('iD.svg.Lines', function () { surface.call(iD.svg.Lines(projection), graph, [graph.entity('lo')], none); var selection = surface.selectAll('g.line-stroke > path.line'); - expect(selection[0][0].__data__.id).to.eql('lo'); - expect(selection[0][1].__data__.id).to.eql('hi'); + expect(selection.nodes()[0].__data__.id).to.eql('lo'); + expect(selection.nodes()[1].__data__.id).to.eql('hi'); }); }); diff --git a/test/spec/svg/midpoints.js b/test/spec/svg/midpoints.js index 0bbca09a2..3b164c7da 100644 --- a/test/spec/svg/midpoints.js +++ b/test/spec/svg/midpoints.js @@ -34,7 +34,7 @@ describe('iD.svg.Midpoints', function () { context.selectedIDs = function() { return [line.id]; }; surface.call(iD.svg.Midpoints(projection, context), graph, [line], filter, extent); - expect(surface.selectAll('.midpoint')[0]).to.have.length(0); + expect(surface.selectAll('.midpoint').nodes()).to.have.length(0); }); it('doesn\'t create midpoint on segment completely outside of the extent', function () { @@ -47,7 +47,7 @@ describe('iD.svg.Midpoints', function () { context.selectedIDs = function() { return [line.id]; }; surface.call(iD.svg.Midpoints(projection, context), graph, [line], filter, extent); - expect(surface.selectAll('.midpoint')[0]).to.have.length(0); + expect(surface.selectAll('.midpoint').nodes()).to.have.length(0); }); it('creates midpoint on extent edge for segment partially outside of the extent', function () { @@ -74,7 +74,7 @@ describe('iD.svg.Midpoints', function () { context.selectedIDs = function() { return [line.id]; }; surface.call(iD.svg.Midpoints(projection, context), graph, [line], filter, extent); - expect(surface.selectAll('.midpoint')[0]).to.have.length(0); + expect(surface.selectAll('.midpoint').nodes()).to.have.length(0); }); });