Skip to content

Commit af1c965

Browse files
committed
commit to your mistakes
1 parent b37a4ac commit af1c965

File tree

5 files changed

+123
-52
lines changed

5 files changed

+123
-52
lines changed

src/powerbpy/button.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@ def __init__(self,
2929
url_link = None,
3030
page_navigation_link = None,
3131
parent_group_id = None,
32-
alt_text = "A button",
33-
background_color = None,
34-
background_color_alpha= None
32+
alt_text = "A button"
3533
):
3634

3735
'''Add a button to a page

src/powerbpy/page.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -298,12 +298,10 @@ def add_button(self,
298298
z_position = 6000,
299299
tab_order=-1001,
300300
fill_color="#3086C3",
301-
fill_color_alpha=0,
301+
fill_color_alpha=100,
302302
url_link = None,
303303
page_navigation_link = None,
304304
alt_text="A button",
305-
background_color = None,
306-
background_color_alpha=None,
307305
parent_group_id=None):
308306

309307
'''Add a button to a page
@@ -360,8 +358,6 @@ def add_button(self,
360358
url_link = url_link,
361359
page_navigation_link = page_navigation_link,
362360
alt_text=alt_text,
363-
background_color=background_color,
364-
background_color_alpha=background_color_alpha,
365361
parent_group_id=parent_group_id)
366362

