diff --git a/modules/actions/circularize.js b/modules/actions/circularize.js index bc63a2c7b..27d6ddaba 100644 --- a/modules/actions/circularize.js +++ b/modules/actions/circularize.js @@ -18,7 +18,7 @@ export function Circularize(wayId keyNodes = nodes.filter(function(n) { return graph.parentWays(n).length !== 1; }), points = nodes.map(function(n) { return projection(n.loc); }), keyPoints = keyNodes.map(function(n) { return projection(n.loc); }), - centroid = (points.length === 2) ? interp(points[0], points[1], 0.5) : d3.geoCentroid({ type: 'Polygon', coordinates: points }), + centroid = (points.length === 2) ? interp(points[0], points[1], 0.5) : d3.geoCentroid({ type: 'Polygon', coordinates: [points] }), radius = d3.median(points, function(p) { return euclideanDistance(centroid, p); }), sign = d3.polygonArea(points) > 0 ? 1 : -1, ids; diff --git a/modules/util/index.js b/modules/util/index.js index 906623f17..92d641e8c 100644 --- a/modules/util/index.js +++ b/modules/util/index.js @@ -17,3 +17,4 @@ export { wrap } from './util'; export { functor } from './util'; export { SessionMutex } from './session_mutex'; export { SuggestNames } from './suggest_names'; +export { triggerEvent } from './trigger_event'; diff --git a/test/spec/actions/circularize.js b/test/spec/actions/circularize.js index 6c6331019..e8443c31e 100644 --- a/test/spec/actions/circularize.js +++ b/test/spec/actions/circularize.js @@ -3,10 +3,10 @@ describe('iD.actions.Circularize', function () { function isCircular(id, graph) { var points = _.map(graph.childNodes(graph.entity(id)), 'loc').map(projection), - centroid = d3.geom.polygon(points).centroid(), + centroid = d3.polygonCentroid(points), radius = iD.geo.euclideanDistance(centroid, points[0]), estArea = Math.PI * radius * radius, - trueArea = Math.abs(d3.geom.polygon(points).area()), + trueArea = Math.abs(d3.polygonArea(points)), pctDiff = (estArea - trueArea) / estArea; return (pctDiff < 0.025); // within 2.5% of circular area.. @@ -106,7 +106,7 @@ describe('iD.actions.Circularize', function () { expect(isCircular('-', graph)).to.be.ok; points = _.map(graph.childNodes(graph.entity('-')), 'loc').map(projection); - centroid = d3.geom.polygon(points).centroid(); + centroid = d3.polygonCentroid(points); for (var i = 0; i < points.length - 1; i++) { expect(angle(points[i], points[i+1], centroid)).to.be.lte(20); @@ -116,7 +116,7 @@ describe('iD.actions.Circularize', function () { }); function area(id, graph) { - return d3.geom.polygon(_.map(graph.childNodes(graph.entity(id)), 'loc')).area(); + return d3.polygonArea(_.map(graph.childNodes(graph.entity(id)), 'loc')); } it('leaves clockwise ways clockwise', function () { diff --git a/test/spec/behavior/hover.js b/test/spec/behavior/hover.js index 157b988be..3068d4ed2 100644 --- a/test/spec/behavior/hover.js +++ b/test/spec/behavior/hover.js @@ -30,7 +30,7 @@ describe('iD.behavior.Hover', function() { .enter().append('span').attr('class', function(d) { return d.id; }); container.call(iD.behavior.Hover(context)); - container.selectAll('.a').trigger('mouseover'); + iD.util.triggerEvent(container.selectAll('.a'), 'mouseover'); expect(container.selectAll('.a.hover')[0]).to.have.length(2); expect(container.selectAll('.b.hover')[0]).to.have.length(0); @@ -42,7 +42,7 @@ describe('iD.behavior.Hover', function() { .enter().append('span').attr('class', function(d) { return d.id; }); container.call(iD.behavior.Hover(context)); - container.selectAll('.a').trigger('mouseover'); + iD.util.triggerEvent(container.selectAll('.a'), 'mouseover'); expect(container.selectAll('.a.hover')[0]).to.have.length(1); expect(container.selectAll('.b.hover')[0]).to.have.length(1); @@ -54,7 +54,7 @@ describe('iD.behavior.Hover', function() { container.append('span').attr('class', 'hover'); container.call(iD.behavior.Hover(context)); - container.selectAll('.hover').trigger('mouseout'); + iD.util.triggerEvent(container.selectAll('.hover'), 'mouseout'); expect(container.selectAll('.hover')[0]).to.have.length(0); }); diff --git a/test/spec/spec_helpers.js b/test/spec/spec_helpers.js index 3dad1ce19..61b02b92f 100644 --- a/test/spec/spec_helpers.js +++ b/test/spec/spec_helpers.js @@ -1,6 +1,6 @@ /* globals chai:false */ -iD.debug = true; +// iD.debug = true; mocha.setup({ ui: 'bdd', diff --git a/test/spec/ui/raw_tag_editor.js b/test/spec/ui/raw_tag_editor.js index afcd3405b..d711f6825 100644 --- a/test/spec/ui/raw_tag_editor.js +++ b/test/spec/ui/raw_tag_editor.js @@ -37,7 +37,7 @@ describe('iD.ui.RawTagEditor', function() { }); it('adds tags when clicking the add button', function (done) { - element.selectAll('button.add-tag').trigger('click'); + iD.util.triggerEvent(element.selectAll('button.add-tag'), 'click'); setTimeout(function() { expect(element.select('.tag-list').selectAll('input')[0][2].value).to.be.empty; expect(element.select('.tag-list').selectAll('input')[0][3].value).to.be.empty; @@ -50,7 +50,7 @@ describe('iD.ui.RawTagEditor', function() { expect(tags).to.eql({highway: undefined}); done(); }); - element.selectAll('button.remove').trigger('click'); + iD.util.triggerEvent(element.selectAll('button.remove'), 'click'); }); it('adds tags when pressing the TAB key on last input.value', function (done) {