The Watch Roads view is where the AVL tree comes to life. After obstacles have been added to the road, you can switch to this full-screen view to trigger tree traversals — pre-order, in-order, or pos-order — and watch each obstacle node highlight in the D3.js SVG as the backend streams the traversal sequence back over Socket.IO. The view also exposes the Delete/Remove button for removing individual obstacles (see Delete an Obstacle).Documentation Index
Fetch the complete documentation index at: https://mintlify.com/tutosrive/avl_tree_car_front/llms.txt
Use this file to discover all available pages before exploring further.
Prerequisites
At least one obstacle must have been added to the road. The Remove & Watch Roads button (#btn-watch-roads) remains disabled on the home screen until either:
- An obstacle was successfully inserted through Insert Obstacles, or
- Obstacles were loaded via Load JSON.
Steps
Click Remove & Watch Roads
Click the Remove & Watch Roads button (
#btn-watch-roads) on the home screen. HomeController instantiates WatchRoadsController (if not already created) and calls WatchRoadsController.init().The view loads and the tree renders
WatchRoadsController.init() performs three actions in sequence:- Replaces
<main>content — fetcheswatchRoads.htmland sets it asmain.innerHTML, replacing the home screen buttons with the Watch Roads layout (traversal buttons, a Back button, a Delete/Remove button, and the tree SVG container). - Initialises the AVL renderer — calls
avlCtrl.init(), which sets up the D3.js SVG element (#tree-svg), clears any previous drawing, and re-registers theavl_tree_balancedDOM event listener. - Requests the current tree — calls
avlCtrl.getTree(), which emitsget_tree_avlto the backend via Socket.IO.
avl_tree_balanced Socket.IO event containing the current tree structure. AVLController.initDataTree() receives the data, formats each node’s x, y, and type fields by looking up the corresponding Obstacle in the road model, and renders the full tree with D3.js. Each node appears as a circle with its obstacle SVG icon and a coordinate label (x, y) below it.Trigger a traversal
Three traversal buttons are available in the button bar:
Clicking any traversal button:
| Button label | Button ID | Socket.IO emit | Socket.IO receive | DOM event dispatched |
|---|---|---|---|---|
| Pre‑Order | #btn-pre | road_preorder | preorder | pre-order |
| In‑Order | #btn-in | road_inorder | inorder | in-order |
| Pos‑Order | #btn-pos | road_posorder | posorder | pos-order |
- Calls
__resetFocusAll()— removes the CSS classcurrentfrom every obstacle circle in the SVG, clearing any previous highlights. - Calls
avlCtrl.service.emit_get_road('<order>'), which emits the corresponding Socket.IO event to the backend (e.g.road_preorder).
Watch the nodes highlight
As the backend processes the traversal it streams node IDs back one at a time. For each emitted ID, The SVG circle whose
TreeService receives the Socket.IO event (e.g. preorder) and dispatches a matching DOM CustomEvent (e.g. pre-order) with the node ID as event.detail.WatchRoadsController.__eventRoadFocus() handles all three DOM events and calls __focusNodeInRoad(id):id attribute matches _<obstacleId> receives the current CSS class, highlighting it in the tree. Nodes light up sequentially as the backend emits each one.Reset or run another traversal
To run a different traversal, simply click another traversal button.
__resetFocusAll() clears all existing current classes before the new traversal begins, so the visualization always starts from a clean state.Navigate back to the home screen
Click the Back button (
#btn-back) in the top-left corner. This calls homeCtrl.init(true), which reloads the home screen HTML into <main> and calls avlCtrl.init(true) to re-render the AVL tree panel on the right side of the home layout. Controller instances and road data are preserved — nothing is reset.Each traversal highlights nodes sequentially as the backend emits them over Socket.IO. The timing between highlights depends entirely on how fast the backend streams the individual
preorder / inorder / posorder events. There is no client-side animation delay — each node highlights the moment its ID arrives.Deleting an obstacle from this view
The Delete/Remove button (#btn-del) in the button bar opens the Delete Obstacle dialog. See the Delete an Obstacle guide for the full workflow.
Element mapping
When the tree is first rendered,WatchRoadsController.__getElements() builds a lookup map from obstacle IDs to their corresponding SVG circle DOM elements: