import { googleGauge } from "./visualization" ; import { Spotfire } from "./api" ; Spotfire . initialize ( async ( mod ) => { let context = mod . getRenderContext ( ) ; let reader = mod . createReader ( mod . visualization . data ( ) , mod . windowSize ( ) ) ; let gauge = await googleGauge ( ) ; reader . subscribe ( async function render ( dataView , size ) { let errors = await dataView . getErrors ( ) ; if ( errors . length > 0 ) { mod . controls . errorOverlay . show ( errors , "DataView" ) ; gauge . clear ( ) ; return ; } mod . controls . errorOverlay . hide ( "DataView" ) ; let categoryHierarchy = await dataView . hierarchy ( "Category" ) ; let categoryRoot = await categoryHierarchy ! . root ( ) ; if ( categoryRoot == null ) { return ; } let hasMeasurement = ( await dataView . continuousAxis ( "Measurement" ) ) != null ; let data = categoryRoot . leaves ( ) . map ( ( leaf ) => [ leaf . formattedPath ( ) , hasMeasurement ? leaf . rows ( ) [ 0 ] ?. continuous ( "Measurement" ) . value ( ) ?? 0 : 0 ] ) ; gauge . render ( data , size ) ; let marking = await dataView . marking ( ) ; let gauges = gauge . element . getElementsByTagName ( "td" ) ; categoryRoot . leaves ( ) . forEach ( ( leaf , index ) => { gauges [ index ] . style . background = marking && leaf . rows ( ) . filter ( r => r . isMarked ( ) ) . length ? "radial-gradient(" + marking . colorHexCode + " 50%, transparent 100%)" : "transparent" ; } ) ; context . signalRenderComplete ( ) ; } ) ; } ) ;