Skip to content

Commit f7f693d

Browse files
committed
Merge pull request #37 from sbatson5/line-chart-updater-fix
line charts update when set length changes
2 parents 5a9174c + defb481 commit f7f693d

File tree

2 files changed

+58
-2
lines changed

2 files changed

+58
-2
lines changed

addon/chart-data-updater.js

+6
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ export default Ember.Object.extend({
2222
if (chart.datasets[0].bars.length !== datasets[0].data.length) {
2323
return this.set('redraw', true);
2424
}
25+
} else if (typeof chart.datasets[0].points !== 'undefined') {
26+
chart.datasets.forEach(function(value, index) {
27+
if (chart.datasets[index].points.length !== datasets[index].data.length) {
28+
return self.set('redraw', true);
29+
}
30+
});
2531
}
2632

2733
// Update Labels

tests/unit/components/ember-chart-test.js

+52-2
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,33 @@ var ChartTestData = Ember.Object.extend({
126126
]
127127
};
128128
}),
129+
lineData3: Ember.computed('lineValue1', 'lineValue2', 'labelValue1', function(){
130+
return {
131+
labels: [this.get('labelValue1'), "February", "March", "April", "May", "June", "July"],
132+
datasets: [
133+
{
134+
label: "My First dataset",
135+
fillColor: "rgba(220,220,220,0.2)",
136+
strokeColor: "rgba(220,220,220,1)",
137+
pointColor: "rgba(220,220,220,1)",
138+
pointStrokeColor: "#fff",
139+
pointHighlightFill: "#fff",
140+
pointHighlightStroke: "rgba(220,220,220,1)",
141+
data: [parseInt(this.get('lineValue1')), parseInt(this.get('lineValue2')), 80, 81]
142+
},
143+
{
144+
label: "My Second dataset",
145+
fillColor: "rgba(151,187,205,0.2)",
146+
strokeColor: "rgba(151,187,205,1)",
147+
pointColor: "rgba(151,187,205,1)",
148+
pointStrokeColor: "#fff",
149+
pointHighlightFill: "#fff",
150+
pointHighlightStroke: "rgba(151,187,205,1)",
151+
data: [28, 48, 40, 19, 86, 27, 90]
152+
}
153+
]
154+
};
155+
}),
129156
barData: Ember.computed(function(){
130157
return {
131158
labels: ["January", "February", "March"],
@@ -193,12 +220,12 @@ test('it should rebuild the legend in case the chart changes', function(assert)
193220
});
194221

195222
var chartParent = this.$().parent();
196-
223+
197224
assert.ok(chartParent.find('.pie-legend').text().match(/Red/));
198225

199226
// Update Data
200227
component.set('data', testData.get('pieData2'));
201-
228+
202229
assert.ok(chartParent.find('.pie-legend').text().match(/Black/), 'The legend should have updated');
203230
});
204231

@@ -356,3 +383,26 @@ test('it should rebuild bar chart if data structure changes', function(assert) {
356383
chart = component.get('chart');
357384
assert.equal(chart.datasets[0].bars.length, 3);
358385
});
386+
387+
test('it should rebuild line chart if data length within a set changes', function(assert) {
388+
var component = this.subject({
389+
type: 'Line',
390+
data: testData.get('lineData')
391+
});
392+
393+
this.render();
394+
var chart = component.get('chart');
395+
assert.equal(chart.datasets[0].points.length, 7);
396+
397+
// Update Data -- increase dataset length for first array of points
398+
component.set('data', testData.get('lineData3'));
399+
400+
chart = component.get('chart');
401+
assert.equal(chart.datasets[0].points.length, 4);
402+
403+
// Update Data -- reset dataset
404+
component.set('data', testData.get('lineData'));
405+
406+
chart = component.get('chart');
407+
assert.equal(chart.datasets[0].points.length, 7);
408+
});

0 commit comments

Comments
 (0)