Skip to content

Commit

Permalink
support different color thresholds per layer (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
chicco785 authored Aug 16, 2019
1 parent 391666b commit a680fbc
Show file tree
Hide file tree
Showing 10 changed files with 136 additions and 137 deletions.
79 changes: 35 additions & 44 deletions dist/partials/editor.html
Original file line number Diff line number Diff line change
Expand Up @@ -151,55 +151,46 @@ <h5 class="section-heading">{{layerName}}</h5>
>
<option value=""></option>
</select>
</div>
</div>
</div>

<div class="section gf-form-group">
<h5 class="section-heading">Markers Coloring</h5>

<div class="gf-form">
<label class="gf-form-label width-10">Column</label>
<input type="text"
class="input-small gf-form-input width-12"
ng-model="ctrl.panel.geoMarkerColoringBinding"
ng-change="ctrl.render()" />
</div>
<label class="gf-form-label width-10">Column</label>
<input type="text"
class="input-small gf-form-input width-12"
ng-model="ctrl.panel.geoMarkerColoringBinding[layerName]"
ng-change="ctrl.render()" />

<div class="gf-form">
<label class="gf-form-label width-10">Color Thresholds</label>
<input type="text"
class="input-small gf-form-input width-12"
placeholder="50, 100"
ng-model="ctrl.panel.geoMarkerColoringThresholds"
ng-change="ctrl.render()" />
</div>
<label class="gf-form-label width-10">Color Thresholds</label>
<input type="text"
class="input-small gf-form-input width-12"
placeholder="50, 100"
ng-model="ctrl.panel.geoMarkerColoringThresholds[layerName]"
ng-change="ctrl.render()" />

<label class="gf-form-label width-10">Colors</label>

<select class="gf-form-input width-12"
ng-model="ctrl.panel.geoMarkerColoringColorLow[layerName]"
ng-options="markerColor for markerColor in ctrl.markerColors"
ng-change="ctrl.render()"
title="Color low">
</select>

<div class="gf-form">
<label class="gf-form-label width-10">Colors</label>

<select class="gf-form-input"
ng-model="ctrl.panel.geoMarkerColoringColorLow"
ng-options="markerColor for markerColor in ctrl.markerColors"
ng-change="ctrl.render()"
title="Color low">
</select>

<select class="gf-form-input"
ng-model="ctrl.panel.geoMarkerColoringColorMedium"
ng-options="markerColor for markerColor in ctrl.markerColors"
ng-change="ctrl.render()"
title="Color medium">
</select>

<select class="gf-form-input"
ng-model="ctrl.panel.geoMarkerColoringColorHigh"
ng-options="markerColor for markerColor in ctrl.markerColors"
ng-change="ctrl.render()"
title="Color high">
</select>
</div>
<select class="gf-form-input width-12"
ng-model="ctrl.panel.geoMarkerColoringColorMedium[layerName]"
ng-options="markerColor for markerColor in ctrl.markerColors"
ng-change="ctrl.render()"
title="Color medium">
</select>

<select class="gf-form-input width-12"
ng-model="ctrl.panel.geoMarkerColoringColorHigh[layerName]"
ng-options="markerColor for markerColor in ctrl.markerColors"
ng-change="ctrl.render()"
title="Color high">
</select>

</div>
</div>
</div>

<div>
Expand Down
2 changes: 1 addition & 1 deletion dist/plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
{"name": "Project site", "url": ""},
{"name": "MIT License", "url": ""}
],
"version": "1.3.1"
"version": "1.3.2"
},

"dependencies": {
Expand Down
48 changes: 26 additions & 22 deletions dist/worldmap.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/worldmap.js.map

Large diffs are not rendered by default.

7 changes: 6 additions & 1 deletion dist/worldmap_ctrl.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/worldmap_ctrl.js.map

Large diffs are not rendered by default.

79 changes: 35 additions & 44 deletions src/partials/editor.html
Original file line number Diff line number Diff line change
Expand Up @@ -151,55 +151,46 @@ <h5 class="section-heading">{{layerName}}</h5>
>
<option value=""></option>
</select>
</div>
</div>
</div>

<div class="section gf-form-group">
<h5 class="section-heading">Markers Coloring</h5>

<div class="gf-form">
<label class="gf-form-label width-10">Column</label>
<input type="text"
class="input-small gf-form-input width-12"
ng-model="ctrl.panel.geoMarkerColoringBinding"
ng-change="ctrl.render()" />
</div>
<label class="gf-form-label width-10">Column</label>
<input type="text"
class="input-small gf-form-input width-12"
ng-model="ctrl.panel.geoMarkerColoringBinding[layerName]"
ng-change="ctrl.render()" />

<div class="gf-form">
<label class="gf-form-label width-10">Color Thresholds</label>
<input type="text"
class="input-small gf-form-input width-12"
placeholder="50, 100"
ng-model="ctrl.panel.geoMarkerColoringThresholds"
ng-change="ctrl.render()" />
</div>
<label class="gf-form-label width-10">Color Thresholds</label>
<input type="text"
class="input-small gf-form-input width-12"
placeholder="50, 100"
ng-model="ctrl.panel.geoMarkerColoringThresholds[layerName]"
ng-change="ctrl.render()" />

<label class="gf-form-label width-10">Colors</label>

<select class="gf-form-input width-12"
ng-model="ctrl.panel.geoMarkerColoringColorLow[layerName]"
ng-options="markerColor for markerColor in ctrl.markerColors"
ng-change="ctrl.render()"
title="Color low">
</select>

<div class="gf-form">
<label class="gf-form-label width-10">Colors</label>

<select class="gf-form-input"
ng-model="ctrl.panel.geoMarkerColoringColorLow"
ng-options="markerColor for markerColor in ctrl.markerColors"
ng-change="ctrl.render()"
title="Color low">
</select>

<select class="gf-form-input"
ng-model="ctrl.panel.geoMarkerColoringColorMedium"
ng-options="markerColor for markerColor in ctrl.markerColors"
ng-change="ctrl.render()"
title="Color medium">
</select>

<select class="gf-form-input"
ng-model="ctrl.panel.geoMarkerColoringColorHigh"
ng-options="markerColor for markerColor in ctrl.markerColors"
ng-change="ctrl.render()"
title="Color high">
</select>
</div>
<select class="gf-form-input width-12"
ng-model="ctrl.panel.geoMarkerColoringColorMedium[layerName]"
ng-options="markerColor for markerColor in ctrl.markerColors"
ng-change="ctrl.render()"
title="Color medium">
</select>

<select class="gf-form-input width-12"
ng-model="ctrl.panel.geoMarkerColoringColorHigh[layerName]"
ng-options="markerColor for markerColor in ctrl.markerColors"
ng-change="ctrl.render()"
title="Color high">
</select>

</div>
</div>
</div>

<div>
Expand Down
2 changes: 1 addition & 1 deletion src/plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
{"name": "Project site", "url": ""},
{"name": "MIT License", "url": ""}
],
"version": "1.3.1"
"version": "1.3.2"
},

