21.4 Clipping

##
21.4 Clipping

A rectangle, polygon, or ellipsis can be used to define a clipping region. Any drawing commands ( see Section 21) issued afterward are confined in the region. You can even nest multiple clipping regions, in which case, drawings will be clipped to the intersection of the regions. `canvas.endclip()` ends the clipping. Clipping commands and `endclip()` must nest properly.

Clipping test

Below is the source code that produces the above chart. ../demos/cliptest.py

    from pychart import *

    can = canvas.default_canvas()

    data = [(10, 20), (20, 65), (30, 55), (40, 45)]

    # tic_angle is the angle X values are displayed below the axis.
    xaxis = axis.X(label="Stuff")
    yaxis = axis.Y(label="Value")

    ar = area.T(x_axis=xaxis, y_axis=yaxis)

    plot = line_plot.T(label="foo", data=data, xcol=0, ycol=1,
                       tick_mark=tick_mark.star)

    ar.add_plot(plot)
    can.ellipsis(line_style.T(width=1.5,dash=(4,4)), None, 30, 20, 80, 0.8)
    can.clip_ellipsis(30, 20, 80, 0.8)
    ar.draw(can)
    can.endclip()

The following `canvas.T` methods are used to control clipping:

`clip`( | x1, y1, x2, y2)

  Activate a rectangular clip region, (X1, Y1) - (X2, Y2). You must call endclip() after you completed drawing.

      canvas.clip(x,y,x2,y2)
      draw something ...
      canvas.endclip()

`clip_ellipsis`( | x, y, radius, y_elongation)

  Create an elliptical clip region. You must call endclip() after you completed drawing. See also the ellipsis method.

`clip_polygon`( | [(x1,y2),(x2,y2), ..., (xn, yn)])

  Create a polygonal clip region. You must call endclip() after you completed drawing. See also the polygon method.

`endclip`( | )

  End the current clip region. When clip calls are nested, it ends the most recently created crip region.