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 wrong ticks distribution for timescale #4844

Closed
wants to merge 1 commit into from
Closed
Changes from all 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 @@ -548,8 +548,8 @@ module.exports = function(Chart) {

if (timestamps.length) {
timestamps = arrayUnique(timestamps).sort(sorter);
min = Math.min(min, timestamps[0]);
max = Math.max(max, timestamps[timestamps.length - 1]);
min = min === MAX_INTEGER ? timestamps[0] : min;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that's wrong, if min !== MAX_INTEGER, we still want Math.min(min, timestamps[0]); because min can change line 545 to a lower value. I don't understand why these 2 lines need to be modified, @Andgoncharov can you elaborate why these changes?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree about elaborating this. @Andgoncharov could you post images with and without these changes? I also agree that we need to keep the Math.min() call.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @simonbrunel, @etimberg,

I've created a fiddle https://jsfiddle.net/andgoncharov/8bgen7b7/ to display the problem. When I change options.time.min and options.time.max values, I expect that chart is displayed within specified borders and ticks are also distributed between those values. Currently, min and max values ain't taken into account if they are inside (timestamps[0], timestamps[length - 1]) interval.

When I apply my changes, the updated chart contains a number of x-axis labels according to the settings I've specified upon creation of the chart. Or may be I misunderstood something?

max = max === MIN_INTEGER ? timestamps[timestamps.length - 1] : max;
}

// In case there is no valid min/max, let's use today limits
Expand Down