airbnb/superset

View on GitHub
superset-frontend/plugins/plugin-chart-echarts/src/utils/series.ts

Summary

Maintainability
F
5 days
Test Coverage

File series.ts has 573 lines of code (exceeds 250 allowed). Consider refactoring.
Open

/* eslint-disable no-underscore-dangle */
/**
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
Severity: Major
Found in superset-frontend/plugins/plugin-chart-echarts/src/utils/series.ts - About 1 day to fix

    Function extractSeries has 77 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    export function extractSeries(
      data: DataRecord[],
      opts: {
        fillNeighborValue?: number;
        xAxis?: string;
    Severity: Major
    Found in superset-frontend/plugins/plugin-chart-echarts/src/utils/series.ts - About 3 hrs to fix

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

      export function sortRows(
        rows: DataRecord[],
        totalStackedValues: number[],
        xAxis: string,
        xAxisSortSeries: SortSeriesType,
      Severity: Major
      Found in superset-frontend/plugins/plugin-chart-echarts/src/utils/series.ts - About 2 hrs to fix

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

          const sortedRows = rows.map((row, idx) => {
            let sortKey: DataRecordValue = '';
            let aggregate: number | undefined;
            let entries = 0;
            Object.entries(row).forEach(([key, value]) => {
        Severity: Major
        Found in superset-frontend/plugins/plugin-chart-echarts/src/utils/series.ts - About 2 hrs to fix

          Function getChartPadding has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
          Open

          export function getChartPadding(
            show: boolean,
            orientation: LegendOrientation,
            margin?: string | number | null,
            padding?: { top?: number; bottom?: number; left?: number; right?: number },
          Severity: Minor
          Found in superset-frontend/plugins/plugin-chart-echarts/src/utils/series.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

          Function formatSeriesName has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
          Open

          export function formatSeriesName(
            name: DataRecordValue | undefined,
            {
              numberFormatter,
              timeFormatter,
          Severity: Minor
          Found in superset-frontend/plugins/plugin-chart-echarts/src/utils/series.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 extractSeries has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
          Open

          export function extractSeries(
            data: DataRecord[],
            opts: {
              fillNeighborValue?: number;
              xAxis?: string;
          Severity: Minor
          Found in superset-frontend/plugins/plugin-chart-echarts/src/utils/series.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 getLegendProps has 35 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          export function getLegendProps(
            type: LegendType,
            orientation: LegendOrientation,
            show: boolean,
            theme: SupersetTheme,
          Severity: Minor
          Found in superset-frontend/plugins/plugin-chart-echarts/src/utils/series.ts - About 1 hr to fix

            Function getChartPadding has 31 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

            export function getChartPadding(
              show: boolean,
              orientation: LegendOrientation,
              margin?: string | number | null,
              padding?: { top?: number; bottom?: number; left?: number; right?: number },
            Severity: Minor
            Found in superset-frontend/plugins/plugin-chart-echarts/src/utils/series.ts - About 1 hr to fix

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

              export function getMinAndMaxFromBounds(
                axisType: AxisType,
                truncateAxis: boolean,
                min?: number,
                max?: number,
              Severity: Minor
              Found in superset-frontend/plugins/plugin-chart-echarts/src/utils/series.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 extractShowValueIndexes has 27 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

              export function extractShowValueIndexes(
                series: SeriesOption[],
                opts: {
                  stack: StackType;
                  onlyTotal?: boolean;
              Severity: Minor
              Found in superset-frontend/plugins/plugin-chart-echarts/src/utils/series.ts - About 1 hr to fix

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

                export function sortAndFilterSeries(
                  rows: DataRecord[],
                  xAxis: string,
                  extraMetricLabels: any[],
                  sortSeriesType?: SortSeriesType,
                Severity: Minor
                Found in superset-frontend/plugins/plugin-chart-echarts/src/utils/series.ts - About 1 hr to fix

                  Function sortRows has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                  Open

                  export function sortRows(
                    rows: DataRecord[],
                    totalStackedValues: number[],
                    xAxis: string,
                    xAxisSortSeries: SortSeriesType,
                  Severity: Minor
                  Found in superset-frontend/plugins/plugin-chart-echarts/src/utils/series.ts - About 55 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 getLegendProps has 6 arguments (exceeds 4 allowed). Consider refactoring.
                  Open

                    type: LegendType,
                    orientation: LegendOrientation,
                    show: boolean,
                    theme: SupersetTheme,
                    zoomable = false,
                  Severity: Minor
                  Found in superset-frontend/plugins/plugin-chart-echarts/src/utils/series.ts - About 45 mins to fix

                    Function getMinAndMaxFromBounds has 5 arguments (exceeds 4 allowed). Consider refactoring.
                    Open

                      axisType: AxisType,
                      truncateAxis: boolean,
                      min?: number,
                      max?: number,
                      seriesType?: EchartsTimeseriesSeriesType,
                    Severity: Minor
                    Found in superset-frontend/plugins/plugin-chart-echarts/src/utils/series.ts - About 35 mins to fix

                      Function sortAndFilterSeries has 5 arguments (exceeds 4 allowed). Consider refactoring.
                      Open

                        rows: DataRecord[],
                        xAxis: string,
                        extraMetricLabels: any[],
                        sortSeriesType?: SortSeriesType,
                        sortSeriesAscending?: boolean,
                      Severity: Minor
                      Found in superset-frontend/plugins/plugin-chart-echarts/src/utils/series.ts - About 35 mins to fix

                        Function sortRows has 5 arguments (exceeds 4 allowed). Consider refactoring.
                        Open

                          rows: DataRecord[],
                          totalStackedValues: number[],
                          xAxis: string,
                          xAxisSortSeries: SortSeriesType,
                          xAxisSortSeriesAscending: boolean,
                        Severity: Minor
                        Found in superset-frontend/plugins/plugin-chart-echarts/src/utils/series.ts - About 35 mins to fix

                          Function getChartPadding has 5 arguments (exceeds 4 allowed). Consider refactoring.
                          Open

                            show: boolean,
                            orientation: LegendOrientation,
                            margin?: string | number | null,
                            padding?: { top?: number; bottom?: number; left?: number; right?: number },
                            isHorizontal?: boolean,
                          Severity: Minor
                          Found in superset-frontend/plugins/plugin-chart-echarts/src/utils/series.ts - About 35 mins to fix

                            Avoid too many return statements within this function.
                            Open

                              return name;
                            Severity: Major
                            Found in superset-frontend/plugins/plugin-chart-echarts/src/utils/series.ts - About 30 mins to fix

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

                              export function getLegendProps(
                                type: LegendType,
                                orientation: LegendOrientation,
                                show: boolean,
                                theme: SupersetTheme,
                              Severity: Minor
                              Found in superset-frontend/plugins/plugin-chart-echarts/src/utils/series.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

                                return {
                                  left: left + (orientation === LegendOrientation.Left ? legendMargin : 0),
                                  right: right + (orientation === LegendOrientation.Right ? legendMargin : 0),
                                  top: top + (orientation === LegendOrientation.Top ? legendMargin : 0),
                                  bottom:
                              superset-frontend/plugins/plugin-chart-echarts/src/utils/series.ts on lines 492..500

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

                              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

                                  return {
                                    left:
                                      left + (orientation === LegendOrientation.Bottom ? legendMargin : 0),
                                    right:
                                      right + (orientation === LegendOrientation.Right ? legendMargin : 0),
                              superset-frontend/plugins/plugin-chart-echarts/src/utils/series.ts on lines 503..509

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

                              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 (min !== undefined) {
                                    ret.min = min;
                                  } else if (seriesType !== EchartsTimeseriesSeriesType.Bar) {
                                    ret.min = 'dataMin';
                                  }
                              superset-frontend/plugins/plugin-chart-echarts/src/utils/series.ts on lines 598..602

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

                              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 (max !== undefined) {
                                    ret.max = max;
                                  } else if (seriesType !== EchartsTimeseriesSeriesType.Bar) {
                                    ret.max = 'dataMax';
                                  }
                              superset-frontend/plugins/plugin-chart-echarts/src/utils/series.ts on lines 593..597

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

                              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