Skip to content

Commit 2e45726

Browse files
committed
merged
2 parents 918703e + 1ba6585 commit 2e45726

File tree

2 files changed

+30
-8
lines changed

2 files changed

+30
-8
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": [
@@ -52,6 +57,11 @@
5257
"bind": {
5358
"to": "I"
5459
}
60+
},
61+
{
62+
"bind": {
63+
"to": "Background"
64+
}
5565
}
5666
],
5767
"dataReductionAlgorithm": {

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)