~ubuntu-branches/ubuntu/utopic/python-chaco/utopic

« back to all changes in this revision

Viewing changes to docs/source/modules_and_classes.rst

  • Committer: Package Import Robot
  • Author(s): Andrew Starr-Bochicchio
  • Date: 2014-06-01 17:04:08 UTC
  • mfrom: (7.2.5 sid)
  • Revision ID: package-import@ubuntu.com-20140601170408-m86xvdjd83a4qon0
Tags: 4.4.1-1ubuntu1
* Merge from Debian unstable. Remaining Ubuntu changes:
 - Let the binary-predeb target work on the usr/lib/python* directory
   as we don't have usr/share/pyshared anymore.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
 
2
 
.. _modules_and_classes:
3
 
 
4
 
Commonly Used Modules and Classes
5
 
=================================
6
 
 
7
 
Base Classes
8
 
-----------------------------------------------------------------------------
9
 
 
10
 
.. rubric:: Plot Component
11
 
 
12
 
All visual components in Chaco subclass from :class:`PlotComponent`. It defines
13
 
all of the common visual attributes like background color, border styles and
14
 
color, and whether the component is visible. (Actually, most of these visual
15
 
attributes are inherited from the Enable drawing framework.) More importantly,
16
 
it provides the base behaviors for participating in layout, handling event
17
 
dispatch to tools and overlays, and drawing various layers in the correct order.
18
 
Subclasses almost never need to override or customize these base behaviors, but
19
 
if they do, there are several easy extension points.
20
 
 
21
 
PlotComponent is a subclass of Enable :class:`Component`. It has its
22
 
own default drawing order. It redefines the inherited traits :attr:`draw_order`
23
 
and :attr:`draw_layer`, but it doesn't define any new traits. Therefore, you
24
 
may need to refer to the API documentation for Enable Component,
25
 
even when you have subclassed Chaco PlotComponent.
26
 
 
27
 
If you subclass PlotComponent, you need to implement :meth:`do_layout`,
28
 
if you want to size the component correctly.
29
 
 
30
 
 
31
 
Data Objects
32
 
-----------------------------------------------------------------------------
33
 
 
34
 
.. rubric:: Data Source
35
 
 
36
 
A data source is a wrapper object for the actual data that it will be
37
 
handling. It provides methods for retrieving data, estimating a size of the
38
 
dataset, indications about the dimensionality of the data, a place for metadata
39
 
(such as selections and annotations), and events that fire when the data gets
40
 
changed. There are two primary reasons for a data source class: 
41
 
 
42
 
* It provides a way for different plotting objects to reference the same data.
43
 
* It defines the interface for embedding Chaco into an existing application.  
44
 
  In most cases, the standard ArrayDataSource will suffice. 
45
 
 
46
 
    *Interface:* :class:`AbstractDataSource`
47
 
 
48
 
    *Subclasses:* :class:`ArrayDataSource`, :class:`MultiArrayDataSource`, 
49
 
    :class:`PointDataSource`, :class:`GridDataSource`, :class:`ImageData`
50
 
 
51
 
.. rubric:: Data Range
52
 
 
53
 
A data range expresses bounds on data space of some dimensionality. The simplest
54
 
data range is just a set of two scalars representing (low, high) bounds in 1-D.
55
 
One of the important aspects of data ranges is that their bounds can be set to
56
 
``auto``, which means that they automatically scale to fit their associated
57
 
datasources. (Each data source can be associated with multiple ranges,
58
 
and each data range can be associated with multiple data sources.)
59
 
 
60
 
    *Interface*: :class:`AbstractDataRange`
61
 
 
62
 
    *Subclasses*: :class:`BaseDataRange`, :class:`DataRange1D`, 
63
 
    :class:`DataRange2D`
64
 
    
65
 
.. rubric:: Data Source
66
 
 
67
 
A data source is an object that supplies data to Chaco. For the most part, a
68
 
