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