-
Notifications
You must be signed in to change notification settings - Fork 2
/
example.tsx
111 lines (97 loc) · 2.8 KB
/
example.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import React, { useEffect } from 'react';
import ReactDOM from 'react-dom';
import ReactMarkdown from 'react-markdown';
import README from './README.md';
import SmoothieComponent, { TimeSeries } from './SmoothieComponent';
const TS = new TimeSeries();
const TS2 = new TimeSeries();
function TestComponent() {
const [toggle, setToggle] = React.useState(false);
const [delay, setDelay] = React.useState(0);
return (
<>
<button onClick={() => setToggle(s => !s)}>Toggle Existence</button>
<button onClick={() => setDelay(d => d + 500)}>Increment Delay</button>
<button onClick={() => setDelay(d => d - 500)}>Decrement Delay</button>
{toggle ? (
<></>
) : (
<SmoothieComponent
responsive
interpolation="step"
minValue={0}
maxValue={1}
streamDelay={delay}
nonRealtimeData={false}
tooltip={props => {
if (!props.display) return <div />;
return (
<div
style={{
userSelect: 'none',
background: '#444',
padding: '1em',
marginLeft: '20px',
fontFamily: 'consolas',
color: 'white',
fontSize: '10px',
pointerEvents: 'none',
}}
>
<strong>{props.time}</strong>
{props.data ? (
<ul>
{props.data.map((data, i) => (
<li key={i} style={{ color: data.series.options.strokeStyle }}>
{data.value}
</li>
))}
</ul>
) : (
<div />
)}
</div>
);
}}
series={[
{
data: TS,
r: 255,
lineWidth: 4,
strokeStyle: { r: 255 },
},
]}
/>
)}
</>
);
}
const interval = setInterval(function () {
var time = new Date().getTime();
// Generate times slightly in the future
// time += 1000;
// ts1.append(time, Math.random());
TS2.append(time, Math.random());
TS.append(time, Math.random());
}, 1000);
function Readme() {
const [source, setSource] = React.useState<string>();
const [fail, setFail] = React.useState(false);
useEffect(() => {
fetch(README)
.then(response => response.text())
.then(text => setSource(text))
.catch(e => {
setFail(true);
setSource(e.message);
});
});
return fail ? <>Failed to load markdown:{source}</> : <ReactMarkdown children={source} />;
}
ReactDOM.render(
<>
<TestComponent />
<Readme />
</>,
document.body.appendChild(document.createElement('div'))
);