Gapminder/vizabi

View on GitHub
src/helpers/d3.axisWithLabelPicker.js

Summary

Maintainability
F
3 wks
Test Coverage

Function axisSmart has a Cognitive Complexity of 582 (exceeds 5 allowed). Consider refactoring.
Open

export default function axisSmart(_orient) {

  return (function d3_axis_smart(_super) {

    const VERTICAL = "vertical axis";
Severity: Minor
Found in src/helpers/d3.axisWithLabelPicker.js - About 1 wk 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 axisSmart has 644 lines of code (exceeds 25 allowed). Consider refactoring.
Open

export default function axisSmart(_orient) {

  return (function d3_axis_smart(_super) {

    const VERTICAL = "vertical axis";
Severity: Major
Found in src/helpers/d3.axisWithLabelPicker.js - About 3 days to fix

    Function d3_axis_smart has 642 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      return (function d3_axis_smart(_super) {
    
        const VERTICAL = "vertical axis";
        const HORIZONTAL = "horizontal axis";
        const X = "labels stack side by side";
    Severity: Major
    Found in src/helpers/d3.axisWithLabelPicker.js - About 3 days to fix

      File d3.axisWithLabelPicker.js has 647 lines of code (exceeds 250 allowed). Consider refactoring.
      Open

      import * as utils from "base/utils";
      //d3.axisSmart
      
      export default function axisSmart(_orient) {
      
      
      Severity: Major
      Found in src/helpers/d3.axisWithLabelPicker.js - About 1 day to fix

        Function labelFactory has 275 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            axis.labelFactory = function(options) {
              if (options == null) options = {};
              if (options.scaleType != "linear" &&
                options.scaleType != "time" &&
                options.scaleType != "genericLog" &&
        Severity: Major
        Found in src/helpers/d3.axisWithLabelPicker.js - About 1 day to fix

          Function axis has 117 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              function axis(g) {
                const checkDmn = axis.scale().domain();
                const checkRng = axis.scale().range();
                if (!checkDmn[0] && checkDmn[0] !== 0 || !checkDmn[1] && checkDmn[1] !== 0
                || !checkRng[0] && checkRng[0] !== 0 || !checkRng[1] && checkRng[1] !== 0) {
          Severity: Major
          Found in src/helpers/d3.axisWithLabelPicker.js - About 4 hrs to fix

            Function highlightValueRun has 75 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                axis.highlightValueRun = function(g) {
            
                  //if viewport is defined and HL value is outside then behave as reset HL
                  if (options.viewportLength && highlightValue != "none" && (
                    axis.scale()(highlightValue) > options.viewportLength ||
            Severity: Major
            Found in src/helpers/d3.axisWithLabelPicker.js - About 3 hrs to fix

              Function repositionLabelsThatStickOut has 66 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  function repositionLabelsThatStickOut(tickValues, options, orient, scale, dimension) {
                    if (!tickValues) return null;
                    const result = {};
              
                    // make an abstraction layer for margin sizes
              Severity: Major
              Found in src/helpers/d3.axisWithLabelPicker.js - About 2 hrs to fix

                Consider simplifying this complex logical expression.
                Open

                      if (!checkDmn[0] && checkDmn[0] !== 0 || !checkDmn[1] && checkDmn[1] !== 0
                      || !checkRng[0] && checkRng[0] !== 0 || !checkRng[1] && checkRng[1] !== 0) {
                        return utils.warn("d3.axisSmart() skips action because of invalid domain " + JSON.stringify(checkDmn) + " or range " + JSON.stringify(checkRng) + " of the attached scale");
                      }
                Severity: Critical
                Found in src/helpers/d3.axisWithLabelPicker.js - About 1 hr to fix

                  Function labelsFitIntoScale has 28 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                        const labelsFitIntoScale = function(tickValues, lengthRange, approximationStyle, rescalingLabels) {
                          if (tickValues == null || tickValues.length <= 1) return true;
                          if (approximationStyle == null) approximationStyle = PESSIMISTIC;
                          if (rescalingLabels == null) scaleType = "none";
                  
                  
                  Severity: Minor
                  Found in src/helpers/d3.axisWithLabelPicker.js - About 1 hr to fix

                    Avoid deeply nested control flow statements.
                    Open

                                    if (!labelsFitIntoScale(trytofit, lengthRange, PESSIMISTIC, "none")) break;
                    Severity: Major
                    Found in src/helpers/d3.axisWithLabelPicker.js - About 45 mins to fix

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

                          function repositionLabelsThatStickOut(tickValues, options, orient, scale, dimension) {
                      Severity: Minor
                      Found in src/helpers/d3.axisWithLabelPicker.js - About 35 mins to fix

                        Avoid too many return statements within this function.
                        Open

                              return axis
                                .ticks(ticksNumber)
                                .tickFormat(options.formatter)
                                .tickValues(tickValues)
                                .tickValuesMinor(tickValuesMinor)
                        Severity: Major
                        Found in src/helpers/d3.axisWithLabelPicker.js - About 30 mins to fix

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

                                  let repositionTail = Math.min(margin.tail, options.widthOfOneDigit * 0.5) + bump
                                    + (orient == VERTICAL ? 1 : 0) * d3.max(range)
                                    - (orient == VERTICAL ? 0 : 1) * d3.min(range)
                                    + (orient == VERTICAL ? -1 : 1) * scale(d)
                                    - (dimension == "x") * options.formatter(d).length * options.widthOfOneDigit / 2
                          Severity: Major
                          Found in src/helpers/d3.axisWithLabelPicker.js and 1 other location - About 1 day to fix
                          src/helpers/d3.axisWithLabelPicker.js on lines 865..873

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

                          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

                                  let repositionHead = Math.min(margin.head, options.widthOfOneDigit * 0.5) + bump
                                    + (orient == HORIZONTAL ? 1 : 0) * d3.max(range)
                                    - (orient == HORIZONTAL ? 0 : 1) * d3.min(range)
                                    + (orient == HORIZONTAL ? -1 : 1) * scale(d)
                                    - (dimension == "x") * options.formatter(d).length * options.widthOfOneDigit / 2
                          Severity: Major
                          Found in src/helpers/d3.axisWithLabelPicker.js and 1 other location - About 1 day to fix
                          src/helpers/d3.axisWithLabelPicker.js on lines 876..884

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

                          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 4 locations. Consider refactoring.
                          Open

                                if (options.cssMargin.top == null || parseInt(options.cssMargin.top) < options.cssLabelMarginLimit)
                                  options.cssMargin.top = options.cssLabelMarginLimit + "px";
                          Severity: Major
                          Found in src/helpers/d3.axisWithLabelPicker.js and 3 other locations - About 1 hr to fix
                          src/helpers/d3.axisWithLabelPicker.js on lines 376..377
                          src/helpers/d3.axisWithLabelPicker.js on lines 378..379
                          src/helpers/d3.axisWithLabelPicker.js on lines 382..383

                          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 4 locations. Consider refactoring.
                          Open

                                if (options.cssMargin.bottom == null || parseInt(options.cssMargin.bottom) < options.cssLabelMarginLimit)
                                  options.cssMargin.bottom = options.cssLabelMarginLimit + "px";
                          Severity: Major
                          Found in src/helpers/d3.axisWithLabelPicker.js and 3 other locations - About 1 hr to fix
                          src/helpers/d3.axisWithLabelPicker.js on lines 376..377
                          src/helpers/d3.axisWithLabelPicker.js on lines 378..379
                          src/helpers/d3.axisWithLabelPicker.js on lines 380..381

                          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 4 locations. Consider refactoring.
                          Open

                                if (options.cssMargin.left == null || parseInt(options.cssMargin.left) < options.cssLabelMarginLimit)
                                  options.cssMargin.left = options.cssLabelMarginLimit + "px";
                          Severity: Major
                          Found in src/helpers/d3.axisWithLabelPicker.js and 3 other locations - About 1 hr to fix
                          src/helpers/d3.axisWithLabelPicker.js on lines 378..379
                          src/helpers/d3.axisWithLabelPicker.js on lines 380..381
                          src/helpers/d3.axisWithLabelPicker.js on lines 382..383

                          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 4 locations. Consider refactoring.
                          Open

                                if (options.cssMargin.right == null || parseInt(options.cssMargin.right) < options.cssLabelMarginLimit)
                                  options.cssMargin.right = options.cssLabelMarginLimit + "px";
                          Severity: Major
                          Found in src/helpers/d3.axisWithLabelPicker.js and 3 other locations - About 1 hr to fix
                          src/helpers/d3.axisWithLabelPicker.js on lines 376..377
                          src/helpers/d3.axisWithLabelPicker.js on lines 380..381
                          src/helpers/d3.axisWithLabelPicker.js on lines 382..383

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

                                      const trytofit = tickValues_1.concat(doublingLabels[j])
                                        .filter(d => !collisionBetween(d, avoidCollidingWith))
                                        .filter(onlyUnique);
                          Severity: Minor
                          Found in src/helpers/d3.axisWithLabelPicker.js and 1 other location - About 45 mins to fix
                          src/helpers/d3.axisWithLabelPicker.js on lines 712..714

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

                          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

                                    const trytofit = tickValues_1.concat(addLabels[j])
                                      .filter(d => !collisionBetween(d, avoidCollidingWith))
                                      .filter(onlyUnique);
                          Severity: Minor
                          Found in src/helpers/d3.axisWithLabelPicker.js and 1 other location - About 45 mins to fix
                          src/helpers/d3.axisWithLabelPicker.js on lines 608..610

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

                          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