From 4d7f947bca5059bc83f4a6430d5acfa42e83070d Mon Sep 17 00:00:00 2001 From: Manfred Cheung Date: Mon, 9 Jun 2025 17:49:14 -0400 Subject: [PATCH 1/4] add `resetFilters` and `resetExclusions` calls --- CHANGELOG.md | 1 + projects/client-api-react/src/bindings.js | 4 +++- projects/client-api/src/index.js | 28 +++++++++++++++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 19c4da8..ec71d12 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline ### Added * **client-api-react**: Add `pointStrokeWidth` and `showCollections` bindings +* **client-api**: Add `resetFilters` and `resetExclusions` calls ### Security diff --git a/projects/client-api-react/src/bindings.js b/projects/client-api-react/src/bindings.js index f452b71..f6dfcc4 100644 --- a/projects/client-api-react/src/bindings.js +++ b/projects/client-api-react/src/bindings.js @@ -126,7 +126,9 @@ const bindings = // TODO: infer this from chainList in client-api const calls = bindings.map(b => b.jsCommand).filter(Boolean).concat([ 'setSelectionExternal', - 'setHighlightExternal' + 'setHighlightExternal', + 'resetFilters', + 'resetExclusions' ]) export { bindings, panelNames, calls }; \ No newline at end of file diff --git a/projects/client-api/src/index.js b/projects/client-api/src/index.js index 1f41114..0ae8100 100644 --- a/projects/client-api/src/index.js +++ b/projects/client-api/src/index.js @@ -1209,6 +1209,20 @@ export function addFilters(expr) { } chainList.addFilters = addFilters; +/** + * Reset all filters in a visualization + * @function resetFilters + * @return {@link GraphistryState} A {@link GraphistryState} {@link Observable} that emits the result of the operation + * @example + * GraphistryJS(document.getElementById('viz')) + * .pipe(resetFilters()) + * .subscribe(); + */ +export function resetFilters() { + return makeCaller('view', 'filters.reset', []); +} +chainList.resetFilters = resetFilters; + /** * Add an exclusion to the visualization with the given expression * @function addExclusion @@ -1253,6 +1267,20 @@ export function addExclusions(expr) { } chainList.addExclusions = addExclusions; +/** + * Reset all exclusions in a visualization + * @function resetExclusions + * @return {@link GraphistryState} A {@link GraphistryState} {@link Observable} that emits the result of the operation + * @example + * GraphistryJS(document.getElementById('viz')) + * .pipe(resetExclusions()) + * .subscribe(); + */ +export function resetExclusions() { + return makeCaller('view', 'exclusions.reset', []); +} +chainList.resetExclusions = resetExclusions; + /** * UNSTABLE: Set the selection. * Currently, this uses internal ids and will be updated to use external ids. From 12aeb7104ed2ae8f9647937cf2d3dd69542f1299 Mon Sep 17 00:00:00 2001 From: Manfred Cheung Date: Wed, 11 Jun 2025 19:10:46 -0400 Subject: [PATCH 2/4] update changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ec71d12..2b98079 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,7 +8,7 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline ### Added * **client-api-react**: Add `pointStrokeWidth` and `showCollections` bindings -* **client-api**: Add `resetFilters` and `resetExclusions` calls +* **client-api**: Add `resetFilters` and `resetExclusions` calls, requires minimum Graphistry version 2.42.18 ### Security From df7c21b4440ed139ab321f8b334d7c78d0afa64a Mon Sep 17 00:00:00 2001 From: Manfred Cheung Date: Thu, 12 Jun 2025 15:13:58 -0400 Subject: [PATCH 3/4] add storybook doc --- .../src/stories/GraphistryJS.stories.jsx | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/projects/client-api-react/src/stories/GraphistryJS.stories.jsx b/projects/client-api-react/src/stories/GraphistryJS.stories.jsx index ab99873..fdae251 100644 --- a/projects/client-api-react/src/stories/GraphistryJS.stories.jsx +++ b/projects/client-api-react/src/stories/GraphistryJS.stories.jsx @@ -8,6 +8,8 @@ import { updateSetting, addFilters, addExclusions, + resetFilters, + resetExclusions, togglePanel, toggleToolbar, toggleHistograms, @@ -294,6 +296,46 @@ export const setFilters = { }, }; +export const ResetFilters = { + render: (args) => { + const iframe = useRef(null); + const [messages, setMessages] = useState(['loading...']); + + useEffect(() => { + //////// Instantiate GraphistryJS for an iframe + const sub = + (graphistryJS(iframe.current) + .pipe( + tap(() => + setMessages((arr) => arr.concat([`graphistryJS instantiated; pausing 3s...`])) + ), + delay(3000), + tap(() => setMessages((arr) => arr.concat([`adding filters`]))), + addFilters( + args.filters || ['point:community_infomap in (4, 5, 6)', 'point:degree > 1'] + ), + addExclusions(args.exclusions || ['edge:id = 1']), + togglePanel('filters', false), + tap(() => setMessages((arr) => arr.concat([`pausing before removing filters`]))), + delay(3000), + tap(() => setMessages((arr) => arr.concat([`removing filters`]))), + resetFilters(), + resetExclusions() + ) + .subscribe(() => null), + (err) => setMessages((arr) => arr.concat([`Error: ${err}`])), + () => setMessages((arr) => arr.concat(['Completed']))); + //////// + return () => (sub.unsubscribe ? sub.unsubscribe() : null); + }, [iframe]); + + return <> +