deneb-viz / deneb

Deneb is a custom visual for Microsoft Power BI, which allows developers to use the declarative JSON syntax of the Vega or Vega-Lite languages to create their own data visualizations.
https://deneb-viz.github.io
MIT License
193 stars 15 forks source link

Bind Vega signals to the Visualization Pane inputs (a dream) #279

Open avatorl opened 1 year ago

avatorl commented 1 year ago

I don't know if it will ever be possible in any custom visual (or if Deneb will ever become a native visual, or if it's even possible in a native visual). But it will significantly simplify the way how custom visualizations for Power BI are being created and it will deeply integrate Vega into Power BI.

The idea is in binding Vega signals to the corresponding Visualization pane controls.

Basically, if there is Vega signal

    {
      "name": "colorTitle",
      "value": "#333333"
    }

Then a color selector should automatically appear on the Format Visual tab of the Visualization pane. An fx button for Measure driven conditional formatting should appear there as well.

image

I assume Vega signal will need "element" property to be defined.

image

And Deneb visual should create corresponding input elements on the Visualization pane for all Vega signals with "element" property defined.

As a result any Vega visualization inside of Deneb will act like an unique custom visual with its own Visualization pane settings. Any Power BI Desktop user will be able to control formatting settings of the Vega visualization using native Power BI Visualization pane visual interface. There will be no need in editing Vega code just to change formatting settings (assuming there were signal created for all important properties of the Vega visualization). It will be easy to fully control Vega visualization from other visuals/slicers on the page (via DAX measures bound to the Vega signals).

Giammaria commented 1 year ago

This would be a nice feature. It may be tricky to implement though since the objects property in the capabilities.json file for Deneb needs to be defined ahead of time. I guess one could predefine those properties with the common properties defined in a Vega spec’s config section. Then I imagine there would need to be some sort of naming convention either in the param/signal name or in its description to be able to tie the signal value to the appropriate power bi formatting option. You could have only those properties that have a matching signal defined in the spec show up in the formatting pane. In this scenario the spec authors would need to know these naming conventions in order to use this functionality. Pretty significant L.O.E if I had to guess, but would be really useful for sharing templates with report developers that don’t have the bandwidth to learn the Vega languages.

dm-p commented 1 year ago

I already provided a thought-based reply for this on the Twitter thread where it originated, but it's been playing on my mind as a concept, particularly as I was thinking of doing custom signals in v2. I've written about these somewhere as an idea but can't find where, but essentially this was centred around the concept of reserving named properties in the formatting pane that could have values or measures bound to them that would create named signals in the Vega view with the property values. The challenge around these is that they can only be textual or numeric, as conditional formatting doesn't support other types, and we would have to explicitly reserve n properties (so if you want n + 1, this is not really possible without adding the capability for it, rebuilding the visual and re-publishing it).

@Giammaria has already noted the same thing as the tweet in that you conventionally have to declare your objects and properties in the visual's capabilities so that Power BI has a list of valid properties for your visual, e.g.:

image

You can absolutely declare a dynamic property at run time, but all it does is create a control in the pane. This can be whatever you specify via code (as you need to write code to choose the correct controls etc. for the specified names, and some logic to populate the pane). We could call this something like dynamicProperty, and this would render for the user, e.g.:

image

So, realistically... this bit we could do. We might even be able to look at the element type from the binding (V | VL) if we had enough time, and create sliders or dropdowns or whatever.

Here's where the idea breaks down though (as we might expect). Because dynamicProperty is not a declared valid property in the visual capabilities, if we change the value, the main window does not store it in the visual metadata, and the value is therefore never passed to the visual when the pane is re-evaluated on the next update (when values, if different from their defaults are made available to the visual logic) :(

We can't even use the persist property API to forcibly push it into the visual's objects in the main window, as Power BI discards unknown property names (I've tested with a known property also and that gets updated remotely, as expected).

I'm happy to make a feature request to MS to see if it's possible to allow dynamic property declaration for this use case, but I'm pretty sure there will be a reason why this isn't already possible. But I can appreciate and understand the use case, so if I hear anything back, I'll be sure to try and update this.

dm-p commented 1 year ago

I've raised an idea for this with the custom visuals folks, so (as stated in the previous comment), I'll let you know if we get any traction with it.

avatorl commented 1 year ago

Thank you Daniel,

It will be really great if they can allow dynamic property declaration. I have had a meeting recently with a potential client who wanted a bunch of highly customized data visualizations and Vega is perfect tool to make them. But what stops him from using Deneb-Vega is lack of Visualization Pane controls to edit visualization settings. So, I'm sure this feature is a real game changer.

but I'm pretty sure there will be a reason why this isn't already possible In this case, as I understand, possible workaround is to create clones of Deneb visual with pre-defined capabilities (for each Vega visualization). I understand that I need to edit capabilities.json to add properties to Visualization pane. But how hard is it to bind Vega signals to these pre-defined properties? Do you have any example of how to do such binding?

dm-p commented 1 year ago

It's not hard per se, but it is a lot of work. If you were looking to do this, the high-level approach might be:

Note that if you clone the visual you will also need to update its guid in pbiviz.json, as Power BI will always load the latest version from AppSource if the guid is known. By severing the guid, you also will not be able to leverage the benefits of the visual being certified (if that's what you need), as it's tied to the guid in AppSource so that people cannot abuse this method. This is how the standalone/alpha/beta builds work - the build process replaces the guid in the source code with an independent one.

dm-p commented 1 year ago

MS are not going to help with making dynamic properties a reality, and I've been thinking about it in conjunction with some of the other requests that have come through around better customization of the displayed elements for params/signals. I've also done research into how external element binding works with Vega, and while we can do this inside the visual with a form element that we create there, we cannot bind to elements in the properties pane, as they are outside the sandbox (and therefore invisible to a custom visual).

I would like to propose an alternative solution. We will need to do a proof-of-concept to explore how well it works, but hopefully it will be possible, and can be a good compromise for building templates that can be modified without going into the editor. Instead of relying on the Power BI formatting properties (that we will not be able to dynamically create), we:

If a PoC works, we can consider things like:

In terms of timings, I would think that we could do a PoC and add this is a 'preview feature', which would be enabled via a property in the properties pane. If this is enabled, then visuals that have this flag enabled would provide the above functionality and allow importing of templates created with this feature. If and when we move the PoC to an MVP for all users, this feature flag would be removed and would be a supported feature.

Does this sound like a good compromise? It will be a lot of work from my end to R&D a PoC so I'd like to be sure that this could be conceptually workable for you as an option before I proceed.

avatorl commented 8 months ago

@dm-p I've missed to answer to you last comment somehow (well, I was badly sick back in September).

That sounds like a great workaround. Requires a few more clicks to open (vs Power BI Format pane), but sounds really good as a workaround. It would be good to have an option to make this new Format pane open by default (instead of Specification pane).

dm-p commented 8 months ago

I actually have a PoC put together for this but it is a little rough around the edges. I'm a bit busy with life over the next few weeks and taking some time off, but remind me sometime after 18th March (when I'm due back) and I can show you what I have as an idea so far

HenrikJeppsson commented 3 weeks ago

The main reason for this feature request is probably that vega json is "scary" for end users. And implementation of a nice looking gui solution to bind properties may be a lot of work.

I think you can get a long way with only a simple separate config page (json, yaml or simply key-value pairs of parameters). Then you could utilize magic tokens in the vega code that is replaced like a pre processor. This way folks that are fluent in vega can do the complex stuff and only expose simple parameters like BGColor.