From a30f7533219b0ae6a3542f260fc3a48f0b8aefb8 Mon Sep 17 00:00:00 2001 From: Ben McCann <322311+benmccann@users.noreply.github.com> Date: Wed, 5 Feb 2020 15:20:01 -0800 Subject: [PATCH] Finishing removing old major/minor options (#7042) * Finishing removing old major/minor options * Fix samples --- samples/scales/time/line-max-span.html | 11 +++- samples/scales/time/line-point-data.html | 9 ++- src/scales/scale.time.js | 14 +--- test/specs/scale.time.tests.js | 82 ------------------------ 4 files changed, 19 insertions(+), 97 deletions(-) diff --git a/samples/scales/time/line-max-span.html b/samples/scales/time/line-max-span.html index 64c003873..365883904 100644 --- a/samples/scales/time/line-max-span.html +++ b/samples/scales/time/line-max-span.html @@ -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; } } }, diff --git a/samples/scales/time/line-point-data.html b/samples/scales/time/line-point-data.html index bf2d240cf..9bcf3af32 100644 --- a/samples/scales/time/line-point-data.html +++ b/samples/scales/time/line-point-data.html @@ -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; } } }, diff --git a/src/scales/scale.time.js b/src/scales/scale.time.js index 64fefc4e1..4f718cc83 100644 --- a/src/scales/scale.time.js +++ b/src/scales/scale.time.js @@ -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; } diff --git a/test/specs/scale.time.tests.js b/test/specs/scale.time.tests.js index 94efd9731..e3295a01b 100644 --- a/test/specs/scale.time.tests.js +++ b/test/specs/scale.time.tests.js @@ -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',