-
Notifications
You must be signed in to change notification settings - Fork 172
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_datacall. 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
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 src/commons/sideContent/SideContentListVisualizer.tsx` (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.
The data visualizer also makes use of:
src/commons/saga/WorkspaceSaga.ts
src/commons/util/JsSlangHelper.ts
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.
What happens in a single "run" of the code in Source Academy is:
- WorkplaceSaga cleans up the environment, and calls
ListVisualizer.clear
to reset the list visualizer's state. - Each call of
draw_data
in the code corresponds to aStep
, which corresponds to an array of drawings, one for each structure in the varargs. The internalsteps
list ofListVisualizer
is then appended with the newStep
, andListVisualizer.setSteps
is called. - At the end of all the calls, the side content React component has an array of
Steps
corresponding to thedraw_data
calls.