From a773aaaab4f1302fe80bfadd96bececca091b269 Mon Sep 17 00:00:00 2001 From: Tom MacWright Date: Thu, 7 Feb 2013 22:55:44 -0500 Subject: [PATCH] Improve perf with some benchmarking. Re translate change see http://jsperf.com/coerce-vs-join-array --- js/id/behavior/hover.js | 8 +++++--- js/id/graph/node.js | 2 +- js/id/renderer/map.js | 2 +- js/id/svg.js | 2 +- js/id/ui/lasso.js | 2 +- 5 files changed, 9 insertions(+), 7 deletions(-) diff --git a/js/id/behavior/hover.js b/js/id/behavior/hover.js index e4d33dd98..b724f13b1 100644 --- a/js/id/behavior/hover.js +++ b/js/id/behavior/hover.js @@ -7,18 +7,20 @@ Only one of these elements can have the :hover pseudo-class, but all of them will have the .hover class. */ -iD.behavior.Hover = function () { +iD.behavior.Hover = function() { var hover = function(selection) { selection.classed('behavior-hover', true); - selection.on('mouseover.hover', function () { + function mouseover() { var datum = d3.event.target.__data__; if (datum) { selection.selectAll('*') .filter(function (d) { return d === datum; }) .classed('hover', true); } - }); + } + + selection.on('mouseover.hover', mouseover); selection.on('mouseout.hover', function () { selection.selectAll('.hover') diff --git a/js/id/graph/node.js b/js/id/graph/node.js index 56fc14eab..76be848fa 100644 --- a/js/id/graph/node.js +++ b/js/id/graph/node.js @@ -12,7 +12,7 @@ _.extend(iD.Node.prototype, { type: "node", extent: function() { - return iD.geo.Extent(this.loc); + return new iD.geo.Extent(this.loc); }, geometry: function(graph) { diff --git a/js/id/renderer/map.js b/js/id/renderer/map.js index 5bdeebce4..ef101dbc7 100644 --- a/js/id/renderer/map.js +++ b/js/id/renderer/map.js @@ -301,7 +301,7 @@ iD.Map = function(context) { map.extent = function(_) { if (!arguments.length) { - return iD.geo.Extent(projection.invert([0, dimensions[1]]), + return new iD.geo.Extent(projection.invert([0, dimensions[1]]), projection.invert([dimensions[0], 0])); } else { var extent = iD.geo.Extent(_), diff --git a/js/id/svg.js b/js/id/svg.js index 3b662b2e7..904a06eeb 100644 --- a/js/id/svg.js +++ b/js/id/svg.js @@ -7,7 +7,7 @@ iD.svg = { PointTransform: function(projection) { return function(entity) { - return 'translate(' + projection(entity.loc) + ')'; + return 'translate(' + projection(entity.loc).join(',') + ')'; }; }, diff --git a/js/id/ui/lasso.js b/js/id/ui/lasso.js index 1ca079fda..338fa2f2d 100644 --- a/js/id/ui/lasso.js +++ b/js/id/ui/lasso.js @@ -22,7 +22,7 @@ iD.ui.lasso = function() { // top-left function topLeft(d) { return 'translate(' + - [Math.min(d[0][0], d[1][0]), Math.min(d[0][1], d[1][1])] + ')'; + [Math.min(d[0][0], d[1][0]), Math.min(d[0][1], d[1][1])].join(',') + ')'; } function width(d) { return Math.abs(d[0][0] - d[1][0]); }