Skip to content

Commit

Permalink
nf-graph: better behavior when setting yMin, yMax to null
Browse files Browse the repository at this point in the history
Previously, setting `yMin` or `yMax` to `undefined` caused

> Error: Invalid value for <g> attribute transform="translate(520, NaN)"

There was no way to set `yMin` or `yMax` to "something if it's defined,
or default behavior otherwise". This now treats the following as
equivalent:

```hbs
{{!-- no yMax specified: --}}
{{nf-graph}}

{{!-- yMax set to undefined: --}}
{{nf-graph yMax=somePropertyThatIsUndefined}}
```
  • Loading branch information
James A. Rosen committed Jul 4, 2015
1 parent 189af95 commit bb39914
Showing 1 changed file with 56 additions and 44 deletions.
100 changes: 56 additions & 44 deletions app/components/nf-graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ var minProperty = function(axis, defaultTickCount){
var _Axis_tickCount_ = axis + 'Axis.tickCount';
var _ScaleFactory_ = axis + 'ScaleFactory';
var __Min_ = '_' + axis + 'Min';
var __didOverride_ = '_didOverride_' + axis + 'Min';
var _prop_ = axis + 'Min';

return Ember.computed(
Expand All @@ -131,33 +132,38 @@ var minProperty = function(axis, defaultTickCount){
var mode = this.get(_MinMode_);
var ext;

if(arguments.length > 1) {
this[__Min_] = value;
} else {
var change = function(val) {
this.set(_prop_, val);
}.bind(this);
if(value != null) {
this[__didOverride_] = true;
return this[__Min_] = value;
}

if(mode === 'auto') {
change(this.get(_DataExtent_)[0] || 0);
}
if(this[__didOverride_]) {
return this[__Min_];
}

var change = function(val) {
this[__Min_] = val;
}.bind(this);

else if(mode === 'push') {
ext = this.get(_DataExtent_)[0];
if(!isNaN(ext) && ext < this[__Min_]) {
change(ext);
}
if(mode === 'auto') {
change(this.get(_DataExtent_)[0] || 0);
}

else if(mode === 'push') {
ext = this.get(_DataExtent_)[0];
if(!isNaN(ext) && ext < this[__Min_]) {
change(ext);
}
}

else if(mode === 'push-tick') {
var extent = this.get(_DataExtent_);
ext = extent[0];
else if(mode === 'push-tick') {
var extent = this.get(_DataExtent_);
ext = extent[0];

if(!isNaN(ext) && ext < this[__Min_]) {
var tickCount = this.get(_Axis_tickCount_) || defaultTickCount;
var newDomain = this.get(_ScaleFactory_)().domain(extent).nice(tickCount).domain();
change(newDomain[0]);
}
if(!isNaN(ext) && ext < this[__Min_]) {
var tickCount = this.get(_Axis_tickCount_) || defaultTickCount;
var newDomain = this.get(_ScaleFactory_)().domain(extent).nice(tickCount).domain();
change(newDomain[0]);
}
}

Expand All @@ -172,6 +178,7 @@ var maxProperty = function(axis, defaultTickCount) {
var _ScaleFactory_ = axis + 'ScaleFactory';
var _MaxMode_ = axis + 'MaxMode';
var __Max_ = '_' + axis + 'Max';
var __didOverride_ = '_didOverride_' + axis + 'Max';
var _prop_ = axis + 'Max';

return Ember.computed(
Expand All @@ -183,33 +190,38 @@ var maxProperty = function(axis, defaultTickCount) {
var mode = this.get(_MaxMode_);
var ext;

if(arguments.length > 1) {
this[__Max_] = value;
} else {
var change = function(val) {
this.set(_prop_, val);
}.bind(this);
if(value != null) {
this[__didOverride_] = true;
return this[__Max_] = value;
}

if(mode === 'auto') {
change(this.get(_DataExtent_)[1] || 1);
}
if(this[__didOverride_]) {
return this[__Max_];
}

var change = function(val) {
this[__Max_] = val;
}.bind(this);

else if(mode === 'push') {
ext = this.get(_DataExtent_)[1];
if(!isNaN(ext) && this[__Max_] < ext) {
change(ext);
}
if(mode === 'auto') {
change(this.get(_DataExtent_)[1] || 1);
}

else if(mode === 'push') {
ext = this.get(_DataExtent_)[1];
if(!isNaN(ext) && this[__Max_] < ext) {
change(ext);
}
}

else if(mode === 'push-tick') {
var extent = this.get(_DataExtent_);
ext = extent[1];
else if(mode === 'push-tick') {
var extent = this.get(_DataExtent_);
ext = extent[1];

if(!isNaN(ext) && this[__Max_] < ext) {
var tickCount = this.get(_Axis_tickCount_) || defaultTickCount;
var newDomain = this.get(_ScaleFactory_)().domain(extent).nice(tickCount).domain();
change(newDomain[1]);
}
if(!isNaN(ext) && this[__Max_] < ext) {
var tickCount = this.get(_Axis_tickCount_) || defaultTickCount;
var newDomain = this.get(_ScaleFactory_)().domain(extent).nice(tickCount).domain();
change(newDomain[1]);
}
}

Expand Down

0 comments on commit bb39914

Please sign in to comment.