From 8e9d53788270c322d4bc0848fc175945da36ddd3 Mon Sep 17 00:00:00 2001 From: Arik Fraimovich Date: Mon, 3 Mar 2014 15:21:49 +0200 Subject: [PATCH 1/2] Fix: graphs with category as x axis were shown as datetime graphs, because drawChart is called twice and on second pass there is no x attribute on point object. --- rd_ui/app/scripts/ng-highchart.js | 35 +++++++++++++++++-------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/rd_ui/app/scripts/ng-highchart.js b/rd_ui/app/scripts/ng-highchart.js index a5eb378d..59ddc7b2 100644 --- a/rd_ui/app/scripts/ng-highchart.js +++ b/rd_ui/app/scripts/ng-highchart.js @@ -210,29 +210,32 @@ scope.chart.series[0].remove(false); }; + if (_.some(scope.series[0].data, function (p) { - return angular.isString(p.x) + return (angular.isString(p.x) || angular.isDefined(p.name)); })) { scope.chart.xAxis[0].update({type: 'category'}); - // We need to make sure that for each category, each series has a value. - var categories = _.union.apply(this, _.map(scope.series, function (s) { - return _.pluck(s.data, 'x') - })); + if (!angular.isDefined(scope.series[0].data[0].name)) { + // We need to make sure that for each category, each series has a value. + var categories = _.union.apply(this, _.map(scope.series, function (s) { + return _.pluck(s.data, 'x') + })); - _.each(scope.series, function (s) { - // TODO: move this logic to Query#getChartData - var yValues = _.groupBy(s.data, 'x'); + _.each(scope.series, function (s) { + // TODO: move this logic to Query#getChartData + var yValues = _.groupBy(s.data, 'x'); - var newData = _.sortBy(_.map(categories, function (category) { - return { - name: category, - y: yValues[category] && yValues[category][0].y - } - }), 'name'); + var newData = _.sortBy(_.map(categories, function (category) { + return { + name: category, + y: yValues[category] && yValues[category][0].y + } + }), 'name'); - s.data = newData; - }); + s.data = newData; + }); + } } else { scope.chart.xAxis[0].update({type: 'datetime'}); } From 9d44a73d026b51feb0da3692d798f73a0830a761 Mon Sep 17 00:00:00 2001 From: Arik Fraimovich Date: Mon, 3 Mar 2014 15:27:39 +0200 Subject: [PATCH 2/2] Feature: sort category charts by y value. --- rd_ui/app/scripts/ng-highchart.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rd_ui/app/scripts/ng-highchart.js b/rd_ui/app/scripts/ng-highchart.js index 59ddc7b2..c68d3d10 100644 --- a/rd_ui/app/scripts/ng-highchart.js +++ b/rd_ui/app/scripts/ng-highchart.js @@ -231,7 +231,7 @@ name: category, y: yValues[category] && yValues[category][0].y } - }), 'name'); + }), 'y').reverse(); s.data = newData; });