Belle II Software development
svgprimitveplotter.py
1
8
9# For safety since we encountered a hanging process
10# when this file is executed with basf2
11from ROOT import Belle2 # make Belle2 namespace available
12
13import os
14
15
16from ROOT import gSystem
17
18gSystem.Load('libtracking_trackFindingCDC')
19
20
22AttributeMap = Belle2.TrackFindingCDC.PrimitivePlotter.AttributeMap
23
24plotter = Plotter()
25
26# Attach a style to a group
27# Gets inherited by all sub elements
28groupAttributes = AttributeMap()
29groupAttributes['stroke'] = 'black'
30groupAttributes['stroke-width'] = '5'
31
32# Start a group
33plotter.startGroup(groupAttributes)
34
35# Draw an arrow
36plotter.drawLine(0, 0, 100, 100)
37
38# Elements may also have attributes, which override the defaults from the group
39lineAttributes = AttributeMap()
40lineAttributes['stroke'] = 'green'
41
42# Draw a line with a styling
43plotter.drawLine(0, 100, 100, 0, lineAttributes)
44
45# Terminate the group
46plotter.endGroup()
47
48# Draw a circle arc
49startX = 10
50startY = 50
51
52endX = 85
53endY = 50
54
55radius = 40
56longArc = False
57sweepFlag = False
58
59arcAttributes = AttributeMap()
60arcAttributes["fill"] = "none"
61arcAttributes["stroke"] = "violet"
62arcAttributes["stroke-width"] = "5"
63
64plotter.drawCircleArc(startX, startY, endX, endY, radius, longArc, sweepFlag, arcAttributes)
65
66# Draw an arrow
67arrowAttributes = AttributeMap()
68arrowAttributes["stroke"] = "yellow"
69arrowAttributes["stroke-width"] = "5"
70
71plotter.drawArrow(50, 90, 50, 10, arrowAttributes)
72
73
74# Now test the animation behaviour.
75# Only changing the visibility from hidden
76# to visible is supported currently.
77# Therefore the special attribute _showAt
78# is used. In general attributes starting with
79# _ are not propagated to the svg but have
80# a special meaning
81
82# Draw a row of circles that pop up one after the other
83circleAttributes = AttributeMap()
84circleAttributes["stroke"] = "green"
85circleAttributes["stroke-width"] = "5"
86circleAttributes["fill"] = "white"
87circleAttributes["_showAt"] = "0s"
88
89y = 25
90r = 15
91
92for secs, x in enumerate((25, 40, 55, 70)):
93 circleAttributes["_showAt"] = str(secs) + "s"
94 plotter.drawCircle(x, y, r, circleAttributes)
95
96
97testFileName = "test.svg"
98
99plotter.save(testFileName)
100
101plotter.clear()
102
103# Output the lines as a test case
104with open(testFileName) as input_file:
105 for line in input_file:
106 print(line, end=' ')
107
108os.remove(testFileName)
A concrete plotter that can draw primitive objects to standalone SVG files.