1 # In this example we create a calendar graph style. The style uses
2 # bar axes for both graph coordinates and it is a simple and minimal
3 # example in the sense that it does not make use of other styles
9 class daystyle(graph
.style
._style
):
11 def columnnames(self
, privatedata
, sharedata
, graph
, columnnames
):
12 # register the new column names
13 usecolumnnames
= ["day", "month", "weekday", "note"]
14 for columnname
in usecolumnnames
:
15 if columnname
not in columnnames
:
16 raise ValueError("column '%s' missing" % columnname
)
19 def adjustaxis(self
, privatedata
, sharedata
, graph
, columnname
, data
):
21 if columnname
== "month":
22 graph
.axes
["x"].adjustaxis([(x
, 0) for x
in data
])
23 graph
.axes
["x"].adjustaxis([(x
, 1) for x
in data
])
24 if columnname
== "day":
25 graph
.axes
["y"].adjustaxis([(x
, 0) for x
in data
])
26 graph
.axes
["y"].adjustaxis([(x
, 1) for x
in data
])
28 def drawpoint(self
, privatedata
, sharedata
, graph
, point
):
30 x1_pt
, y1_pt
= graph
.pos_pt((point
["month"], 0), (point
["day"], 0))
31 x2_pt
, y2_pt
= graph
.pos_pt((point
["month"], 1), (point
["day"], 1))
32 p
= path
.rect_pt(x1_pt
, y1_pt
, x2_pt
- x1_pt
, y2_pt
- y1_pt
)
33 if point
["weekday"] == calendar
.day_abbr
[-1]:
34 graph
.stroke(p
, [deco
.filled([color
.gray(0.8)])])
37 graph
.text_pt(x1_pt
+3, y2_pt
-3,
38 "%i %s" % (point
["day"], point
["weekday"]),
41 graph
.text_pt(x1_pt
+3, y1_pt
+3, point
["note"], [text
.size
.tiny
])
43 # create calendar data
45 notes
= {1: {17: r
"\PyX{} 0.2 (2003)", 20: r
"\PyX{} 0.5 (2004)", 22: r
"\PyX{} 0.5.1 (2004)"},
46 3: {30: r
"\PyX{} 0.6 (2003)", 31: r
"\PyX{} 0.3 ('03), \PyX{} 0.6.1 ('04)"},
47 4: {4: r
"\PyX{} 0.3.1 (2003)", 7: r
"\PyX{} 0.6.2 (2003)", 27: r
"\PyX{} 0.6.3 (2003)"},
48 7: {13: r
"\PyX{} 0.8 (2003)"},
49 8: {22: r
"\PyX{} 0.4 (2003)"},
50 9: {17: r
"\PyX{} 0.4.1 (2003)"},
51 10: {7: r
"\PyX{} 0.1 (2002)", 21: r
"\PyX{} 0.7 (2004)"},
52 12: {15: r
"\PyX{} 0.7.1 (2004)"}}
53 d
= graph
.data
.list([(d
,
54 calendar
.month_name
[m
],
55 calendar
.day_abbr
[calendar
.weekday(year
, m
, d
)],
56 notes
.get(m
, {}).get(d
))
58 for d
in range(1, calendar
.monthrange(year
, m
)[1]+1)],
59 day
=1, month
=2, weekday
=3, note
=4)
62 g
= graph
.graphxy(width
=40, x2
=graph
.axis
.bar(dist
=0, linkpainter
=None),
63 y
=graph
.axis
.bar(dist
=0, reverse
=1, painter
=None))
64 g
.plot(d
, [daystyle()])
66 # we could write the full calendar by
67 # g.writeEPSfile("cal", paperformat=document.paperformat.A3, rotated=1)
69 # instead we clip the result to show only a small part
70 clip
= canvas
.clip(g
.bbox().enlarged(0.1, bottom
=-17, right
=-25).path())
71 gc
= canvas
.canvas([clip
])
73 # and add some dots at the clipped parts
77 c
.text(gcbb
.right()+0.5, gcbb
.center()[1], r
"\dots")
78 c
.text(gcbb
.center()[0], gcbb
.bottom()-0.5, r
"\dots")