Skip to content

Commit

Permalink
More robust for invalid data
Browse files Browse the repository at this point in the history
  • Loading branch information
pissang committed Mar 2, 2016
1 parent 080fa37 commit 2989873
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/data/List.js
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ define(function (require) {
};

/**
* Get value
* Get value. Return NaN if idx is out of range.
* @param {string} dim Dim must be concrete name.
* @param {number} idx
* @param {boolean} stack
Expand All @@ -306,6 +306,11 @@ define(function (require) {
var storage = this._storage;
var dataIndex = this.indices[idx];

// If value not exists
if (dataIndex == null) {
return NaN;
}

var value = storage[dim] && storage[dim][dataIndex];
// FIXME ordinal data type is not stackable
if (stack) {
Expand Down
3 changes: 3 additions & 0 deletions src/util/number.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ define(function (require) {
* @param {number} val
*/
number.getPrecision = function (val) {
if (isNaN(val)) {
return 0;
}
// It is much faster than methods converting number to string as follows
// var tmp = val.toString();
// return tmp.length - 1 - tmp.indexOf('.');
Expand Down

0 comments on commit 2989873

Please sign in to comment.