gopheracademy/gcon

View on GitHub
assets/admin/global/plugins/amcharts/amstockcharts/plugins/export/export.js

Summary

Maintainability
F
7 mos
Test Coverage

File export.js has 2274 lines of code (exceeds 250 allowed). Consider refactoring.
Open

/*
Plugin Name: amCharts Export
Description: Adds export capabilities to amCharts products
Author: Benjamin Maertz, amCharts
Version: 1.3.3

    Function capture has 499 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

                capture: function( options, callback ) {
                    var i1;
                    var cfg = _this.deepMerge( _this.deepMerge( {}, _this.config.fabric ), options || {} );
                    var groups = [];
                    var offset = {

      Function createMenu has 225 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

                  createMenu: function( list, container ) {
                      var div;
      
                      function buildList( list, container ) {
                          var i1, i2, ul = document.createElement( "ul" );

        Function buildList has 199 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

                        function buildList( list, container ) {
                            var i1, i2, ul = document.createElement( "ul" );
                            for ( i1 = 0; i1 < list.length; i1++ ) {
                                var item = typeof list[ i1 ] === "string" ? {
                                    format: list[ i1 ]

          Function getChartData has 103 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

                      getChartData: function( options ) {
                          var cfg = _this.deepMerge( {
                              data: [],
                              titles: {},
                              dateFields: [],

            Function change has 96 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                                change: function( options, skipped, target ) {
                                    var cfg = _this.deepMerge( {}, options || {} );
                                    var state, i1, rgba;
                                    var current = target || _this.drawing.buffer.target;
                                    var objects = current ? current._objects ? current._objects : [ current ] : null;

              Function construct has 83 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                          construct: function() {
                              // ANNOTATION; MAP "DONE"
                              _this.drawing.handler.cancel = _this.drawing.handler.done;
              
                              // CHECK BLOB CONSTRUCTOR

                Function line has 69 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                                    line: function( options ) {
                                        var cfg = _this.deepMerge( {
                                            x1: ( _this.setup.fabric.width / 2 ) - ( _this.setup.fabric.width / 10 ),
                                            x2: ( _this.setup.fabric.width / 2 ) + ( _this.setup.fabric.width / 10 ),
                                            y1: ( _this.setup.fabric.height / 2 ),

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

                              toXLSX: function( options, callback ) {
                                  var cfg = _this.deepMerge( {
                                      name: "amCharts",
                                      dateFormat: _this.config.dateFormat || "dateObject",
                                      withHeader: true,

                    Function processData has 63 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                                processData: function( options ) {
                                    var cfg = _this.deepMerge( {
                                        data: [],
                                        titles: {},
                                        dateFields: [],

                      Function toByteArray has 55 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                                  toByteArray: function( options, callback ) {
                                      var cfg = _this.deepMerge( {
                                          // NUFFIN
                                      }, options || {} );
                                      var Arr = ( typeof Uint8Array !== 'undefined' ) ? Uint8Array : Array

                        Function gatherElements has 54 lines of code (exceeds 25 allowed). Consider refactoring.
                        Open

                                    gatherElements: function( group, cfg, images ) {
                                        var i1, i2;
                                        for ( i1 = 0; i1 < group.children.length; i1++ ) {
                                            var childNode = group.children[ i1 ];
                        

                          Function download has 53 lines of code (exceeds 25 allowed). Consider refactoring.
                          Open

                                      download: function( data, type, filename ) {
                                          // SAVE
                                          if ( window.saveAs && _this.setup.hasBlob ) {
                                              var blob = _this.toBlob( {
                                                  data: data,

                            Function toCSV has 44 lines of code (exceeds 25 allowed). Consider refactoring.
                            Open

                                        toCSV: function( options, callback ) {
                                            var row, col;
                                            var cfg = _this.deepMerge( {
                                                data: _this.getChartData( options ),
                                                delimiter: ",",

                              Function loadListeners has 43 lines of code (exceeds 25 allowed). Consider refactoring.
                              Open

                                          loadListeners: function() {
                                              function handleClone( clone ) {
                                                  if ( clone ) {
                                                      clone.set( {
                                                          top: clone.top + 10,

                                Function loadResource has 38 lines of code (exceeds 25 allowed). Consider refactoring.
                                Open

                                            loadResource: function( src, addons ) {
                                                var i1, exist, node, item, check, type;
                                                var url = src.indexOf( "//" ) != -1 ? src : [ _this.libs.path, src ].join( "" );
                                
                                                function callback() {

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

                                              deepMerge: function( a, b, overwrite ) {
                                                  var i1, v, type = b instanceof Array ? "array" : "object";
                                  
                                                  for ( i1 in b ) {
                                                      // PREVENT METHODS

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

                                                    function sheet_from_array_of_arrays( data, opts ) {
                                                        var ws = {};
                                                        var range = {
                                                            s: {
                                                                c: 10000000,

                                      Function toSVG has 35 lines of code (exceeds 25 allowed). Consider refactoring.
                                      Open

                                                  toSVG: function( options, callback ) {
                                                      var cfg = _this.deepMerge( {
                                                          reviver: function( string ) {
                                                              var matcher = new RegExp( /\bstyle=(['"])(.*?)\1/ );
                                                              var match = matcher.exec( string )[ 0 ].slice( 7, -1 );

                                        Function toArray has 34 lines of code (exceeds 25 allowed). Consider refactoring.
                                        Open

                                                    toArray: function( options, callback ) {
                                                        var row, col;
                                                        var cfg = _this.deepMerge( {
                                                            data: _this.getChartData( options ),
                                                            withHeader: false,

                                          Consider simplifying this complex logical expression.
                                          Open

                                                              if (
                                                                  ( a instanceof Object || a instanceof Array ) &&
                                                                  ( v instanceof Object || v instanceof Array ) &&
                                                                  !( v instanceof Function || v instanceof Date || _this.isElement( v ) ) &&
                                                                  i1 != "chart"

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

                                                        delay: function( options, callback ) {
                                                            var cfg = _this.deepMerge( {
                                                                delay: 3,
                                                                precision: 2
                                                            }, options || {} );

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

                                                                  add: function( options ) {
                                                                      var cfg = _this.deepMerge( {
                                                                          top: _this.setup.fabric.height / 2,
                                                                          left: _this.setup.fabric.width / 2
                                                                      }, options || {} );

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

                                                            migrateSetup: function( setup ) {
                                                                var cfg = {
                                                                    enabled: true,
                                                                    migrated: true,
                                                                    libs: {

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

                                                              toPRINT: function( options, callback ) {
                                                                  var i1;
                                                                  var cfg = _this.deepMerge( {
                                                                      delay: 1,
                                                                      lossless: false

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

                                                                getAngle: function( x1, y1, x2, y2 ) {
                                                                    var x = x2 - x1;
                                                                    var y = y2 - y1;
                                                                    var angle;
                                                                    if ( x == 0 ) {

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

                                                                      function b64ToByteArray( b64 ) {
                                                                          var i, j, l, tmp, placeHolders, arr
                                                      
                                                                          if ( b64.length % 4 > 0 ) {
                                                                              throw new Error( 'Invalid string. Length must be a multiple of 4' )

                                                        Avoid deeply nested control flow statements.
                                                        Open

                                                                                    if ( childNode.childNodes[ i2 ].tagName == "rect" ) {
                                                                                        props.fill = childNode.childNodes[ i2 ].getAttribute( "fill" );
                                                                                    }

                                                          Avoid deeply nested control flow statements.
                                                          Open

                                                                                          if ( isPanel ) {
                                                                                              offset.pY = _this.pxToNumber( isPanel.style.marginTop );
                                                                                              group.offset.y += offset.pY;
                                                          
                                                                                              // SCROLLBAR; OFFSET

                                                            Avoid deeply nested control flow statements.
                                                            Open

                                                                                                if ( current instanceof fabric.Group ) {
                                                                                                    if ( cfg.color || cfg.opacity ) {
                                                                                                        objects[ i1 ].set( {
                                                                                                            stroke: cfg.color
                                                                                                        } );

                                                              Avoid deeply nested control flow statements.
                                                              Open

                                                                                                  } else if ( String( g.paths[ i1 ].fill ).slice( 0, 3 ) == "url" ) {
                                                                                                      var PID = g.paths[ i1 ].fill.slice( 5, -1 );
                                                                                                      if ( group.patterns && group.patterns[ PID ] ) {
                                                                                                          g.paths[ i1 ].set( {
                                                                                                              fill: group.patterns[ PID ],

                                                                Avoid deeply nested control flow statements.
                                                                Open

                                                                                                        if ( group.clippings[ PID ] ) {
                                                                                                            var mask = group.clippings[ PID ].childNodes[ 0 ];
                                                                                                            var transform = g.paths[ i1 ].svg.getAttribute( "transform" ) || "translate(0,0)";
                                                                
                                                                                                            transform = transform.slice( 10, -1 ).split( "," );

                                                                  Avoid deeply nested control flow statements.
                                                                  Open

                                                                                                  if ( cfg.exportSelection ) {
                                                                                                      if ( value instanceof Date ) {
                                                                                                          if ( value < chart.startDate || value > chart.endDate ) {
                                                                                                              skip = true;
                                                                                                          }

                                                                    Avoid deeply nested control flow statements.
                                                                    Open

                                                                                                if ( isLegend ) {
                                                                                                    offset.pY += _this.pxToNumber( isPanel.style.height ) + _this.setup.chart.panelsSettings.panelSpacing;
                                                                    
                                                                                                    // SCROLLBAR; OFFSET
                                                                                                } else if ( isScrollbar ) {

                                                                      Avoid deeply nested control flow statements.
                                                                      Open

                                                                                                      if ( group.legend.position == "left" ) {
                                                                                                          offset.x += group.legend.width;
                                                                                                      } else if ( group.legend.position == "right" ) {
                                                                                                          group.offset.x += offset.width - group.legend.width;
                                                                                                      } else if ( group.legend.position == "top" ) {

                                                                        Avoid deeply nested control flow statements.
                                                                        Open

                                                                                                        for ( i3 = 0; i3 < panel.stockGraphs.length; i3++ ) {
                                                                                                            var graph = panel.stockGraphs[ i3 ];
                                                                        
                                                                                                            for ( i4 = 0; i4 < lookupFields.length; i4++ ) {
                                                                                                                if ( graph[ lookupFields[ i4 ] ] == fieldMap.toField ) {

                                                                          Avoid deeply nested control flow statements.
                                                                          Open

                                                                                                          if ( cfg.stringify ) {
                                                                                                              value = String( value );
                                                                                                          } else {
                                                                                                              value = value;
                                                                                                          }

                                                                            Avoid deeply nested control flow statements.
                                                                            Open

                                                                                                        if ( dataItem[ field ] ) {
                                                                                                            for ( i2 = 0; i2 < dataItem[ field ].length; i2++ ) {
                                                                                                                dataItem[ field ][ i2 ][ _this.setup.chart.categoryField ] = dataItem[ _this.setup.chart.categoryField ];
                                                                                                                cfg.data.push( dataItem[ field ][ i2 ] );
                                                                                                            }

                                                                              Avoid deeply nested control flow statements.
                                                                              Open

                                                                                                      for ( i1 = 0; i1 < _this.setup.chart.graphs.length; i1++ ) {
                                                                                                          var graph = _this.setup.chart.graphs[ i1 ];
                                                                              
                                                                                                          for ( i2 = 0; i2 < lookupFields.length; i2++ ) {
                                                                                                              var dataField = lookupFields[ i2 ];

                                                                                Avoid deeply nested control flow statements.
                                                                                Open

                                                                                                        if ( _this.setup.chart.categoryAxis ) {
                                                                                                            addField( _this.setup.chart.categoryField, _this.setup.chart.categoryAxis.title );
                                                                                                            cfg.dateFields.push( _this.setup.chart.categoryField );
                                                                                                        }

                                                                                  Avoid deeply nested control flow statements.
                                                                                  Open

                                                                                                                  if ( cfg.dataDateFormat && ( value instanceof String || typeof value == "string" ) ) {
                                                                                                                      value = AmCharts.stringToDate( value, cfg.dataDateFormat );
                                                                                  
                                                                                                                  // CONVERT TIMESTAMP TO DATE OBJECT
                                                                                                                  } else if ( cfg.dateFormat && ( value instanceof Number || typeof value == "number" ) ) {

                                                                                    Avoid deeply nested control flow statements.
                                                                                    Open

                                                                                                                            if ( g.paths[ i1 ].fill.type == "radial" ) {
                                                                                                                                g.paths[ i1 ].fill.coords.r2 = g.paths[ i1 ].fill.coords.r1 * -1;
                                                                                                                                g.paths[ i1 ].fill.coords.r1 = 0;
                                                                                                                            }

                                                                                      Avoid deeply nested control flow statements.
                                                                                      Open

                                                                                                                      if ( type == "shapes" ) {
                                                                                                                          var io = items[ i2 ].indexOf( "//" ) == -1;
                                                                                                                          var url = ( io ? _this.config.path + "shapes/" : "" ) + items[ i2 ];
                                                                                      
                                                                                                                          tmp.action = "add";

                                                                                        Avoid deeply nested control flow statements.
                                                                                        Open

                                                                                                                        for ( i3 = 0; i3 < graph.dataSet.fieldMappings.length; i3++ ) {
                                                                                                                            var fieldMap = graph.dataSet.fieldMappings[ i3 ];
                                                                                                                            var uid = graph.dataSet.id + "_" + fieldMap.toField;
                                                                                        
                                                                                                                            if ( i2 < cfg.data.length ) {

                                                                                          Avoid deeply nested control flow statements.
                                                                                          Open

                                                                                                                          if ( title in tmp ) {
                                                                                                                              title += [ "( ", uniqueField, " )" ].join( "" );
                                                                                                                          }

                                                                                            Avoid deeply nested control flow statements.
                                                                                            Open

                                                                                                                            if ( cfg.dateFormat && cfg.dateFormat != "dateObject" && value instanceof Date ) {
                                                                                                                                value = AmCharts.formatDate( value, cfg.dateFormat );
                                                                                                                            }

                                                                                              Avoid deeply nested control flow statements.
                                                                                              Open

                                                                                                                          for ( i2 = 0; i2 < lookupFields.length; i2++ ) {
                                                                                                                              var dataField = lookupFields[ i2 ];
                                                                                                                              var graphField = graph[ dataField ];
                                                                                                                              var title = graph.title;
                                                                                              

                                                                                                Avoid deeply nested control flow statements.
                                                                                                Open

                                                                                                                                        if ( g.paths[ i1 ].textAlign == "left" ) {
                                                                                                                                            g.paths[ i1 ].set( {
                                                                                                                                                left: bb.left + ( g.paths[ i1 ].width / 2 )
                                                                                                                                            } );
                                                                                                                                        } else {

                                                                                                  Avoid deeply nested control flow statements.
                                                                                                  Open

                                                                                                                              if ( _this.drawing.handler[ action ] instanceof Function ) {
                                                                                                                                  item.action = action;
                                                                                                                                  item.click = ( function( item ) {
                                                                                                                                      return function() {
                                                                                                                                          this.drawing.handler[ item.action ]( item );

                                                                                                    Consider simplifying this complex logical expression.
                                                                                                    Open

                                                                                                                                            if ( group.clippings[ PID ] ) {
                                                                                                                                                var mask = group.clippings[ PID ].childNodes[ 0 ];
                                                                                                                                                var transform = g.paths[ i1 ].svg.getAttribute( "transform" ) || "translate(0,0)";
                                                                                                    
                                                                                                                                                transform = transform.slice( 10, -1 ).split( "," );

                                                                                                      Avoid too many return statements within this function.
                                                                                                      Open

                                                                                                                              return code - UPPER

                                                                                                        Avoid too many return statements within this function.
                                                                                                        Open

                                                                                                                                return code - LOWER + 26

                                                                                                          TODO found
                                                                                                          Open

                                                                                                                                  // TODO; WAIT FOR TSPAN SUPPORT FROM FABRICJS SIDE

                                                                                                          TODO found
                                                                                                          Open

                                                                                                                                                  // PATTERN; TODO: DISTINGUISH OPACITY TYPES

                                                                                                          TODO found
                                                                                                          Open

                                                                                                                                          // OPACITY; TODO: DISTINGUISH OPACITY TYPES

                                                                                                          TODO found
                                                                                                          Open

                                                                                                                                  // HIDE HIDDEN ELEMENTS; TODO: FIND A BETTER WAY TO HANDLE THAT

                                                                                                          TODO found
                                                                                                          Open

                                                                                                                                              // TODO; WAIT FOR TSPAN SUPPORT FROM FABRICJS SIDE

                                                                                                          HACK found
                                                                                                          Open

                                                                                                                              // THIS IS JUST A CHEAP HACK TO NOT DO INDEXOF TWICE

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

                                                                                                          ( function() {
                                                                                                              AmCharts[ "export" ] = function( chart, config ) {
                                                                                                                  var _this = {
                                                                                                                      name: "export",
                                                                                                                      version: "1.3.3",
                                                                                                          assets/admin/global/plugins/amcharts/amcharts/plugins/export/export.js on lines 67..2993
                                                                                                          assets/admin/global/plugins/amcharts/ammap/plugins/export/export.js on lines 67..2993

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

                                                                                                          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                                                                                                          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                                                                                                          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                                                                                                          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                                                                                                          Refactorings

                                                                                                          Further Reading

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

                                                                                                          if ( !AmCharts.translations[ "export" ][ "en" ] ) {
                                                                                                              AmCharts.translations[ "export" ][ "en" ] = {
                                                                                                                  "fallback.save.text": "CTRL + C to copy the data into the clipboard.",
                                                                                                                  "fallback.save.image": "Rightclick -> Save picture as... to save the image.",
                                                                                                          
                                                                                                          assets/admin/global/plugins/amcharts/amcharts/plugins/export/export.js on lines 32..62
                                                                                                          assets/admin/global/plugins/amcharts/ammap/plugins/export/export.js on lines 32..62

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

                                                                                                          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