chaco.overlays.data_label module

Defines the DataLabel class and related trait and function.

class chaco.overlays.data_label.DataLabel(component=None, *args, **kw)

Bases: chaco.overlays.tooltip.ToolTip

A label on a point in data space.

Optionally, an arrow is drawn to the point.

arrow_color = ColorTrait("black")

The color of the arrow.

arrow_max_length = Float(inf)

The maximum length of the arrow before it will be drawn. By default, the arrow will be drawn regardless of how long it is.

arrow_min_length = Float(0)

The minimum length of the arrow before it will be drawn. By default, the arrow will be drawn regardless of how short it is.

arrow_root = Enum("auto", "top left", "top right", "bottom left",

The position of the base of the arrow on the label. If this is ‘auto’, then the label uses label_position. Otherwise, it treats the label as if it were at the label position indicated by this attribute.

arrow_size = Float(10)

The length of the arrowhead, in screen points (e.g., pixels).

arrow_visible = Bool(True)   # FIXME: replace with some sort of ArrowStyle

Draw an arrow from the label to the data point? Only used if data_point is not None.

clip_to_plot = Bool(True)

Does the label clip itself against the main plot area? If not, then the label draws into the padding area (where axes typically reside).

corner_radius = Float(10)

The radius (in screen coordinates) of the curved corners of the “bubble”

custom_symbol = Any

The symbol to use if marker is set to “custom”. This attribute must be a compiled path for the given Kiva context.

data_point = ArrayOrNone()

The point in data space where this label should anchor itself.

label_format = Str("(%(x)f, %(y)f)")

The format string that determines the label’s text. This string is formatted using a dict containing the keys ‘x’ and ‘y’, corresponding to data space values.

label_position = LabelPositionTrait

The location of the data label relative to the data point.

label_style = Enum('box', 'bubble')

‘box’ is a simple rectangular box, with an arrow that is a single line with an arrowhead at the data point. ‘bubble’ can be given rounded corners (by setting corner_radius), and the ‘arrow’ is a thin triangular wedge with its point at the data point. When label_style is ‘bubble’, the following traits are ignored: arrow_size, arrow_color, arrow_root, and arrow_max_length.

label_text = Str

The text to show on the label, or above the coordinates for the label, if show_label_coords is True

marker = MarkerTrait

The type of marker to use. This is a mapped trait using strings as the keys.

marker_color = ColorTrait("red")

The color of the inside of the marker.

marker_line_color = ColorTrait("black")

The color out of the border drawn around the marker.

marker_line_width = Float(1.0)

The thickness, in pixels, of the outline to draw around the marker. If this is 0, no outline will be drawn.

marker_size = Int(4)

The pixel size of the marker (doesn’t include the thickness of the outline).

marker_visible = Bool(True)

Mark the point on the data that this label refers to?

overlay(component, gc, view_bounds=None, mode='normal')

Draws the tooltip overlaid on another component.

Overrides and extends ToolTip.overlay()

show_label_coords = Bool(True)

Flag whether to show coordinates with the label or not.

xmid = Property(Float, observe=['x', 'x2'])

The center x position (average of x and x2)

ymid = Property(Float, observe=['y', 'y2'])

The center y position (average of y and y2)

chaco.overlays.data_label.draw_arrow(gc, pt1, pt2, color, arrowhead_size=10.0, offset1=0, offset2=0, arrow=None, minlen=0, maxlen=inf)

Renders an arrow from pt1 to pt2. If gc is None, then just returns the arrow object.

Parameters
  • gc (graphics context) – where to render the arrow

  • pt1 (point) – the origin of the arrow

  • pt2 (point) – where the arrow is pointing

  • color (a 3- or 4-tuple of color value) – the color to use for the arrow stem and head

  • arrowhead_size (number) – screen units corresponding to the length of the arrowhead

  • offset1 (number) – the amount of space from the start of the arrow to pt1

  • offset2 (number) – the amount of space from the tip of the arrow to pt2

  • arrow (object) – an opaque object returned by previous calls to draw_arrow. If this argument is provided, all other arguments (except gc) are ignored

  • minlen (number or None) – the minimum length of the arrow; if the arrow is shorter than this, it will not be drawn

  • maxlen (number or None) – the maximum length of the arrow; if the arrow is longer than this, it will not be drawn

Returns

  • An ‘arrow’ (opaque object) which can be passed in to subsequent

  • calls to this method to short-circuit some of the computation.

  • Even if an arrow is not drawn (due to minlen/maxlen restrictions),

  • an arrow will be returned.

chaco.overlays.data_label.find_region(px, py, x, y, x2, y2)

Classify the location of the point (px, py) relative to a rectangle.

(x, y) and (x2, y2) are the lower-left and upper-right corners of the rectangle, respectively. (px, py) is classified as “left”, “right”, “top”, “bottom” or “inside”, according to the following diagram:

top / # noqa
/ # noqa

+———-+ # noqa

left | inside | right # noqa

+———-+ # noqa

/ # noqa

/ bottom # noqa