Finishing removing old major/minor options (#7042)

* Finishing removing old major/minor options
* Fix samples
This commit is contained in:
Ben McCann 2020-02-05 15:20:01 -08:00 committed by GitHub
parent f9cd9fdf76
commit a30f753321
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 19 additions and 97 deletions

View File

@ -91,9 +91,16 @@
labelString: 'Date'
},
ticks: {
autoSkip: false,
maxRotation: 0,
major: {
fontStyle: 'bold',
fontColor: '#FF0000'
enabled: true
},
fontStyle: function(context) {
return context.tick && context.tick.major ? 'bold' : undefined;
},
fontColor: function(context) {
return context.tick && context.tick.major ? '#FF0000' : undefined;
}
}
},

View File

@ -91,8 +91,13 @@
},
ticks: {
major: {
fontStyle: 'bold',
fontColor: '#FF0000'
enabled: true
},
fontStyle: function(context) {
return context.tick && context.tick.major ? 'bold' : undefined;
},
fontColor: function(context) {
return context.tick && context.tick.major ? '#FF0000' : undefined;
}
}
},

View File

@ -4,7 +4,6 @@ import adapters from '../core/core.adapters';
import defaults from '../core/core.defaults';
import {isFinite, isNullOrUndef, mergeIf, valueOrDefault} from '../helpers/helpers.core';
import {toRadians} from '../helpers/helpers.math';
import {resolve} from '../helpers/helpers.options';
import Scale from '../core/core.scale';
import {_lookup, _lookupByKey} from '../helpers/helpers.collection';
@ -645,22 +644,15 @@ class TimeScale extends Scale {
*/
_tickFormatFunction(time, index, ticks, format) {
const me = this;
const adapter = me._adapter;
const options = me.options;
const formats = options.time.displayFormats;
const minorFormat = formats[me._unit];
const majorUnit = me._majorUnit;
const minorFormat = formats[me._unit];
const majorFormat = formats[majorUnit];
const tick = ticks[index];
const tickOpts = options.ticks;
const major = majorUnit && majorFormat && tick && tick.major;
const label = adapter.format(time, format ? format : major ? majorFormat : minorFormat);
const nestedTickOpts = major ? tickOpts.major : tickOpts.minor;
const formatter = resolve([
nestedTickOpts.callback,
tickOpts.callback
]);
const label = me._adapter.format(time, format ? format : major ? majorFormat : minorFormat);
const formatter = options.ticks.callback;
return formatter ? formatter(label, index, ticks) : label;
}

View File

@ -716,88 +716,6 @@ describe('Time scale tests', function() {
});
});
describe('when ticks.major.callback and ticks.minor.callback are specified', function() {
beforeEach(function() {
this.chart = window.acquireChart({
type: 'line',
data: {
datasets: [{
xAxisID: 'x',
data: [0, 0]
}],
labels: ['2015-01-01T20:00:00', '2015-01-01T20:01:00']
},
options: {
scales: {
x: {
type: 'time',
ticks: {
callback: function(value) {
return '<' + value + '>';
},
major: {
enabled: true,
callback: function(value) {
return '[[' + value + ']]';
}
},
minor: {
callback: function(value) {
return '(' + value + ')';
}
}
}
}
}
}
});
this.scale = this.chart.scales.x;
});
it('should get the correct labels for major and minor ticks', function() {
var labels = getLabels(this.scale);
expect(labels.length).toEqual(21);
expect(labels[0]).toEqual('[[8:00 pm]]');
expect(labels[Math.floor(labels.length / 2)]).toEqual('(8:00:30 pm)');
expect(labels[labels.length - 1]).toEqual('[[8:01 pm]]');
});
it('should only use ticks.minor callback if ticks.major.enabled is false', function() {
var chart = this.chart;
chart.options.scales.x.ticks.major.enabled = false;
chart.update();
var labels = getLabels(this.scale);
expect(labels.length).toEqual(21);
expect(labels[0]).toEqual('(8:00:00 pm)');
expect(labels[labels.length - 1]).toEqual('(8:01:00 pm)');
});
it('should use ticks.callback if ticks.major.callback is omitted', function() {
var chart = this.chart;
chart.options.scales.x.ticks.major.callback = undefined;
chart.update();
var labels = getLabels(this.scale);
expect(labels.length).toEqual(21);
expect(labels[0]).toEqual('<8:00 pm>');
expect(labels[labels.length - 1]).toEqual('<8:01 pm>');
});
it('should use ticks.callback if ticks.minor.callback is omitted', function() {
var chart = this.chart;
chart.options.scales.x.ticks.minor.callback = undefined;
chart.update();
var labels = getLabels(this.scale);
expect(labels.length).toEqual(21);
expect(labels[0]).toEqual('[[8:00 pm]]');
expect(labels[Math.floor(labels.length / 2)]).toEqual('<8:00:30 pm>');
expect(labels[labels.length - 1]).toEqual('[[8:01 pm]]');
});
});
it('should get the correct label when time is specified as a string', function() {
var chart = window.acquireChart({
type: 'line',