]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Finishing removing old major/minor options (#7042)
authorBen McCann <322311+benmccann@users.noreply.github.com>
Wed, 5 Feb 2020 23:20:01 +0000 (15:20 -0800)
committerGitHub <noreply@github.com>
Wed, 5 Feb 2020 23:20:01 +0000 (18:20 -0500)
* Finishing removing old major/minor options
* Fix samples

samples/scales/time/line-max-span.html
samples/scales/time/line-point-data.html
src/scales/scale.time.js
test/specs/scale.time.tests.js

index 64c0038731f267f7d11720d42b7d80964a8957a8..3658839046aa82c1daaf50d727811eef1e42c6f6 100644 (file)
                                                        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;
                                                        }
                                                }
                                        },
index bf2d240cfce7c2861b7a0bc3b9b3b4a15b39c3b5..9bcf3af321b3f6e3c16ea18210a2553710b1bf92 100644 (file)
                                                },
                                                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;
                                                        }
                                                }
                                        },
index 64fefc4e19efd56910cdb11e8d305bbf33ffe438..4f718cc83d332b094682c06592d9c119ceb4be68 100644 (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;
        }
 
index 94efd9731f00f390afecc72bd6b2f6689e57056a..e3295a01b88738e6e433814b2d90151ad4bef931 100644 (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',