data source looks like an array of values, with an optional mask and metadata.
69
 
 
70
 
    *Interface*: :class:AbstractDataSource`
71
 
    
72
 
    *Subclasses*: :class:`ArrayDataSource`, :class:`DataContextDataSource`,
73
 
    :class:`GridDataSource`, :class:`ImageData`, :class:`MultiArrayDataSource`,
74
 
    :class:`PointDataSource`
75
 
 
76
 
The :attr:`metadata` trait attribute is a dictionary where you can stick 
77
 
stuff for other tools to find, without inserting it in the actual data.
78
 
 
79
 
Events that are fired on data sources are:
80
 
 
81
 
 * :attr:`data_changed`
82
 
 * :attr:`bounds_changed`
83
 
 * :attr:`metadata_changed`
84
 
 
85
 
    
86
 
.. rubric:: Mapper
87
 
 
88
 
Mappers perform the job of mapping a data space region to screen space, and
89
 
vice versa. Bounds on mappers are set by data range objects. 
90
 
 
91
 
    *Interface*: :class:`AbstractMapper`
92
 
 
93
 
    *Subclasses*: :class:`Base1DMapper`, :class:`LinearMapper`, 
94
 
    :class:`LogMapper`, :class:`GridMapper`, :class:`PolarMapper`
95
 
 
96
 
 
97
 
Containers
98
 
-----------------------------------------------------------------------------
99
 
 
100
 
.. rubric:: PlotContainer
101
 
 
102
 
:class:`PlotContainer` is Chaco's way of handling layout. Because it logically
103
 
partitions the screen space, it also serves as a way for efficient event
104
 
dispatch. It is very similar to sizers or layout grids in GUI toolkits like
105
 
WX. Containers are subclasses of PlotComponent, thus allowing them to
106
 
be nested. :class:`BasePlotContainer` implements the logic to correctly render
107
 
and dispatch events to sub-components, while its subclasses implement the
108
 
different layout calculations. 
109
 
 
110
 
A container gets the preferred size from its components, and tries to allocate
111
 
space for them. Non-resizeable components get their required size; whatever is
112
 
left over is divided among the resizeable components.
113
 
 
114
 
Chaco currently has three types of containers, 
115
 
described in the following sections.
116
 
 
117
 
    *Interface*: :class:`BasePlotContainer`
118
 
 
119
 
    *Subclasses*: :class:`OverlayPlotContainer`, :class:`HPlotContainer`, 
120
 
    :class:`VPlotContainer`, :class:`GridPlotContainer`
121
 
 
122
 
The listed subclasses are defined in the module 
123
 
:mod:`chaco.plot_containers`.
124
 
 
125
 
 
126
 
Renderers
127
 
-----------------------------------------------------------------------------
128
 
 
129
 
Plot renderers are the classes that actually draw a type of plot. 
130
 
 
131
 
    *Interface*: :class:`AbstractPlotRenderer`
132
 
    *Subclasses*:
133
 
    
134
 
      * :class:`BarPlot`
135
 
      * :class:`Base2DPlot`
136
 
      
137
 
        * :class:`ContourLinePlot`
138
 
        * :class:`ContourPolyPlot`
139
 
        * :class:`ImagePlot`: displays an image file, or color-maps scalar
140
 
          data to make an image
141
 
        * :class:`CMapImagePlot`
142
 
          
143
 
      * :class:`BaseXYPlot`: This class is often emulated by writers of other
144
 
        plot renderers, but renderers don't *need* to be structured this way.
145
 
        By convention, many have a :meth:`hittest` method. They *do* need
146
 
        to implement :meth:`map_screen`, :meth:`map_data`, and :meth:`map_index`
147
 
        from :class:`AbstractPlotRenderer`.
148
 
        
149
 
        * :class:`LinePlot`
150
 
        
151
 
          * :class:`ErrorBarPlot`
152
 
          
153
 
        * :class:`PolygonPlot`
154
 
        
155
 
          * :class:`FilledLinePlot`
156
 
          
157
 
        * :class:`ScatterPlot`
158
 
        
159
 
          * :class:`ColormappedScatterPlot`
160
 
          
161
 
        * :class:`ColorBar`
162
 
        * :class:`PolarLineRenderer`: NOTE: doesn't play well with others
163
 
        
164
 
You can use these classes to compose more interesting plots.
165
 
 
166
 
The module :mod:`chaco.plot_factory` contains various convenience
167
 
functions for creating plots, which simplify the set-up.
168
 
 
169
 
The :class:`chaco.plot.Plot` class (called "capital P Plot" when
170
 
speaking) represents what the user usually thinks of as a "plot": a set of data,
171
 
renderers, and axes in a single screen region. It is a subclass of
172
 
:class:`DataView`.
173
 
      
174
 
Tools
175
 
-----------------------------------------------------------------------------
176
 
 
177
 
Tools attach to a component, which gives events to the tool.
178
 
 
179
 
All tools subclass from Enable's :class:`BaseTool`, which is in turn an Enable
180
 
:class:`Interactor`.  Do not try to make tools that draw: use an overlay for
181
 
that.
182
 
 
183
 
Some tool subclasses exist in both Enable and Chaco, because they were created
184
 
first in Chaco, and then moved into Enable. 
185
 
 
186
 
    *Interface*: :class:`BaseTool`
187
 
    *Subclasses*: 
188
 
    
189
 
        * :class:`BroadcasterTool`: Keeps a list of other tools, and broadcasts
190
 
          events it receives to all those tools.
191
 
        * :class:`DataPrinter`: Prints the data-space position of the point
192
 
          under the cursor.
193
 
        * :class:`enable.tools.api.DragTool`: Enable base class
194
 
          for tools that do dragging.
195
 
          
196
 
          * :class:`MoveTool`
197
 
          * :class:`ResizeTool`
198
 
          * :class:`ViewportPanTool`
199
 
          
200
 
        * :class:`chaco.tools.api.DragTool`: Chaco base class
201
 
          for tools that do dragging.
202
 
          
203
 
          * :class:`BaseCursorTool`
204
 
          
205
 
            * :class:`CursorTool1D`
206
 
            * :class:`CursorTool2D`
207
 
            
208
 
          * :class:`DataLabelTool`
209
 
          * :class:`DragZoom`
210
 
          * :class:`LegendTool`
211
 
          * :class:`MoveTool`
212
 
          
213
 
        * :class:`DrawPointsTool`
214
 
        * :class:`HighlightTool`
215
 
        * :class:`HoverTool`
216
 
        * :class:`ImageInspectorTool`
217
 
        * :class:`LineInspector`
218
 
        * :class:`PanTool`
219
 
        
220
 
          * :class:`TrackingPanTool`
221
 
          
222
 
        * :class:`PointMarker`
223
 
        * :class:`SaveTool`
224
 
        * :class:`SelectTool`
225
 
          
226
 
          * :class:`ScatterInspector`
227
 
          * :class:`SelectableLegend`
228
 
        
229
 
        * :class:`enable.tools.api.TraitsTool`
230
 
        * :class:`chaco.tools.api.TraitsTool`
231
 
            
232
 
          
233
 
 
234
 
DragTool is a base class for tools that do dragging.
235
 
 
236
 
Other tools do things like panning, moving, highlighting, line segments, range selection, drag zoom, move data labels, scatter inspection, Traits UI. 
237
 
 
238
 
Overlays
239
 
-----------------------------------------------------------------------------
240
 
 
241
 
 
242
 
Miscellaneous
243
 
-----------------------------------------------------------------------------
244
 
 
245