[RFC] Feed widgets selected categories state from source filters
Clebal opened this issue · 6 comments
Precedents
Currently, a widget like CategoryWidget have a state called selectedCategories
that starts empty by default, when the user selects a category, a filter is applied and the selectedCategories state is updated.
Problem
The problem with this approach is that we're managing widget selected categories in two ways: one inside the widget with the selectedCategories
state and another one with the source filters. This cause that if the filter that that widget creates is already added (because, for example, we saved a previous state that we want to apply again) in the source, the widget doesn't know it because it doesn't update its internal state with filter value.
Solution
I'd advocate for removing widget internal selectedCategories
state and using filter value as replacement to feed the UI and managing the state.
This improvement will be in every widget.
I understand your approach involves reading the filter state in the widget initialization and setting the selected categories (CategoryWidget, PieWidget) or bars (HistogramWidget) depending on the current filters applied to the source using the selected column
property. Also, when you select a category or bar, or clear the selected filters, you will directly updating the filters in the source (as it is done today).
For the categories, I don't see a problem because we have an "IN" filter that should be easy to parse.
I'm not sure what will be the approach with selected bars in histograms. Imagine we have a histogram widget with ticks = [1, 5, 10] and we have set the following filter in the same column used by the histogram: BETWEEN 3 AND 7. What should we do in this case?
Yes @borja-munoz, the HistogramWidget is a different case, but it can be managed easily.
In the filter we have: [1, 5]
, because 5 is the tick number 1, we know that selectedBars
value is [1].
In the filter we have: [10, undefined]
, because undefined is in second place, it means that the selected bar is the last one. Then selectedBars
value is [ticks.length].
In the filter we have: [undefined, 1]
, because undefined is in first place, it means that the selected bar is the first one. Then selectedBars
value is [0].
About your first paragraph:
I would only keep the widget state in the HistogramWidget, in others I would just use filter state as selectedCategories state because it doesn't need any intermediary, you can use it directly.
But this is not how filters are specified for sources. We specify the filter using BETWEEN (for numeric properties).
Also my question was related to the particular case where the BETWEEN interval in the filter does not match with the breaks/ticks in the histogram. If you are filtering the features with value between 3 and 7, what should you display in the [1-5] and the [5-10] bars?
If filter value is between 3 and 7 and the ticks are [1,5,10], then those filters are not applied correctly and then the widget won't have selected bars.
It is indeed. We agree this is a good proposal