From 219d8e8b5e8e2fcd639bbdad6d5b19819f9ad6aa Mon Sep 17 00:00:00 2001 From: Sylvia Wang Date: Fri, 11 Oct 2024 19:38:34 +1100 Subject: [PATCH 1/9] annotation done --- .../RoleAnnotation/AnnotationFactory.tsx | 20 ++ .../RoleAnnotation/BinaryTreeAnnotation.tsx | 195 ++++++++++++++++++ .../Configuration/TypeAnnotation.tsx | 13 +- .../Types/annotationType.ts | 17 ++ 4 files changed, 242 insertions(+), 3 deletions(-) create mode 100644 client/src/visualiser-debugger/Component/Configuration/RoleAnnotation/AnnotationFactory.tsx create mode 100644 client/src/visualiser-debugger/Component/Configuration/RoleAnnotation/BinaryTreeAnnotation.tsx diff --git a/client/src/visualiser-debugger/Component/Configuration/RoleAnnotation/AnnotationFactory.tsx b/client/src/visualiser-debugger/Component/Configuration/RoleAnnotation/AnnotationFactory.tsx new file mode 100644 index 000000000..4843f895e --- /dev/null +++ b/client/src/visualiser-debugger/Component/Configuration/RoleAnnotation/AnnotationFactory.tsx @@ -0,0 +1,20 @@ +import { BackendTypeRole } from "visualiser-debugger/Types/annotationType"; +import { LinkedListNodeAnnotation } from "./LinkedListAnnotation"; +import { assertUnreachable } from "visualiser-debugger/Component/Visualizer/Util/util"; +import { TypeAnnotationProp } from "../TypeAnnotation"; +import { TreeNodeAnnotation } from "./BinaryTreeAnnotation"; +export function AnnotationFactory (backendRole: BackendTypeRole, { + typeDeclaration, + }: TypeAnnotationProp) : JSX.Element | null { + switch(backendRole){ + case BackendTypeRole.LinkedList: + + case BackendTypeRole.BinaryTree: + + case BackendTypeRole.Empty: + return null; + default: + assertUnreachable(backendRole); +} + return null; +} \ No newline at end of file diff --git a/client/src/visualiser-debugger/Component/Configuration/RoleAnnotation/BinaryTreeAnnotation.tsx b/client/src/visualiser-debugger/Component/Configuration/RoleAnnotation/BinaryTreeAnnotation.tsx new file mode 100644 index 000000000..986d9d2ed --- /dev/null +++ b/client/src/visualiser-debugger/Component/Configuration/RoleAnnotation/BinaryTreeAnnotation.tsx @@ -0,0 +1,195 @@ +import { BackendTypeDeclaration, isNativeTypeName, isPointerType, isStructTypeName } from 'visualiser-debugger/Types/backendType'; +import styles from 'styles/Configuration.module.css'; +import * as RadioGroup from '@radix-ui/react-radio-group'; +import { BinaryTreeAnnotation, DataStructureType, PossibleBinaryTreeAnnotation } from '../../../Types/annotationType'; +import { AnnotationComponent, AnnotationProp } from './AnnotationComponentBase'; +import { useEffect, useState } from 'react'; +import { useGlobalStore } from 'visualiser-debugger/Store/globalStateStore'; +import ConfigurationSelect from '../ConfigurationSelect'; + +export const createPossibleTreeTypeDecl = ( + typeDecl: BackendTypeDeclaration +) : PossibleBinaryTreeAnnotation | null => { + if (!('fields' in typeDecl)) { + return null; + } + + if (!isStructTypeName(typeDecl.typeName)) { + return null; + } + + const possibleTypeDecl: PossibleBinaryTreeAnnotation = { + typeName: typeDecl.typeName, + possibleValues: [], + possibleLefts: [], + possibleRights: [], + }; + + typeDecl.fields.forEach((field) => { + if (isNativeTypeName(field.typeName)) { + possibleTypeDecl.possibleValues.push({ + name: field.name, + typeName: field.typeName, + }); + } + if ( + isPointerType(field.typeName) && + isStructTypeName(field.typeName.slice(0, -1)) && + field.name.includes('left') + ) { + possibleTypeDecl.possibleLefts.push({ + name: field.name, + typeName: field.typeName, + }); + } + if ( + isPointerType(field.typeName) && + isStructTypeName(field.typeName.slice(0, -1)) && + field.name.includes('right') + ) { + possibleTypeDecl.possibleRights.push({ + name: field.name, + typeName: field.typeName, + }); + } + }); + + if ( + possibleTypeDecl.possibleValues.length >= 1 && + possibleTypeDecl.possibleLefts.length >= 1 && + possibleTypeDecl.possibleRights.length >= 1 + ) { + return possibleTypeDecl; + } + return null; +} + +export const TreeNodeAnnotation: AnnotationComponent = ({ backendType }: AnnotationProp) => { + const [possibleTypeDeclForTree, setPossibleTypeDeclForTree] = + useState(createPossibleTreeTypeDecl(backendType)); + const { updateUserAnnotation, visualizer } = useGlobalStore(); + const [nodeAnnotation, setNodeAnnotation] = useState(null); + const handleUpdateNodeAnnotation = (newAnnotation: BinaryTreeAnnotation) => { + updateUserAnnotation({ + stackAnnotation: visualizer.userAnnotation.stackAnnotation, + typeAnnotation: { + ...visualizer.userAnnotation.typeAnnotation, + [backendType.typeName]: newAnnotation, + }, + }); + } + const handleTreeNodeAnnotation = (possibleTypeAnnotation: PossibleBinaryTreeAnnotation) => { + if (possibleTypeAnnotation === null) return; + setPossibleTypeDeclForTree(possibleTypeAnnotation); + const newAnnotation: BinaryTreeAnnotation = { + typeName: backendType.typeName as `struct ${string}`, + type: DataStructureType.BinaryTree, + value: { + name: possibleTypeAnnotation.possibleValues[0].name, + typeName: possibleTypeAnnotation.possibleValues[0].typeName, + }, + left: { + name: possibleTypeAnnotation.possibleLefts[0].name, + typeName: possibleTypeAnnotation.possibleLefts[0].typeName, + }, + right: { + name: possibleTypeAnnotation.possibleRights[0].name, + typeName: possibleTypeAnnotation.possibleRights[0].typeName, + }, + + } + setNodeAnnotation(newAnnotation); + handleUpdateNodeAnnotation(newAnnotation); + } + + useEffect(() => { + handleTreeNodeAnnotation(possibleTypeDeclForTree); + } , [possibleTypeDeclForTree]); + + useEffect(() => { + const possibleTypeDecls = createPossibleTreeTypeDecl(backendType); + setPossibleTypeDeclForTree(possibleTypeDecls); + }, [backendType]); + + const handleUpdateNodeData = (newNodeData: string, newNodeDataType: string) => { + if (isNativeTypeName(newNodeDataType)) { + const newAnnotation: BinaryTreeAnnotation = { + ...nodeAnnotation, + value: { + name: newNodeData, + typeName: newNodeDataType, + }, + }; + setNodeAnnotation(newAnnotation); + handleUpdateNodeAnnotation(newAnnotation); + } + }; + + const handleUpdateLeftData = (newLeftData: string, newLeftDataType: string) => { + if (isPointerType(newLeftDataType) && isStructTypeName(newLeftDataType.slice(0, -1))) { + const newAnnotation: BinaryTreeAnnotation = { + ...nodeAnnotation, + left: { + name: newLeftData, + typeName: newLeftDataType, + }, + }; + setNodeAnnotation(newAnnotation); + handleUpdateNodeAnnotation(newAnnotation); + } + } + + const handleUpdateRightData = (newRightData: string, newRightDataType: string) => { + if (isPointerType(newRightDataType) && isStructTypeName(newRightDataType.slice(0, -1))) { + const newAnnotation: BinaryTreeAnnotation = { + ...nodeAnnotation, + right: { + name: newRightData, + typeName: newRightDataType, + }, + }; + setNodeAnnotation(newAnnotation); + handleUpdateNodeAnnotation(newAnnotation); + } + } + + if (!possibleTypeDeclForTree) { + return ( +
+ + Error: No possible{' '} + {/* where is the styles.highlightLinkedList */} + binary tree annotation can be made. + +
+ ); + } + return ( +
+ +
+ Node Data + +
+ +
+ Left Child + +
+
+ Right Child + +
+
+
+ ); +} \ No newline at end of file diff --git a/client/src/visualiser-debugger/Component/Configuration/TypeAnnotation.tsx b/client/src/visualiser-debugger/Component/Configuration/TypeAnnotation.tsx index 41773bb96..e3b61fdc1 100644 --- a/client/src/visualiser-debugger/Component/Configuration/TypeAnnotation.tsx +++ b/client/src/visualiser-debugger/Component/Configuration/TypeAnnotation.tsx @@ -6,10 +6,12 @@ import { MotionCollapse } from './MotionCollapse'; import './typeAnnotation.css'; import { BackendTypeRole } from '../../Types/annotationType'; import { - LinkedListNodeAnnotation, createPossibleLinkedListTypeDecl, } from './RoleAnnotation/LinkedListAnnotation'; import { BackendTypeDeclaration } from '../../Types/backendType'; +import { AnnotationFactory } from './RoleAnnotation/AnnotationFactory'; +import { createPossibleTreeTypeDecl } from './RoleAnnotation/BinaryTreeAnnotation'; + export type TypeAnnotationProp = { typeDeclaration: BackendTypeDeclaration; @@ -26,8 +28,11 @@ export const TypeAnnotation: React.FC = ({ if (createPossibleLinkedListTypeDecl(typeDeclaration) !== null) { setSelectedRole(BackendTypeRole.LinkedList); } + if (createPossibleTreeTypeDecl(typeDeclaration) !== null) { + setSelectedRole(BackendTypeRole.BinaryTree); + } }, []); - + const annotation = AnnotationFactory(selectedRole, {typeDeclaration}); return (
@@ -97,7 +102,9 @@ export const TypeAnnotation: React.FC = ({
- + {/** Create a Factory pattern to generate Annotation classs */} + {annotation} + {/* */}
); diff --git a/client/src/visualiser-debugger/Types/annotationType.ts b/client/src/visualiser-debugger/Types/annotationType.ts index 630995301..9135a9486 100644 --- a/client/src/visualiser-debugger/Types/annotationType.ts +++ b/client/src/visualiser-debugger/Types/annotationType.ts @@ -136,6 +136,7 @@ export type PossibleStructAnnotation = { export enum BackendTypeRole { LinkedList = 'Linked List Node', + BinaryTree = 'Binary Tree Node', Empty = 'Not Visualized', } @@ -155,3 +156,19 @@ export type PossibleLinkedListAnnotation = { typeName: PointerType['typeName']; }[]; }; + +export type PossibleBinaryTreeAnnotation = { + typeName: StructType['typeName']; + possibleValues: { + name: Name; + typeName: NativeTypeName; + }[]; + possibleLefts: { + name: Name; + typeName: PointerType['typeName']; + }[]; + possibleRights: { + name: Name; + typeName: PointerType['typeName']; + }[]; +}; \ No newline at end of file From f3fe5541ecaa4eb8d7be566800226a22b797db8c Mon Sep 17 00:00:00 2001 From: Sylvia Wang Date: Fri, 8 Nov 2024 20:12:02 +1100 Subject: [PATCH 2/9] fixed annotation not showing up --- .../Configuration/RoleAnnotation/AnnotationFactory.tsx | 6 +++--- .../Component/Configuration/TypeAnnotation.tsx | 6 ++---- client/src/visualiser-debugger/Types/annotationType.ts | 1 + 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/client/src/visualiser-debugger/Component/Configuration/RoleAnnotation/AnnotationFactory.tsx b/client/src/visualiser-debugger/Component/Configuration/RoleAnnotation/AnnotationFactory.tsx index 4843f895e..9ff9cf673 100644 --- a/client/src/visualiser-debugger/Component/Configuration/RoleAnnotation/AnnotationFactory.tsx +++ b/client/src/visualiser-debugger/Component/Configuration/RoleAnnotation/AnnotationFactory.tsx @@ -8,9 +8,9 @@ export function AnnotationFactory (backendRole: BackendTypeRole, { }: TypeAnnotationProp) : JSX.Element | null { switch(backendRole){ case BackendTypeRole.LinkedList: - - case BackendTypeRole.BinaryTree: - + return + case BackendTypeRole.BinaryTree: + return case BackendTypeRole.Empty: return null; default: diff --git a/client/src/visualiser-debugger/Component/Configuration/TypeAnnotation.tsx b/client/src/visualiser-debugger/Component/Configuration/TypeAnnotation.tsx index e3b61fdc1..185fae207 100644 --- a/client/src/visualiser-debugger/Component/Configuration/TypeAnnotation.tsx +++ b/client/src/visualiser-debugger/Component/Configuration/TypeAnnotation.tsx @@ -100,11 +100,9 @@ export const TypeAnnotation: React.FC = ({ - - - {/** Create a Factory pattern to generate Annotation classs */} + {/* should this be true??? */} + {annotation} - {/* */} ); diff --git a/client/src/visualiser-debugger/Types/annotationType.ts b/client/src/visualiser-debugger/Types/annotationType.ts index 9135a9486..9f11f00ad 100644 --- a/client/src/visualiser-debugger/Types/annotationType.ts +++ b/client/src/visualiser-debugger/Types/annotationType.ts @@ -143,6 +143,7 @@ export enum BackendTypeRole { export enum StackVariableRole { LinkedListPointer = 'Linked List Node', Empty = 'Not Visualized', + BinaryTreePointer = 'Binary Tree Node', } export type PossibleLinkedListAnnotation = { From db90faba0c1cd84f7f4fbebdc2f9c1c51188b557 Mon Sep 17 00:00:00 2001 From: Sylvia Wang Date: Fri, 8 Nov 2024 20:22:37 +1100 Subject: [PATCH 3/9] added bst to stack variable --- .../Component/Configuration/StackVarDeclaration.tsx | 4 ++-- client/src/visualiser-debugger/Types/annotationType.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/client/src/visualiser-debugger/Component/Configuration/StackVarDeclaration.tsx b/client/src/visualiser-debugger/Component/Configuration/StackVarDeclaration.tsx index c4fb4af90..35c664829 100644 --- a/client/src/visualiser-debugger/Component/Configuration/StackVarDeclaration.tsx +++ b/client/src/visualiser-debugger/Component/Configuration/StackVarDeclaration.tsx @@ -33,7 +33,7 @@ export const StackVarAnnotation: React.FC = ({ // Annotate by default if the variable contains a pointer useEffect(() => { - if (selectedRole === StackVariableRole.LinkedListPointer) { + if (selectedRole === StackVariableRole.LinkedListPointer || selectedRole === StackVariableRole.BinaryTreePointer) { const newStackAnnotation = { [name]: memoryValue.typeName, }; @@ -84,7 +84,7 @@ export const StackVarAnnotation: React.FC = ({ type="button" onClick={() => { setSelectedRole(role[1]); - if (role[1] === StackVariableRole.LinkedListPointer) { + if (role[1] === StackVariableRole.LinkedListPointer || role[1] === StackVariableRole.BinaryTreePointer) { updateStackAnnotation({ [name]: memoryValue.typeName }); } else { updateStackAnnotation({ [name]: null }); diff --git a/client/src/visualiser-debugger/Types/annotationType.ts b/client/src/visualiser-debugger/Types/annotationType.ts index 9f11f00ad..c1fabd0ba 100644 --- a/client/src/visualiser-debugger/Types/annotationType.ts +++ b/client/src/visualiser-debugger/Types/annotationType.ts @@ -142,8 +142,8 @@ export enum BackendTypeRole { export enum StackVariableRole { LinkedListPointer = 'Linked List Node', - Empty = 'Not Visualized', BinaryTreePointer = 'Binary Tree Node', + Empty = 'Not Visualized', } export type PossibleLinkedListAnnotation = { From 0adf0b8a6307eedbff1d2ee89ea737c29ee69574 Mon Sep 17 00:00:00 2001 From: Sylvia Wang Date: Fri, 11 Apr 2025 16:23:59 +1000 Subject: [PATCH 4/9] tree annotation types --- .../RoleAnnotation/BinaryTreeAnnotation.tsx | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/client/src/visualiser-debugger/Component/Configuration/RoleAnnotation/BinaryTreeAnnotation.tsx b/client/src/visualiser-debugger/Component/Configuration/RoleAnnotation/BinaryTreeAnnotation.tsx index 986d9d2ed..c99688d12 100644 --- a/client/src/visualiser-debugger/Component/Configuration/RoleAnnotation/BinaryTreeAnnotation.tsx +++ b/client/src/visualiser-debugger/Component/Configuration/RoleAnnotation/BinaryTreeAnnotation.tsx @@ -24,7 +24,9 @@ export const createPossibleTreeTypeDecl = ( possibleLefts: [], possibleRights: [], }; - + if (typeDecl.fields === undefined) { + return null; + } typeDecl.fields.forEach((field) => { if (isNativeTypeName(field.typeName)) { possibleTypeDecl.possibleValues.push({ @@ -66,9 +68,9 @@ export const createPossibleTreeTypeDecl = ( export const TreeNodeAnnotation: AnnotationComponent = ({ backendType }: AnnotationProp) => { const [possibleTypeDeclForTree, setPossibleTypeDeclForTree] = - useState(createPossibleTreeTypeDecl(backendType)); + useState(createPossibleTreeTypeDecl(backendType)); const { updateUserAnnotation, visualizer } = useGlobalStore(); - const [nodeAnnotation, setNodeAnnotation] = useState(null); + const [nodeAnnotation, setNodeAnnotation] = useState(null); const handleUpdateNodeAnnotation = (newAnnotation: BinaryTreeAnnotation) => { updateUserAnnotation({ stackAnnotation: visualizer.userAnnotation.stackAnnotation, @@ -78,7 +80,7 @@ export const TreeNodeAnnotation: AnnotationComponent = ({ backendType }: Annotat }, }); } - const handleTreeNodeAnnotation = (possibleTypeAnnotation: PossibleBinaryTreeAnnotation) => { + const handleTreeNodeAnnotation = (possibleTypeAnnotation: PossibleBinaryTreeAnnotation | null) => { if (possibleTypeAnnotation === null) return; setPossibleTypeDeclForTree(possibleTypeAnnotation); const newAnnotation: BinaryTreeAnnotation = { From dca1e2f1136c285a441251a523afaf2cb42ab37b Mon Sep 17 00:00:00 2001 From: Sylvia Wang Date: Fri, 11 Oct 2024 19:38:34 +1100 Subject: [PATCH 5/9] annotation done --- .../RoleAnnotation/AnnotationFactory.tsx | 20 ++ .../RoleAnnotation/BinaryTreeAnnotation.tsx | 195 ++++++++++++++++++ .../Configuration/TypeAnnotation.tsx | 13 +- .../Types/annotationType.ts | 17 ++ 4 files changed, 242 insertions(+), 3 deletions(-) create mode 100644 client/src/visualiser-debugger/Component/Configuration/RoleAnnotation/AnnotationFactory.tsx create mode 100644 client/src/visualiser-debugger/Component/Configuration/RoleAnnotation/BinaryTreeAnnotation.tsx diff --git a/client/src/visualiser-debugger/Component/Configuration/RoleAnnotation/AnnotationFactory.tsx b/client/src/visualiser-debugger/Component/Configuration/RoleAnnotation/AnnotationFactory.tsx new file mode 100644 index 000000000..4843f895e --- /dev/null +++ b/client/src/visualiser-debugger/Component/Configuration/RoleAnnotation/AnnotationFactory.tsx @@ -0,0 +1,20 @@ +import { BackendTypeRole } from "visualiser-debugger/Types/annotationType"; +import { LinkedListNodeAnnotation } from "./LinkedListAnnotation"; +import { assertUnreachable } from "visualiser-debugger/Component/Visualizer/Util/util"; +import { TypeAnnotationProp } from "../TypeAnnotation"; +import { TreeNodeAnnotation } from "./BinaryTreeAnnotation"; +export function AnnotationFactory (backendRole: BackendTypeRole, { + typeDeclaration, + }: TypeAnnotationProp) : JSX.Element | null { + switch(backendRole){ + case BackendTypeRole.LinkedList: + + case BackendTypeRole.BinaryTree: + + case BackendTypeRole.Empty: + return null; + default: + assertUnreachable(backendRole); +} + return null; +} \ No newline at end of file diff --git a/client/src/visualiser-debugger/Component/Configuration/RoleAnnotation/BinaryTreeAnnotation.tsx b/client/src/visualiser-debugger/Component/Configuration/RoleAnnotation/BinaryTreeAnnotation.tsx new file mode 100644 index 000000000..986d9d2ed --- /dev/null +++ b/client/src/visualiser-debugger/Component/Configuration/RoleAnnotation/BinaryTreeAnnotation.tsx @@ -0,0 +1,195 @@ +import { BackendTypeDeclaration, isNativeTypeName, isPointerType, isStructTypeName } from 'visualiser-debugger/Types/backendType'; +import styles from 'styles/Configuration.module.css'; +import * as RadioGroup from '@radix-ui/react-radio-group'; +import { BinaryTreeAnnotation, DataStructureType, PossibleBinaryTreeAnnotation } from '../../../Types/annotationType'; +import { AnnotationComponent, AnnotationProp } from './AnnotationComponentBase'; +import { useEffect, useState } from 'react'; +import { useGlobalStore } from 'visualiser-debugger/Store/globalStateStore'; +import ConfigurationSelect from '../ConfigurationSelect'; + +export const createPossibleTreeTypeDecl = ( + typeDecl: BackendTypeDeclaration +) : PossibleBinaryTreeAnnotation | null => { + if (!('fields' in typeDecl)) { + return null; + } + + if (!isStructTypeName(typeDecl.typeName)) { + return null; + } + + const possibleTypeDecl: PossibleBinaryTreeAnnotation = { + typeName: typeDecl.typeName, + possibleValues: [], + possibleLefts: [], + possibleRights: [], + }; + + typeDecl.fields.forEach((field) => { + if (isNativeTypeName(field.typeName)) { + possibleTypeDecl.possibleValues.push({ + name: field.name, + typeName: field.typeName, + }); + } + if ( + isPointerType(field.typeName) && + isStructTypeName(field.typeName.slice(0, -1)) && + field.name.includes('left') + ) { + possibleTypeDecl.possibleLefts.push({ + name: field.name, + typeName: field.typeName, + }); + } + if ( + isPointerType(field.typeName) && + isStructTypeName(field.typeName.slice(0, -1)) && + field.name.includes('right') + ) { + possibleTypeDecl.possibleRights.push({ + name: field.name, + typeName: field.typeName, + }); + } + }); + + if ( + possibleTypeDecl.possibleValues.length >= 1 && + possibleTypeDecl.possibleLefts.length >= 1 && + possibleTypeDecl.possibleRights.length >= 1 + ) { + return possibleTypeDecl; + } + return null; +} + +export const TreeNodeAnnotation: AnnotationComponent = ({ backendType }: AnnotationProp) => { + const [possibleTypeDeclForTree, setPossibleTypeDeclForTree] = + useState(createPossibleTreeTypeDecl(backendType)); + const { updateUserAnnotation, visualizer } = useGlobalStore(); + const [nodeAnnotation, setNodeAnnotation] = useState(null); + const handleUpdateNodeAnnotation = (newAnnotation: BinaryTreeAnnotation) => { + updateUserAnnotation({ + stackAnnotation: visualizer.userAnnotation.stackAnnotation, + typeAnnotation: { + ...visualizer.userAnnotation.typeAnnotation, + [backendType.typeName]: newAnnotation, + }, + }); + } + const handleTreeNodeAnnotation = (possibleTypeAnnotation: PossibleBinaryTreeAnnotation) => { + if (possibleTypeAnnotation === null) return; + setPossibleTypeDeclForTree(possibleTypeAnnotation); + const newAnnotation: BinaryTreeAnnotation = { + typeName: backendType.typeName as `struct ${string}`, + type: DataStructureType.BinaryTree, + value: { + name: possibleTypeAnnotation.possibleValues[0].name, + typeName: possibleTypeAnnotation.possibleValues[0].typeName, + }, + left: { + name: possibleTypeAnnotation.possibleLefts[0].name, + typeName: possibleTypeAnnotation.possibleLefts[0].typeName, + }, + right: { + name: possibleTypeAnnotation.possibleRights[0].name, + typeName: possibleTypeAnnotation.possibleRights[0].typeName, + }, + + } + setNodeAnnotation(newAnnotation); + handleUpdateNodeAnnotation(newAnnotation); + } + + useEffect(() => { + handleTreeNodeAnnotation(possibleTypeDeclForTree); + } , [possibleTypeDeclForTree]); + + useEffect(() => { + const possibleTypeDecls = createPossibleTreeTypeDecl(backendType); + setPossibleTypeDeclForTree(possibleTypeDecls); + }, [backendType]); + + const handleUpdateNodeData = (newNodeData: string, newNodeDataType: string) => { + if (isNativeTypeName(newNodeDataType)) { + const newAnnotation: BinaryTreeAnnotation = { + ...nodeAnnotation, + value: { + name: newNodeData, + typeName: newNodeDataType, + }, + }; + setNodeAnnotation(newAnnotation); + handleUpdateNodeAnnotation(newAnnotation); + } + }; + + const handleUpdateLeftData = (newLeftData: string, newLeftDataType: string) => { + if (isPointerType(newLeftDataType) && isStructTypeName(newLeftDataType.slice(0, -1))) { + const newAnnotation: BinaryTreeAnnotation = { + ...nodeAnnotation, + left: { + name: newLeftData, + typeName: newLeftDataType, + }, + }; + setNodeAnnotation(newAnnotation); + handleUpdateNodeAnnotation(newAnnotation); + } + } + + const handleUpdateRightData = (newRightData: string, newRightDataType: string) => { + if (isPointerType(newRightDataType) && isStructTypeName(newRightDataType.slice(0, -1))) { + const newAnnotation: BinaryTreeAnnotation = { + ...nodeAnnotation, + right: { + name: newRightData, + typeName: newRightDataType, + }, + }; + setNodeAnnotation(newAnnotation); + handleUpdateNodeAnnotation(newAnnotation); + } + } + + if (!possibleTypeDeclForTree) { + return ( +
+ + Error: No possible{' '} + {/* where is the styles.highlightLinkedList */} + binary tree annotation can be made. + +
+ ); + } + return ( +
+ +
+ Node Data + +
+ +
+ Left Child + +
+
+ Right Child + +
+
+
+ ); +} \ No newline at end of file diff --git a/client/src/visualiser-debugger/Component/Configuration/TypeAnnotation.tsx b/client/src/visualiser-debugger/Component/Configuration/TypeAnnotation.tsx index 41773bb96..e3b61fdc1 100644 --- a/client/src/visualiser-debugger/Component/Configuration/TypeAnnotation.tsx +++ b/client/src/visualiser-debugger/Component/Configuration/TypeAnnotation.tsx @@ -6,10 +6,12 @@ import { MotionCollapse } from './MotionCollapse'; import './typeAnnotation.css'; import { BackendTypeRole } from '../../Types/annotationType'; import { - LinkedListNodeAnnotation, createPossibleLinkedListTypeDecl, } from './RoleAnnotation/LinkedListAnnotation'; import { BackendTypeDeclaration } from '../../Types/backendType'; +import { AnnotationFactory } from './RoleAnnotation/AnnotationFactory'; +import { createPossibleTreeTypeDecl } from './RoleAnnotation/BinaryTreeAnnotation'; + export type TypeAnnotationProp = { typeDeclaration: BackendTypeDeclaration; @@ -26,8 +28,11 @@ export const TypeAnnotation: React.FC = ({ if (createPossibleLinkedListTypeDecl(typeDeclaration) !== null) { setSelectedRole(BackendTypeRole.LinkedList); } + if (createPossibleTreeTypeDecl(typeDeclaration) !== null) { + setSelectedRole(BackendTypeRole.BinaryTree); + } }, []); - + const annotation = AnnotationFactory(selectedRole, {typeDeclaration}); return (
@@ -97,7 +102,9 @@ export const TypeAnnotation: React.FC = ({
- + {/** Create a Factory pattern to generate Annotation classs */} + {annotation} + {/* */}
); diff --git a/client/src/visualiser-debugger/Types/annotationType.ts b/client/src/visualiser-debugger/Types/annotationType.ts index 630995301..9135a9486 100644 --- a/client/src/visualiser-debugger/Types/annotationType.ts +++ b/client/src/visualiser-debugger/Types/annotationType.ts @@ -136,6 +136,7 @@ export type PossibleStructAnnotation = { export enum BackendTypeRole { LinkedList = 'Linked List Node', + BinaryTree = 'Binary Tree Node', Empty = 'Not Visualized', } @@ -155,3 +156,19 @@ export type PossibleLinkedListAnnotation = { typeName: PointerType['typeName']; }[]; }; + +export type PossibleBinaryTreeAnnotation = { + typeName: StructType['typeName']; + possibleValues: { + name: Name; + typeName: NativeTypeName; + }[]; + possibleLefts: { + name: Name; + typeName: PointerType['typeName']; + }[]; + possibleRights: { + name: Name; + typeName: PointerType['typeName']; + }[]; +}; \ No newline at end of file From b5113dd30b9e0e5baedacf2a129c107b02666142 Mon Sep 17 00:00:00 2001 From: Sylvia Wang Date: Fri, 8 Nov 2024 20:12:02 +1100 Subject: [PATCH 6/9] fixed annotation not showing up --- .../Configuration/RoleAnnotation/AnnotationFactory.tsx | 6 +++--- .../Component/Configuration/TypeAnnotation.tsx | 6 ++---- client/src/visualiser-debugger/Types/annotationType.ts | 1 + 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/client/src/visualiser-debugger/Component/Configuration/RoleAnnotation/AnnotationFactory.tsx b/client/src/visualiser-debugger/Component/Configuration/RoleAnnotation/AnnotationFactory.tsx index 4843f895e..9ff9cf673 100644 --- a/client/src/visualiser-debugger/Component/Configuration/RoleAnnotation/AnnotationFactory.tsx +++ b/client/src/visualiser-debugger/Component/Configuration/RoleAnnotation/AnnotationFactory.tsx @@ -8,9 +8,9 @@ export function AnnotationFactory (backendRole: BackendTypeRole, { }: TypeAnnotationProp) : JSX.Element | null { switch(backendRole){ case BackendTypeRole.LinkedList: - - case BackendTypeRole.BinaryTree: - + return + case BackendTypeRole.BinaryTree: + return case BackendTypeRole.Empty: return null; default: diff --git a/client/src/visualiser-debugger/Component/Configuration/TypeAnnotation.tsx b/client/src/visualiser-debugger/Component/Configuration/TypeAnnotation.tsx index e3b61fdc1..185fae207 100644 --- a/client/src/visualiser-debugger/Component/Configuration/TypeAnnotation.tsx +++ b/client/src/visualiser-debugger/Component/Configuration/TypeAnnotation.tsx @@ -100,11 +100,9 @@ export const TypeAnnotation: React.FC = ({
- - - {/** Create a Factory pattern to generate Annotation classs */} + {/* should this be true??? */} + {annotation} - {/* */} ); diff --git a/client/src/visualiser-debugger/Types/annotationType.ts b/client/src/visualiser-debugger/Types/annotationType.ts index 9135a9486..9f11f00ad 100644 --- a/client/src/visualiser-debugger/Types/annotationType.ts +++ b/client/src/visualiser-debugger/Types/annotationType.ts @@ -143,6 +143,7 @@ export enum BackendTypeRole { export enum StackVariableRole { LinkedListPointer = 'Linked List Node', Empty = 'Not Visualized', + BinaryTreePointer = 'Binary Tree Node', } export type PossibleLinkedListAnnotation = { From 2384c8fe9f243c7fe79a9af3f4ebd17cb10bcbde Mon Sep 17 00:00:00 2001 From: Sylvia Wang Date: Fri, 8 Nov 2024 20:22:37 +1100 Subject: [PATCH 7/9] added bst to stack variable --- .../Component/Configuration/StackVarDeclaration.tsx | 4 ++-- client/src/visualiser-debugger/Types/annotationType.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/client/src/visualiser-debugger/Component/Configuration/StackVarDeclaration.tsx b/client/src/visualiser-debugger/Component/Configuration/StackVarDeclaration.tsx index c4fb4af90..35c664829 100644 --- a/client/src/visualiser-debugger/Component/Configuration/StackVarDeclaration.tsx +++ b/client/src/visualiser-debugger/Component/Configuration/StackVarDeclaration.tsx @@ -33,7 +33,7 @@ export const StackVarAnnotation: React.FC = ({ // Annotate by default if the variable contains a pointer useEffect(() => { - if (selectedRole === StackVariableRole.LinkedListPointer) { + if (selectedRole === StackVariableRole.LinkedListPointer || selectedRole === StackVariableRole.BinaryTreePointer) { const newStackAnnotation = { [name]: memoryValue.typeName, }; @@ -84,7 +84,7 @@ export const StackVarAnnotation: React.FC = ({ type="button" onClick={() => { setSelectedRole(role[1]); - if (role[1] === StackVariableRole.LinkedListPointer) { + if (role[1] === StackVariableRole.LinkedListPointer || role[1] === StackVariableRole.BinaryTreePointer) { updateStackAnnotation({ [name]: memoryValue.typeName }); } else { updateStackAnnotation({ [name]: null }); diff --git a/client/src/visualiser-debugger/Types/annotationType.ts b/client/src/visualiser-debugger/Types/annotationType.ts index 9f11f00ad..c1fabd0ba 100644 --- a/client/src/visualiser-debugger/Types/annotationType.ts +++ b/client/src/visualiser-debugger/Types/annotationType.ts @@ -142,8 +142,8 @@ export enum BackendTypeRole { export enum StackVariableRole { LinkedListPointer = 'Linked List Node', - Empty = 'Not Visualized', BinaryTreePointer = 'Binary Tree Node', + Empty = 'Not Visualized', } export type PossibleLinkedListAnnotation = { From e9f985f6a2408b8960da97e083ef92fb1b8ff6af Mon Sep 17 00:00:00 2001 From: Sylvia Wang Date: Fri, 11 Apr 2025 16:23:59 +1000 Subject: [PATCH 8/9] tree annotation types --- .../RoleAnnotation/BinaryTreeAnnotation.tsx | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/client/src/visualiser-debugger/Component/Configuration/RoleAnnotation/BinaryTreeAnnotation.tsx b/client/src/visualiser-debugger/Component/Configuration/RoleAnnotation/BinaryTreeAnnotation.tsx index 986d9d2ed..c99688d12 100644 --- a/client/src/visualiser-debugger/Component/Configuration/RoleAnnotation/BinaryTreeAnnotation.tsx +++ b/client/src/visualiser-debugger/Component/Configuration/RoleAnnotation/BinaryTreeAnnotation.tsx @@ -24,7 +24,9 @@ export const createPossibleTreeTypeDecl = ( possibleLefts: [], possibleRights: [], }; - + if (typeDecl.fields === undefined) { + return null; + } typeDecl.fields.forEach((field) => { if (isNativeTypeName(field.typeName)) { possibleTypeDecl.possibleValues.push({ @@ -66,9 +68,9 @@ export const createPossibleTreeTypeDecl = ( export const TreeNodeAnnotation: AnnotationComponent = ({ backendType }: AnnotationProp) => { const [possibleTypeDeclForTree, setPossibleTypeDeclForTree] = - useState(createPossibleTreeTypeDecl(backendType)); + useState(createPossibleTreeTypeDecl(backendType)); const { updateUserAnnotation, visualizer } = useGlobalStore(); - const [nodeAnnotation, setNodeAnnotation] = useState(null); + const [nodeAnnotation, setNodeAnnotation] = useState(null); const handleUpdateNodeAnnotation = (newAnnotation: BinaryTreeAnnotation) => { updateUserAnnotation({ stackAnnotation: visualizer.userAnnotation.stackAnnotation, @@ -78,7 +80,7 @@ export const TreeNodeAnnotation: AnnotationComponent = ({ backendType }: Annotat }, }); } - const handleTreeNodeAnnotation = (possibleTypeAnnotation: PossibleBinaryTreeAnnotation) => { + const handleTreeNodeAnnotation = (possibleTypeAnnotation: PossibleBinaryTreeAnnotation | null) => { if (possibleTypeAnnotation === null) return; setPossibleTypeDeclForTree(possibleTypeAnnotation); const newAnnotation: BinaryTreeAnnotation = { From fd1df0271c3c7d1431c3fa4b6c5b2cccf4e4383d Mon Sep 17 00:00:00 2001 From: Sylvia Wang Date: Fri, 18 Apr 2025 19:36:06 +1000 Subject: [PATCH 9/9] fix errors --- .../Configuration/RoleAnnotation/BinaryTreeAnnotation.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/client/src/visualiser-debugger/Component/Configuration/RoleAnnotation/BinaryTreeAnnotation.tsx b/client/src/visualiser-debugger/Component/Configuration/RoleAnnotation/BinaryTreeAnnotation.tsx index c99688d12..41752fbeb 100644 --- a/client/src/visualiser-debugger/Component/Configuration/RoleAnnotation/BinaryTreeAnnotation.tsx +++ b/client/src/visualiser-debugger/Component/Configuration/RoleAnnotation/BinaryTreeAnnotation.tsx @@ -121,7 +121,7 @@ export const TreeNodeAnnotation: AnnotationComponent = ({ backendType }: Annotat name: newNodeData, typeName: newNodeDataType, }, - }; + } as BinaryTreeAnnotation; setNodeAnnotation(newAnnotation); handleUpdateNodeAnnotation(newAnnotation); } @@ -135,7 +135,7 @@ export const TreeNodeAnnotation: AnnotationComponent = ({ backendType }: Annotat name: newLeftData, typeName: newLeftDataType, }, - }; + } as BinaryTreeAnnotation; setNodeAnnotation(newAnnotation); handleUpdateNodeAnnotation(newAnnotation); } @@ -149,7 +149,7 @@ export const TreeNodeAnnotation: AnnotationComponent = ({ backendType }: Annotat name: newRightData, typeName: newRightDataType, }, - }; + } as BinaryTreeAnnotation; setNodeAnnotation(newAnnotation); handleUpdateNodeAnnotation(newAnnotation); }