mirror of
https://github.com/chartjs/Chart.js.git
synced 2026-03-09 01:36:51 +01:00
Merge pull request #1810 from olyckne/fix/ticks_callback
Fix ticks callback and auto skip
This commit is contained in:
@@ -62,6 +62,7 @@ afterUpdate | Function | undefined | Callback that runs at the end of the update
|
||||
*ticks*.suggestedMax | Number | - | User defined maximum number for the scale, overrides maximum value *except for if* it is lower than the maximum value.
|
||||
*ticks*.min | Number | - | User defined minimum number for the scale, overrides minimum value
|
||||
*ticks*.max | Number | - | User defined minimum number for the scale, overrides maximum value
|
||||
*ticks*.autoSkip | Boolean | true | If true, automatically calculates how many labels that can be shown and hides labels accordingly. Turn it off to show all labels no matter what
|
||||
*ticks*.callback | Function | `function(value) { return '' + value; } ` | Returns the string representation of the tick value as it should be displayed on the chart.
|
||||
|
||||
The `callback` method may be used for advanced tick customization. The following callback would display every label in scientific notation
|
||||
|
||||
@@ -46,6 +46,7 @@
|
||||
padding: 10,
|
||||
reverse: false,
|
||||
display: true,
|
||||
autoSkip: true,
|
||||
callback: function(value) {
|
||||
return '' + value;
|
||||
},
|
||||
@@ -441,6 +442,7 @@
|
||||
var skipRatio;
|
||||
var scaleLabelX;
|
||||
var scaleLabelY;
|
||||
var useAutoskipper = this.options.ticks.autoSkip;
|
||||
|
||||
// Make sure we draw text in the correct color and font
|
||||
this.ctx.fillStyle = this.options.ticks.fontColor;
|
||||
@@ -456,6 +458,10 @@
|
||||
skipRatio = 1 + Math.floor(((this.options.ticks.fontSize + 4) * this.ticks.length) / (this.width - (this.paddingLeft + this.paddingRight)));
|
||||
}
|
||||
|
||||
if (!useAutoskipper) {
|
||||
skipRatio = false;
|
||||
}
|
||||
|
||||
helpers.each(this.ticks, function(label, index) {
|
||||
// Blank ticks
|
||||
if ((skipRatio > 1 && index % skipRatio > 0) || (label === undefined || label === null)) {
|
||||
|
||||
@@ -244,6 +244,7 @@ describe('Core helper tests', function() {
|
||||
reverse: false,
|
||||
display: true,
|
||||
callback: merged.scales.yAxes[1].ticks.callback, // make it nicer, then check explicitly below
|
||||
autoSkip: true
|
||||
},
|
||||
type: 'linear'
|
||||
}, {
|
||||
@@ -280,6 +281,7 @@ describe('Core helper tests', function() {
|
||||
reverse: false,
|
||||
display: true,
|
||||
callback: merged.scales.yAxes[2].ticks.callback, // make it nicer, then check explicitly below
|
||||
autoSkip: true
|
||||
},
|
||||
type: 'linear'
|
||||
}]
|
||||
|
||||
@@ -43,6 +43,7 @@ describe('Category scale tests', function() {
|
||||
reverse: false,
|
||||
display: true,
|
||||
callback: defaultConfig.ticks.callback, // make this nicer, then check explicitly below
|
||||
autoSkip: true
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -42,6 +42,7 @@ describe('Linear Scale', function() {
|
||||
reverse: false,
|
||||
display: true,
|
||||
callback: defaultConfig.ticks.callback, // make this work nicer, then check below
|
||||
autoSkip: true
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -41,6 +41,7 @@ describe('Logarithmic Scale tests', function() {
|
||||
reverse: false,
|
||||
display: true,
|
||||
callback: defaultConfig.ticks.callback, // make this nicer, then check explicitly below
|
||||
autoSkip: true
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@@ -58,7 +58,7 @@ describe('Test the radial linear scale', function() {
|
||||
showLabelBackdrop: true,
|
||||
display: true,
|
||||
callback: defaultConfig.ticks.callback, // make this nicer, then check explicitly below
|
||||
|
||||
autoSkip: true
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@@ -45,7 +45,8 @@ describe('Time scale tests', function() {
|
||||
padding: 10,
|
||||
reverse: false,
|
||||
display: true,
|
||||
callback: defaultConfig.ticks.callback, // make this nicer, then check explicitly below
|
||||
callback: defaultConfig.ticks.callback, // make this nicer, then check explicitly below,
|
||||
autoSkip: true
|
||||
},
|
||||
time: {
|
||||
format: false,
|
||||
|
||||
Reference in New Issue
Block a user