From e0d7daad3a14c4b68f5f7429df92a9fa348dba8a Mon Sep 17 00:00:00 2001 From: Bryan Housel Date: Tue, 15 Mar 2016 14:42:08 -0400 Subject: [PATCH] Minor style adjustments, code cleanups --- css/app.css | 4 ++-- js/id/behavior/lasso.js | 12 ++++-------- js/id/ui/lasso.js | 34 ++++++++++------------------------ 3 files changed, 16 insertions(+), 34 deletions(-) diff --git a/css/app.css b/css/app.css index 52122e1d2..c29f6429b 100644 --- a/css/app.css +++ b/css/app.css @@ -2919,8 +2919,8 @@ div.full-screen > button:hover { color: rgba(40,40,40,.5); } -.lasso-box { - fill-opacity:0.1; +.lasso-path { + fill-opacity:0.3; stroke: #fff; stroke-width: 1; stroke-opacity: 1; diff --git a/js/id/behavior/lasso.js b/js/id/behavior/lasso.js index 648545a9d..b9f115667 100644 --- a/js/id/behavior/lasso.js +++ b/js/id/behavior/lasso.js @@ -1,13 +1,10 @@ iD.behavior.Lasso = function(context) { var behavior = function(selection) { - var mouse = null, - lasso; + var lasso; function mousedown() { if (d3.event.shiftKey === true) { - - mouse = context.mouse(); lasso = null; selection @@ -20,7 +17,7 @@ iD.behavior.Lasso = function(context) { function mousemove() { if (!lasso) { - lasso = iD.ui.Lasso(context).p(mouse); + lasso = iD.ui.Lasso(context); context.surface().call(lasso); } @@ -41,9 +38,8 @@ iD.behavior.Lasso = function(context) { if (!lasso) return; var graph = context.graph(), - extent = iD.geo.Extent( - normalize(context.projection.invert(lasso.getBounds()[0]), - context.projection.invert(lasso.getBounds()[1]))); + bounds = lasso.extent().map(context.projection.invert), + extent = iD.geo.Extent(normalize(bounds[0], bounds[1])); lasso.close(); diff --git a/js/id/ui/lasso.js b/js/id/ui/lasso.js index 3d3576a93..237c500e0 100644 --- a/js/id/ui/lasso.js +++ b/js/id/ui/lasso.js @@ -1,7 +1,5 @@ iD.ui.Lasso = function(context) { - - var group, path, - polygon, p; + var group, polygon; lasso.coordinates = []; @@ -13,45 +11,33 @@ iD.ui.Lasso = function(context) { .attr('class', 'lasso hide'); polygon = group.append('path') - .attr('class', 'lasso-box'); + .attr('class', 'lasso-path'); group.call(iD.ui.Toggle(true)); } - // top-left - function topLeft(d) { - return path = (path ? (path + ' L ') : 'M ') + d[0] + ' ' + d[1]; - } - function draw() { if (polygon) { - polygon.data([p]) - .attr('d', topLeft); + polygon.data([lasso.coordinates]) + .attr('d', function(d) { return 'M' + d.join(' L') + ' Z'; }); } } - lasso.getBounds = function () { - var x = lasso.coordinates.map(function(i) {return i[0];}); - var y = lasso.coordinates.map(function(i) {return i[1];}); - return [[Math.min.apply(null, x), Math.min.apply(null, y)], - [Math.max.apply(null, x), Math.max.apply(null, y)]]; + lasso.extent = function () { + return lasso.coordinates.reduce(function(extent, point) { + return extent.extend(iD.geo.Extent(point)); + }, iD.geo.Extent()); }; lasso.p = function(_) { - if (!arguments.length) return p; - p = _; - lasso.coordinates.push(p); + if (!arguments.length) return lasso; + lasso.coordinates.push(_); draw(); return lasso; }; - lasso.close = function() { - - polygon.data([p]) - .attr('d', path + ' Z'); - if (group) { group.call(iD.ui.Toggle(false, function() { d3.select(this).remove();