Forum Discussion
Need to add a Format Property per Measure
For each Measure in the dataset, I need to add a format property. I've allowed multiple measures in the capabilities.json file, but I actually want an AxisObject per measure. Therefore, I'd like the format to be Axis_1 with a Property 1 and a Property 2, then an Axis_2 with a Property 1 and a Property 2. This way I can group them by measure rather than the alternative of grouping them by Property.
Here is my current Capabilities and enumerateObjectInstances (right now I'm just looping statically 2 times to try and get it to work). I've tried different selector types with no luck.
"objects": {
"axisObject" : {
"displayName": "Axis",
"properties": {
"property1": {
"displayName": "Property 1",
"type": {
"bool": true
}
},
"property2": {
"displayName": "Property 2",
"type": {
"bool": true
}
}
}
}
switch( objectName ) {
case 'axisObject':
for(let i = 0; i < 2; i++) {
objectEnumeration.push({
objectName: objectName,
displayName: objectName + "_" + i,
properties: {
property1: this.settings.axisObject.property1,
property2: this.settings.axisObject.property2
},
selector: null
});
}
break;
};4 Replies
- murphycrosbyRegular Visitor
The only way I can get it to work the way I want, is to hard code them in the capabilities, and then don't push them on the
objectEnumeration array unless the categorical value length is long enough. However, that seems like a hack."objects": { "yaxisObject1": { "displayName": "Y-Axis 1", "properties": { "property1": { "displayName": "Property 1", "type": { "bool": true } }, "property2": { "displayName": "Property 2", "type": { "bool": true } } } }, "yaxisObject2": { "displayName": "Y-Axis 2", "properties": { "property1": { "displayName": "Property 1", "type": { "bool": true } }, "property2": { "displayName": "Property 2", "type": { "bool": true } } } }, "yaxisObject3": { "displayName": "Y-Axis 3", "properties": { "property1": { "displayName": "Property 1", "type": { "bool": true } }, "property2": { "displayName": "Property 2", "type": { "bool": true } } } } }public enumerateObjectInstances(options: EnumerateVisualObjectInstancesOptions): VisualObjectInstance[] | VisualObjectInstanceEnumerationObject { console.log('enumerateObjectInstances', this.dataView); let objectName: string = options.objectName; let objectEnumeration: VisualObjectInstance[] = []; switch( objectName ) { case 'yaxisObject1': if(this.dataView.categorical.values.length > 0) { objectEnumeration.push({ objectName: objectName, properties: { property1: this.settings.yaxisObject1.property1, property2: this.settings.yaxisObject1.property2 }, selector: null }); } break; case 'yaxisObject2': if(this.dataView.categorical.values.length > 1) { objectEnumeration.push({ objectName: objectName, properties: { property1: this.settings.yaxisObject2.property1, property2: this.settings.yaxisObject2.property2 }, selector: null }); } break; case 'yaxisObject3': if(this.dataView.categorical.values.length > 2) { objectEnumeration.push({ objectName: objectName, properties: { property1: this.settings.yaxisObject3.property1, property2: this.settings.yaxisObject3.property2 }, selector: null }); } break; }; return objectEnumeration; //return VisualSettings.enumerateObjectInstances(this.settings || VisualSettings.getDefault(), options); }- v-viigCommunity Champion
It seems you should specify a selector for each instance of VisualObjectInstance.
To find out more please take a look at this example.
Ignat Vilesov,
Software Engineer
Microsoft Power BI Custom Visuals
- murphycrosbyRegular Visitor
That example only seems to show adding properties dynamically to a group. I'm needing to dynamically add additional groups of properties.
Currently, I've defined 5 of the same groups of properties then just don't push them if I don't have a measure for it. This makes my capabilities longer than it needs to be, and caps my number of measures to the number of properties defined in the capabilities.