diff --git a/src/scripts/charts/bar.js b/src/scripts/charts/bar.js index cf13232..75595d6 100644 --- a/src/scripts/charts/bar.js +++ b/src/scripts/charts/bar.js @@ -352,7 +352,7 @@ // Create bar element bar = seriesElement.elem('line', positions, options.classNames.bar).attr({ - 'ct:value': [value.x, value.y].filter(Chartist.isNum).join(','), + 'ct:value': [value.x, value.y].filter(Chartist.isNumeric).join(','), 'ct:meta': Chartist.getMetaData(series, valueIndex) }); diff --git a/src/scripts/charts/line.js b/src/scripts/charts/line.js index 862d2ef..d014aea 100644 --- a/src/scripts/charts/line.js +++ b/src/scripts/charts/line.js @@ -141,8 +141,8 @@ if(options.axisY.type === undefined) { axisY = new Chartist.AutoScaleAxis(Chartist.Axis.units.y, data, chartRect, Chartist.extend({}, options.axisY, { - high: Chartist.isNum(options.high) ? options.high : options.axisY.high, - low: Chartist.isNum(options.low) ? options.low : options.axisY.low + high: Chartist.isNumeric(options.high) ? options.high : options.axisY.high, + low: Chartist.isNumeric(options.low) ? options.low : options.axisY.low })); } else { axisY = options.axisY.type.call(Chartist, Chartist.Axis.units.y, data, chartRect, options.axisY); @@ -213,7 +213,7 @@ x2: pathElement.x + 0.01, y2: pathElement.y }, options.classNames.point).attr({ - 'ct:value': [pathElement.data.value.x, pathElement.data.value.y].filter(Chartist.isNum).join(','), + 'ct:value': [pathElement.data.value.x, pathElement.data.value.y].filter(Chartist.isNumeric).join(','), 'ct:meta': pathElement.data.meta }); diff --git a/src/scripts/core.js b/src/scripts/core.js index 3054d7e..e7534a7 100644 --- a/src/scripts/core.js +++ b/src/scripts/core.js @@ -579,14 +579,14 @@ var Chartist = { }; /** - * Checks if the value is a valid number or string with a number. + * Checks if a value can be safely coerced to a number. This includes all values except null which result in finite numbers when coerced. This excludes NaN, since it's not finite. * * @memberof Chartist.Core * @param value * @returns {Boolean} */ - Chartist.isNum = function(value) { - return (typeof value === "number" || typeof value === "string") && !isNaN(value) && isFinite(value); + Chartist.isNumeric = function(value) { + return value === null ? false : isFinite(value); }; /** @@ -608,7 +608,7 @@ var Chartist = { * @returns {*} */ Chartist.getNumberOrUndefined = function(value) { - return Chartist.isNum(value) ? +value : undefined; + return Chartist.isNumeric(value) ? +value : undefined; }; /** @@ -620,7 +620,7 @@ var Chartist = { * @returns {*} */ Chartist.getMultiValue = function(value, dimension, defaultValue) { - if(Chartist.isNum(value)) { + if(Chartist.isNumeric(value)) { return +value; } else if(value) { return Chartist.isFalseyButZero(value[dimension || 'y']) ? defaultValue : value[dimension || 'y'];