mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 17:59:23 -04:00
[vislib/tilemap] fix a bug in addLegend by refactoring
This commit is contained in:
parent
9596f3307a
commit
96d371f831
1 changed files with 21 additions and 38 deletions
|
@ -322,10 +322,7 @@ define(function (require) {
|
|||
filter: self._filterToMapBounds(map)
|
||||
});
|
||||
|
||||
// add legend
|
||||
if (mapData.features.length > 1) {
|
||||
self.addLegend(mapData, map);
|
||||
}
|
||||
self.addLegend(mapData, map);
|
||||
|
||||
return featureLayer;
|
||||
};
|
||||
|
@ -362,10 +359,7 @@ define(function (require) {
|
|||
filter: self._filterToMapBounds(map)
|
||||
});
|
||||
|
||||
// add legend
|
||||
if (mapData.features.length > 1) {
|
||||
self.addLegend(mapData, map);
|
||||
}
|
||||
self.addLegend(mapData, map);
|
||||
|
||||
return featureLayer;
|
||||
};
|
||||
|
@ -418,10 +412,7 @@ define(function (require) {
|
|||
filter: self._filterToMapBounds(map)
|
||||
});
|
||||
|
||||
// add legend
|
||||
if (mapData.features.length > 1) {
|
||||
self.addLegend(mapData, map);
|
||||
}
|
||||
self.addLegend(mapData, map);
|
||||
|
||||
return featureLayer;
|
||||
};
|
||||
|
@ -457,6 +448,9 @@ define(function (require) {
|
|||
* @return {undefined}
|
||||
*/
|
||||
TileMap.prototype.addLegend = function (mapData, map) {
|
||||
// only draw the legend for maps with multiple items
|
||||
if (mapData.features.length <= 1) return;
|
||||
|
||||
var self = this;
|
||||
var isLegend = $('div.tilemap-legend', this.chartEl).length;
|
||||
|
||||
|
@ -466,34 +460,23 @@ define(function (require) {
|
|||
var legend = L.control({position: 'bottomright'});
|
||||
|
||||
legend.onAdd = function () {
|
||||
var div = L.DomUtil.create('div', 'tilemap-legend');
|
||||
var colors = self._attr.colors;
|
||||
var labels = [];
|
||||
var i = 0;
|
||||
var vals;
|
||||
var strokecol;
|
||||
var $div = $('<div>').addClass('tilemap-legend');
|
||||
|
||||
if (mapData.properties.min === mapData.properties.max) {
|
||||
// 1 val for legend
|
||||
vals = self._attr.cScale.invertExtent(colors[i]);
|
||||
strokecol = self.darkerColor(colors[i]);
|
||||
labels.push(
|
||||
'<i style="background:' + colors[i] + ';border-color:' + strokecol + '"></i> ' +
|
||||
valueFormatter(vals[0].toFixed(0)));
|
||||
} else {
|
||||
// 3 to 5 vals for legend
|
||||
if (colors) {
|
||||
for (i = 0; i < colors.length; i++) {
|
||||
vals = self._attr.cScale.invertExtent(colors[i]);
|
||||
strokecol = self.darkerColor(colors[i]);
|
||||
labels.push('<i style="background:' + colors[i] + ';border-color:' +
|
||||
strokecol + '"></i> ' + valueFormatter(vals[0]) + ' – ' + valueFormatter(vals[1]));
|
||||
}
|
||||
}
|
||||
}
|
||||
div.innerHTML = labels.join('<br>');
|
||||
_.each(self._attr.colors, function (color, i) {
|
||||
var icon = $('<i>').css({
|
||||
background: color,
|
||||
'border-color': self.darkerColor(color)
|
||||
});
|
||||
|
||||
return div;
|
||||
var range = self._attr.cScale
|
||||
.invertExtent(color)
|
||||
.map(valueFormatter)
|
||||
.join(' – ');
|
||||
|
||||
$div.append(i > 0 ? '<br>' : '').append(icon).append(range);
|
||||
});
|
||||
|
||||
return $div.get(0);
|
||||
};
|
||||
legend.addTo(map);
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue