@@ -12,8 +12,8 @@ import {
1212 AbsolutePosition ,
1313 RelativePosition
1414} from "../../../types/position" ;
15- import { Traces , Trace } from "../../../types/traces " ;
16- import { Axes , Axis } from "../../../types/axes " ;
15+ import { Trace } from "../../../types/trace " ;
16+ import { Axis } from "../../../types/axis " ;
1717import {
1818 ComplexParserDict ,
1919 ParserDict ,
@@ -484,7 +484,7 @@ function opiParseLabelPosition(props: any): string {
484484 * @param props list of props for this element
485485 * @returns a Traces object
486486 */
487- function opiParseTraces ( props : any ) : Traces {
487+ function opiParseTraces ( props : any ) : Trace [ ] {
488488 // Find PV value if it's one of the trace properties
489489 let pvName = opiParseString ( props . pv_name ) ;
490490 if ( pvName . includes ( "trace_" ) ) {
@@ -494,10 +494,13 @@ function opiParseTraces(props: any): Traces {
494494 const traces : Trace [ ] = [ ] ;
495495 // Parse all of the 'trace' properties
496496 for ( let i = 0 ; i < count ; i ++ ) {
497- const trace = parseMultipleNamedProps ( "trace" , props , new Trace ( i ) ) ;
497+ const trace = new Trace ( {
498+ fromOpi : true ,
499+ ...parseMultipleNamedProps ( `trace_${ i } ` , props )
500+ } ) ;
498501 traces . push ( trace ) ;
499502 }
500- return new Traces ( count , pvName , traces ) ;
503+ return traces ;
501504}
502505
503506/**
@@ -506,15 +509,18 @@ function opiParseTraces(props: any): Traces {
506509 * @param props
507510 * @returns an Axes object.
508511 */
509- function opiParseAxes ( props : any ) : Axes {
512+ function opiParseAxes ( props : any ) : Axis [ ] {
510513 const count = opiParseNumber ( props . axis_count ) ;
511514 const axes : Axis [ ] = [ ] ;
512515 // Parse all of the 'axis' properties
513516 for ( let i = 0 ; i < count ; i ++ ) {
514- const axis = parseMultipleNamedProps ( "axis" , props , new Axis ( i ) ) ;
517+ const axis = new Axis ( {
518+ fromOpi : true ,
519+ ...parseMultipleNamedProps ( `axis_${ i } ` , props )
520+ } ) ;
515521 axes . push ( axis ) ;
516522 }
517- return new Axes ( count , axes ) ;
523+ return axes ;
518524}
519525
520526/**
@@ -526,28 +532,24 @@ function opiParseAxes(props: any): Axes {
526532 * @param idx number to search for in prop names
527533 * @returns object containing parsed props
528534 */
529- function parseMultipleNamedProps ( name : string , props : any , obj : any ) {
535+ function parseMultipleNamedProps ( name : string , props : any ) {
536+ const obj : { [ key : string ] : any } = { } ;
530537 // Create keyword string and search for matches
531- const num = `${ name } _${ obj . index } _ ` ;
538+ const num = `${ name } _` ;
532539 const names = Object . getOwnPropertyNames ( props ) ;
533540 const newProps = names . filter ( s => s . includes ( num ) ) ;
534541 newProps . forEach ( item => {
535542 // For each match, convert the name and parse
536- const newName = snakeCaseToCamelCase ( item , num . length , undefined ) ;
543+ const newName = snakeCaseToCamelCase ( item , num . length , item . length ) ;
537544 try {
538- if ( newName ) {
539- // Get the type of the property
540- const match = obj [ newName ] ;
541- if ( typeof match === "boolean" ) {
542- obj [ newName ] = opiParseBoolean ( props [ item ] ) ;
543- } else if ( typeof match === "number" ) {
544- obj [ newName ] = opiParseNumber ( props [ item ] ) ;
545- } else if ( typeof match === "string" ) {
546- obj [ newName ] = opiParseString ( props [ item ] ) ;
547- } else if ( match instanceof Color ) {
548- obj [ newName ] = opiParseColor ( props [ item ] ) ;
549- } else if ( match instanceof Font ) {
550- obj [ newName ] = opiParseFont ( props [ item ] ) ;
545+ if ( newName && OPI_SIMPLE_PARSERS . hasOwnProperty ( newName ) ) {
546+ const [ opiPropName , propParser ] = OPI_SIMPLE_PARSERS [ newName ] ;
547+ obj [ newName ] = propParser ( props [ item ] ) ;
548+ // Some properties should be passed to more generic names
549+ if ( newName === "traceColor" || newName === "axisColor" ) {
550+ obj . color = opiParseColor ( props [ opiPropName ] ) ;
551+ } else if ( newName === "axisTitle" ) {
552+ obj . title = opiParseString ( props [ item ] ) ;
551553 }
552554 }
553555 } catch {
@@ -718,7 +720,19 @@ export const OPI_SIMPLE_PARSERS: ParserDict = {
718720 resize : [ "resize_behaviour" , opiParseResizing ] ,
719721 labelsFromPv : [ "labels_from_pv" , opiParseBoolean ] ,
720722 limitsFromPv : [ "limits_from_pv" , opiParseBoolean ] ,
721- format : [ "format_type" , opiParseNumber ]
723+ format : [ "format_type" , opiParseNumber ] ,
724+ antiAlias : [ "anti_alias" , opiParseBoolean ] ,
725+ concatenateData : [ "concatenate_data" , opiParseBoolean ] ,
726+ bufferSize : [ "buffer_size" , opiParseNumber ] ,
727+ onRight : [ "left_bottom_side" , opiParseBoolean ] ,
728+ updateMode : [ "update_mode" , opiParseNumber ] ,
729+ updateDelay : [ "update_delay" , opiParseNumber ] ,
730+ scaleFormat : [ "scale_format" , opiParseNumber ] ,
731+ scakeFont : [ "scale_font" , opiParseFont ] ,
732+ showGrid : [ "show_grid" , opiParseBoolean ] ,
733+ scaleFont : [ "scale_font" , opiParseFont ] ,
734+ minimum : [ "minimum" , opiParseNumber ] ,
735+ maximum : [ "maximum" , opiParseNumber ]
722736} ;
723737
724738/**
0 commit comments