@@ -58,6 +58,8 @@ module powerbi.extensibility.visual {
58
58
private dataPoints : any ;
59
59
private r : number ;
60
60
private grad : Uint8ClampedArray ;
61
+ private useAutoDetectIntensity : boolean ;
62
+ private usePercentageScaling : boolean ;
61
63
62
64
public defaultRadius = 5 ;
63
65
public defaultGradient = {
@@ -92,6 +94,18 @@ module powerbi.extensibility.visual {
92
94
return this ;
93
95
}
94
96
97
+ public autoIntensity ( auto )
98
+ {
99
+ this . useAutoDetectIntensity = auto ;
100
+ return this ;
101
+ }
102
+
103
+ public percentageScaling ( use )
104
+ {
105
+ this . usePercentageScaling = use ;
106
+ return this ;
107
+ }
108
+
95
109
public add ( point ) {
96
110
this . dataPoints . push ( point ) ;
97
111
return this ;
@@ -156,7 +170,19 @@ module powerbi.extensibility.visual {
156
170
var ctx = this . ctx ;
157
171
158
172
ctx . clearRect ( 0 , 0 , this . width , this . height ) ;
159
-
173
+ if ( this . useAutoDetectIntensity )
174
+ {
175
+ console . log ( 'using auto detect intensity' ) ;
176
+ var tmpMax = 0 ;
177
+ for ( var i = 0 , len = this . dataPoints . length ; i < len ; i ++ )
178
+ {
179
+ if ( this . dataPoints [ i ] [ 2 ] > tmpMax )
180
+ {
181
+ tmpMax = this . dataPoints [ i ] [ 2 ] ;
182
+ }
183
+ }
184
+ this . maxValue = tmpMax ;
185
+ }
160
186
// draw a grayscale heatmap by putting a blurred circle at each data point
161
187
for ( var i = 0 , len = this . dataPoints . length , p ; i < len ; i ++ ) {
162
188
p = this . dataPoints [ i ] ;
@@ -165,9 +191,12 @@ module powerbi.extensibility.visual {
165
191
//make it so the X and Y input values are a percentage
166
192
//this means that the data collected is from 0 to 1 along each axis
167
193
//multiply it by the current canvas size
168
- //this should keep the data scalable with the images and resizing
169
- p [ 0 ] = p [ 0 ] * this . width ;
170
- p [ 1 ] = p [ 1 ] * this . height ;
194
+ //this should keep the data scalable with the images and resizing
195
+ if ( this . usePercentageScaling )
196
+ {
197
+ p [ 0 ] = p [ 0 ] * this . width ;
198
+ p [ 1 ] = p [ 1 ] * this . height ;
199
+ }
171
200
//end proposed change
172
201
173
202
ctx . globalAlpha = Math . max ( p [ 2 ] / this . maxValue , minOpacity === undefined ? 0.05 : minOpacity ) ;
@@ -227,20 +256,19 @@ module powerbi.extensibility.visual {
227
256
var catDv : DataViewCategorical = dataView . categorical ;
228
257
var values = catDv . values ;
229
258
if ( typeof ( dataView . metadata . columns [ 0 ] . roles ) !== 'undefined' ) {
230
- for ( var i = 0 ; i < dataView . metadata . columns . length ; i ++ ) {
231
- var colRole = Object . keys ( dataView . metadata . columns [ i ] . roles ) [ 0 ] ;
259
+ for ( var i = 0 ; i < catDv . values . length ; i ++ ) {
260
+ var colRole = values [ i ] . source . displayName
232
261
switch ( colRole ) {
233
262
case "X" :
234
263
xCol = index ;
235
264
break ;
236
265
case "Y" :
237
266
yCol = index ;
238
267
break ;
239
- case "I " :
268
+ case "Intensity " :
240
269
iCol = index ;
241
270
break ;
242
271
case "Category" :
243
- index -- ;
244
272
break ;
245
273
}
246
274
index ++ ;
@@ -294,6 +322,8 @@ module powerbi.extensibility.visual {
294
322
//this.updateCanvasSize();
295
323
this . updateInternal ( false ) ;
296
324
this . heatMap . max ( Visual . getFieldNumber ( this . dataView , 'settings' , 'maxValue' , this . maxValue ) ) ;
325
+ this . heatMap . autoIntensity ( Visual . getFieldBoolean ( this . dataView , 'settings' , 'autoIntensity' , false ) ) ;
326
+ this . heatMap . percentageScaling ( Visual . getFieldBoolean ( this . dataView , 'settings' , 'pctscale' , false ) ) ;
297
327
this . heatMap . radius ( Visual . getFieldNumber ( this . dataView , 'settings' , 'radius' , 5 ) , Visual . getFieldNumber ( this . dataView , 'settings' , 'blur' , 5 ) ) ;
298
328
var data = Visual . converter ( this . dataView ) ;
299
329
this . heatMap . clear ( ) ;
@@ -330,11 +360,13 @@ module powerbi.extensibility.visual {
330
360
displayName : 'General' ,
331
361
selector : null ,
332
362
properties : {
333
- backgroundUrl : Visual . getFieldText ( dataView , 'settings' , 'backgroundUrl' , '' ) ,
363
+ backgroundUrl : Visual . getFieldText ( dataView , 'settings' , 'backgroundUrl' , this . backgroundUrl ) ,
334
364
radius : Visual . getFieldNumber ( dataView , 'settings' , 'radius' , 5 ) ,
335
365
blur : Visual . getFieldNumber ( dataView , 'settings' , 'blur' , 15 ) ,
336
366
// maxWidth: HeatMapChart.getFieldNumber(dataView, 'settings', 'maxWidth', this.canvasWidth),
337
367
// maxHeight: HeatMapChart.getFieldNumber(dataView, 'settings', 'maxHeight', this.canvasHeight),
368
+ autoIntensity : Visual . getFieldBoolean ( dataView , 'settings' , 'autoIntensity' , false ) ,
369
+ pctscale : Visual . getFieldBoolean ( dataView , 'settings' , 'pctscale' , false ) ,
338
370
maxValue : Visual . getFieldNumber ( dataView , 'settings' , 'maxValue' , 1 )
339
371
}
340
372
} ;
@@ -400,7 +432,7 @@ module powerbi.extensibility.visual {
400
432
var lineHeight = 20 ;
401
433
var x = ( this . canvasWidth - maxWidth ) / 2 ;
402
434
var y = border ;
403
- wrapText ( context , 'Select a background image, the width and height of the image should match the maximum x,y data points in the dataset.' , x , y , maxWidth , lineHeight ) ;
435
+ wrapText ( context , 'Select a background image, the width and height of the image should match the maximum x,y data points in the dataset. Alternatively you can enable percentage scale, then you x, y coordinate should be between 0 and 1 and the visual will scale their position to the size of the image ' , x , y , maxWidth , lineHeight ) ;
404
436
}
405
437
406
438
private updateBackgroundUrl ( ) {
@@ -479,5 +511,20 @@ module powerbi.extensibility.visual {
479
511
}
480
512
return defaultValue ;
481
513
}
514
+
515
+ private static getFieldBoolean ( dataView : DataView , field : string , property : string = 'text' , defaultValue : boolean = false ) : boolean {
516
+ if ( dataView ) {
517
+ var objects = dataView . metadata . objects ;
518
+ if ( objects ) {
519
+ var f = objects [ field ] ;
520
+ if ( f ) {
521
+ var num = < boolean > f [ property ] ;
522
+ if ( num )
523
+ return num ;
524
+ }
525
+ }
526
+ }
527
+ return defaultValue ;
528
+ }
482
529
}
483
530
}
0 commit comments