@@ -21,35 +21,89 @@ class Ftp extends Component {
2121 info : null ,
2222 isLoading : false ,
2323 error : null ,
24+ maxPoints : width / 2 ,
25+ x : null ,
26+ y : null
2427 } ;
28+ }
29+
30+ getXScale ( domain , advance ) {
31+ const plotLength = 5000000 ;
32+ // let initialTime = (new Date()).valueOf() * 1000; // Need microseconds
33+ let initialTime = null ;
34+ let x1 = null ;
35+ let x2 = null ;
36+
37+ if ( typeof domain === "number" ) {
38+ x1 = domain ;
39+ x2 = domain + plotLength ;
40+ } else {
41+ [ x1 , x2 ] = domain || [ null , null ] ;
42+ }
2543
26- this . date = new Date ( )
44+ if ( advance ) {
45+ // initialTime = x1 + ((x2 - x1) / (1 / advance));
46+ initialTime = advance ;
47+ } else {
48+ initialTime = x1 ;
49+ }
2750
28- this . x = scaleTime ( )
29- . domain ( [ 0 , width ] )
51+ return scaleLinear ( )
52+ . domain ( [ initialTime , initialTime + plotLength ] )
3053 . range ( [ 0 , width ] ) ;
31- this . y = scaleLinear ( )
32- . domain ( [ 0 , 60.2 ] )
54+ }
55+
56+ getYScale ( ) {
57+ return scaleLinear ( )
58+ . domain ( [ - 2 , 2 ] )
3359 . range ( [ height , 0 ] )
3460 . nice ( ) ;
3561 }
3662
3763 componentWillReceiveProps ( ) {
3864 const { data : newData , info : newInfo } = this . props . data ;
39-
40- // console.log(this.x(new Date(newData.timestamp)) + 390)
41- // console.log(this.y(newData.data)) ;
65+ const dataSize = newData . data . length / 2 ;
66+ let domainMin = null ;
67+ let domainMax = null ;
4268
4369 this . setState ( ( { data } ) => {
70+ const result = { info : newInfo } ;
4471 let combinedData = data . slice ( ) ; // Copy Array
45- combinedData . push ( { x : new Date ( newData . timestamp + 390 ) , y : newData . data } ) ;
46- if ( combinedData . length > width ) {
47- combinedData = combinedData . slice ( width / 4 ) ;
72+
73+ for ( let ii = 0 ; ii < dataSize ; ii ++ ) {
74+ combinedData . push ( {
75+ x : newData . data [ ii + dataSize ] ,
76+ y : newData . data [ ii ] ,
77+ } ) ;
78+ }
79+ // newData.data.forEach((datum, i) => {
80+ // combinedData.push({
81+ // // multiply by the frequency
82+ // x: microseconds + (i * 694),
83+ // y: datum
84+ // });
85+ // });
86+ result . data = combinedData ;
87+
88+
89+ if ( this . state . x === null || this . state . y === null ) {
90+ result . x = this . getXScale ( result . data [ 0 ] . x ) ;
91+ result . y = this . getYScale ( ) ;
92+ [ domainMin , domainMax ] = this . getXScale ( result . data [ 0 ] . x ) . domain ( ) ;
93+ } else {
94+ [ domainMin , domainMax ] = this . state . x . domain ( ) ;
4895 }
49- return {
50- data : combinedData ,
51- info : newInfo
96+
97+ if ( result . data [ result . data . length - 1 ] . x > domainMax ) {
98+ result . data = result . data . slice ( result . data . length / 4 ) ;
99+ // console.log(`newFirstPoint: ${result.data[0].x} newX1: ${domainMin + (domainMax - domainMin) / 4}`);
100+ // console.log(`Diff: ${result.data[0].x - (domainMin + (domainMax - domainMin) / 4)}`);
101+ // result.x = this.getXScale([domainMin, domainMax], 1 / 4);
102+ result . x = this . getXScale ( [ domainMin , domainMax ] , result . data [ 0 ] . x ) ;
103+ result . y = this . getYScale ( ) ;
52104 }
105+
106+ return result ;
53107 } ) ;
54108 }
55109
@@ -64,11 +118,12 @@ class Ftp extends Component {
64118 innerHeight = { height }
65119 innerWidth = { width }
66120 margin = { margin }
121+ device = { this . state . info ? this . state . info . name : "" }
67122 data = { this . state . data }
68123 />
69124 < Animation
70- xscale = { this . x }
71- yscale = { this . y }
125+ xscale = { this . state . x }
126+ yscale = { this . state . y }
72127 width = { width } // {this.props.width}
73128 height = { height } // {this.props.height}
74129 style = { {
0 commit comments