Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix time series scale to have each data point is spread equidistant #11388

Merged
merged 3 commits into from
Jul 13, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/scales/scale.time.js
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ export default class TimeScale extends Scale {
* `minor` unit using the given scale time `options`.
* Important: this method can return ticks outside the min and max range, it's the
* responsibility of the calling code to clamp values if needed.
* @private
* @protected
*/
_generate() {
const adapter = this._adapter;
Expand Down Expand Up @@ -485,7 +485,7 @@ export default class TimeScale extends Scale {
}

// @ts-ignore
return Object.keys(ticks).sort((a, b) => a - b).map(x => +x);
return Object.keys(ticks).sort(sorter).map(x => +x);
}

/**
Expand Down
19 changes: 19 additions & 0 deletions src/scales/scale.timeseries.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,25 @@ class TimeSeriesScale extends TimeScale {
return table;
}

/**
* Generates all timestamps defined in the data.
* Important: this method can return ticks outside the min and max range, it's the
* responsibility of the calling code to clamp values if needed.
* @protected
*/
_generate() {
const min = this.min;
const max = this.max;
let timestamps = super.getDataTimestamps();
if (!timestamps.includes(min) || !timestamps.length) {
timestamps.splice(0, 0, min);
}
if (!timestamps.includes(max) || timestamps.length === 1) {
timestamps.push(max);
}
return timestamps.sort((a, b) => a - b).map(x => +x);
stockiNail marked this conversation as resolved.
Show resolved Hide resolved
}

/**
* Returns all timestamps
* @return {number[]}
Expand Down
Loading