]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Update millisecond default format. Removed unnecessary space at right edge of time...
authorEvert Timberg <evert.timberg@gmail.com>
Sat, 30 Jan 2016 21:35:10 +0000 (16:35 -0500)
committerEvert Timberg <evert.timberg@gmail.com>
Sat, 30 Jan 2016 21:35:10 +0000 (16:35 -0500)
src/scales/scale.time.js
test/scale.time.tests.js

index b2dffa762935b346c0bc35dff2b471fc2631955a..0dfab52168a7e4289bddc60d9e3c6328e889d9f4 100644 (file)
@@ -54,7 +54,7 @@
 
                        // defaults to unit's corresponding unitFormat below or override using pattern string from http://momentjs.com/docs/#/displaying/format/
                        displayFormats: {
-                               'millisecond': 'SSS [ms]',
+                               'millisecond': 'h:mm:ss.SSS a', // 11:20:01.123 AM,
                                'second': 'h:mm:ss a', // 11:20:01 AM
                                'minute': 'h:mm:ss a', // 11:20:01 AM
                                'hour': 'MMM D, hA', // Sept 4, 5PM
                                // Determine the smallest needed unit of the time
                                var innerWidth = this.isHorizontal() ? this.width - (this.paddingLeft + this.paddingRight) : this.height - (this.paddingTop + this.paddingBottom);
                                var labelCapacity = innerWidth / (this.options.ticks.fontSize + 10);
-                               var buffer = this.options.time.round ? 0 : 2;
+                               var buffer = this.options.time.round ? 0 : 1;
 
                                // Start as small as possible
                                this.tickUnit = 'millisecond';
                        // Always show the right tick
                        if (this.options.time.max) {
                                this.ticks.push(this.lastTick.clone());
-                       } else {
+                       } else if (this.ticks[this.ticks.length - 1].diff(this.lastTick, this.tickUnit, true) !== 0) {
                                this.tickRange = Math.ceil(this.tickRange / this.unitScale) * this.unitScale;
                                this.ticks.push(this.firstTick.clone().add(this.tickRange, this.tickUnit));
                                this.lastTick = this.ticks[this.ticks.length - 1].clone();
index 6b16ecd63e036ac289e7366b15be45e52cfb9ebc..87155deeaf7c11f600f1c0593b707d7d02859fae 100644 (file)
@@ -55,7 +55,7 @@ describe('Time scale tests', function() {
                                round: false,
                                displayFormat: false,
                                displayFormats: {
-                                       'millisecond': 'SSS [ms]',
+                                       'millisecond': 'h:mm:ss.SSS a', // 11:20:01.123 AM
                                        'second': 'h:mm:ss a', // 11:20:01 AM
                                        'minute': 'h:mm:ss a', // 11:20:01 AM
                                        'hour': 'MMM D, hA', // Sept 4, 5PM
@@ -122,7 +122,7 @@ describe('Time scale tests', function() {
                scale.update(400, 50);
 
                // Counts down because the lines are drawn top to bottom
-               expect(scale.ticks).toEqual(['Jan 1, 2015', 'Jan 3, 2015', 'Jan 5, 2015', 'Jan 7, 2015', 'Jan 9, 2015', 'Jan 11, 2015', 'Jan 13, 2015']);
+               expect(scale.ticks).toEqual(['Jan 1, 2015', 'Jan 3, 2015', 'Jan 5, 2015', 'Jan 7, 2015', 'Jan 9, 2015', 'Jan 11, 2015']);
        });
 
        it('should build ticks when the data is xy points', function() {
@@ -173,7 +173,7 @@ describe('Time scale tests', function() {
                scale.update(400, 50);
 
                // Counts down because the lines are drawn top to bottom
-               expect(scale.ticks).toEqual(['Jan 1, 2015', 'Jan 3, 2015', 'Jan 5, 2015', 'Jan 7, 2015', 'Jan 9, 2015', 'Jan 11, 2015', 'Jan 13, 2015']);
+               expect(scale.ticks).toEqual(['Jan 1, 2015', 'Jan 3, 2015', 'Jan 5, 2015', 'Jan 7, 2015', 'Jan 9, 2015', 'Jan 11, 2015']);
        });
 
        it('should build ticks using the config unit', function() {
@@ -224,6 +224,8 @@ describe('Time scale tests', function() {
 
                //scale.buildTicks();
                scale.update(400, 50);
+
+               // last date is feb 15 because we round to start of week
                expect(scale.ticks).toEqual(['Dec 28, 2014', 'Jan 4, 2015', 'Jan 11, 2015', 'Jan 18, 2015', 'Jan 25, 2015', 'Feb 1, 2015', 'Feb 8, 2015', 'Feb 15, 2015']);
        });