nnnick/Chart.js

View on GitHub
src/plugins/plugin.tooltip.js

Summary

Maintainability
F
1 wk
Test Coverage

File plugin.tooltip.js has 976 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import Animations from '../core/core.animations.js';
import Element from '../core/core.element.js';
import {addRoundedRectPath} from '../helpers/helpers.canvas.js';
import {each, noop, isNullOrUndef, isArray, _elementsEqual, isObject} from '../helpers/helpers.core.js';
import {toFont, toPadding, toTRBLCorners} from '../helpers/helpers.options.js';
Severity: Major
Found in src/plugins/plugin.tooltip.js - About 2 days to fix

    Tooltip has 26 functions (exceeds 20 allowed). Consider refactoring.
    Open

    export class Tooltip extends Element {
    
      /**
       * @namespace Chart.Tooltip.positioners
       */
    Severity: Minor
    Found in src/plugins/plugin.tooltip.js - About 3 hrs to fix

      Function _drawColorBox has 62 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        _drawColorBox(ctx, pt, i, rtlHelper, options) {
          const labelColor = this.labelColors[i];
          const labelPointStyle = this.labelPointStyles[i];
          const {boxHeight, boxWidth} = options;
          const bodyFont = toFont(options.bodyFont);
      Severity: Major
      Found in src/plugins/plugin.tooltip.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 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 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 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 draw has 29 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                    draw(ctx) {
                      const options = this.options.setContext(this.getContext());
                      let opacity = this.opacity;
                  
                      if (!opacity) {
                  Severity: Minor
                  Found in src/plugins/plugin.tooltip.js - About 1 hr to fix

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

                      constructor(config) {
                        super();
                    
                        this.opacity = 0;
                        this._active = [];
                    Severity: Minor
                    Found in src/plugins/plugin.tooltip.js - About 1 hr to fix

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

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

                        nearest(items, eventPosition) {
                          if (!items.length) {
                            return false;
                          }
                      
                      
                      Severity: Minor
                      Found in src/plugins/plugin.tooltip.js - About 1 hr to fix

                        Function _createItems has 27 lines of code (exceeds 25 allowed). Consider refactoring.
                        Open

                          _createItems(options) {
                            const active = this._active;
                            const data = this.chart.data;
                            const labelColors = [];
                            const labelPointStyles = [];
                        Severity: Minor
                        Found in src/plugins/plugin.tooltip.js - About 1 hr to fix

                          Function drawBody has a Cognitive Complexity of 9 (exceeds 7 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 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 nearest has a Cognitive Complexity of 9 (exceeds 7 allowed). Consider refactoring.
                          Open

                            nearest(items, eventPosition) {
                              if (!items.length) {
                                return false;
                              }
                          
                          
                          Severity: Minor
                          Found in src/plugins/plugin.tooltip.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 _drawColorBox has a Cognitive Complexity of 9 (exceeds 7 allowed). Consider refactoring.
                          Open

                            _drawColorBox(ctx, pt, i, rtlHelper, options) {
                              const labelColor = this.labelColors[i];
                              const labelPointStyle = this.labelPointStyles[i];
                              const {boxHeight, boxWidth} = options;
                              const bodyFont = toFont(options.bodyFont);
                          Severity: Minor
                          Found in src/plugins/plugin.tooltip.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 title has a Cognitive Complexity of 8 (exceeds 7 allowed). Consider refactoring.
                          Open

                            title(tooltipItems) {
                              if (tooltipItems.length > 0) {
                                const item = tooltipItems[0];
                                const labels = item.chart.data.labels;
                                const labelCount = labels ? labels.length : 0;
                          Severity: Minor
                          Found in src/plugins/plugin.tooltip.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

                                ctx.lineWidth = isObject(labelColor.borderWidth) ? Math.max(...Object.values(labelColor.borderWidth)) : (labelColor.borderWidth || 1); // TODO, v4 remove fallback
                          Severity: Minor
                          Found in src/plugins/plugin.tooltip.js by fixme

                          TODO found
                          Open

                              // TODO: V4, make this private, rename to `_labelStyles`, and combine with `labelPointStyles`
                          Severity: Minor
                          Found in src/plugins/plugin.tooltip.js by fixme

                          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

                          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

                                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

                                  ctx.fillText(title[i], rtlHelper.x(pt.x), pt.y + titleFont.lineHeight / 2);
                          Severity: Minor
                          Found in src/plugins/plugin.tooltip.js and 1 other location - About 30 mins to fix
                          src/plugins/plugin.tooltip.js on lines 950..950

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

                          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

                                  ctx.fillText(footer[i], rtlHelper.x(pt.x), pt.y + footerFont.lineHeight / 2);
                          Severity: Minor
                          Found in src/plugins/plugin.tooltip.js and 1 other location - About 30 mins to fix
                          src/plugins/plugin.tooltip.js on lines 771..771

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

                          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