nnnick/Chart.js

View on GitHub

Showing 245 of 245 total issues

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

  updateElements(bars, start, count, mode) {
    const reset = mode === 'reset';
    const {index, _cachedMeta: {vScale}} = this;
    const base = vScale.getBasePixel();
    const horizontal = vScale.isHorizontal();
Severity: Minor
Found in src/controllers/controller.bar.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 a Cognitive Complexity of 17 (exceeds 7 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

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 splineCurveMonotone has a Cognitive Complexity of 17 (exceeds 7 allowed). Consider refactoring.
Open

export function splineCurveMonotone(points: SplinePoint[], indexAxis: 'x' | 'y' = 'x') {
  const valueAxis = getValueAxis(indexAxis);
  const pointsLen = points.length;
  const deltaK: number[] = Array(pointsLen).fill(0);
  const mK: number[] = Array(pointsLen);
Severity: Minor
Found in src/helpers/helpers.curve.ts - 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

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

      if (position === 'center') {
        borderValue = alignBorderValue((chartArea.left + chartArea.right) / 2);
      } else if (isObject(position)) {
        const positionAxisID = Object.keys(position)[0];
        const value = position[positionAxisID];
Severity: Major
Found in src/core/core.scale.js and 1 other location - About 1 hr to fix
src/core/core.scale.js on lines 1060..1066

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

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

      if (position === 'center') {
        borderValue = alignBorderValue((chartArea.top + chartArea.bottom) / 2 + 0.5);
      } else if (isObject(position)) {
        const positionAxisID = Object.keys(position)[0];
        const value = position[positionAxisID];
Severity: Major
Found in src/core/core.scale.js and 1 other location - About 1 hr to fix
src/core/core.scale.js on lines 1073..1079

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

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

      for (let i = data.length - 1; i >= 0; --i) {
        max = Math.max(max, data[i].size(this.resolveDataElementOptions(i)) / 2);
      }
Severity: Major
Found in src/controllers/controller.scatter.js and 1 other location - About 1 hr to fix
src/controllers/controller.bubble.js on lines 87..89

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

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

    for (let i = data.length - 1; i >= 0; --i) {
      max = Math.max(max, data[i].size(this.resolveDataElementOptions(i)) / 2);
    }
Severity: Major
Found in src/controllers/controller.bubble.js and 1 other location - About 1 hr to fix
src/controllers/controller.scatter.js on lines 162..164

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

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

function lttbDecimation(data, start, count, availableWidth, options) {
  /**
   * Implementation of the Largest Triangle Three Buckets algorithm.
   *
   * This implementation is based on the original implementation by Sveinn Steinarsson
Severity: Minor
Found in src/plugins/plugin.decimation.js - About 1 hr to fix

    Function drawLegendBox has 44 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        const drawLegendBox = function(x, y, legendItem) {
          if (isNaN(boxWidth) || boxWidth <= 0 || isNaN(boxHeight) || boxHeight < 0) {
            return;
          }
    
    
    Severity: Minor
    Found in src/plugins/plugin.legend.js - About 1 hr to fix

      Function solidSegments has a Cognitive Complexity of 16 (exceeds 7 allowed). Consider refactoring.
      Open

      function solidSegments(points, start, max, loop) {
        const count = points.length;
        const result = [];
        let last = start;
        let prev = points[start];
      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

      Function _createAnimations has a Cognitive Complexity of 16 (exceeds 7 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

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

        drawGrid(chartArea) {
          const grid = this.options.grid;
          const ctx = this.ctx;
          const items = this._gridLineItems || (this._gridLineItems = this._computeGridLineItems(chartArea));
          let i, ilen;
      Severity: Minor
      Found in src/core/core.scale.js - About 1 hr to fix

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

          constructor(_descriptors, _appliers) {
            this.animation = undefined;
            this.backgroundColor = 'rgba(0,0,0,0.1)';
            this.borderColor = 'rgba(0,0,0,0.1)';
            this.color = '#666';
        Severity: Minor
        Found in src/core/core.defaults.js - About 1 hr to fix

          Function fastPathSegment has 43 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          function fastPathSegment(ctx, line, segment, params) {
            const points = line.points;
            const {count, start, ilen} = pathVars(points, segment, params);
            const {move = true, reverse} = params || {};
            let avgX = 0;
          Severity: Minor
          Found in src/elements/element.line.js - About 1 hr to fix

            Function getCaretPosition has 42 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              getCaretPosition(tooltipPoint, size, options) {
                const {xAlign, yAlign} = this;
                const {caretSize, cornerRadius} = options;
                const {topLeft, topRight, bottomLeft, bottomRight} = toTRBLCorners(cornerRadius);
                const {x: ptX, y: ptY} = tooltipPoint;
            Severity: Minor
            Found in src/plugins/plugin.tooltip.js - About 1 hr to fix

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

                update(changed, replay) {
                  const options = this.options.setContext(this.getContext());
                  const active = this._active;
                  let properties;
                  let tooltipItems = [];
              Severity: Minor
              Found in src/plugins/plugin.tooltip.js - About 1 hr to fix

                Function _computeLabelSizes has 42 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                  _computeLabelSizes(ticks, length, maxTicksLimit) {
                    const {ctx, _longestTextCache: caches} = this;
                    const widths = [];
                    const heights = [];
                    const increment = Math.floor(length / getTicksLimit(length, maxTicksLimit));
                Severity: Minor
                Found in src/core/core.scale.js - About 1 hr to fix

                  Function drawBody has 41 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                    drawBody(pt, ctx, options) {
                      const {body} = this;
                      const {bodySpacing, bodyAlign, displayColors, boxHeight, boxWidth, boxPadding} = options;
                      const bodyFont = toFont(options.bodyFont);
                      let bodyLineHeight = bodyFont.lineHeight;
                  Severity: Minor
                  Found in src/plugins/plugin.tooltip.js - About 1 hr to fix

                    Function fit has 40 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                      fit() {
                        // Reset
                        const minSize = {
                          width: 0,
                          height: 0
                    Severity: Minor
                    Found in src/core/core.scale.js - About 1 hr to fix

                      Function bindResponsiveEvents has 40 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                        bindResponsiveEvents() {
                          if (!this._responsiveListeners) {
                            this._responsiveListeners = {};
                          }
                          const listeners = this._responsiveListeners;
                      Severity: Minor
                      Found in src/core/core.controller.js - About 1 hr to fix
                        Severity
                        Category
                        Status
                        Source
                        Language