Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vega advanced cross filtering clears when clicking anywhere on the visual #496

Open
vfridkin opened this issue Aug 31, 2024 · 3 comments
Open

Comments

@vfridkin
Copy link

vfridkin commented Aug 31, 2024

When doing advanced cross filter, after activating pbiCrossFilterApply(), it seems a pbiCrossFilterClear() message activates when clicking anywhere on the visual even when pbiCrossFilterClear() is not in the specification.

This has been tested on the simple visual attached and also with the example [here] (#394 (comment)) after removing the pbiCrossFilterClear() from the specification.

The effect is like this:
1 - make a selection that activates pbiCrossFilterApply()
2 - click anywhere on the visual, even not the chart area
3 - the chart resets and all filters are cleared - unexpected behaviour

240901_crossfilter.zip

In the attachment, test the cross filter by:
1: brush an area
2: click on the 'activate filter' text mark
3: note that the table on the right has been successfully filtered
4: click anywhere on the visual, even outside the chart area, everything clears

Alternatively, dragging the brushed area after 3 and releasing the mouse outside the visual area does not clear everything. In fact, the 'activate filter' text mark can be clicked to filter again. The intended behaviour is that users do not have to release the mouse outside the visual area.

@vfridkin vfridkin changed the title vega advanced cross filtering clears when clicking on the visual vega advanced cross filtering clears when clicking anywhere on the visual Aug 31, 2024
@dm-p
Copy link
Member

dm-p commented Sep 4, 2024

Hi, and sorry for the delay. I'm currently on leave and have limited ability to respond.

From a very quick look, it's possible you may not have added the handling for the "fall-through" to the view. This is a Vega limitation (as it propagates events rather than prevents them) and is mentioned in the Advanced Cross-Filtering documentation.

Adding a mouseup listener to the view (as per the example but renaming for your mark) may help mitigate the situation. I did a quick check, and this doesn't clear the selection:

    // cross filter start ------------------------------------------
    {
      "name": "pbiCrossFilterSelection",
      "value": [],
      "on": [
        // when mark is brushed apply cross filter
        {
          "events": {
            "markname": "activate_filter",
            "type": "click",
            "filter": [
              "event.item && event.item.mark.name == 'activate_filter'"
            ],
            "consume": true,
            "force": true
          },
          "update": "main_brush ? pbiCrossFilterApply(event, \"datum['x'] >= main_brush[0] & datum['x'] <= main_brush[1]\" ) : pbiCrossFilterClear()"
        },
        /* When the view is clicked (but not our mark by name), clear the current cross-filter */
        {
          "events": {
            "source": "view",
            "type": "mouseup",
            "filter": [
              "!event.item || event.item.mark.name != 'main_brush'"
            ]
          },
          "update": "pbiCrossFilterClear()"
        }
      ]
    }

@vfridkin
Copy link
Author

vfridkin commented Sep 5, 2024

Thank you and no worries about any delays! I've read through the documentation on advanced cross filter multiple times (and hopefully understood it too 😄) and used the code you provided however the issue remains, so I believe I did not explain well - please let me try again.

The issue is it clears the filter when it shouldn't. Here are the steps that lead to the issue:

  1. brush a few data points
  2. click on the text mark which triggers the cross filter, table is filtered properly
  3. ISSUE: click anywhere on the visual and it clears the cross filter

image
The use case is that users will cross filter based on a brush selection, then move the brushed area somewhere else without having to restart the brush, do another cross filter, etc... except right now after the first cross filter, if a user moves the brush or clicks on anything in the visual the brushed area disappears.

Please note, the brushed area is recreated each time the cross filter is activated - this part works fine. It is after it is recreated that the issue starts.

I believe this might be a bug as I've tested with the example [here] (#394 (comment)). To test I removed the pbiCrossFilterClear() from the specification and it cleared the cross filter after clicking anywhere on the Deneb visual as in this case.

@vfridkin
Copy link
Author

vfridkin commented Sep 5, 2024

cross_filter.mp4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants