konvajs/konva

View on GitHub
src/Stage.ts

Summary

Maintainability
F
6 days
Test Coverage

File Stage.ts has 767 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import { Util } from './Util';
import { Factory } from './Factory';
import { Container, ContainerConfig } from './Container';
import { Konva } from './Global';
import { SceneCanvas, HitCanvas } from './Canvas';
Severity: Major
Found in src/Stage.ts - About 1 day to fix

    Stage has 42 functions (exceeds 20 allowed). Consider refactoring.
    Open

    export class Stage extends Container<Layer> {
      content: HTMLDivElement;
      pointerPos: Vector2d | null;
      _pointerPositions: (Vector2d & { id?: number })[] = [];
      _changedPointerPositions: (Vector2d & { id: number })[] = [];
    Severity: Minor
    Found in src/Stage.ts - About 5 hrs to fix

      Function _pointerup has 79 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        _pointerup(evt) {
          const events = getEventsMap(evt.type);
          const eventType = getEventType(evt.type);
      
          if (!events) {
      Severity: Major
      Found in src/Stage.ts - About 3 hrs to fix

        Function _pointermove has 61 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          _pointermove(evt: TouchEvent | MouseEvent | PointerEvent) {
            const events = getEventsMap(evt.type);
            const eventType = getEventType(evt.type);
            if (!events) {
              return;
        Severity: Major
        Found in src/Stage.ts - About 2 hrs to fix

          Function setContainer has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
          Open

            setContainer(container) {
              if (typeof container === STRING) {
                if (container.charAt(0) === '.') {
                  var className = container.slice(1);
                  container = document.getElementsByClassName(className)[0];
          Severity: Minor
          Found in src/Stage.ts - 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 _pointerdown has 36 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            _pointerdown(evt: TouchEvent | MouseEvent | PointerEvent) {
              const events = getEventsMap(evt.type);
              const eventType = getEventType(evt.type);
          
              if (!events) {
          Severity: Minor
          Found in src/Stage.ts - About 1 hr to fix

            Function setPointersPositions has 36 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              setPointersPositions(evt) {
                var contentPosition = this._getContentPosition(),
                  x: number | null = null,
                  y: number | null = null;
                evt = evt ? evt : window.event;
            Severity: Minor
            Found in src/Stage.ts - About 1 hr to fix

              Function _pointerleave has 32 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                _pointerleave(evt) {
                  const events = getEventsMap(evt.type);
                  const eventType = getEventType(evt.type);
              
                  if (!events) {
              Severity: Minor
              Found in src/Stage.ts - About 1 hr to fix

                Function _toKonvaCanvas has 29 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                  _toKonvaCanvas(config) {
                    config = config || {};
                
                    config.x = config.x || 0;
                    config.y = config.y || 0;
                Severity: Minor
                Found in src/Stage.ts - About 1 hr to fix

                  Function add has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                  Open

                    add(layer: Layer, ...rest) {
                      if (arguments.length > 1) {
                        for (var i = 0; i < arguments.length; i++) {
                          this.add(arguments[i]);
                        }
                  Severity: Minor
                  Found in src/Stage.ts - 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

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

                    _wheel(evt) {
                      this.setPointersPositions(evt);
                      var shape = this.getIntersection(this.getPointerPosition()!);
                  
                      if (shape && shape.isListening()) {
                  Severity: Major
                  Found in src/Stage.ts and 1 other location - About 3 hrs to fix
                  src/Stage.ts on lines 759..772

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

                  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

                    _contextmenu(evt) {
                      this.setPointersPositions(evt);
                      var shape = this.getIntersection(this.getPointerPosition()!);
                  
                      if (shape && shape.isListening()) {
                  Severity: Major
                  Found in src/Stage.ts and 1 other location - About 3 hrs to fix
                  src/Stage.ts on lines 774..787

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

                  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

                        Array.prototype.forEach.call(evt.touches, (touch: any) => {
                          this._pointerPositions.push({
                            id: touch.identifier,
                            x: (touch.clientX - contentPosition.left) / contentPosition.scaleX,
                            y: (touch.clientY - contentPosition.top) / contentPosition.scaleY,
                  Severity: Major
                  Found in src/Stage.ts and 1 other location - About 2 hrs to fix
                  src/Stage.ts on lines 842..848

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

                  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

                          (touch: any) => {
                            this._changedPointerPositions.push({
                              id: touch.identifier,
                              x: (touch.clientX - contentPosition.left) / contentPosition.scaleX,
                              y: (touch.clientY - contentPosition.top) / contentPosition.scaleY,
                  Severity: Major
                  Found in src/Stage.ts and 1 other location - About 2 hrs to fix
                  src/Stage.ts on lines 832..838

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

                  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

                    _pointerover(evt) {
                      this.setPointersPositions(evt);
                      const events = getEventsMap(evt.type);
                      if (events) {
                        this._fire(events.pointerover, {
                  Severity: Major
                  Found in src/Stage.ts and 1 other location - About 1 hr to fix
                  src/Stage.ts on lines 471..481

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

                  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

                    _pointerenter(evt: PointerEvent) {
                      this.setPointersPositions(evt);
                      const events = getEventsMap(evt.type);
                      if (events) {
                        this._fire(events.pointerenter, {
                  Severity: Major
                  Found in src/Stage.ts and 1 other location - About 1 hr to fix
                  src/Stage.ts on lines 482..492

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

                  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 (arguments.length > 1) {
                        for (var i = 0; i < arguments.length; i++) {
                          this.add(arguments[i]);
                        }
                        return this;
                  Severity: Major
                  Found in src/Stage.ts and 1 other location - About 1 hr to fix
                  src/Container.ts on lines 130..135

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

                  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 (!triggeredOnShape) {
                        this._fire(events.pointerup, {
                          evt: evt,
                          target: this,
                          currentTarget: this,
                  Severity: Major
                  Found in src/Stage.ts and 1 other location - About 1 hr to fix
                  src/Stage.ts on lines 649..656

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

                  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 (!triggeredOnShape) {
                        this._fire(events.pointermove, {
                          evt: evt,
                          target: this,
                          currentTarget: this,
                  Severity: Major
                  Found in src/Stage.ts and 1 other location - About 1 hr to fix
                  src/Stage.ts on lines 739..746

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

                  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