-
Notifications
You must be signed in to change notification settings - Fork 2
/
_devicePlot.tsx
44 lines (40 loc) · 1.28 KB
/
_devicePlot.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
import { fromFlux, Plot, LayerTypes, LayerConfig } from '@influxdata/giraffe'
const style = {
width: "calc(50vw - 20px)",
height: "calc(20vh - 20px)",
margin: "40px",
}
export function DevicePlot(
{ csv, plot, title }:
{ csv: string, plot: 'line' | 'table', title?: string})
{
const csvData = csv?.trim() || ''
const tableData = fromFlux(csvData).table || undefined
let field = tableData.getColumn('_field')
const fieldTitle = Array.isArray(field) ? field[0] : ''
const layer : { line: () => LayerConfig, table: () => LayerConfig, } = {
line: () => ({
type: LayerTypes.Line,
x: "_time",
y: "_value",
fill: []
}),
table: () => ({
fluxResponse: csvData,
type: LayerTypes.SimpleTable,
showAll: false,
})
}
return (
<div>
<div style={style}>
<h3>{title === '' ? '' : (title || fieldTitle)}</h3>
{tableData && csvData && layer[plot] && <Plot config={{
fluxResponse: csvData,
table: tableData,
layers: [layer[plot]()],
}} />}
</div>
</div>
)
}