nnnick/Chart.js

View on GitHub

Showing 245 of 245 total issues

Function update has 58 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  update(chart, width, height, minPadding) {
    if (!chart) {
      return;
    }

Severity: Major
Found in src/core/core.layouts.js - About 2 hrs to fix

    Function _getYAxisLabelAlignment has 58 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      _getYAxisLabelAlignment(tl) {
        const {position, ticks: {crossAlign, mirror, padding}} = this.options;
        const labelSizes = this._getLabelSizes();
        const tickAndPadding = tl + padding;
        const widest = labelSizes.widest.width;
    Severity: Major
    Found in src/core/core.scale.js - About 2 hrs to fix

      Function buildOrUpdateScales has 56 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        buildOrUpdateScales() {
          const options = this.options;
          const scaleOpts = options.scales;
          const scales = this.scales;
          const updated = Object.keys(scales).reduce((obj, id) => {
      Severity: Major
      Found in src/core/core.controller.js - About 2 hrs to fix

        Function _calculateBarValuePixels has 55 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          _calculateBarValuePixels(index) {
            const {_cachedMeta: {vScale, _stacked, index: datasetIndex}, options: {base: baseValue, minBarLength}} = this;
            const actualBase = baseValue || 0;
            const parsed = this.getParsed(index);
            const custom = parsed._custom;
        Severity: Major
        Found in src/controllers/controller.bar.js - About 2 hrs to fix

          Function beforeElementsUpdate has 55 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            beforeElementsUpdate: (chart, args, options) => {
              if (!options.enabled) {
                // The decimation plugin may have been previously enabled. Need to remove old `dataset._data` handlers
                cleanDecimatedData(chart);
                return;
          Severity: Major
          Found in src/plugins/plugin.decimation.js - About 2 hrs to fix

            Function constructor has 54 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              constructor(item, userConfig) {
                const config = this.config = new Config(userConfig);
                const initialCanvas = getCanvas(item);
                const existingChart = getChart(initialCanvas);
                if (existingChart) {
            Severity: Major
            Found in src/core/core.controller.js - About 2 hrs to fix

              File helpers.core.ts has 254 lines of code (exceeds 250 allowed). Consider refactoring.
              Open

              /**
               * @namespace Chart.helpers
               */
              
              import type {AnyObject} from '../types/basic.js';
              Severity: Minor
              Found in src/helpers/helpers.core.ts - About 2 hrs to fix

                Function placeBoxes has a Cognitive Complexity of 18 (exceeds 7 allowed). Consider refactoring.
                Open

                function placeBoxes(boxes, chartArea, params, stacks) {
                  const userPadding = params.padding;
                  let {x, y} = chartArea;
                
                  for (const layout of boxes) {
                Severity: Minor
                Found in src/core/core.layouts.js - About 2 hrs to fix

                Cognitive Complexity

                Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                A method's cognitive complexity is based on a few simple rules:

                • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                • Code is considered more complex for each "break in the linear flow of the code"
                • Code is considered more complex when "flow breaking structures are nested"

                Further reading

                Function pathArc has a Cognitive Complexity of 18 (exceeds 7 allowed). Consider refactoring.
                Open

                function pathArc(
                  ctx: CanvasRenderingContext2D,
                  element: ArcElement,
                  offset: number,
                  spacing: number,
                Severity: Minor
                Found in src/elements/element.arc.ts - About 2 hrs to fix

                Cognitive Complexity

                Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                A method's cognitive complexity is based on a few simple rules:

                • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                • Code is considered more complex for each "break in the linear flow of the code"
                • Code is considered more complex when "flow breaking structures are nested"

                Further reading

                Function doSplitByStyles has 51 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                function doSplitByStyles(line, segments, points, segmentOptions) {
                  const chartContext = line._chart.getContext();
                  const baseStyle = readStyle(line.options);
                  const {_datasetIndex: datasetIndex, options: {spanGaps}} = line;
                  const count = points.length;
                Severity: Major
                Found in src/helpers/helpers.segment.js - About 2 hrs to fix

                  Function getTooltipSize has 51 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                  function getTooltipSize(tooltip, options) {
                    const ctx = tooltip.chart.ctx;
                    const {body, footer, title} = tooltip;
                    const {boxWidth, boxHeight} = options;
                    const bodyFont = toFont(options.bodyFont);
                  Severity: Major
                  Found in src/plugins/plugin.tooltip.js - About 2 hrs to fix

                    Function minMaxDecimation has 51 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                    function minMaxDecimation(data, start, count, availableWidth) {
                      let avgX = 0;
                      let countX = 0;
                      let i, point, x, y, prevX, minIndex, maxIndex, startIndex, minY, maxY;
                      const decimated = [];
                    Severity: Major
                    Found in src/plugins/plugin.decimation.js - About 2 hrs to fix

                      File helpers.segment.js has 251 lines of code (exceeds 250 allowed). Consider refactoring.
                      Open

                      import {_angleBetween, _angleDiff, _isBetween, _normalizeAngle} from './helpers.math.js';
                      import {createContext} from './helpers.options.js';
                      import {isPatternOrGradient} from './helpers.color.js';
                      
                      /**
                      Severity: Minor
                      Found in src/helpers/helpers.segment.js - About 2 hrs to fix

                        Similar blocks of code found in 2 locations. Consider refactoring.
                        Open

                            } else if (position === 'bottom') {
                              borderValue = alignBorderValue(this.top);
                              y1 = chartArea.top;
                              y2 = alignBorderValue(chartArea.bottom) - axisHalfWidth;
                              ty1 = borderValue + axisHalfWidth;
                        Severity: Major
                        Found in src/core/core.scale.js and 1 other location - About 2 hrs to fix
                        src/core/core.scale.js on lines 1053..1085

                        Duplicated Code

                        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                        Tuning

                        This issue has a mass of 75.

                        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                        Refactorings

                        Further Reading

                        Similar blocks of code found in 2 locations. Consider refactoring.
                        Open

                            } else if (position === 'right') {
                              borderValue = alignBorderValue(this.left);
                              x1 = chartArea.left;
                              x2 = alignBorderValue(chartArea.right) - axisHalfWidth;
                              tx1 = borderValue + axisHalfWidth;
                        Severity: Major
                        Found in src/core/core.scale.js and 1 other location - About 2 hrs to fix
                        src/core/core.scale.js on lines 1041..1085

                        Duplicated Code

                        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                        Tuning

                        This issue has a mass of 75.

                        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                        Refactorings

                        Further Reading

                        Similar blocks of code found in 2 locations. Consider refactoring.
                        Open

                            } else if (position === 'left') {
                              borderValue = alignBorderValue(this.right);
                              tx1 = this.right - tl;
                              tx2 = borderValue - axisHalfWidth;
                              x1 = alignBorderValue(chartArea.left) + axisHalfWidth;
                        Severity: Major
                        Found in src/core/core.scale.js and 1 other location - About 2 hrs to fix
                        src/core/core.scale.js on lines 1035..1085

                        Duplicated Code

                        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                        Tuning

                        This issue has a mass of 75.

                        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                        Refactorings

                        Further Reading

                        Similar blocks of code found in 2 locations. Consider refactoring.
                        Open

                            if (position === 'top') {
                              borderValue = alignBorderValue(this.bottom);
                              ty1 = this.bottom - tl;
                              ty2 = borderValue - axisHalfWidth;
                              y1 = alignBorderValue(chartArea.top) + axisHalfWidth;
                        Severity: Major
                        Found in src/core/core.scale.js and 1 other location - About 2 hrs to fix
                        src/core/core.scale.js on lines 1047..1085

                        Duplicated Code

                        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                        Tuning

                        This issue has a mass of 75.

                        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                        Refactorings

                        Further Reading

                        Function update has 49 lines of code (exceeds 25 allowed). Consider refactoring.
                        Open

                          update(maxWidth, maxHeight, margins) {
                            const {beginAtZero, grace, ticks: tickOpts} = this.options;
                            const sampleSize = tickOpts.sampleSize;
                        
                            // Update Lifecycle - Probably don't want to ever extend or overwrite this function ;)
                        Severity: Minor
                        Found in src/core/core.scale.js - About 1 hr to fix

                          Function constructor has 48 lines of code (exceeds 25 allowed). Consider refactoring.
                          Open

                            constructor(cfg) {
                              super();
                          
                              /** @type {string} */
                              this.id = cfg.id;
                          Severity: Minor
                          Found in src/core/core.scale.js - About 1 hr to fix

                            Function _boundSegment has a Cognitive Complexity of 17 (exceeds 7 allowed). Consider refactoring.
                            Open

                            export function _boundSegment(segment, points, bounds) {
                              if (!bounds) {
                                return [segment];
                              }
                            
                            
                            Severity: Minor
                            Found in src/helpers/helpers.segment.js - About 1 hr to fix

                            Cognitive Complexity

                            Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                            A method's cognitive complexity is based on a few simple rules:

                            • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                            • Code is considered more complex for each "break in the linear flow of the code"
                            • Code is considered more complex when "flow breaking structures are nested"

                            Further reading

                            Severity
                            Category
                            Status
                            Source
                            Language