nnnick/Chart.js

View on GitHub

Showing 245 of 245 total issues

Function updateElements has a Cognitive Complexity of 14 (exceeds 7 allowed). Consider refactoring.
Open

  updateElements(arcs, start, count, mode) {
    const reset = mode === 'reset';
    const chart = this.chart;
    const opts = chart.options;
    const animationOpts = opts.animation;
Severity: Minor
Found in src/controllers/controller.polarArea.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

Function generateTicks has a Cognitive Complexity of 14 (exceeds 7 allowed). Consider refactoring.
Open

function generateTicks(generationOptions, {min, max}) {
  min = finiteOrDefault(generationOptions.min, min);
  const ticks = [];
  const minExp = log10Floor(min);
  let exp = startExp(min, max);
Severity: Minor
Found in src/scales/scale.logarithmic.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

Function _calculatePadding has a Cognitive Complexity of 14 (exceeds 7 allowed). Consider refactoring.
Open

  _calculatePadding(first, last, sin, cos) {
    const {ticks: {align, padding}, position} = this.options;
    const isRotated = this.labelRotation !== 0;
    const labelsBelowTicks = position !== 'top' && this.axis === 'x';

Severity: Minor
Found in src/core/core.scale.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

Function _longestText has 35 lines of code (exceeds 25 allowed). Consider refactoring.
Open

export function _longestText(
  ctx: CanvasRenderingContext2D,
  font: string,
  arrayOfThings: Things,
  cache?: {data?: Record<string, number>, garbageCollect?: string[], font?: string}
Severity: Minor
Found in src/helpers/helpers.canvas.ts - About 1 hr to fix

    Function _createAnimations has 34 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      _createAnimations(target, values) {
        const animatedProps = this._properties;
        const animations = [];
        const running = target.$animations || (target.$animations = {});
        const props = Object.keys(values);
    Severity: Minor
    Found in src/core/core.animations.js - About 1 hr to fix

      Function updateElements has 34 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        updateElements(arcs, start, count, mode) {
          const reset = mode === 'reset';
          const chart = this.chart;
          const chartArea = chart.chartArea;
          const opts = chart.options;
      Severity: Minor
      Found in src/controllers/controller.doughnut.js - About 1 hr to fix

        Function drawBackground has 34 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          drawBackground(pt, ctx, tooltipSize, options) {
            const {xAlign, yAlign} = this;
            const {x, y} = pt;
            const {width, height} = tooltipSize;
            const {topLeft, topRight, bottomLeft, bottomRight} = toTRBLCorners(options.cornerRadius);
        Severity: Minor
        Found in src/plugins/plugin.tooltip.js - About 1 hr to fix

          Function buildOrUpdateControllers has 34 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            buildOrUpdateControllers() {
              const newControllers = [];
              const datasets = this.data.datasets;
              let i, ilen;
          
          
          Severity: Minor
          Found in src/core/core.controller.js - About 1 hr to fix

            Function mergeScaleConfig has 34 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

            function mergeScaleConfig(config, options) {
              const chartDefaults = overrides[config.type] || {scales: {}};
              const configScales = options.scales || {};
              const chartIndexAxis = getIndexAxis(config.type, options);
              const scales = Object.create(null);
            Severity: Minor
            Found in src/core/core.config.js - About 1 hr to fix

              Function initCanvas has 33 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

              function initCanvas(canvas, aspectRatio) {
                const style = canvas.style;
              
                // NOTE(SB) canvas.getAttribute('width') !== canvas.width: in the first case it
                // returns null or '' if no explicit value has been set to the canvas attribute.
              Severity: Minor
              Found in src/platform/platform.dom.js - About 1 hr to fix

                Function updateElements has 33 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                  updateElements(points, start, count, mode) {
                    const reset = mode === 'reset';
                    const {iScale, vScale, _stacked, _dataset} = this._cachedMeta;
                    const firstOpts = this.resolveDataElementOptions(start, mode);
                    const sharedOptions = this.getSharedOptions(firstOpts);
                Severity: Minor
                Found in src/controllers/controller.scatter.js - About 1 hr to fix

                  Function parse has 33 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                    parse(start, count) {
                      const {_cachedMeta: meta, _data: data} = this;
                      const {iScale, _stacked} = meta;
                      const iAxis = iScale.axis;
                  
                  
                  Severity: Minor
                  Found in src/core/core.datasetController.js - About 1 hr to fix

                    Function getMinMax has 33 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                      getMinMax(scale, canStack) {
                        const meta = this._cachedMeta;
                        const _parsed = meta._parsed;
                        const sorted = meta._sorted && scale === meta.iScale;
                        const ilen = _parsed.length;
                    Severity: Minor
                    Found in src/core/core.datasetController.js - About 1 hr to fix

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

                            const vPixel = properties[vAxis] = reset || nullData ? vScale.getBasePixel() : vScale.getPixelForValue(_stacked ? this.applyStack(vScale, parsed, _stacked) : parsed[vAxis], i);
                      Severity: Major
                      Found in src/controllers/controller.line.js and 1 other location - About 1 hr to fix
                      src/controllers/controller.scatter.js on lines 130..130

                      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 61.

                      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

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

                            const vPixel = properties[vAxis] = reset || nullData ? vScale.getBasePixel() : vScale.getPixelForValue(_stacked ? this.applyStack(vScale, parsed, _stacked) : parsed[vAxis], i);
                      Severity: Major
                      Found in src/controllers/controller.scatter.js and 1 other location - About 1 hr to fix
                      src/controllers/controller.line.js on lines 101..101

                      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 61.

                      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 titleArgs has 32 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                      function titleArgs(scale, offset, position, align) {
                        const {top, left, bottom, right, chart} = scale;
                        const {chartArea, scales} = chart;
                        let rotation = 0;
                        let maxWidth, titleX, titleY;
                      Severity: Minor
                      Found in src/core/core.scale.js - About 1 hr to fix

                        Function adjustHitBoxes has 32 lines of code (exceeds 25 allowed). Consider refactoring.
                        Open

                          adjustHitBoxes() {
                            if (!this.options.display) {
                              return;
                            }
                            const titleHeight = this._computeTitleHeight();
                        Severity: Minor
                        Found in src/plugins/plugin.legend.js - About 1 hr to fix

                          Function fitWithPointLabels has 32 lines of code (exceeds 25 allowed). Consider refactoring.
                          Open

                          function fitWithPointLabels(scale) {
                          
                            // Right, this is really confusing and there is a lot of maths going on here
                            // The gist of the problem is here: https://gist.github.com/nnnick/696cc9c55f4b0beb8fe9
                            //
                          Severity: Minor
                          Found in src/scales/scale.radialLinear.js - About 1 hr to fix

                            Function drawBorder has 32 lines of code (exceeds 25 allowed). Consider refactoring.
                            Open

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

                              Function adjustHitBoxes has a Cognitive Complexity of 13 (exceeds 7 allowed). Consider refactoring.
                              Open

                                adjustHitBoxes() {
                                  if (!this.options.display) {
                                    return;
                                  }
                                  const titleHeight = this._computeTitleHeight();
                              Severity: Minor
                              Found in src/plugins/plugin.legend.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