-
Notifications
You must be signed in to change notification settings - Fork 6
Graph Response Area (Re-opened) #8
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
Open
HongleiGu
wants to merge
45
commits into
lambda-feedback:main
Choose a base branch
from
lambda-feedback:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
45 commits
Select commit
Hold shift + click to select a range
a39f305
feat: first FSA draft with Reactflow, the wizard definitely need some…
HongleiGu b9e9a30
fix: dev notice in FSA.md
HongleiGu 675d612
fix: updated UI display, removed prompting, add information panel, ne…
HongleiGu da333ba
refactor: Reactflow is not so suitable for maths, changing to cytosca…
HongleiGu 21e9a11
fix: align with the backend, can pass basic tests
HongleiGu 3e813d7
feat: added feedback
HongleiGu a467516
Merge pull request #3 from HongleiGu/cytoscape
HongleiGu 5456800
fix: remove debugging logs
HongleiGu 897f324
Merge pull request #4 from HongleiGu/cytoscape
HongleiGu 822f87e
feat: implement GraphQL data fetching and add live preview functional…
JohnnyWan1123 8b60ada
fix: style modification
HongleiGu 107050e
Merge branch 'preview' of github.com:HongleiGu/FSA-response-area into…
HongleiGu ce94457
Merge pull request #5 from HongleiGu/preview
HongleiGu c88db1b
revert: revert back to before preview
HongleiGu b7c8401
Merge pull request #6 from HongleiGu/cytoscape
HongleiGu 1370a0d
fix: styles forgetten by the revert
HongleiGu 04a1e4d
feat: should be everything
HongleiGu 88b141a
Merge pull request #7 from HongleiGu/cytoscape
HongleiGu 690aff5
feat: first draft, still need fix
HongleiGu 3117859
implemented feedback panel
HarrySu123 605e6e6
fixed panels
HarrySu123 06f1588
functioning front end
HarrySu123 544c107
Merge branch 'main' into sync
HongleiGu 1c4f985
Refactor code structure for improved readability and maintainability,…
HarrySu123 c60111a
feat: added configuration panel to control evlauation type
HarrySu123 f7cb4e1
Merge pull request #1 from lambda-feedback/sync
HongleiGu 01853f5
feat: removed redundant graph eidotr in answer response area
HarrySu123 5695892
Merge branch 'main' of github.com:lambda-feedback/Graph-response-area…
HongleiGu 210e4c4
feat: made markdown file for Graph and deleted FSA.md
HarrySu123 684c86d
fix: removed unnecessary gitignore items
HarrySu123 0406b54
fix: removed mention and FSA in README.md and replaced with Graph ref…
HarrySu123 af2e31d
fix: removed commented out code
HarrySu123 3dc8d16
feat: removed validation on the front end, and removed preview panel …
HarrySu123 8a520b4
feat: removed utils.ts, duplicated algorithm
HarrySu123 594188d
fix: student response area not influenced by reference answer graph e…
HarrySu123 85dd5a2
fix: moved Graph.component styles into its own file
HarrySu123 c891e36
fix: moved styles from ConfigPanel out into its own files
HarrySu123 bc1152e
feat: updated Graph.md
HarrySu123 4a2f42f
feat: removed all consol logs
HarrySu123 555aa31
fix: removed magic numbers in graph.components.tsx
HarrySu123 b5d2a77
fix: removed use of compressed Graph
HarrySu123 eb504fc
feat: used Vite version 7.0.0
HarrySu123 a7ec6fa
fix: added back missing imports
HarrySu123 faaf3e4
fix: added back removed response types
HarrySu123 46c160a
feat: updated Graph.md
HarrySu123 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,4 +15,4 @@ yarn-error.log* | |
| tsconfig.tsbuildinfo | ||
|
|
||
| # env files (copy .env.example) | ||
| .env | ||
| .env | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,220 @@ | ||
| # Graph Module Documentation | ||
|
|
||
| This module provides a visual editor for Graphs built with **Cytoscape.js** and **Paper.js**. It bridges a **Python-style backend** (deeply nested objects) and a **TypeScript/Zod frontend** (restricted to 2-level JSON nesting via pipe-delimited strings). | ||
|
|
||
| --- | ||
|
|
||
| ## 1. The Core Data Structures | ||
|
|
||
| ### Frontend Schema (`Graph`) | ||
|
|
||
| The full graph type used internally by the editor. Defined as a Zod schema in `type.ts`. | ||
|
|
||
| ```typescript | ||
| type Graph = { | ||
| nodes: Array<{ | ||
| id: string; | ||
| label?: string; | ||
| x?: number; | ||
| y?: number; | ||
| metadata: Record<string, any>; | ||
| }>; | ||
| edges: Array<{ | ||
| source: string; | ||
| target: string; | ||
| weight?: number; // currently unused | ||
| label?: string; | ||
| id?: string; | ||
| metadata: Record<string, any>; | ||
| }>; | ||
| directed: boolean; | ||
| weighted: boolean; // currently unused | ||
| multigraph: boolean; // currently unused | ||
| metadata: Record<string, any>; | ||
| } | ||
| ``` | ||
|
|
||
| ### Flattened Schema (`SimpleGraph`) | ||
|
|
||
| To satisfy the `jsonNestedSchema` (2-level nesting limit, Shimmy communication issues), nodes and edges are serialised as pipe-delimited strings. | ||
|
|
||
| ```typescript | ||
| type SimpleGraph = { | ||
| nodes: string[]; // Format: "id|label|x|y" | ||
| edges: string[]; // Format: "source|target|weight|label" | ||
| directed: boolean; | ||
| weighted: boolean; | ||
| multigraph: boolean; | ||
| evaluation_type: string[]; | ||
| } | ||
| ``` | ||
|
|
||
| ### Config Schema (`GraphConfig`) | ||
|
|
||
| Teacher-configured parameters stored separately in `config`, **not** in the answer. `evaluation_type` is a plain string (the backend Pydantic `EvaluationParams` expects a string, not an array). | ||
|
|
||
| ```typescript | ||
| type GraphConfig = { | ||
| directed: boolean; | ||
| weighted: boolean; | ||
| multigraph: boolean; | ||
| evaluation_type: string; // e.g. 'connectivity', 'isomorphism', ... | ||
| } | ||
| ``` | ||
|
|
||
| ### Answer Schema (`GraphAnswer`) | ||
|
|
||
| Topology-only answer — config flags live in `GraphConfig`, not here. | ||
|
|
||
| ```typescript | ||
| type GraphAnswer = { | ||
| nodes: string[]; // pipe-delimited node strings | ||
| edges: string[]; // pipe-delimited edge strings | ||
| } | ||
| ``` | ||
|
|
||
| ### Validation & Feedback Types | ||
|
|
||
| ```typescript | ||
| enum CheckPhase { Idle = 'idle', Evaluated = 'evaluated' } | ||
|
|
||
| interface ValidationError { | ||
| type: 'error' | 'warning' | ||
| message: string | ||
| field?: string | ||
| } | ||
|
|
||
| interface GraphFeedback { | ||
| valid: boolean | ||
| errors: ValidationError[] | ||
| phase: CheckPhase | ||
| } | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| ## 2. File Structure | ||
|
|
||
| ``` | ||
| src/types/Graph/ | ||
| Graph.component.tsx # GraphEditor — Cytoscape + Paper.js visual editor (panel inlined) | ||
| Graph.component.styles.ts # makeStyles (emotion/tss-react) styles for GraphEditor | ||
| index.tsx # GraphResponseAreaTub, WizardPanel, InputComponent | ||
| type.ts # All Zod schemas, types, and conversion utilities | ||
| components/ | ||
| ConfigPanel.tsx # Teacher config UI (graph type, evaluation type) | ||
| ConfigPanel.styles.ts # makeStyles styles for ConfigPanel | ||
| ``` | ||
|
|
||
| > **Note:** Styles use `makeStyles` from `@styles` (tss-react/emotion) rather than CSS modules. This is required because the project builds as an IIFE library — CSS modules are extracted into a separate file that may not be loaded by the consuming app, while emotion injects styles at runtime inside the JS bundle. | ||
|
|
||
| --- | ||
|
|
||
| ## 3. Key Components | ||
|
|
||
| ### `Graph.component.tsx` — `GraphEditor` | ||
|
|
||
| The primary visual editor. | ||
|
|
||
| - **Rendering**: Uses **Cytoscape.js** for graph rendering and interaction. | ||
| - **Draw Mode**: Uses **Paper.js** (overlaid canvas) for freehand drawing: | ||
| - **Draw a circle** → creates a new node at the circle's centre. | ||
| - **Draw a line between nodes** → creates a new edge between the two closest nodes. | ||
| - **Click two nodes** (while in draw mode) → creates an edge between them. | ||
| - **Selection**: Clicking a node or edge selects it; its properties appear in the inlined **Item Properties** side panel. | ||
| - **Sync**: Every mutation (add/delete/edit) calls `syncToGraph()`, which reads Cytoscape state and fires `onChange(graph)`. | ||
|
|
||
| ### `components/ConfigPanel.tsx` | ||
|
|
||
| Teacher-facing configuration panel (rendered in `WizardComponent` only). | ||
|
|
||
| - Toggle **Directed / Undirected**. | ||
| - Select an **Evaluation Type** (e.g. `isomorphism`, `connectivity`, `tree`, ...). | ||
| - Accepts an optional `AnswerPanel?: React.ReactNode` prop, rendered below the evaluation-type selector when `isomorphism` is selected. | ||
| - Styles are extracted to `ConfigPanel.styles.ts`. | ||
|
|
||
| ### Item Properties Panel (inlined in `Graph.component.tsx`) | ||
|
|
||
| Left side panel rendered directly inside `GraphEditor` for editing selected elements: | ||
|
|
||
| - **Add Node** button. | ||
| - **Fit to Screen** button. | ||
| - **Draw Edge** toggle (activates draw mode). | ||
| - Edit **Display Name** of a selected node. | ||
| - Edit **Edge Label** of a selected edge. | ||
| - **Delete** button for nodes and edges. | ||
|
|
||
| --- | ||
|
|
||
| ## 4. Transformation Logic | ||
|
|
||
| Conversion utilities in `type.ts` handle the boundary between the rich editor format and the flattened wire format. | ||
|
|
||
| | Function | Source | Target | | ||
| |---|---|---| | ||
| | `toSimpleGraph(graph, evaluationType?)` | `Graph` | `SimpleGraph` | | ||
| | `fromSimpleGraph(simple)` | `SimpleGraph` | `Graph` | | ||
| | `graphAnswerToSimple(answer, config)` | `GraphAnswer` + `GraphConfig` | `SimpleGraph` | | ||
| | `simpleToAnswer(simple)` | `SimpleGraph` | `GraphAnswer` | | ||
|
|
||
| --- | ||
|
|
||
| ## 5. Usage in the Pipeline | ||
|
|
||
| 1. **Load**: Data arrives from the backend as a flattened answer object (nodes + edges + config flags merged together). | ||
| 2. **Convert**: `fromSimpleGraph(graphAnswerToSimple(answer, config))` reconstructs the rich `Graph` for the editor. | ||
| 3. **Edit**: The user interacts with `GraphEditor`. Internal state stays in the rich `Graph` format. | ||
| 4. **Save**: On change, `simpleToAnswer(toSimpleGraph(graph))` flattens the topology back. Config flags are merged into the answer object before sending to the backend: | ||
| ```typescript | ||
| const flatAnswer = { | ||
| ...answer, | ||
| directed: config.directed, | ||
| weighted: config.weighted, | ||
| multigraph: config.multigraph, | ||
| evaluation_type: config.evaluation_type, | ||
| } | ||
| ``` | ||
|
|
||
| ### Legacy migration | ||
|
|
||
| `extractConfig` and `extractAnswer` in `GraphResponseAreaTub` handle two legacy cases: | ||
| - `evaluation_type` stored as `string[]` (old format) — first element is taken. | ||
| - Config flags flattened directly into the answer object (old format) — flags are read from there and a proper `GraphConfig` is reconstructed. | ||
|
|
||
| --- | ||
|
|
||
| ## 6. Important Implementation Notes | ||
|
|
||
| - **Node IDs**: Auto-generated as `n0`, `n1`, `n2`, ... The counter tracks the highest existing ID to avoid duplicates on reload. | ||
| - **Edge IDs**: Generated as `` `e-${source}-${target}-${Date.now()}` `` to guarantee uniqueness, including in multigraphs. | ||
| - **Config is flattened into answer**: The backend reads `directed`, `weighted`, `multigraph`, and `evaluation_type` from the answer object, not a separate config field. This is handled in `WizardPanel.onChange`. | ||
| - **Stable sub-components**: `WizardPanel` is defined outside the `GraphResponseAreaTub` class to prevent React from treating it as a new component type on re-render, which would unmount/remount `GraphEditor` and destroy Cytoscape state. | ||
| - **Cytoscape vs Paper.js layering**: Paper.js canvas sits on top of Cytoscape (`zIndex: 10`) with `pointerEvents: none` when not in draw mode, and `pointerEvents: auto` + `cursor: crosshair` when draw mode is active. | ||
| - **Arrow direction**: The Cytoscape edge style `target-arrow-shape` is reactively updated whenever `graph.directed` changes. | ||
| - **Isomorphism mode**: When `evaluation_type === 'isomorphism'`, `WizardPanel` renders a second `GraphEditor` for the teacher to define the reference graph. | ||
| - **Initial emit**: `WizardPanel` emits `onChange` on mount so config is always persisted to the DB even if the teacher never interacts with it. | ||
|
|
||
| --- | ||
|
|
||
| ## 7. Supported Evaluation Types | ||
|
|
||
| ``` | ||
| isomorphism, connectivity, bipartite, cycle_detection, | ||
| graph_coloring, planarity, tree, forest, dag, eulerian, | ||
| semi_eulerian, regular, complete, degree_sequence, | ||
| subgraph, hamiltonian_path, hamiltonian_cycle, clique_number | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| ## 8. Dev Notice | ||
|
|
||
| Run `yarn dev` to start (runs `build:watch` + `preview` in parallel). | ||
|
|
||
| Note: for dev mode only, there is an extra config in `vite.config.ts`: | ||
|
|
||
| ```ts | ||
| root: 'dev', // for dev only | ||
| ``` | ||
|
|
||
| Remember to remove it before going to production. |
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. References FSA. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same issue as FSA.md, simple fix |
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
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
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
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
Oops, something went wrong.
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.
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.
Should this be ignored or just not added to the commit? (Do we want to ignore these in the future?)
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.
I think this is here by accident, FSA and PropositionalLogic never existed in this repo, will definitely fix this
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.
Oops, this was done by me, I had an issue with my laptop where I couldn't open more than 1 vscode open at the same time, but I wanted to see the code for PL config panel and FSA graph to take inspiration for Graph. Fixed now.