Skip to content

Commit

Permalink
Support sort by y values for charts that have a single value per series
Browse files Browse the repository at this point in the history
  • Loading branch information
stanhu committed Apr 22, 2015
1 parent 84d9527 commit fd056ed
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
30 changes: 30 additions & 0 deletions rd_ui/app/scripts/ng_highchart.js
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,36 @@
series = seriesCopy;
}

if (chartOptions['sortY'] === true || chartOptions['sortY'] === undefined) {
var sortable = true;

for (var i = 0; i < series.length; i++) {
if (series[i].data.length != 1) {
sortable = false;
break;
}
}

if (sortable) {
var sortFunction = function(s1, s2) {
if (s1.data.length == 1 && s2.data.length == 1) {
var a = s1.data[0].y;
var b = s2.data[0].y;

if (a < b) {
return -1;
} else if (a == b) {
return 0;
} else {
return 1;
}
}
}

series.sort(sortFunction);
}
}

if (!('xAxis' in chartOptions && 'type' in chartOptions['xAxis'])) {
if (series.length > 0 && _.some(series[0].data, function (p) {
return (angular.isString(p.x) || angular.isDefined(p.name));
Expand Down
8 changes: 8 additions & 0 deletions rd_ui/app/views/visualizations/chart_editor.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@
ng-model="visualization.options.sortX">
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2">Sort Y Values</label>

<div class="col-sm-10">
<input name="sortY" type="checkbox" class="form-control"
ng-model="visualization.options.sortY">
</div>
</div>
</div>
</div>

Expand Down

0 comments on commit fd056ed

Please sign in to comment.