amcharts / export

Apache License 2.0
56 stars 33 forks source link

Chrome Print #59

Closed Egoryk closed 6 years ago

Egoryk commented 7 years ago

Loss of context after printing or after printing is canceled. Version 58.0.3029.96 (64-bit)

maertz commented 7 years ago

Disable "autoClose" to keep the annotation context.

{
    "enabled": true,
    "drawing": {
      "autoClose": false
    }
}
Egoryk commented 7 years ago

Unfortunately did not help. Are there any other ideas?

maertz commented 7 years ago

Please ensure there is no cached configuration, you can disable the cache temporary within the network tab in your developer console. If the issue is still there, send me a sample to reproduce the issue.

Egoryk commented 7 years ago
chart.export = {
  enabled: true,
  "pageOrientation": "landscape",
  "pageOrigin": false,
  "drawing": {
    "autoClose": false
  },
  "menu": [ {
    "class": "export-main",
    "label": "Export",
    "menu": [ {
      "label": translationMap[ "menu.label.save.image" ],
      "menu": [ "PNG", "JPG", "PDF" ]
    }, {
      "label": translationMap[ "menu.label.save.data" ],
      "menu": [ {
          "label": "CSV",
          "click": function() {
            //some code
          }
        }, {
          label: "XLSX",
          "click": function() {
            //some code
          }
        }

      ]
    }, "PRINT" ]
  } ]
};

also after export to csv or xlsx the menu item stay still active. Print is default

jigargaglani commented 7 years ago

Was this issue resolved ?. I am facing the same issue including no preview for print as well. Here is my config for chart.


{
                        "type": "serial",
                        "theme": "light",
                        "autoResize": true,
                        "marginRight": 0,
                        "marginLeft": 40,
                        "autoMarginOffset": 20,
                        //"mouseWheelZoomEnabled": true,
                        "dataDateFormat": "YYYY-MM-DD",
                        "valueAxes": [{
                            "id": "v1",
                            "axisAlpha": 0,
                            "position": "left",
                            "ignoreAxisWidth": false
                        }],
                        "legend": {
                            "enabled": true
                        },
                        "balloon": {
                            "borderThickness": 1,
                            "shadowAlpha": 0
                        },
                        "graphs": [],
                        "chartScrollbar": {
                            "graph": "g1",
                            "enabled": false,

                            "oppositeAxis": false,
                            "offset": 30,
                            "scrollbarHeight": 80,
                            "backgroundAlpha": 0,
                            "selectedBackgroundAlpha": 0.1,
                            "selectedBackgroundColor": "#888888",
                            "graphFillAlpha": 0,
                            "graphLineAlpha": 0.5,
                            "selectedGraphFillAlpha": 0,
                            "selectedGraphLineAlpha": 1,
                            "autoGridCount": true,
                            "color": "#AAAAAA"
                        },
                        "chartCursor": {
                            "pan": true,
                            "valueLineEnabled": true,
                            "valueLineBalloonEnabled": true,
                            "cursorAlpha": 1,
                            "cursorColor": "#258cbb",
                            "limitToGraph": "g1",
                            "valueLineAlpha": 0.2,
                            "categoryBalloonDateFormat": "JJ:NN, DD MMMM"
                            //"valueZoomable": true
                        },
                        "valueScrollbar": {
                            "oppositeAxis": false,
                            "offset": 50,
                            "enabled": false,

                            "scrollbarHeight": 10
                        },
                        "categoryField": "date",
                        "categoryAxis": {
                            "parseDates": true,
                            "minPeriod": "hh",
                            "dashLength": 1,
                            "minorGridEnabled": true
                        },
                        "export": {
                            "enabled": true,
                            "pageOrigin": false,
                            "drawing": {
                                "autoClose": false
                            }
                        },
                        "path": NAVIGATION_URL + "Scripts/amcharts/"
                        // "dataProvider": value
                    }
Egoryk commented 7 years ago

