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

Deeper Identity Extraction from datum Objects #297

Open dm-p opened 1 year ago

dm-p commented 1 year ago

In Vega, if we use a mark that derives data from another mark (e.g., a text mark representing a label for one that has already had a layout transform like force applied to it), then the underlying data point from the Power BI dataset gets further abstracted to a datum property of that datum.

Deneb currently only looks for the top-level datum property against a mark and returns that for any attempt to resolve a data point for interactivity purposes. As such, marks that derive from these are not eligible for interactivity in the same way that regular marks are.

It is possible to work around this by adding a transform to the mark containing the affecting transform that hoists the __identity__ field to that level, e.g.:

      "transform": [
        ... layout transform already included here ...
        {
          "type": "formula",
          "expr": "datum.datum.__identity__",
          "as": "__identity__"
        },
      ]

This is then available to Deneb in the subsequent mark and can then be eligible for interactivity (and will be visible in that mark's dataset without having to look at the datum).

The same approach will need to be done for any fields that may be needed to leverage interactivity, e.g., the __selected__ field, or the creator can chain as many datum properties as needed (depending on depth).

It is likely not possible that we can inject the other fields to the relevant place in the spec and the burden may be on the creator here, but we should be able to search deeper for presence of an __identity__ field when Deneb checks a mark for presence of this field.

Giammaria commented 1 year ago

Very good to know. Thanks for this.