Refactored isNum core function to more meaningful logic

This commit is contained in:
Gion Kunz 2016-10-21 19:22:59 +02:00
parent 05a607422f
commit 2d83da5a2c
3 changed files with 9 additions and 9 deletions

View File

@ -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)
});

View File

@ -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
});

View File

@ -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'];