Skip to content

Commit 4be2a7c

Browse files
committed
Change toChartHTML to correctly set the size of the svg container when specified by Chart.withSize
1 parent 5c9c094 commit 4be2a7c

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

src/FSharp.Plotly/GenericChart.fs

+11-5
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ module GenericChart =
9494
let tryGetLayoutSize gChart =
9595
let layout = getLayout gChart
9696
let width,height =
97-
ReflectionHelper.tryGetPropertyValueAs<float> layout "width",
98-
ReflectionHelper.tryGetPropertyValueAs<float> layout "height"
97+
layout.TryGetTypedValue<float> "width",
98+
layout.TryGetTypedValue<float> "height"
9999
match (width,height) with
100100
|(Some w, Some h) -> Some (w,h)
101101
|_ -> None
@@ -141,7 +141,7 @@ module GenericChart =
141141

142142

143143

144-
/// Converts a GenericChart to it HTML representation
144+
/// Converts a GenericChart to it HTML representation. The div layer has a default size of 600 if not specified otherwise.
145145
let toChartHTML gChart =
146146
let guid = Guid.NewGuid().ToString()
147147
let tracesJson =
@@ -150,12 +150,18 @@ module GenericChart =
150150
let layoutJson =
151151
getLayout gChart
152152
|> JsonConvert.SerializeObject
153+
154+
let dims = tryGetLayoutSize gChart
155+
let width,height =
156+
match dims with
157+
|Some (w,h) -> w,h
158+
|None -> 600., 600.
153159

154160
let html =
155161
HTML.chart
156162
//.Replace("style=\"width: [WIDTH]px; height: [HEIGHT]px;\"","style=\"width: 600px; height: 600px;\"")
157-
.Replace("[WIDTH]", string 600 )
158-
.Replace("[HEIGHT]", string 600)
163+
.Replace("[WIDTH]", string width )
164+
.Replace("[HEIGHT]", string height)
159165
.Replace("[ID]", guid)
160166
.Replace("[DATA]", tracesJson)
161167
.Replace("[LAYOUT]", layoutJson)

0 commit comments

Comments
 (0)