]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Fix style issues in core and scales
authorZach Panzarino <zachary@panzarino.com>
Thu, 15 Sep 2016 00:23:30 +0000 (00:23 +0000)
committerZach Panzarino <zachary@panzarino.com>
Thu, 15 Sep 2016 00:23:30 +0000 (00:23 +0000)
src/core/core.helpers.js
src/core/core.layoutService.js
src/core/core.legend.js
src/core/core.scale.js
src/core/core.tooltip.js
src/scales/scale.category.js
src/scales/scale.linear.js
src/scales/scale.logarithmic.js
src/scales/scale.radialLinear.js

index 9c021a78096f1e2f24dbd1d705f2936d355654e0..1593b72de0477e495c8a0272cfb6fdccc3b78af8 100644 (file)
@@ -45,7 +45,9 @@ module.exports = function(Chart) {
                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);
                }
@@ -150,7 +152,9 @@ module.exports = function(Chart) {
                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) {
@@ -162,20 +166,21 @@ module.exports = function(Chart) {
        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) {
@@ -211,15 +216,15 @@ module.exports = function(Chart) {
        };
        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;
@@ -228,7 +233,7 @@ module.exports = function(Chart) {
                        helpers.extend(ChartElement.prototype, extensions);
                }
 
-               ChartElement.__super__ = parent.prototype;
+               ChartElement.__super__ = me.prototype;
 
                return ChartElement;
        };
@@ -250,22 +255,22 @@ module.exports = function(Chart) {
                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)) {
@@ -274,7 +279,9 @@ module.exports = function(Chart) {
                        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;
                };
@@ -455,16 +462,14 @@ module.exports = function(Chart) {
                        } 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);
@@ -656,9 +661,8 @@ module.exports = function(Chart) {
                                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) {
@@ -996,7 +1000,9 @@ module.exports = function(Chart) {
                }
        };
        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]';
                };
@@ -1029,10 +1035,10 @@ module.exports = function(Chart) {
                        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();
        };
 };
index 324e93f5f0d76f2eaf4adcd82c3d0bddb627cc26..1bb06fcf3654343a6ddbc425de7c78456f793921 100644 (file)
@@ -161,8 +161,8 @@ module.exports = function(Chart) {
 
                        // 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) {
@@ -196,8 +196,8 @@ module.exports = function(Chart) {
                        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 = {
index 369b549fa62b458ee3170ffdb7eedc36c245b779..e82c06ea3ed23b592488b0b9d98eb5d4617dc0e5 100644 (file)
@@ -397,12 +397,10 @@ module.exports = function(Chart) {
                                                        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);
index 7a5613c0ffe55d89fb039bfbf4fa86aa6945e129..123da31841df64e81e0c3df0d34d30d8accdbaa4 100644 (file)
@@ -406,9 +406,8 @@ module.exports = function(Chart) {
                        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
@@ -440,10 +439,9 @@ module.exports = function(Chart) {
                                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
@@ -456,9 +454,8 @@ module.exports = function(Chart) {
                                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() {
@@ -584,7 +581,8 @@ module.exports = function(Chart) {
 
                                // 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) {
@@ -611,15 +609,13 @@ module.exports = function(Chart) {
                                                        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
index e59b26a2d7499beb7928a587bd81e6044890ed73..5edfd0075f8d98c4195509afe6c626c824906593 100755 (executable)
@@ -492,12 +492,10 @@ module.exports = function(Chart) {
                                } 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;
index 4979f193e5b7c70fddcaf250abd2a196e48d650c..7e1b3d409d6679b1f88ba8da5eae20291257ed6e 100644 (file)
@@ -56,9 +56,8 @@ module.exports = function(Chart) {
 
                        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
@@ -83,17 +82,16 @@ module.exports = function(Chart) {
                                }
 
                                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);
index 33a3e4930db8dcd82117bdb79ddfa9714b3c8929..f2700a3a4ae92ee1952f0b7e8ee5b1e5bbc7a804 100644 (file)
@@ -54,8 +54,6 @@ module.exports = function(Chart) {
 
                        if (opts.stacked) {
                                var valuesPerType = {};
-                               var hasPositiveValues = false;
-                               var hasNegativeValues = false;
 
                                helpers.each(datasets, function(dataset, datasetIndex) {
                                        var meta = chart.getDatasetMeta(datasetIndex);
@@ -82,14 +80,10 @@ module.exports = function(Chart) {
 
                                                        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;
                                                        }
                                                });
                                        }
@@ -175,11 +169,10 @@ module.exports = function(Chart) {
                                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;
index 2d4f323fdd97cc30cd358ede9ce502c71e6c45cd..50417528a5b582b8f703e3ddbd0ef25a5c7c0d0c 100644 (file)
@@ -16,9 +16,8 @@ module.exports = function(Chart) {
                                        return '0';
                                } else if (remain === 1 || remain === 2 || remain === 5 || index === 0 || index === arr.length - 1) {
                                        return value.toExponential();
-                               } else {
-                                       return '';
                                }
+                               return '';
                        }
                }
        };
index d6eef1c04299558d042d4ab0a9269a75a3abb8ba..361ad3cbab1d3b2947baca4fbfc09daa437a1a12 100644 (file)
@@ -195,12 +195,10 @@ module.exports = function(Chart) {
                                                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;
                                }
                        }
 
@@ -252,9 +250,8 @@ module.exports = function(Chart) {
                        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;