From f6eb675470485c487c4e8c88f0e4cad265264456 Mon Sep 17 00:00:00 2001 From: Zach Panzarino Date: Wed, 14 Sep 2016 18:03:55 +0000 Subject: [PATCH 1/9] Update new eslint rules --- .eslintrc | 100 ++++++++++++++++++++++++++++++------------------------ 1 file changed, 55 insertions(+), 45 deletions(-) diff --git a/.eslintrc b/.eslintrc index 96eca84f53e..4ba4ba5a098 100644 --- a/.eslintrc +++ b/.eslintrc @@ -12,9 +12,8 @@ env: # http://eslint.org/docs/rules/ rules: # Possible Errors - comma-dangle: [2, never] no-cond-assign: 2 - no-console: 0 + no-console: 1 no-constant-condition: 2 no-control-regex: 2 no-debugger: 2 @@ -25,7 +24,7 @@ rules: no-empty-character-class: 2 no-ex-assign: 2 no-extra-boolean-cast: 2 - no-extra-parens: 0 + no-extra-parens: [2, functions] no-extra-semi: 2 no-func-assign: 2 no-inner-declarations: [2, functions] @@ -43,37 +42,38 @@ rules: # Best Practices accessor-pairs: 2 + array-callback-return: 0 block-scoped-var: 0 complexity: [2, 6] consistent-return: 0 curly: [2, all] - default-case: 0 + default-case: 2 dot-location: 0 - dot-notation: 0 + dot-notation: 2 eqeqeq: 2 guard-for-in: 2 no-alert: 2 no-caller: 2 no-case-declarations: 2 no-div-regex: 2 - no-else-return: 0 + no-else-return: 2 no-empty-pattern: 2 no-eq-null: 2 no-eval: 2 no-extend-native: 2 no-extra-bind: 2 no-fallthrough: 2 - no-floating-decimal: 0 + no-floating-decimal: 2 no-implicit-coercion: 0 no-implied-eval: 2 no-invalid-this: 0 no-iterator: 2 - no-labels: 0 + no-labels: 2 no-lone-blocks: 2 no-loop-func: 2 no-magic-number: 0 - no-multi-spaces: 0 - no-multi-str: 0 + no-multi-spaces: 2 + no-multi-str: 2 no-native-reassign: 2 no-new-func: 2 no-new-wrappers: 2 @@ -85,7 +85,7 @@ rules: no-return-assign: 2 no-script-url: 2 no-self-compare: 2 - no-sequences: 0 + no-sequences: 2 no-throw-literal: 0 no-unused-expressions: 2 no-useless-call: 2 @@ -96,7 +96,7 @@ rules: radix: 2 vars-on-top: 0 wrap-iife: 2 - yoda: 0 + yoda: [2, never] # Strict strict: 0 @@ -107,12 +107,12 @@ rules: no-delete-var: 2 no-label-var: 2 no-shadow-restricted-names: 2 - no-shadow: 0 + no-shadow: 2 no-undef-init: 2 - no-undef: 0 + no-undef: 2 no-undefined: 0 - no-unused-vars: 0 - no-use-before-define: 0 + no-unused-vars: 2 + no-use-before-define: 2 # Node.js and CommonJS callback-return: 2 @@ -126,39 +126,46 @@ rules: no-sync: 0 # Stylistic Issues - array-bracket-spacing: 0 + array-bracket-spacing: [2, never] block-spacing: 0 - brace-style: 0 - camelcase: 0 - comma-spacing: 0 - comma-style: 0 - computed-property-spacing: 0 - consistent-this: 0 - eol-last: 0 - func-names: 0 + brace-style: [2, 1tbs] + camelcase: 2 + comma-dangle: [2, never] + comma-spacing: 2 + comma-style: [2, last] + computed-property-spacing: [2, never] + consistent-this: [2, me] + eol-last: 2 + func-names: [2, never] func-style: 0 id-length: 0 id-match: 0 indent: [2, tab] jsx-quotes: 0 - key-spacing: 0 - linebreak-style: 0 + key-spacing: 2 + linebreak-style: [2, unix] lines-around-comment: 0 max-depth: 0 max-len: 0 + max-lines: 0 max-nested-callbacks: 0 max-params: 0 + max-statements-per-line: 0 max-statements: [2, 30] + multiline-ternary: 0 new-cap: 0 - new-parens: 0 + new-parens: 2 newline-after-var: 0 + newline-before-return: 0 + newline-per-chained-call: 0 no-array-constructor: 0 no-bitwise: 0 no-continue: 0 no-inline-comments: 0 - no-lonely-if: 0 - no-mixed-spaces-and-tabs: 0 - no-multiple-empty-lines: 0 + no-lonely-if: 2 + no-mixed-operators: 0 + no-mixed-spaces-and-tabs: 2 + no-multiple-empty-lines: [2, {max: 2}] no-negated-condition: 0 no-nested-ternary: 0 no-new-object: 0 @@ -166,30 +173,33 @@ rules: no-restricted-syntax: 0 no-spaced-func: 0 no-ternary: 0 - no-trailing-spaces: 0 + no-trailing-spaces: 2 no-underscore-dangle: 0 no-unneeded-ternary: 0 - object-curly-spacing: 0 + no-whitespace-before-property: 2 + object-curly-newline: 0 + object-curly-spacing: [2, never] + object-property-newline: 0 + one-var-declaration-per-line: 2 one-var: 0 operator-assignment: 0 operator-linebreak: 0 padded-blocks: 0 - quote-props: 0 - quotes: 0 + quote-props: [2, as-needed] + quotes: [2, single] require-jsdoc: 0 - semi-spacing: 0 - semi: 0 + semi-spacing: 2 + semi: [2, always] + sort-keys: 0 sort-vars: 0 - space-after-keywords: 0 - space-before-blocks: 0 - space-before-function-paren: 0 - space-before-keywords: 0 - space-in-parens: 0 + space-before-blocks: [2, always] + space-before-function-paren: [2, never] + space-in-parens: [2, never] space-infix-ops: 0 - space-return-throw-case: 0 space-unary-ops: 0 - spaced-comment: 0 - wrap-regex: 0 + spaced-comment: [2, always] + unicode-bom: 0 + wrap-regex: 2 # ECMAScript 6 arrow-body-style: 0 From 2d2f475a7a5a48f9d623de88df9314aee0d5f059 Mon Sep 17 00:00:00 2001 From: Zach Panzarino Date: Wed, 14 Sep 2016 18:05:19 +0000 Subject: [PATCH 2/9] First round of eslint fixes --- src/charts/Chart.Bar.js | 4 +- src/charts/Chart.Bubble.js | 4 +- src/charts/Chart.Doughnut.js | 4 +- src/charts/Chart.Line.js | 4 +- src/charts/Chart.PolarArea.js | 4 +- src/charts/Chart.Radar.js | 6 +-- src/charts/Chart.Scatter.js | 16 ++++---- src/controllers/controller.bar.js | 32 +++++++-------- src/controllers/controller.bubble.js | 16 ++++---- src/controllers/controller.doughnut.js | 20 +++++----- src/controllers/controller.line.js | 8 ++-- src/controllers/controller.polarArea.js | 10 ++--- src/controllers/controller.radar.js | 4 +- src/core/core.animation.js | 10 ++--- src/core/core.canvasHelpers.js | 6 +-- src/core/core.controller.js | 40 +++++++++---------- src/core/core.datasetController.js | 4 +- src/core/core.element.js | 2 +- src/core/core.helpers.js | 52 ++++++++++++------------- src/core/core.js | 16 ++++---- src/core/core.layoutService.js | 12 +++--- src/core/core.legend.js | 10 ++--- src/core/core.plugin.js | 2 +- src/core/core.scale.js | 30 +++++++------- src/core/core.scaleService.js | 4 +- src/core/core.title.js | 6 +-- src/core/core.tooltip.js | 44 ++++++++++----------- src/elements/element.arc.js | 8 ++-- src/elements/element.line.js | 8 ++-- src/elements/element.point.js | 2 +- src/elements/element.rectangle.js | 4 +- src/scales/scale.category.js | 8 ++-- src/scales/scale.linear.js | 8 ++-- src/scales/scale.linearbase.js | 4 +- src/scales/scale.logarithmic.js | 20 +++++----- src/scales/scale.radialLinear.js | 26 ++++++------- src/scales/scale.time.js | 10 ++--- 37 files changed, 234 insertions(+), 234 deletions(-) diff --git a/src/charts/Chart.Bar.js b/src/charts/Chart.Bar.js index b80100c00e4..e1ad7962f9a 100644 --- a/src/charts/Chart.Bar.js +++ b/src/charts/Chart.Bar.js @@ -1,4 +1,4 @@ -"use strict"; +'use strict'; module.exports = function(Chart) { @@ -8,4 +8,4 @@ module.exports = function(Chart) { return new Chart(context, config); }; -}; \ No newline at end of file +}; diff --git a/src/charts/Chart.Bubble.js b/src/charts/Chart.Bubble.js index 37f4a98bb5f..2de4a1047ec 100644 --- a/src/charts/Chart.Bubble.js +++ b/src/charts/Chart.Bubble.js @@ -1,4 +1,4 @@ -"use strict"; +'use strict'; module.exports = function(Chart) { @@ -7,4 +7,4 @@ module.exports = function(Chart) { return new Chart(context, config); }; -}; \ No newline at end of file +}; diff --git a/src/charts/Chart.Doughnut.js b/src/charts/Chart.Doughnut.js index 41f80a244bc..e1e8ce54b34 100644 --- a/src/charts/Chart.Doughnut.js +++ b/src/charts/Chart.Doughnut.js @@ -1,4 +1,4 @@ -"use strict"; +'use strict'; module.exports = function(Chart) { @@ -8,4 +8,4 @@ module.exports = function(Chart) { return new Chart(context, config); }; -}; \ No newline at end of file +}; diff --git a/src/charts/Chart.Line.js b/src/charts/Chart.Line.js index ea328ac6eea..e89662ff7c1 100644 --- a/src/charts/Chart.Line.js +++ b/src/charts/Chart.Line.js @@ -1,4 +1,4 @@ -"use strict"; +'use strict'; module.exports = function(Chart) { @@ -8,4 +8,4 @@ module.exports = function(Chart) { return new Chart(context, config); }; -}; \ No newline at end of file +}; diff --git a/src/charts/Chart.PolarArea.js b/src/charts/Chart.PolarArea.js index 3a3e032f680..e07e4bac5a1 100644 --- a/src/charts/Chart.PolarArea.js +++ b/src/charts/Chart.PolarArea.js @@ -1,4 +1,4 @@ -"use strict"; +'use strict'; module.exports = function(Chart) { @@ -8,4 +8,4 @@ module.exports = function(Chart) { return new Chart(context, config); }; -}; \ No newline at end of file +}; diff --git a/src/charts/Chart.Radar.js b/src/charts/Chart.Radar.js index 322c4544af4..1648e9faca6 100644 --- a/src/charts/Chart.Radar.js +++ b/src/charts/Chart.Radar.js @@ -1,9 +1,9 @@ -"use strict"; +'use strict'; module.exports = function(Chart) { - + Chart.Radar = function(context, config) { - config.options = Chart.helpers.configMerge({ aspectRatio: 1 }, config.options); + config.options = Chart.helpers.configMerge({aspectRatio: 1}, config.options); config.type = 'radar'; return new Chart(context, config); diff --git a/src/charts/Chart.Scatter.js b/src/charts/Chart.Scatter.js index 7ab5c5717c7..84594f63755 100644 --- a/src/charts/Chart.Scatter.js +++ b/src/charts/Chart.Scatter.js @@ -1,4 +1,4 @@ -"use strict"; +'use strict'; module.exports = function(Chart) { @@ -9,14 +9,14 @@ module.exports = function(Chart) { scales: { xAxes: [{ - type: "linear", // scatter should not use a category axis - position: "bottom", - id: "x-axis-1" // need an ID so datasets can reference the scale + type: 'linear', // scatter should not use a category axis + position: 'bottom', + id: 'x-axis-1' // need an ID so datasets can reference the scale }], yAxes: [{ - type: "linear", - position: "left", - id: "y-axis-1" + type: 'linear', + position: 'left', + id: 'y-axis-1' }] }, @@ -44,4 +44,4 @@ module.exports = function(Chart) { return new Chart(context, config); }; -}; \ No newline at end of file +}; diff --git a/src/controllers/controller.bar.js b/src/controllers/controller.bar.js index 30347a28d4d..73ed2df2a0d 100644 --- a/src/controllers/controller.bar.js +++ b/src/controllers/controller.bar.js @@ -1,4 +1,4 @@ -"use strict"; +'use strict'; module.exports = function(Chart) { @@ -6,12 +6,12 @@ module.exports = function(Chart) { Chart.defaults.bar = { hover: { - mode: "label" + mode: 'label' }, scales: { xAxes: [{ - type: "category", + type: 'category', // Specific to Bar Controller categoryPercentage: 0.8, @@ -23,7 +23,7 @@ module.exports = function(Chart) { } }], yAxes: [{ - type: "linear" + type: 'linear' }] } }; @@ -281,17 +281,17 @@ module.exports = function(Chart) { // it extends bar (like pie extends doughnut) Chart.defaults.horizontalBar = { hover: { - mode: "label" + mode: 'label' }, scales: { xAxes: [{ - type: "linear", - position: "bottom" + type: 'linear', + position: 'bottom' }], yAxes: [{ - position: "left", - type: "category", + position: 'left', + type: 'category', // Specific to Horizontal Bar Controller categoryPercentage: 0.8, @@ -368,7 +368,7 @@ module.exports = function(Chart) { borderWidth: custom.borderWidth ? custom.borderWidth : helpers.getValueAtIndexOrDefault(dataset.borderWidth, index, rectangleElementOptions.borderWidth) }, - draw: function () { + draw: function() { var ctx = this._chart.ctx; var vm = this._view; @@ -425,7 +425,7 @@ module.exports = function(Chart) { } }, - inRange: function (mouseX, mouseY) { + inRange: function(mouseX, mouseY) { var vm = this._view; var inRange = false; @@ -444,7 +444,7 @@ module.exports = function(Chart) { rectangle.pivot(); }, - calculateBarBase: function (datasetIndex, index) { + calculateBarBase: function(datasetIndex, index) { var me = this; var meta = me.getMeta(); var xScale = me.getScaleForId(meta.xAxisID); @@ -470,7 +470,7 @@ module.exports = function(Chart) { return xScale.getBasePixel(); }, - getRuler: function (index) { + getRuler: function(index) { var me = this; var meta = me.getMeta(); var yScale = me.getScaleForId(meta.yAxisID); @@ -506,7 +506,7 @@ module.exports = function(Chart) { }; }, - calculateBarHeight: function (index) { + calculateBarHeight: function(index) { var me = this; var yScale = me.getScaleForId(me.getMeta().yAxisID); if (yScale.options.barThickness) { @@ -516,7 +516,7 @@ module.exports = function(Chart) { return yScale.options.stacked ? ruler.categoryHeight : ruler.barHeight; }, - calculateBarX: function (index, datasetIndex) { + calculateBarX: function(index, datasetIndex) { var me = this; var meta = me.getMeta(); var xScale = me.getScaleForId(meta.xAxisID); @@ -550,7 +550,7 @@ module.exports = function(Chart) { return xScale.getPixelForValue(value); }, - calculateBarY: function (index, datasetIndex) { + calculateBarY: function(index, datasetIndex) { var me = this; var meta = me.getMeta(); var yScale = me.getScaleForId(meta.yAxisID); diff --git a/src/controllers/controller.bubble.js b/src/controllers/controller.bubble.js index 49aa5007859..b1c6474e0cc 100644 --- a/src/controllers/controller.bubble.js +++ b/src/controllers/controller.bubble.js @@ -1,4 +1,4 @@ -"use strict"; +'use strict'; module.exports = function(Chart) { @@ -6,19 +6,19 @@ module.exports = function(Chart) { Chart.defaults.bubble = { hover: { - mode: "single" + mode: 'single' }, scales: { xAxes: [{ - type: "linear", // bubble should probably use a linear scale by default - position: "bottom", - id: "x-axis-0" // need an ID so datasets can reference the scale + type: 'linear', // bubble should probably use a linear scale by default + position: 'bottom', + id: 'x-axis-0' // need an ID so datasets can reference the scale }], yAxes: [{ - type: "linear", - position: "left", - id: "y-axis-0" + type: 'linear', + position: 'left', + id: 'y-axis-0' }] }, diff --git a/src/controllers/controller.doughnut.js b/src/controllers/controller.doughnut.js index 096f3085a41..40d4e2c842d 100644 --- a/src/controllers/controller.doughnut.js +++ b/src/controllers/controller.doughnut.js @@ -1,4 +1,4 @@ -"use strict"; +'use strict'; module.exports = function(Chart) { @@ -7,9 +7,9 @@ module.exports = function(Chart) { defaults.doughnut = { animation: { - //Boolean - Whether we animate the rotation of the Doughnut + // Boolean - Whether we animate the rotation of the Doughnut animateRotate: true, - //Boolean - Whether we animate scaling the Doughnut from the centre + // Boolean - Whether we animate scaling the Doughnut from the centre animateScale: false }, aspectRatio: 1, @@ -35,7 +35,7 @@ module.exports = function(Chart) { } text.push(''); - return text.join(""); + return text.join(''); }, legend: { labels: { @@ -84,13 +84,13 @@ module.exports = function(Chart) { } }, - //The percentage of the chart that we cut out of the middle. + // The percentage of the chart that we cut out of the middle. cutoutPercentage: 50, - //The rotation of the chart, where the first data arc begins. + // The rotation of the chart, where the first data arc begins. rotation: Math.PI * -0.5, - //The total circumference of the chart. + // The total circumference of the chart. circumference: Math.PI * 2.0, // Need to override these to give a nice default @@ -253,7 +253,7 @@ module.exports = function(Chart) { } }); - /*if (total === 0) { + /* if (total === 0) { total = NaN; }*/ @@ -269,8 +269,8 @@ module.exports = function(Chart) { } }, - //gets the max border or hover width to properly scale pie charts - getMaxBorderWidth: function (elements) { + // gets the max border or hover width to properly scale pie charts + getMaxBorderWidth: function(elements) { var max = 0, index = this.index, length = elements.length, diff --git a/src/controllers/controller.line.js b/src/controllers/controller.line.js index 53d3f38e6c3..a516a1e368e 100644 --- a/src/controllers/controller.line.js +++ b/src/controllers/controller.line.js @@ -1,4 +1,4 @@ -"use strict"; +'use strict'; module.exports = function(Chart) { @@ -9,16 +9,16 @@ module.exports = function(Chart) { spanGaps: false, hover: { - mode: "label" + mode: 'label' }, scales: { xAxes: [{ - type: "category", + type: 'category', id: 'x-axis-0' }], yAxes: [{ - type: "linear", + type: 'linear', id: 'y-axis-0' }] } diff --git a/src/controllers/controller.polarArea.js b/src/controllers/controller.polarArea.js index 9870546245b..6a11b4599ac 100644 --- a/src/controllers/controller.polarArea.js +++ b/src/controllers/controller.polarArea.js @@ -1,4 +1,4 @@ -"use strict"; +'use strict'; module.exports = function(Chart) { @@ -7,14 +7,14 @@ module.exports = function(Chart) { Chart.defaults.polarArea = { scale: { - type: "radialLinear", + type: 'radialLinear', lineArc: true, // so that lines are circular ticks: { beginAtZero: true } }, - //Boolean - Whether to animate the rotation of the chart + // Boolean - Whether to animate the rotation of the chart animation: { animateRotate: true, animateScale: true @@ -41,7 +41,7 @@ module.exports = function(Chart) { } text.push(''); - return text.join(""); + return text.join(''); }, legend: { labels: { @@ -155,7 +155,7 @@ module.exports = function(Chart) { } } - //var negHalfPI = -0.5 * Math.PI; + // var negHalfPI = -0.5 * Math.PI; var datasetStartAngle = opts.startAngle; var distance = arc.hidden ? 0 : scale.getDistanceFromCenterForValue(dataset.data[index]); var startAngle = datasetStartAngle + (circumference * visibleCount); diff --git a/src/controllers/controller.radar.js b/src/controllers/controller.radar.js index bc963b86835..3c050595a83 100644 --- a/src/controllers/controller.radar.js +++ b/src/controllers/controller.radar.js @@ -1,4 +1,4 @@ -"use strict"; +'use strict'; module.exports = function(Chart) { @@ -6,7 +6,7 @@ module.exports = function(Chart) { Chart.defaults.radar = { scale: { - type: "radialLinear" + type: 'radialLinear' }, elements: { line: { diff --git a/src/core/core.animation.js b/src/core/core.animation.js index 17c0f659782..7ccb3749322 100644 --- a/src/core/core.animation.js +++ b/src/core/core.animation.js @@ -1,5 +1,5 @@ -/*global window: false */ -"use strict"; +/* global window: false */ +'use strict'; module.exports = function(Chart) { @@ -7,7 +7,7 @@ module.exports = function(Chart) { Chart.defaults.global.animation = { duration: 1000, - easing: "easeOutQuart", + easing: 'easeOutQuart', onProgress: helpers.noop, onComplete: helpers.noop }; @@ -15,7 +15,7 @@ module.exports = function(Chart) { Chart.Animation = Chart.Element.extend({ currentStep: null, // the current animation step numSteps: 60, // default number of steps - easing: "", // the easing to use for this animation + easing: '', // the easing to use for this animation render: null, // render function used by the animation service onAnimationProgress: null, // user specified callback to fire on each step of the animation @@ -128,4 +128,4 @@ module.exports = function(Chart) { } } }; -}; \ No newline at end of file +}; diff --git a/src/core/core.canvasHelpers.js b/src/core/core.canvasHelpers.js index f8c35c96e64..439df7dba1b 100644 --- a/src/core/core.canvasHelpers.js +++ b/src/core/core.canvasHelpers.js @@ -1,4 +1,4 @@ -"use strict"; +'use strict'; module.exports = function(Chart) { // Global Chart canvas helpers object for drawing items to canvas @@ -40,7 +40,7 @@ module.exports = function(Chart) { case 'rect': size = 1 / Math.SQRT2 * radius; ctx.beginPath(); - ctx.fillRect(x - size, y - size, 2 * size, 2 * size); + ctx.fillRect(x - size, y - size, 2 * size, 2 * size); ctx.strokeRect(x - size, y - size, 2 * size, 2 * size); break; case 'rectRot': @@ -101,4 +101,4 @@ module.exports = function(Chart) { ctx.stroke(); }; -}; \ No newline at end of file +}; diff --git a/src/core/core.controller.js b/src/core/core.controller.js index dc99400763e..f996fa2b5ef 100644 --- a/src/core/core.controller.js +++ b/src/core/core.controller.js @@ -1,13 +1,13 @@ -"use strict"; +'use strict'; module.exports = function(Chart) { var helpers = Chart.helpers; - //Create a dictionary of chart types, to allow for extension of existing types + // Create a dictionary of chart types, to allow for extension of existing types Chart.types = {}; - //Store a reference to each instance - allowing us to globally resize chart instances on window resize. - //Destroy method on the chart will remove the instance of the chart from this reference. + // Store a reference to each instance - allowing us to globally resize chart instances on window resize. + // Destroy method on the chart will remove the instance of the chart from this reference. Chart.instances = {}; // Controllers available for dataset visualization eg. bar, line, slice, etc. @@ -30,7 +30,7 @@ module.exports = function(Chart) { } }); - //Add the chart instance to the global namespace + // Add the chart instance to the global namespace Chart.instances[this.id] = this; if (this.options.responsive) { @@ -99,7 +99,7 @@ module.exports = function(Chart) { helpers.retinaScale(chart); // Notify any plugins about the resize - var newSize = { width: newWidth, height: newHeight }; + var newSize = {width: newWidth, height: newHeight}; Chart.plugins.notify('resize', [me, newSize]); // Notify of resize @@ -145,13 +145,13 @@ module.exports = function(Chart) { if (options.scales) { items = items.concat( (options.scales.xAxes || []).map(function(xAxisOptions) { - return { options: xAxisOptions, dtype: 'category' }; }), + return {options: xAxisOptions, dtype: 'category'}; }), (options.scales.yAxes || []).map(function(yAxisOptions) { - return { options: yAxisOptions, dtype: 'linear' }; })); + return {options: yAxisOptions, dtype: 'linear'}; })); } if (options.scale) { - items.push({ options: options.scale, dtype: 'radialLinear', isDefault: true }); + items.push({options: options.scale, dtype: 'radialLinear', isDefault: true}); } helpers.each(items, function(item) { @@ -291,12 +291,12 @@ module.exports = function(Chart) { var me = this; var i, ilen; - if (Chart.plugins.notify('beforeDatasetsUpdate', [ me ])) { + if (Chart.plugins.notify('beforeDatasetsUpdate', [me])) { for (i = 0, ilen = me.data.datasets.length; i < ilen; ++i) { me.getDatasetMeta(i).controller.update(); } - Chart.plugins.notify('afterDatasetsUpdate', [ me ]); + Chart.plugins.notify('afterDatasetsUpdate', [me]); } }, @@ -307,7 +307,7 @@ module.exports = function(Chart) { var animationOptions = me.options.animation; if (animationOptions && ((typeof duration !== 'undefined' && duration !== 0) || (typeof duration === 'undefined' && animationOptions.duration !== 0))) { var animation = new Chart.Animation(); - animation.numSteps = (duration || animationOptions.duration) / 16.66; //60 fps + animation.numSteps = (duration || animationOptions.duration) / 16.66; // 60 fps animation.easing = animationOptions.easing; // render function @@ -392,7 +392,7 @@ module.exports = function(Chart) { var eventPosition = helpers.getRelativePosition(e, me.chart); var elementsArray = []; - var found = (function() { + var found = function() { if (me.data.datasets) { for (var i = 0; i < me.data.datasets.length; i++) { var meta = me.getDatasetMeta(i); @@ -405,7 +405,7 @@ module.exports = function(Chart) { } } } - }).call(me); + }.call(me); if (!found) { return elementsArray; @@ -415,7 +415,7 @@ module.exports = function(Chart) { if (me.isDatasetVisible(datasetIndex)) { var meta = me.getDatasetMeta(datasetIndex), element = meta.data[found._index]; - if(element && !element._view.skip){ + if(element && !element._view.skip) { elementsArray.push(element); } } @@ -429,7 +429,7 @@ module.exports = function(Chart) { var eventPosition = helpers.getRelativePosition(e, me.chart); var elementsArray = []; - var found = (function() { + var found = function() { if (me.data.datasets) { for (var i = 0; i < me.data.datasets.length; i++) { var meta = me.getDatasetMeta(i); @@ -442,7 +442,7 @@ module.exports = function(Chart) { } } } - }).call(me); + }.call(me); if (!found) { return elementsArray; @@ -451,7 +451,7 @@ module.exports = function(Chart) { helpers.each(me.data.datasets, function(dataset, datasetIndex) { if (me.isDatasetVisible(datasetIndex)) { var meta = me.getDatasetMeta(datasetIndex); - var index = helpers.findIndex(meta.data, function (it) { + var index = helpers.findIndex(meta.data, function(it) { return found._model.x === it._model.x; }); if(index !== -1 && !meta.data[index]._view.skip) { @@ -587,7 +587,7 @@ module.exports = function(Chart) { switch (mode) { case 'single': - elements = [ elements[0] ]; + elements = [elements[0]]; break; case 'label': case 'dataset': @@ -623,7 +623,7 @@ module.exports = function(Chart) { me.tooltipActive = []; } else { me.active = me.getElementsAtEventForMode(e, hoverOptions.mode); - me.tooltipActive = me.getElementsAtEventForMode(e, tooltipsOptions.mode); + me.tooltipActive = me.getElementsAtEventForMode(e, tooltipsOptions.mode); } // On Hover hook diff --git a/src/core/core.datasetController.js b/src/core/core.datasetController.js index bc140800d82..29b1aacea35 100644 --- a/src/core/core.datasetController.js +++ b/src/core/core.datasetController.js @@ -1,4 +1,4 @@ -"use strict"; +'use strict'; module.exports = function(Chart) { @@ -161,4 +161,4 @@ module.exports = function(Chart) { }); Chart.DatasetController.extend = helpers.inherits; -}; \ No newline at end of file +}; diff --git a/src/core/core.element.js b/src/core/core.element.js index e385074ae9c..14c6dbad2f2 100644 --- a/src/core/core.element.js +++ b/src/core/core.element.js @@ -1,4 +1,4 @@ -"use strict"; +'use strict'; module.exports = function(Chart) { diff --git a/src/core/core.helpers.js b/src/core/core.helpers.js index 2c69adcd561..9c021a78096 100644 --- a/src/core/core.helpers.js +++ b/src/core/core.helpers.js @@ -1,14 +1,14 @@ -/*global window: false */ -/*global document: false */ -"use strict"; +/* global window: false */ +/* global document: false */ +'use strict'; var color = require('chartjs-color'); module.exports = function(Chart) { - //Global Chart helpers object for utility methods and classes + // Global Chart helpers object for utility methods and classes var helpers = Chart.helpers = {}; - //-- Basic js utility methods + // -- Basic js utility methods helpers.each = function(loopable, callback, self, reverse) { // Check to see if null or undefined firstly. var i, len; @@ -83,7 +83,7 @@ module.exports = function(Chart) { } }); - } else if (base.hasOwnProperty(key) && typeof base[key] === "object" && base[key] !== null && typeof value === "object") { + } else if (base.hasOwnProperty(key) && typeof base[key] === 'object' && base[key] !== null && typeof value === 'object') { // If we are overwriting an object with an object, do a merge of the properties. base[key] = helpers.configMerge(base[key], value); @@ -123,7 +123,7 @@ module.exports = function(Chart) { base[key].push(helpers.configMerge(Chart.scaleService.getScaleDefaults(axisType), valueObj)); }); } - } else if (base.hasOwnProperty(key) && typeof base[key] === "object" && base[key] !== null && typeof value === "object") { + } else if (base.hasOwnProperty(key) && typeof base[key] === 'object' && base[key] !== null && typeof value === 'object') { // If we are overwriting an object with an object, do a merge of the properties. base[key] = helpers.configMerge(base[key], value); @@ -210,9 +210,9 @@ module.exports = function(Chart) { } }; helpers.inherits = function(extensions) { - //Basic javascript inheritance based on the model created in Backbone.js + // Basic javascript inheritance based on the model created in Backbone.js var parent = this; - var ChartElement = (extensions && extensions.hasOwnProperty("constructor")) ? extensions.constructor : function() { + var ChartElement = (extensions && extensions.hasOwnProperty('constructor')) ? extensions.constructor : function() { return parent.apply(this, arguments); }; @@ -239,7 +239,7 @@ module.exports = function(Chart) { return id++; }; }()); - //-- Math methods + // -- Math methods helpers.isNumber = function(n) { return !isNaN(parseFloat(n)) && isFinite(n); }; @@ -305,8 +305,8 @@ module.exports = function(Chart) { return (pixelWidth % 2 === 0) ? 0 : 0.5; }; helpers.splineCurve = function(firstPoint, middlePoint, afterPoint, t) { - //Props to Rob Spencer at scaled innovation for his post on splining between points - //http://scaledinnovation.com/analytics/splines/aboutSplines.html + // Props to Rob Spencer at scaled innovation for his post on splining between points + // http://scaledinnovation.com/analytics/splines/aboutSplines.html // This function must also respect "skipped" points @@ -402,7 +402,7 @@ module.exports = function(Chart) { tauK = 3 / Math.sqrt(squaredMagnitude); pointCurrent.mK = alphaK * tauK * pointCurrent.deltaK; - pointAfter.mK = betaK * tauK * pointCurrent.deltaK; + pointAfter.mK = betaK * tauK * pointCurrent.deltaK; } // Compute control points @@ -469,8 +469,8 @@ module.exports = function(Chart) { return niceFraction * Math.pow(10, exponent); }; - //Easing functions adapted from Robert Penner's easing equations - //http://www.robertpenner.com/easing/ + // Easing functions adapted from Robert Penner's easing equations + // http://www.robertpenner.com/easing/ var easingEffects = helpers.easingEffects = { linear: function(t) { return t; @@ -667,7 +667,7 @@ module.exports = function(Chart) { return easingEffects.easeOutBounce(t * 2 - 1) * 0.5 + 1 * 0.5; } }; - //Request animation polyfill - http://www.paulirish.com/2011/requestanimationframe-for-smart-animating/ + // Request animation polyfill - http://www.paulirish.com/2011/requestanimationframe-for-smart-animating/ helpers.requestAnimFrame = (function() { return window.requestAnimationFrame || window.webkitRequestAnimationFrame || @@ -688,7 +688,7 @@ module.exports = function(Chart) { return window.clearTimeout(callback, 1000 / 60); }; }()); - //-- DOM methods + // -- DOM methods helpers.getRelativePosition = function(evt, chart) { var mouseX, mouseY; var e = evt.originalEvent || evt, @@ -730,18 +730,18 @@ module.exports = function(Chart) { if (node.addEventListener) { node.addEventListener(eventType, method); } else if (node.attachEvent) { - node.attachEvent("on" + eventType, method); + node.attachEvent('on' + eventType, method); } else { - node["on" + eventType] = method; + node['on' + eventType] = method; } }; helpers.removeEvent = function(node, eventType, handler) { if (node.removeEventListener) { node.removeEventListener(eventType, handler, false); } else if (node.detachEvent) { - node.detachEvent("on" + eventType, handler); + node.detachEvent('on' + eventType, handler); } else { - node["on" + eventType] = helpers.noop; + node['on' + eventType] = helpers.noop; } }; helpers.bindEvents = function(chartInstance, arrayOfEvents, handler) { @@ -784,7 +784,7 @@ module.exports = function(Chart) { * @private */ function isConstrainedValue(value) { - return value !== undefined && value !== null && value !== 'none'; + return value !== undefined && value !== null && value !== 'none'; } // Private helper to get a constraint dimension @@ -859,12 +859,12 @@ module.exports = function(Chart) { canvas.style.width = width + 'px'; canvas.style.height = height + 'px'; }; - //-- Canvas methods + // -- Canvas methods helpers.clear = function(chart) { chart.ctx.clearRect(0, 0, chart.width, chart.height); }; helpers.fontString = function(pixelSize, fontStyle, fontFamily) { - return fontStyle + " " + pixelSize + "px " + fontFamily; + return fontStyle + ' ' + pixelSize + 'px ' + fontFamily; }; helpers.longestText = function(ctx, font, arrayOfThings, cache) { cache = cache || {}; @@ -904,7 +904,7 @@ module.exports = function(Chart) { } return longest; }; - helpers.measureText = function (ctx, data, gc, longest, string) { + helpers.measureText = function(ctx, data, gc, longest, string) { var textWidth = data[string]; if (!textWidth) { textWidth = data[string] = ctx.measureText(string).width; @@ -1000,7 +1000,7 @@ module.exports = function(Chart) { function(obj) { return Object.prototype.toString.call(obj) === '[object Array]'; }; - //! @see http://stackoverflow.com/a/14853974 + // ! @see http://stackoverflow.com/a/14853974 helpers.arrayEquals = function(a0, a1) { var i, ilen, v0, v1; diff --git a/src/core/core.js b/src/core/core.js index 9000dbd223c..c4f65e5cacd 100755 --- a/src/core/core.js +++ b/src/core/core.js @@ -1,12 +1,12 @@ -"use strict"; +'use strict'; module.exports = function() { - //Occupy the global variable of Chart, and create a simple base class + // Occupy the global variable of Chart, and create a simple base class var Chart = function(context, config) { var me = this; var helpers = Chart.helpers; - me.config = config || { + me.config = config || { data: { datasets: [] } @@ -19,7 +19,7 @@ module.exports = function() { // Support a canvas domnode if (context.getContext) { - context = context.getContext("2d"); + context = context.getContext('2d'); } me.ctx = context; @@ -62,13 +62,13 @@ module.exports = function() { }; - //Globally expose the defaults to allow for user updating/changing + // Globally expose the defaults to allow for user updating/changing Chart.defaults = { global: { responsive: true, responsiveAnimationDuration: 0, maintainAspectRatio: true, - events: ["mousemove", "mouseout", "click", "touchstart", "touchmove"], + events: ['mousemove', 'mouseout', 'click', 'touchstart', 'touchmove'], hover: { onHover: null, mode: 'single', @@ -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, @@ -98,7 +98,7 @@ module.exports = function() { } text.push(''); - return text.join(""); + return text.join(''); } } }; diff --git a/src/core/core.layoutService.js b/src/core/core.layoutService.js index 6e649b13a7d..324e93f5f0d 100644 --- a/src/core/core.layoutService.js +++ b/src/core/core.layoutService.js @@ -1,4 +1,4 @@ -"use strict"; +'use strict'; module.exports = function(Chart) { @@ -36,21 +36,21 @@ module.exports = function(Chart) { var yPadding = 0; var leftBoxes = helpers.where(chartInstance.boxes, function(box) { - return box.options.position === "left"; + return box.options.position === 'left'; }); var rightBoxes = helpers.where(chartInstance.boxes, function(box) { - return box.options.position === "right"; + return box.options.position === 'right'; }); var topBoxes = helpers.where(chartInstance.boxes, function(box) { - return box.options.position === "top"; + return box.options.position === 'top'; }); var bottomBoxes = helpers.where(chartInstance.boxes, function(box) { - return box.options.position === "bottom"; + return box.options.position === 'bottom'; }); // Boxes that overlay the chartarea such as the radialLinear scale var chartAreaBoxes = helpers.where(chartInstance.boxes, function(box) { - return box.options.position === "chartArea"; + return box.options.position === 'chartArea'; }); // Ensure that full width boxes are at the very top / bottom diff --git a/src/core/core.legend.js b/src/core/core.legend.js index 7691cab225c..7c78dc1cecb 100644 --- a/src/core/core.legend.js +++ b/src/core/core.legend.js @@ -1,4 +1,4 @@ -"use strict"; +'use strict'; module.exports = function(Chart) { @@ -151,7 +151,7 @@ module.exports = function(Chart) { buildLabels: function() { var me = this; me.legendItems = me.options.labels.generateLabels.call(me, me.chart); - if(me.options.reverse){ + if(me.options.reverse) { me.legendItems.reverse(); } }, @@ -200,7 +200,7 @@ module.exports = function(Chart) { var lineWidths = me.lineWidths = [0]; var totalHeight = me.legendItems.length ? fontSize + (labelOpts.padding) : 0; - ctx.textAlign = "left"; + ctx.textAlign = 'left'; ctx.textBaseline = 'top'; helpers.each(me.legendItems, function(legendItem, i) { @@ -277,7 +277,7 @@ module.exports = function(Chart) { // Shared Methods isHorizontal: function() { - return this.options.position === "top" || this.options.position === "bottom"; + return this.options.position === 'top' || this.options.position === 'bottom'; }, // Actualy draw the legend on the canvas @@ -301,7 +301,7 @@ module.exports = function(Chart) { labelFont = helpers.fontString(fontSize, fontStyle, fontFamily); // Canvas setup - ctx.textAlign = "left"; + ctx.textAlign = 'left'; ctx.textBaseline = 'top'; ctx.lineWidth = 0.5; ctx.strokeStyle = fontColor; // for strikethrough effect diff --git a/src/core/core.plugin.js b/src/core/core.plugin.js index d6f95c4d117..b675fbe3172 100644 --- a/src/core/core.plugin.js +++ b/src/core/core.plugin.js @@ -1,4 +1,4 @@ -"use strict"; +'use strict'; module.exports = function(Chart) { diff --git a/src/core/core.scale.js b/src/core/core.scale.js index 8faa49ef50f..7a5613c0ffe 100644 --- a/src/core/core.scale.js +++ b/src/core/core.scale.js @@ -1,4 +1,4 @@ -"use strict"; +'use strict'; module.exports = function(Chart) { @@ -6,19 +6,19 @@ module.exports = function(Chart) { Chart.defaults.scale = { display: true, - position: "left", + position: 'left', // grid line settings gridLines: { display: true, - color: "rgba(0, 0, 0, 0.1)", + color: 'rgba(0, 0, 0, 0.1)', lineWidth: 1, drawBorder: true, drawOnChartArea: true, drawTicks: true, tickMarkLength: 10, zeroLineWidth: 1, - zeroLineColor: "rgba(0,0,0,0.25)", + zeroLineColor: 'rgba(0,0,0,0.25)', offsetGridLines: false, borderDash: [], borderDashOffset: 0.0 @@ -192,8 +192,8 @@ module.exports = function(Chart) { var globalDefaults = Chart.defaults.global; var optionTicks = me.options.ticks; - //Get the width of each grid by calculating the difference - //between x offsets between 0 and 1. + // Get the width of each grid by calculating the difference + // between x offsets between 0 and 1. var tickFontSize = helpers.getValueOrDefault(optionTicks.fontSize, globalDefaults.defaultFontSize); var tickFontStyle = helpers.getValueOrDefault(optionTicks.fontStyle, globalDefaults.defaultFontStyle); var tickFontFamily = helpers.getValueOrDefault(optionTicks.fontFamily, globalDefaults.defaultFontFamily); @@ -225,7 +225,7 @@ module.exports = function(Chart) { // only the index matters for a dataset scale, but we want a consistent interface between scales var tickWidth = me.getPixelForTick(1) - me.getPixelForTick(0) - 6; - //Max label rotation can be set or default to 90 - also act as a loop counter + // Max label rotation can be set or default to 90 - also act as a loop counter while (labelWidth > tickWidth && me.labelRotation < optionTicks.maxRotation) { cosRotation = Math.cos(helpers.toRadians(me.labelRotation)); sinRotation = Math.sin(helpers.toRadians(me.labelRotation)); @@ -386,7 +386,7 @@ module.exports = function(Chart) { // Shared Methods isHorizontal: function() { - return this.options.position === "top" || this.options.position === "bottom"; + return this.options.position === 'top' || this.options.position === 'bottom'; }, isFullWidth: function() { return (this.options.fullWidth); @@ -403,7 +403,7 @@ module.exports = function(Chart) { return NaN; } // If it is in fact an object, dive in one more level - if (typeof(rawValue) === "object") { + if (typeof(rawValue) === 'object') { if ((rawValue instanceof Date) || (rawValue.isValid)) { return rawValue; } else { @@ -447,7 +447,7 @@ module.exports = function(Chart) { }, // Utility for getting the pixel location of a percentage of scale - getPixelForDecimal: function(decimal /*, includeOffset*/ ) { + getPixelForDecimal: function(decimal /* , includeOffset*/) { var me = this; if (me.isHorizontal()) { var innerWidth = me.width - (me.paddingLeft + me.paddingRight); @@ -553,10 +553,10 @@ module.exports = function(Chart) { } - var xTickStart = options.position === "right" ? me.left : me.right - tl; - var xTickEnd = options.position === "right" ? me.left + tl : me.right; - var yTickStart = options.position === "bottom" ? me.top : me.bottom - tl; - var yTickEnd = options.position === "bottom" ? me.top + tl : me.bottom; + var xTickStart = options.position === 'right' ? me.left : me.right - tl; + var xTickEnd = options.position === 'right' ? me.left + tl : me.right; + var yTickStart = options.position === 'bottom' ? me.top : me.bottom - tl; + var yTickEnd = options.position === 'bottom' ? me.top + tl : me.bottom; helpers.each(me.ticks, function(label, index) { // If the callback returned a null or undefined value, do not draw this line @@ -577,7 +577,7 @@ module.exports = function(Chart) { // Draw the first index specially lineWidth = gridLines.zeroLineWidth; lineColor = gridLines.zeroLineColor; - } else { + } else { lineWidth = helpers.getValueAtIndexOrDefault(gridLines.lineWidth, index); lineColor = helpers.getValueAtIndexOrDefault(gridLines.color, index); } diff --git a/src/core/core.scaleService.js b/src/core/core.scaleService.js index 7c351e5d289..81a95079053 100644 --- a/src/core/core.scaleService.js +++ b/src/core/core.scaleService.js @@ -1,4 +1,4 @@ -"use strict"; +'use strict'; module.exports = function(Chart) { @@ -37,4 +37,4 @@ module.exports = function(Chart) { }); } }; -}; \ No newline at end of file +}; diff --git a/src/core/core.title.js b/src/core/core.title.js index 25abad2a743..0a8c1a5aa54 100644 --- a/src/core/core.title.js +++ b/src/core/core.title.js @@ -1,4 +1,4 @@ -"use strict"; +'use strict'; module.exports = function(Chart) { @@ -30,7 +30,7 @@ module.exports = function(Chart) { // These methods are ordered by lifecyle. Utilities then follow. - beforeUpdate: function () { + beforeUpdate: function() { var chartOpts = this.chart.options; if (chartOpts && chartOpts.title) { this.options = helpers.configMerge(Chart.defaults.global.title, chartOpts.title); @@ -136,7 +136,7 @@ module.exports = function(Chart) { // Shared Methods isHorizontal: function() { var pos = this.options.position; - return pos === "top" || pos === "bottom"; + return pos === 'top' || pos === 'bottom'; }, // Actualy draw the title block on the canvas diff --git a/src/core/core.tooltip.js b/src/core/core.tooltip.js index 8da2fa44e43..e59b26a2d74 100755 --- a/src/core/core.tooltip.js +++ b/src/core/core.tooltip.js @@ -1,4 +1,4 @@ -"use strict"; +'use strict'; module.exports = function(Chart) { @@ -8,24 +8,24 @@ module.exports = function(Chart) { enabled: true, custom: null, mode: 'single', - backgroundColor: "rgba(0,0,0,0.8)", - titleFontStyle: "bold", + backgroundColor: 'rgba(0,0,0,0.8)', + titleFontStyle: 'bold', titleSpacing: 2, titleMarginBottom: 6, - titleFontColor: "#fff", - titleAlign: "left", + titleFontColor: '#fff', + titleAlign: 'left', bodySpacing: 2, - bodyFontColor: "#fff", - bodyAlign: "left", - footerFontStyle: "bold", + bodyFontColor: '#fff', + bodyAlign: 'left', + footerFontStyle: 'bold', footerSpacing: 2, footerMarginTop: 6, - footerFontColor: "#fff", - footerAlign: "left", + footerFontColor: '#fff', + footerAlign: 'left', yPadding: 6, xPadding: 6, - yAlign : 'center', - xAlign : 'center', + yAlign: 'center', + xAlign: 'center', caretSize: 5, cornerRadius: 6, multiKeyBackground: '#fff', @@ -86,7 +86,7 @@ module.exports = function(Chart) { function pushOrConcat(base, toPush) { if (toPush) { if (helpers.isArray(toPush)) { - //base = base.concat(toPush); + // base = base.concat(toPush); Array.prototype.push.apply(base, toPush); } else { base.push(toPush); @@ -107,7 +107,7 @@ module.exports = function(Chart) { for (i = 0, len = elements.length; i < len; ++i) { var el = elements[i]; - if (el && el.hasValue()){ + if (el && el.hasValue()) { var pos = el.tooltipPosition(); xPositions.push(pos.x); yPositions.push(pos.y); @@ -117,7 +117,7 @@ module.exports = function(Chart) { var x = 0, y = 0; for (i = 0; i < xPositions.length; ++i) { - if (xPositions[ i ]) { + if (xPositions[i]) { x += xPositions[i]; y += yPositions[i]; } @@ -158,8 +158,8 @@ module.exports = function(Chart) { // Positioning xPadding: tooltipOpts.xPadding, yPadding: tooltipOpts.yPadding, - xAlign : tooltipOpts.xAlign, - yAlign : tooltipOpts.yAlign, + xAlign: tooltipOpts.xAlign, + yAlign: tooltipOpts.yAlign, // Body bodyFontColor: tooltipOpts.bodyFontColor, @@ -292,8 +292,8 @@ module.exports = function(Chart) { // If the user provided a sorting function, use it to modify the tooltip items if (opts.itemSort) { - tooltipItems = tooltipItems.sort(function(a,b) { - return opts.itemSort(a,b, data); + tooltipItems = tooltipItems.sort(function(a, b) { + return opts.itemSort(a, b, data); }); } @@ -571,7 +571,7 @@ module.exports = function(Chart) { if (title.length) { ctx.textAlign = vm._titleAlign; - ctx.textBaseline = "top"; + ctx.textBaseline = 'top'; var titleFontSize = vm.titleFontSize, titleSpacing = vm.titleSpacing; @@ -597,7 +597,7 @@ module.exports = function(Chart) { var body = vm.body; ctx.textAlign = vm._bodyAlign; - ctx.textBaseline = "top"; + ctx.textBaseline = 'top'; var bodyFontColor = helpers.color(vm.bodyFontColor); var textColor = bodyFontColor.alpha(opacity * bodyFontColor.alpha()).rgbString(); @@ -659,7 +659,7 @@ module.exports = function(Chart) { pt.y += vm.footerMarginTop; ctx.textAlign = vm._footerAlign; - ctx.textBaseline = "top"; + ctx.textBaseline = 'top'; var footerFontColor = helpers.color(vm.footerFontColor); ctx.fillStyle = footerFontColor.alpha(opacity * footerFontColor.alpha()).rgbString(); diff --git a/src/elements/element.arc.js b/src/elements/element.arc.js index 64d96048365..6056e847762 100644 --- a/src/elements/element.arc.js +++ b/src/elements/element.arc.js @@ -1,4 +1,4 @@ -"use strict"; +'use strict'; module.exports = function(Chart) { @@ -7,7 +7,7 @@ module.exports = function(Chart) { globalOpts.elements.arc = { backgroundColor: globalOpts.defaultColor, - borderColor: "#fff", + borderColor: '#fff', borderWidth: 2 }; @@ -32,7 +32,7 @@ module.exports = function(Chart) { angle = pointRelativePosition.angle, distance = pointRelativePosition.distance; - //Sanitise angle range + // Sanitise angle range var startAngle = vm.startAngle; var endAngle = vm.endAngle; while (endAngle < startAngle) { @@ -45,7 +45,7 @@ module.exports = function(Chart) { angle += 2.0 * Math.PI; } - //Check if within the range of the open/close angle + // Check if within the range of the open/close angle var betweenAngles = (angle >= startAngle && angle <= endAngle), withinRadius = (distance >= vm.innerRadius && distance <= vm.outerRadius); diff --git a/src/elements/element.line.js b/src/elements/element.line.js index 2267fef6753..6ce178fbd6e 100644 --- a/src/elements/element.line.js +++ b/src/elements/element.line.js @@ -1,4 +1,4 @@ -"use strict"; +'use strict'; module.exports = function(Chart) { @@ -34,7 +34,7 @@ module.exports = function(Chart) { var vm = point._view; if (point._view.steppedLine === true) { ctx.lineTo(point._view.x, previousPoint._view.y); - ctx.lineTo(point._view.x, point._view.y); + ctx.lineTo(point._view.x, point._view.y); } else if (point._view.tension === 0) { ctx.lineTo(vm.x, vm.y); } else { @@ -94,7 +94,7 @@ module.exports = function(Chart) { } } else { if (lastDrawnIndex !== (index - 1)) { - // There was a gap and this is the first point after the gap. If we've never drawn a point, this is a special case. + // There was a gap and this is the first point after the gap. If we've never drawn a point, this is a special case. // If the first data point is NaN, then there is no real gap to skip if (spanGaps && lastDrawnIndex !== -1) { // We are spanning the gap, so simple draw a line to this point @@ -174,4 +174,4 @@ module.exports = function(Chart) { ctx.restore(); } }); -}; \ No newline at end of file +}; diff --git a/src/elements/element.point.js b/src/elements/element.point.js index 4131f8ceded..474ef252f53 100644 --- a/src/elements/element.point.js +++ b/src/elements/element.point.js @@ -1,4 +1,4 @@ -"use strict"; +'use strict'; module.exports = function(Chart) { diff --git a/src/elements/element.rectangle.js b/src/elements/element.rectangle.js index dd252a76cf6..6752228c870 100644 --- a/src/elements/element.rectangle.js +++ b/src/elements/element.rectangle.js @@ -1,4 +1,4 @@ -"use strict"; +'use strict'; module.exports = function(Chart) { @@ -92,4 +92,4 @@ module.exports = function(Chart) { } }); -}; \ No newline at end of file +}; diff --git a/src/scales/scale.category.js b/src/scales/scale.category.js index 6d9c33b646d..4979f193e5b 100644 --- a/src/scales/scale.category.js +++ b/src/scales/scale.category.js @@ -1,11 +1,11 @@ -"use strict"; +'use strict'; module.exports = function(Chart) { var helpers = Chart.helpers; // Default config for a category scale var defaultConfig = { - position: "bottom" + position: 'bottom' }; var DatasetScale = Chart.Scale.extend({ @@ -126,6 +126,6 @@ module.exports = function(Chart) { } }); - Chart.scaleService.registerScaleType("category", DatasetScale, defaultConfig); + Chart.scaleService.registerScaleType('category', DatasetScale, defaultConfig); -}; \ No newline at end of file +}; diff --git a/src/scales/scale.linear.js b/src/scales/scale.linear.js index 2c19f71a7b7..33a3e4930db 100644 --- a/src/scales/scale.linear.js +++ b/src/scales/scale.linear.js @@ -1,11 +1,11 @@ -"use strict"; +'use strict'; module.exports = function(Chart) { var helpers = Chart.helpers; var defaultConfig = { - position: "left", + position: 'left', ticks: { callback: function(tickValue, index, ticks) { // If we have lots of ticks, don't use the ones @@ -194,6 +194,6 @@ module.exports = function(Chart) { return this.getPixelForValue(this.ticksAsNumbers[index]); } }); - Chart.scaleService.registerScaleType("linear", LinearScale, defaultConfig); + Chart.scaleService.registerScaleType('linear', LinearScale, defaultConfig); -}; \ No newline at end of file +}; diff --git a/src/scales/scale.linearbase.js b/src/scales/scale.linearbase.js index e9e8cefa6da..37caa035933 100644 --- a/src/scales/scale.linearbase.js +++ b/src/scales/scale.linearbase.js @@ -1,4 +1,4 @@ -"use strict"; +'use strict'; module.exports = function(Chart) { @@ -122,4 +122,4 @@ module.exports = function(Chart) { Chart.Scale.prototype.convertTicksToLabels.call(me); } }); -}; \ No newline at end of file +}; diff --git a/src/scales/scale.logarithmic.js b/src/scales/scale.logarithmic.js index fe3e44c4f18..2535deaa69e 100644 --- a/src/scales/scale.logarithmic.js +++ b/src/scales/scale.logarithmic.js @@ -1,18 +1,18 @@ -"use strict"; +'use strict'; module.exports = function(Chart) { var helpers = Chart.helpers; var defaultConfig = { - position: "left", + position: 'left', // label settings ticks: { callback: function(value, index, arr) { var remain = value / (Math.pow(10, Math.floor(helpers.log10(value)))); - if (value === 0){ + if (value === 0) { return '0'; } else if (remain === 1 || remain === 2 || remain === 5 || index === 0 || index === arr.length - 1) { return value.toExponential(); @@ -144,7 +144,7 @@ module.exports = function(Chart) { var exp; var significand; - if(tickVal === 0){ + if(tickVal === 0) { exp = Math.floor(helpers.log10(me.minNotZero)); significand = Math.round(me.minNotZero / Math.pow(10, exp)); } else { @@ -221,20 +221,20 @@ module.exports = function(Chart) { } else { // Bottom - top since pixels increase downard on a screen innerDimension = me.height - (paddingTop + paddingBottom); - if(start === 0 && !tickOpts.reverse){ + if(start === 0 && !tickOpts.reverse) { range = helpers.log10(me.end) - helpers.log10(me.minNotZero); if (newVal === start) { pixel = me.bottom - paddingBottom; - } else if(newVal === me.minNotZero){ + } else if(newVal === me.minNotZero) { pixel = me.bottom - paddingBottom - innerDimension * 0.02; } else { pixel = me.bottom - paddingBottom - innerDimension * 0.02 - (innerDimension * 0.98/ range * (helpers.log10(newVal)-helpers.log10(me.minNotZero))); } - } else if (me.end === 0 && tickOpts.reverse){ + } else if (me.end === 0 && tickOpts.reverse) { range = helpers.log10(me.start) - helpers.log10(me.minNotZero); if (newVal === me.end) { pixel = me.top + paddingTop; - } else if(newVal === me.minNotZero){ + } else if(newVal === me.minNotZero) { pixel = me.top + paddingTop + innerDimension * 0.02; } else { pixel = me.top + paddingTop + innerDimension * 0.02 + (innerDimension * 0.98/ range * (helpers.log10(newVal)-helpers.log10(me.minNotZero))); @@ -262,6 +262,6 @@ module.exports = function(Chart) { return value; } }); - Chart.scaleService.registerScaleType("logarithmic", LogarithmicScale, defaultConfig); + Chart.scaleService.registerScaleType('logarithmic', LogarithmicScale, defaultConfig); -}; \ No newline at end of file +}; diff --git a/src/scales/scale.radialLinear.js b/src/scales/scale.radialLinear.js index d0cb7f2c6d0..d6eef1c0429 100644 --- a/src/scales/scale.radialLinear.js +++ b/src/scales/scale.radialLinear.js @@ -1,4 +1,4 @@ -"use strict"; +'use strict'; module.exports = function(Chart) { @@ -8,37 +8,37 @@ module.exports = function(Chart) { var defaultConfig = { display: true, - //Boolean - Whether to animate scaling the chart from the centre + // Boolean - Whether to animate scaling the chart from the centre animate: true, lineArc: false, - position: "chartArea", + position: 'chartArea', angleLines: { display: true, - color: "rgba(0, 0, 0, 0.1)", + color: 'rgba(0, 0, 0, 0.1)', lineWidth: 1 }, // label settings ticks: { - //Boolean - Show a backdrop to the scale label + // Boolean - Show a backdrop to the scale label showLabelBackdrop: true, - //String - The colour of the label backdrop - backdropColor: "rgba(255,255,255,0.75)", + // String - The colour of the label backdrop + backdropColor: 'rgba(255,255,255,0.75)', - //Number - The backdrop padding above & below the label in pixels + // Number - The backdrop padding above & below the label in pixels backdropPaddingY: 2, - //Number - The backdrop padding to the side of the label in pixels + // Number - The backdrop padding to the side of the label in pixels backdropPaddingX: 2 }, pointLabels: { - //Number - Point label font size in pixels + // Number - Point label font size in pixels fontSize: 10, - //Function - Used to convert point labels + // Function - Used to convert point labels callback: function(label) { return label; } @@ -347,7 +347,7 @@ module.exports = function(Chart) { } ctx.textAlign = 'center'; - ctx.textBaseline = "middle"; + ctx.textBaseline = 'middle'; ctx.fillStyle = tickFontColor; ctx.fillText(label, me.xCenter, yHeight); } @@ -412,6 +412,6 @@ module.exports = function(Chart) { } } }); - Chart.scaleService.registerScaleType("radialLinear", LinearRadialScale, defaultConfig); + Chart.scaleService.registerScaleType('radialLinear', LinearRadialScale, defaultConfig); }; diff --git a/src/scales/scale.time.js b/src/scales/scale.time.js index 23435aa13ee..7895dd490c5 100755 --- a/src/scales/scale.time.js +++ b/src/scales/scale.time.js @@ -1,5 +1,5 @@ -/*global window: false */ -"use strict"; +/* global window: false */ +'use strict'; var moment = require('moment'); moment = typeof(moment) === 'function' ? moment : window.moment; @@ -39,7 +39,7 @@ module.exports = function(Chart) { }; var defaultConfig = { - position: "bottom", + position: 'bottom', time: { parser: false, // false == a pattern string from http://momentjs.com/docs/#/parsing/string-format/ or a custom callback that converts its argument to a moment @@ -451,13 +451,13 @@ module.exports = function(Chart) { } // Custom parsing (return an instance of moment) if (typeof me.options.time.format !== 'string' && me.options.time.format.call) { - console.warn("options.time.format is deprecated and replaced by options.time.parser. See http://nnnick.github.io/Chart.js/docs-v2/#scales-time-scale"); + console.warn('options.time.format is deprecated and replaced by options.time.parser. See http://nnnick.github.io/Chart.js/docs-v2/#scales-time-scale'); return me.options.time.format(label); } // Moment format parsing return moment(label, me.options.time.format); } }); - Chart.scaleService.registerScaleType("time", TimeScale, defaultConfig); + Chart.scaleService.registerScaleType('time', TimeScale, defaultConfig); }; From 11739234a4b218d65a008c1afcb72c8ee42556a9 Mon Sep 17 00:00:00 2001 From: Zach Panzarino Date: Wed, 14 Sep 2016 18:12:23 +0000 Subject: [PATCH 3/9] Add keyword spacing to eslint and update code --- .eslintrc | 2 ++ src/core/core.controller.js | 4 ++-- src/core/core.legend.js | 2 +- src/scales/scale.logarithmic.js | 10 +++++----- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/.eslintrc b/.eslintrc index 4ba4ba5a098..38916dfb02e 100644 --- a/.eslintrc +++ b/.eslintrc @@ -136,6 +136,7 @@ rules: computed-property-spacing: [2, never] consistent-this: [2, me] eol-last: 2 + func-call-spacing: [2, never] func-names: [2, never] func-style: 0 id-length: 0 @@ -143,6 +144,7 @@ rules: indent: [2, tab] jsx-quotes: 0 key-spacing: 2 + keyword-spacing: 2 linebreak-style: [2, unix] lines-around-comment: 0 max-depth: 0 diff --git a/src/core/core.controller.js b/src/core/core.controller.js index f996fa2b5ef..0f74bcad6bf 100644 --- a/src/core/core.controller.js +++ b/src/core/core.controller.js @@ -415,7 +415,7 @@ module.exports = function(Chart) { if (me.isDatasetVisible(datasetIndex)) { var meta = me.getDatasetMeta(datasetIndex), element = meta.data[found._index]; - if(element && !element._view.skip) { + if (element && !element._view.skip) { elementsArray.push(element); } } @@ -454,7 +454,7 @@ module.exports = function(Chart) { var index = helpers.findIndex(meta.data, function(it) { return found._model.x === it._model.x; }); - if(index !== -1 && !meta.data[index]._view.skip) { + if (index !== -1 && !meta.data[index]._view.skip) { elementsArray.push(meta.data[index]); } } diff --git a/src/core/core.legend.js b/src/core/core.legend.js index 7c78dc1cecb..369b549fa62 100644 --- a/src/core/core.legend.js +++ b/src/core/core.legend.js @@ -151,7 +151,7 @@ module.exports = function(Chart) { buildLabels: function() { var me = this; me.legendItems = me.options.labels.generateLabels.call(me, me.chart); - if(me.options.reverse) { + if (me.options.reverse) { me.legendItems.reverse(); } }, diff --git a/src/scales/scale.logarithmic.js b/src/scales/scale.logarithmic.js index 2535deaa69e..2d4f323fdd9 100644 --- a/src/scales/scale.logarithmic.js +++ b/src/scales/scale.logarithmic.js @@ -100,7 +100,7 @@ module.exports = function(Chart) { me.max = value; } - if(value !== 0 && (me.minNotZero === null || value < me.minNotZero)) { + if (value !== 0 && (me.minNotZero === null || value < me.minNotZero)) { me.minNotZero = value; } }); @@ -144,7 +144,7 @@ module.exports = function(Chart) { var exp; var significand; - if(tickVal === 0) { + if (tickVal === 0) { exp = Math.floor(helpers.log10(me.minNotZero)); significand = Math.round(me.minNotZero / Math.pow(10, exp)); } else { @@ -221,11 +221,11 @@ module.exports = function(Chart) { } else { // Bottom - top since pixels increase downard on a screen innerDimension = me.height - (paddingTop + paddingBottom); - if(start === 0 && !tickOpts.reverse) { + if (start === 0 && !tickOpts.reverse) { range = helpers.log10(me.end) - helpers.log10(me.minNotZero); if (newVal === start) { pixel = me.bottom - paddingBottom; - } else if(newVal === me.minNotZero) { + } else if (newVal === me.minNotZero) { pixel = me.bottom - paddingBottom - innerDimension * 0.02; } else { pixel = me.bottom - paddingBottom - innerDimension * 0.02 - (innerDimension * 0.98/ range * (helpers.log10(newVal)-helpers.log10(me.minNotZero))); @@ -234,7 +234,7 @@ module.exports = function(Chart) { range = helpers.log10(me.start) - helpers.log10(me.minNotZero); if (newVal === me.end) { pixel = me.top + paddingTop; - } else if(newVal === me.minNotZero) { + } else if (newVal === me.minNotZero) { pixel = me.top + paddingTop + innerDimension * 0.02; } else { pixel = me.top + paddingTop + innerDimension * 0.02 + (innerDimension * 0.98/ range * (helpers.log10(newVal)-helpers.log10(me.minNotZero))); From 9bf2e2bf7a339f59539fa784f67bdaf4c705d416 Mon Sep 17 00:00:00 2001 From: Zach Panzarino Date: Wed, 14 Sep 2016 18:16:21 +0000 Subject: [PATCH 4/9] Remove func-call-spacing rule --- .eslintrc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.eslintrc b/.eslintrc index 38916dfb02e..827b73c3777 100644 --- a/.eslintrc +++ b/.eslintrc @@ -136,7 +136,7 @@ rules: computed-property-spacing: [2, never] consistent-this: [2, me] eol-last: 2 - func-call-spacing: [2, never] + func-call-spacing: 0 func-names: [2, never] func-style: 0 id-length: 0 From dd8fa78b453dd71f88934f0b561e2d613be6a1ab Mon Sep 17 00:00:00 2001 From: Zach Panzarino Date: Wed, 14 Sep 2016 22:34:41 +0000 Subject: [PATCH 5/9] Fix more style errors in controllers, elements, and scales --- .eslintrc | 2 +- src/controllers/controller.bar.js | 10 +++----- src/controllers/controller.doughnut.js | 6 ++--- src/controllers/controller.line.js | 3 +-- src/controllers/controller.polarArea.js | 6 ++--- src/core/core.controller.js | 17 +++++++------ src/core/core.element.js | 18 ++++---------- src/elements/element.arc.js | 6 ++--- src/elements/element.line.js | 26 +++++++++---------- src/scales/scale.time.js | 33 +++++++++++-------------- 10 files changed, 54 insertions(+), 73 deletions(-) diff --git a/.eslintrc b/.eslintrc index 827b73c3777..340d657baf5 100644 --- a/.eslintrc +++ b/.eslintrc @@ -96,7 +96,7 @@ rules: radix: 2 vars-on-top: 0 wrap-iife: 2 - yoda: [2, never] + yoda: [1, never] # Strict strict: 0 diff --git a/src/controllers/controller.bar.js b/src/controllers/controller.bar.js index 73ed2df2a0d..d9fa7bfeb05 100644 --- a/src/controllers/controller.bar.js +++ b/src/controllers/controller.bar.js @@ -232,9 +232,8 @@ module.exports = function(Chart) { if (value < 0) { return yScale.getPixelForValue(sumNeg + value); - } else { - return yScale.getPixelForValue(sumPos + value); } + return yScale.getPixelForValue(sumPos + value); } return yScale.getPixelForValue(value); @@ -409,8 +408,8 @@ module.exports = function(Chart) { startCorner = 0; } - function cornerAt(index) { - return corners[(startCorner + index) % 4]; + function cornerAt(cornerIndex) { + return corners[(startCorner + cornerIndex) % 4]; } // Draw rectangle from 'startCorner' @@ -542,9 +541,8 @@ module.exports = function(Chart) { if (value < 0) { return xScale.getPixelForValue(sumNeg + value); - } else { - return xScale.getPixelForValue(sumPos + value); } + return xScale.getPixelForValue(sumPos + value); } return xScale.getPixelForValue(value); diff --git a/src/controllers/controller.doughnut.js b/src/controllers/controller.doughnut.js index 40d4e2c842d..0e9c5fe802c 100644 --- a/src/controllers/controller.doughnut.js +++ b/src/controllers/controller.doughnut.js @@ -64,9 +64,8 @@ module.exports = function(Chart) { index: i }; }); - } else { - return []; } + return []; } }, @@ -264,9 +263,8 @@ module.exports = function(Chart) { var total = this.getMeta().total; if (total > 0 && !isNaN(value)) { return (Math.PI * 2.0) * (value / total); - } else { - return 0; } + return 0; }, // gets the max border or hover width to properly scale pie charts diff --git a/src/controllers/controller.line.js b/src/controllers/controller.line.js index a516a1e368e..bfc061af22b 100644 --- a/src/controllers/controller.line.js +++ b/src/controllers/controller.line.js @@ -238,9 +238,8 @@ module.exports = function(Chart) { var rightValue = Number(yScale.getRightValue(value)); if (rightValue < 0) { return yScale.getPixelForValue(sumNeg + rightValue); - } else { - return yScale.getPixelForValue(sumPos + rightValue); } + return yScale.getPixelForValue(sumPos + rightValue); } return yScale.getPixelForValue(value); diff --git a/src/controllers/controller.polarArea.js b/src/controllers/controller.polarArea.js index 6a11b4599ac..b27daf4170d 100644 --- a/src/controllers/controller.polarArea.js +++ b/src/controllers/controller.polarArea.js @@ -70,9 +70,8 @@ module.exports = function(Chart) { index: i }; }); - } else { - return []; } + return []; } }, @@ -209,9 +208,8 @@ module.exports = function(Chart) { var count = this.getMeta().count; if (count > 0 && !isNaN(value)) { return (2 * Math.PI) / count; - } else { - return 0; } + return 0; } }); }; diff --git a/src/core/core.controller.js b/src/core/core.controller.js index 0f74bcad6bf..30ba1341888 100644 --- a/src/core/core.controller.js +++ b/src/core/core.controller.js @@ -79,7 +79,7 @@ module.exports = function(Chart) { return this; }, - resize: function resize(silent) { + resize: function(silent) { var me = this; var chart = me.chart; var canvas = chart.canvas; @@ -145,9 +145,12 @@ module.exports = function(Chart) { if (options.scales) { items = items.concat( (options.scales.xAxes || []).map(function(xAxisOptions) { - return {options: xAxisOptions, dtype: 'category'}; }), + return {options: xAxisOptions, dtype: 'category'}; + }), (options.scales.yAxes || []).map(function(yAxisOptions) { - return {options: yAxisOptions, dtype: 'linear'}; })); + return {options: yAxisOptions, dtype: 'linear'}; + }) + ); } if (options.scale) { @@ -226,7 +229,7 @@ module.exports = function(Chart) { }, me); }, - update: function update(animationDuration, lazy) { + update: function(animationDuration, lazy) { var me = this; Chart.plugins.notify('beforeUpdate', [me]); @@ -300,7 +303,7 @@ module.exports = function(Chart) { } }, - render: function render(duration, lazy) { + render: function(duration, lazy) { var me = this; Chart.plugins.notify('beforeRender', [me]); @@ -515,7 +518,7 @@ module.exports = function(Chart) { getVisibleDatasetCount: function() { var count = 0; for (var i = 0, ilen = this.data.datasets.length; i= vm.innerRadius && distance <= vm.outerRadius); return (betweenAngles && withinRadius); - } else { - return false; } + return false; }, tooltipPosition: function() { var vm = this._view; diff --git a/src/elements/element.line.js b/src/elements/element.line.js index 6ce178fbd6e..9981d3d2f63 100644 --- a/src/elements/element.line.js +++ b/src/elements/element.line.js @@ -31,20 +31,20 @@ module.exports = function(Chart) { // Helper function to draw a line to a point function lineToPoint(previousPoint, point) { - var vm = point._view; + var pointvm = point._view; if (point._view.steppedLine === true) { - ctx.lineTo(point._view.x, previousPoint._view.y); - ctx.lineTo(point._view.x, point._view.y); + ctx.lineTo(pointvm.x, previousPoint._view.y); + ctx.lineTo(pointvm.x, pointvm.y); } else if (point._view.tension === 0) { - ctx.lineTo(vm.x, vm.y); + ctx.lineTo(pointvm.x, pointvm.y); } else { ctx.bezierCurveTo( previousPoint._view.controlPointNextX, previousPoint._view.controlPointNextY, - vm.controlPointPreviousX, - vm.controlPointPreviousY, - vm.x, - vm.y + pointvm.controlPointPreviousX, + pointvm.controlPointPreviousY, + pointvm.x, + pointvm.y ); } } @@ -99,13 +99,11 @@ module.exports = function(Chart) { if (spanGaps && lastDrawnIndex !== -1) { // We are spanning the gap, so simple draw a line to this point lineToPoint(previous, current); + } else if (loop) { + ctx.lineTo(currentVM.x, currentVM.y); } else { - if (loop) { - ctx.lineTo(currentVM.x, currentVM.y); - } else { - ctx.lineTo(currentVM.x, scaleZero); - ctx.lineTo(currentVM.x, currentVM.y); - } + ctx.lineTo(currentVM.x, scaleZero); + ctx.lineTo(currentVM.x, currentVM.y); } } else { // Line to next point diff --git a/src/scales/scale.time.js b/src/scales/scale.time.js index 7895dd490c5..5a5638cef70 100755 --- a/src/scales/scale.time.js +++ b/src/scales/scale.time.js @@ -52,15 +52,15 @@ module.exports = function(Chart) { // defaults to unit's corresponding unitFormat below or override using pattern string from http://momentjs.com/docs/#/displaying/format/ displayFormats: { - 'millisecond': 'h:mm:ss.SSS a', // 11:20:01.123 AM, - 'second': 'h:mm:ss a', // 11:20:01 AM - 'minute': 'h:mm:ss a', // 11:20:01 AM - 'hour': 'MMM D, hA', // Sept 4, 5PM - 'day': 'll', // Sep 4 2015 - 'week': 'll', // Week 46, or maybe "[W]WW - YYYY" ? - 'month': 'MMM YYYY', // Sept 2015 - 'quarter': '[Q]Q - YYYY', // Q3 - 'year': 'YYYY' // 2015 + millisecond: 'h:mm:ss.SSS a', // 11:20:01.123 AM, + second: 'h:mm:ss a', // 11:20:01 AM + minute: 'h:mm:ss a', // 11:20:01 AM + hour: 'MMM D, hA', // Sept 4, 5PM + day: 'll', // Sep 4 2015 + week: 'll', // Week 46, or maybe "[W]WW - YYYY" ? + month: 'MMM YYYY', // Sept 2015 + quarter: '[Q]Q - YYYY', // Q3 + year: 'YYYY' // 2015 } }, ticks: { @@ -107,9 +107,8 @@ module.exports = function(Chart) { var me = this; if (me.options.time.unit === 'week' && me.options.time.isoWeekday !== false) { return tick.clone().startOf('isoWeek').isoWeekday(me.options.time.isoWeekday); - } else { - return tick.clone().startOf(me.tickUnit); } + return tick.clone().startOf(me.tickUnit); }, determineDataLimits: function() { var me = this; @@ -381,9 +380,8 @@ module.exports = function(Chart) { if (callback) { return callback(formattedTick, index, ticks); - } else { - return formattedTick; } + return formattedTick; }, convertTicksToLabels: function() { var me = this; @@ -415,12 +413,11 @@ module.exports = function(Chart) { var valueOffset = (innerWidth * decimal) + me.paddingLeft; return me.left + Math.round(valueOffset); - } else { - var innerHeight = me.height - (me.paddingTop + me.paddingBottom); - var heightOffset = (innerHeight * decimal) + me.paddingTop; - - return me.top + Math.round(heightOffset); } + var innerHeight = me.height - (me.paddingTop + me.paddingBottom); + var heightOffset = (innerHeight * decimal) + me.paddingTop; + + return me.top + Math.round(heightOffset); } }, getPixelForTick: function(index) { From bddd4cd94bbb2fa40d36029433069fa7950fd3ef Mon Sep 17 00:00:00 2001 From: Zach Panzarino Date: Thu, 15 Sep 2016 00:23:30 +0000 Subject: [PATCH 6/9] Fix style issues in core and scales --- src/core/core.helpers.js | 82 +++++++++++++++++--------------- src/core/core.layoutService.js | 8 ++-- src/core/core.legend.js | 10 ++-- src/core/core.scale.js | 28 +++++------ src/core/core.tooltip.js | 10 ++-- src/scales/scale.category.js | 20 ++++---- src/scales/scale.linear.js | 19 +++----- src/scales/scale.logarithmic.js | 3 +- src/scales/scale.radialLinear.js | 13 ++--- 9 files changed, 89 insertions(+), 104 deletions(-) diff --git a/src/core/core.helpers.js b/src/core/core.helpers.js index 9c021a78096..1593b72de04 100644 --- a/src/core/core.helpers.js +++ b/src/core/core.helpers.js @@ -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(); }; }; diff --git a/src/core/core.layoutService.js b/src/core/core.layoutService.js index 324e93f5f0d..1bb06fcf365 100644 --- a/src/core/core.layoutService.js +++ b/src/core/core.layoutService.js @@ -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 = { diff --git a/src/core/core.legend.js b/src/core/core.legend.js index 369b549fa62..e82c06ea3ed 100644 --- a/src/core/core.legend.js +++ b/src/core/core.legend.js @@ -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); diff --git a/src/core/core.scale.js b/src/core/core.scale.js index 7a5613c0ffe..123da31841d 100644 --- a/src/core/core.scale.js +++ b/src/core/core.scale.js @@ -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 diff --git a/src/core/core.tooltip.js b/src/core/core.tooltip.js index e59b26a2d74..5edfd0075f8 100755 --- a/src/core/core.tooltip.js +++ b/src/core/core.tooltip.js @@ -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; diff --git a/src/scales/scale.category.js b/src/scales/scale.category.js index 4979f193e5b..7e1b3d409d6 100644 --- a/src/scales/scale.category.js +++ b/src/scales/scale.category.js @@ -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); diff --git a/src/scales/scale.linear.js b/src/scales/scale.linear.js index 33a3e4930db..f2700a3a4ae 100644 --- a/src/scales/scale.linear.js +++ b/src/scales/scale.linear.js @@ -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; diff --git a/src/scales/scale.logarithmic.js b/src/scales/scale.logarithmic.js index 2d4f323fdd9..50417528a5b 100644 --- a/src/scales/scale.logarithmic.js +++ b/src/scales/scale.logarithmic.js @@ -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 ''; } } }; diff --git a/src/scales/scale.radialLinear.js b/src/scales/scale.radialLinear.js index d6eef1c0429..361ad3cbab1 100644 --- a/src/scales/scale.radialLinear.js +++ b/src/scales/scale.radialLinear.js @@ -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; From 8bc280e1856c4ab09a8a529347f2ef1e5292807e Mon Sep 17 00:00:00 2001 From: Zach Panzarino Date: Thu, 15 Sep 2016 00:27:29 +0000 Subject: [PATCH 7/9] Allow variable use before define with warning --- .eslintrc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.eslintrc b/.eslintrc index 340d657baf5..7cae49e4157 100644 --- a/.eslintrc +++ b/.eslintrc @@ -112,7 +112,7 @@ rules: no-undef: 2 no-undefined: 0 no-unused-vars: 2 - no-use-before-define: 2 + no-use-before-define: 1 # Node.js and CommonJS callback-return: 2 From a929fd473e5f74ebac6611cabc192b2d007683be Mon Sep 17 00:00:00 2001 From: Zach Panzarino Date: Thu, 15 Sep 2016 01:21:45 +0000 Subject: [PATCH 8/9] Include changes suggested by @etimberg in code review --- src/elements/element.line.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/elements/element.line.js b/src/elements/element.line.js index 9981d3d2f63..d81e7861cd5 100644 --- a/src/elements/element.line.js +++ b/src/elements/element.line.js @@ -31,20 +31,20 @@ module.exports = function(Chart) { // Helper function to draw a line to a point function lineToPoint(previousPoint, point) { - var pointvm = point._view; + var pointVM = point._view; if (point._view.steppedLine === true) { - ctx.lineTo(pointvm.x, previousPoint._view.y); - ctx.lineTo(pointvm.x, pointvm.y); + ctx.lineTo(pointVM.x, previousPoint._view.y); + ctx.lineTo(pointVM.x, pointVM.y); } else if (point._view.tension === 0) { - ctx.lineTo(pointvm.x, pointvm.y); + ctx.lineTo(pointVM.x, pointVM.y); } else { ctx.bezierCurveTo( previousPoint._view.controlPointNextX, previousPoint._view.controlPointNextY, - pointvm.controlPointPreviousX, - pointvm.controlPointPreviousY, - pointvm.x, - pointvm.y + pointVM.controlPointPreviousX, + pointVM.controlPointPreviousY, + pointVM.x, + pointVM.y ); } } From 82070277433212f96e73c4b872297bd3c950843a Mon Sep 17 00:00:00 2001 From: Zach Panzarino Date: Thu, 15 Sep 2016 12:49:11 +0000 Subject: [PATCH 9/9] Implement eslint changes proposed by @simonbrunel in code review --- .eslintrc | 8 ++--- src/core/core.helpers.js | 2 +- src/core/core.js | 2 +- src/core/core.layoutService.js | 56 +++++++++++++++++----------------- 4 files changed, 34 insertions(+), 34 deletions(-) diff --git a/.eslintrc b/.eslintrc index 7cae49e4157..991867f10ff 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 1593b72de04..5364d191f8e 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 c4f65e5cacd..577db878e16 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 1bb06fcf365..7336deac0d2 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,