[RELEASE] OpenERP 5.0.12
[odoo/odoo.git] / bin / pychart / zap.py
1 #
2 # Copyright (C) 2000-2005 by Yasushi Saito (yasushi.saito@gmail.com)
3
4 # Jockey is free software; you can redistribute it and/or modify it
5 # under the terms of the GNU General Public License as published by the
6 # Free Software Foundation; either version 2, or (at your option) any
7 # later version.
8 #
9 # Jockey is distributed in the hope that it will be useful, but WITHOUT
10 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 # FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12 # for more details.
13 #
14 import fill_style
15 import line_style
16 import copy
17
18 def _draw_zap(can, p1, p2, style, pat):
19     x = copy.deepcopy(p1)
20     x.extend(p2)
21     can.polygon(None, pat, x)
22     can.lines(style, p1)
23     can.lines(style, p2)
24     
25
26 def zap_horizontally(can, style, pat, x1, y1, x2, y2, xsize, ysize):
27     """Draw a horizontal "zapping" symbol on the canvas that shows
28     that a graph is ripped in the middle.
29
30     Parameter <fill_style> specifies the style for the zig-zag lines.
31     PAT specifies the pattern with which the area is filled.
32     The symbol is drawn in the rectangle (<x1>, <y1>) - (<x2>, <y2>).
33     Each "zigzag" has the width <xsize>, height <ysize>."""
34
35     assert isinstance(style, line_style.T)
36     assert isinstance(pat, fill_style.T)
37
38     points = []
39     points2 = []
40     x = x1
41     y = y1
42     while x < x2:
43         points.append((x, y))
44         points2.append((x, y + (y2-y1)))
45         x += xsize
46         if y == y1:
47             y += ysize
48         else:
49             y -= ysize
50
51     points2.reverse()
52     _draw_zap(can, points, points2, style, pat)
53
54 def zap_vertically(can, style, pat, x1, y1, x2, y2, xsize, ysize):
55     """Draw a vertical "zapping" symbol on the canvas that shows
56     that a graph is ripped in the middle.
57
58     Parameter <fill_style> specifies the style for the zig-zag lines.
59     PAT specifies the pattern with which the area is filled.
60     The symbol is drawn in the rectangle (<x1>, <y1>) - (<x2>, <y2>).
61     Each "zigzag" has the width <xsize>, height <ysize>."""
62     
63     points = []
64     points2 = []
65     x = x1
66     y = y1
67     while y < y2:
68         points.append((x, y))
69         points2.append((x + (x2-x1), y))
70         y += ysize
71         if x == x1:
72             x += xsize
73         else:
74             x -= xsize
75
76     points2.reverse()
77     _draw_zap(can, points, points2, style, pat)
78