CartoDB/cartodb20

View on GitHub
lib/assets/javascripts/cartodb/table/mapview.js

Summary

Maintainability
F
1 wk
Test Coverage

File mapview.js has 1200 lines of code (exceeds 250 allowed). Consider refactoring.
Open

/**
 * map tab shown in cartodb admin
 */

/**
Severity: Major
Found in lib/assets/javascripts/cartodb/table/mapview.js - About 3 days to fix

    MapTab has 71 functions (exceeds 20 allowed). Consider refactoring.
    Open

    cdb.admin.MapTab = cdb.core.View.extend({
    
      events: {
        'click .toggle_slides.button': '_toggleSlides',
        'click .add_overlay.button':   'killEvent',
    Severity: Major
    Found in lib/assets/javascripts/cartodb/table/mapview.js - About 1 day to fix

      Function GrouperLayerMapView has a Cognitive Complexity of 65 (exceeds 5 allowed). Consider refactoring.
      Open

      function GrouperLayerMapView(mapViewClass) {
      
        return {
      
          initialize: function() {
      Severity: Minor
      Found in lib/assets/javascripts/cartodb/table/mapview.js - About 1 day 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 GrouperLayerMapView has 147 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      function GrouperLayerMapView(mapViewClass) {
      
        return {
      
          initialize: function() {
      Severity: Major
      Found in lib/assets/javascripts/cartodb/table/mapview.js - About 5 hrs to fix

        Function _bindDataLayer has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
        Open

          _bindDataLayer: function(layerView, layer) {
            var self = this;
            var layerType = layer.get('type');
        
            if (layerType === 'CartoDB' || layerType === 'torque') { // unbind previos stuff
        Severity: Minor
        Found in lib/assets/javascripts/cartodb/table/mapview.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 clearMap has 48 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          clearMap: function() {
        
            clearTimeout(this.autoSaveBoundsTimer);
        
            this.mapView.clean();
        Severity: Minor
        Found in lib/assets/javascripts/cartodb/table/mapview.js - About 1 hr to fix

          Function _addTimeline has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
          Open

            _addTimeline: function() {
              if (!this.mapView) return;
              // check if there is some torque layer
              if(!this.map.layers.any(function(lyr) { return lyr.get('type') === 'torque' && lyr.get('visible'); })) {
                this.timeline && this.timeline.clean();
          Severity: Minor
          Found in lib/assets/javascripts/cartodb/table/mapview.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 _addLegend has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
          Open

            _addLegend: function(layer) {
          
              var type = layer.get('type');
          
              if (type === 'CartoDB' || type === 'torque') {
          Severity: Minor
          Found in lib/assets/javascripts/cartodb/table/mapview.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 _addInfowindow has 46 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            _addInfowindow: function() {
              if(this.infowindow) this.infowindow.clean();
              if(this.table && this.mapView) {
                this.infowindow = new cdb.admin.MapInfowindow({
                  model: this.infowindowModel,
          Severity: Minor
          Found in lib/assets/javascripts/cartodb/table/mapview.js - About 1 hr to fix

            Function _bindDataLayer has 46 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              _bindDataLayer: function(layerView, layer) {
                var self = this;
                var layerType = layer.get('type');
            
                if (layerType === 'CartoDB' || layerType === 'torque') { // unbind previos stuff
            Severity: Minor
            Found in lib/assets/javascripts/cartodb/table/mapview.js - About 1 hr to fix

              Function _showDesktopCanvas has 42 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                _showDesktopCanvas: function(mode) {
              
                  var self = this;
              
                  this.overlays._hideOverlays("mobile");
              Severity: Minor
              Found in lib/assets/javascripts/cartodb/table/mapview.js - About 1 hr to fix

                Function setupMap has 39 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                  setupMap: function() {
                
                    this.$('.tipsy').remove();
                
                    var self = this;
                Severity: Minor
                Found in lib/assets/javascripts/cartodb/table/mapview.js - About 1 hr to fix

                  Function _routeErrors has 37 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                      _routeErrors: function(errors) {
                        var styleRegExp = /style(\d+)/;
                        var postgresExp = /layer(\d+):/i;
                        var generalPostgresExp = /PSQL error/i;
                        var syntaxErrorExp = /syntax error/i;
                  Severity: Minor
                  Found in lib/assets/javascripts/cartodb/table/mapview.js - About 1 hr to fix

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

                      clearMap: function() {
                    
                        clearTimeout(this.autoSaveBoundsTimer);
                    
                        this.mapView.clean();
                    Severity: Minor
                    Found in lib/assets/javascripts/cartodb/table/mapview.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 checkGeoRef has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
                    Open

                      checkGeoRef: function() {
                        if (this.options && this.table) {
                          this.georeferenced = this.table.isGeoreferenced();
                          if (this.noGeoRefDialog) {
                            this.noGeoRefDialog.hide();
                    Severity: Minor
                    Found in lib/assets/javascripts/cartodb/table/mapview.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 _showMobileCanvas has 35 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                      _showMobileCanvas: function(mode) {
                    
                        var self = this;
                    
                        var width  = 288;
                    Severity: Minor
                    Found in lib/assets/javascripts/cartodb/table/mapview.js - About 1 hr to fix

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

                        _addTimeline: function() {
                          if (!this.mapView) return;
                          // check if there is some torque layer
                          if(!this.map.layers.any(function(lyr) { return lyr.get('type') === 'torque' && lyr.get('visible'); })) {
                            this.timeline && this.timeline.clean();
                      Severity: Minor
                      Found in lib/assets/javascripts/cartodb/table/mapview.js - About 1 hr to fix

                        Function _addLayer has 30 lines of code (exceeds 25 allowed). Consider refactoring.
                        Open

                            _addLayer: function(layer, layers, opts) {
                              opts = opts || {};
                              // create group layer to acumulate cartodb layers
                              if (layer.get('type') === 'CartoDB') {
                                var self = this;
                        Severity: Minor
                        Found in lib/assets/javascripts/cartodb/table/mapview.js - About 1 hr to fix

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

                            _addBasemapDropdown: function() {
                          
                              if (!this.basemapDropdown) {
                          
                                if (this.vis.get("type") !== "table") {
                          Severity: Minor
                          Found in lib/assets/javascripts/cartodb/table/mapview.js - About 1 hr to fix

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

                              bindGeoRefCheck: function() {
                                if(!this.table.data().fetched) {
                                  this.table.bind('dataLoaded', function() {
                                    this.checkGeoRef();
                                    if (!this.scratchDialog) {
                            Severity: Minor
                            Found in lib/assets/javascripts/cartodb/table/mapview.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 _addBasemapDropdown has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                            Open

                              _addBasemapDropdown: function() {
                            
                                if (!this.basemapDropdown) {
                            
                                  if (this.vis.get("type") !== "table") {
                            Severity: Minor
                            Found in lib/assets/javascripts/cartodb/table/mapview.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

                            Avoid deeply nested control flow statements.
                            Open

                                        } else if(generalPostgresExp.exec(err) || syntaxErrorExp.exec(err) || tilerError.exec(err)) {
                                          var error = 'sqlError';
                                          if (webMercatorErrorExp.exec(err)) {
                                            error = 'sqlNoMercator';
                                            err = _t("you should select the_geom_webmercator column");
                            Severity: Major
                            Found in lib/assets/javascripts/cartodb/table/mapview.js - About 45 mins to fix

                              Avoid deeply nested control flow statements.
                              Open

                                            if (webMercatorErrorExp.exec(err)) {
                                              err = _t("you should select the_geom_webmercator column");
                                              layers[layerIndex].trigger('sqlNoMercator', [err]);
                                            } else {
                                              layers[layerIndex].trigger('sqlParseError', [err]);
                              Severity: Major
                              Found in lib/assets/javascripts/cartodb/table/mapview.js - About 45 mins to fix

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

                                    var onBackgroundShown = function() {
                                
                                      $map.animate(
                                        { width: width, marginLeft: -Math.round(width/2) - 1, left: "50%" },
                                        { easing: "easeOutQuad", duration: 200, complete: onCanvasLandscapeStretched }
                                Severity: Major
                                Found in lib/assets/javascripts/cartodb/table/mapview.js and 1 other location - About 1 hr to fix
                                lib/assets/javascripts/cartodb/table/mapview.js on lines 930..937

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

                                    var onCanvasLandscapeStretched = function() {
                                
                                      $map.animate(
                                        { height: height, marginTop: -Math.round(height/2) + 23,  top:  "50%" },
                                        { easing: "easeOutQuad", duration: 200, complete: onCanvasPortraitStretched }
                                Severity: Major
                                Found in lib/assets/javascripts/cartodb/table/mapview.js and 1 other location - About 1 hr to fix
                                lib/assets/javascripts/cartodb/table/mapview.js on lines 898..905

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

                                  _toggleLegends: function() {
                                    if (this.map.get("legends")) {
                                      this._addLegends();
                                    } else {
                                      this._cleanLegends();
                                Severity: Major
                                Found in lib/assets/javascripts/cartodb/table/mapview.js and 3 other locations - About 55 mins to fix
                                lib/assets/javascripts/deep-insights/widgets/dropdown/widget-dropdown-view.js on lines 100..106
                                lib/assets/javascripts/deep-insights/widgets/histogram/chart.js on lines 749..755
                                lib/assets/javascripts/deep-insights/widgets/histogram/chart.js on lines 757..763

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

                                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

                                  hideDataLayer: function() {
                                    this.mapView.disableInteraction();
                                    this.layerDataView.setOpacity && this.layerDataView.setOpacity(0.5);
                                  },
                                Severity: Minor
                                Found in lib/assets/javascripts/cartodb/table/mapview.js and 1 other location - About 50 mins to fix
                                lib/assets/javascripts/cartodb/table/mapview.js on lines 1576..1579

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

                                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

                                  showDataLayer: function() {
                                    this.mapView.enableInteraction();
                                    this.layerDataView.setOpacity && this.layerDataView.setOpacity(1.0);
                                  },
                                Severity: Minor
                                Found in lib/assets/javascripts/cartodb/table/mapview.js and 1 other location - About 50 mins to fix
                                lib/assets/javascripts/cartodb/table/mapview.js on lines 1581..1584

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

                                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