CartoDB/cartodb20

View on GitHub
lib/assets/javascripts/builder/editor/style/style-converter.js

Summary

Maintainability
F
6 days
Test Coverage

File style-converter.js has 582 lines of code (exceeds 250 allowed). Consider refactoring.
Open

var _ = require('underscore');
var camshaftReference = require('builder/data/camshaft-reference');
var Utils = require('builder/helpers/utils');
var InputQualitativeRamps = require('builder/components/input-color/input-qualitative-ramps/main-view.js');

Severity: Major
Found in lib/assets/javascripts/builder/editor/style/style-converter.js - About 1 day to fix

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

    function pointFill (props, animationType) {
      var css = {};
      var color = props && props.color || {};
      var isTorqueCategory = animationType && !color.fixed;
      var markerFillOpacity = color.opacity;
    Severity: Minor
    Found in lib/assets/javascripts/builder/editor/style/style-converter.js - 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 _labels has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
    Open

    function _labels (props) {
      var css = {};
      if (isValidAttribute(props.attribute)) {
        css['text-name'] = '[' + props.attribute + ']';
        css['text-face-name'] = "'" + props.font + "'";
    Severity: Minor
    Found in lib/assets/javascripts/builder/editor/style/style-converter.js - 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 makeColorRamp has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
    Open

    function makeColorRamp (props, isTorqueCategory) {
      var attribute = isTorqueCategory ? 'value' : props.attribute;
      var c = ['ramp([' + attribute + ']'];
    
      if (props.range) {
    Severity: Minor
    Found in lib/assets/javascripts/builder/editor/style/style-converter.js - 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 makeColorRamp has 43 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    function makeColorRamp (props, isTorqueCategory) {
      var attribute = isTorqueCategory ? 'value' : props.attribute;
      var c = ['ramp([' + attribute + ']'];
    
      if (props.range) {
    Severity: Minor
    Found in lib/assets/javascripts/builder/editor/style/style-converter.js - About 1 hr to fix

      Function generateCartoCSS has 33 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      function generateCartoCSS (style, geometryType, configModel) {
        var css = '';
        var styleDef = style.properties;
        var isAnimatable = isTypeTorque(style.type);
        var isCategory = isCategoryType(styleDef, geometryType);
      Severity: Minor
      Found in lib/assets/javascripts/builder/editor/style/style-converter.js - About 1 hr to fix

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

        function animation (style, mapContext) {
          var color = style.properties.fill.color;
          var columnType = color.attribute_type;
          var columnName = color.attribute;
          var hasOthers = color.range && color.range.length > InputQualitativeRamps.MAX_VALUES;
        Severity: Minor
        Found in lib/assets/javascripts/builder/editor/style/style-converter.js - About 1 hr to fix

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

          function pointFill (props, animationType) {
            var css = {};
            var color = props && props.color || {};
            var isTorqueCategory = animationType && !color.fixed;
            var markerFillOpacity = color.opacity;
          Severity: Minor
          Found in lib/assets/javascripts/builder/editor/style/style-converter.js - About 1 hr to fix

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

            function generateStyle (style, geometryType, mapContext, configModel) {
              if (style.type === 'none') {
                return {
                  cartoCSS: CONFIG.GENERIC_STYLE,
                  sql: null,
            Severity: Minor
            Found in lib/assets/javascripts/builder/editor/style/style-converter.js - About 1 hr to fix

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

              function animation (style, mapContext) {
                var color = style.properties.fill.color;
                var columnType = color.attribute_type;
                var columnName = color.attribute;
                var hasOthers = color.range && color.range.length > InputQualitativeRamps.MAX_VALUES;
              Severity: Minor
              Found in lib/assets/javascripts/builder/editor/style/style-converter.js - 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 polygonStroke has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
              Open

              function polygonStroke (props) {
                var css = {};
                if (props.size) {
                  if (props.size.fixed !== undefined) {
                    css['line-width'] = props.size.fixed;
              Severity: Minor
              Found in lib/assets/javascripts/builder/editor/style/style-converter.js - 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 _labels has 27 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

              function _labels (props) {
                var css = {};
                if (isValidAttribute(props.attribute)) {
                  css['text-name'] = '[' + props.attribute + ']';
                  css['text-face-name'] = "'" + props.font + "'";
              Severity: Minor
              Found in lib/assets/javascripts/builder/editor/style/style-converter.js - About 1 hr to fix

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

                function generateStyle (style, geometryType, mapContext, configModel) {
                  if (style.type === 'none') {
                    return {
                      cartoCSS: CONFIG.GENERIC_STYLE,
                      sql: null,
                Severity: Minor
                Found in lib/assets/javascripts/builder/editor/style/style-converter.js - 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 polygonFill has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                Open

                function polygonFill (props) {
                  var css = {};
                  if (props.color) {
                    if (props.color.fixed !== undefined) {
                      css['polygon-fill'] = props.color.fixed;
                Severity: Minor
                Found in lib/assets/javascripts/builder/editor/style/style-converter.js - 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

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

                function pointStroke (props, animationType) {
                  var css = {};
                
                  if (animationType === 'heatmap') {
                    return css;
                Severity: Minor
                Found in lib/assets/javascripts/builder/editor/style/style-converter.js - 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

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

                function pointAnimated (props) {
                  var css = {};
                  if (isValidAttribute(props.attribute)) {
                    css['-torque-frame-count'] = props.steps;
                    css['-torque-animation-duration'] = props.duration;
                Severity: Minor
                Found in lib/assets/javascripts/builder/editor/style/style-converter.js - 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

                    if (props.fill) {
                      css['text-size'] = props.fill.size.fixed;
                
                      if (props.fill.color.opacity != null && props.fill.color.opacity < 1) {
                        css['text-fill'] = Utils.hexToRGBA(props.fill.color.fixed, props.fill.color.opacity);
                lib/assets/javascripts/builder/editor/style/style-converter.js on lines 307..315

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

                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 (props.halo) {
                      css['text-halo-radius'] = props.halo.size.fixed;
                
                      if (props.halo.color.opacity != null && props.halo.color.opacity < 1) {
                        css['text-halo-fill'] = Utils.hexToRGBA(props.halo.color.fixed, props.halo.color.opacity);
                lib/assets/javascripts/builder/editor/style/style-converter.js on lines 297..305

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

                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

                function squares (style, mapContext) {
                  var aggregation = style.properties.aggregation;
                  var sql = 'WITH hgrid AS (SELECT CDB_RectangleGrid ( ST_Expand(!bbox!, CDB_XYZ_Resolution(<%= z %>) * <%= size %>), CDB_XYZ_Resolution(<%= z %>) * <%= size %>, CDB_XYZ_Resolution(<%= z %>) * <%= size %>) as cell) SELECT hgrid.cell as the_geom_webmercator, <%= agg %> as agg_value, <%= agg %> /power( <%= size %> * CDB_XYZ_Resolution(<%= z %>), 2 ) as agg_value_density, row_number() over () as cartodb_id FROM hgrid, <%= table %> i where ST_Intersects(i.the_geom_webmercator, hgrid.cell) GROUP BY hgrid.cell';
                  return _.template(sql)({
                    table: '(<%= sql %>)',
                lib/assets/javascripts/builder/editor/style/style-converter.js on lines 512..521

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

                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

                function hexabins (style, mapContext) {
                  var aggregation = style.properties.aggregation;
                  var sql = 'WITH hgrid AS (SELECT CDB_HexagonGrid(ST_Expand(!bbox!, CDB_XYZ_Resolution(<%= z %>) * <%= size %>), CDB_XYZ_Resolution(<%= z %>) * <%= size %>) as cell) SELECT hgrid.cell as the_geom_webmercator, <%= agg %> as agg_value, count(1)/power( <%= size %> * CDB_XYZ_Resolution(<%= z %>), 2 ) as agg_value_density, row_number() over () as cartodb_id FROM hgrid, <%= table %> i where ST_Intersects(i.the_geom_webmercator, hgrid.cell) GROUP BY hgrid.cell';
                  return _.template(sql)({
                    table: '(<%= sql %>)',
                lib/assets/javascripts/builder/editor/style/style-converter.js on lines 523..532

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

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

                    if (props.color.fixed !== undefined) {
                      css['polygon-fill'] = props.color.fixed;
                    } else if (props.color.attribute) {
                      css['polygon-fill'] = makeColorRamp(props.color);
                    }
                lib/assets/javascripts/builder/editor/style/style-converter.js on lines 237..241
                lib/assets/javascripts/builder/editor/style/style-converter.js on lines 252..256

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

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

                    if (props.color.fixed !== undefined) {
                      css['marker-line-color'] = props.color.fixed;
                    } else if (props.color.attribute) {
                      css['marker-line-color'] = makeColorRamp(props.color);
                    }
                lib/assets/javascripts/builder/editor/style/style-converter.js on lines 209..213
                lib/assets/javascripts/builder/editor/style/style-converter.js on lines 252..256

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

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

                    if (props.size.fixed !== undefined) {
                      css['line-width'] = props.size.fixed;
                    } else if (props.size.attribute) {
                      css['line-width'] = makeWidthRamp(props.size);
                    }
                lib/assets/javascripts/builder/editor/style/style-converter.js on lines 209..213
                lib/assets/javascripts/builder/editor/style/style-converter.js on lines 237..241

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

                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