*ticks*.fontStyle | String | "normal" | Font style for the tick labels, follows CSS font-style options (i.e. normal, italic, oblique, initial, inherit).
*ticks*.maxRotation | Number | 90 | Maximum rotation for tick labels when rotating to condense labels. Note: Rotation doesn't occur until necessary. *Note: Only applicable to horizontal scales.*
*ticks*.minRotation | Number | 20 | *currently not-implemented* Minimum rotation for tick labels when condensing is necessary. *Note: Only applicable to horizontal scales.*
+*ticks*.maxTicksLimit | Number | 11 | Maximum number of ticks and gridlines to show.
*ticks*.padding | Number | 10 | Padding between the tick label and the axis. *Note: Only applicable to horizontal scales.*
*ticks*.mirror | Boolean | false | Flips tick labels around axis, displaying the labels inside the chart instead of outside. *Note: Only applicable to vertical scales.*
*ticks*.reverse | Boolean | false | Reverses order of tick labels.
//Number - The backdrop padding to the side of the label in pixels
backdropPaddingX: 2,
- //Number - Limit the maximum number of ticks
+ //Number - Limit the maximum number of ticks and gridlines
maxTicksLimit: 11,
},
var scaleLabelY;
var useAutoskipper = this.options.ticks.autoSkip;
+
+ // figure out the maximum number of gridlines to show
+ var maxTicks;
+
+ if (this.isHorizontal()) {
+ maxTicks = Math.min(
+ helpers.getValueOrDefault(this.options.ticks.maxTicksLimit, 11),
+ Math.ceil(this.width / 50)
+ );
+ } else {
+ // The factor of 2 used to scale the font size has been experimentally determined.
+ maxTicks = Math.min(
+ helpers.getValueOrDefault(this.options.ticks.maxTicksLimit, 11),
+ Math.ceil(this.height / (2 * this.options.ticks.fontSize))
+ );
+ }
+
+ // Make sure we always have at least 2 ticks
+ maxTicks = Math.max(2, maxTicks);
+
+
// Make sure we draw text in the correct color and font
this.ctx.fillStyle = this.options.ticks.fontColor;
var labelFont = helpers.fontString(this.options.ticks.fontSize, this.options.ticks.fontStyle, this.options.ticks.fontFamily);
if (!useAutoskipper) {
skipRatio = false;
}
+
+ // if they defined a max number of ticks,
+ // increase skipRatio until that number is met
+ if (maxTicks) {
+ while (!skipRatio || this.ticks.length / (skipRatio || 1) > maxTicks) {
+ if (!skipRatio) {
+ skipRatio = 1;
+ }
+ skipRatio += 1;
+ }
+ }
helpers.each(this.ticks, function(label, index) {
// Blank ticks
var maxTicks;
if (this.isHorizontal()) {
- maxTicks = Math.min(this.options.ticks.maxTicksLimit ? this.options.ticks.maxTicksLimit : 11,
- Math.ceil(this.width / 50));
+ maxTicks = Math.min(
+ helpers.getValueOrDefault(this.options.ticks.maxTicksLimit, 11),
+ Math.ceil(this.width / 50)
+ );
} else {
- // The factor of 2 used to scale the font size has been experimentally determined.
- maxTicks = Math.min(this.options.ticks.maxTicksLimit ? this.options.ticks.maxTicksLimit : 11,
- Math.ceil(this.height / (2 * this.options.ticks.fontSize)));
+ // The factor of 2 used to scale the font size has been experimentally determined.
+ maxTicks = Math.min(
+ helpers.getValueOrDefault(this.options.ticks.maxTicksLimit, 11),
+ Math.ceil(this.height / (2 * this.options.ticks.fontSize))
+ );
}
// Make sure we always have at least 2 ticks