11global model
2+ global Data
23
3- sql = model .SqlContent ('BudgetSummary' ).replace ('@p1' , '1' )
4+ y = Data .p1 or '1'
5+
6+ sql = model .SqlContent ('BudgetSummary' ).replace ('@p1' , y )
47d = model .SqlListDynamicData (sql )
58
69def formatMoney (num ):
@@ -13,8 +16,8 @@ def formatMoney(num):
1316
1417labelPositions = [[]]
1518def determineLine (x ):
16- margin = 80
17-
19+ margin = 85
20+
1821 line = 1
1922 while True :
2023 c = False
@@ -23,7 +26,7 @@ def determineLine(x):
2326 for lp in labelPositions [line ]:
2427 if lp is None :
2528 continue
26-
29+
2730 if lp > x - margin and lp < x + margin :
2831 line += 1
2932 c = True
@@ -38,12 +41,12 @@ def getMarkedLabel(x, y, label1, label2, textColor="#000", lineStyle="stroke:#99
3841 line = determineLine (x )
3942 yBase = y + 10 # top of bar
4043 y += line * 50 + 10 # top of the indicator (for line 1, bottom of the bar).
41-
44+
4245 yTop = yBase - (10 if extendTop else 0 )
4346 r = "<line x1=\" {0}\" y1=\" {2}\" x2=\" {0}\" y2=\" {3}\" style=\" {1}\" />" .format (x , lineStyle , yTop , yBase + 50 )
44-
47+
4548 r += "<line x1=\" {0}\" y1=\" {2}\" x2=\" {0}\" y2=\" {3}\" style=\" {1}\" />" .format (x , lineStyle , y , y + 10 )
46-
49+
4750 r += "<text x=\" {0}\" y=\" {1}\" fill=\" {2}\" style=\" text-anchor: middle\" font-family=\" Lato, sans-serif\" >" .format (x , y + 25 , textColor )
4851 r += "<tspan x=\" {0}\" dy=\" 0\" >{1}</tspan>" .format (x , label1 )
4952 r += "<tspan x=\" {0}\" dy=\" 15\" >{1}</tspan>" .format (x , label2 )
@@ -57,43 +60,45 @@ def getMarkedLabel(x, y, label1, label2, textColor="#000", lineStyle="stroke:#99
5760for f in d :
5861 if f ['Budget FY' ] is not None and f ['Budget FY' ] > maxBudget :
5962 maxBudget = f ['Budget FY' ]
60-
63+ if f ["Giving YTD" ] is not None and f ["Giving YTD" ] > maxBudget :
64+ maxBudget = f ["Giving YTD" ]
65+
6166yCum = 0
6267
6368for f in d :
6469 givingPos = 100 + (500 * f ["Giving YTD" ] / maxBudget )
6570 budgetPos = 100 + (500 * f ["Budget YTD" ] / maxBudget ) if f ["Budget YTD" ] is not None else None
6671 prevPos = 100 + (500 * f ["Giving PYTD" ] / maxBudget ) if f ["Giving PYTD" ] is not None else None
6772 barWidth = (500 * f ["Budget FY" ] / maxBudget ) if f ["Budget FY" ] is not None else None
68-
73+
6974 chart += "<!-- {} -->" .format (f ['Fund' ])
70-
75+
7176 # fund label
7277 # chart += "<text x=\"{0}\" y=\"{1}\" fill=\"#000\">".format(3, yCum+35)
7378 # chart += "<tspan x=\"{0}\" dy=\"0\">{1}</tspan>".format(3, f['Fund'])
7479 # chart += "</text>"
75-
80+
7681 # base bar
7782 if barWidth is not None :
7883 chart += """<rect width="{0}" height="50" x="100" y="{1}" style="fill:#ccc;" />""" .format (barWidth , yCum + 10 )
79-
84+
8085 # giving bar
8186 chart += """<rect width="{0}" height="50" x="100" y="{1}" style="fill:#49917b;" />""" .format (givingPos - 100 , yCum + 10 )
82-
87+
8388 chart += getMarkedLabel (givingPos , yCum , "Giving YTD" , formatMoney (f ["Giving YTD" ]))
84-
85- if f ["Budget YTD" ] is not None and f ["Budget FY" ] is not None and f ["Budget YTD" ] / f ["Budget FY" ] < 10.0 / 12 :
89+
90+ if f ["Budget YTD" ] is not None and f ["Budget FY" ] is not None and f ["Budget YTD" ] / f ["Budget FY" ] < 11.2 / 12 :
8691 chart += getMarkedLabel (budgetPos , yCum , "Budget YTD" , formatMoney (f ["Budget YTD" ]), "#000" , "stroke:#000;stroke-width:3" , True )
87-
92+
8893 if f ["Budget FY" ] is not None :
8994 chart += getMarkedLabel (barWidth + 100 , yCum , "Budget FY" , formatMoney (f ["Budget FY" ]))
90-
95+
9196 chart += getMarkedLabel (prevPos , yCum , "Giving Last Year" , formatMoney (f ["Giving PYTD" ]), "#999" )
92-
97+
9398 height = len (labelPositions ) * 50 + 10
9499 yCum += height
95100 labelPositions = [None ]
96-
101+
97102 break
98103
99104print ("""<?xml version="1.0" encoding="UTF-8" standalone="no"?>
0 commit comments