367363
self.visuals.append(button)
@@ -819,6 +815,8 @@ def add_shape(self,
819815
shape_rotation_angle=0,
820816
#background_color="#FFFFFF",
821817
# background_color_alpha=None,
818+
border_width=1,
819+
border_color="#2323ba",
822820
fill_color="#4A90E2",
823821
fill_color_alpha=None,
824822
tab_order = -1001,
@@ -841,6 +839,8 @@ def add_shape(self,
841839
parent_group_id=parent_group_id,
842840
#background_color=background_color,
843841
#background_color_alpha=background_color_alpha,
842+
border_color=border_color,
843+
border_width=border_width,
844844
fill_color=fill_color,
845845
fill_color_alpha=fill_color_alpha,
846846
tab_order = tab_order,

src/powerbpy/shape.py

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ def __init__(self,
2626
fill_color_alpha,
2727
#background_color,
2828
#background_color_alpha,
29+
border_color,
30+
border_width,
2931
tab_order,
3032
z_position,
3133
shape_rotation_angle=0,
@@ -35,31 +37,34 @@ def __init__(self,
3537
3638
Parameters
3739
----------
40+
visual_id: str
41+
Please choose a unique id to use to identify the shape. PBI defaults to using a UUID, but it'd probably be easier if you choose your own id.
3842
shape_type : str
39-
The type of shape you want to put on the page. For example an arrow would be "arrow"
43+
The type of shape you want to put on the page. For example an arrow would be "arrow".
4044
shape_rotation_angle : str
4145
The angle that you want to rotate the shape by. Defaults to 0, or no rotation.
4246
fill_color : str
4347
The hex code of the color that you want to use to fill the shape.
4448
fill_color_alpha : int
4549
The transparency of the fill color. Must be a whole integer between 1 and 100. Defaults to 0, (100% not transparent).
50+
border_width : int
51+
border_color : str
4652
alt_text : str
4753
Alternate text for the visualization can be provided as an argument. This is important for screen readers (accesibility) or if the visualization doesn't load properly.
48-
chart_title_font_size: int
49-
Font size for chart title
5054
x_position : int
51-
The x coordinate of where you want to put the chart on the page. Origin is page's top left corner.
55+
The x coordinate of where you want to put the shape on the page. Origin is page's top left corner.
5256
y_position : int
53-
The y coordinate of where you want to put the chart on the page. Origin is page's top left corner.
57+
The y coordinate of where you want to put the shape on the page. Origin is page's top left corner.
5458
height : int
55-
Height of chart on the page
59+
Height of shape on the page
5660
width : int
57-
Width of chart on the page
61+
Width of shape on the page
5862
tab_order : int
5963
The order which the screen reader reads different elements on the page. Defaults to -1001 for now. (I need to do more to figure out what the numbers correpond to. It should also be possible to create a function to automatically order this left to right top to bottom by looping through all the visuals on a page and comparing their x and y positions)
6064
z_position : int
61-
The z index for the visual. (Larger number means more to the front, smaller number means more to the back). Defaults to 6000
62-
65+
The z index for the visual. (Larger number means more to the front, smaller number means more to the back). Defaults to 6000.
66+
parent_group_id : str
67+
This should be a valid id code for another Power BI visual. If supplied the current visual will be nested inside the parent group.
6368
'''
6469

6570
self.page = page
@@ -73,7 +78,8 @@ def __init__(self,
7378
y_position=y_position,
7479
fill_color=fill_color,
7580
fill_color_alpha=fill_color_alpha,
76-
81+
border_color=border_color,
82+
border_width=border_width,
7783
z_position=z_position,
7884
tab_order=tab_order,
7985
parent_group_id=parent_group_id,
@@ -119,6 +125,7 @@ def __init__(self,
119125

120126
]
121127

128+
122129
# Write out the new json
123130
with open(self.visual_json_path, "w", encoding="utf-8") as file:
124131
json.dump(self.visual_json, file, indent = 2)

src/powerbpy/table.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ def __init__(self,
3636
'''This function adds a new table to a page in a power BI dashboard report.
3737
Parameters
3838
----------
39-
4039
visual_id: str
4140
Please choose a unique id to use to identify the table. PBI defaults to using a UUID, but it'd probably be easier if you choose your own id.
4241
data_source: str

src/powerbpy/visual.py

Lines changed: 100 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ def __init__(self,
3030
background_color=None,
3131
background_color_alpha=None,
3232
fill_color=None,
33-
fill_color_alpha=None
33+
fill_color_alpha=None,
34+
border_width=None,
35+
border_color=None
3436
):
3537

3638
#from powerbpy.page import _Page
@@ -56,6 +58,8 @@ def __init__(self,
5658
self.background_color_alpha = background_color_alpha
5759
self.fill_color = fill_color
5860
self.fill_color_alpha = fill_color_alpha
61+
self.border_width = border_width
62+
self.border_color = border_color
5963

6064
# Define generic properties
6165
self.powerbi_schema = "https://developer.microsoft.com/json-schemas/fabric/item/report/definition/visualContainer/1.3.0/schema.json"
@@ -112,6 +116,18 @@ def __init__(self,
112116
}
113117
},
114118

119+
"fillColor": {
120+
"solid": {
121+
"color": {
122+
"expr": {
123+
"Literal": {
124+
"Value": f"'#3086C3'"
125+
}
126+
}
127+
}
128+
}
129+
},
130+
115131
"transparency": {
116132
"expr": {
117133
"Literal": {
@@ -121,7 +137,45 @@ def __init__(self,
121137
}
122138
}
123139
}
124-
]},
140+
],
141+
"outline": [
142+
{
143+
"properties": {
144+
145+
"show": {
146+
"expr": {
147+
"Literal": {
148+
"Value": "false"
149+
}
150+
}
151+
},
152+
"weight": {
153+
"expr": {
154+
"Literal": {
155+
"Value": "1D"
156+
}
157+
}
158+
},
159+
160+
"lineColor": {
161+
"solid": {
162+
"color": {
163+
"expr": {
164+
165+
"Literal": {
166+
"Value": f"'#2323ba'"
167+
}
168+
169+
}
170+
}
171+
}
172+
}
173+
}
174+
} ]
175+
176+
177+
178+
},
125179

126180
"visualContainerObjects": {
127181
"general": [
@@ -218,7 +272,7 @@ def __init__(self,
218272
"color": {
219273
"expr": {
220274
"Literal": {
221-
"Value": f"'{self.background_color}'"
275+
"Value": f"'#3086C3'"
222276
}
223277
}
224278
}
@@ -242,44 +296,57 @@ def __init__(self,
242296

243297
# add a fill color if the user provided one
244298
if self.fill_color is not None:
245-
self.visual_json["visual"]["objects"]["fill"].append( {
246-
"properties": {
247-
"show": {
248-
"expr": {
249-
"Literal": {
250-
"Value": "true"
251-
}
252-
}
253-
}
254-
}
255-
})
256-
257-
self.visual_json["visual"]["objects"]["fill"].append( {
258-
"properties": {
259-
"fillColor": {
260-
"solid": {
261-
"color": {
262-
"expr": {
263-
"Literal": {
264-
"Value": f"'{self.fill_color}'"
265-
}
266-
}
267-
}
268-
}
269-
}
270-
},
271-
"selector": {
272-
"id": "default"
273-
}
299+
for obj in self.visual_json["visual"]["objects"]["fill"]:
300+
if "show" in obj.get("properties"):
301+
obj["properties"]["show"]["expr"]["Literal"]["Value"] = "true"
274302

303+
if "fillColor" in obj.get("properties"):
304+
obj["properties"]["fillColor"]["solid"]["color"]["expr"]["Literal"]["Value"] = f"'{self.fill_color}'"
275305

276-
})
277306

278307
if self.fill_color_alpha is not None:
279308
for bg_obj in self.visual_json["visual"]["objects"]["fill"]:
309+
310+
if "show" in obj.get("properties"):
311+
obj["properties"]["show"]["expr"]["Literal"]["Value"] = "true"
312+
280313
if "transparency" in bg_obj.get("properties", {}):
281314
bg_obj["properties"]["transparency"]["expr"]["Literal"]["Value"] = f"{fill_color_alpha}D"
282315

316+
317+
318+
319+
# Border width
320+
if self.border_width is not None:
321+
for obj in self.visual_json["visual"]["objects"]["outline"]:
322+
323+
# turn the border on
324+
if "show" in obj.get("properties", {}):
325+
obj["properties"]["show"]["expr"]["Literal"]["Value"] = "true"
326+
327+
# change width from default
328+
if "weight" in obj.get("properties", {}):
329+
obj["properties"]["weight"]["expr"]["Literal"]["Value"] = f"{self.border_width}D"
330+
331+
# border color
332+
if self.border_color is not None:
333+
for obj in self.visual_json["visual"]["objects"]["outline"]:
334+
335+
# turn the border on
336+
if "show" in obj.get("properties", {}):
337+
obj["properties"]["show"]["expr"]["Literal"]["Value"] = "true"
338+
339+
# change width from default
340+
if "lineColor" in obj.get("properties", {}):
341+
obj["properties"]["lineColor"]["solid"]["color"]["expr"]["Literal"]["Value"] = f"'{self.border_color}'"
342+
343+
344+
345+
346+
347+
348+
349+
283350
# add the parent group id if the user supplies one
284351
if self.parent_group_id is not None:
285352
self.visual_json["parentGroupName"] = self.parent_group_id

0 commit comments

Comments
 (0)