From c5b3a16d3aeb7b9fb36f7330b8929c2dc40f1b10 Mon Sep 17 00:00:00 2001 From: Tom MacWright Date: Sat, 3 Sep 2016 16:39:30 -0400 Subject: [PATCH] Fix getSetValue, fix line display --- modules/svg/lines.js | 25 ++++++++++++++----------- modules/ui/fields/address.js | 2 +- modules/ui/raw_tag_editor.js | 9 ++++++--- modules/util/get_set_value.js | 23 +++++++++++------------ 4 files changed, 32 insertions(+), 27 deletions(-) diff --git a/modules/svg/lines.js b/modules/svg/lines.js index cd99ba9b0..55f39e690 100644 --- a/modules/svg/lines.js +++ b/modules/svg/lines.js @@ -61,25 +61,29 @@ export function Lines(projection) { .selectAll('g.layergroup') .data(d3.range(-10, 11)); - layergroup.enter() + layergroup = layergroup.enter() .append('g') - .attr('class', function(d) { return 'layer layergroup layer' + String(d); }); + .attr('class', function(d) { return 'layer layergroup layer' + String(d); }) + .merge(layergroup); var linegroup = layergroup .selectAll('g.linegroup') .data(['shadow', 'casing', 'stroke']); - linegroup.enter() + linegroup = linegroup.enter() .append('g') - .attr('class', function(d) { return 'layer linegroup line-' + d; }); + .attr('class', function(d) { return 'layer linegroup line-' + d; }) + .merge(linegroup); var lines = linegroup .selectAll('path') .filter(filter) .data( - function() { return pathdata[this.parentNode.parentNode.__data__] || []; }, + function() { + return pathdata[this.parentNode.__data__] || []; + }, Entity.key ); @@ -88,12 +92,11 @@ export function Lines(projection) { lines.enter() .append('path') .attr('class', function(d) { return 'way line ' + this.parentNode.__data__ + ' ' + d.id; }) - .call(TagClasses()); - - lines - .sort(waystack) - .attr('d', getPath) - .call(TagClasses().tags(RelationMemberTags(graph))); + .call(TagClasses()) + .merge(lines) + .sort(waystack) + .attr('d', getPath) + .call(TagClasses().tags(RelationMemberTags(graph))); lines.exit() .remove(); diff --git a/modules/ui/fields/address.js b/modules/ui/fields/address.js index 396009966..d5176207f 100644 --- a/modules/ui/fields/address.js +++ b/modules/ui/fields/address.js @@ -212,7 +212,7 @@ export function address(field, context) { if (isInitialized) { updateTags(tags); } else { - dispatch.call('on', this, 'init', function () { + dispatch.on('init', function () { updateTags(tags); }); } diff --git a/modules/ui/raw_tag_editor.js b/modules/ui/raw_tag_editor.js index 82100ff11..97aff8d4e 100644 --- a/modules/ui/raw_tag_editor.js +++ b/modules/ui/raw_tag_editor.js @@ -43,8 +43,9 @@ export function RawTagEditor(context) { var $list = $wrap.selectAll('.tag-list') .data([0]); - $list.enter().append('ul') - .attr('class', 'tag-list'); + $list = $list.enter().append('ul') + .attr('class', 'tag-list') + .merge($list); var $newTag = $wrap.selectAll('.add-tag') .data([0]); @@ -89,6 +90,8 @@ export function RawTagEditor(context) { // Update + $items = $items.merge($enter); + $items.order(); $items.each(function(tag) { @@ -112,7 +115,7 @@ export function RawTagEditor(context) { .attr('title', function(d) { return d.key; }) .on('blur', keyChange) .on('change', keyChange), - function(d) { return d.key; } + function(d) { console.log(d, this); return d.key; } ); getSetValue($items.select('input.value') diff --git a/modules/util/get_set_value.js b/modules/util/get_set_value.js index 9d7d92a07..7137d5141 100644 --- a/modules/util/get_set_value.js +++ b/modules/util/get_set_value.js @@ -1,24 +1,23 @@ // Like selection.property('value', ...), but avoids no-op value sets, // which can result in layout/repaint thrashing in some situations. -export function getSetValue(target, value) { +export function getSetValue(selection, value) { function d3_selection_value(value) { function valueNull() { - delete target.value; + delete this.value; } function valueConstant() { - if (target.value !== value) { - target.value = value; + if (this.value !== value) { + this.value = value; } } function valueFunction() { - var x = value.apply(target, arguments); + var x = value.apply(this, arguments); if (x == null) { - delete target.value; - } - else if (target.value !== x) { - target.value = x; + delete this.value; + } else if (this.value !== x) { + this.value = x; } } @@ -27,8 +26,8 @@ export function getSetValue(target, value) { ? valueFunction : valueConstant); } - if (!arguments.length) { - return target.property('value'); + if (arguments.length === 1) { + return selection.property('value'); } - return target.each(d3_selection_value(value)); + return selection.each(d3_selection_value(value)); }