Skip to content

Commit 65b1bd9

Browse files
committed
fix merge conflict
2 parents c428799 + 3f3fef9 commit 65b1bd9

File tree

10 files changed

+82
-6
lines changed

10 files changed

+82
-6
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,15 @@ Similar to the Elasticsearch query above, 3 fields are expected (2 of them are m
9292

9393
![Example influxdb query](https://cloud.githubusercontent.com/assets/434655/16535977/8cd520be-3fec-11e6-8dc9-2ecf7b16ad5f.png)
9494

95+
## JSON result as the Data Source
96+
97+
98+
Supported Databases:
99+
100+
- Warp 10 via [grafana-warp10-datasource](https://github.com/cityzendata/grafana-warp10) plugin
101+
102+
It supports any datasource capable of generating a JSON response with a a custom list of locations (the same format that for the JSON enpoint).
103+
95104
### Map Visual Option Settings
96105

97106
**Center**

dist/README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,15 @@ Similar to the Elasticsearch query above, 3 fields are expected (2 of them are m
9292

9393
![Example influxdb query](https://cloud.githubusercontent.com/assets/434655/16535977/8cd520be-3fec-11e6-8dc9-2ecf7b16ad5f.png)
9494

95+
## JSON result as the Data Source
96+
97+
98+
Supported Databases:
99+
100+
- Warp 10 via [grafana-warp10-datasource](https://github.com/cityzendata/grafana-warp10) plugin
101+
102+
It supports any datasource capable of generating a JSON response with a a custom list of locations (the same format that for the JSON enpoint).
103+
95104
### Map Visual Option Settings
96105

97106
**Center**

dist/data_formatter.js

Lines changed: 26 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/data_formatter.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/partials/editor.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ <h5 class="section-heading">Map Data Options</h5>
4545
<div class="gf-form">
4646
<label class="gf-form-label width-12">Location Data</label>
4747
<div class="gf-form-select-wrapper max-width-10">
48-
<select class="input-small gf-form-input" ng-model="ctrl.panel.locationData" ng-options="t for t in ['countries', 'countries_3letter', 'states', 'probes', 'geohash', 'json endpoint', 'jsonp endpoint', 'table']" ng-change="ctrl.changeLocationData()"></select>
48+
<select class="input-small gf-form-input" ng-model="ctrl.panel.locationData" ng-options="t for t in ['countries', 'countries_3letter', 'states', 'probes', 'geohash', 'json endpoint', 'jsonp endpoint', 'json result', 'table']" ng-change="ctrl.changeLocationData()"></select>
4949
</div>
5050
</div>
5151
<div class="gf-form" ng-show="ctrl.panel.locationData !== 'geohash'">

dist/worldmap_ctrl.js

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

dist/worldmap_ctrl.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.

src/data_formatter.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,4 +172,30 @@ export default class DataFormatter {
172172
data.valueRange = highestValue - lowestValue;
173173
}
174174
}
175+
176+
setJsonValues(data) {
177+
if (this.ctrl.series && this.ctrl.series.length > 0) {
178+
let highestValue = 0;
179+
let lowestValue = Number.MAX_VALUE;
180+
181+
this.ctrl.series.forEach((point) => {
182+
const dataValue = {
183+
key: point.key,
184+
locationName: point.name,
185+
locationLatitude: point.latitude,
186+
locationLongitude: point.longitude,
187+
value: (point.value !== undefined) ? point.value : 1,
188+
valueRounded: 0
189+
};
190+
if (dataValue.value > highestValue) highestValue = dataValue.value;
191+
if (dataValue.value < lowestValue) lowestValue = dataValue.value;
192+
dataValue.valueRounded = Math.round(dataValue.value);
193+
data.push(dataValue);
194+
});
195+
data.highestValue = highestValue;
196+
data.lowestValue = lowestValue;
197+
data.valueRange = highestValue - lowestValue;
198+
}
199+
}
175200
}
201+

src/partials/editor.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ <h5 class="section-heading">Map Data Options</h5>
4545
<div class="gf-form">
4646
<label class="gf-form-label width-12">Location Data</label>
4747
<div class="gf-form-select-wrapper max-width-10">
48-
<select class="input-small gf-form-input" ng-model="ctrl.panel.locationData" ng-options="t for t in ['countries', 'countries_3letter', 'states', 'probes', 'geohash', 'json endpoint', 'jsonp endpoint', 'table']" ng-change="ctrl.changeLocationData()"></select>
48+
<select class="input-small gf-form-input" ng-model="ctrl.panel.locationData" ng-options="t for t in ['countries', 'countries_3letter', 'states', 'probes', 'geohash', 'json endpoint', 'jsonp endpoint', 'json result', 'table']" ng-change="ctrl.changeLocationData()"></select>
4949
</div>
5050
</div>
5151
<div class="gf-form" ng-show="ctrl.panel.locationData !== 'geohash'">

src/worldmap_ctrl.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ export default class WorldmapCtrl extends MetricsPanelCtrl {
100100
});
101101
} else if (this.panel.locationData === 'table') {
102102
// .. Do nothing
103-
} else if (this.panel.locationData !== 'geohash') {
103+
} else if (this.panel.locationData !== 'geohash' && this.panel.locationData !== 'json result') {
104104
window.$.getJSON('public/plugins/grafana-worldmap-panel/data/' + this.panel.locationData + '.json')
105105
.then(this.reloadLocations.bind(this));
106106
}
@@ -133,6 +133,9 @@ export default class WorldmapCtrl extends MetricsPanelCtrl {
133133
} else if (this.panel.locationData === 'table') {
134134
const tableData = dataList.map(DataFormatter.tableHandler.bind(this));
135135
this.dataFormatter.setTableValues(tableData, data);
136+
} else if (this.panel.locationData === 'json result') {
137+
this.series = dataList;
138+
this.dataFormatter.setJsonValues(data);
136139
} else {
137140
this.series = dataList.map(this.seriesHandler.bind(this));
138141
this.dataFormatter.setValues(data);

0 commit comments

Comments
 (0)