Skip to content

Issue 793/tabular view of data/data download of filtered charts#188

Merged
StRhys merged 8 commits intomainfrom
issue-793/Tabular-view-of-data/data-download-of-filtered-charts
Mar 27, 2023
Merged

Issue 793/tabular view of data/data download of filtered charts#188
StRhys merged 8 commits intomainfrom
issue-793/Tabular-view-of-data/data-download-of-filtered-charts

Conversation

@StRhys
Copy link
Copy Markdown
Contributor

@StRhys StRhys commented Mar 2, 2023

This ticket allows for filters that have been applied to charts to feed through into the data tab view and the downloadable csv. Filters can be applied by clicking on the legend of a chart. Legends can also be double clicked to have different effects on filters depending on what filters are already applied.

This could have been me doing something wrong but Plotly has a few issues which tie to clicking on the legend.
The first being when a legend click event triggers it will pass an event which contains the data the chart, with also has series visibility on (true, undefined, and 'legendonly'). The issue with this is it will contain the data of the chart pre click, so using it to set the filters on the chart becomes complicated and impossible when a double click triggers, which can turn on/off multiple filters. So this method isn't used.

So I decided to use an array to track which series have been filtered. Event data passes a 'curveNumber' which is the index of the clicked series. The issue that arose was that this click trigger event wouldn't lead to the state of the index array being set, it was only set when switching tabs. The logic behind tracking filtered indexes needs an up to date array and so in the end a normal variable array was used to track the current index array, with another one used to keep state when switching tabs.

@StRhys StRhys self-assigned this Mar 2, 2023
@StRhys StRhys marked this pull request as ready for review March 16, 2023 11:17
@StRhys StRhys requested review from eldeal and mikeAdamss March 16, 2023 11:17
@StRhys StRhys force-pushed the issue-793/Tabular-view-of-data/data-download-of-filtered-charts branch from 3c30de8 to 4834a38 Compare March 16, 2023 14:46
Copy link
Copy Markdown

@eldeal eldeal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll take another look at it on Monday. Some of the logic is not quite clicking for me but that could just be a Friday thing! :)


const onLegendClick = (e: any) => {
// check if the passed 'e.curveNumber' is in filteredColumnIndexes
// if it is, that means its filter is on and should be turned off
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm finding it tricky to keep track of whether 'filtered' means present or not present. These 2 lines of comment I think accentuate the point. Is it worth considering renaming it to 'hidden' or 'visible' so its clearer what the consequence of the filter action is? so filteredColumnIndexes might become visibleColumnIndexes or something?

If not, I think at least in these comments it would be helpful to be clearer that if it is, that means its filter is on and the column should not be visible or whatever the appropriate consequence is

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've renamed filteredColumnIndexes to hiddenColumnIndexes, and reworded some comments for clarity.
I think I'm biased so if it's still not clear I'm happy to expand further.

const filteredData = data.filter(
(_element: any, index: number) => !indexes.includes(index),
);
// this setting of filteredColumnIndex is here because onLegendClick fires twice when
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont know if this is the same thing, but would configuring the double click delay help prevent it getting picked up as 2 clicks? https://plotly.com/javascript/configuration-options/#double-click-delay

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good find, I had a play with it but it was still firing the single click twice. It was just delaying how long it took to put the filter on the actual chart, this could be an issue with plotly though.
https://plotly.com/javascript/reference/layout/#layout-legend-itemdoubleclick
We do have the option of changing what the double click does.

- rename filteredColumnIndexes to hiddenColumnIndexes
Copy link
Copy Markdown

@eldeal eldeal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment and variable updates make it much clearer 👍

@StRhys StRhys merged commit 79f3bab into main Mar 27, 2023
@StRhys StRhys deleted the issue-793/Tabular-view-of-data/data-download-of-filtered-charts branch March 27, 2023 15:39
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

Successfully merging this pull request may close these issues.

3 participants