The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredCompete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.
Hi, I've made a Custom visual that Looks quite ok and has about 60 Format settings that a user can vary depending on their preference.
It all worked perfectly untill I saved a PBI file with this visual and opened it up again. All the settings were back to default. Any ideas on what I did wrong?
below is the general scheme of how my code looks like related to the settings:
...
interface Viewmodel {
...
settings: MSTASettings;
}
interface MSTASettings {
lines: {
show: boolean;
...
}
...
}
let defaultSettings: MSTASettings = {
lines: {
show: true,
...
}
...
}
export class Visual implements IVisual {
constructor(options: VisualConstructorOptions) {
this.mstaSettings = <MSTASettings>{};
...
}
public enumerateObjectInstances(options: EnumerateVisualObjectInstancesOptions): VisualObjectInstanceEnumeration {
let objectEnumeration: VisualObjectInstance[] = [];
switch (options.objectName) {
case 'lines':
objectEnumeration.push({
objectName: objectName,
properties: {
show: this.mstaSettings.lines.show,
...
},
selector: {}
});
break;
...
return objectEnumeration
}
public update(options: VisualUpdateOptions) {
let viewModel = this.getViewModel(options);
let settings = this.mstaSettings = viewModel.settings;
...
}
private getViewModel(options: VisualUpdateOptions): Viewmodel {
let viewmodel: Viewmodel = {
...
settings:<MSTASettings>{},
...
};
viewmodel.settings = {
lines: {
show: getValue<boolean>(objects, 'lines', 'show', defaultSettings.lines.show),
...
},
...
}
...
return viewmodel;
}
function getValue<T>(objects: DataViewObjects, objectName: string, propertyName: string, defaultValue: T): T {
if (objects) {
let object = objects[objectName];
if (object) {
let property: T = <T>object[propertyName];
if (property !== undefined) {
return property;
}
}
}
return defaultValue;
}
}
Note: I didn't use the latest version as I started this project a couple of years ago and only now found the time to tweek it.
Note2: I tried getting rid of the line In the Constructor. My code still worked, but the issue remained the same.