Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 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 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 | 'use client'; import { useCallback, useEffect, useState } from 'react'; import Button from 'react-bootstrap/Button'; import Col from 'react-bootstrap/Col'; import Row from 'react-bootstrap/Row'; import { Line } from 'react-chartjs-2'; import { BsArrowClockwise } from 'react-icons/bs'; import { useChartData, usePageSize } from './common'; import LoadingSpinner from '@/components/loadingSpinner/loadingSpinner'; import { ChartComponentParams, TimingChart } from '@/types/frontend/chart'; export default function StatusTimingLineChart({ title, body, shouldFetchData, lazyLoad, setChartLoaded, convertValue = v => v, mode, }: Readonly<ChartComponentParams<TimingChart>>) { const [ shouldLoad, setShouldLoad, ] = useState(false); if (!lazyLoad && shouldFetchData && !shouldLoad) { setShouldLoad(true); } const [ data, resetDataRaw, ] = useChartData( body, shouldFetchData, setChartLoaded, false, convertValue ); const resetData = useCallback(() => { resetDataRaw(); setShouldLoad(true); }, [ resetDataRaw, ]); useEffect(() => { resetDataRaw(); }, [ mode, ]); // eslint-disable-line react-hooks/exhaustive-deps const datasets = data?.datasets.map((v, i, a) => { if (i < a.length - 1) { return v; } return { ...v, data: v.data.map((v, i2) => v - a[i - 1].data[i2]), }; }) || []; const [ pageWidth, pageHeight, ] = usePageSize(); return <> <h3 className='text-center mt-5'>{title} <BsArrowClockwise style={{ cursor: 'pointer', }} onClick={resetData} /></h3> <Row><Col style={{ height: 'calc(80vh - 60px)', }}> {typeof data === 'undefined' && !lazyLoad && <div style={{ height: '100%', }}><LoadingSpinner fullHeight={true} /></div>} {typeof data === 'undefined' && lazyLoad && shouldLoad && <LoadingSpinner fullHeight={true} />} {typeof data === 'undefined' && lazyLoad && !shouldLoad && <Col className='d-grid' xs={{ span: 6, offset: 3, }} style={{ height: '100%', }} > <Button className='align-self-center' variant='success' onClick={() => setShouldLoad(true)} >Load Chart</Button> </Col>} {data === null && <h2 className='text-center'>Error loading data</h2>} {data && data.datasets.length === 0 && <Col className='d-grid' xs={{ span: 6, offset: 3, }} style={{ height: '75%', }} ><h2 className='text-center align-self-center'>No Data Found</h2></Col>} {data && data.datasets.length > 0 && <Line data={{ labels: data.labels, datasets, }} options={{ maintainAspectRatio: false, interaction: { mode: 'index', }, scales: { y: { min: 0, stacked: true, title: { display: true, text: 'Cumulative Time (s)', }, ticks: { callback: v => (Number(v) / 1000).toFixed(1), }, }, }, plugins: { legend: { position: pageWidth && pageHeight && pageWidth > pageHeight ? 'right' : 'bottom', }, tooltip: { callbacks: { label: context => { let label = context.dataset.label || ''; if (label) { label += ': '; } if (context.parsed.y !== null) { label += (Math.round(context.parsed.y / 100) / 10).toFixed(1) + 's'; } if (context.parsed._stacks?.y && context.datasetIndex > 0) { let sum = 0; for (let i = 0; i <= context.datasetIndex; i++) { sum += context.parsed._stacks.y[i] || 0; } sum = Math.round(sum / 100) / 10; label += ` (cum: ${sum.toFixed(1)}s)`; } return label; }, }, }, }, }} />} </Col></Row> </>; } |