diff --git a/src/js/charts/AxisChart.js b/src/js/charts/AxisChart.js index a348db9..8e7abeb 100644 --- a/src/js/charts/AxisChart.js +++ b/src/js/charts/AxisChart.js @@ -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) { diff --git a/src/js/charts/BaseChart.js b/src/js/charts/BaseChart.js index 08b9f57..dd500b5 100644 --- a/src/js/charts/BaseChart.js +++ b/src/js/charts/BaseChart.js @@ -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); } diff --git a/src/js/utils/axis-chart-utils.js b/src/js/utils/axis-chart-utils.js index 08ce68c..bc4a24d 100644 --- a/src/js/utils/axis-chart-utils.js +++ b/src/js/utils/axis-chart-utils.js @@ -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); }