Skip to content

Commit

Permalink
Update dataset metadata when axisID changes (#6321)
Browse files Browse the repository at this point in the history
  • Loading branch information
nagix committed Jun 14, 2019
1 parent bf094c5 commit 9eecdf4
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/core/core.datasetController.js
Expand Up @@ -139,13 +139,16 @@ helpers.extend(DatasetController.prototype, {
linkScales: function() {
var me = this;
var meta = me.getMeta();
var chart = me.chart;
var scales = chart.scales;
var dataset = me.getDataset();
var scalesOpts = chart.options.scales;

if (meta.xAxisID === null || !(meta.xAxisID in me.chart.scales)) {
meta.xAxisID = dataset.xAxisID || me.chart.options.scales.xAxes[0].id;
if (meta.xAxisID === null || !(meta.xAxisID in scales) || dataset.xAxisID) {
meta.xAxisID = dataset.xAxisID || scalesOpts.xAxes[0].id;
}
if (meta.yAxisID === null || !(meta.yAxisID in me.chart.scales)) {
meta.yAxisID = dataset.yAxisID || me.chart.options.scales.yAxes[0].id;
if (meta.yAxisID === null || !(meta.yAxisID in scales) || dataset.yAxisID) {
meta.yAxisID = dataset.yAxisID || scalesOpts.yAxes[0].id;
}
},

Expand Down
39 changes: 39 additions & 0 deletions test/specs/core.datasetController.tests.js
Expand Up @@ -221,6 +221,45 @@ describe('Chart.DatasetController', function() {
expect(meta.data.length).toBe(42);
});

it('should re-synchronize metadata when scaleID changes', function() {
var chart = acquireChart({
type: 'line',
data: {
datasets: [{
data: [],
xAxisID: 'firstXScaleID',
yAxisID: 'firstYScaleID',
}]
},
options: {
scales: {
xAxes: [{
id: 'firstXScaleID'
}, {
id: 'secondXScaleID'
}],
yAxes: [{
id: 'firstYScaleID'
}, {
id: 'secondYScaleID'
}]
}
}
});

var meta = chart.getDatasetMeta(0);

expect(meta.xAxisID).toBe('firstXScaleID');
expect(meta.yAxisID).toBe('firstYScaleID');

chart.data.datasets[0].xAxisID = 'secondXScaleID';
chart.data.datasets[0].yAxisID = 'secondYScaleID';
chart.update();

expect(meta.xAxisID).toBe('secondXScaleID');
expect(meta.yAxisID).toBe('secondYScaleID');
});

it('should cleanup attached properties when the reference changes or when the chart is destroyed', function() {
var data0 = [0, 1, 2, 3, 4, 5];
var data1 = [6, 7, 8];
Expand Down

0 comments on commit 9eecdf4

Please sign in to comment.