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';
*/
_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;
}
});
});
- 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',