* If the tooltip callback returns `undefined`, then the default callback will be used.
* `maintainAspectRatio` respects container height.
* Time and timeseries scales use `ticks.stepSize` instead of `time.stepSize`, which has been removed.
+* `maxTickslimit` wont be used for the ticks in `autoSkip` if the determined max ticks is less then the `maxTicksLimit`.
#### Type changes
* The order of the `ChartMeta` parameters have been changed from `<Element, DatasetElement, Type>` to `<Type, Element, DatasetElement>`.
*/
export function autoSkip(scale, ticks) {
const tickOpts = scale.options.ticks;
- const ticksLimit = tickOpts.maxTicksLimit || determineMaxTicks(scale);
+ const determinedMaxTicks = determineMaxTicks(scale);
+ const ticksLimit = Math.min(tickOpts.maxTicksLimit || determinedMaxTicks, determinedMaxTicks);
const majorIndices = tickOpts.major.enabled ? getMajorIndices(ticks) : [];
const numMajorIndices = majorIndices.length;
const first = majorIndices[0];
});
}
+ function getChartBigData(maxTicksLimit) {
+ return window.acquireChart({
+ type: 'line',
+ data: {
+ labels: new Array(300).fill('red'),
+ datasets: [{
+ data: new Array(300).fill(5),
+ }]
+ },
+ options: {
+ scales: {
+ x: {
+ ticks: {
+ autoSkip: true,
+ maxTicksLimit
+ }
+ }
+ }
+ }
+ });
+ }
+
function lastTick(chart) {
var xAxis = chart.scales.x;
var ticks = xAxis.getTicks();
return ticks[ticks.length - 1];
}
+ it('should use autoSkip amount of ticks when maxTicksLimit is set to a larger number as autoSkip calculation', function() {
+ var chart = getChartBigData(300);
+ expect(chart.scales.x.ticks.length).toEqual(20);
+ });
+
+ it('should use maxTicksLimit amount of ticks when maxTicksLimit is set to a smaller number as autoSkip calculation', function() {
+ var chart = getChartBigData(3);
+ expect(chart.scales.x.ticks.length).toEqual(3);
+ });
+
it('should display the last tick if it fits evenly with other ticks', function() {
var chart = getChart({
labels: [