Skip to content

Commit

Permalink
feat/fix: Fixes #404 maintaining backwards compat
Browse files Browse the repository at this point in the history
  • Loading branch information
uhrjun committed Dec 15, 2022
1 parent 256649f commit 1b955a9
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/js/charts/AxisChart.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
25 changes: 16 additions & 9 deletions src/js/charts/BaseChart.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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;
Expand All @@ -87,8 +92,8 @@ export default class BaseChart {
this.configure(options);
}

prepareData(data) {
return data;
prepareData(data, config) {
return data, config;
}

prepareFirstData(data) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
}
Expand Down
4 changes: 3 additions & 1 deletion src/js/utils/axis-chart-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit 1b955a9

Please sign in to comment.