Skip to content

Commit b2c802b

Browse files
committed
merging master
2 parents da3aa34 + c776ba4 commit b2c802b

File tree

2 files changed

+30
-24
lines changed

2 files changed

+30
-24
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
# Changelog
22

3-
43
## v0.3.0
54

5+
- Fixes error handling that made everything disappear in edit mode, [#213](https://github.com/grafana/worldmap-panel/issues/213)
6+
- Fixes partial (not full height) map on first render [#212](https://github.com/grafana/worldmap-panel/issues/212)
67
- Add new mapping options `table+json` and `table+jsonp` to retrieve
78
location information from JSON endpoint, even for table data.
89
The lookup key is the value obtained from the database field
@@ -55,6 +56,7 @@
5556
- Acquire location data again after being cleared out when hitting an empty dataset
5657
- Improve initialisation and refresh behaviour
5758

59+
5860
## v0.2.0
5961

6062
- Convert to TypeScript, webpack and Jest

src/worldmap_ctrl.ts

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { WorldmapCore } from './core';
1010
import { WorldmapChrome } from './chrome';
1111
import { ErrorManager } from './errors';
1212
import DataFormatter from './data_formatter';
13+
import appEvents from 'grafana/app/core/app_events';
1314

1415
const panelDefaults = {
1516
maxDataPoints: 1,
@@ -264,13 +265,16 @@ export default class WorldmapCtrl extends MetricsPanelCtrl {
264265
* Obtain data from the Grafana data source,
265266
* decode appropriately and render the map.
266267
*/
267-
268268
console.info('Data received:', dataList);
269269

270270
// Is this the right place to indicate the plugin has been initialized?
271271
this.initializing = false;
272272

273273
try {
274+
if (this.dashboard.snapshot && this.locations) {
275+
this.panel.snapshotLocationData = this.locations;
276+
}
277+
274278
this.processData(dataList);
275279

276280
this.updateThresholdData();
@@ -280,9 +284,9 @@ export default class WorldmapCtrl extends MetricsPanelCtrl {
280284
if (this.data.length && autoCenterMap) {
281285
this.updateMapCenter(false);
282286
}
283-
} catch (e) {
284-
this.errors.add(e, { domain: 'data' });
285-
throw e;
287+
} catch (err) {
288+
this.errors.add(err, { domain: 'data' });
289+
appEvents.emit('alert-error', ['Data error', err.toString()]);
286290
} finally {
287291
this.render();
288292
}
@@ -370,48 +374,48 @@ export default class WorldmapCtrl extends MetricsPanelCtrl {
370374
}
371375

372376
link(scope, elem, attrs, ctrl) {
373-
/*
374-
* Hook the panel into the rendering phase.
375-
*/
377+
let firstRender = true;
376378

377-
ctrl.events.on('render', ev => {
378-
// Perform rendering.
379+
ctrl.events.on('render', () => {
379380
render();
380381
ctrl.renderingCompleted();
381-
console.info('Rendering panel completed');
382-
383-
// Propagate warnings and errors to tooltip in panel corner.
384-
ctrl.propagateWarningsAndErrors();
385382
});
386383

387384
function render() {
388-
console.info('Rendering panel');
389385
if (!ctrl.data) {
390386
return;
391387
}
392388

389+
// delay first render as the map panel sizing is bugged first render even though the element has correct height
390+
if (firstRender) {
391+
firstRender = false;
392+
setTimeout(render, 100);
393+
return;
394+
}
395+
393396
const mapContainer = elem.find('.mapcontainer');
394397

395398
if (mapContainer[0].id.indexOf('{{') > -1) {
396399
return;
397400
}
398401

399-
console.info('Rendering map');
400402
if (!ctrl.map) {
401-
// Create map.
402403
const map = new WorldMap(ctrl, mapContainer[0]);
403404
map.createMap();
404405
ctrl.map = map;
406+
}
405407

406-
// When rendering the first time, make sure to signal `panToMapCenter()`.
407-
ctrl.mapCenterMoved = true;
408+
ctrl.map.resize();
408409

409-
// Render the map the first time, timing-safe.
410-
ctrl.map.renderMapFirst();
411-
} else {
412-
// Invoke regular map rendering.
413-
ctrl.map.renderMap();
410+
if (ctrl.mapCenterMoved) {
411+
ctrl.map.panToMapCenter();
414412
}
413+
414+
if (!ctrl.map.legend && ctrl.panel.showLegend) {
415+
ctrl.map.createLegend();
416+
}
417+
418+
ctrl.map.drawCircles();
415419
}
416420
}
417421

0 commit comments

Comments
 (0)