feat/fix: Fixes #404 maintaining backwards compat

This commit is contained in:
Arjun Choudhary 2022-12-15 20:10:35 +05:30
parent 256649fbcc
commit 1b955a9f19
3 changed files with 21 additions and 12 deletions

View File

@ -63,8 +63,8 @@ export default class AxisChart extends BaseChart {
this.config.legendRowHeight = 30;
}
prepareData(data = this.data) {
return dataPrep(data, this.type);
prepareData(data = this.data, config = this.config) {
return dataPrep(data, this.type, config.continuous);
}
prepareFirstData(data = this.data) {

View File

@ -46,9 +46,6 @@ export default class BaseChart {
this.title = options.title || "";
this.type = options.type || "";
this.realData = this.prepareData(options.data, options.config);
this.data = this.prepareFirstData(this.realData);
this.colors = this.validateColors(options.colors, this.type);
this.config = {
@ -64,10 +61,18 @@ export default class BaseChart {
typeof options.truncateLegends !== "undefined"
? options.truncateLegends
: 1,
continuous:
typeof options.continuous !== "undefined"
? options.continuous
: 1,
};
this.measures = JSON.parse(JSON.stringify(BASE_MEASURES));
let m = this.measures;
this.realData = this.prepareData(options.data, this.config);
this.data = this.prepareFirstData(this.realData);
this.setMeasures(options);
if (!this.title.length) {
m.titleHeight = 0;
@ -87,8 +92,8 @@ export default class BaseChart {
this.configure(options);
}
prepareData(data) {
return data;
prepareData(data, config) {
return data, config;
}
prepareFirstData(data) {
@ -188,9 +193,11 @@ export default class BaseChart {
if (init) {
this.data = this.realData;
setTimeout(() => {
this.update(this.data, true);
// Not needed anymore since animate defaults to 0 and might potentially be refactored or deprecated
/* setTimeout(() => {
this.update(this.data, true);
}, this.initTimeout);
}, this.initTimeout); */
}
if (this.config.showLegend) {
@ -271,10 +278,10 @@ export default class BaseChart {
this.components = new Map();
}
update(data, drawing = false) {
update(data, drawing = false, config) {
if (!data) console.error("No data to update.");
if (!drawing) data = deepClone(data);
this.data = this.prepareData(data);
this.data = this.prepareData(data, config);
this.calc(); // builds state
this.render(this.components, this.config.animate);
}

View File

@ -6,7 +6,7 @@ import {
SERIES_LABEL_SPACE_RATIO,
} from "../utils/constants";
export function dataPrep(data, type) {
export function dataPrep(data, type, config) {
data.labels = data.labels || [];
let datasetLength = data.labels.length;
@ -35,6 +35,8 @@ export function dataPrep(data, type) {
// Trim or extend
if (vals.length > datasetLength) {
vals = vals.slice(0, datasetLength);
} if (config) {
vals = fillArray(vals, datasetLength - vals.length, null);
} else {
vals = fillArray(vals, datasetLength - vals.length, 0);
}