From 30e77c863e14e42468fa5276ae30ca8753c385cb Mon Sep 17 00:00:00 2001 From: aaronhayes Date: Sat, 25 Apr 2015 23:40:00 +1000 Subject: [PATCH 1/3] Update x-labels without full redraw --- .gitignore | 2 ++ lib/core.js | 1 + 2 files changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index dfad54d..ed8166f 100644 --- a/.gitignore +++ b/.gitignore @@ -30,3 +30,5 @@ node_modules .DS_Store showcase .generator-release + +.idea/* \ No newline at end of file diff --git a/lib/core.js b/lib/core.js index 5cfa723..871c51e 100644 --- a/lib/core.js +++ b/lib/core.js @@ -42,6 +42,7 @@ module.exports = { } else { dataKey = dataKey || dataKeys[chart.name]; updatePoints(nextProps, chart, dataKey); + chart.scale.xLabels = nextProps.data.labels; chart.update(); } }; From 13fe5bee6b235c382fd12b427d55a7a3d92a3a17 Mon Sep 17 00:00:00 2001 From: aaronhayes Date: Sun, 26 Apr 2015 16:58:46 +1000 Subject: [PATCH 2/3] dynamically add data to chart --- lib/core.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/core.js b/lib/core.js index 871c51e..d3edba2 100644 --- a/lib/core.js +++ b/lib/core.js @@ -94,12 +94,21 @@ var updatePoints = function(nextProps, chart, dataKey) { } else { nextProps.data.datasets.forEach(function(set, setIndex) { set.data.forEach(function(val, pointIndex) { - chart.datasets[setIndex][dataKey][pointIndex].value = val; + if (typeof(chart.datasets[setIndex][dataKey][pointIndex]) == "undefined") { + addData(nextProps, chart, setIndex, pointIndex); + } else { + chart.datasets[setIndex][dataKey][pointIndex].value = val; + } }); }); } }; - - +var addData = function(nextProps, chart, setIndex, pointIndex) { + var values = []; + nextProps.data.datasets.forEach(function(set) { + values.push(set.data[pointIndex]); + }); + chart.addData(values, nextProps.data.labels[setIndex]); +}; From 750ee873c4fcda515e2d3ddf2538e8cb319d5989 Mon Sep 17 00:00:00 2001 From: aaronhayes Date: Tue, 28 Apr 2015 11:54:15 +1000 Subject: [PATCH 3/3] dynamically remove data from chart. Auto rotate x-scale labels. --- lib/core.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/core.js b/lib/core.js index d3edba2..c3b5620 100644 --- a/lib/core.js +++ b/lib/core.js @@ -43,6 +43,7 @@ module.exports = { dataKey = dataKey || dataKeys[chart.name]; updatePoints(nextProps, chart, dataKey); chart.scale.xLabels = nextProps.data.labels; + chart.scale.calculateXLabelRotation(); chart.update(); } }; @@ -92,6 +93,9 @@ var updatePoints = function(nextProps, chart, dataKey) { chart.segments[segmentIndex].value = segment.value; }); } else { + while (chart.scale.xLabels.length > nextProps.data.labels.length) { + chart.removeData(); + } nextProps.data.datasets.forEach(function(set, setIndex) { set.data.forEach(function(val, pointIndex) { if (typeof(chart.datasets[setIndex][dataKey][pointIndex]) == "undefined") {