import powerbi from "powerbi-visuals-api" ; import * as _ from "lodash" ; import DataView = powerbi . DataView ; import DataViewMetadataColumn = powerbi . DataViewMetadataColumn ; import DataViewCategorical = powerbi . DataViewCategorical ; import DataViewCategoryColumn = powerbi . DataViewCategoryColumn ; import DataViewValueColumn = powerbi . DataViewValueColumn ; import DataViewValueColumns = powerbi . DataViewValueColumns ; export class ForceGraphColumns < T > { public static getMetadataColumns ( dataView ) { let columns = dataView && dataView . metadata && dataView . metadata . columns ; return columns && _ . mapValues ( new ForceGraphColumns < DataViewMetadataColumn > ( ) , ( n , i ) => columns . filter ( x => x . roles && x . roles [ i ] ) [ 0 ] ) ; } public static getCategoricalColumns ( dataView ) { const categorical = dataView && dataView . categorical ; const categories = categorical && categorical . categories || [ ] ; const values = categorical && categorical . values || < DataViewValueColumns > [ ] ; return categorical && _ . mapValues ( new this < DataViewCategoryColumn & DataViewValueColumn [ ] & DataViewValueColumns > ( ) , ( n , i ) => { let result = categories . filter ( x => x . source . roles && x . source . roles [ i ] ) [ 0 ] ; if ( ! result ) { result = values . source && values . source . roles && values . source . roles [ i ] && values ; } if ( ! result ) { result = values . filter ( x => x . source . roles && x . source . roles [ i ] ) ; if ( _ . isEmpty ( result ) ) { result = undefined ; } } return result ; } ) ; } public Source : T = null ; public Target : T = null ; public Weight : T = null ; public LinkType : T = null ; public SourceType : T = null ; public TargetType : T = null ; }