Skip to content

Commit fd81bb6

Browse files
committed
Add tryGetLayoutSize function to access the layout size of a GenericChart
1 parent 1768bfc commit fd81bb6

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/FSharp.Plotly/GenericChart.fs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ module GenericChart =
8282
| MultiChart (t,_) -> MultiChart (t,layout)
8383

8484

85-
8685
// Adds a Layout function to the GenericChart
8786
let addLayout layout gChart =
8887
match gChart with
@@ -91,6 +90,16 @@ module GenericChart =
9190
| MultiChart (traces,l') ->
9291
MultiChart (traces, (DynObj.combine l' layout |> unbox))
9392

93+
/// Returns a tuple containing the width and height of a GenericChart's layout if the property is set, otherwise returns None
94+
let tryGetLayoutSize gChart =
95+
let layout = getLayout gChart
96+
let width,height =
97+
ReflectionHelper.tryGetPropertyValueAs<float> layout "width",
98+
ReflectionHelper.tryGetPropertyValueAs<float> layout "height"
99+
match (width,height) with
100+
|(Some w, Some h) -> Some (w,h)
101+
|_ -> None
102+
94103
// // Adds multiple Layout functions to the GenericChart
95104
// let addLayouts layouts gChart =
96105
// match gChart with

0 commit comments

Comments
 (0)