From 7651ec123f1142bd1efa57ce701fb5c2382fea15 Mon Sep 17 00:00:00 2001 From: Akihiko Kusanagi Date: Thu, 17 Aug 2017 22:50:35 +0800 Subject: [PATCH 1/3] Fix bar chart with {x, y} data points - Use a value scale to check the value when drawing bars - Add null check in arrayUnique() - Fix document issue --- docs/charts/bar.md | 2 +- src/controllers/controller.bar.js | 2 +- src/scales/scale.time.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/charts/bar.md b/docs/charts/bar.md index 974cf8a7104..524c795214c 100644 --- a/docs/charts/bar.md +++ b/docs/charts/bar.md @@ -155,7 +155,7 @@ data: [20, 10] You can also specify the dataset as x/y coordinates. ```javascript -data: [{x:'2016-12-25', y:20}, {'2016-12-26', y:10}] +data: [{x:'2016-12-25', y:20}, {x:'2016-12-26', y:10}] ``` # Stacked Bar Chart diff --git a/src/controllers/controller.bar.js b/src/controllers/controller.bar.js index baea1d94975..ae4aee45d17 100644 --- a/src/controllers/controller.bar.js +++ b/src/controllers/controller.bar.js @@ -362,7 +362,7 @@ module.exports = function(Chart) { draw: function() { var me = this; var chart = me.chart; - var scale = me.getIndexScale(); + var scale = me.getValueScale(); var rects = me.getMeta().data; var dataset = me.getDataset(); var ilen = rects.length; diff --git a/src/scales/scale.time.js b/src/scales/scale.time.js index dd014e1069f..0ae64cd9fab 100644 --- a/src/scales/scale.time.js +++ b/src/scales/scale.time.js @@ -71,7 +71,7 @@ function arrayUnique(items) { for (i = 0, ilen = items.length; i < ilen; ++i) { item = items[i]; - if (!hash[item]) { + if (item !== null && !hash[item]) { hash[item] = true; out.push(item); } From 4edbb2ee9ab022280c191aac47d8079509608924 Mon Sep 17 00:00:00 2001 From: Akihiko Kusanagi Date: Fri, 18 Aug 2017 10:52:34 +0800 Subject: [PATCH 2/3] move null check to the outside of --- src/scales/scale.time.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/scales/scale.time.js b/src/scales/scale.time.js index 0ae64cd9fab..47fa2459d49 100644 --- a/src/scales/scale.time.js +++ b/src/scales/scale.time.js @@ -71,7 +71,7 @@ function arrayUnique(items) { for (i = 0, ilen = items.length; i < ilen; ++i) { item = items[i]; - if (item !== null && !hash[item]) { + if (!hash[item]) { hash[item] = true; out.push(item); } @@ -480,11 +480,16 @@ module.exports = function(Chart) { var timestamps = []; var datasets = []; var labels = []; + var rawLabels = []; var i, j, ilen, jlen, data, timestamp; // Convert labels to timestamps for (i = 0, ilen = chart.data.labels.length; i < ilen; ++i) { - labels.push(parse(chart.data.labels[i], me)); + timestamp = parse(chart.data.labels[i], me); + if (timestamp !== null) { + labels.push(timestamp); + } + rawLabels.push(timestamp); } // Convert data to timestamps @@ -498,12 +503,14 @@ module.exports = function(Chart) { for (j = 0, jlen = data.length; j < jlen; ++j) { timestamp = parse(data[j], me); - timestamps.push(timestamp); + if (timestamp !== null) { + timestamps.push(timestamp); + } datasets[i][j] = timestamp; } } else { timestamps.push.apply(timestamps, labels); - datasets[i] = labels.slice(0); + datasets[i] = rawLabels.slice(0); } } else { datasets[i] = []; From ad0b28699014853fcc569477944a67a7be9601a1 Mon Sep 17 00:00:00 2001 From: Akihiko Kusanagi Date: Wed, 23 Aug 2017 23:40:28 +0800 Subject: [PATCH 3/3] Remove null timestamp checks --- src/scales/scale.time.js | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/src/scales/scale.time.js b/src/scales/scale.time.js index 47fa2459d49..dd014e1069f 100644 --- a/src/scales/scale.time.js +++ b/src/scales/scale.time.js @@ -480,16 +480,11 @@ module.exports = function(Chart) { var timestamps = []; var datasets = []; var labels = []; - var rawLabels = []; var i, j, ilen, jlen, data, timestamp; // Convert labels to timestamps for (i = 0, ilen = chart.data.labels.length; i < ilen; ++i) { - timestamp = parse(chart.data.labels[i], me); - if (timestamp !== null) { - labels.push(timestamp); - } - rawLabels.push(timestamp); + labels.push(parse(chart.data.labels[i], me)); } // Convert data to timestamps @@ -503,14 +498,12 @@ module.exports = function(Chart) { for (j = 0, jlen = data.length; j < jlen; ++j) { timestamp = parse(data[j], me); - if (timestamp !== null) { - timestamps.push(timestamp); - } + timestamps.push(timestamp); datasets[i][j] = timestamp; } } else { timestamps.push.apply(timestamps, labels); - datasets[i] = rawLabels.slice(0); + datasets[i] = labels.slice(0); } } else { datasets[i] = [];