Skip to content

Draw_Data: Implement new visualizers#3678

Merged
martin-henz merged 39 commits into
masterfrom
CP3108_26MH
Apr 8, 2026
Merged

Draw_Data: Implement new visualizers#3678
martin-henz merged 39 commits into
masterfrom
CP3108_26MH

Conversation

@elsxyss

@elsxyss elsxyss commented Mar 18, 2026

Copy link
Copy Markdown
Contributor

Summary

This PR adds 2 new box-and-pointer visualizers for when the draw_data function is ran, so that now there are:

  • Original View (original draw_data rendering)
  • Render Binary Tree (binary tree structure with coloured node groups)
  • Render General Tree (tree structure with coloured node groups, including non-binary trees)

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update
  • Code quality improvements

Added Functionality

  • Added 3 buttons to toggle between the Original View mode, Render Binary Tree mode, and Render General Tree mode
  • Added variable visual space generation for both of the Tree modes, to generate the space required in the data visualizer based on the input tree structure, before generating the input
  • Added specific node spacing algorithms for both of the Tree modes, to generate the input in a tree structure
  • Added sequential colouring to the nodes for both of the Tree modes
  • Added input validation checks for Render Binary Tree mode (valid binary tree input) and Render General Tree mode (valid tree input), and corresponding error messages
  • Adjusted arrow (pointer) generation for all 3 modes (for better alignment with node boxes)

Files Edited

  • Documentation:
    • src/features/dataVisualizer/[Documentation.md](http://documentation.md/)
    • src/features/dataVisualizer/images/BINARY_TREE_IMAGE.png
    • src/features/dataVisualizer/images/GENERAL_TREE_IMAGE.png
    • src/features/dataVisualizer/images/ORIGINAL_VIEW_IMAGE.png
  • Buttons:
    • src/commons/sideContent/content/SideContentDataVisualizer.tsx
  • Tree Drawing:
    • src/features/dataVisualizer/dataVisualizer.tsx
    • src/features/dataVisualizer/dataVisualizerTypes.ts
    • src/features/dataVisualizer/drawable/ArrayDrawable.tsx
    • src/features/dataVisualizer/drawable/ArrowDrawable.tsx
    • src/features/dataVisualizer/tree/ArrayTreeNode.tsx
    • src/features/dataVisualizer/tree/BaseTreeNode.ts
    • src/features/dataVisualizer/tree/DrawableTreeNode.tsx
    • src/features/dataVisualizer/tree/FunctionTreeNode.tsx
    • src/features/dataVisualizer/tree/Tree.tsx
    • src/commons/sagas/WorkspaceSaga/index.ts
  • Spacing:
    • src/features/dataVisualizer/Config.ts

How to Test

Run the following code in the Source Academy playground and open the Data Visualizer:
draw_data(list(1,2,3)): should only give error for “Render Binary Tree” mode.
draw_data([1,2,3]): should only give errors for “Render Binary Tree” mode and “Render General Tree” mode.
draw_data(list(1,list(2,null,null),list(3,null, null))): should not have any error, generates tree structures correctly in any of the 3 modes.

The appropriate box-and-pointer diagram should be generated. Boxes belonging to the same node should be the same colour, while those from the neighbouring nodes should be in different colours. Examples are shown in the documentation file.

Checklist

  • I have tested this code
  • I have updated the documentation

RichDom2185

This comment was marked as outdated.

Comment thread src/features/dataVisualizer/dataVisualizer.tsx Outdated
Comment thread src/features/dataVisualizer/dataVisualizer.tsx Outdated
@elsxyss elsxyss requested a review from RichDom2185 March 18, 2026 09:43
Comment thread src/features/dataVisualizer/dataVisualizer.tsx
Comment thread src/commons/sideContent/content/SideContentDataVisualizer.tsx Outdated
@coveralls

This comment was marked as outdated.

Comment thread src/features/dataVisualizer/tree/Tree.tsx Outdated
RichDom2185

This comment was marked as outdated.

Comment thread src/features/dataVisualizer/dataVisualizer.tsx Outdated
Comment thread src/commons/sideContent/content/SideContentDataVisualizer.tsx Outdated
Comment thread src/features/dataVisualizer/dataVisualizer.tsx
@martin-henz

This comment was marked as outdated.

Comment thread src/features/dataVisualizer/dataVisualizer.tsx Outdated
Comment thread src/features/dataVisualizer/dataVisualizer.tsx Outdated
@RichDom2185

This comment was marked as resolved.

@RichDom2185 RichDom2185 marked this pull request as draft March 23, 2026 12:06
@elsxyss elsxyss marked this pull request as ready for review March 25, 2026 08:54
Comment thread src/features/dataVisualizer/dataVisualizer.tsx Outdated
@martin-henz martin-henz enabled auto-merge (squash) April 6, 2026 15:11
@martin-henz martin-henz requested a review from RichDom2185 April 6, 2026 15:11
@TYS2

This comment was marked as resolved.

gemini-code-assist[bot]

This comment was marked as resolved.

@TYS2

TYS2 commented Apr 8, 2026

Copy link
Copy Markdown
Contributor

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces specialized visualization modes for binary and general trees within the Data Visualizer. It refactors the drawing logic into dedicated drawer classes and adds UI controls to switch between these modes. Feedback highlights a flaw in the binary tree validation logic that fails to check all branches, and an issue where TreeDepth is not reset, potentially causing layout errors during redraws. Additionally, the review points out unsafe non-null assertions in the tree drawers, the use of non-standard onMouseUp events for buttons, and the presence of unused dead code.

Comment thread src/features/dataVisualizer/dataVisualizer.tsx
Comment thread src/features/dataVisualizer/dataVisualizer.tsx Outdated
Comment thread src/features/dataVisualizer/tree/GeneralTreeDrawer.tsx Outdated
Comment thread src/commons/sideContent/content/SideContentDataVisualizer.tsx
Comment thread src/features/dataVisualizer/dataVisualizer.tsx Outdated
Comment thread src/features/dataVisualizer/dataVisualizer.tsx Outdated
Comment thread src/features/dataVisualizer/dataVisualizer.tsx
Comment thread src/features/dataVisualizer/dataVisualizer.tsx
Comment thread src/features/dataVisualizer/dataVisualizer.tsx Outdated
Comment thread src/features/dataVisualizer/dataVisualizer.tsx
@martin-henz

Copy link
Copy Markdown
Member

/gemini review
can you do a final check that all reviewer comments are resolved?

@gemini-code-assist

Copy link
Copy Markdown
Contributor

I have reviewed the current state of the pull request. The implementation of the new visualizers is in place, and the requested OOP refactor is underway. Regarding your request for a final check on reviewer comments:

Since the PR is currently marked as a draft, please ensure all remaining refactoring tasks are completed and the code is fully tested before marking it as ready for final review. Let me know if you need any further assistance with specific parts of the implementation.

@martin-henz martin-henz self-requested a review April 8, 2026 11:06

@martin-henz martin-henz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good now. All reviewer comments are addressed.

@martin-henz martin-henz dismissed RichDom2185’s stale review April 8, 2026 11:07

gemini bot confirmed that the reviewer comments are addressed.

@martin-henz martin-henz merged commit ecbe69a into master Apr 8, 2026
10 checks passed
@martin-henz martin-henz deleted the CP3108_26MH branch April 8, 2026 11:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants