11import { MetricsPanelCtrl } from "grafana/app/plugins/sdk" ;
22import TimeSeries from "grafana/app/core/time_series2" ;
3- import appEvents from 'grafana/app/core/app_events' ;
3+ import appEvents from "grafana/app/core/app_events" ;
4+ import { textUtil } from "@grafana/data" ;
45
56import * as _ from "lodash" ;
67import DataFormatter from "./data_formatter" ;
@@ -23,7 +24,7 @@ const panelDefaults = {
2324 colors : [
2425 "rgba(245, 54, 54, 0.9)" ,
2526 "rgba(237, 129, 40, 0.89)" ,
26- "rgba(50, 172, 45, 0.97)"
27+ "rgba(50, 172, 45, 0.97)" ,
2728 ] ,
2829 unitSingle : "" ,
2930 unitPlural : "" ,
@@ -39,8 +40,8 @@ const panelDefaults = {
3940 geohashField : "geohash" ,
4041 latitudeField : "latitude" ,
4142 longitudeField : "longitude" ,
42- metricField : "metric"
43- }
43+ metricField : "metric" ,
44+ } ,
4445} ;
4546
4647const mapCenters = {
@@ -49,7 +50,7 @@ const mapCenters = {
4950 Europe : { mapCenterLatitude : 46 , mapCenterLongitude : 14 } ,
5051 "West Asia" : { mapCenterLatitude : 26 , mapCenterLongitude : 53 } ,
5152 "SE Asia" : { mapCenterLatitude : 10 , mapCenterLongitude : 106 } ,
52- "Last GeoHash" : { mapCenterLatitude : 0 , mapCenterLongitude : 0 }
53+ "Last GeoHash" : { mapCenterLatitude : 0 , mapCenterLongitude : 0 } ,
5354} ;
5455
5556export default class WorldmapCtrl extends MetricsPanelCtrl {
@@ -111,23 +112,28 @@ export default class WorldmapCtrl extends MetricsPanelCtrl {
111112 return ;
112113 }
113114
115+ this . panel . jsonpUrl = textUtil . sanitizeUrl ( this . panel . jsonpUrl ) ;
116+ this . panel . jsonpCallback = textUtil . sanitizeUrl ( this . panel . jsonpCallback ) ;
117+
114118 $ . ajax ( {
115119 type : "GET" ,
116120 url : this . panel . jsonpUrl + "?callback=?" ,
117121 contentType : "application/json" ,
118122 jsonpCallback : this . panel . jsonpCallback ,
119123 dataType : "jsonp" ,
120- success : res => {
124+ success : ( res ) => {
121125 this . locations = res ;
122126 this . render ( ) ;
123- }
127+ } ,
124128 } ) ;
125129 } else if ( this . panel . locationData === "json endpoint" ) {
126130 if ( ! this . panel . jsonUrl ) {
127131 return ;
128132 }
129133
130- $ . getJSON ( this . panel . jsonUrl ) . then ( res => {
134+ this . panel . jsonUrl = textUtil . sanitizeUrl ( this . panel . jsonUrl ) ;
135+
136+ $ . getJSON ( this . panel . jsonUrl ) . then ( ( res ) => {
131137 this . locations = res ;
132138 this . render ( ) ;
133139 } ) ;
@@ -212,7 +218,7 @@ export default class WorldmapCtrl extends MetricsPanelCtrl {
212218 this . render ( ) ;
213219 }
214220 } catch ( err ) {
215- appEvents . emit ( ' alert-error' , [ ' Data error' , err . toString ( ) ] )
221+ appEvents . emit ( " alert-error" , [ " Data error" , err . toString ( ) ] ) ;
216222 }
217223 }
218224
@@ -231,7 +237,7 @@ export default class WorldmapCtrl extends MetricsPanelCtrl {
231237 seriesHandler ( seriesData ) {
232238 const series = new TimeSeries ( {
233239 datapoints : seriesData . datapoints ,
234- alias : seriesData . target
240+ alias : seriesData . target ,
235241 } ) ;
236242
237243 series . flotpairs = series . getFlotPairs ( this . panel . nullPointMode ) ;
@@ -277,7 +283,7 @@ export default class WorldmapCtrl extends MetricsPanelCtrl {
277283 }
278284
279285 updateThresholdData ( ) {
280- this . data . thresholds = this . panel . thresholds . split ( "," ) . map ( strValue => {
286+ this . data . thresholds = this . panel . thresholds . split ( "," ) . map ( ( strValue ) => {
281287 return Number ( strValue . trim ( ) ) ;
282288 } ) ;
283289 while ( _ . size ( this . panel . colors ) > _ . size ( this . data . thresholds ) + 1 ) {
@@ -307,7 +313,7 @@ export default class WorldmapCtrl extends MetricsPanelCtrl {
307313 ctrl . renderingCompleted ( ) ;
308314 } ) ;
309315
310- function render ( ) {
316+ function render ( ) {
311317 if ( ! ctrl . data ) {
312318 return ;
313319 }
0 commit comments