-
Notifications
You must be signed in to change notification settings - Fork 174
Data Visualizer
The data visualizer tool is a tool that allows the visualization of data in a convenient way.
draw_data is the Source function corresponding to the data visualizer.
draw_data is a varargs function; multiple data structures can be used as parameters in a single draw_data call. Each draw_data call maps to a single step, which can then be stepped through using the left and right arrow keys (when the side content panel is focused), or the "Prev" and "Next" buttons.
For example, the following will generate a single step containing two drawings, one for each list.
draw_data(list(1,2,3), list(4,5,6));The code for the data visualizer resides in src/features/listVisualizer
src/features/listVisualizer:
- drawable -- React components corresponding to various drawings
- Drawable.ts -- exposes the Drawables to external classes
- ArrowDrawable.tsx -- draws an arrow used with pairs and functions
- FunctionDrawable.tsx -- draws two balls representing a function
- NullDrawable.tsx -- draws the line corresponding to a slash, which represents a null value in a box-and-pointer diagram
- PairDrawable.tsx -- draws two boxes representing a pair
- tree
- TreeNode.ts -- exposes the TreeNodes to external classes
- BaseTreeNode.ts -- TreeNode class representing a tree node
- Tree.tsx -- Tree class responsible for parsing a Source data structure; TreeDrawer class responsible for drawing a parsed Tree
- DataTreeNode.tsx -- A TreeNode that corresponds to a piece of data (data is defined as a non-pair and non-function)
- DrawableTreeNode.tsx -- A TreeNode that has a pre-defined drawable, i.e. FunctionTreeNode and PairTreeNode. These are nodes that represent non-primitives, and can be pointed at back twice in the same structure (e.g. `pair(lst, lst)`)
- FunctionTreeNode.tsx -- TreeNode representing a function
- PairTreeNode.tsx -- TreeNode representing a pair
- Config.ts -- configuration for drawings
- list.js -- definitions of Source data structures and functions, in Javascript
- ListVisualizer.tsx -- the main public-facing class
- ListVisualizerTypes.tsx -- Typescript type definitions corresponding to Source types (pairs, lists, etc.).
- ListVisualizerUtils.tsx -- utility functions
The data visualizer also makes use of:
src/commons/saga/WorkspaceSaga.tssrc/commons/util/JsSlangHelper.tssrc/commons/sideContent/SideContentListVisualizer.tsx
The main outfacing code is in ListVisualizer.tsx, where the static functions init, drawData, and clear are exposed.
This is used by the corresponding side content React component ` (the one responsible for rendering the content of the draw data tool at the right side of Source Academy Playground) to render the drawings of the data.
What happens in a single "run" of the code in Source Academy is:
- WorkplaceSaga cleans up the environment, and calls
ListVisualizer.clearto reset the list visualizer's state. - Each call of
draw_datain the code corresponds to aStep, which corresponds to an array of drawings, one for each structure in the varargs. The internalstepslist ofListVisualizeris then appended with the newStep, andListVisualizer.setStepsis called. - At the end of all the calls, the side content React component has an array of
Stepscorresponding to thedraw_datacalls.
ListVisualizer.init is called by SideContentListVisualizer to attach a listener function setSteps. setSteps will be called by ListVisualizer when the steps -- each corresponding to a draw_data call -- are updated.
ListVisualizer.drawData is the function that corresponds to draw_data in Source Academy.
The way that draw_data invokes this is via JsSlangHelper.visualizeList, which is called by Source.
ListVisualizer.clear is used to reset the list visualizer's state whenever the code is re-run, so as to clear the drawings.