mirror of
https://github.com/chartjs/Chart.js.git
synced 2026-02-01 17:47:09 +00:00
Tests and fixes for data watching (#6831)
* Tests and fixes for data watching * Remove call to _configure
This commit is contained in:
parent
6f6005d7b8
commit
3baade7862
@ -270,6 +270,7 @@ helpers.extend(DatasetController.prototype, {
|
||||
me.index = datasetIndex;
|
||||
me._cachedMeta = meta = me.getMeta();
|
||||
me._type = meta.type;
|
||||
me._configure();
|
||||
me.linkScales();
|
||||
meta._stacked = isStacked(meta.vScale, meta);
|
||||
me.addElements();
|
||||
@ -464,6 +465,7 @@ helpers.extend(DatasetController.prototype, {
|
||||
}
|
||||
}
|
||||
});
|
||||
me._parsing = resolve([me._config.parsing, me.chart.options.parsing, true]);
|
||||
},
|
||||
|
||||
/**
|
||||
@ -473,11 +475,10 @@ helpers.extend(DatasetController.prototype, {
|
||||
const me = this;
|
||||
const {_cachedMeta: meta, _data: data} = me;
|
||||
const {iScale, vScale, _stacked} = meta;
|
||||
const parsing = resolve([me.getDataset().parsing, me.chart.options.parsing, true]);
|
||||
let offset = 0;
|
||||
let i, parsed;
|
||||
|
||||
if (parsing === false) {
|
||||
if (me._parsing === false) {
|
||||
meta._parsed = data;
|
||||
} else {
|
||||
if (helpers.isArray(data[start])) {
|
||||
@ -790,7 +791,6 @@ helpers.extend(DatasetController.prototype, {
|
||||
const dataset = meta.dataset;
|
||||
let style;
|
||||
|
||||
me._configure();
|
||||
if (dataset && index === undefined) {
|
||||
style = me._resolveDatasetElementOptions();
|
||||
} else {
|
||||
@ -968,7 +968,8 @@ helpers.extend(DatasetController.prototype, {
|
||||
insertElements: function(start, count) {
|
||||
const me = this;
|
||||
const elements = new Array(count);
|
||||
const data = me._cachedMeta.data;
|
||||
const meta = me._cachedMeta;
|
||||
const data = meta.data;
|
||||
let i;
|
||||
|
||||
for (i = 0; i < count; ++i) {
|
||||
@ -976,10 +977,26 @@ helpers.extend(DatasetController.prototype, {
|
||||
}
|
||||
data.splice(start, 0, ...elements);
|
||||
|
||||
if (me._parsing) {
|
||||
meta._parsed.splice(start, 0, ...new Array(count));
|
||||
}
|
||||
me._parse(start, count);
|
||||
|
||||
me.updateElements(data, start, count);
|
||||
},
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
removeElements: function(start, count) {
|
||||
const me = this;
|
||||
if (me._parsing) {
|
||||
me._cachedMeta._parsed.splice(start, count);
|
||||
}
|
||||
me._cachedMeta.data.splice(start, count);
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
@ -992,21 +1009,21 @@ helpers.extend(DatasetController.prototype, {
|
||||
* @private
|
||||
*/
|
||||
onDataPop: function() {
|
||||
this._cachedMeta.data.pop();
|
||||
this.removeElements(this._cachedMeta.data.length - 1, 1);
|
||||
},
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
onDataShift: function() {
|
||||
this._cachedMeta.data.shift();
|
||||
this.removeElements(0, 1);
|
||||
},
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
onDataSplice: function(start, count) {
|
||||
this._cachedMeta.data.splice(start, count);
|
||||
this.removeElements(start, count);
|
||||
this.insertElements(start, arguments.length - 2);
|
||||
},
|
||||
|
||||
|
||||
@ -118,9 +118,9 @@ describe('Chart.DatasetController', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('should synchronize metadata when data are inserted or removed', function() {
|
||||
var data = [0, 1, 2, 3, 4, 5];
|
||||
var chart = acquireChart({
|
||||
it('should synchronize metadata when data are inserted or removed and parsing is on', function() {
|
||||
const data = [0, 1, 2, 3, 4, 5];
|
||||
const chart = acquireChart({
|
||||
type: 'line',
|
||||
data: {
|
||||
datasets: [{
|
||||
@ -129,8 +129,9 @@ describe('Chart.DatasetController', function() {
|
||||
}
|
||||
});
|
||||
|
||||
var meta = chart.getDatasetMeta(0);
|
||||
var first, second, last;
|
||||
const meta = chart.getDatasetMeta(0);
|
||||
const parsedYValues = () => meta._parsed.map(p => p.y);
|
||||
let first, second, last;
|
||||
|
||||
first = meta.data[0];
|
||||
last = meta.data[5];
|
||||
@ -139,12 +140,14 @@ describe('Chart.DatasetController', function() {
|
||||
expect(meta.data.length).toBe(10);
|
||||
expect(meta.data[0]).toBe(first);
|
||||
expect(meta.data[5]).toBe(last);
|
||||
expect(parsedYValues()).toEqual(data);
|
||||
|
||||
last = meta.data[9];
|
||||
data.pop();
|
||||
expect(meta.data.length).toBe(9);
|
||||
expect(meta.data[0]).toBe(first);
|
||||
expect(meta.data.indexOf(last)).toBe(-1);
|
||||
expect(parsedYValues()).toEqual(data);
|
||||
|
||||
last = meta.data[8];
|
||||
data.shift();
|
||||
@ -153,6 +156,7 @@ describe('Chart.DatasetController', function() {
|
||||
expect(meta.data.length).toBe(6);
|
||||
expect(meta.data.indexOf(first)).toBe(-1);
|
||||
expect(meta.data[5]).toBe(last);
|
||||
expect(parsedYValues()).toEqual(data);
|
||||
|
||||
first = meta.data[0];
|
||||
second = meta.data[1];
|
||||
@ -162,12 +166,14 @@ describe('Chart.DatasetController', function() {
|
||||
expect(meta.data[0]).toBe(first);
|
||||
expect(meta.data[3]).toBe(last);
|
||||
expect(meta.data.indexOf(second)).toBe(-1);
|
||||
expect(parsedYValues()).toEqual(data);
|
||||
|
||||
data.unshift(12, 13, 14, 15);
|
||||
data.unshift(16, 17);
|
||||
expect(meta.data.length).toBe(10);
|
||||
expect(meta.data[6]).toBe(first);
|
||||
expect(meta.data[9]).toBe(last);
|
||||
expect(parsedYValues()).toEqual(data);
|
||||
});
|
||||
|
||||
it('should synchronize metadata when data are inserted or removed and parsing is off', function() {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user