A skeletal class to be subclassed when creating new visualizations from scratch. New visualizations using Matplotlib should use MPLVisualization
instead. The class should only be subclassed; it should not be instantiated itself and cannot be used directly as a visualizer.
Subclasses are required to implement the launch()
, update()
, and event()
methods.
Methods
Click a method name for more detailed documentation.
onStart( )
Called when a model begins or resumes after pausing. This function may be overridden by any subclass of
BaseVisualization
, but should not be called from model code.onStop( )
Called when a model pauses or terminates. This function may be overridden by any subclass of
BaseVisualization
, but should not be called from model code.event( t, color, **kwargs )
Called when an event is triggered, in order to be reflected in the visualization. For example, a line is drawn in
TimeSeries
, and the background flashes inCharts
. Any kwargs passed toEvents.add()
are passed to this function, allowing subclasses to receive custom arguments (for example,linestyle
inTimeSeries.event()
). This method is mandatory for subclasses to implement.This function is called automatically when an event is triggered and should not be called by user code.
launch( title )
Launches the visualization window (if in Tkinter) or cell (if in Jupyter). This method is required to be implemented by subclasses.
refresh( data )
Updates the visualization with new data and refreshes the display. This is mandatory for any subclasses to implement. Subclasses implementing this method should also use it to store any data necessary for future visualizer operations.
This function should only rarely be called by the user; call
model.step()
instead to increment the model by one period and update the graph.terminate( )
Cleanup on model termination. This function is called automatically from
model.terminate()
and should not be called from user code.
Object Properties
isNull — bool
True
when the model should run as-if with no visualization, for example if all the plots are unselected.False
indicates the window can be launched.lastUpdate — int
Because the model can be set to refresh the visualization only every so many periods, this property records the model time when data was last drawn to the visualization. This property is
None
until the visualization window is launched.Initial value: None
Hooks
Click a hook name for more detailed documentation.
visualRefresh( model, visual )
Runs when the visualizer updates, every n periods as determined by the
refresh
parameter.visualLaunch( model, visual )
Runs when
model.launchVisual()
is called, after the visualization is launched. Use themodelPostSetup
hook to catch before the visualization is launched.
Notes and Examples