Skip to content

Commit 1ba6585

Browse files
committed
added support for dynamic background image
1 parent 1b726fc commit 1ba6585

File tree

3 files changed

+31
-9
lines changed

3 files changed

+31
-9
lines changed

capabilities.json

+10
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@
1919
"name": "I",
2020
"kind": "Measure",
2121
"displayName": "Intensity"
22+
},
23+
{
24+
"name": "Background",
25+
"kind": "Measure",
26+
"displayName": "Background"
2227
}
2328
],
2429
"dataViewMappings": [
@@ -47,6 +52,11 @@
4752
"bind": {
4853
"to": "I"
4954
}
55+
},
56+
{
57+
"bind": {
58+
"to": "Background"
59+
}
5060
}
5161
]
5262
}

pbiviz.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"displayName": "Heatmap",
55
"guid": "PBI_CV_FCF70EF9_270E_4A52_913E_345CC4A8BFBA",
66
"visualClassName": "Visual",
7-
"version": "4.0.1",
7+
"version": "4.1.0",
88
"description": "The Heatmap Visual enables users to draw a heatmap overlay from a X, Y coordinate set on to an existing image. The user specify the image, and provide a data set of X, Y coordinates and optionally an intensity for each data point. The radius and the bluriness of the heatmap bubbles can be customized as well as the max value for the intensity.",
99
"supportUrl": "http://powerbi.sjkp.dk/support",
1010
"gitHubUrl": "https://github.com/sjkp/heatmap"

src/visual.ts

+20-8
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ module powerbi.extensibility.visual {
229229
x: PrimitiveValue;
230230
y: PrimitiveValue;
231231
i: PrimitiveValue;
232+
b: PrimitiveValue
232233
}
233234

234235
export interface HeatMapDataModel {
@@ -252,8 +253,8 @@ module powerbi.extensibility.visual {
252253
public static converter(dataView: DataView): HeatMapDataModel {
253254
console.log('converter', dataView);
254255
var dataPoints: HeatMapData[] = [];
255-
var xCol, yCol, iCol;
256-
xCol = yCol = iCol = -1;
256+
var xCol, yCol, iCol, bCol;
257+
xCol = yCol = iCol = bCol = -1;
257258
var index = 0;
258259
var catDv: DataViewCategorical = dataView.categorical;
259260
var values = catDv.values;
@@ -270,6 +271,9 @@ module powerbi.extensibility.visual {
270271
if (colRole["Intensity"]) {
271272
iCol = index;
272273
}
274+
if (colRole["Background"]) {
275+
bCol = index;
276+
}
273277
if (colRole["Category"]) {
274278
continue;
275279
}
@@ -296,7 +300,8 @@ module powerbi.extensibility.visual {
296300
dataPoints.push({
297301
x: values[xCol].values[k],
298302
y: values[yCol].values[k],
299-
i: iCol !== -1 ? values[iCol].values[k] : 1
303+
i: iCol !== -1 ? values[iCol].values[k] : 1,
304+
b: bCol !== -1 ? values[bCol].values[k] : ''
300305
});
301306
}
302307
}
@@ -315,8 +320,7 @@ module powerbi.extensibility.visual {
315320
public update(options: VisualUpdateOptions) {
316321

317322
this.dataView = options.dataViews[0];
318-
this.currentViewport = options.viewport;
319-
this.updateBackgroundUrl();
323+
this.currentViewport = options.viewport;
320324
this.redrawCanvas();
321325

322326
}
@@ -333,6 +337,12 @@ module powerbi.extensibility.visual {
333337
this.heatMap.data(data.dataArray.map(s => {
334338
return [s.x, s.y, s.i];
335339
}));
340+
var newBackgroundUrl = Visual.getFieldText(this.dataView, 'settings', 'backgroundUrl', this.defaultBackgroundUrl);
341+
if (data.dataArray.length > 0 && data.dataArray[0].b !== '')
342+
{
343+
newBackgroundUrl = data.dataArray[data.dataArray.length-1].b as string;
344+
}
345+
this.updateBackgroundUrl(newBackgroundUrl);
336346
this.heatMap.draw();
337347
}
338348

@@ -403,7 +413,9 @@ module powerbi.extensibility.visual {
403413
container.appendChild(canvas);
404414

405415
this.element = canvas;
406-
this.updateBackgroundUrl();
416+
417+
var newBackgroundUrl = Visual.getFieldText(this.dataView, 'settings', 'backgroundUrl', this.defaultBackgroundUrl);
418+
this.updateBackgroundUrl(newBackgroundUrl);
407419
this.writeHelpOnCanvas();
408420
}
409421

@@ -438,8 +450,8 @@ module powerbi.extensibility.visual {
438450
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);
439451
}
440452

441-
private updateBackgroundUrl() {
442-
var newBackgroundUrl = Visual.getFieldText(this.dataView, 'settings', 'backgroundUrl', this.defaultBackgroundUrl);
453+
private updateBackgroundUrl(newBackgroundUrl) {
454+
443455
if (this.backgroundUrl !== newBackgroundUrl) {
444456
var style = this.element.style;
445457

0 commit comments

Comments
 (0)