Add getMappedGraph and getFilteredGraph transforms - #33
Merged
Conversation
Predicate-based filtering and data-mapping transforms that preserve graph structure, closing the map/filter API gap with effect/graph (mapNodes/mapEdges/filterNodes/filterEdges). Dropping a node drops its incident edges and strips dangling parent/initial references, matching getSubgraph semantics. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01ATzbKkoDMTaWLqD8xZBQNv
Forward graph-level direction and style in getMappedGraph, getFilteredGraph, getSubgraph, and getReversedGraph so transformed graphs keep their top-level drawing settings. Adds a changeset for the new transforms. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01ATzbKkoDMTaWLqD8xZBQNv
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds two structural transforms to
transforms.ts, rounding out the transform family (getSubgraph,getReversedGraph,getLineGraph,getFlattenedGraph):getMappedGraph(graph, { node?, edge? })— returns a new graph with node and/or edgedatatransformed by mapping functions. Structure (IDs, endpoints, hierarchy, ports, layout, weights) is fully preserved; onlydatachanges. Generic over the new data types (Graph<N, E, G, P>→Graph<N2, E2, G, P>), and returningundefinedclearsdata.getFilteredGraph(graph, { node?, edge? })— returns a new graph keeping only nodes/edges that pass the given predicates. Dropping a node also drops its incident edges and strips danglingparentId/initialNodeIdreferences, matchinggetSubgraphsemantics (reuses the same scoping helper).Chaining the two covers filter-then-map workflows.
getSubgraphremains the ID-list form;getFilteredGraphis the predicate form.Changes
src/transforms.ts: newgetMappedGraph,getFilteredGraph, and theirMappedGraphOptions/FilteredGraphOptionstypessrc/index.ts: export the new functions and option typestests/transforms.test.ts: 8 new tests (data mapping, structure preservation, incident-edge removal, dangling-reference stripping, predicate combinations, no-op copies)README.md: structural transforms list updatedTesting
pnpm vitest run— 1860 tests pass (82 files)pnpm typecheck— clean🤖 Generated with Claude Code
https://claude.ai/code/session_01ATzbKkoDMTaWLqD8xZBQNv
Generated by Claude Code