1
- import { MetricsPanelCtrl } from ' grafana/app/plugins/sdk' ;
2
- import TimeSeries from ' grafana/app/core/time_series2' ;
1
+ import { MetricsPanelCtrl } from " grafana/app/plugins/sdk" ;
2
+ import TimeSeries from " grafana/app/core/time_series2" ;
3
3
4
- import * as _ from ' lodash' ;
5
- import DataFormatter from ' ./data_formatter' ;
6
- import ' ./css/worldmap-panel.css' ;
7
- import $ from ' jquery' ;
8
- import ' ./css/leaflet.css' ;
9
- import WorldMap from ' ./worldmap' ;
4
+ import * as _ from " lodash" ;
5
+ import DataFormatter from " ./data_formatter" ;
6
+ import " ./css/worldmap-panel.css" ;
7
+ import $ from " jquery" ;
8
+ import " ./css/leaflet.css" ;
9
+ import WorldMap from " ./worldmap" ;
10
10
11
11
const panelDefaults = {
12
12
maxDataPoints : 1 ,
13
- mapCenter : ' (0°, 0°)' ,
13
+ mapCenter : " (0°, 0°)" ,
14
14
mapCenterLatitude : 0 ,
15
15
mapCenterLongitude : 0 ,
16
16
initialZoom : 1 ,
17
- valueName : ' total' ,
17
+ valueName : " total" ,
18
18
circleMinSize : 2 ,
19
19
circleMaxSize : 30 ,
20
- locationData : 'countries' ,
21
- thresholds : '0,10' ,
22
- colors : [ 'rgba(245, 54, 54, 0.9)' , 'rgba(237, 129, 40, 0.89)' , 'rgba(50, 172, 45, 0.97)' ] ,
23
- unitSingle : '' ,
24
- unitPlural : '' ,
20
+ locationData : "countries" ,
21
+ thresholds : "0,10" ,
22
+ colors : [
23
+ "rgba(245, 54, 54, 0.9)" ,
24
+ "rgba(237, 129, 40, 0.89)" ,
25
+ "rgba(50, 172, 45, 0.97)"
26
+ ] ,
27
+ unitSingle : "" ,
28
+ unitPlural : "" ,
25
29
showLegend : true ,
26
30
mouseWheelZoom : false ,
27
- esMetric : ' Count' ,
31
+ esMetric : " Count" ,
28
32
decimals : 0 ,
29
33
hideEmpty : false ,
30
34
hideZero : false ,
31
35
stickyLabels : false ,
32
36
tableQueryOptions : {
33
- queryType : ' geohash' ,
34
- geohashField : ' geohash' ,
35
- latitudeField : ' latitude' ,
36
- longitudeField : ' longitude' ,
37
- metricField : ' metric' ,
38
- } ,
37
+ queryType : " geohash" ,
38
+ geohashField : " geohash" ,
39
+ latitudeField : " latitude" ,
40
+ longitudeField : " longitude" ,
41
+ metricField : " metric"
42
+ }
39
43
} ;
40
44
41
45
const mapCenters = {
42
- ' (0°, 0°)' : { mapCenterLatitude : 0 , mapCenterLongitude : 0 } ,
43
- ' North America' : { mapCenterLatitude : 40 , mapCenterLongitude : - 100 } ,
46
+ " (0°, 0°)" : { mapCenterLatitude : 0 , mapCenterLongitude : 0 } ,
47
+ " North America" : { mapCenterLatitude : 40 , mapCenterLongitude : - 100 } ,
44
48
Europe : { mapCenterLatitude : 46 , mapCenterLongitude : 14 } ,
45
- ' West Asia' : { mapCenterLatitude : 26 , mapCenterLongitude : 53 } ,
46
- ' SE Asia' : { mapCenterLatitude : 10 , mapCenterLongitude : 106 } ,
47
- ' Last GeoHash' : { mapCenterLatitude : 0 , mapCenterLongitude : 0 } ,
49
+ " West Asia" : { mapCenterLatitude : 26 , mapCenterLongitude : 53 } ,
50
+ " SE Asia" : { mapCenterLatitude : 10 , mapCenterLongitude : 106 } ,
51
+ " Last GeoHash" : { mapCenterLatitude : 0 , mapCenterLongitude : 0 }
48
52
} ;
49
53
50
54
export default class WorldmapCtrl extends MetricsPanelCtrl {
51
- static templateUrl = ' partials/module.html' ;
55
+ static templateUrl = " partials/module.html" ;
52
56
53
57
dataFormatter : DataFormatter ;
54
58
locations : any ;
@@ -68,24 +72,26 @@ export default class WorldmapCtrl extends MetricsPanelCtrl {
68
72
69
73
this . dataFormatter = new DataFormatter ( this ) ;
70
74
71
- this . events . on ( ' init-edit-mode' , this . onInitEditMode . bind ( this ) ) ;
72
- this . events . on ( ' data-received' , this . onDataReceived . bind ( this ) ) ;
73
- this . events . on ( ' panel-teardown' , this . onPanelTeardown . bind ( this ) ) ;
74
- this . events . on ( ' data-snapshot-load' , this . onDataSnapshotLoad . bind ( this ) ) ;
75
+ this . events . on ( " init-edit-mode" , this . onInitEditMode . bind ( this ) ) ;
76
+ this . events . on ( " data-received" , this . onDataReceived . bind ( this ) ) ;
77
+ this . events . on ( " panel-teardown" , this . onPanelTeardown . bind ( this ) ) ;
78
+ this . events . on ( " data-snapshot-load" , this . onDataSnapshotLoad . bind ( this ) ) ;
75
79
76
80
this . loadLocationDataFromFile ( ) ;
77
81
}
78
82
79
83
setMapProvider ( contextSrv ) {
80
- this . tileServer = contextSrv . user . lightTheme ? 'CartoDB Positron' : 'CartoDB Dark' ;
84
+ this . tileServer = contextSrv . user . lightTheme
85
+ ? "CartoDB Positron"
86
+ : "CartoDB Dark" ;
81
87
this . setMapSaturationClass ( ) ;
82
88
}
83
89
84
90
setMapSaturationClass ( ) {
85
- if ( this . tileServer === ' CartoDB Dark' ) {
86
- this . saturationClass = ' map-darken' ;
91
+ if ( this . tileServer === " CartoDB Dark" ) {
92
+ this . saturationClass = " map-darken" ;
87
93
} else {
88
- this . saturationClass = '' ;
94
+ this . saturationClass = "" ;
89
95
}
90
96
}
91
97
@@ -99,23 +105,23 @@ export default class WorldmapCtrl extends MetricsPanelCtrl {
99
105
return ;
100
106
}
101
107
102
- if ( this . panel . locationData === ' jsonp endpoint' ) {
108
+ if ( this . panel . locationData === " jsonp endpoint" ) {
103
109
if ( ! this . panel . jsonpUrl || ! this . panel . jsonpCallback ) {
104
110
return ;
105
111
}
106
112
107
113
$ . ajax ( {
108
- type : ' GET' ,
109
- url : this . panel . jsonpUrl + ' ?callback=?' ,
110
- contentType : ' application/json' ,
114
+ type : " GET" ,
115
+ url : this . panel . jsonpUrl + " ?callback=?" ,
116
+ contentType : " application/json" ,
111
117
jsonpCallback : this . panel . jsonpCallback ,
112
- dataType : ' jsonp' ,
118
+ dataType : " jsonp" ,
113
119
success : res => {
114
120
this . locations = res ;
115
121
this . render ( ) ;
116
- } ,
122
+ }
117
123
} ) ;
118
- } else if ( this . panel . locationData === ' json endpoint' ) {
124
+ } else if ( this . panel . locationData === " json endpoint" ) {
119
125
if ( ! this . panel . jsonUrl ) {
120
126
return ;
121
127
}
@@ -124,12 +130,17 @@ export default class WorldmapCtrl extends MetricsPanelCtrl {
124
130
this . locations = res ;
125
131
this . render ( ) ;
126
132
} ) ;
127
- } else if ( this . panel . locationData === ' table' ) {
133
+ } else if ( this . panel . locationData === " table" ) {
128
134
// .. Do nothing
129
- } else if ( this . panel . locationData !== 'geohash' && this . panel . locationData !== 'json result' ) {
130
- $ . getJSON ( 'public/plugins/grafana-worldmap-panel/data/' + this . panel . locationData + '.json' ) . then (
131
- this . reloadLocations . bind ( this )
132
- ) ;
135
+ } else if (
136
+ this . panel . locationData !== "geohash" &&
137
+ this . panel . locationData !== "json result"
138
+ ) {
139
+ $ . getJSON (
140
+ "public/plugins/grafana-worldmap-panel/data/" +
141
+ this . panel . locationData +
142
+ ".json"
143
+ ) . then ( this . reloadLocations . bind ( this ) ) ;
133
144
}
134
145
}
135
146
@@ -139,11 +150,17 @@ export default class WorldmapCtrl extends MetricsPanelCtrl {
139
150
}
140
151
141
152
showTableGeohashOptions ( ) {
142
- return this . panel . locationData === 'table' && this . panel . tableQueryOptions . queryType === 'geohash' ;
153
+ return (
154
+ this . panel . locationData === "table" &&
155
+ this . panel . tableQueryOptions . queryType === "geohash"
156
+ ) ;
143
157
}
144
158
145
159
showTableCoordinateOptions ( ) {
146
- return this . panel . locationData === 'table' && this . panel . tableQueryOptions . queryType === 'coordinates' ;
160
+ return (
161
+ this . panel . locationData === "table" &&
162
+ this . panel . tableQueryOptions . queryType === "coordinates"
163
+ ) ;
147
164
}
148
165
149
166
onPanelTeardown ( ) {
@@ -153,7 +170,11 @@ export default class WorldmapCtrl extends MetricsPanelCtrl {
153
170
}
154
171
155
172
onInitEditMode ( ) {
156
- this . addEditorTab ( 'Worldmap' , 'public/plugins/grafana-worldmap-panel/partials/editor.html' , 2 ) ;
173
+ this . addEditorTab (
174
+ "Worldmap" ,
175
+ "public/plugins/grafana-worldmap-panel/partials/editor.html" ,
176
+ 2
177
+ ) ;
157
178
}
158
179
159
180
onDataReceived ( dataList ) {
@@ -167,12 +188,12 @@ export default class WorldmapCtrl extends MetricsPanelCtrl {
167
188
168
189
const data = [ ] ;
169
190
170
- if ( this . panel . locationData === ' geohash' ) {
191
+ if ( this . panel . locationData === " geohash" ) {
171
192
this . dataFormatter . setGeohashValues ( dataList , data ) ;
172
- } else if ( this . panel . locationData === ' table' ) {
193
+ } else if ( this . panel . locationData === " table" ) {
173
194
const tableData = dataList . map ( DataFormatter . tableHandler . bind ( this ) ) ;
174
195
this . dataFormatter . setTableValues ( tableData , data ) ;
175
- } else if ( this . panel . locationData === ' json result' ) {
196
+ } else if ( this . panel . locationData === " json result" ) {
176
197
this . series = dataList ;
177
198
this . dataFormatter . setJsonValues ( data ) ;
178
199
} else {
@@ -183,7 +204,7 @@ export default class WorldmapCtrl extends MetricsPanelCtrl {
183
204
184
205
this . updateThresholdData ( ) ;
185
206
186
- if ( this . data . length && this . panel . mapCenter === ' Last GeoHash' ) {
207
+ if ( this . data . length && this . panel . mapCenter === " Last GeoHash" ) {
187
208
this . centerOnLastGeoHash ( ) ;
188
209
} else {
189
210
this . render ( ) ;
@@ -193,7 +214,8 @@ export default class WorldmapCtrl extends MetricsPanelCtrl {
193
214
centerOnLastGeoHash ( ) {
194
215
const last : any = _ . last ( this . data ) ;
195
216
mapCenters [ this . panel . mapCenter ] . mapCenterLatitude = last . locationLatitude ;
196
- mapCenters [ this . panel . mapCenter ] . mapCenterLongitude = last . locationLongitude ;
217
+ mapCenters [ this . panel . mapCenter ] . mapCenterLongitude =
218
+ last . locationLongitude ;
197
219
this . setNewMapCenter ( ) ;
198
220
}
199
221
@@ -204,17 +226,19 @@ export default class WorldmapCtrl extends MetricsPanelCtrl {
204
226
seriesHandler ( seriesData ) {
205
227
const series = new TimeSeries ( {
206
228
datapoints : seriesData . datapoints ,
207
- alias : seriesData . target ,
229
+ alias : seriesData . target
208
230
} ) ;
209
231
210
232
series . flotpairs = series . getFlotPairs ( this . panel . nullPointMode ) ;
211
233
return series ;
212
234
}
213
235
214
236
setNewMapCenter ( ) {
215
- if ( this . panel . mapCenter !== 'custom' ) {
216
- this . panel . mapCenterLatitude = mapCenters [ this . panel . mapCenter ] . mapCenterLatitude ;
217
- this . panel . mapCenterLongitude = mapCenters [ this . panel . mapCenter ] . mapCenterLongitude ;
237
+ if ( this . panel . mapCenter !== "custom" ) {
238
+ this . panel . mapCenterLatitude =
239
+ mapCenters [ this . panel . mapCenter ] . mapCenterLatitude ;
240
+ this . panel . mapCenterLongitude =
241
+ mapCenters [ this . panel . mapCenter ] . mapCenterLongitude ;
218
242
}
219
243
this . mapCenterMoved = true ;
220
244
this . render ( ) ;
@@ -248,7 +272,7 @@ export default class WorldmapCtrl extends MetricsPanelCtrl {
248
272
}
249
273
250
274
updateThresholdData ( ) {
251
- this . data . thresholds = this . panel . thresholds . split ( ',' ) . map ( strValue => {
275
+ this . data . thresholds = this . panel . thresholds . split ( "," ) . map ( strValue => {
252
276
return Number ( strValue . trim ( ) ) ;
253
277
} ) ;
254
278
while ( _ . size ( this . panel . colors ) > _ . size ( this . data . thresholds ) + 1 ) {
@@ -257,21 +281,21 @@ export default class WorldmapCtrl extends MetricsPanelCtrl {
257
281
}
258
282
while ( _ . size ( this . panel . colors ) < _ . size ( this . data . thresholds ) + 1 ) {
259
283
// not enough colors. add one.
260
- const newColor = ' rgba(50, 172, 45, 0.97)' ;
284
+ const newColor = " rgba(50, 172, 45, 0.97)" ;
261
285
this . panel . colors . push ( newColor ) ;
262
286
}
263
287
}
264
288
265
289
changeLocationData ( ) {
266
290
this . loadLocationDataFromFile ( true ) ;
267
291
268
- if ( this . panel . locationData === ' geohash' ) {
292
+ if ( this . panel . locationData === " geohash" ) {
269
293
this . render ( ) ;
270
294
}
271
295
}
272
296
273
297
link ( scope , elem , attrs , ctrl ) {
274
- ctrl . events . on ( ' render' , ( ) => {
298
+ ctrl . events . on ( " render" , ( ) => {
275
299
render ( ) ;
276
300
ctrl . renderingCompleted ( ) ;
277
301
} ) ;
@@ -281,9 +305,9 @@ export default class WorldmapCtrl extends MetricsPanelCtrl {
281
305
return ;
282
306
}
283
307
284
- const mapContainer = elem . find ( ' .mapcontainer' ) ;
308
+ const mapContainer = elem . find ( " .mapcontainer" ) ;
285
309
286
- if ( mapContainer [ 0 ] . id . indexOf ( '{{' ) > - 1 ) {
310
+ if ( mapContainer [ 0 ] . id . indexOf ( "{{" ) > - 1 ) {
287
311
return ;
288
312
}
289
313
@@ -293,7 +317,9 @@ export default class WorldmapCtrl extends MetricsPanelCtrl {
293
317
ctrl . map = map ;
294
318
}
295
319
296
- ctrl . map . resize ( ) ;
320
+ setTimeout ( ( ) => {
321
+ ctrl . map . resize ( ) ;
322
+ } , 1 ) ;
297
323
298
324
if ( ctrl . mapCenterMoved ) {
299
325
ctrl . map . panToMapCenter ( ) ;
0 commit comments