feat/fix: Fixes #404 maintaining backwards compat
This commit is contained in:
parent
256649fbcc
commit
1b955a9f19
@ -63,8 +63,8 @@ export default class AxisChart extends BaseChart {
|
|||||||
this.config.legendRowHeight = 30;
|
this.config.legendRowHeight = 30;
|
||||||
}
|
}
|
||||||
|
|
||||||
prepareData(data = this.data) {
|
prepareData(data = this.data, config = this.config) {
|
||||||
return dataPrep(data, this.type);
|
return dataPrep(data, this.type, config.continuous);
|
||||||
}
|
}
|
||||||
|
|
||||||
prepareFirstData(data = this.data) {
|
prepareFirstData(data = this.data) {
|
||||||
|
|||||||
@ -46,9 +46,6 @@ export default class BaseChart {
|
|||||||
this.title = options.title || "";
|
this.title = options.title || "";
|
||||||
this.type = options.type || "";
|
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.colors = this.validateColors(options.colors, this.type);
|
||||||
|
|
||||||
this.config = {
|
this.config = {
|
||||||
@ -64,10 +61,18 @@ export default class BaseChart {
|
|||||||
typeof options.truncateLegends !== "undefined"
|
typeof options.truncateLegends !== "undefined"
|
||||||
? options.truncateLegends
|
? options.truncateLegends
|
||||||
: 1,
|
: 1,
|
||||||
|
continuous:
|
||||||
|
typeof options.continuous !== "undefined"
|
||||||
|
? options.continuous
|
||||||
|
: 1,
|
||||||
};
|
};
|
||||||
|
|
||||||
this.measures = JSON.parse(JSON.stringify(BASE_MEASURES));
|
this.measures = JSON.parse(JSON.stringify(BASE_MEASURES));
|
||||||
let m = this.measures;
|
let m = this.measures;
|
||||||
|
|
||||||
|
this.realData = this.prepareData(options.data, this.config);
|
||||||
|
this.data = this.prepareFirstData(this.realData);
|
||||||
|
|
||||||
this.setMeasures(options);
|
this.setMeasures(options);
|
||||||
if (!this.title.length) {
|
if (!this.title.length) {
|
||||||
m.titleHeight = 0;
|
m.titleHeight = 0;
|
||||||
@ -87,8 +92,8 @@ export default class BaseChart {
|
|||||||
this.configure(options);
|
this.configure(options);
|
||||||
}
|
}
|
||||||
|
|
||||||
prepareData(data) {
|
prepareData(data, config) {
|
||||||
return data;
|
return data, config;
|
||||||
}
|
}
|
||||||
|
|
||||||
prepareFirstData(data) {
|
prepareFirstData(data) {
|
||||||
@ -188,9 +193,11 @@ export default class BaseChart {
|
|||||||
|
|
||||||
if (init) {
|
if (init) {
|
||||||
this.data = this.realData;
|
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.update(this.data, true);
|
||||||
}, this.initTimeout);
|
}, this.initTimeout); */
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.config.showLegend) {
|
if (this.config.showLegend) {
|
||||||
@ -271,10 +278,10 @@ export default class BaseChart {
|
|||||||
this.components = new Map();
|
this.components = new Map();
|
||||||
}
|
}
|
||||||
|
|
||||||
update(data, drawing = false) {
|
update(data, drawing = false, config) {
|
||||||
if (!data) console.error("No data to update.");
|
if (!data) console.error("No data to update.");
|
||||||
if (!drawing) data = deepClone(data);
|
if (!drawing) data = deepClone(data);
|
||||||
this.data = this.prepareData(data);
|
this.data = this.prepareData(data, config);
|
||||||
this.calc(); // builds state
|
this.calc(); // builds state
|
||||||
this.render(this.components, this.config.animate);
|
this.render(this.components, this.config.animate);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,7 +6,7 @@ import {
|
|||||||
SERIES_LABEL_SPACE_RATIO,
|
SERIES_LABEL_SPACE_RATIO,
|
||||||
} from "../utils/constants";
|
} from "../utils/constants";
|
||||||
|
|
||||||
export function dataPrep(data, type) {
|
export function dataPrep(data, type, config) {
|
||||||
data.labels = data.labels || [];
|
data.labels = data.labels || [];
|
||||||
|
|
||||||
let datasetLength = data.labels.length;
|
let datasetLength = data.labels.length;
|
||||||
@ -35,6 +35,8 @@ export function dataPrep(data, type) {
|
|||||||
// Trim or extend
|
// Trim or extend
|
||||||
if (vals.length > datasetLength) {
|
if (vals.length > datasetLength) {
|
||||||
vals = vals.slice(0, datasetLength);
|
vals = vals.slice(0, datasetLength);
|
||||||
|
} if (config) {
|
||||||
|
vals = fillArray(vals, datasetLength - vals.length, null);
|
||||||
} else {
|
} else {
|
||||||
vals = fillArray(vals, datasetLength - vals.length, 0);
|
vals = fillArray(vals, datasetLength - vals.length, 0);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user