Add graph subsystem (Graph, generators, algorithms, GraphPlot) + notebook fixes#11
Open
msollami wants to merge 4 commits into
Open
Add graph subsystem (Graph, generators, algorithms, GraphPlot) + notebook fixes#11msollami wants to merge 4 commits into
msollami wants to merge 4 commits into
Conversation
- Drag on empty canvas draws a dashed selection rectangle; on release any notebooks whose bounds overlap the rect become selected (blue outline glow matching each notebook's accent color) - Dragging a selected notebook by its title bar moves all selected notebooks together by the same world-space delta - Notebook card and minimap now use the same palette index (nb.id numeric suffix) so card border colors always match minimap dots - Horizontal split-handle now stretches full cell height (align-items: stretch) with a 12px hit area and animated ::before visual indicator
… algorithms, visualization Introduce a new src/graph/ subsystem making Graph a first-class symbol, mirroring the src/linalg/ layout (one builtin per translation unit, a graph.h of entry points, and a graph_init() registered from core_init). Graphs are ordinary Expr trees Graph[List[verts], List[edges]] with DirectedEdge/ UndirectedEdge; no new EXPR_* tag and no changes under src/external/. 30 builtins across 19 files: - Construction/predicates: Graph (normalizes ->/<-> and Directed/UndirectedEdge, derives vertices, validates, canonicalizes), GraphQ, DirectedGraphQ, ConnectedGraphQ. - Query: VertexList, EdgeList, VertexCount, EdgeCount, AdjacencyList, VertexDegree/In/Out. - Matrix views: AdjacencyMatrix, IncidenceMatrix, AdjacencyGraph (interop with Det/Tr/Eigenvalues via dense List-of-Lists). - Generators: CompleteGraph, CycleGraph, PathGraph, RandomGraph (seeded RNG). - Algorithms: FindShortestPath, GraphDistance, ConnectedComponents, WeaklyConnectedComponents, StronglyConnectedComponents (Tarjan), FindSpanningTree, VertexConnectivity, over a shared adjacency builder. - Visualization: GraphPlot (circular layout -> Graphics). Parser gains the <-> (TwoWayRule) operator; the printer renders Directed/UndirectedEdge infix and Graph as a terse summary with a round-trippable InputForm. Every builtin has attributes, a docstring, a docs/spec/builtins/graphs.md entry, and changelog notes. New tests/test_graph.c covers normalization, queries, matrix round-trips, generators, algorithms, and GraphPlot structure; wired into the CMake suite.
The notebook's Graphics-to-Plotly serializer only handled Line and Polygon, so
GraphPlot output rendered as a bare line (vertex Disks and Text labels were
dropped, with no equal-aspect layout). Extend graphics_json.c to serialize:
- Disk/Point as marker-mode scatter traces (vertices),
- Text[label, {x,y}] as Plotly annotations (labels),
- a "diagram mode" (triggered when Disk/Text are present) using a square canvas
with hidden axes and yaxis.scaleanchor:"x" so a circular vertex layout stays
circular,
- sub-1e-12 coordinate snapping so floating-point dust (e.g. sin(pi)) does not
blow up an auto-ranged axis.
Plot[] output is unchanged (no Disk/Text, so it keeps the standard axed layout).
Also make the pipe-protocol parse error self-diagnosing: it now echoes the exact
input string ("Parse error: <input>") so a stray/invisible character or bracket
mismatch in the caller's text is visible rather than opaque.
The Edit menu bound custom, unhandled items to the clipboard accelerators (Copy Cell(s) -> Cmd+C, Paste Cell(s) -> Cmd+V, Delete Cell(s) -> Backspace). On macOS a menu accelerator captures the key combination app-wide, so those shortcuts never reached the focused cell editor -- and no frontend listener handled the events, so they did nothing but block the clipboard. Replace them with the predefined Undo/Redo/Cut/Copy/Paste/Select All menu items, which route through the macOS responder chain to the focused text editor. Cmd+C/X/V/A and Cmd+Z now work inside cells, and Backspace is no longer hijacked.
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 a graph subsystem to Mathilda —
Graphas a first-class symbol withconstruction, queries, matrix views, generators, algorithms, and visualization —
plus notebook fixes so
GraphPlotrenders as a node-link diagram and cellcopy/paste works. Graphs are ordinary
Exprtrees(
Graph[List[verts], List[edges]]); no newEXPR_*tag and no changes undersrc/external/.Changes
src/graph/, 30 builtins, one per file): construction/normalization (
Graph), predicates (GraphQ,DirectedGraphQ,ConnectedGraphQ), queries (VertexList,EdgeList, counts,AdjacencyList,degrees), matrix views (
AdjacencyMatrix,IncidenceMatrix,AdjacencyGraph— interop with
Det/Tr/Eigenvalues), generators (CompleteGraph,CycleGraph,PathGraph,RandomGraph), algorithms (FindShortestPath,GraphDistance, connected components incl. Tarjan SCC,FindSpanningTree,VertexConnectivity), andGraphPlot.<->(TwoWayRule) operator; infixDirected/UndirectedEdgeprinting and a terse, round-trippableGraphform.graphics_json.c): serializeDisk/Pointas markersand
Textas annotations, with an equal-aspect diagram layout soGraphPlotdraws correctly (Plot output unchanged).
repl.c): parse errors echo the received input.src-tauri/src/lib.rs): use predefinedCut/Copy/Paste/Select-All/Undo/Redo menu items so cell copy/paste works on
macOS.
docs/spec/builtins/graphs.md+ weekly changelog;Mathilda_spec.mdrows.
Testing
tests/test_graph.c(wired into the CMake suite): normalization of alledge sugars, vertex derivation,
GraphQtruth table, malformed-inputrejection, query builtins,
AdjacencyMatrixsymmetry +AdjacencyGraphround-trip, generator counts/degrees, shortest paths (incl. unreachable),
weak vs. strong components, spanning-tree edge counts, connectivity values,
and
GraphPlotstructure. All pass.-std=c99 -Wall -Wextrabuild; full Desired-End-State REPL walkthroughmatches (e.g.
Eigenvalues[AdjacencyMatrix[4-cycle]] = {-1, 1, -I, I}).follows the SPEC §4 build-from-copies / paired alloc-free contract.
JIRA Ticket
N/A