From: Zach Panzarino Date: Thu, 15 Sep 2016 12:49:11 +0000 (+0000) Subject: Implement eslint changes proposed by @simonbrunel in code review X-Git-Tag: v2.3.0-rc.1~1^2~6^2 X-Git-Url: http://git.ipfire.org/gitweb/?a=commitdiff_plain;h=refs%2Fpull%2F3308%2Fhead;p=thirdparty%2FChart.js.git Implement eslint changes proposed by @simonbrunel in code review --- diff --git a/.eslintrc b/.eslintrc index 7cae49e41..991867f10 100644 --- a/.eslintrc +++ b/.eslintrc @@ -13,7 +13,7 @@ env: rules: # Possible Errors no-cond-assign: 2 - no-console: 1 + no-console: [2, {allow: [warn, error]}] no-constant-condition: 2 no-control-regex: 2 no-debugger: 2 @@ -112,7 +112,7 @@ rules: no-undef: 2 no-undefined: 0 no-unused-vars: 2 - no-use-before-define: 1 + no-use-before-define: 2 # Node.js and CommonJS callback-return: 2 @@ -130,7 +130,7 @@ rules: block-spacing: 0 brace-style: [2, 1tbs] camelcase: 2 - comma-dangle: [2, never] + comma-dangle: [2, only-multiline] comma-spacing: 2 comma-style: [2, last] computed-property-spacing: [2, never] @@ -188,7 +188,7 @@ rules: operator-linebreak: 0 padded-blocks: 0 quote-props: [2, as-needed] - quotes: [2, single] + quotes: [2, single, {avoidEscape: true}] require-jsdoc: 0 semi-spacing: 2 semi: [2, always] diff --git a/src/core/core.helpers.js b/src/core/core.helpers.js index 1593b72de..5364d191f 100644 --- a/src/core/core.helpers.js +++ b/src/core/core.helpers.js @@ -945,7 +945,7 @@ module.exports = function(Chart) { }; helpers.color = function(c) { if (!color) { - console.log('Color.js not found!'); + console.error('Color.js not found!'); return c; } diff --git a/src/core/core.js b/src/core/core.js index c4f65e5ca..577db878e 100755 --- a/src/core/core.js +++ b/src/core/core.js @@ -77,7 +77,7 @@ module.exports = function() { onClick: null, defaultColor: 'rgba(0,0,0,0.1)', defaultFontColor: '#666', - defaultFontFamily: '\'Helvetica Neue\', \'Helvetica\', \'Arial\', sans-serif', + defaultFontFamily: "'Helvetica Neue', 'Helvetica', 'Arial', sans-serif", defaultFontSize: 12, defaultFontStyle: 'normal', showLines: true, diff --git a/src/core/core.layoutService.js b/src/core/core.layoutService.js index 1bb06fcf3..7336deac0 100644 --- a/src/core/core.layoutService.js +++ b/src/core/core.layoutService.js @@ -115,8 +115,6 @@ module.exports = function(Chart) { var maxChartAreaHeight = chartHeight; var minBoxSizes = []; - helpers.each(leftBoxes.concat(rightBoxes, topBoxes, bottomBoxes), getMinimumBoxSize); - function getMinimumBoxSize(box) { var minSize; var isHorizontal = box.isHorizontal(); @@ -136,6 +134,8 @@ module.exports = function(Chart) { }); } + helpers.each(leftBoxes.concat(rightBoxes, topBoxes, bottomBoxes), getMinimumBoxSize); + // At this point, maxChartAreaHeight and maxChartAreaWidth are the size the chart area could // be if the axes are drawn at their minimum sizes. @@ -145,20 +145,6 @@ module.exports = function(Chart) { var totalTopBoxesHeight = yPadding; var totalBottomBoxesHeight = yPadding; - // Update, and calculate the left and right margins for the horizontal boxes - helpers.each(leftBoxes.concat(rightBoxes), fitBox); - - helpers.each(leftBoxes, function(box) { - totalLeftBoxesWidth += box.width; - }); - - helpers.each(rightBoxes, function(box) { - totalRightBoxesWidth += box.width; - }); - - // Set the Left and Right margins for the horizontal boxes - helpers.each(topBoxes.concat(bottomBoxes), fitBox); - // Function to fit a box function fitBox(box) { var minBoxSize = helpers.findNextWhere(minBoxSizes, function(minBox) { @@ -183,6 +169,20 @@ module.exports = function(Chart) { } } + // Update, and calculate the left and right margins for the horizontal boxes + helpers.each(leftBoxes.concat(rightBoxes), fitBox); + + helpers.each(leftBoxes, function(box) { + totalLeftBoxesWidth += box.width; + }); + + helpers.each(rightBoxes, function(box) { + totalRightBoxesWidth += box.width; + }); + + // Set the Left and Right margins for the horizontal boxes + helpers.each(topBoxes.concat(bottomBoxes), fitBox); + // Figure out how much margin is on the top and bottom of the vertical boxes helpers.each(topBoxes, function(box) { totalTopBoxesHeight += box.height; @@ -192,9 +192,6 @@ module.exports = function(Chart) { totalBottomBoxesHeight += box.height; }); - // Let the left layout know the final margin - helpers.each(leftBoxes.concat(rightBoxes), finalFitVerticalBox); - function finalFitVerticalBox(box) { var minBoxSize = helpers.findNextWhere(minBoxSizes, function(minSize) { return minSize.box === box; @@ -212,6 +209,9 @@ module.exports = function(Chart) { } } + // Let the left layout know the final margin + helpers.each(leftBoxes.concat(rightBoxes), finalFitVerticalBox); + // Recalculate because the size of each layout might have changed slightly due to the margins (label rotation for instance) totalLeftBoxesWidth = xPadding; totalRightBoxesWidth = xPadding; @@ -268,15 +268,6 @@ module.exports = function(Chart) { var left = xPadding; var top = yPadding; - helpers.each(leftBoxes.concat(topBoxes), placeBox); - - // Account for chart width and height - left += maxChartAreaWidth; - top += maxChartAreaHeight; - - helpers.each(rightBoxes, placeBox); - helpers.each(bottomBoxes, placeBox); - function placeBox(box) { if (box.isHorizontal()) { box.left = box.options.fullWidth ? xPadding : totalLeftBoxesWidth; @@ -299,6 +290,15 @@ module.exports = function(Chart) { } } + helpers.each(leftBoxes.concat(topBoxes), placeBox); + + // Account for chart width and height + left += maxChartAreaWidth; + top += maxChartAreaHeight; + + helpers.each(rightBoxes, placeBox); + helpers.each(bottomBoxes, placeBox); + // Step 8 chartInstance.chartArea = { left: totalLeftBoxesWidth,