@@ -27,6 +27,7 @@ var graph_time_multiplier = 0;
27
27
var graph_interval_id = null ;
28
28
var fullCycleTime = 4294967296 / 80000000 ;
29
29
var graph_labels = null ;
30
+ var graph_csv_data = new Array ;
30
31
31
32
var console_header_arrived = false ;
32
33
var console_header = null ;
@@ -581,16 +582,21 @@ function graph_new_data(stream) {
581
582
} else {
582
583
graph_temp_data [ row ] . unshift ( ts + graph_time_multiplier -
583
584
graph_timestamp_start + graph_timestamp_restart ) ;
584
- for ( j = 2 ; j < graph_temp_data [ row ] . length ; j ++ ) {
585
+ var graph_csv_temp = ( Math . round ( graph_temp_data [ row ] [ 0 ] * 10000 ) / 10000 ) + ',' ;
586
+ for ( var j = 2 ; j < graph_temp_data [ row ] . length ; j ++ ) {
587
+ graph_csv_temp += graph_temp_data [ row ] [ j ] + ',' ;
585
588
graph_data . series [ j - 2 ] . push ( {
586
589
x : graph_temp_data [ row ] [ 0 ] ,
587
590
y : graph_temp_data [ row ] [ j ] || null
588
591
} ) ;
589
592
if ( graph_temp_data [ row ] [ 0 ] > graph_options . sampleTotal )
590
593
graph_data . series [ j - 2 ] . shift ( ) ;
591
594
}
595
+ graph_csv_data . push ( graph_csv_temp . slice ( 0 , - 1 ) . split ( ',' ) ) ;
592
596
}
593
597
598
+
599
+
594
600
/*
595
601
var read_serial_to_div = '';
596
602
for (var l = 0; l < graph_temp_data[row].length; l++)
@@ -616,6 +622,8 @@ function graph_reset() {
616
622
graph_interval_id = null ;
617
623
graph_temp_data = null ;
618
624
graph_temp_data = new Array ;
625
+ graph_csv_data = null ;
626
+ graph_csv_data = new Array ;
619
627
graph_data = {
620
628
series : [ // add more here for more possible lines...
621
629
[ ] ,
@@ -697,19 +705,58 @@ function downloadGraph() {
697
705
} ) ;
698
706
}
699
707
708
+ function downloadCSV ( ) {
709
+ utils . prompt ( "Download Graph data as CSV - Filename:" , 'graph_data' + idProject , function ( value ) {
710
+ if ( value ) {
711
+
712
+ // put all of the pieces together into a downloadable file
713
+ var saveData = ( function ( ) {
714
+ var a = document . createElement ( "a" ) ;
715
+ document . body . appendChild ( a ) ;
716
+ a . style = "display: none" ;
717
+ return function ( data , fileName ) {
718
+ var blob = new Blob ( [ data ] , { type : "octet/stream" } ) ;
719
+ var url = window . URL . createObjectURL ( blob ) ;
720
+ a . href = url ;
721
+ a . download = fileName ;
722
+ a . click ( ) ;
723
+ window . URL . revokeObjectURL ( url ) ;
724
+ } ;
725
+ } ( ) ) ;
726
+ var graph_csv_temp = graph_csv_data . join ( '\n' ) ;
727
+ var idx1 = graph_csv_temp . indexOf ( '\n' ) + 1 ;
728
+ var idx2 = graph_csv_temp . indexOf ( '\n' , idx1 + 1 ) ;
729
+ saveData ( graph_csv_temp . substring ( 0 , idx1 ) + graph_csv_temp . substring ( idx2 + 1 , graph_csv_temp . length - 1 ) , value + '.csv' ) ;
730
+ }
731
+ } ) ;
732
+ }
733
+
700
734
function graph_new_labels ( ) {
735
+ var graph_csv_temp = '' ;
701
736
var labelsvg = '<svg width="60" height="300">' ;
737
+ graph_csv_temp += '"time",' ;
702
738
for ( var t = 0 ; t < graph_labels . length ; t ++ ) {
703
- labelsvg += '<g id="labelgroup' + ( t + 1 ) + '" transform="translate(0,' + ( t * 25 + 35 ) + ')">' ;
704
- labelsvg += '<path id="label' + ( t + 1 ) + '" class="ct-marker-' + ( t + 1 ) ;
705
- labelsvg += '" d="M0,6 L5,0 58,0 59,1 60,2 60,10 59,11 58,12 5,12 Z"/>' ;
706
- labelsvg += '<text id="label' + ( t + 1 ) + 'text" x="6" y="10" style="font-family:' ;
707
- labelsvg += 'Arial;font-size: 10px;fill:#fff; font-weight:bold;">' + graph_labels [ t ] + '</text></g>' ;
739
+ labelsvg += '<g id="labelgroup' + ( t + 1 ) + '" transform="translate(0,' + ( t * 30 + 25 ) + ')">' ;
740
+ labelsvg += '<rect x="0" y = "0" width="60" height="26" rx="3" ry="3" id="label' + ( t + 1 ) + '" ' ;
741
+ labelsvg += 'style="stroke:1px;stroke-color:blue;" class="ct-marker-' + ( t + 1 ) + '"/><rect x="3" y = "12"' ;
742
+ labelsvg += 'width="54" height="11" rx="3" ry="3" id="value' + ( t + 1 ) + 'bkg" style="fill:rgba' ;
743
+ labelsvg += '(255,255,255,.7);stroke:none;"/><text id="label' + ( t + 1 ) + 'text" x="3" ' ;
744
+ labelsvg += 'y="9" style="font-family:Arial;font-size: 9px;fill:#fff;font-weight:bold;">' + graph_labels [ t ] ;
745
+ labelsvg += '</text><text id="gValue' + ( t + 1 ) + '" x="5" y="21" style="align:right;' ;
746
+ labelsvg += 'font-family:Arial;font-size: 10px;fill:#000;"></text></g>' ;
747
+ graph_csv_temp += '"' + graph_labels [ t ] . replace ( / " / g, '_' ) + '",' ;
708
748
}
709
749
labelsvg += '</svg>' ;
750
+ graph_csv_data . push ( graph_csv_temp . slice ( 0 , - 1 ) ) ;
710
751
$ ( '#serial_graphing_labels' ) . html ( labelsvg ) ;
711
752
}
712
753
713
754
function graph_update_labels ( ) {
714
-
755
+ var row = graph_temp_data . length - 1 ;
756
+ if ( graph_temp_data [ row ] ) {
757
+ var col = graph_temp_data [ row ] . length ;
758
+ for ( var w = 2 ; w < col ; w ++ ) {
759
+ document . getElementById ( 'gValue' + ( w - 1 ) . toString ( 10 ) ) . textContent = graph_temp_data [ row ] [ w ] ;
760
+ }
761
+ }
715
762
}
0 commit comments