Skip to content

Commit

Permalink
redraw line chart if dataset lengths change
Browse files Browse the repository at this point in the history
  • Loading branch information
aomran committed Jun 17, 2015
1 parent 1b95483 commit a178e3b
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 1 deletion.
5 changes: 5 additions & 0 deletions addon/chart-data-updater.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ export default Ember.Object.extend({
else { console.error(e); }
}
});

return this.get('redraw');
},

updatePieCharts: function () {
Expand All @@ -59,5 +61,8 @@ export default Ember.Object.extend({
chart.addData(segment);
}
});

return this.get('redraw');
}

});
56 changes: 55 additions & 1 deletion tests/unit/components/ember-chart-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,43 @@ var ChartTestData = Ember.Object.extend({
}
]
};
}),
lineData2: Ember.computed(function(){
return {
labels: ["January", "February", "March", "April", "May", "June", "July"],
datasets: [
{
label: "My First dataset",
fillColor: "rgba(220,220,220,0.2)",
strokeColor: "rgba(220,220,220,1)",
pointColor: "rgba(220,220,220,1)",
pointStrokeColor: "#fff",
pointHighlightFill: "#fff",
pointHighlightStroke: "rgba(220,220,220,1)",
data: [parseInt(this.get('lineValue1')), parseInt(this.get('lineValue2')), 80, 81, 56, 55, 40]
},
{
label: "My Second dataset",
fillColor: "rgba(151,187,205,0.2)",
strokeColor: "rgba(151,187,205,1)",
pointColor: "rgba(151,187,205,1)",
pointStrokeColor: "#fff",
pointHighlightFill: "#fff",
pointHighlightStroke: "rgba(151,187,205,1)",
data: [28, 48, 40, 19, 86, 27, 90]
},
{
label: "My Third dataset",
fillColor: "rgba(151,187,205,0.2)",
strokeColor: "rgba(151,187,205,1)",
pointColor: "rgba(151,187,205,1)",
pointStrokeColor: "#fff",
pointHighlightFill: "#fff",
pointHighlightStroke: "rgba(151,187,205,1)",
data: [28, 48, 40, 19, 86, 27, 90]
}
]
};
})
});

Expand Down Expand Up @@ -216,7 +253,7 @@ test('it should update charts dynamically', function(assert) {
assert.equal(chart.scale.xLabels[0], 'December');
});

test('it should update chart if data structure changes', function(assert) {
test('it should update pie chart if data structure changes', function(assert) {
var component = this.subject({
type: 'Pie',
data: testData.get('pieData')
Expand All @@ -235,3 +272,20 @@ test('it should update chart if data structure changes', function(assert) {
assert.equal(segments.findBy('label', 'Black').value, 20);
assert.equal(segments.length, 3);
});

test('it should update line chart if data structure changes', function(assert) {
var component = this.subject({
type: 'Line',
data: testData.get('lineData')
});

this.render();
var chart = component.get('chart');
assert.equal(chart.datasets.length, 2);

// Update Data
component.set('data', testData.get('lineData2'));

chart = component.get('chart');
assert.equal(chart.datasets.length, 3);
});

0 comments on commit a178e3b

Please sign in to comment.