import powerbi from "powerbi-visuals-api" ; import * as _ from "lodash" ; import DataView = powerbi . DataView ; import DataViewValueColumn = powerbi . DataViewValueColumn ; import DataViewCategorical = powerbi . DataViewCategorical ; import DataViewValueColumns = powerbi . DataViewValueColumns ; import DataViewValueColumnGroup = powerbi . DataViewValueColumnGroup ; import DataViewCategoricalColumn = powerbi . DataViewCategoricalColumn ; import PrimitiveValue = powerbi . PrimitiveValue ; import { valueFormatter as ValueFormatter } from "powerbi-visuals-utils-formattingutils" ; import { converterHelper as ch } from "powerbi-visuals-utils-dataviewutils" ; import converterHelper = ch . converterHelper ; const extraInformationRole = "ExtraInformation" ; export class GanttColumns < T > { public static getGroupedValueColumns ( dataView ) { let categorical = dataView && dataView . categorical ; let values = categorical && categorical . values ; let grouped = values && values . grouped ( ) ; return grouped && grouped . map ( g => _ . mapValues ( new this < DataViewValueColumn > ( ) , ( n , i ) => g . values . filter ( v => v . source . roles [ i ] ) [ 0 ] ) ) ; } public static getCategoricalValues ( dataView ) { let categorical = dataView && dataView . categorical ; let categories = categorical && categorical . categories || [ ] ; let values = categorical && categorical . values || < DataViewValueColumns > [ ] ; let series = categorical && values . source && this . getSeriesValues ( dataView ) ; return categorical && _ . mapValues ( new this < any [ ] > ( ) , ( n , i ) => { let columns ; ( < DataViewValueColumn [ ] > _ . toArray ( categories ) ) . concat ( _ . toArray ( values ) ) . filter ( x => x . source . roles && x . source . roles [ i ] ) . forEach ( x => { if ( i === extraInformationRole && x . source . roles && x . source . roles [ extraInformationRole ] ) { if ( ! columns ) { columns = { } ; } if ( x . source . format ) { const formatter = ValueFormatter . create ( { format : x . source . format } ) ; columns [ x . source . displayName ] = x . values . map ( v => formatter . format ( v ) ) ; } else { columns [ x . source . displayName ] = x . values ; } } else { columns = x . values ; } } ) ; return columns || values . source && values . source . roles && values . source . roles [ i ] && series ; } ) ; } public static getSeriesValues ( dataView ) { return dataView && dataView . categorical && dataView . categorical . values && dataView . categorical . values . map ( x => converterHelper . getSeriesName ( x . source ) ) ; } public Legend : T = null ; public Task : T = null ; public Parent : T = null ; public StartDate : T = null ; public EndDate : T = null ; public Duration : T = null ; public Completion : T = null ; public Resource : T = null ; public ExtraInformation : T = null ; public Milestones : T = null ; }