-
Notifications
You must be signed in to change notification settings - Fork 2
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
feat: make scatter plot legends clickable #690
feat: make scatter plot legends clickable #690
Conversation
wip: click changes the colors of points in an unexpected way
As discussed with @dv-usama-ansari , this is already implemented in visyn_core, and ready to use 🙂 |
Implemented in 7d22667 and it works beautifully! Thanks for the hint @dvdanielamoitzi! |
src/vis/scatter/ScatterVis.tsx
Outdated
return <LegendItem key={c} color={colorMap(c)} label={c} onClick={() => onClick(c)} filtered={false} />; | ||
})} | ||
{categories.map((c) => ( | ||
<LegendItem key={c} color={colorMap(c)} label={c} onClick={() => onClick(c)} filtered={hiddenCategories.some((hc) => hc === c)} /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At this point, why dont you just pass the set to the component and use Set.has()?
src/vis/scatter/ScatterVis.tsx
Outdated
<Legend | ||
categories={legendData.color.categories} | ||
colorMap={legendData.color.mappingFunction} | ||
hiddenCategories={[...hiddenCategoriesSet]} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pass the set?
src/vis/scatter/ScatterVis.tsx
Outdated
}); | ||
|
||
React.useEffect(() => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like a very flaky solution. In general I tried to remove all useEffects from the scatter plot, since they visually they introduce the problem of flickering (since they run 2-3 ms after the values changed) and there are just better alternatives.
Without thinking long about it, the solution that I had in mind is to pass the categories to useDataPreparation and just do the filtering the useMemo then this should not be necessary
src/vis/scatter/ScatterVis.tsx
Outdated
@@ -290,6 +313,13 @@ export function ScatterVis({ | |||
internalLayoutRef, | |||
}); | |||
|
|||
React.useEffect(() => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should not be necessary
src/vis/scatter/ScatterVis.tsx
Outdated
} else { | ||
hiddenCategoriesSet.add(e); | ||
} | ||
calculateScatter([...hiddenCategoriesSet]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here we should just set the categories and useDataPreparation should react to that with useMemo
ids.forEach((v, i) => { | ||
idToIndex.set(v, i); | ||
}); | ||
const calculateScatter = React.useCallback( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move this code to the memo
src/vis/scatter/useLayout.tsx
Outdated
@@ -163,6 +164,7 @@ export function useLayout({ | |||
height, | |||
}; | |||
|
|||
setLayout(finalLayout); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove all those
idToIndex, | ||
}; | ||
}, [status, value]); | ||
const finalScatter = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general:
The approach with useEffect and the callback broke multiple things. For instance the state is stale. When I switch between facet/scatter then the legend does not reset (e.g. its still hidden which is weird). Also the regression line switch does not work anymore as well as the scale switch. All these problems can be mitigated if the useMemo is left in place
There are the 4 cases for
- scatter, splom, facet, subplots. They are split up because each case is slightly different. So for each of the 4 cases you need to move the filtering code to the useMemo case and use that data in the plotly component then it should work
…o ua/reprovisyn-2249-make-scatter-plot-legend-clickable
As of 47071b9 2025-01-28.14-00-45.mp4 |
…yn_core into ua/reprovisyn-2249-make-scatter-plot-legend-clickable
As of e6cd58d Fixed selection flickering: 2025-01-30.12-42-57.mp4 |
* chore: prepare next dev release * feat: make scatter plot legends clickable (#690) * feat(wip): make scatter plot legends clickable wip: click changes the colors of points in an unexpected way * fix: build * fix: make legend ui more intuitive to the user * fix: address PR feedback + rectify logic to filter out values on legend click * chore: add comments * basic principle * fix: selectedpoints computation * chore: improve tooltips * chore: cleanup --------- Co-authored-by: Moritz Heckmann <moritz.heckmann@datavisyn.io> * fix: removed use-deep-compare-effect, removed Awaited type (#716) - Removed **use-deep-compare-effect** from package.json, since we have our own version - Removed Awaited<T> type, since TS 4.5 has an inbuilt one - Moved 4 individual state properties to one common object, to remove flaky behavior (double renders with out-of-sync values) in case React will not batch the setStates * feat: add waitForClientConfig flag to allow skipping the wait for the clientConfig (#717) feat: add waitForClientConfig flag to skip waiting for the clientConfig * Prepare release version 16.1.0 --------- Co-authored-by: datavisyn-bot <> Co-authored-by: Usama Ansari <115616380+dv-usama-ansari@users.noreply.github.com> Co-authored-by: Moritz Heckmann <moritz.heckmann@datavisyn.io> Co-authored-by: Moritz Heckmann <77104411+dvmoritzschoefl@users.noreply.github.com> Co-authored-by: Michael Pühringer <51900829+puehringer@users.noreply.github.com>
Closes https://github.com/datavisyn/reprovisyn/issues/2249
Developer Checklist (Definition of Done)
Issue
UI/UX/Vis
Code
PR
release: minor
) to this PR following semverCloses #...
)Summary of changes
Screenshots
EDIT: As of 47071b9
2025-01-28.14-00-45.mp4
Additional notes for the reviewer(s)