Merge pull request #5687 from MISP/feature-widget-improvement

chg: [widget:worldmap] Various JS and UI Improvements
pull/5705/head
Andras Iklody 2020-03-09 11:08:41 +01:00 committed by GitHub
commit 0e2babfa04
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 41 additions and 26 deletions

View File

@ -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>