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
190 stars 15 forks source link

Enhancement Suggestions: Improved Signal Display, Formatting of UPDATE Signals, and Dynamic Tooltips #449

Open CSalcedoDataBI opened 4 months ago

CSalcedoDataBI commented 4 months ago

Hello @dm-p,

First of all, thank you very much for all your hard work and effort invested in this wonderful visual. I would like to make some suggestions; some might not be feasible, but I want to share them anyway.

Is it possible that in the signals tab, when there is one containing a large object or array, we can view the information through the tool as shown in the attached image?

image

My second suggestion:

Is it possible for Vega signals of type UPDATE, which contain objects, to be properly formatted? Please refer to the attached GIF for more clarity.

PBIDesktop_YmWcY32a7f

My third suggestion concerns JSON objects in tooltips. Is there a way for these to receive an expression in the key, as shown in the image, for more dynamic tooltip scenarios? I'm thinking of something like a "pbiTooltip" function, similar to the Deneb-specific functions like pbiFormat or pbiColor.

image

Thank you very much for considering these suggestions!


dm-p commented 4 months ago

Hi @CSalcedoDataBI, and thanks for the suggestions. Please consider creating an issue for each individual request, as it makes it easier to keep any discussions and work focused on what is being requested rather than having to manage multiple threads.

For your first request, I have split this out into #450.

Your second request will not be possible, unfortunately. You can't line-break a string value in JSON - this Stack Overflow answer may provide more clarification.

Your third request is a bit 50:50 - your example is actually a syntax error based on ES6 syntax and normally you might use a computed property name by surrounding it with square brackets, or a template literal in square brackets to create a dynamic property in an object. However, Vega's parser doesn't support this currently. This would need to be fixed/enabled to work as you intend here.

The way I've dealt with this in the past is to create a datum, based on a series of transforms, such as a pivot. Here's a quick and dirty example of a series-based line chart with this technique for Vega-Lite:

image

The relevant portion is this:

{
  "data": {"name": "dataset"},
  "layer": [
    {
     ...
      "transform": [
        {
          "pivot": "Segment",
          "value": "$ Sales__formatted",
          "op": "min",
          "groupby": ["Date"]
        }
      ],
      "mark": {
        "type": "rule",
        "strokeWidth": 1,
        "tooltip": {"content": "data"}
      },
      ...
    },
    ...
  ],
  ...
}

It may be possible to think along these lines for Vega, but it's not something I've tried yet.


As already mentioned, I think the right way to solve this is with vega-expression, but hypothetically, a custom function might need to look like the following:

pbiKeyValue ( [ [ key1, value1 ], [key2, value2], ... ] )

This would be an array of 2-element arrays, which could potentially output this to the tooltip handler:

{
    "key1": "value1",
    "key2": "value2"
}

In your case, this might look as follows:

pbiKeyValue ( [ [ datum['Product'], datum['Sum of Sales'] ], ['X', 100], ... ] )

Resulting in:

{
    "Amarilla": 494439759,
    "X": 100
}

I will have to think in more detail when the backlog is a bit clearer as to whether this is a suitable solution or if it creates other problems. I'll keep this issue open to focus on this specific problem and as discussed, question 1 can be handled in #450.

CSalcedoDataBI commented 4 months ago

Wow, @dm-p ! I am truly impressed and deeply grateful for your willingness to consider these improvements. Thank you so much for the example you provided; it's extremely useful for understanding other contexts where this functionality could be beneficial.

Regarding the management of JSON in tooltips with Vega, I have managed to implement solutions using conditionals with multiple JSON objects, such as:

"tooltip": {"signal": "ScenarioParameter==1 ? {...} : ScenarioParameter==2 ? {...} : ScenarioParameter==3 ? {...} : {...}"}

However, this approach becomes limited when I need to handle more than two or three different analysis scenarios in a visualization. Each scenario requires its own JSON object, which can make the code quite extensive.

Vega already offers us many powerful options, but the idea of creating a function that simplifies this operation would truly be revolutionary. I am overjoyed to know that you will consider a solution to this challenge. I am very excited to see what new capabilities we might explore with this improvement!