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

This fixes #2599 #2600

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
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
22 changes: 17 additions & 5 deletions src/core/core.scale.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ module.exports = function(Chart) {
reverse: false,
display: true,
autoSkip: true,
allowSkipLastTick: false,
autoSkipPadding: 0,
labelOffset: 0,
callback: function(value) {
Expand Down Expand Up @@ -471,6 +472,7 @@ module.exports = function(Chart) {
var scaleLabelX;
var scaleLabelY;
var useAutoskipper = optionTicks.autoSkip;
var allowSkipLastTick = optionTicks.allowSkipLastTick;

// figure out the maximum number of gridlines to show
var maxTicks;
Expand Down Expand Up @@ -506,8 +508,14 @@ module.exports = function(Chart) {
var yTickEnd = options.position === "bottom" ? this.top + tl : this.bottom;
skipRatio = false;

if (((longestRotatedLabel / 2) + optionTicks.autoSkipPadding) * this.ticks.length > (this.width - (this.paddingLeft + this.paddingRight))) {
skipRatio = 1 + Math.floor((((longestRotatedLabel / 2) + optionTicks.autoSkipPadding) * this.ticks.length) / (this.width - (this.paddingLeft + this.paddingRight)));
// Only calculate the skip ratio with the half width of longestRotateLabel if we got an actual rotation
// See #2584
if (isRotated) {
longestRotatedLabel /= 2;
}

if ((longestRotatedLabel + optionTicks.autoSkipPadding) * this.ticks.length > (this.width - (this.paddingLeft + this.paddingRight))) {
skipRatio = 1 + Math.floor(((longestRotatedLabel + optionTicks.autoSkipPadding) * this.ticks.length) / (this.width - (this.paddingLeft + this.paddingRight)));
}

// if they defined a max number of optionTicks,
Expand All @@ -528,10 +536,14 @@ module.exports = function(Chart) {
helpers.each(this.ticks, function (label, index) {
// Blank optionTicks
var isLastTick = this.ticks.length === index + 1;
var shouldSkip = skipRatio > 1 && index % skipRatio > 0;

// If we skip the last tick, we may need to hide the last shown one before
if (!allowSkipLastTick) {
shouldSkip = shouldSkip || (index % skipRatio === 0 && index + skipRatio >= this.ticks.length);
}

// Since we always show the last tick,we need may need to hide the last shown one before
var shouldSkip = (skipRatio > 1 && index % skipRatio > 0) || (index % skipRatio === 0 && index + skipRatio > this.ticks.length);
if (shouldSkip && !isLastTick || (label === undefined || label === null)) {
if (shouldSkip && !(isLastTick && !allowSkipLastTick) || (label === undefined || label === null)) {
return;
}
var xLineValue = this.getPixelForTick(index); // xvalues for grid lines
Expand Down
26 changes: 14 additions & 12 deletions src/scales/scale.time.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,18 +274,20 @@ module.exports = function(Chart) {
}

// Always show the right tick
var diff = this.ticks[this.ticks.length - 1].diff(this.lastTick, this.tickUnit);
if (diff !== 0 || this.scaleSizeInUnits === 0) {
// this is a weird case. If the <max> option is the same as the end option, we can't just diff the times because the tick was created from the roundedStart
// but the last tick was not rounded.
if (this.options.time.max) {
this.ticks.push(this.lastTick.clone());
this.scaleSizeInUnits = this.lastTick.diff(this.ticks[0], this.tickUnit, true);
} else {
this.ticks.push(this.lastTick.clone());
this.scaleSizeInUnits = this.lastTick.diff(this.firstTick, this.tickUnit, true);
}
}
if (!this.options.ticks.allowSkipLastTick) {
var diff = this.ticks[this.ticks.length - 1].diff(this.lastTick, this.tickUnit);
if (diff !== 0 || this.scaleSizeInUnits === 0) {
// this is a weird case. If the <max> option is the same as the end option, we can't just diff the times because the tick was created from the roundedStart
// but the last tick was not rounded.
if (this.options.time.max) {
this.ticks.push(this.lastTick.clone());
this.scaleSizeInUnits = this.lastTick.diff(this.ticks[0], this.tickUnit, true);
} else {
this.ticks.push(this.lastTick.clone());
this.scaleSizeInUnits = this.lastTick.diff(this.firstTick, this.tickUnit, true);
}
}
}

this.ctx.restore();
},
Expand Down