Rewrite some confusing nested ternaries (close #8117)

This commit is contained in:
Quincy Morgan
2020-12-03 12:18:39 -05:00
parent ec1c922cda
commit 2dd0b8449f
4 changed files with 26 additions and 6 deletions
+9 -2
View File
@@ -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.' :
+3 -1
View File
@@ -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;
+6 -2
View File
@@ -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];
}
}
+8 -1
View File
@@ -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')