11define ( [ 'plotly-js/plotly.min' , 'd3' ] , function ( Plotly , d3 ) {
22 'use strict' ;
33 return {
4- plotData : function ( plotId , data , offset ) {
5- // extent returns array: [min, max]
6- var maxXs = Object . keys ( data ) . map ( function ( key ) {
7- return d3 . extent ( data [ key ] . data , function ( xy ) { return xy [ 0 ] - offset ; } ) [ 1 ] ;
8- } ) ;
9- var maxYs = Object . keys ( data ) . map ( function ( key ) {
10- return d3 . extent ( data [ key ] . data , function ( xy ) { return xy [ 1 ] ; } ) [ 1 ] ;
11- } ) ;
12- var xdomain = d3 . max ( maxXs ) ;
13- var ydomain = d3 . max ( maxYs ) ;
4+ plotData : function ( plotId , data ) {
5+ // extent returns array: [min, max]
6+ var maxXs = Object . keys ( data ) . map ( function ( key ) {
7+ return d3 . extent ( data [ key ] . data , function ( xy ) { return xy [ 0 ] ; } ) [ 1 ] ;
8+ } ) ;
9+ var maxYs = Object . keys ( data ) . map ( function ( key ) {
10+ return d3 . extent ( data [ key ] . data , function ( xy ) { return xy [ 1 ] ; } ) [ 1 ] ;
11+ } ) ;
12+ var xdomain = d3 . max ( maxXs ) ;
13+ var ydomain = d3 . max ( maxYs ) ;
1414
15- var pdata = [ ] ;
15+ var pdata = [ ] ;
1616
17- Object . keys ( data ) . map ( function ( key ) {
18- pdata . push ( {
19- x : data [ key ] . data . map ( function ( xy ) { return new Date ( xy [ 0 ] ) ; } ) ,
20- y : data [ key ] . data . map ( function ( xy ) { return xy [ 1 ] ; } ) ,
21- mode : 'lines' ,
17+ Object . keys ( data ) . map ( function ( key ) {
18+ pdata . push ( {
19+ x : data [ key ] . data . map ( function ( xy ) { return new Date ( xy [ 0 ] ) ; } ) ,
20+ y : data [ key ] . data . map ( function ( xy ) { return xy [ 1 ] ; } ) ,
21+ mode : 'lines' ,
2222 type : 'scatter' ,
23- name : key ,
23+ name : key ,
2424 marker : {
2525 maxdisplayed : 1000 // ,
2626 /*
27- color: "rgb(164, 194, 244)",
28- size: 12,
29- line: {
30- color: "white",
31- width: 0.5
32- }
33- */
27+ color: "rgb(164, 194, 244)",
28+ size: 12,
29+ line: {
30+ color: "white",
31+ width: 0.5
32+ }
33+ */
3434 }
35- } ) ;
36- } ) ;
35+ } ) ;
36+ } ) ;
3737
38- var layout = {
39- xaxis : {
40- title : 'Time (s)'
41- } ,
38+ var layout = {
39+ xaxis : {
40+ title : 'Time (s)'
41+ } ,
4242 legend : {
4343 xanchor : 'right'
4444 } ,
@@ -52,66 +52,66 @@ define(['plotly-js/plotly.min', 'd3'], function(Plotly,d3) {
5252 hovermode : 'closest' ,
5353 autosize : true ,
5454 showlegend : true
55- } ;
55+ } ;
5656
57- Plotly . plot ( plotId , pdata , layout , {
58- modeBarButtons : [ [ {
59- 'name' : 'toImage' ,
60- 'title' : 'Download plot as png' ,
61- 'icon' : Plotly . Icons . camera ,
62- 'click' : function ( gd ) {
63- var format = 'png' ;
64- var id = '#' + plotId ;
57+ Plotly . plot ( plotId , pdata , layout , {
58+ modeBarButtons : [ [ {
59+ 'name' : 'toImage' ,
60+ 'title' : 'Download plot as png' ,
61+ 'icon' : Plotly . Icons . camera ,
62+ 'click' : function ( gd ) {
63+ var format = 'png' ;
64+ var id = '#' + plotId ;
6565
66- /*
67- Plotly.Lib.notifier('Taking snapshot - this may take a few seconds', 'long');
66+ /*
67+ Plotly.Lib.notifier('Taking snapshot - this may take a few seconds', 'long');
6868
69- if(Plotly.Lib.isIE()) {
70- Plotly.Lib.notifier('IE only supports svg. Changing format to svg.', 'long');
71- format = 'svg';
72- }
73- */
74-
75- Plotly . downloadImage ( gd , {
76- 'format' : format ,
77- 'width' : $ ( id ) . width ( ) ,
78- 'width ' : $ ( id ) . width ( ) ,
79- } )
80- . then ( function ( filename ) {
81- //Plotly.Lib.notifier('Snapshot succeeded - ' + filename, 'long');
82- } )
83- . catch ( function ( ) {
84- //Plotly.Lib.notifier('Sorry there was a problem downloading your snapshot!', 'long');
85- } ) ;
86- }
87- } ] , [
88- 'zoom2d' ,
89- 'pan2d' ,
90- 'select2d' ,
91- 'lasso2d' ,
92- 'zoomIn2d' ,
93- 'zoomOut2d' ,
94- 'autoScale2d' ,
95- 'resetScale2d' ,
96- 'hoverClosestCartesian' ,
97- 'hoverCompareCartesian'
98- ] ] ,
99- /*
100- modeBarButtonsToRemove: ['toImage', 'sendDataToCloud'],
101- modeBarButtonsToAdd: [{
102- name: 'toImage2',
103- icon: Plotly.Icons.camera,
104- click: function(gd) {
105- console.log($('#'+plotId).height());
106- console.log($('#'+plotId).width());
107- Plotly.downloadImage(gd, {
108- height: $('#'+plotId).height(),
109- width: $('#'+plotId).width(),
110- });
111- }
112- }],
113- */
114- } ) ;
115- }
69+ if(Plotly.Lib.isIE()) {
70+ Plotly.Lib.notifier('IE only supports svg. Changing format to svg.', 'long');
71+ format = 'svg';
72+ }
73+ */
74+
75+ Plotly . downloadImage ( gd , {
76+ 'format' : format ,
77+ 'width' : $ ( id ) . width ( ) ,
78+ 'height ' : $ ( id ) . height ( ) ,
79+ } )
80+ . then ( function ( filename ) {
81+ //Plotly.Lib.notifier('Snapshot succeeded - ' + filename, 'long');
82+ } )
83+ . catch ( function ( ) {
84+ //Plotly.Lib.notifier('Sorry there was a problem downloading your snapshot!', 'long');
85+ } ) ;
86+ }
87+ } ] , [
88+ 'zoom2d' ,
89+ 'pan2d' ,
90+ 'select2d' ,
91+ 'lasso2d' ,
92+ 'zoomIn2d' ,
93+ 'zoomOut2d' ,
94+ 'autoScale2d' ,
95+ 'resetScale2d' ,
96+ 'hoverClosestCartesian' ,
97+ 'hoverCompareCartesian'
98+ ] ] ,
99+ /*
100+ modeBarButtonsToRemove: ['toImage', 'sendDataToCloud'],
101+ modeBarButtonsToAdd: [{
102+ name: 'toImage2',
103+ icon: Plotly.Icons.camera,
104+ click: function(gd) {
105+ console.log($('#'+plotId).height());
106+ console.log($('#'+plotId).width());
107+ Plotly.downloadImage(gd, {
108+ height: $('#'+plotId).height(),
109+ width: $('#'+plotId).width(),
110+ });
111+ }
112+ }],
113+ */
114+ } ) ;
115+ }
116116 } ;
117117} ) ;
0 commit comments