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