Renderers
- class spb.backends.base_renderer.Renderer(plot, series)[source]
Base class for renderers. A renderer is responsible to render something on a plot and keep it updated when interactive widgets change states.
A renderer stores the following information:
plot
: the instance of thePlot
class containing the actual figure in which the renderer adds graphical elements.series
: the instance of BaseSeries that generates numerical data.handles
: a list, in which each handle stores the necessary objects in order to update the graphical elements in case of interactive-widgets plot. It will be populated by therenderer.draw()
method.draw_update_map
: a dictionary mapping draw_method to update_method, which is where the rendering is actually implemented. In particular:draw_method(renderer, data)
: use numericaldata
to add graphical elements torenderer.plot.fig
. It must return an handle, which is eventually used by update_method.update_method(renderer, data, handle)
: update graphical elements stored inhandle
with new numericaldata
.
Multiple key/value pairs can be added, all of which will receive the same numerical data. This allows to add different graphical elements to the same data series, in order to create more complex plots, promoting code reusability at the same time.
A renderer implements these methods:
draw: it will be called by
plot
when the figure is empty. This method extracts the numerical data from theseries
, and sends it to eachdraw_method
contained indraw_update_map
.update
: it will be called byplot
when the widgets change state. This method extracts the numerical data from theseries
, and sends it to eachupdate_method
contained indraw_update_map
, together with the appropriatehandle
.