no( Even here https://live.amcharts.com/ create a chart and print a blank page on Chrome

Egoryk commented 7 years ago

Do you have other ways to solve this situation?

maertz commented 7 years ago

Unfortunately no but I'm working on it. I'll keep you updated.

valdepeace commented 7 years ago

One solution for me in angularjs 1.5 in directive with chrome Versión 59.0.3071.115 :

chart.export.menu[0].menu[1].click = function () {
                                this.capture({},function(){
                                    var i1;
                                    var cfg = {
                                        delay: 2,
                                        lossless: false
                                    };
                                    var data = this.toImage( cfg );
                                    var states = [];
                                    var items = document.body.childNodes;
                                    var scroll = document.documentElement.scrollTop || document.body.scrollTop;

                                    data.setAttribute( "style", "width: 100%; max-height: 100%;" );

                                    for ( i1 = 0; i1 < items.length; i1++ ) {
                                        if ( isElement( items[ i1 ] ) ) {
                                            states[ i1 ] = items[ i1 ].style.display;
                                            items[ i1 ].style.display = "none";
                                        }
                                    }

                                    document.body.appendChild( data );

                                  $timeout( function() {
                                       $window.print();
                                        document.body.removeChild( data );
                                        document.documentElement.scrollTop = document.body.scrollTop = scroll;
                                        for ( i1 = 0; i1 < items.length; i1++ ) {
                                            if ( isElement( items[ i1 ] ) ) {
                                                items[ i1 ].style.display = states[ i1 ];
                                            }
                                        }
                                    }, cfg.delay );

                                    return true;
                                })
....
 /**
                 * Checks if given argument is a valid node
                 */
                function isElement( thingy ) {
                    return thingy instanceof Object && thingy && thingy.nodeType === 1;
                }

"$window.print()" in "$timeout" have time refresh DOM and continue display DOM original, as DOM original not have time refresh, so "$window.print()" print old DOM and when i close window print refresh with original DOM. I hope it works for you.

maertz commented 7 years ago

I was not able to reproduce such behaviour, even with throttling the actual CPU speed but following update should make it work. It simply changed the delay to 1 second instead of the default of 10 milliseconds and added the delay also in front of the "print" method.

/**
 * Generates an image; hides all elements on page to trigger native print method
 */
toPRINT: function( options, callback ) {
  var i1;
  var cfg = _this.deepMerge( {
    delay: 1,
    lossless: false
  }, options || {} );
  var data = _this.toImage( cfg );
  var states = [];
  var items = document.body.childNodes;
  var scroll = document.documentElement.scrollTop || document.body.scrollTop;

  data.setAttribute( "style", "width: 100%; max-height: 100%;" );

  for ( i1 = 0; i1 < items.length; i1++ ) {
    if ( _this.isElement( items[ i1 ] ) ) {
      states[ i1 ] = items[ i1 ].style.display;
      items[ i1 ].style.display = "none";
    }
  }

  document.body.appendChild( data );

  // CONVERT TO SECONDS
  cfg.delay *= 1000;

  // IOS EXCEPTION DELAY MIN. 1 SECOND
  var isIOS = /iPad|iPhone|iPod/.test( navigator.userAgent ) && !window.MSStream;
  if ( isIOS && cfg.delay < 1000 ) {
    cfg.delay = 1000;
  }

  // DELAY WHOLE PROCESS
  setTimeout(function() {
    // PRINT
    window.print();

    setTimeout( function() {
      for ( i1 = 0; i1 < items.length; i1++ ) {
        if ( _this.isElement( items[ i1 ] ) ) {
          items[ i1 ].style.display = states[ i1 ];
        }
      }
      document.body.removeChild( data );
      document.documentElement.scrollTop = document.body.scrollTop = scroll;

      // TRIGGER CALLBACK
      _this.handleCallback( callback, data, cfg );
    }, cfg.delay );
  }, cfg.delay);

  return data;
}

Looks like the browser doesn't ensure the render state of the DOM elements before starting the printing process. As @Negrero mentioned the old state gets captured instead of the new one, therefore this behaviour is most likely shown on slower computer.

export.js v1.4.69 - unreleased update

Egoryk commented 6 years ago

After the print is canceled, I have a blank page. Increasing the delay did not help