-
Notifications
You must be signed in to change notification settings - Fork 0
add lines to visualize relationships #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
Merged
Merged
Changes from 8 commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
7017e08
draw lines between related heap objects
MaKhandare 1870b0b
add a nested class to see if it behaves correctly
MaKhandare 59f79ff
instead of fixed offset, get size of node and adjust
MaKhandare 6e9988e
add datatype and some basic styling
MaKhandare f44d4c0
try to memoize with useMemo
MaKhandare 31168ce
refac connection drawing to improve performance
MaKhandare 974f1b5
change render order of text so it does not randomly hide behind the node
MaKhandare df041e3
some color adjustments
MaKhandare cd5d94f
Update playground/csharp/Program.cs
MaKhandare 08856ab
Update server/src/HeapConnections.tsx
MaKhandare ce7dde4
Update playground/csharp/Program.cs
MaKhandare 3b40270
Update server/src/HeapConnections.tsx
MaKhandare 573ff7a
Update server/src/HeapConnections.tsx
MaKhandare 214493d
Update server/src/HeapConnections.tsx
MaKhandare d5844c8
rename HeapConnections to HeapConnectionsProvider
MaKhandare 3401bab
use a themeprovider instead of hardcoded colors
MaKhandare 13784f6
invert if for readability
MaKhandare 538be14
helper hook for connections provider
MaKhandare f008a5c
rename pChildren and rChildren, use else instead of else if
MaKhandare 5cc36d3
move variables into correct scope
MaKhandare 8449457
early check return
MaKhandare 1f6827f
remove as cast by introducing a VariableWithParent t ype
MaKhandare 3dc598a
ref can be null, with proper null checks no as casts needed
MaKhandare c12b60a
use a map to store children and pass to heapnode
MaKhandare 5562a61
remove theme from props
MaKhandare 9a0e63c
simplify useHeapConnections
MaKhandare b8c17bf
remove unnecessary if statement
MaKhandare 7246d7d
give body temporarily a gruvbox color
MaKhandare 74b5507
gruvbox colors
MaKhandare 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
MaKhandare marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
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,134 @@ | ||
| import { Variable } from "./DapvizProvider"; | ||
| import { QuadraticBezierLine, QuadraticBezierLineRef } from "@react-three/drei"; | ||
| import React, { createContext, useMemo, useRef } from "react"; | ||
| import { useCallback, useState } from "react"; | ||
| import * as THREE from "three"; | ||
| import { useFrame } from "@react-three/fiber"; | ||
|
|
||
|
|
||
| export type HeapConnectionContextType = { | ||
| registerNode: (id: number, ref: React.RefObject<THREE.Group>) => void; | ||
| unregisterNode: (id: number) => void; | ||
| }; | ||
|
|
||
| export const HeapConnectionContext = createContext<HeapConnectionContextType | null>(null); | ||
|
|
||
|
|
||
| interface ConnectionLineProps { | ||
| parentRef: React.RefObject<THREE.Group>; | ||
| childRef: React.RefObject<THREE.Group>; | ||
| } | ||
|
|
||
| export const ConnectionLine = ({ parentRef, childRef }: ConnectionLineProps) => { | ||
MaKhandare marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| const lineRef = useRef<QuadraticBezierLineRef>(null); | ||
|
|
||
| const startCircleRef = useRef<THREE.Mesh>(null); | ||
| const endCircleRef = useRef<THREE.Mesh>(null); | ||
|
|
||
| const startPos = useMemo(() => new THREE.Vector3(), []); | ||
| const endPos = useMemo(() => new THREE.Vector3(), []); | ||
| const midPos = useMemo(() => new THREE.Vector3(), []); | ||
| const box = useMemo(() => new THREE.Box3(), []); | ||
| const size = useMemo(() => new THREE.Vector3(), []); | ||
MaKhandare marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| useFrame(() => { | ||
thekatze marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| if (parentRef.current && childRef.current && lineRef.current) { | ||
MaKhandare marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| parentRef.current.getWorldPosition(startPos); | ||
| childRef.current.getWorldPosition(endPos); | ||
|
|
||
| box.setFromObject(parentRef.current); | ||
| box.getSize(size); | ||
| const startOffset = size.x / 2; | ||
|
|
||
| box.setFromObject(childRef.current); | ||
| box.getSize(size); | ||
| const endOffset = size.x / 2; | ||
|
|
||
| const padding = 3; | ||
|
|
||
| const finalStart = startPos.clone(); | ||
| finalStart.x += startOffset + padding; | ||
|
|
||
| const finalEnd = endPos.clone(); | ||
| finalEnd.x -= endOffset + padding; | ||
|
|
||
|
|
||
| midPos.addVectors(finalStart, finalEnd).multiplyScalar(0.5); | ||
|
|
||
| midPos.y += 80; | ||
|
|
||
| lineRef.current.setPoints(finalStart, finalEnd, midPos); | ||
| startCircleRef.current?.position.copy(finalStart); | ||
| endCircleRef.current?.position.copy(finalEnd); | ||
| } | ||
| }); | ||
|
|
||
| return ( | ||
| <> | ||
| <QuadraticBezierLine | ||
| ref={lineRef} | ||
| start={[0, 0, 0]} | ||
| end={[0, 0, 0]} | ||
| color="#a89984" | ||
| lineWidth={1} | ||
| /> | ||
|
|
||
| <mesh ref={startCircleRef}> | ||
| <circleGeometry args={[2.5, 16]} /> | ||
| <meshBasicMaterial color="#689d6a" /> | ||
MaKhandare marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| </mesh> | ||
| <mesh ref={endCircleRef}> | ||
| <circleGeometry args={[2.5, 16]} /> | ||
| <meshBasicMaterial color="#d79921" /> | ||
MaKhandare marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| </mesh> | ||
| </> | ||
|
|
||
| ); | ||
| } | ||
|
|
||
| export const HeapConnectionsProvider = ({ children, allVariables }: { children: React.ReactNode, allVariables: Variable[] }) => { | ||
|
|
||
| const [nodeRefs, setNodeRefs] = useState<Map<number, React.RefObject<THREE.Group>>>(new Map()); | ||
thekatze marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| const registerNode = useCallback((id: number, ref: React.RefObject<THREE.Group>) => { | ||
| setNodeRefs(prev => new Map(prev).set(id, ref)); | ||
| }, []); | ||
MaKhandare marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| const unregisterNode = useCallback((id: number) => { | ||
| setNodeRefs(prev => { | ||
| const newMap = new Map(prev); | ||
| newMap.delete(id); | ||
| return newMap; | ||
| }); | ||
| }, []); | ||
MaKhandare marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| const connections = useMemo(() => | ||
| allVariables.filter(v => v.parent && v.parent > 0 && v.reference > 0), | ||
| [allVariables] | ||
| ); | ||
MaKhandare marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| return ( | ||
| <HeapConnectionContext.Provider value={{ registerNode, unregisterNode }}> | ||
| {children} | ||
|
|
||
| <group> | ||
| {connections.map(variable => { | ||
| const parentRef = nodeRefs.get(variable.parent as number); | ||
MaKhandare marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| const childRef = nodeRefs.get(variable.reference); | ||
|
|
||
| if (parentRef && childRef) { | ||
| return ( | ||
| <ConnectionLine | ||
| key={`${variable.parent}-${variable.reference}`} | ||
| parentRef={parentRef} | ||
| childRef={childRef} | ||
| /> | ||
| ); | ||
| } | ||
| return null; | ||
MaKhandare marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| })} | ||
| </group> | ||
| </HeapConnectionContext.Provider> | ||
| ); | ||
| } | ||
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
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.
Uh oh!
There was an error while loading. Please reload this page.