From f75116a91eea82db1cabdec51d021685a69ddede Mon Sep 17 00:00:00 2001 From: Evert Timberg Date: Sat, 30 Jan 2016 16:35:10 -0500 Subject: [PATCH] Update millisecond default format. Removed unnecessary space at right edge of time scale. --- src/scales/scale.time.js | 6 +++--- test/scale.time.tests.js | 8 +++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/scales/scale.time.js b/src/scales/scale.time.js index b2dffa762..0dfab5216 100644 --- a/src/scales/scale.time.js +++ b/src/scales/scale.time.js @@ -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 @@ -143,7 +143,7 @@ // 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'; @@ -225,7 +225,7 @@ // 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(); diff --git a/test/scale.time.tests.js b/test/scale.time.tests.js index 6b16ecd63..87155deea 100644 --- a/test/scale.time.tests.js +++ b/test/scale.time.tests.js @@ -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']); }); -- 2.47.3