| Home | Trees | Index | Help |
|---|
| Package ocempgui :: Package widgets :: Module Graph2D :: Class Graph2D |
|
object--+ |INotifyable--+ |BaseObject--+ |object--+ | | |Sprite--+ |BaseWidget--+ |Diagram--+ | Graph2D
Graph2D (width, height) -> Graph2D
A widget displaying graphs on a cartesian coordinate plane.
The Graph2D widget displays function graphs on a cartesian
coordinate plane using two axes.
The axes, scale units and units attributes must have at least two
values on assignment to fit both, the horizontal and vertical axes.
self.axes = 't', 'v' # Set velocity related to time.
self.set_axes ('x', 'y') # The default.
# seconds for the time axis, mph for the velocity axis.
self.scale_units = 's', 'mph'
self.set_scale_units ('-', '-') # The default.
# Each second has a distance of 10px to its neighbours and each mph
# has a distance of 25px to its neighbours.
self.units = 10, 25
self.set_units (10, 10) # The default.
Setting the 'orientation' attribute of the Graph2D widget to
ORIENTATION_VERTICAL will cause it to be rotated clockwise by 90
degrees.
The Graph2D can display the names of the axes and their scale units
next to the related axes. This can be adjusted using the
'show_names' attribute and set_show_names() method:
self.show_names = True # Show the names and scale units.
self.set_show_names (False) # Do not show them.
The axes and graph colors can be set to individual values (e.g. to
outline certain function behaviours) through the 'axis_color' and
'graph_color' attributes and their respective methods
set_axis_color() and set_graph_color().
self.axis_color = (0, 255, 0)
self.set_axiscolor ((255, 255, 0))
self.graph_color = (0, 255, 255)
self.set_graph_color (255, 0, 0)
The 'zoom_factor' attribute and set_zoom_factor() method set the zoom
factor for the graph. Values between 0 and 1 will zoom it out while
values greater than 1 will zoom it out.
Note: The zoom factor directly modifies the 'units' attribute values,
which can lead to rounding errors when using floating point zoom factors.
This usually results in a minor discrepancy, when you try to restore the
original values.
# Zoom the x axis out and the y axis in.
self.zoom_factor = 0.5, 2.0
# Zoom both axis in.
self.set_zoom_factor (3.0, 3.0)
Default action (invoked by activate()):
See the Diagram class.
Mnemonic action (invoked by activate_mnemonic()):
See the Diagram class.
Signals:
SIG_KEYDOWN - Invoked, when a key is pressed while the Graph2D has
the input.
SIG_MOUSEDOWN - Invoked, when a mouse button is pressed on the
Graph2D.
SIG_DOUBLECLICKED - Invoked, when a double-click was emitted on the
Graph2D.
Attributes:
show_names - Indicates, whether the axis names and scale units should
be shown or not.
axis_color - The color for both axes.
graph_color - The color for the displayed graph.
zoom_factor - The zoom factor values for both axes.
| Method Summary | |
|---|---|
__init__(self,
width,
height)
| |
W.draw () -> None | |
G.draw_bg () -> Surface | |
G.get_axes (...) -> None | |
G.get_scale_units (...) -> None | |
G.set_units (...) -> None | |
G.notify (...) -> None | |
G.set_axes (...) -> None | |
G.set_axis_color (...) -> None | |
G.set_data (...) -> None | |
G.set_graph_color (...) -> None | |
G.set_scale_units (...) -> None | |
G.set_show_names (...) -> None | |
G.set_units (...) -> None | |
G.set_zoom_factor (...) -> None | |
G.zoom_in () -> None | |
G.zoom_out () -> None | |
| Inherited from Diagram | |
D.evaluate () -> None | |
D.set_eval_func (...) -> None | |
D.set_negative (...) -> None | |
D.set_orientation (...) -> None | |
D.set_origin (...) -> None | |
D.set_values (...) -> None | |
| Inherited from BaseWidget | |
W.activate () -> None | |
W.activate_mnemonic (...) -> bool | |
W.check_sizes (...) -> int, int | |
W.create_style () -> WidgetStyle | |
For debugging usage only | |
W.destroy () -> None | |
W.get_style () -> WidgetStyle | |
B.initclass () -> None (Class method) | |
W.lock () -> None | |
W.rect_to_client (...) -> pygame.Rect | |
W.set_depth (...) -> None | |
W.set_dirty (...) -> None | |
W.set_entered (...) -> None | |
W.set_event_area (...) -> None | |
W.set_event_manager (...) -> None | |
W.set_focus (...) -> bool | |
W.set_index (...) -> None | |
W.set_indexable (...) -> None | |
W.set_maximum_size (...) -> None | |
W.set_minimum_size (...) -> None | |
W.set_opacity (...) -> None | |
W.set_position (...) -> None | |
W.set_sensitive (...) -> None | |
W.set_size (...) -> None | |
W.set_state (...) -> None | |
W.set_style (...) -> None | |
W.set_tooltip (...) -> None | |
W.unlock () -> None | |
W.update (...) -> None | |
| Inherited from BaseObject | |
B.connect_signal (...) -> EventCallback | |
B.disconnect_signal (...) -> None | |
B.emit (...) -> bool | |
B.run_signal_handlers (...) -> None | |
| Inherited from Sprite | |
| |
add(group or list of of groups, ...) add a sprite to container | |
| |
alive() -> bool check to see if the sprite is in any groups | |
groups() -> list of groups list used sprite containers | |
kill() remove this sprite from all groups | |
remove(group or list of groups, ...) remove a sprite from container | |
| |
| Inherited from object | |
x.__delattr__('name') <==> del x.name | |
x.__getattribute__('name') <==> x.name | |
x.__hash__() <==> hash(x) | |
T.__new__(S, ...) -> a new object with type S, a subtype of T | |
helper for pickle | |
helper for pickle | |
x.__setattr__('name', value) <==> x.name = value | |
x.__str__() <==> str(x) | |
| Property Summary | |
|---|---|
axis_color: The color of the axes. | |
graph_color: The color of the graph. | |
show_names: Indicates, whether the axis names should be shown. | |
zoom_factor: Zoom factor for the axes. | |
| Inherited from Diagram | |
axes: The axes to show. | |
data: The data to evaluate. | |
eval_func: The evaluation function for calculation. | |
negative: Indicates, whether negative values are shown. | |
orientation: The orientation of the axes. | |
origin: Coordinates of the point of origin on the widget | |
scale_units: The scale units of the axes. | |
units: The pixels per unit to set. | |
values: The calculated values of the set data. | |
| Inherited from BaseWidget | |
bottom | |
bottomleft | |
bottomright | |
center | |
centerx | |
centery | |
controls: Widgets associated with the widget. | |
depth: The z-axis layer depth of the widget. | |
dirty: Indicates, whether the widget need to be redrawn. | |
entered: Indicates, whether the widget is entered. | |
eventarea: The area, which gets the events. | |
focus: The focus of the widget. | |
h | |
height | |
image: The visible surface of the widget. | |
index: The tab index position of the widget. | |
indexable: The IIndexable, the widget is attached to. | |
left | |
locked: Indicates, whether the widget is locked. | |
maxsize: The maximum size to occupy by the widget. | |
midbottom | |
midleft | |
midright | |
midtop | |
minsize: The guaranteed size of the widget. | |
opacity: The opacity of the widget. | |
position: The position of the topleft corner. | |
rect: The area occupied by the widget. | |
right | |
sensitive: The sensitivity of the widget. | |
size | |
state: The current state of the widget. | |
style: The style of the widget. | |
tooltip: The tool tip text to display for the widget. | |
top | |
topleft | |
topright | |
w | |
width | |
x | |
y | |
| Inherited from BaseObject | |
manager: The event manager to use by the object. | |
| Instance Method Details |
|---|
draw(self)W.draw () -> None Draws the Graph2D surface. Creates the visible surface of the Graph2D.
|
draw_bg(self)G.draw_bg () -> Surface Draws the Graph2D background surface and returns it. Creates the visible background surface of the Graph2D and returns it to the caller. |
get_axes(self)G.get_axes (...) -> None Gets the amount and names of the axes.
|
get_scale_units(self)G.get_scale_units (...) -> None Gets the scale units of the axes. |
get_units(self)G.set_units (...) -> None Gets the pixels per unit for dimensioning.
|
notify(self, event)G.notify (...) -> None Notifies the Graph2D about an event. |
set_axes(self, axes)G.set_axes (...) -> None Sets the amount and names of the axes. Raises a TypeError, if the passed argument is not a list or tuple. Raises a ValueError, if the passed argument values are not strings.
|
set_axis_color(self, var)G.set_axis_color (...) -> None Sets the color of the axes of the coordinate plane. |
set_data(self, data)G.set_data (...) -> None Sets the data to evaluate. Raises a TypeError, if the passed argument is not a list or tuple. Raises a ValueError, if the passed argument values are not integers or floats.
|
set_graph_color(self, var)G.set_graph_color (...) -> None Sets the color of the graph to draw. |
set_scale_units(self, units)G.set_scale_units (...) -> None Sets the scale units of the axes. Raises a TypeError, if the passed argument is not a list or tuple. Raises a ValueError, if the passed argument values are not strings. |
set_show_names(self, var)G.set_show_names (...) -> None Sets, whether the axis names and scale units should be shown. If set to True, the names and scale units of both axes will be displayed besides and beneath the axes in the form 'name / unit'. |
set_units(self, units)G.set_units (...) -> None Sets the pixels per unit for dimensioning. Raises a TypeError, if the passed argument is not a list or tuple. Raises a ValueError, if the passed argument values are not integers greater than 0.
|
set_zoom_factor(self, x, y)G.set_zoom_factor (...) -> None Zooms the graph in or out by modifying the pixel per units values. Zooms the graph in or out by modifying the pixel per units values. Passing 0 as zoom factor will reset the Raises a TypeError, if the passed arguments are not floats or integers. Raises a ValueError, if the passed arguments are smaller than or equal to 0. |
zoom_in(self)G.zoom_in () -> None Zooms into the graph by factor 2. |
zoom_out(self)G.zoom_out () -> None Zoom out of the graph by factor 2. |
| Property Details |
|---|
axis_colorThe color of the axes.
|
graph_colorThe color of the graph.
|
show_namesIndicates, whether the axis names should be shown.
|
zoom_factorZoom factor for the axes.
|
| Home | Trees | Index | Help |
|---|
| Generated by Epydoc 2.1 on Thu Jan 10 10:18:44 2008 | http://epydoc.sf.net |