import powerbi from "powerbi-visuals-api" ; import DataViewMetadataColumn = powerbi . DataViewMetadataColumn ; import VisualTooltipDataItem = powerbi . extensibility . VisualTooltipDataItem ; import { dataRoleHelper as DataRoleHelperModule } from "powerbi-visuals-utils-dataviewutils" ; import hasRole = DataRoleHelperModule . DataRoleHelper . hasRole ; import { valueFormatter as vf } from "powerbi-visuals-utils-formattingutils" ; import valueFormatter = vf . valueFormatter ; export interface ForceGraphTooltipInputObject { [ propertyName ] : any ; } export class ForceGraphTooltipsFactory { public static build ( inputObject , dataViewMetadataColumns ) { let tooltips = [ ] ; if ( ! inputObject ) { return tooltips ; } for ( let propertyName in inputObject ) { let column , value ; column = ForceGraphMetadataRoleHelper . getColumnByRoleName ( dataViewMetadataColumns , propertyName ) ; if ( ! column || ! column . displayName ) { continue ; } value = inputObject [ propertyName ] ; if ( ! ( typeof value === "number" ) ) { value = valueFormatter . format ( value , valueFormatter . getFormatStringByColumn ( column ) ) ; } tooltips . push ( { displayName : column . displayName , value : `${ value }` } ) ; } return tooltips ; } } export class ForceGraphMetadataRoleHelper { public static getColumnByRoleName ( dataViewMetadataColumns , roleName ) { if ( dataViewMetadataColumns && dataViewMetadataColumns . length && roleName ) { for ( const metadataColumn of dataViewMetadataColumns ) { if ( metadataColumn && hasRole ( metadataColumn , roleName ) ) { return metadataColumn ; } } } return null ; } }