From a5bbc21728270ce51e5fe386a6e0db46a8fcb423 Mon Sep 17 00:00:00 2001 From: Bryan Housel Date: Mon, 11 Dec 2017 17:34:01 -0500 Subject: [PATCH] Remove unnecessary zoom parameter --- modules/renderer/map.js | 8 ++--- modules/svg/vertices.js | 56 +++++++++++++++++-------------- modules/ui/fields/restrictions.js | 2 +- test/spec/svg/vertices.js | 27 ++++++++------- 4 files changed, 50 insertions(+), 43 deletions(-) diff --git a/modules/renderer/map.js b/modules/renderer/map.js index e53297ff4..1538f5a22 100644 --- a/modules/renderer/map.js +++ b/modules/renderer/map.js @@ -183,7 +183,7 @@ export function rendererMap(context) { if (map.editable() && !transformed) { var hover = d3_event.target.__data__; surface.selectAll('.data-layer-osm') - .call(drawVertices.drawHover, context.graph(), hover, map.extent(), map.zoom()); + .call(drawVertices.drawHover, context.graph(), hover, map.extent()); dispatch.call('drawn', this, {full: false}); } }) @@ -191,7 +191,7 @@ export function rendererMap(context) { if (map.editable() && !transformed) { var hover = d3_event.relatedTarget && d3_event.relatedTarget.__data__; surface.selectAll('.data-layer-osm') - .call(drawVertices.drawHover, context.graph(), hover, map.extent(), map.zoom()); + .call(drawVertices.drawHover, context.graph(), hover, map.extent()); dispatch.call('drawn', this, {full: false}); } }); @@ -207,7 +207,7 @@ export function rendererMap(context) { all = context.features().filter(all, graph); surface.selectAll('.data-layer-osm') - .call(drawVertices, graph, all, filter, map.extent(), map.zoom()) + .call(drawVertices, graph, all, filter, map.extent()) .call(drawMidpoints, graph, all, filter, map.trimmedExtent()); dispatch.call('drawn', this, {full: false}); } @@ -297,7 +297,7 @@ export function rendererMap(context) { data = features.filter(data, graph); surface.selectAll('.data-layer-osm') - .call(drawVertices, graph, data, filter, map.extent(), map.zoom()) + .call(drawVertices, graph, data, filter, map.extent()) .call(drawLines, graph, data, filter) .call(drawAreas, graph, data, filter) .call(drawMidpoints, graph, data, filter, map.trimmedExtent()) diff --git a/modules/svg/vertices.js b/modules/svg/vertices.js index c0425154c..a26f9c08f 100644 --- a/modules/svg/vertices.js +++ b/modules/svg/vertices.js @@ -1,10 +1,16 @@ import _values from 'lodash-es/values'; +import { select as d3_select } from 'd3-selection'; + import { dataFeatureIcons } from '../../data'; import { osmEntity } from '../osm'; import { svgPointTransform } from './index'; +var TAU = 2 * Math.PI; +function ktoz(k) { return Math.log(k * TAU) / Math.LN2 - 8; } + + export function svgVertices(projection, context) { var radiuses = { // z16-, z17, z18+, tagged @@ -55,11 +61,12 @@ export function svgVertices(projection, context) { } - function draw(selection, vertices, klass, graph, zoom, siblings) { + function draw(selection, vertices, klass, graph, siblings) { siblings = siblings || {}; var icons = {}; var directions = {}; var wireframe = context.surface().classed('fill-wireframe'); + var zoom = ktoz(projection.scale()); var z = (zoom < 17 ? 0 : zoom < 18 ? 1 : 2); @@ -95,23 +102,20 @@ export function svgVertices(projection, context) { var rads = radiuses[klass]; selection.selectAll('.' + klass) .each(function(entity) { - var i = z && getIcon(entity), - c = i ? 0.5 : 0, - r = rads[i ? 3 : z]; + var i = z && getIcon(entity); + var c = i ? 0.5 : 0; + var r = rads[i ? 3 : z]; // slightly increase the size of unconnected endpoints #3775 if (entity.isEndpoint(graph) && !entity.isConnected(graph)) { r += 1.5; } - this.setAttribute('cx', c); - this.setAttribute('cy', -c); - this.setAttribute('r', r); - if (i && klass === 'fill') { - this.setAttribute('visibility', 'hidden'); - } else { - this.removeAttribute('visibility'); - } + d3_select(this) + .attr('cx', c) + .attr('cy', -c) + .attr('r', r) + .attr('visibility', ((i && klass === 'fill') ? 'hidden' : null)); }); }); @@ -148,8 +152,8 @@ export function svgVertices(projection, context) { .append('use') .attr('transform', 'translate(-5, -6)') .attr('xlink:href', function(d) { - var picon = getIcon(d), - isMaki = dataFeatureIcons.indexOf(picon) !== -1; + var picon = getIcon(d); + var isMaki = dataFeatureIcons.indexOf(picon) !== -1; return '#' + picon + (isMaki ? '-11' : ''); }) .attr('width', '11px') @@ -204,14 +208,14 @@ export function svgVertices(projection, context) { } - function drawVertices(selection, graph, entities, filter, extent, zoom) { - var siblings = siblingAndChildVertices(context.selectedIDs(), graph, extent), - wireframe = context.surface().classed('fill-wireframe'), - vertices = []; + function drawVertices(selection, graph, entities, filter, extent) { + var siblings = siblingAndChildVertices(context.selectedIDs(), graph, extent); + var wireframe = context.surface().classed('fill-wireframe'); + var vertices = []; for (var i = 0; i < entities.length; i++) { - var entity = entities[i], - geometry = entity.geometry(graph); + var entity = entities[i]; + var geometry = entity.geometry(graph); if ((geometry === 'point') && (wireframe || entity.directions(graph, projection).length)) { vertices.push(entity); @@ -232,25 +236,25 @@ export function svgVertices(projection, context) { var layer = selection.selectAll('.layer-hit'); layer.selectAll('g.vertex.vertex-persistent') .filter(filter) - .call(draw, vertices, 'vertex-persistent', graph, zoom, siblings); + .call(draw, vertices, 'vertex-persistent', graph, siblings); - drawHover(selection, graph, extent, zoom); + drawHover(selection, graph, extent); } - function drawHover(selection, graph, extent, zoom) { + function drawHover(selection, graph, extent) { var hovered = _hover ? siblingAndChildVertices([_hover.id], graph, extent) : {}; var layer = selection.selectAll('.layer-hit'); layer.selectAll('g.vertex.vertex-hover') - .call(draw, _values(hovered), 'vertex-hover', graph, zoom); + .call(draw, _values(hovered), 'vertex-hover', graph); } - drawVertices.drawHover = function(selection, graph, target, extent, zoom) { + drawVertices.drawHover = function(selection, graph, target, extent) { if (target === _hover) return; _hover = target; - drawHover(selection, graph, extent, zoom); + drawHover(selection, graph, extent); }; return drawVertices; diff --git a/modules/ui/fields/restrictions.js b/modules/ui/fields/restrictions.js index f70b47f48..579e17aa5 100644 --- a/modules/ui/fields/restrictions.js +++ b/modules/ui/fields/restrictions.js @@ -115,7 +115,7 @@ export function uiFieldRestrictions(field, context) { surface .call(utilSetDimensions, d) - .call(drawVertices, graph, [vertex], filter, extent, z) + .call(drawVertices, graph, [vertex], filter, extent) .call(drawLines, graph, intersection.ways, filter) .call(drawTurns, graph, intersection.turns(fromNodeID)); diff --git a/test/spec/svg/vertices.js b/test/spec/svg/vertices.js index f539db5fa..2c5104d22 100644 --- a/test/spec/svg/vertices.js +++ b/test/spec/svg/vertices.js @@ -1,9 +1,14 @@ describe('iD.svgVertices', function () { - var context, surface, - projection = d3.geoProjection(function(x, y) { return [x, -y]; }) - .translate([0, 0]) - .scale(180 / Math.PI) - .clipExtent([[0, 0], [Infinity, Infinity]]); + var TAU = 2 * Math.PI; + function ztok(z) { return 256 * Math.pow(2, z) / TAU; } + + var context; + var surface; + var projection = d3.geoProjection(function(x, y) { return [x, -y]; }) + .translate([0, 0]) + .scale(ztok(17)) + .clipExtent([[0, 0], [Infinity, Infinity]]); + beforeEach(function () { context = iD.Context(); @@ -15,14 +20,12 @@ describe('iD.svgVertices', function () { it('adds the .shared class to vertices that are members of two or more ways', function () { - var zoom = 17, - node = iD.Node({loc: [0, 0]}), - way1 = iD.Way({nodes: [node.id], tags: {highway: 'residential'}}), - way2 = iD.Way({nodes: [node.id], tags: {highway: 'residential'}}), - graph = iD.Graph([node, way1, way2]); - - surface.call(iD.svgVertices(projection, context), graph, [node], zoom); + var node = iD.Node({loc: [0, 0]}); + var way1 = iD.Way({nodes: [node.id], tags: {highway: 'residential'}}); + var way2 = iD.Way({nodes: [node.id], tags: {highway: 'residential'}}); + var graph = iD.Graph([node, way1, way2]); + surface.call(iD.svgVertices(projection, context), graph, [node]); expect(surface.select('.vertex').classed('shared')).to.be.true; }); });