@@ -32,36 +32,55 @@ import { ValueType } from "powerbi-visuals-utils-typeutils/lib/valueType";
32
32
// powerbi.extensibility.utils.test
33
33
import { getRandomNumbers } from "powerbi-visuals-utils-testutils" ;
34
34
import { TestDataViewBuilder , TestDataViewBuilderCategoryColumnOptions } from "powerbi-visuals-utils-testutils/lib/dataViewBuilder/testDataViewBuilder" ;
35
+ import { DataViewBuilderValuesColumnOptions } from "powerbi-visuals-utils-testutils/lib/dataViewBuilder/dataViewBuilder" ;
35
36
import { getRandomUniqueSortedDates } from "./helpers/helpers" ;
36
37
38
+ const maxValue : number = 100 ;
39
+
37
40
export class ProductSalesByDateData extends TestDataViewBuilder {
38
41
private static DefaultFormat : string = "$0,000.00" ;
39
42
private static DefaultDateFormat : string = "dddd MMMM d yyyy" ;
40
43
private static DefaultGroupName : string = "Product" ;
41
44
42
45
public static ColumnCategory : string = "Date" ;
43
46
public static GroupCategory : string = "Group" ;
44
- public static ColumnValues1 : string = "Product sales 1" ;
45
- public static ColumnValues2 : string = "Product sales 2" ;
46
- public static ColumnValues3 : string = "Product sales 3" ;
47
- public static ColumnValues4 : string = "Product sales 4" ;
47
+ public static GroupNames : string [ ] = [ "Product 1" , "Product 2" , "Product 3" , "Product 4" ] ;
48
+ public static ColumnValues : string [ ] = [ "Product sales 1" , "Product sales 2" , "Product sales 3" , "Product sales 4" ] ;
48
49
49
50
public valuesDate : Date [ ] = getRandomUniqueSortedDates (
50
51
50 ,
51
52
new Date ( 2014 , 0 , 1 ) ,
52
53
new Date ( 2015 , 5 , 10 ) ) ;
53
54
54
- public valuesSales1 : number [ ] = getRandomNumbers ( this . valuesDate . length ) ;
55
- public valuesSales2 : number [ ] = getRandomNumbers ( this . valuesDate . length ) ;
56
- public valuesSales3 : number [ ] = getRandomNumbers ( this . valuesDate . length ) ;
57
- public valuesSales4 : number [ ] = getRandomNumbers ( this . valuesDate . length ) ;
55
+ public valuesSales : [ number [ ] , number [ ] , number [ ] , number [ ] ] = [
56
+ getRandomNumbers ( this . valuesDate . length , - maxValue , maxValue ) ,
57
+ getRandomNumbers ( this . valuesDate . length , - maxValue , maxValue ) ,
58
+ getRandomNumbers ( this . valuesDate . length , - maxValue , maxValue ) ,
59
+ getRandomNumbers ( this . valuesDate . length , - maxValue , maxValue )
60
+ ] ;
58
61
59
62
public groups : string [ ] = [
60
63
"FirstGroup" ,
61
64
"SecondGroup"
62
65
] ;
63
66
64
- public getDataView ( columnNames ?: string [ ] , isGroupsEnabled : boolean = false ) : DataView {
67
+ public generateHightLightedValues ( valuesArray : number [ ] , hightlightedElementNumber ?: number ) : number [ ] {
68
+ let array : number [ ] = [ ] ;
69
+ const lenght : number = valuesArray . length ;
70
+ for ( let i : number = 0 ; i < lenght ; i ++ ) {
71
+ array [ i ] = null ;
72
+ }
73
+ if ( ! hightlightedElementNumber )
74
+ return array ;
75
+ if ( hightlightedElementNumber >= lenght || hightlightedElementNumber < 0 ) {
76
+ array [ 0 ] = valuesArray [ 0 ] ;
77
+ } else {
78
+ array [ hightlightedElementNumber ] = valuesArray [ hightlightedElementNumber ] ;
79
+ }
80
+ return array ;
81
+ }
82
+
83
+ public getDataView ( columnNames ?: string [ ] , isGroupsEnabled : boolean = false , withHighlights : boolean = false , hightlightedIndex : number = 0 , hightlightedElementNumber : number = 0 ) : DataView {
65
84
const categoriesColumn : TestDataViewBuilderCategoryColumnOptions [ ] = [ {
66
85
source : {
67
86
displayName : ProductSalesByDateData . ColumnCategory ,
@@ -82,48 +101,62 @@ export class ProductSalesByDateData extends TestDataViewBuilder {
82
101
} ) ;
83
102
}
84
103
104
+ let columns : DataViewBuilderValuesColumnOptions [ ] = [ {
105
+ source : {
106
+ displayName : ProductSalesByDateData . ColumnValues [ 0 ] ,
107
+ isMeasure : true ,
108
+ format : ProductSalesByDateData . DefaultFormat ,
109
+ groupName : ProductSalesByDateData . DefaultGroupName ,
110
+ type : ValueType . fromDescriptor ( { numeric : true } )
111
+ } ,
112
+ values : this . valuesSales [ 0 ]
113
+ } , {
114
+ source : {
115
+ displayName : ProductSalesByDateData . ColumnValues [ 1 ] ,
116
+ isMeasure : true ,
117
+ format : ProductSalesByDateData . DefaultFormat ,
118
+ groupName : ProductSalesByDateData . DefaultGroupName ,
119
+ type : ValueType . fromDescriptor ( { numeric : true } )
120
+ } ,
121
+ values : this . valuesSales [ 1 ]
122
+ } , {
123
+ source : {
124
+ displayName : ProductSalesByDateData . ColumnValues [ 2 ] ,
125
+ isMeasure : true ,
126
+ format : ProductSalesByDateData . DefaultFormat ,
127
+ groupName : ProductSalesByDateData . DefaultGroupName ,
128
+ type : ValueType . fromDescriptor ( { numeric : true } )
129
+ } ,
130
+ values : this . valuesSales [ 2 ]
131
+ } , {
132
+ source : {
133
+ displayName : ProductSalesByDateData . ColumnValues [ 3 ] ,
134
+ isMeasure : true ,
135
+ format : ProductSalesByDateData . DefaultFormat ,
136
+ groupName : ProductSalesByDateData . DefaultGroupName ,
137
+ type : ValueType . fromDescriptor ( { numeric : true } )
138
+ } ,
139
+ values : this . valuesSales [ 3 ]
140
+ } ] ;
141
+
142
+ if ( withHighlights ) {
143
+ columns [ hightlightedIndex ] . highlights = this . generateHightLightedValues ( this . valuesSales [ hightlightedIndex ] , hightlightedElementNumber ) ;
144
+ columns [ hightlightedIndex ] . source . groupName = ProductSalesByDateData . GroupNames [ hightlightedIndex ] ;
145
+
146
+ for ( let i = 0 ; i < columns . length ; i ++ ) {
147
+ if ( i !== hightlightedIndex ) {
148
+ columns [ i ] . highlights = this . generateHightLightedValues ( this . valuesSales [ i ] ) ;
149
+ columns [ i ] . source . groupName = ProductSalesByDateData . GroupNames [ i ] ;
150
+ }
151
+ }
152
+ }
153
+
85
154
return this . createCategoricalDataViewBuilder (
86
155
categoriesColumn , [
87
- {
88
- source : {
89
- displayName : ProductSalesByDateData . ColumnValues1 ,
90
- isMeasure : true ,
91
- format : ProductSalesByDateData . DefaultFormat ,
92
- groupName : ProductSalesByDateData . DefaultGroupName ,
93
- type : ValueType . fromDescriptor ( { numeric : true } )
94
- } ,
95
- values : this . valuesSales1
96
- } ,
97
- {
98
- source : {
99
- displayName : ProductSalesByDateData . ColumnValues2 ,
100
- isMeasure : true ,
101
- format : ProductSalesByDateData . DefaultFormat ,
102
- groupName : ProductSalesByDateData . DefaultGroupName ,
103
- type : ValueType . fromDescriptor ( { numeric : true } )
104
- } ,
105
- values : this . valuesSales1
106
- } ,
107
- {
108
- source : {
109
- displayName : ProductSalesByDateData . ColumnValues3 ,
110
- isMeasure : true ,
111
- format : ProductSalesByDateData . DefaultFormat ,
112
- groupName : ProductSalesByDateData . DefaultGroupName ,
113
- type : ValueType . fromDescriptor ( { numeric : true } )
114
- } ,
115
- values : this . valuesSales2
116
- } ,
117
- {
118
- source : {
119
- displayName : ProductSalesByDateData . ColumnValues4 ,
120
- isMeasure : true ,
121
- format : ProductSalesByDateData . DefaultFormat ,
122
- groupName : ProductSalesByDateData . DefaultGroupName ,
123
- type : ValueType . fromDescriptor ( { numeric : true } )
124
- } ,
125
- values : this . valuesSales3
126
- }
156
+ columns [ 0 ] ,
157
+ columns [ 1 ] ,
158
+ columns [ 2 ] ,
159
+ columns [ 3 ]
127
160
] , columnNames ) . build ( ) ;
128
161
}
129
162
}
0 commit comments