Skip to content

Commit

Permalink
Allow updating dataset types
Browse files Browse the repository at this point in the history
  • Loading branch information
benmccann committed Jul 31, 2017
1 parent 53b7a63 commit ff08f03
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/core/core.controller.js
Expand Up @@ -289,8 +289,14 @@ module.exports = function(Chart) {

helpers.each(me.data.datasets, function(dataset, datasetIndex) {
var meta = me.getDatasetMeta(datasetIndex);
var type = dataset.type || me.config.type;
if (!meta.type) {
meta.type = dataset.type || me.config.type;
meta.type = type;
} else if (meta.type !== type) {
meta.controller.destroy();
delete me.data.datasets[datasetIndex]._meta;
meta = me.getDatasetMeta(datasetIndex);
meta.type = type;
}

types.push(meta.type);
Expand Down
35 changes: 35 additions & 0 deletions test/specs/core.controller.tests.js
Expand Up @@ -693,6 +693,41 @@ describe('Chart', function() {
chart.update();
expect(chart.tooltip._options).toEqual(jasmine.objectContaining(newTooltipConfig));
});

it ('should update the metadata', function() {
var cfg = {
data: {
labels: ['A', 'B', 'C', 'D'],
datasets: [{
type: 'line',
data: [10, 20, 30, 0]
}]
},
options: {
responsive: true,
scales: {
xAxes: [{
type: 'time'
}],
yAxes: [{
scaleLabel: {
display: true,
labelString: 'Value'
}
}]
}
}
};
var chart = acquireChart(cfg);
var meta = chart.getDatasetMeta(0);
expect(meta.type).toBe('line');

// change the dataset to bar and check that meta was updated
cfg.data.datasets[0].type = 'bar'
chart.update(cfg);
meta = chart.getDatasetMeta(0);
expect(meta.type).toBe('bar');
});
});

describe('plugin.extensions', function() {
Expand Down

0 comments on commit ff08f03

Please sign in to comment.