From eea2094431ef0d5f7046095c05238725677a5680 Mon Sep 17 00:00:00 2001 From: Justin Lan Date: Thu, 24 Sep 2015 17:03:41 -0700 Subject: [PATCH] [Scales.Time] Change default extent to be wider and consistent. Previously, the default extent was supposed to be based on the current day, but wound up defaulting instead to [Unix epoch, + 1 second]. The default extent has now been changed to be [Unix epoch, + 1 day]. Close #2740. --- plottable.js | 7 ++----- src/scales/timeScale.ts | 7 ++----- test/scales/timeScaleTests.ts | 8 ++++++++ 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/plottable.js b/plottable.js index d6916e4a2c..9aef2eb449 100644 --- a/plottable.js +++ b/plottable.js @@ -2335,6 +2335,7 @@ var Plottable; function Time() { _super.call(this); this._d3Scale = d3.time.scale(); + this.autoDomain(); } /** * Returns an array of ticks values separated by the specified interval. @@ -2358,11 +2359,7 @@ var Plottable; return _super.prototype._setDomain.call(this, values); }; Time.prototype._defaultExtent = function () { - var now = new Date(); - var endTimeValue = now.valueOf(); - now.setDate(now.getDate() - 1); - var startTimeValue = now.valueOf(); - return [new Date(startTimeValue), new Date(endTimeValue)]; + return [new Date("1970-01-01"), new Date("1970-01-02")]; }; Time.prototype._expandSingleValueDomain = function (singleValueDomain) { var startTime = singleValueDomain[0].getTime(); diff --git a/src/scales/timeScale.ts b/src/scales/timeScale.ts index ff01e0ce77..399d2da999 100644 --- a/src/scales/timeScale.ts +++ b/src/scales/timeScale.ts @@ -12,6 +12,7 @@ export module Scales { constructor() { super(); this._d3Scale = d3.time.scale(); + this.autoDomain(); } /** @@ -38,11 +39,7 @@ export module Scales { } protected _defaultExtent(): Date[] { - let now = new Date(); - let endTimeValue = now.valueOf(); - now.setDate(now.getDate() - 1); - let startTimeValue = now.valueOf(); - return [new Date(startTimeValue), new Date(endTimeValue)]; + return [new Date("1970-01-01"), new Date("1970-01-02")]; } protected _expandSingleValueDomain(singleValueDomain: Date[]): Date[] { diff --git a/test/scales/timeScaleTests.ts b/test/scales/timeScaleTests.ts index ce29211c88..a8dd6a11a0 100644 --- a/test/scales/timeScaleTests.ts +++ b/test/scales/timeScaleTests.ts @@ -49,6 +49,14 @@ describe("Scales", () => { assert.operator(scale.domain()[1].getTime(), ">", unpaddedDomain[1].getTime(), "right side of domain was padded"); }); + it("has a consistent default domain", () => { + let scale2 = new Plottable.Scales.Time(); + assert.strictEqual(scale.domain()[0].getTime(), scale2.domain()[0].getTime(), + "both scales have the same default left side of domain"); + assert.strictEqual(scale.domain()[1].getTime(), scale2.domain()[1].getTime(), + "both scales have the same default right side of domain"); + }); + it("respects padding exceptions", () => { let minValue = new Date(2000, 5, 4); let maxValue = new Date(2000, 5, 6);