nnnick/Chart.js

View on GitHub

Showing 245 of 245 total issues

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

function generateTicks(generationOptions, dataRange) {
  const ticks = [];
  // To get a "nice" value for the tick spacing, we will use the appropriately named
  // "nice number" algorithm. See https://stackoverflow.com/questions/8506881/nice-label-algorithm-for-charts-with-minimum-ticks
  // for details.
Severity: Minor
Found in src/scales/scale.linearbase.js - About 5 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

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

import type {
  Chart,
  Point,
  FontSpec,
  CanvasFontSpec,
Severity: Minor
Found in src/helpers/helpers.canvas.ts - About 5 hrs to fix

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

    function createDetachObserver(chart, type, listener) {
      const canvas = chart.canvas;
      const observer = new MutationObserver(entries => {
        let trigger = false;
        for (const entry of entries) {
    Severity: Major
    Found in src/platform/platform.dom.js and 1 other location - About 5 hrs to fix
    src/platform/platform.dom.js on lines 129..143

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

    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

    function createAttachObserver(chart, type, listener) {
      const canvas = chart.canvas;
      const observer = new MutationObserver(entries => {
        let trigger = false;
        for (const entry of entries) {
    Severity: Major
    Found in src/platform/platform.dom.js and 1 other location - About 5 hrs to fix
    src/platform/platform.dom.js on lines 145..159

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

    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

    File scale.time.js has 384 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    import adapters from '../core/core.adapters.js';
    import {callback as call, isFinite, isNullOrUndef, mergeIf, valueOrDefault} from '../helpers/helpers.core.js';
    import {toRadians, isNumber, _limitValue} from '../helpers/helpers.math.js';
    import Scale from '../core/core.scale.js';
    import {_arrayUnique, _filterBetween, _lookup} from '../helpers/helpers.collection.js';
    Severity: Minor
    Found in src/scales/scale.time.js - About 5 hrs to fix

      Function drawPointLegend has 119 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      export function drawPointLegend(
        ctx: CanvasRenderingContext2D,
        options: DrawPointOptions,
        x: number,
        y: number,
      Severity: Major
      Found in src/helpers/helpers.canvas.ts - About 4 hrs to fix

        Function _draw has 118 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          _draw() {
            const {options: opts, columnSizes, lineWidths, ctx} = this;
            const {align, labels: labelOpts} = opts;
            const defaultColor = defaults.color;
            const rtlHelper = getRtlAdapter(opts.rtl, this.left, this.width);
        Severity: Major
        Found in src/plugins/plugin.legend.js - About 4 hrs to fix

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

              if (isObject(position)) {
                const positionAxisID = Object.keys(position)[0];
                const value = position[positionAxisID];
                titleX = scales[positionAxisID].getPixelForValue(value) - width + offset;
              } else if (position === 'center') {
          Severity: Major
          Found in src/core/core.scale.js and 1 other location - About 4 hrs to fix
          src/core/core.scale.js on lines 142..150

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

          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 (isObject(position)) {
                const positionAxisID = Object.keys(position)[0];
                const value = position[positionAxisID];
                titleY = scales[positionAxisID].getPixelForValue(value) + height - offset;
              } else if (position === 'center') {
          Severity: Major
          Found in src/core/core.scale.js and 1 other location - About 4 hrs to fix
          src/core/core.scale.js on lines 153..161

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

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

            _computeGridLineItems(chartArea) {
              const axis = this.axis;
              const chart = this.chart;
              const options = this.options;
              const {grid, position, border} = options;
          Severity: Major
          Found in src/core/core.scale.js - About 4 hrs to fix

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

            /* eslint-disable @typescript-eslint/no-use-before-define */
            import type {AnyObject} from '../types/basic.js';
            import type {ChartMeta} from '../types/index.js';
            import type {
              ResolverObjectKey,
            Severity: Minor
            Found in src/helpers/helpers.config.ts - About 4 hrs to fix

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

                getTitle(context, options) {
                  const {callbacks} = options;
              
                  const beforeTitle = invokeCallbackWithFallback(callbacks, 'beforeTitle', this, context);
                  const title = invokeCallbackWithFallback(callbacks, 'title', this, context);
              Severity: Major
              Found in src/plugins/plugin.tooltip.js and 1 other location - About 4 hrs to fix
              src/plugins/plugin.tooltip.js on lines 577..590

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

              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

                getFooter(tooltipItems, options) {
                  const {callbacks} = options;
              
                  const beforeFooter = invokeCallbackWithFallback(callbacks, 'beforeFooter', this, tooltipItems);
                  const footer = invokeCallbackWithFallback(callbacks, 'footer', this, tooltipItems);
              Severity: Major
              Found in src/plugins/plugin.tooltip.js and 1 other location - About 4 hrs to fix
              src/plugins/plugin.tooltip.js on lines 528..541

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

              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 _getYAxisLabelAlignment has a Cognitive Complexity of 29 (exceeds 7 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: Minor
              Found in src/core/core.scale.js - About 3 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

              effects has 31 functions (exceeds 20 allowed). Consider refactoring.
              Open

              const effects = {
                linear: (t: number) => t,
              
                easeInQuad: (t: number) => t * t,
              
              
              Severity: Minor
              Found in src/helpers/helpers.easing.ts - About 3 hrs to fix

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

                      if (xAlign === 'left') {
                        x1 = ptX;
                        x2 = x1 - caretSize;
                
                        // Left draws bottom -> top, this y1 is on the bottom
                Severity: Major
                Found in src/plugins/plugin.tooltip.js and 1 other location - About 3 hrs to fix
                src/plugins/plugin.tooltip.js on lines 731..745

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

                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 (yAlign === 'top') {
                        y1 = ptY;
                        y2 = y1 - caretSize;
                
                        // Top draws left -> right, thus x1 is on the left
                Severity: Major
                Found in src/plugins/plugin.tooltip.js and 1 other location - About 3 hrs to fix
                src/plugins/plugin.tooltip.js on lines 705..719

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

                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 (reverse) {
                    if (val >= table[lo].pos && val <= table[hi].pos) {
                      ({lo, hi} = _lookupByKey(table, 'pos', val));
                    }
                    ({pos: prevSource, time: prevTarget} = table[lo]);
                Severity: Major
                Found in src/scales/scale.timeseries.js and 1 other location - About 3 hrs to fix
                src/scales/scale.timeseries.js on lines 22..28

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

                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 (val >= table[lo].time && val <= table[hi].time) {
                      ({lo, hi} = _lookupByKey(table, 'time', val));
                    }
                    ({time: prevSource, pos: prevTarget} = table[lo]);
                Severity: Major
                Found in src/scales/scale.timeseries.js and 1 other location - About 3 hrs to fix
                src/scales/scale.timeseries.js on lines 16..22

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

                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

                File core.config.js has 310 lines of code (exceeds 250 allowed). Consider refactoring.
                Open

                import defaults, {overrides, descriptors} from './core.defaults.js';
                import {mergeIf, resolveObjectKey, isArray, isFunction, valueOrDefault, isObject} from '../helpers/helpers.core.js';
                import {_attachContext, _createResolver, _descriptors} from '../helpers/helpers.config.js';
                
                export function getIndexAxis(type, options) {
                Severity: Minor
                Found in src/core/core.config.js - About 3 hrs to fix
                  Severity
                  Category
                  Status
                  Source
                  Language