18 Annotation

class text_box.T
A text box is an optional element that adds a text box and arrows to a chart. This class supports the following attributes:

bottom_fudge
Type: length in points ( See Section 4) Default: 5.

The amount of space below the last line

fill_style
Type: fill_style.T ( see Section 16) Default: fill_style.white.

Specifies the fill style of the text box.

left_fudge
Type: length in points ( See Section 4) Default: 5.

The amount of space left of the box

line_style
Type: line_style.T ( see Section 14) Default: line_style.black.

The line style of the surrounding frame.

loc
Type: tuple Default: (0, 0).

The location of the text box.

radius
Type: length in points ( See Section 4) Default: 0.

Radius of the four corners of the rectangle. If the value is zero, a sharp-cornered rectangle is drawn.

right_fudge
Type: length in points ( See Section 4) Default: 5.

The amount of space right of the box

shadow
Type: (xoff,yoff,fill) Default: None.

The value is either None or a tuple. When non-None, a drop-shadow is drawn beneath the object. X-off, and y-off specifies the offset of the shadow relative to the object, and fill specifies the style of the shadow ( see Section 16).

text
Type: str Default: "???".

Text body. See Section 17

top_fudge
Type: length in points (See Section 4) Default: 0.

The amount of space (in points) above the first line

In addition to the above attributes, this class provides the following methods.

add_arrow( tip, tail=None, arrow=arrow.default)
This method adds a straight arrow that points to tip, which is a tuple of integers. Parameter tail specifies the starting point of the arrow. It is either None or a string consisting of the following letters:
'l', 'c', 'r', 't', 'm,', 'b'

Letters 'l', 'c', or 'r' means to start the arrow from the left, center, or right of the text box, respectively. Letters 't', 'm', or 'b' means to start the arrow from the top, middle or bottom of the text box. For example, when tail = 'tc' then arrow is drawn from top-center point of the text box. Parameter arrow specifies the style of the arrow.

See Also:

Section 19 for arrows.

Image annotations

Annotations example

Below is the source code that produces the above chart. /home/saito/pychart/demos/annotations.py

#
# Copyright (C) 2000-2005 by Yasushi Saito (yasushi.saito@gmail.com)
# 
# Pychart is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2, or (at your option) any
# later version.
#
# Pychart is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
# for more details.
#
from pychart import *

tb = text_box.T(loc=(100,100), text="Without frame")
tb.add_arrow((50, 100))
tb.add_arrow((180, 100))
tb.draw()

tb = text_box.T(loc=(100,130), text="/hCMulti\n/bLine")
tb.add_arrow((50, 120))
tb.add_arrow((180, 100))
tb.draw()

tb = text_box.T(loc=(100,160), text="Fat arrow", line_style=None)
tb.add_arrow((180, 140), tail='rm', arrow = arrow.fat1)
tb.draw()

text_box.T(loc=(180, 100), text="/a90Funny background",
           fill_style = fill_style.gray70).draw()

text_box.T(loc=(180, 140), text="/hL/20Big/oText\n/24/bHuge/oText",
           fill_style = None).draw()