Skip to content

Commit

Permalink
[Maps] Correctly handle single-feature joins (#30409) (#30471)
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasneirynck authored Feb 8, 2019
1 parent 2ea8c33 commit 273549e
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions x-pack/plugins/maps/public/shared/layers/styles/vector_style.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,10 +219,21 @@ export class VectorStyle extends AbstractStyle {
max = Math.max(max, newValue);
}
}
//scale to [0,1]
const diff = max - min;
const propName = VectorStyle.getComputedFieldName(fieldName);

//scale to [0,1] domain
for (let i = 0; i < features.length; i++) {
features[i].properties[propName] = (features[i].properties[fieldName] - min) / (max - min);
const unscaledValue = features[i].properties[fieldName];
let scaledValue;
if (typeof unscaledValue !== 'number' || isNaN(unscaledValue)) {//cannot scale
scaledValue = -1;//put outside range
} else if (diff === 0) {//values are identical
scaledValue = 1;//snap to end of color range
} else {
scaledValue = (features[i].properties[fieldName] - min) / diff;
}
features[i].properties[propName] = scaledValue;
}
featureCollection.computed.push(fieldName);
return true;
Expand Down

0 comments on commit 273549e

Please sign in to comment.