Permalink
Browse files

solidify and add tests for zero xMin/yMin values

fixes gh-5
  • Loading branch information...
1 parent 9cb4097 commit cf89b882c591e2099227024f9cdb108dee62f532 @paularmstrong paularmstrong committed Jun 28, 2013
Showing with 39 additions and 9 deletions.
  1. +4 −4 lib/chart.js
  2. +6 −3 lib/scales.js
  3. +11 −1 test/chart.test.js
  4. +18 −1 test/scales.test.js
View
@@ -232,10 +232,10 @@ _.defaults(xChart.prototype, {
break;
}
- if (data.xMin != null) o.xMin = data.xMin;
- if (data.xMax != null) o.xMax = data.xMax;
- if (data.yMin != null) o.yMin = data.yMin;
- if (data.yMax != null) o.yMax = data.yMax;
+ o.xMin = (isNaN(parseInt(data.xMin, 10))) ? o.xMin : data.xMin;
+ o.xMax = (isNaN(parseInt(data.xMax, 10))) ? o.xMax : data.xMax;
+ o.yMin = (isNaN(parseInt(data.yMin, 10))) ? o.yMin : data.yMin;
+ o.yMax = (isNaN(parseInt(data.yMax, 10))) ? o.yMax : data.yMax;
if (self._vis) {
self._destroy(self._vis, self._mainStorage);
View
@@ -88,9 +88,12 @@ function _getExtents(options, data, xType, yType) {
if (type !== 'time') {
extended = _extendDomain(extents[axis]);
}
- extents[axis][i] = (options.hasOwnProperty(minMax) &&
- options[minMax] !== null) ? options[minMax]
- : (type !== 'time') ? extended[i] : extents[axis][i];
+
+ if (options.hasOwnProperty(minMax) && options[minMax] !== null) {
+ extents[axis][i] = options[minMax];
+ } else if (type !== 'time') {
+ extents[axis][i] = extended[i];
+ }
});
});
View
@@ -265,9 +265,19 @@
xMax: 10,
yMin: 2,
yMax: 8
- });
+ }),
+ d;
+ c.setData(newData);
+ expect(c._options.xMin).to.equal(newData.xMin);
+
+ c = new xChart('bar', mData, container);
+ newData = _.extend(newData, {
+ xMin: 0,
+ yMin: 0,
+ });
c.setData(newData);
expect(c._options.xMin).to.equal(newData.xMin);
+ expect(c._options.yMin).to.equal(newData.yMin);
});
});
View
@@ -101,7 +101,8 @@
],
sOrdinal,
sLinear,
- sTime;
+ sTime,
+ zeroMins;
sOrdinal = scales.xy(foo, data, 'ordinal', 'ordinal');
expect(sOrdinal.x.domain()).to.eql([1, 2]);
@@ -111,6 +112,22 @@
expect(sLinear.x.domain()).to.eql([foo._options.xMin, foo._options.xMax]);
expect(sLinear.y.domain()).to.eql([foo._options.yMin, foo._options.yMax]);
+ zeroMins = {
+ _options: {
+ xMin: 0,
+ xMax: 20,
+ yMin: 0,
+ yMax: 40
+ },
+ _width: 100,
+ _height: 100
+ };
+ sLinear = scales.xy(zeroMins, data, 'linear', 'linear');
+ expect(sLinear.x.domain()).to.eql([zeroMins._options.xMin,
+ zeroMins._options.xMax]);
+ expect(sLinear.y.domain()).to.eql([zeroMins._options.yMin,
+ zeroMins._options.yMax]);
+
foo._options = {
xMin: new Date(2012, 1, 1),
xMax: new Date(2012, 10, 1),

0 comments on commit cf89b88

Please sign in to comment.