nnnick/Chart.js

View on GitHub
src/core/core.datasetController.js

Summary

Maintainability
F
4 days
Test Coverage

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

import Animations from './core.animations.js';
import defaults from './core.defaults.js';
import {isArray, isFinite, isObject, valueOrDefault, resolveObjectKey, defined} from '../helpers/helpers.core.js';
import {listenArrayEvents, unlistenArrayEvents} from '../helpers/helpers.collection.js';
import {createContext, sign} from '../helpers/index.js';
Severity: Major
Found in src/core/core.datasetController.js - About 1 day to fix

    DatasetController has 55 functions (exceeds 20 allowed). Consider refactoring.
    Open

    export default class DatasetController {
    
      /**
       * @type {any}
       */
    Severity: Major
    Found in src/core/core.datasetController.js - About 7 hrs to fix

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

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

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

            draw() {
              const ctx = this._ctx;
              const chart = this.chart;
              const meta = this._cachedMeta;
              const elements = meta.data || [];
          Severity: Minor
          Found in src/core/core.datasetController.js - About 1 hr to fix

            Function applyStack has a Cognitive Complexity of 11 (exceeds 7 allowed). Consider refactoring.
            Open

            function applyStack(stack, value, dsIndex, options = {}) {
              const keys = stack.keys;
              const singleMode = options.mode === 'single';
              let i, ilen, datasetIndex, otherValue;
            
            
            Severity: Minor
            Found in src/core/core.datasetController.js - About 55 mins 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 draw has a Cognitive Complexity of 9 (exceeds 7 allowed). Consider refactoring.
            Open

              draw() {
                const ctx = this._ctx;
                const chart = this.chart;
                const meta = this._cachedMeta;
                const elements = meta.data || [];
            Severity: Minor
            Found in src/core/core.datasetController.js - About 35 mins 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 clearStacks has a Cognitive Complexity of 9 (exceeds 7 allowed). Consider refactoring.
            Open

            function clearStacks(meta, items) {
              // Not using meta.index here, because it might be already updated if the dataset changed location
              const datasetIndex = meta.controller.index;
              const axis = meta.vScale && meta.vScale.axis;
              if (!axis) {
            Severity: Minor
            Found in src/core/core.datasetController.js - About 35 mins 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 _dataCheck has a Cognitive Complexity of 8 (exceeds 7 allowed). Consider refactoring.
            Open

              _dataCheck() {
                const dataset = this.getDataset();
                const data = dataset.data || (dataset.data = []);
                const _data = this._data;
            
            
            Severity: Minor
            Found in src/core/core.datasetController.js - About 25 mins 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

            TODO found
            Open

                  // TODO: It is not optimal to always parse the old data
            Severity: Minor
            Found in src/core/core.datasetController.js by fixme

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

              _setDatasetHoverStyle() {
                const element = this._cachedMeta.dataset;
            
                if (element) {
                  this._setStyle(element, undefined, 'active', true);
            Severity: Minor
            Found in src/core/core.datasetController.js and 1 other location - About 40 mins to fix
            src/core/core.datasetController.js on lines 928..934

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

            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

              _removeDatasetHoverStyle() {
                const element = this._cachedMeta.dataset;
            
                if (element) {
                  this._setStyle(element, undefined, 'active', false);
            Severity: Minor
            Found in src/core/core.datasetController.js and 1 other location - About 40 mins to fix
            src/core/core.datasetController.js on lines 939..945

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

            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

            There are no issues that match your filters.

            Category
            Status