lib/network/modules/components/shared/Label.js

Summary

Maintainability
F
3 days
Test Coverage

File Label.js has 409 lines of code (exceeds 250 allowed). Consider refactoring.
Open

let util = require('../../../../util');
let ComponentUtil = require('./ComponentUtil').default;
let LabelSplitter = require('./LabelSplitter').default;

/**
Severity: Minor
Found in lib/network/modules/components/shared/Label.js - About 5 hrs to fix

    Function _drawText has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
    Open

      _drawText(ctx, x, y, baseline = 'middle', viewFontSize) {
        [x, y] = this._setAlignment(ctx, x, y, baseline);
    
        ctx.textAlign = 'left';
        x = x - this.size.width / 2; // Shift label 1/2-distance to the left
    Severity: Minor
    Found in lib/network/modules/components/shared/Label.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

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

    class Label {
    
      /**
       * @param {Object} body
       * @param {Object} options
    Severity: Minor
    Found in lib/network/modules/components/shared/Label.js - About 3 hrs to fix

      Function getFormattingValues has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
      Open

        getFormattingValues(ctx, selected, hover, mod) {
          let getValue = function(fontOptions, mod, option) {
            if (mod === "normal") {
              if (option === 'mod' ) return "";
              return fontOptions[option];
      Severity: Minor
      Found in lib/network/modules/components/shared/Label.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 constrain has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
      Open

        constrain(pile) {
          // NOTE: constrainWidth and  constrainHeight never set!
          // NOTE: for edge labels, only 'maxWdt' set
          // Node labels can set all the fields
          let fontOptions = {
      Severity: Minor
      Found in lib/network/modules/components/shared/Label.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 getFontOption has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
      Open

        getFontOption(pile, multiName, option) {
          let multiFont;
      
          // Search multi font in local properties
          for (let n = 0; n < pile.length; ++n) {
      Severity: Minor
      Found in lib/network/modules/components/shared/Label.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 _drawText has 39 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        _drawText(ctx, x, y, baseline = 'middle', viewFontSize) {
          [x, y] = this._setAlignment(ctx, x, y, baseline);
      
          ctx.textAlign = 'left';
          x = x - this.size.width / 2; // Shift label 1/2-distance to the left
      Severity: Minor
      Found in lib/network/modules/components/shared/Label.js - About 1 hr to fix

        Function getFormattingValues has 38 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          getFormattingValues(ctx, selected, hover, mod) {
            let getValue = function(fontOptions, mod, option) {
              if (mod === "normal") {
                if (option === 'mod' ) return "";
                return fontOptions[option];
        Severity: Minor
        Found in lib/network/modules/components/shared/Label.js - About 1 hr to fix

          Function constrain has 38 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            constrain(pile) {
              // NOTE: constrainWidth and  constrainHeight never set!
              // NOTE: for edge labels, only 'maxWdt' set
              // Node labels can set all the fields
              let fontOptions = {
          Severity: Minor
          Found in lib/network/modules/components/shared/Label.js - About 1 hr to fix

            Function setOptions has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
            Open

              setOptions(options) {
                this.elementOptions = options;  // Reference to the options of the parent Node-instance 
            
                this.initFontOptions(options.font);
            
            
            Severity: Minor
            Found in lib/network/modules/components/shared/Label.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 getSize has 27 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              getSize() {
                let lineMargin = 2;
                let x = this.size.left;                 // default values which might be overridden below
                let y = this.size.top - 0.5*lineMargin; // idem
            
            
            Severity: Minor
            Found in lib/network/modules/components/shared/Label.js - About 1 hr to fix

              Function _setAlignment has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
              Open

                _setAlignment(ctx, x, y, baseline) {
                  // check for label alignment (for edges)
                  // TODO: make alignment for nodes
                  if (this.isEdgeLabel && this.fontOptions.align !== 'horizontal' && this.pointToSelf === false) {
                    x = 0;
              Severity: Minor
              Found in lib/network/modules/components/shared/Label.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

              TODO found
              Open

                      // TODO: inefficient to do this conversion every time; find a better way.

              TODO found
              Open

                  // TODO: make alignment for nodes

              There are no issues that match your filters.

              Category
              Status