From 2dd0b8449f778f753e1b08b57e3a2939342fce1b Mon Sep 17 00:00:00 2001 From: Quincy Morgan <2046746+quincylvania@users.noreply.github.com> Date: Thu, 3 Dec 2020 12:18:39 -0500 Subject: [PATCH] Rewrite some confusing nested ternaries (close #8117) --- modules/behavior/draw_way.js | 11 +++++++++-- modules/services/improveOSM.js | 4 +++- modules/svg/notes.js | 8 ++++++-- modules/ui/note_header.js | 9 ++++++++- 4 files changed, 26 insertions(+), 6 deletions(-) diff --git a/modules/behavior/draw_way.js b/modules/behavior/draw_way.js index 34a6dbda0..84d6af211 100644 --- a/modules/behavior/draw_way.js +++ b/modules/behavior/draw_way.js @@ -238,8 +238,15 @@ export function behaviorDrawWay(context, wayID, mode, startGraph) { _drawNode = undefined; _didResolveTempEdit = false; _origWay = context.entity(wayID); - _headNodeID = typeof _nodeIndex === 'number' ? _origWay.nodes[_nodeIndex] : - (_origWay.isClosed() ? _origWay.nodes[_origWay.nodes.length - 2] : _origWay.nodes[_origWay.nodes.length - 1]); + + if (typeof _nodeIndex === 'number') { + _headNodeID = _origWay.nodes[_nodeIndex]; + } else if (_origWay.isClosed()) { + _headNodeID = _origWay.nodes[_origWay.nodes.length - 2]; + } else { + _headNodeID = _origWay.nodes[_origWay.nodes.length - 1]; + } + _wayGeometry = _origWay.geometry(context.graph()); _annotation = t((_origWay.nodes.length === (_origWay.isClosed() ? 2 : 1) ? 'operations.start.annotation.' : diff --git a/modules/services/improveOSM.js b/modules/services/improveOSM.js index 9b139bff1..045788591 100644 --- a/modules/services/improveOSM.js +++ b/modules/services/improveOSM.js @@ -109,7 +109,9 @@ function preventCoincident(loc, bumpUp) { let coincident = false; do { // first time, move marker up. after that, move marker right. - let delta = coincident ? [0.00001, 0] : (bumpUp ? [0, 0.00001] : [0, 0]); + let delta = coincident ? [0.00001, 0] : + bumpUp ? [0, 0.00001] : + [0, 0]; loc = geoVecAdd(loc, delta); let bbox = geoExtent(loc).bbox(); coincident = _cache.rtree.search(bbox).length; diff --git a/modules/svg/notes.js b/modules/svg/notes.js index bc8fc55e7..8d2c6376e 100644 --- a/modules/svg/notes.js +++ b/modules/svg/notes.js @@ -153,7 +153,9 @@ export function svgNotes(projection, context, dispatch) { .attr('x', '-3px') .attr('y', '-19px') .attr('xlink:href', function(d) { - return '#iD-icon-' + (d.id < 0 ? 'plus' : (d.status === 'open' ? 'close' : 'apply')); + if (d.id < 0) return '#iD-icon-plus'; + if (d.status === 'open') return '#iD-icon-close'; + return '#iD-icon-apply'; }); // update @@ -196,7 +198,9 @@ export function svgNotes(projection, context, dispatch) { function sortY(a, b) { - return (a.id === selectedID) ? 1 : (b.id === selectedID) ? -1 : b.loc[1] - a.loc[1]; + if (a.id === selectedID) return 1; + if (b.id === selectedID) return -1; + return b.loc[1] - a.loc[1]; } } diff --git a/modules/ui/note_header.js b/modules/ui/note_header.js index 99b1d4c44..c496e5b8c 100644 --- a/modules/ui/note_header.js +++ b/modules/ui/note_header.js @@ -31,7 +31,14 @@ export function uiNoteHeader() { .call(svgIcon('#iD-icon-note', 'note-fill')); iconEnter.each(function(d) { - var statusIcon = '#iD-icon-' + (d.id < 0 ? 'plus' : (d.status === 'open' ? 'close' : 'apply')); + var statusIcon; + if (d.id < 0) { + statusIcon = '#iD-icon-plus'; + } else if (d.status === 'open') { + statusIcon = '#iD-icon-close'; + } else { + statusIcon = '#iD-icon-apply'; + } iconEnter .append('div') .attr('class', 'note-icon-annotation')