1/**
2 * This is a sample chart export config file. It is provided as a reference on
3 * how miscelaneous items in export menu can be used and set up.
4 *
5 * Please refer to README.md for more information.
6 */
7
8/**
9 * PDF-specfic configuration
10 */
11AmCharts.exportDrawingMenu = [ {
12  class: "export-drawing",
13  label: "Export",
14  menu: [ {
15    label: "Undo",
16    click: function() {
17      this.drawing.undo();
18    }
19  }, {
20    label: "Redo",
21    click: function() {
22      this.drawing.redo();
23    }
24  }, {
25    label: "Cancel",
26    click: function() {
27      this.drawing.done();
28    }
29  }, {
30    label: "Save",
31    menu: [ {
32      label: "JPG",
33      click: function() {
34        this.drawing.done();
35        this.toJPG( {}, function( data ) {
36          this.download( data, "image/jpg", "amCharts.jpg" );
37        } );
38      }
39    }, {
40      label: "PNG",
41      click: function() {
42        this.drawing.done();
43        this.toPNG( {}, function( data ) {
44          this.download( data, "image/png", "amCharts.png" );
45        } );
46      }
47    }, {
48      label: "PDF",
49      click: function() {
50        this.drawing.done();
51        this.toPDF( {}, function( data ) {
52          this.download( data, "application/pdf", "amCharts.pdf" );
53        } );
54      }
55    }, {
56      label: "SVG",
57      click: function() {
58        this.drawing.done();
59        this.toSVG( {}, function( data ) {
60          this.download( data, "text/xml", "amCharts.svg" );
61        } );
62      }
63    } ]
64  } ]
65} ];
66
67
68/**
69 * Define main universal config
70 */
71AmCharts.exportCFG = {
72  enabled: true,
73  libs: {
74    path: "../libs/"
75  },
76  menu: [ {
77    class: "export-main",
78    label: "Export",
79    menu: [
80      /*
81       ** DRAWING
82       */
83      {
84        label: "Draw",
85        click: function() {
86          this.capture( {
87            action: "draw",
88            freeDrawingBrush: {
89              width: 2,
90              color: "#000000",
91              shadow: {
92                color: "rgba(0,0,0,0.3)",
93                blur: 10,
94                offsetX: 3,
95                offsetY: 3
96              }
97            }
98          }, function() {
99            this.createMenu( AmCharts.exportDrawingMenu );
100          } );
101        }
102      },
103
104      /*
105       ** DELAYED EXPORT
106       */
107      {
108        label: "Delayed",
109        click: function() {
110          var _this = this;
111          var delay = 2;
112          var timer = 0;
113          var starttime = Number( new Date() );
114          var menu = this.createMenu( [ {
115            label: "Capturing: " + delay,
116            click: function() {
117              clearTimeout( timer );
118              this.createMenu( this.defaults.menu );
119            }
120          } ] );
121          var label = menu.getElementsByTagName( "span" )[ 0 ];
122
123          timer = setInterval( function() {
124            diff = ( delay - ( Number( new Date() ) - starttime ) / 1000 );
125            label.innerHTML = "Capturing: " + ( diff < 0 ? 0 : diff ).toFixed( 2 );
126
127            if ( diff <= 0 ) {
128              clearTimeout( timer );
129              _this.capture( {}, function() {
130                this.toJPG( {}, function( data ) {
131                  this.download( data, "image/jpg", "amCharts.jpg" );
132                } );
133                this.createMenu( this.defaults.menu );
134              } );
135            }
136          }, 10 );
137        }
138      },
139
140      /*
141       ** DELAYED EXPORT WITH DRAWING
142       */
143      {
144        label: "Delayed Draw",
145        click: function() {
146          var _this = this;
147          var delay = 2;
148          var timer = 0;
149          var starttime = Number( new Date() );
150          var menu = this.createMenu( [ {
151            label: "Capturing: " + delay,
152            click: function() {
153              clearTimeout( timer );
154              this.createMenu( this.defaults.menu );
155            }
156          } ] );
157          var label = menu.getElementsByTagName( "span" )[ 0 ];
158
159          timer = setInterval( function() {
160            var diff = ( delay - ( Number( new Date() ) - starttime ) / 1000 );
161            label.innerHTML = "Capturing: " + ( diff < 0 ? 0 : diff ).toFixed( 2 );
162
163            if ( diff <= 0 ) {
164              clearTimeout( timer );
165              _this.capture( {
166                action: "draw"
167              }, function() {
168                _this.createMenu( AmCharts.exportDrawingMenu );
169              } );
170            }
171          }, 10 );
172        }
173      },
174
175      /*
176       ** DOWNLOAD
177       */
178      {
179        label: "Download",
180        menu: [ {
181          label: "JPG",
182          click: function() {
183            this.capture( {}, function() {
184              this.toJPG( {}, function( data ) {
185                this.download( data, "image/jpg", "amCharts.jpg" );
186              } );
187            } );
188          }
189        }, {
190          label: "PNG",
191          click: function() {
192            this.capture( {}, function() {
193              this.toPNG( {}, function( data ) {
194                this.download( data, "image/png", "amCharts.png" );
195              } );
196            } );
197          }
198        }, {
199          label: "PDF",
200          click: function() {
201            this.capture( {}, function() {
202              this.toPDF( {}, function( data ) {
203                this.download( data, "application/pdf", "amCharts.pdf" );
204              } );
205            } );
206          }
207        }, {
208          label: "PDF + data",
209          click: function() {
210            this.capture( {}, function() {
211              var tableData = this.setup.chart.dataProvider;
212              var tableBody = this.toArray( {
213                withHeader: true,
214                data: tableData
215              } );
216
217              var tableWidths = [];
218              var content = [ {
219                image: "reference",
220                fit: [ 523.28, 769.89 ]
221              } ];
222
223              for ( i in tableBody[ 0 ] ) {
224                tableWidths.push( "*" );
225              }
226
227              content.push( {
228                table: {
229                  headerRows: 1,
230                  widths: tableWidths,
231                  body: tableBody
232                },
233                layout: 'lightHorizontalLines'
234              } );
235
236              this.toPDF( {
237                content: content
238              }, function( data ) {
239                this.download( data, "application/pdf", "amCharts.pdf" );
240              } );
241            } );
242          }
243        }, {
244          label: "SVG",
245          click: function() {
246            this.capture( {}, function() {
247              this.toSVG( {}, function( data ) {
248                this.download( data, "text/xml", "amCharts.svg" );
249              } );
250            } );
251          }
252        }, {
253          label: "CSV",
254          click: function() {
255            this.toCSV( {}, function( data ) {
256              this.download( data, "text/plain", "amCharts.csv" );
257            } );
258          }
259        }, {
260          label: "JSON",
261          click: function() {
262            this.toJSON( {}, function( data ) {
263              this.download( data, "text/plain", "amCharts.json" );
264            } );
265          }
266        }, {
267          label: "XLSX",
268          click: function() {
269            this.toXLSX( {}, function( data ) {
270              this.download( data, "application/octet-stream", "amCharts.xlsx" );
271            } );
272          }
273        } ]
274      }
275    ]
276  } ]
277};