"dependencies": {
Expand Down
46 changes: 24 additions & 22 deletions src/worldmap.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,20 +193,20 @@ export default class WorldMap {
}

getGeoMarkerColor(objectValues) {
const bindingValue = objectValues[this.ctrl.panel.geoMarkerColoringBinding];
const {medium, high} = this.getGeoMarkerColorThesholds();
const bindingValue = objectValues[this.ctrl.panel.geoMarkerColoringBinding[objectValues.type]];
const {medium, high} = this.getGeoMarkerColorThesholds(objectValues);

if (bindingValue < medium) {
return this.ctrl.panel.geoMarkerColoringColorLow;
return this.ctrl.panel.geoMarkerColoringColorLow[objectValues.type];
}
if (bindingValue > high) {
return this.ctrl.panel.geoMarkerColoringColorHigh;
return this.ctrl.panel.geoMarkerColoringColorHigh[objectValues.type];
}
return this.ctrl.panel.geoMarkerColoringColorMedium;
return this.ctrl.panel.geoMarkerColoringColorMedium[objectValues.type];
}

getGeoMarkerColorThesholds() {
const thresholds = this.ctrl.panel.geoMarkerColoringThresholds || '';
getGeoMarkerColorThesholds(objectValues) {
const thresholds = this.ctrl.panel.geoMarkerColoringThresholds[objectValues.type] || '';
const splitted = thresholds.split(',');
return {
medium: parseInt(splitted[0], 10),
Expand Down Expand Up @@ -407,23 +407,25 @@ export default class WorldMap {
}

setDefaultValues() {
if (this.ctrl.panel.geoMarkerColoringBinding === undefined) {
this.ctrl.panel.geoMarkerColoringBinding = 'value';
}
Object.keys(this.ctrl.data).forEach((layerKey) => {
if (this.ctrl.panel.geoMarkerColoringBinding[layerKey] === undefined) {
this.ctrl.panel.geoMarkerColoringBinding[layerKey] = 'value';
}

if (this.ctrl.panel.geoMarkerColoringThresholds === undefined) {
this.ctrl.panel.geoMarkerColoringThresholds = '30, 50';
}
if (this.ctrl.panel.geoMarkerColoringThresholds[layerKey] === undefined) {
this.ctrl.panel.geoMarkerColoringThresholds[layerKey] = '30, 50';
}

if (this.ctrl.panel.geoMarkerColoringColorLow === undefined) {
this.ctrl.panel.geoMarkerColoringColorLow = 'red';
}
if (this.ctrl.panel.geoMarkerColoringColorMedium === undefined) {
this.ctrl.panel.geoMarkerColoringColorMedium = 'orange';
}
if (this.ctrl.panel.geoMarkerColoringColorHigh === undefined) {
this.ctrl.panel.geoMarkerColoringColorHigh = 'green';
}
if (this.ctrl.panel.geoMarkerColoringColorLow[layerKey] === undefined) {
this.ctrl.panel.geoMarkerColoringColorLow[layerKey] = 'red';
}
if (this.ctrl.panel.geoMarkerColoringColorMedium[layerKey] === undefined) {
this.ctrl.panel.geoMarkerColoringColorMedium[layerKey] = 'orange';
}
if (this.ctrl.panel.geoMarkerColoringColorHigh[layerKey] === undefined) {
this.ctrl.panel.geoMarkerColoringColorHigh[layerKey] = 'green';
}
});
}
}

Expand Down
6 changes: 6 additions & 0 deletions src/worldmap_ctrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ export default class WorldmapCtrl extends MetricsPanelCtrl {
this.markerColors = MARKER_COLORS;
this.environmentVars = this.templateSrv.variables.map((elem) => elem.name);

this.panel.geoMarkerColoringColorHigh = [];
this.panel.geoMarkerColoringColorMedium = [];
this.panel.geoMarkerColoringColorLow = [];
this.panel.geoMarkerColoringThresholds = [];
this.panel.geoMarkerColoringBinding = [];

// bind grafana events
this.events.on('init-edit-mode', this.onInitEditMode.bind(this));
this.events.on('data-error', this.onDataError.bind(this));
Expand Down

0 comments on commit a680fbc

Please sign in to comment.