FarmBot/Farmbot-Web-App

View on GitHub
frontend/curves/chart.tsx

Summary

Maintainability
F
3 days
Test Coverage

File chart.tsx has 422 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import React from "react";
import { t } from "../i18next_wrapper";
import { floor, isUndefined, range, round } from "lodash";
import { Curve } from "farmbot/dist/resources/api_resources";
import { Color, Popover } from "../ui";
Severity: Minor
Found in frontend/curves/chart.tsx - About 6 hrs to fix

    Function Data has 102 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    const Data = (props: DataProps) => {
      const { curve, setHovered, showHoverEffect, dragging } = props;
      const { normX, normY, yZero, yMax } = props.plotTools;
      const { data, type } = curve.body;
      const fullWidth = X_MAX / maxDay(data);
    Severity: Major
    Found in frontend/curves/chart.tsx - About 4 hrs to fix

      Function getWarningLinesContent has 68 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        (props: GetWarningLinesContentProps): WarningLinesContent => {
          const { x, y } = props;
          const gantryHeight = props.sourceFbosConfig("gantry_height").value as number;
          const locationSoilHeight = getZAtLocation({
            x,
      Severity: Major
      Found in frontend/curves/chart.tsx - About 2 hrs to fix

        Function CurveSvg has 49 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        export const CurveSvg = (props: CurveSvgProps) => {
          const { curve, dispatch, editable, hovered, setHovered } = props;
          const { data } = curve.body;
          const normX = normDay(data);
          const normY = normValue(data);
        Severity: Minor
        Found in frontend/curves/chart.tsx - About 1 hr to fix

          Function Data has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
          Open

          const Data = (props: DataProps) => {
            const { curve, setHovered, showHoverEffect, dragging } = props;
            const { normX, normY, yZero, yMax } = props.plotTools;
            const { data, type } = curve.body;
            const fullWidth = X_MAX / maxDay(data);
          Severity: Minor
          Found in frontend/curves/chart.tsx - 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 CurveSvgWithPopover has 32 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          export const CurveSvgWithPopover = (props: CurveSvgWithPopoverProps) => {
            const [open, setOpen] = React.useState(false);
            const warnings = getWarningLinesContent({
              curve: props.curve,
              sourceFbosConfig: props.sourceFbosConfig,
          Severity: Minor
          Found in frontend/curves/chart.tsx - About 1 hr to fix

            Function DataLabels has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
            Open

            const DataLabels = (props: DataLabelsProps) => {
              const { curve, showHoverEffect } = props;
              const { normX, normY } = props.plotTools;
              const { data, type } = curve.body;
              const label = (plus: string) =>
            Severity: Minor
            Found in frontend/curves/chart.tsx - 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 DataLabels has 30 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

            const DataLabels = (props: DataLabelsProps) => {
              const { curve, showHoverEffect } = props;
              const { normX, normY } = props.plotTools;
              const { data, type } = curve.body;
              const label = (plus: string) =>
            Severity: Minor
            Found in frontend/curves/chart.tsx - About 1 hr to fix

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

              const YAxis = (props: YAxisProps) => {
                const { data } = props.curve.body;
                const { normY, xMax } = props.plotTools;
                const thirds = maxValue(data) / 3;
                const yStep = floor(thirds, 1 - ("" + floor(thirds)).length);
              Severity: Minor
              Found in frontend/curves/chart.tsx - About 1 hr to fix

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

                        d={Object.entries(data)
                          .map(([day, value], index) => {
                            const prefix = index == 0 ? "M" : "L";
                            return `${prefix}${normX(day)},${normY(value)}`;
                          }).join(" ")} />}
                Severity: Major
                Found in frontend/curves/chart.tsx and 1 other location - About 1 hr to fix
                frontend/curves/chart.tsx on lines 418..422

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

                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

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

                  const curvePathArray = Object.entries(populatedData(data))
                    .map(([day, value], index) => {
                      const prefix = index == 0 ? "M" : "L";
                      return `${prefix}${normX(day)},${normY(value)}`;
                    });
                Severity: Major
                Found in frontend/curves/chart.tsx and 1 other location - About 1 hr to fix
                frontend/curves/chart.tsx on lines 183..187

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

                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

                      y: {
                        min: (maxValueNum - distanceToEdge.y.min) / 2,
                        max: (maxValueNum - distanceToEdge.y.max) / 2,
                      },
                Severity: Minor
                Found in frontend/curves/chart.tsx and 1 other location - About 40 mins to fix
                frontend/curves/chart.tsx on lines 342..345

                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

                        onMouseEnter={() => {
                          setHovered(day);
                          !props.editable && type == CurveType.spread &&
                            setHoveredSpread(value);
                        }}
                Severity: Minor
                Found in frontend/curves/chart.tsx and 1 other location - About 40 mins to fix
                frontend/curves/chart.tsx on lines 157..162

                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

                        onMouseLeave={() => {
                          setHovered(undefined);
                          !props.editable && type == CurveType.spread &&
                            setHoveredSpread(undefined);
                
                
                Severity: Minor
                Found in frontend/curves/chart.tsx and 1 other location - About 40 mins to fix
                frontend/curves/chart.tsx on lines 152..156

                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

                      x: {
                        min: (maxValueNum - distanceToEdge.x.min) / 2,
                        max: (maxValueNum - distanceToEdge.x.max) / 2,
                      },
                Severity: Minor
                Found in frontend/curves/chart.tsx and 1 other location - About 40 mins to fix
                frontend/curves/chart.tsx on lines 346..349

                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