Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Finishing removing old major/minor options #7042

Merged
merged 2 commits into from
Feb 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions samples/scales/time/line-max-span.html
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
},
Expand Down
9 changes: 7 additions & 2 deletions samples/scales/time/line-point-data.html
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
},
Expand Down
14 changes: 3 additions & 11 deletions src/scales/scale.time.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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;
kurkle marked this conversation as resolved.
Show resolved Hide resolved
return formatter ? formatter(label, index, ticks) : label;
}

Expand Down
82 changes: 0 additions & 82 deletions test/specs/scale.time.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down