@@ -5,6 +5,19 @@ import React, { useState } from "react";
55const grafana_stub =
66 "https://shadow.nd.rl.ac.uk/grafana/d/wMlwwaHMk/block-history?viewPanel=2&orgId=1&var-block=" ;
77
8+ function numberFormatter ( value : string | number | undefined ) {
9+ var nValue : number = value == undefined ? NaN : + value
10+ if ( isNaN ( nValue ) ) {
11+ return value
12+ } else {
13+ if ( nValue != 0 && ( Math . abs ( nValue ) < 0.001 || Math . abs ( nValue ) > 10000 ) ) {
14+ return nValue . toExponential ( )
15+ } else {
16+ return nValue . toPrecision ( )
17+ }
18+ }
19+ }
20+
821export default function Block ( {
922 pv,
1023 instName,
@@ -36,19 +49,6 @@ export default function Block({
3649 pvChangedIndicator . classList . add ( "text-transparent" ) ;
3750 } , 2000 ) ;
3851 }
39- var formattedValue = currentValue
40- if ( typeof currentValue === 'string' ) {
41- var formattedValue : number = + currentValue
42- }
43- if ( isNaN ( formattedValue ) ) {
44- var formattedValue = currentValue
45- } else {
46- if ( pv . units != null && formattedValue != 0 && ( formattedValue < 0.001 || formattedValue > 10000 ) ) {
47- var formattedValue = formattedValue . toExponential ( )
48- } else {
49- var formattedValue = formattedValue . toPrecision ( )
50- }
51- }
5252
5353 const minimum_date_to_be_shown = 631152000 ; // This is what PVWS thinks epoch time is for some reason. don't bother showing it as the instrument wasn't running EPICS on 01/01/1990
5454 return (
@@ -82,7 +82,7 @@ export default function Block({
8282 className = { pv . severity != "NONE" ? "text-red-400" : "" }
8383 >
8484 { showAdvanced && "Readback: " }
85- { formattedValue } { pv . units != null && pv . units }
85+ { numberFormatter ( pv . value ) } { pv . units != null && pv . units }
8686 </ span >
8787 < svg
8888 id = { pv . human_readable_name + "_CIRCLE" }
0 commit comments