Skip to content
This repository was archived by the owner on Jan 23, 2025. It is now read-only.

Commit f652100

Browse files
committed
Add error handling to onDataRecevied, fixes #213
1 parent 5f71ecd commit f652100

File tree

7 files changed

+71
-35
lines changed

7 files changed

+71
-35
lines changed

CHANGELOG.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
# Changelog
22

3+
## v0.2.1
4+
5+
- Fixes partial (not full height) map on first render [#212](https://github.com/grafana/worldmap-panel/issues/212)
6+
7+
## v0.2.0
8+
9+
- Convert to TypeScript, webpack and Jest
10+
- Use Yarn on CircleCI
11+
- Add missing dev dependencies
12+
- Tweak for incorrect height on render
13+
which occurs more frequently in Grafana 6.0
14+
315
## v0.1.2
416

517
- Map centering ignores configured location [#149](https://github.com/grafana/worldmap-panel/issues/149) Thanks [@clompsy](https://github.com/clompsy)
@@ -13,7 +25,7 @@
1325
## v0.1.0
1426

1527
- Configuration option for turning mouse wheel zoom on or off. [#140](https://github.com/grafana/worldmap-panel/issues/140) Thanks [@Perlovka](https://github.com/Perlovka)
16-
- Upgrade to Leaflet JS [#132](https://github.com/grafana/worldmap-panel/pull/132) Thanks [@cbarbier](https://github.com/cbarbier)
28+
- Upgrade to Leaflet JS [#132](https://github.com/grafana/worldmap-panel/pull/132) Thanks [@cbarbier](https://github.com/cbarbier)
1729

1830
## v0.0.21
1931

dist/CHANGELOG.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
# Changelog
22

3+
## v0.2.1
4+
5+
- Fixes partial (not full height) map on first render [#212](https://github.com/grafana/worldmap-panel/issues/212)
6+
7+
## v0.2.0
8+
9+
- Convert to TypeScript, webpack and Jest
10+
- Use Yarn on CircleCI
11+
- Add missing dev dependencies
12+
- Tweak for incorrect height on render
13+
which occurs more frequently in Grafana 6.0
14+
315
## v0.1.2
416

517
- Map centering ignores configured location [#149](https://github.com/grafana/worldmap-panel/issues/149) Thanks [@clompsy](https://github.com/clompsy)
@@ -13,7 +25,7 @@
1325
## v0.1.0
1426

1527
- Configuration option for turning mouse wheel zoom on or off. [#140](https://github.com/grafana/worldmap-panel/issues/140) Thanks [@Perlovka](https://github.com/Perlovka)
16-
- Upgrade to Leaflet JS [#132](https://github.com/grafana/worldmap-panel/pull/132) Thanks [@cbarbier](https://github.com/cbarbier)
28+
- Upgrade to Leaflet JS [#132](https://github.com/grafana/worldmap-panel/pull/132) Thanks [@cbarbier](https://github.com/cbarbier)
1729

1830
## v0.0.21
1931

dist/module.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/module.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/plugin.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
{"name": "USA", "path": "images/worldmap-usa.png"},
2424
{"name": "Light Theme", "path": "images/worldmap-light-theme.png"}
2525
],
26-
"version": "0.2.0",
27-
"updated": "2019-02-21"
26+
"version": "0.2.1",
27+
"updated": "2019-08-29"
2828
},
2929

3030
"dependencies": {

src/plugin.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
{"name": "USA", "path": "images/worldmap-usa.png"},
2424
{"name": "Light Theme", "path": "images/worldmap-light-theme.png"}
2525
],
26-
"version": "0.2.0",
27-
"updated": "2019-02-21"
26+
"version": "0.2.1",
27+
"updated": "2019-08-29"
2828
},
2929

3030
"dependencies": {

src/worldmap_ctrl.ts

Lines changed: 39 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { MetricsPanelCtrl } from "grafana/app/plugins/sdk";
22
import TimeSeries from "grafana/app/core/time_series2";
3+
import appEvents from 'grafana/app/core/app_events';
34

45
import * as _ from "lodash";
56
import DataFormatter from "./data_formatter";
@@ -182,32 +183,36 @@ export default class WorldmapCtrl extends MetricsPanelCtrl {
182183
return;
183184
}
184185

185-
if (this.dashboard.snapshot && this.locations) {
186-
this.panel.snapshotLocationData = this.locations;
187-
}
188-
189-
const data = [];
186+
try {
187+
if (this.dashboard.snapshot && this.locations) {
188+
this.panel.snapshotLocationData = this.locations;
189+
}
190190

191-
if (this.panel.locationData === "geohash") {
192-
this.dataFormatter.setGeohashValues(dataList, data);
193-
} else if (this.panel.locationData === "table") {
194-
const tableData = dataList.map(DataFormatter.tableHandler.bind(this));
195-
this.dataFormatter.setTableValues(tableData, data);
196-
} else if (this.panel.locationData === "json result") {
197-
this.series = dataList;
198-
this.dataFormatter.setJsonValues(data);
199-
} else {
200-
this.series = dataList.map(this.seriesHandler.bind(this));
201-
this.dataFormatter.setValues(data);
202-
}
203-
this.data = data;
191+
const data = [];
192+
193+
if (this.panel.locationData === "geohash") {
194+
this.dataFormatter.setGeohashValues(dataList, data);
195+
} else if (this.panel.locationData === "table") {
196+
const tableData = dataList.map(DataFormatter.tableHandler.bind(this));
197+
this.dataFormatter.setTableValues(tableData, data);
198+
} else if (this.panel.locationData === "json result") {
199+
this.series = dataList;
200+
this.dataFormatter.setJsonValues(data);
201+
} else {
202+
this.series = dataList.map(this.seriesHandler.bind(this));
203+
this.dataFormatter.setValues(data);
204+
}
205+
this.data = data;
204206

205-
this.updateThresholdData();
207+
this.updateThresholdData();
206208

207-
if (this.data.length && this.panel.mapCenter === "Last GeoHash") {
208-
this.centerOnLastGeoHash();
209-
} else {
210-
this.render();
209+
if (this.data.length && this.panel.mapCenter === "Last GeoHash") {
210+
this.centerOnLastGeoHash();
211+
} else {
212+
this.render();
213+
}
214+
} catch (err) {
215+
appEvents.emit('alert-error', ['Data error', err.toString()])
211216
}
212217
}
213218

@@ -295,16 +300,25 @@ export default class WorldmapCtrl extends MetricsPanelCtrl {
295300
}
296301

297302
link(scope, elem, attrs, ctrl) {
303+
let firstRender = true;
304+
298305
ctrl.events.on("render", () => {
299306
render();
300307
ctrl.renderingCompleted();
301308
});
302309

303-
function render() {
310+
function render() {
304311
if (!ctrl.data) {
305312
return;
306313
}
307314

315+
// delay first render as the map panel sizing is bugged first render even though the element has correct height
316+
if (firstRender) {
317+
firstRender = false;
318+
setTimeout(render, 100);
319+
return;
320+
}
321+
308322
const mapContainer = elem.find(".mapcontainer");
309323

310324
if (mapContainer[0].id.indexOf("{{") > -1) {
@@ -317,9 +331,7 @@ export default class WorldmapCtrl extends MetricsPanelCtrl {
317331
ctrl.map = map;
318332
}
319333

320-
setTimeout(() => {
321-
ctrl.map.resize();
322-
}, 1);
334+
ctrl.map.resize();
323335

324336
if (ctrl.mapCenterMoved) {
325337
ctrl.map.panToMapCenter();

0 commit comments

Comments
 (0)