From a189857d84481c63aae4bbacc615e7f4d3ef1626 Mon Sep 17 00:00:00 2001 From: Chris Teague Date: Wed, 22 Oct 2014 11:46:46 +1030 Subject: [PATCH] Adding named array support for order --- c3.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/c3.js b/c3.js index 06bd006..b6eebc8 100644 --- a/c3.js +++ b/c3.js @@ -1647,7 +1647,17 @@ }); } else if (isFunction(config.data_order)) { targets.sort(config.data_order); - } // TODO: accept name array for order + } else if (Object.prototype.toString.call(config.data_order) === '[object Array]' ) { + targets.sort(function (t1, t2)) { + var t1Pos = config.data_order.indexOf(t1.id); + if(t1Pos == -1) { t1Pos = config.data_order.length; } + + var t2Pos = config.data_order.indexOf(t2.id); + if(t2Pos == -1) { t2Pos = config.data_order.length; } + + return t1Pos - t2Pos; + } + } return targets; }; c3_chart_internal_fn.filterByX = function (targets, x) {