From d0dd7f5c65391b4679d8a71f3a48dfbc58cf4683 Mon Sep 17 00:00:00 2001 From: Nick Date: Fri, 21 Apr 2017 16:17:15 +0100 Subject: [PATCH] Add mechanism to control application of .nice() If the forceTickCount property is set on the axis, the call to .nice(...) will take the specified tickCount into account when generating the scale function for the axis. --- src/objects/axis/begin.js | 2 ++ src/objects/axis/methods/_update.js | 9 +++++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/objects/axis/begin.js b/src/objects/axis/begin.js index 6f24504b..e191ac36 100755 --- a/src/objects/axis/begin.js +++ b/src/objects/axis/begin.js @@ -58,6 +58,8 @@ this.fontFamily = "sans-serif"; // Help: http://github.com/PMSI-AlignAlytics/dimple/wiki/dimple.axis#wiki-autoRotateLabel this.autoRotateLabel = (autoRotateLabel === null || autoRotateLabel === undefined ? true : autoRotateLabel); + // whether the tickCount (if specified) should be applied to call to .nice() when building the axis scale + this.forceTickCount = false; // If this is a composite axis, store links to all slaves this._slaves = []; diff --git a/src/objects/axis/methods/_update.js b/src/objects/axis/methods/_update.js index 7de59106..9c8b66ec 100755 --- a/src/objects/axis/methods/_update.js +++ b/src/objects/axis/methods/_update.js @@ -9,6 +9,7 @@ remainder, origin, tickCount = this.ticks || 10, + niceTickCount = this.forceTickCount && this.ticks ? tickCount : undefined, getOrderedCategories = function (self, axPos, oppPos) { var category = self.categoryFields[0], axisData = self._getAxisData(), @@ -65,7 +66,7 @@ ]) .clamp(this.clamp) .base(this.logBase) - .nice(); + .nice(niceTickCount); } else if (this.measure === null || this.measure === undefined) { distinctCats = getOrderedCategories(this, "x", "y"); // If there are any slaves process accordingly @@ -82,7 +83,7 @@ .range([this.chart._xPixels(), this.chart._xPixels() + this.chart._widthPixels()]) .domain([this._min, this._max]) .clamp(this.clamp) - .nice(); + .nice(niceTickCount); } // If it's visible, orient it at the top or bottom if it's first or second respectively if (!this.hidden) { @@ -121,7 +122,7 @@ ]) .clamp(this.clamp) .base(this.logBase) - .nice(); + .nice(niceTickCount); } else if (this.measure === null || this.measure === undefined) { distinctCats = getOrderedCategories(this, "y", "x"); // If there are any slaves process accordingly @@ -138,7 +139,7 @@ .range([this.chart._yPixels() + this.chart._heightPixels(), this.chart._yPixels()]) .domain([this._min, this._max]) .clamp(this.clamp) - .nice(); + .nice(niceTickCount); } // if it's visible, orient it at the left or right if it's first or second respectively if (!this.hidden) {