@@ -14,8 +14,6 @@ export default {
14
14
} ,
15
15
} as Meta ;
16
16
17
- /** Util functions *****************/
18
-
19
17
const generateNewXY = ( serie : SeriesPoint , step : number ) : [ number , number ] => {
20
18
const x = serie . x + step ;
21
19
const rand = Math . floor ( Math . random ( ) * 10 ) ;
@@ -35,8 +33,6 @@ const getLastData = (
35
33
return newVals ;
36
34
} ;
37
35
38
- /** Main Component *****************/
39
-
40
36
type Props = Record < string , number > ;
41
37
export function NasdaqExample ( props : Props ) {
42
38
const {
@@ -45,38 +41,35 @@ export function NasdaqExample(props: Props) {
45
41
displayInterval, // interval to display (s)
46
42
} = props ;
47
43
48
- function PlotRefresher ( ) {
49
- const [ data , setData ] = useState ( srcData ) ;
44
+ const [ data , setData ] = useState ( srcData ) ;
50
45
51
- useEffect ( ( ) => {
52
- const timer = setTimeout ( ( ) => {
53
- const [ x , y ] = generateNewXY ( data [ data . length - 1 ] , step ) ; // generate a new coordinates
54
- const newData = getLastData ( [ ...data , { x, y } ] , displayInterval ) ; // get last 500s data
55
- setData ( newData ) ;
56
- } , refreshFrequency * 1000 ) ;
57
- return ( ) => clearTimeout ( timer ) ;
58
- } , [ data ] ) ;
59
- //const timeFormat = new Intl.DateTimeFormat('en-GB', { timeStyle: 'short' });
60
- return (
61
- < Plot { ...DEFAULT_PLOT_CONFIG } >
62
- < Heading title = "Nasdaq values Simulation" />
63
- < LineSeries
64
- data = { data . map ( ( { x, y } ) => ( { x : x * 1000 , y } ) ) }
65
- xAxis = "x"
66
- yAxis = "y"
67
- lineStyle = { { stroke : 'green' , strokeWidth : 1.5 } }
68
- />
69
- < Axis id = "x" position = "bottom" label = "Time (hh:mm)" scale = "time" />
70
- < Axis
71
- id = "y"
72
- position = "left"
73
- label = "Nasdaq value [USD]"
74
- displayPrimaryGridLines
75
- paddingStart = "10%"
76
- paddingEnd = "10%"
77
- />
78
- </ Plot >
79
- ) ;
80
- }
81
- return < PlotRefresher /> ;
46
+ useEffect ( ( ) => {
47
+ const timer = setTimeout ( ( ) => {
48
+ const [ x , y ] = generateNewXY ( data [ data . length - 1 ] , step ) ; // generate a new coordinates
49
+ const newData = getLastData ( [ ...data , { x, y } ] , displayInterval ) ; // get last 500s data
50
+ setData ( newData ) ;
51
+ } , refreshFrequency * 1000 ) ;
52
+ return ( ) => clearTimeout ( timer ) ;
53
+ } , [ data , displayInterval , refreshFrequency , step ] ) ;
54
+ //const timeFormat = new Intl.DateTimeFormat('en-GB', { timeStyle: 'short' });
55
+ return (
56
+ < Plot { ...DEFAULT_PLOT_CONFIG } >
57
+ < Heading title = "Nasdaq values Simulation" />
58
+ < LineSeries
59
+ data = { data . map ( ( { x, y } ) => ( { x : x * 1000 , y } ) ) }
60
+ xAxis = "x"
61
+ yAxis = "y"
62
+ lineStyle = { { stroke : 'green' , strokeWidth : 1.5 } }
63
+ />
64
+ < Axis id = "x" position = "bottom" label = "Time (hh:mm)" scale = "time" />
65
+ < Axis
66
+ id = "y"
67
+ position = "left"
68
+ label = "Nasdaq value [USD]"
69
+ displayPrimaryGridLines
70
+ paddingStart = "10%"
71
+ paddingEnd = "10%"
72
+ />
73
+ </ Plot >
74
+ ) ;
82
75
}
0 commit comments