@@ -36,13 +36,21 @@ type info = {
3636
3737class Line {
3838 name : string ;
39+
3940 lineData : PlotData ;
41+
4042 layout : Layout ;
43+
4144 revision : number ;
45+
4246 shortDisplaySeconds : number ;
47+
4348 shortX : Date [ ] ;
49+
4450 shortY : number [ ] ;
51+
4552 longX : Date [ ] ;
53+
4654 longY : number [ ] ;
4755
4856 constructor ( name : string ) {
@@ -94,11 +102,12 @@ class Line {
94102 }
95103
96104 getLineData ( mode : Number ) {
97- if ( mode == 0 ) {
105+ if ( mode === 0 ) {
98106 this . lineData . x = this . shortX ;
99107 this . lineData . y = this . shortY ;
100108 return this . lineData ;
101- } else if ( mode == 1 ) {
109+ }
110+ if ( mode === 1 ) {
102111 this . lineData . x = this . longX ;
103112 this . lineData . y = this . longY ;
104113 return this . lineData ;
@@ -130,7 +139,7 @@ const availableBaudRates = [
130139 115200 , 230400 , 250000 , 460800 , 500000 , 921600 , 1000000 , 2000000 ,
131140] ;
132141
133- export function DataLogger ( ) {
142+ export default function DataLogger ( ) {
134143 const buttonGetAvailableSerialPorts = useRef < HTMLButtonElement > ( null ) ;
135144 const selectAvailablePorts = useRef < HTMLSelectElement > ( null ) ;
136145 const [ availablePorts , SetAvailablePorts ] = useState < Array < PortInfo > > ( [ ] ) ;
@@ -151,7 +160,7 @@ export function DataLogger() {
151160 } ;
152161
153162 const setSerialPort = async ( value : string ) => {
154- if ( value == '' ) {
163+ if ( value === '' ) {
155164 window . api . closeSerialPort ( ) ;
156165 setCurrentStatus ( status . idle ) ;
157166 return ;
@@ -183,33 +192,29 @@ export function DataLogger() {
183192 // plot functions
184193 useEffect ( ( ) => {
185194 if ( newData === undefined ) return ;
195+
186196 if (
187- ! (
188- currentStatus === status . streaming ||
189- currentStatus === status . recordStarted
190- )
197+ currentStatus !== status . streaming &&
198+ currentStatus !== status . recordStarted
191199 ) {
192- const lines = [ ] ;
193- for ( const point of newData . rawData ) {
200+ const initialLines = newData . rawData . map ( ( point ) => {
194201 const lineName = point . split ( ':' ) [ 0 ] . trim ( ) ;
195- const line = new Line ( lineName ) ;
196- console . log ( lineName ) ;
197- lines . push ( line ) ;
198- }
199- setLines ( lines ) ;
202+ return new Line ( lineName ) ;
203+ } ) ;
204+ setLines ( initialLines ) ;
200205 setCurrentStatus ( status . streaming ) ;
201206 } else {
202- const updateLines = Array . from ( lines ) ;
203- for ( let i = 0 ; i < lines . length ; i ++ ) {
207+ const updateLines = [ ... lines ] ;
208+ newData . rawData . forEach ( ( point , i ) => {
204209 const pointY =
205- newData . rawData [ i ]
206- . split ( ':' ) [ 1 ]
207- . match ( / [ + - ] ? (?: \d + \. ? \d * | \. \d + ) / ) ! [ 0 ] || '0' ;
208- updateLines [ i ] . appendData ( newData . timestamp , parseFloat ( pointY ) ) ;
209- }
210+ point . split ( ':' ) [ 1 ] . match ( / [ + - ] ? (?: \d + \. ? \d * | \. \d + ) / ) ?. [ 0 ] || '0' ;
211+ if ( updateLines [ i ] ) {
212+ updateLines [ i ] . appendData ( newData . timestamp , parseFloat ( pointY ) ) ;
213+ }
214+ } ) ;
210215 setLines ( updateLines ) ;
211216 }
212- } , [ newData ] ) ;
217+ } , [ newData , currentStatus , lines ] ) ;
213218
214219 // record functions
215220 const recordStart = async ( ) => {
@@ -227,13 +232,13 @@ export function DataLogger() {
227232 } ;
228233
229234 const recordStop = async ( ) => {
230- const result = await window . api . recordStop ( ) ;
235+ await window . api . recordStop ( ) ;
231236 setCurrentStatus ( status . portSelected ) ;
232237 setDisplayMode ( displayModes . short ) ;
233238 } ;
234239
235240 const openSaveFolder = async ( ) => {
236- const result = await window . api . openSaveFolder ( savePath ) ;
241+ await window . api . openSaveFolder ( savePath ) ;
237242 } ;
238243
239244 // 初回のみ実行
@@ -268,8 +273,8 @@ export function DataLogger() {
268273 case status . chgBaudRate :
269274 // loading
270275 return (
271- < Center h = { ' 100%' } >
272- < VStack spacing = { ' 1em' } >
276+ < Center h = " 100%" >
277+ < VStack spacing = " 1em" >
273278 < Spinner
274279 thickness = "4px"
275280 speed = "0.65s"
@@ -284,10 +289,10 @@ export function DataLogger() {
284289
285290 default :
286291 // グラフ描画
287- return lines . map ( ( line , idx ) => {
292+ return lines . map ( ( line ) => {
288293 return (
289294 < Plot
290- key = { `plot_ ${ idx } ` }
295+ key = { line . name }
291296 className = { styles . plot }
292297 data = { [ line . getLineData ( displayMode ) ] }
293298 layout = { line . layout }
@@ -301,28 +306,28 @@ export function DataLogger() {
301306 return (
302307 < Grid
303308 templateAreas = { `"header header" "nav main"` }
304- gridTemplateRows = { ' auto 1fr' }
305- gridTemplateColumns = { ' 20% 1fr' }
306- h = { ' 100vh' }
309+ gridTemplateRows = " auto 1fr"
310+ gridTemplateColumns = " 20% 1fr"
311+ h = " 100vh"
307312 m = { 3 }
308313 >
309- < GridItem area = { ' header' } margin = { ' 0 0 1em 0' } >
314+ < GridItem area = " header" margin = " 0 0 1em 0" >
310315 < Heading > Realtime Data Logger</ Heading >
311316 < Text > リアルタイムの測定値を表示・保存します。</ Text >
312317 </ GridItem >
313- < GridItem area = { ' nav' } >
318+ < GridItem area = " nav" >
314319 < Stack direction = "column" spacing = { 5 } >
315- < Box bgColor = { ' white' } >
316- < Heading fontSize = { 'xl' } mb = { 1 } >
320+ < Box bgColor = " white" >
321+ < Heading fontSize = "xl" mb = { 1 } >
317322 Select Serial Port
318323 </ Heading >
319324 < Stack direction = "row" spacing = { 1 } >
320325 < Select
321326 size = "sm"
322327 borderWidth = "1px"
323328 borderRadius = "md"
324- color = { ' teal.600' }
325- borderColor = { ' teal.600' }
329+ color = " teal.600"
330+ borderColor = " teal.600"
326331 ref = { selectAvailablePorts }
327332 isDisabled = { currentStatus === status . recordStarted }
328333 onChange = { ( e ) => setSerialPort ( e . target . value ) }
@@ -350,22 +355,22 @@ export function DataLogger() {
350355 </ Tooltip >
351356 </ Stack >
352357 </ Box >
353- < Box bgColor = { ' white' } >
354- < Heading fontSize = { 'xl' } mb = { 1 } >
358+ < Box bgColor = " white" >
359+ < Heading fontSize = "xl" mb = { 1 } >
355360 Select Baud Rate
356361 </ Heading >
357362 < Stack direction = "row" spacing = { 1 } >
358363 < Select
359364 size = "sm"
360365 borderWidth = "1px"
361366 borderRadius = "md"
362- color = { ' teal.600' }
363- borderColor = { ' teal.600' }
367+ color = " teal.600"
368+ borderColor = " teal.600"
364369 ref = { selectAvailablePorts }
365370 value = { baudRate }
366371 isDisabled = {
367- currentStatus == status . idle ||
368- currentStatus == status . recordStarted
372+ currentStatus === status . idle ||
373+ currentStatus === status . recordStarted
369374 }
370375 onChange = { ( e ) => ChangeBaudRate ( e . target . value ) }
371376 >
@@ -380,18 +385,18 @@ export function DataLogger() {
380385 </ Select >
381386 </ Stack >
382387 </ Box >
383- < Box bgColor = { ' white' } >
384- < Heading fontSize = { 'xl' } mb = { 1 } >
388+ < Box bgColor = " white" >
389+ < Heading fontSize = "xl" mb = { 1 } >
385390 Record
386391 </ Heading >
387- < Flex justifyContent = { ' space-between' } >
392+ < Flex justifyContent = " space-between" >
388393 < Button
389394 colorScheme = "teal"
390395 variant = "outline"
391396 size = "sm"
392397 onClick = { recordStart }
393- isDisabled = { currentStatus != status . streaming }
394- w = { ' 48%' }
398+ isDisabled = { currentStatus !== status . streaming }
399+ w = " 48%"
395400 >
396401 Start
397402 </ Button >
@@ -400,16 +405,16 @@ export function DataLogger() {
400405 variant = "outline"
401406 size = "sm"
402407 onClick = { recordStop }
403- isDisabled = { currentStatus != status . recordStarted }
404- w = { ' 48%' }
408+ isDisabled = { currentStatus !== status . recordStarted }
409+ w = " 48%"
405410 >
406411 Stop
407412 </ Button >
408413 </ Flex >
409414 < Stack
410- direction = { ' row' }
415+ direction = " row"
411416 m = { 1 }
412- color = { ' teal.600' }
417+ color = " teal.600"
413418 opacity = { status . recordStarted <= currentStatus ? 1 : 0.4 }
414419 >
415420 < Text > elapsed time: </ Text >
@@ -421,9 +426,9 @@ export function DataLogger() {
421426 </ Text >
422427 </ Stack >
423428 < Stack
424- direction = { ' row' }
429+ direction = " row"
425430 m = { 1 }
426- color = { ' teal.600' }
431+ color = " teal.600"
427432 opacity = { status . recordStarted <= currentStatus ? 1 : 0.4 }
428433 >
429434 < Text > file size: </ Text >
@@ -435,13 +440,13 @@ export function DataLogger() {
435440 </ Text >
436441 </ Stack >
437442 < Stack
438- direction = { ' row' }
443+ direction = " row"
439444 m = { 1 }
440- color = { ' teal.600' }
445+ color = " teal.600"
441446 opacity = { status . recordStarted <= currentStatus ? 1 : 0.4 }
442447 >
443448 < Text > file: </ Text >
444- < Text as = { 'u' } cursor = { ' pointer' } onClick = { openSaveFolder } >
449+ < Text as = "u" cursor = " pointer" onClick = { openSaveFolder } >
445450 { status . recordStarted <= currentStatus
446451 ? `${ savePath . split ( '/' ) . slice ( - 1 ) [ 0 ] } `
447452 : '' }
@@ -450,7 +455,7 @@ export function DataLogger() {
450455 </ Box >
451456 </ Stack >
452457 </ GridItem >
453- < GridItem bg = "" overflowX = { ' auto' } overflowY = { ' scroll' } area = { ' main' } >
458+ < GridItem bg = "" overflowX = " auto" overflowY = " scroll" area = " main" >
454459 < Tabs
455460 variant = "unstyled"
456461 align = "center"
@@ -463,8 +468,8 @@ export function DataLogger() {
463468 cursor = "pointer"
464469 borderWidth = "1px"
465470 borderRadius = "md"
466- color = { ' teal.600' }
467- borderColor = { ' teal.600' }
471+ color = " teal.600"
472+ borderColor = " teal.600"
468473 _hover = { { background : 'teal.50' } }
469474 _disabled = { {
470475 opacity : '0.4' ,
@@ -489,8 +494,8 @@ export function DataLogger() {
489494 cursor = "pointer"
490495 borderWidth = "1px"
491496 borderRadius = "md"
492- color = { ' teal.600' }
493- borderColor = { ' teal.600' }
497+ color = " teal.600"
498+ borderColor = " teal.600"
494499 _hover = { { background : 'teal.50' } }
495500 _disabled = { {
496501 opacity : '0.4' ,
0 commit comments