grafana/grafana-polystat-panel

View on GitHub
src/components/layout/layoutManager.ts

Summary

Maintainability
D
1 day
Test Coverage

File layoutManager.ts has 378 lines of code (exceeds 250 allowed). Consider refactoring.
Wontfix

import * as d3 from 'd3';
import { PolygonShapes, PolystatDiameters } from '../types';
import { LayoutPoint } from './types';
/**
 * LayoutManager creates layouts for supported polygon shapes
Severity: Minor
Found in src/components/layout/layoutManager.ts - About 5 hrs to fix

    Function generatePossibleColumnAndRowsSizes has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring.
    Open

      generatePossibleColumnAndRowsSizes(columnAutoSize: boolean, rowAutoSize: boolean, dataSize: number) {
        if (rowAutoSize && columnAutoSize) {
          // sqrt of # data items
          const squared = Math.sqrt(dataSize);
          // favor columns when width is greater than height
    Severity: Minor
    Found in src/components/layout/layoutManager.ts - 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

    Function generatePoints has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
    Open

      generatePoints(data: any, displayLimit: number, shape: PolygonShapes): LayoutPoint[] {
        const points: LayoutPoint[] = [];
        if (typeof data === 'undefined') {
          return points;
        }
    Severity: Minor
    Found in src/components/layout/layoutManager.ts - 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

    Function generateUniformPoints has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
    Open

      generateUniformPoints(data: any, displayLimit: number): any {
        const points = [] as any;
        if (typeof data === 'undefined') {
          return points;
        }
    Severity: Minor
    Found in src/components/layout/layoutManager.ts - 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

    Function generateActualColumnAndRowUsage has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
    Open

      generateActualColumnAndRowUsage(data: any, displayLimit: number) {
        let polygonsUsed = 0;
        let maxRowsUsed = 0;
        let columnsUsed = 0;
        let maxColumnsUsed = 0;
    Severity: Minor
    Found in src/components/layout/layoutManager.ts - 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

    Avoid deeply nested control flow statements.
    Open

                if (columnsUsed > maxColumnsUsed) {
                  maxColumnsUsed = columnsUsed;
                }
    Severity: Major
    Found in src/components/layout/layoutManager.ts - About 45 mins to fix

      Avoid deeply nested control flow statements.
      Open

                  if (columnsUsed > maxColumnsUsed) {
                    maxColumnsUsed = columnsUsed;
                  }
      Severity: Major
      Found in src/components/layout/layoutManager.ts - About 45 mins to fix

        Avoid deeply nested control flow statements.
        Open

                    if (columnsUsed > maxColumnsUsed) {
                      maxColumnsUsed = columnsUsed;
                    }
        Severity: Major
        Found in src/components/layout/layoutManager.ts - About 45 mins to fix

          Function constructor has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
          Open

            constructor(
              width: number,
              height: number,
              numColumns: number,
              numRows: number,
          Severity: Minor
          Found in src/components/layout/layoutManager.ts - About 45 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

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

                if (this.width > this.height) {
                  this.numColumns = Math.ceil((this.width / this.height) * squared * 0.75);
                  // always at least 1 column and max. data.length columns
                  if (this.numColumns < 1) {
                    this.numColumns = 1;
          Severity: Major
          Found in src/components/layout/layoutManager.ts and 1 other location - About 6 hrs to fix
          src/components/layout/layoutManager.ts on lines 174..188

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

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

                } else {
                  this.numRows = Math.ceil((this.height / this.width) * squared * 0.75);
                  // always at least 1 row and max. data.length rows
                  if (this.numRows < 1) {
                    this.numRows = 1;
          Severity: Major
          Found in src/components/layout/layoutManager.ts and 1 other location - About 6 hrs to fix
          src/components/layout/layoutManager.ts on lines 159..174

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

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

              let hexRadius = d3.min([
                this.width / ((this.numColumns + 0.5) * this.SQRT3),
                this.height / ((this.numRows + 1 / 3) * 1.5),
              ]);
          Severity: Major
          Found in src/components/layout/layoutManager.ts and 1 other location - About 1 hr to fix
          src/components/layout/layoutManager.ts on lines 393..396

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

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

              let hexRadius = d3.min([
                this.width / ((this.numColumns + 0.5) * this.SQRT3),
                this.height / ((this.numRows + 1 / 3) * 1.5),
              ]);
          Severity: Major
          Found in src/components/layout/layoutManager.ts and 1 other location - About 1 hr to fix
          src/components/layout/layoutManager.ts on lines 98..101

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

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

              } else if (rowAutoSize) {
                // Align rows count to fixed columns count
                this.numRows = Math.ceil(dataSize / this.numColumns);
                // always at least 1 row
                if (this.numRows < 1) {
          Severity: Major
          Found in src/components/layout/layoutManager.ts and 1 other location - About 1 hr to fix
          src/components/layout/layoutManager.ts on lines 196..203

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

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

              } else if (columnAutoSize) {
                // Align columns count to fixed rows count
                this.numColumns = Math.ceil(dataSize / this.numRows);
                // always at least 1 column
                if (this.numColumns < 1) {
          Severity: Major
          Found in src/components/layout/layoutManager.ts and 1 other location - About 1 hr to fix
          src/components/layout/layoutManager.ts on lines 189..203

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

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

              if (displayLimit < 0 || isNaN(displayLimit)) {
                this.displayLimit = 100;
              } else {
                this.displayLimit = displayLimit;
              }
          Severity: Minor
          Found in src/components/layout/layoutManager.ts and 1 other location - About 35 mins to fix
          src/components/layout/layoutManager.ts on lines 38..42

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

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

              if (numRows < 1 || isNaN(numRows)) {
                this.numRows = 8;
              } else {
                this.numRows = numRows;
              }
          Severity: Minor
          Found in src/components/layout/layoutManager.ts and 1 other location - About 35 mins to fix
          src/components/layout/layoutManager.ts on lines 48..52

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

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

            generateHexagonPointedTopLayout(): any {
              const layout = {};
              this.radius = this.getHexFlatTopRadius();
              return layout;
            }
          Severity: Minor
          Found in src/components/layout/layoutManager.ts and 1 other location - About 30 mins to fix
          src/components/layout/layoutManager.ts on lines 84..88

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

            generateUniformLayout(): any {
              const layout = {};
              this.radius = this.getUniformRadius();
              return layout;
            }
          Severity: Minor
          Found in src/components/layout/layoutManager.ts and 1 other location - About 30 mins to fix
          src/components/layout/layoutManager.ts on lines 75..79

          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