Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
satishr
Helper III
Helper III

Revert to default option doesn't work in my custom visual

I have developed a simple custom visual following the documentation available. I have created few format options in the capabilities.ts file and have assigned values to them in visual.ts using variables. I want to know how to get the "Revert to default" button to work which is present in the format pane. Note: I haven't used settings.ts. Here is the sample of my code.

Capabilities.ts

----------------

 

"objects": {
"kpiName": {
"displayName": "KPI Name",
"properties": {
"name": {
"displayName": "Name",
"type":{ "text": true}
},
"color": {
"displayName": "Color",
"type": {
"fill": {
"solid": {
"color": true
}
}
}
},
"fontSize":{
"displayName": "Font size",
"type": {"formatting": {"fontSize": true}}
}
}
}

}

 

Visual.ts:

---------


module powerbi.extensibility.visual {
"use strict";
export class Visual implements IVisual {
private kpiName: string;
private kpiColor: string;
private kpiTextSize: string;
private kpiFont: string;

 

constructor(options: VisualConstructorOptions) {

this.kpiName = "KPI Name";
this.kpiColor = "#444444";
this.kpiTextSize = "20";

}

 

 public update(options: VisualUpdateOptions) {

if (options.dataViews[0].metadata.objects)
{
if (options.dataViews[0].metadata.objects["kpiName"] && options.dataViews[0].metadata.objects["kpiName"]["name"]) {this.kpiName = options.dataViews[0].metadata.objects["kpiName"]["name"].toString();}
if (options.dataViews[0].metadata.objects["kpiName"] && options.dataViews[0].metadata.objects["kpiName"]["color"]) {this.kpiColor = options.dataViews[0].metadata.objects["kpiName"]["color"]["solid"]["color"].toString();}
if (options.dataViews[0].metadata.objects["kpiName"] && options.dataViews[0].metadata.objects["kpiName"]["fontSize"]) {this.kpiTextSize = options.dataViews[0].metadata.objects["kpiName"]["fontSize"].toString();}
}

}

 

public enumerateObjectInstances(options: EnumerateVisualObjectInstancesOptions): VisualObjectInstanceEnumeration {
let objectName = options.objectName;
let objectEnumeration: VisualObjectInstance[] = [];

switch (objectName) {
case 'kpiName':
objectEnumeration.push({
objectName: objectName,
properties: {
name: this.kpiName,
color: this.kpiColor,
fontSize: this.kpiTextSize,
},
selector: null
});
break;

};

return objectEnumeration;
}

 

1 ACCEPTED SOLUTION
v-viig
Community Champion
Community Champion

You use single variable to keep the default value and current value.

That means, you should move default values to new variables and use them if and only if the property is undefined in metadata.

 

this.kpiName = options.dataViews[0].metadata.objects["kpiName"] && options.dataViews[0].metadata.objects["kpiName"]["name"]
    ? this.kpiName = options.dataViews[0].metadata.objects["kpiName"]["name"].toString()
    : "KPI Name";

Ignat Vilesov,

Software Engineer

 

Microsoft Power BI Custom Visuals

pbicvsupport@microsoft.com

 

 

View solution in original post

1 REPLY 1
v-viig
Community Champion
Community Champion

You use single variable to keep the default value and current value.

That means, you should move default values to new variables and use them if and only if the property is undefined in metadata.

 

this.kpiName = options.dataViews[0].metadata.objects["kpiName"] && options.dataViews[0].metadata.objects["kpiName"]["name"]
    ? this.kpiName = options.dataViews[0].metadata.objects["kpiName"]["name"].toString()
    : "KPI Name";

Ignat Vilesov,

Software Engineer

 

Microsoft Power BI Custom Visuals

pbicvsupport@microsoft.com

 

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.