return objClone;
};
helpers.extend = function(base) {
- var setFn = function(value, key) { base[key] = value; };
+ var setFn = function(value, key) {
+ base[key] = value;
+ };
for (var i = 1, ilen = arguments.length; i < ilen; i++) {
helpers.each(arguments[i], setFn);
}
return value === undefined ? defaultValue : value;
};
helpers.indexOf = Array.prototype.indexOf?
- function(array, item) { return array.indexOf(item); } :
+ function(array, item) {
+ return array.indexOf(item);
+ }:
function(array, item) {
for (var i = 0, ilen = array.length; i < ilen; ++i) {
if (array[i] === item) {
helpers.where = function(collection, filterCallback) {
if (helpers.isArray(collection) && Array.prototype.filter) {
return collection.filter(filterCallback);
- } else {
- var filtered = [];
+ }
+ var filtered = [];
- helpers.each(collection, function(item) {
- if (filterCallback(item)) {
- filtered.push(item);
- }
- });
+ helpers.each(collection, function(item) {
+ if (filterCallback(item)) {
+ filtered.push(item);
+ }
+ });
- return filtered;
- }
+ return filtered;
};
helpers.findIndex = Array.prototype.findIndex?
- function(array, callback, scope) { return array.findIndex(callback, scope); } :
+ function(array, callback, scope) {
+ return array.findIndex(callback, scope);
+ } :
function(array, callback, scope) {
scope = scope === undefined? array : scope;
for (var i = 0, ilen = array.length; i < ilen; ++i) {
};
helpers.inherits = function(extensions) {
// Basic javascript inheritance based on the model created in Backbone.js
- var parent = this;
+ var me = this;
var ChartElement = (extensions && extensions.hasOwnProperty('constructor')) ? extensions.constructor : function() {
- return parent.apply(this, arguments);
+ return me.apply(this, arguments);
};
var Surrogate = function() {
this.constructor = ChartElement;
};
- Surrogate.prototype = parent.prototype;
+ Surrogate.prototype = me.prototype;
ChartElement.prototype = new Surrogate();
ChartElement.extend = helpers.inherits;
helpers.extend(ChartElement.prototype, extensions);
}
- ChartElement.__super__ = parent.prototype;
+ ChartElement.__super__ = me.prototype;
return ChartElement;
};
return array.reduce(function(max, value) {
if (!isNaN(value)) {
return Math.max(max, value);
- } else {
- return max;
}
+ return max;
}, Number.NEGATIVE_INFINITY);
};
helpers.min = function(array) {
return array.reduce(function(min, value) {
if (!isNaN(value)) {
return Math.min(min, value);
- } else {
- return min;
}
+ return min;
}, Number.POSITIVE_INFINITY);
};
helpers.sign = Math.sign?
- function(x) { return Math.sign(x); } :
+ function(x) {
+ return Math.sign(x);
+ } :
function(x) {
x = +x; // convert to a number
if (x === 0 || isNaN(x)) {
return x > 0 ? 1 : -1;
};
helpers.log10 = Math.log10?
- function(x) { return Math.log10(x); } :
+ function(x) {
+ return Math.log10(x);
+ } :
function(x) {
return Math.log(x) / Math.LN10;
};
} else {
niceFraction = 10;
}
+ } else if (fraction <= 1.0) {
+ niceFraction = 1;
+ } else if (fraction <= 2) {
+ niceFraction = 2;
+ } else if (fraction <= 5) {
+ niceFraction = 5;
} else {
- if (fraction <= 1.0) {
- niceFraction = 1;
- } else if (fraction <= 2) {
- niceFraction = 2;
- } else if (fraction <= 5) {
- niceFraction = 5;
- } else {
- niceFraction = 10;
- }
+ niceFraction = 10;
}
return niceFraction * Math.pow(10, exponent);
return 1 * (7.5625 * (t -= (1.5 / 2.75)) * t + 0.75);
} else if (t < (2.5 / 2.75)) {
return 1 * (7.5625 * (t -= (2.25 / 2.75)) * t + 0.9375);
- } else {
- return 1 * (7.5625 * (t -= (2.625 / 2.75)) * t + 0.984375);
}
+ return 1 * (7.5625 * (t -= (2.625 / 2.75)) * t + 0.984375);
},
easeInOutBounce: function(t) {
if (t < 1 / 2) {
}
};
helpers.isArray = Array.isArray?
- function(obj) { return Array.isArray(obj); } :
+ function(obj) {
+ return Array.isArray(obj);
+ } :
function(obj) {
return Object.prototype.toString.call(obj) === '[object Array]';
};
fn.apply(_tArg, args);
}
};
- helpers.getHoverColor = function(color) {
+ helpers.getHoverColor = function(colorValue) {
/* global CanvasPattern */
- return (color instanceof CanvasPattern) ?
- color :
- helpers.color(color).saturate(0.5).darken(0.1).rgbString();
+ return (colorValue instanceof CanvasPattern) ?
+ colorValue :
+ helpers.color(colorValue).saturate(0.5).darken(0.1).rgbString();
};
};
// Function to fit a box
function fitBox(box) {
- var minBoxSize = helpers.findNextWhere(minBoxSizes, function(minBoxSize) {
- return minBoxSize.box === box;
+ var minBoxSize = helpers.findNextWhere(minBoxSizes, function(minBox) {
+ return minBox.box === box;
});
if (minBoxSize) {
helpers.each(leftBoxes.concat(rightBoxes), finalFitVerticalBox);
function finalFitVerticalBox(box) {
- var minBoxSize = helpers.findNextWhere(minBoxSizes, function(minBoxSize) {
- return minBoxSize.box === box;
+ var minBoxSize = helpers.findNextWhere(minBoxSizes, function(minSize) {
+ return minSize.box === box;
});
var scaleMargin = {
cursor.line++;
x = cursor.x = me.left + ((legendWidth - lineWidths[cursor.line]) / 2);
}
- } else {
- if (y + itemHeight > me.bottom) {
- x = cursor.x = x + me.columnWidths[cursor.line] + labelOpts.padding;
- y = cursor.y = me.top;
- cursor.line++;
- }
+ } else if (y + itemHeight > me.bottom) {
+ x = cursor.x = x + me.columnWidths[cursor.line] + labelOpts.padding;
+ y = cursor.y = me.top;
+ cursor.line++;
}
drawLegendBox(x, y, legendItem);
if (typeof(rawValue) === 'object') {
if ((rawValue instanceof Date) || (rawValue.isValid)) {
return rawValue;
- } else {
- return this.getRightValue(this.isHorizontal() ? rawValue.x : rawValue.y);
}
+ return this.getRightValue(this.isHorizontal() ? rawValue.x : rawValue.y);
}
// Value is good, return it
var finalVal = me.left + Math.round(pixel);
finalVal += me.isFullWidth() ? me.margins.left : 0;
return finalVal;
- } else {
- var innerHeight = me.height - (me.paddingTop + me.paddingBottom);
- return me.top + (index * (innerHeight / (me.ticks.length - 1)));
}
+ var innerHeight = me.height - (me.paddingTop + me.paddingBottom);
+ return me.top + (index * (innerHeight / (me.ticks.length - 1)));
},
// Utility for getting the pixel location of a percentage of scale
var finalVal = me.left + Math.round(valueOffset);
finalVal += me.isFullWidth() ? me.margins.left : 0;
return finalVal;
- } else {
- return me.top + (decimal * me.height);
}
+ return me.top + (decimal * me.height);
},
getBasePixel: function() {
// Common properties
var tx1, ty1, tx2, ty2, x1, y1, x2, y2, labelX, labelY;
- var textAlign, textBaseline = 'middle';
+ var textAlign = 'middle';
+ var textBaseline = 'middle';
if (isHorizontal) {
if (!isRotated) {
labelX = me.right - optionTicks.padding;
textAlign = 'right';
}
+ // right side
+ } else if (optionTicks.mirror) {
+ labelX = me.left - optionTicks.padding;
+ textAlign = 'right';
} else {
- // right side
- if (optionTicks.mirror) {
- labelX = me.left - optionTicks.padding;
- textAlign = 'right';
- } else {
- labelX = me.left + optionTicks.padding;
- textAlign = 'left';
- }
+ labelX = me.left + optionTicks.padding;
+ textAlign = 'left';
}
var yLineValue = me.getPixelForTick(index); // xvalues for grid lines
} else if (xAlign === 'right') {
pt.x -= paddingAndSize;
}
- } else {
- if (xAlign === 'left') {
- pt.x -= radiusAndPadding;
- } else if (xAlign === 'right') {
- pt.x += radiusAndPadding;
- }
+ } else if (xAlign === 'left') {
+ pt.x -= radiusAndPadding;
+ } else if (xAlign === 'right') {
+ pt.x += radiusAndPadding;
}
return pt;
if ((data.xLabels && isHorizontal) || (data.yLabels && !isHorizontal)) {
return me.getRightValue(data.datasets[datasetIndex].data[index]);
- } else {
- return me.ticks[index];
}
+ return me.ticks[index];
},
// Used to get data value locations. Value can either be an index or a numerical value
}
return me.left + Math.round(widthOffset);
- } else {
- var innerHeight = me.height - (me.paddingTop + me.paddingBottom);
- var valueHeight = innerHeight / offsetAmt;
- var heightOffset = (valueHeight * (index - me.minIndex)) + me.paddingTop;
-
- if (me.options.gridLines.offsetGridLines && includeOffset) {
- heightOffset += (valueHeight / 2);
- }
+ }
+ var innerHeight = me.height - (me.paddingTop + me.paddingBottom);
+ var valueHeight = innerHeight / offsetAmt;
+ var heightOffset = (valueHeight * (index - me.minIndex)) + me.paddingTop;
- return me.top + Math.round(heightOffset);
+ if (me.options.gridLines.offsetGridLines && includeOffset) {
+ heightOffset += (valueHeight / 2);
}
+
+ return me.top + Math.round(heightOffset);
},
getPixelForTick: function(index, includeOffset) {
return this.getPixelForValue(this.ticks[index], index + this.minIndex, null, includeOffset);
if (opts.stacked) {
var valuesPerType = {};
- var hasPositiveValues = false;
- var hasNegativeValues = false;
helpers.each(datasets, function(dataset, datasetIndex) {
var meta = chart.getDatasetMeta(datasetIndex);
if (opts.relativePoints) {
positiveValues[index] = 100;
+ } else if (value < 0) {
+ negativeValues[index] += value;
} else {
- if (value < 0) {
- hasNegativeValues = true;
- negativeValues[index] += value;
- } else {
- hasPositiveValues = true;
- positiveValues[index] += value;
- }
+ positiveValues[index] += value;
}
});
}
innerDimension = me.width - (paddingLeft + me.paddingRight);
pixel = me.left + (innerDimension / range * (rightValue - start));
return Math.round(pixel + paddingLeft);
- } else {
- innerDimension = me.height - (me.paddingTop + paddingBottom);
- pixel = (me.bottom - paddingBottom) - (innerDimension / range * (rightValue - start));
- return Math.round(pixel);
}
+ innerDimension = me.height - (me.paddingTop + paddingBottom);
+ pixel = (me.bottom - paddingBottom) - (innerDimension / range * (rightValue - start));
+ return Math.round(pixel);
},
getValueForPixel: function(pixel) {
var me = this;
return '0';
} else if (remain === 1 || remain === 2 || remain === 5 || index === 0 || index === arr.length - 1) {
return value.toExponential();
- } else {
- return '';
}
+ return '';
}
}
};
furthestRight = pointPosition.x + textWidth;
furthestRightIndex = i;
}
- } else {
- // More than half the values means we'll right align the text
- if (pointPosition.x - textWidth < furthestLeft) {
- furthestLeft = pointPosition.x - textWidth;
- furthestLeftIndex = i;
- }
+ // More than half the values means we'll right align the text
+ } else if (pointPosition.x - textWidth < furthestLeft) {
+ furthestLeft = pointPosition.x - textWidth;
+ furthestLeftIndex = i;
}
}
var scalingFactor = me.drawingArea / (me.max - me.min);
if (me.options.reverse) {
return (me.max - value) * scalingFactor;
- } else {
- return (value - me.min) * scalingFactor;
}
+ return (value - me.min) * scalingFactor;
},
getPointPosition: function(index, distanceFromCenter) {
var me = this;