mirror of https://github.com/MISP/MISP
Merge pull request #5687 from MISP/feature-widget-improvement
chg: [widget:worldmap] Various JS and UI Improvementspull/5705/head
commit
0e2babfa04
|
@ -16,30 +16,45 @@
|
|||
|
||||
<div id="world-map-<?= $randomNumber ?>" style="width: 600px; height: 400px"></div>
|
||||
<script>
|
||||
var mapData = <?= json_encode($data['data']); ?>;
|
||||
$('#world-map-<?= $randomNumber ?>').vectorMap({
|
||||
map: 'world_mill',
|
||||
series: {
|
||||
regions: [{
|
||||
values: mapData,
|
||||
scale: ['#F08080', '#8B0000'],
|
||||
normalizeFunction: 'polynomial'
|
||||
}]
|
||||
},
|
||||
onRegionTipShow: function(e, el, code) {
|
||||
el.html(el.html()+' (<?= h($data['scope']) ?> - '+mapData[code]+')');
|
||||
}
|
||||
});
|
||||
var container_<?= $randomNumber ?> = $('#world-map-<?= $randomNumber ?>').parent().parent();
|
||||
(function() { // variables and functions have their own scope (no override)
|
||||
'use strict';
|
||||
var randomNumber = "<?= $randomNumber ?>";
|
||||
var scope = "<?= h($data['scope']) ?>";
|
||||
var resize_timeout;
|
||||
var mapData = <?= json_encode($data['data']); ?>;
|
||||
var $worldmap = $('#world-map-'+randomNumber);
|
||||
var $container = $worldmap.closest('div.widgetContent');
|
||||
$worldmap.vectorMap({
|
||||
map: 'world_mill',
|
||||
series: {
|
||||
regions: [{
|
||||
values: mapData,
|
||||
scale: ['#003FBF','#0063BF','#0087BF','#00ACBF','#00BFAD','#00BF89','#00BF64','#00BF40','#00BF1C','#08BF00','#2CBF00','#51BF00','#75BF00','#99BF00','#BEBF00','#BF9B00','#BF7700','#BF5200','#BF2E00','#BF0900'], // gradient blue->green->yellow->red
|
||||
normalizeFunction: 'polynomial'
|
||||
}]
|
||||
},
|
||||
onRegionTipShow: function(e, el, code) {
|
||||
var amount = mapData[code] !== undefined ? mapData[code] : 0; // no data defaulted to 0
|
||||
el.html(el.html()+' (' + scope + ' - '+amount+')');
|
||||
}
|
||||
});
|
||||
|
||||
function resizeDashboardWorldMap(id) {
|
||||
var width = eval('container_' + id + '.width()');
|
||||
var height = eval('container_' + id + '.height() - 60');
|
||||
$('#world-map-' + id).css('width', width + 'px');
|
||||
$('#world-map-' + id).css('height', height + 'px');
|
||||
$('#world-map-' + id).vectorMap('get','mapObject').updateSize();
|
||||
}
|
||||
$(document).ready(function() {
|
||||
resizeDashboardWorldMap(<?= $randomNumber ?>);
|
||||
});
|
||||
</script>
|
||||
function resizeDashboardWorldMap() {
|
||||
var width = $container.width();
|
||||
var height = $container.height();
|
||||
$worldmap
|
||||
.css('width', width + 'px')
|
||||
.css('height', height + 'px')
|
||||
.vectorMap('get','mapObject').updateSize();
|
||||
}
|
||||
$(document).ready(function() {
|
||||
resizeDashboardWorldMap();
|
||||
window.addEventListener("resize", function() {
|
||||
if (resize_timeout !== undefined) {
|
||||
clearTimeout(resize_timeout);
|
||||
}
|
||||
resize_timeout = setTimeout(function() { resizeDashboardWorldMap() }, 500); // redraw after 500ms
|
||||
});
|
||||
});
|
||||
}());
|
||||
</script>
|
Loading…
Reference in New Issue