@@ -13,6 +13,10 @@ module ChartExtensions =
1313 open Trace
1414 //open StyleParam
1515
16+ //open ChartExtensions
17+
18+ //open StyleParam
19+
1620 /// Provides a set of static methods for creating charts.
1721 type Chart with
1822
@@ -122,7 +126,7 @@ module ChartExtensions =
122126 let layout =
123127 let id = if Id.IsSome then StyleParam.AxisId.X Id.Value else StyleParam.AxisId.X 1
124128 GenericChart.getLayout ch
125- |> Layout.AddLinearAxis ( id, axis= xAxis)
129+ |> Layout.UpdateLinearAxisById ( id, axis= xAxis)
126130 GenericChart.setLayout layout ch
127131 | true ->
128132 let layout =
@@ -157,7 +161,7 @@ module ChartExtensions =
157161 let layout =
158162 let id = if Id.IsSome then StyleParam.AxisId.Y Id.Value else StyleParam.AxisId.Y 1
159163 GenericChart.getLayout ch
160- |> Layout.AddLinearAxis ( id, axis= yAxis)
164+ |> Layout.UpdateLinearAxisById ( id, axis= yAxis)
161165 GenericChart.setLayout layout ch
162166 | true ->
163167 let layout =
@@ -275,8 +279,7 @@ module ChartExtensions =
275279 let margin =
276280 Margin.init ( ?Left= Left,? Right= Right,? Top= Top,? Bottom= Bottom,? Pad= Pad,? Autoexpand= Autoexpand )
277281 Chart.withMargin( margin)
278-
279-
282+
280283
281284 // TODO: Include withLegend & withLegendStyle
282285
@@ -304,6 +307,70 @@ module ChartExtensions =
304307 static member Combine ( gCharts : seq < GenericChart >) =
305308 GenericChart.combine gCharts
306309
310+
311+ /// Create a combined chart with the given charts merged
312+ static member Stack (? ColCount : int , ? Space ) =
313+ ( fun ( charts : #seq <GenericChart> ) ->
314+
315+ let col = defaultArg ColCount 2
316+ let len = charts |> Seq.length
317+ let colWidth = 1. / float col
318+ let rowWidth =
319+ let tmp = float len / float col |> ceil
320+ 1. / tmp
321+ let space =
322+ let s = defaultArg Space 0.05
323+ if s < 0. || s > 1. then
324+ printfn " Space should be between 0.0 - 1.0. Automaticaly set to default (0.05)"
325+ 0.05
326+ else
327+ s
328+
329+ charts
330+ |> Seq.mapi ( fun i ch ->
331+ let colI , rowI , index = ( i% col+ 1 ), ( i/ col+ 1 ),( i+ 1 )
332+ let xdomain = ( colWidth * float ( colI-1 ), ( colWidth * float colI) - space )
333+ let ydomain = ( 1. - (( rowWidth * float rowI) - space ), 1. - ( rowWidth * float ( rowI-1 )))
334+ let xaxis , yaxis , layout =
335+ let layout = GenericChart.getLayout ch
336+ let xName , yName = StyleParam.AxisId.X 1 |> StyleParam.AxisId.toString, StyleParam.AxisId.Y 1 |> StyleParam.AxisId.toString
337+ match ( layout.TryGetTypedValue< Axis.LinearAxis> xName),( layout.TryGetTypedValue< Axis.LinearAxis> yName) with
338+ | Some x, Some y ->
339+ // remove axis
340+ DynObj.remove layout xName
341+ DynObj.remove layout yName
342+
343+ x |> Axis.LinearAxis.style( Anchor= StyleParam.AxisAnchorId.Y index, Domain= StyleParam.Range.MinMax xdomain),
344+ y |> Axis.LinearAxis.style( Anchor= StyleParam.AxisAnchorId.X index, Domain= StyleParam.Range.MinMax ydomain),
345+ layout
346+ | Some x, None ->
347+ // remove x - axis
348+ DynObj.remove layout xName
349+ x |> Axis.LinearAxis.style( Anchor= StyleParam.AxisAnchorId.Y index, Domain= StyleParam.Range.MinMax xdomain),
350+ Axis.LinearAxis.init( Anchor= StyleParam.AxisAnchorId.X index, Domain= StyleParam.Range.MinMax ydomain),
351+ layout
352+ | None, Some y ->
353+ // remove y - axis
354+ DynObj.remove layout yName
355+ Axis.LinearAxis.init( Anchor= StyleParam.AxisAnchorId.Y index, Domain= StyleParam.Range.MinMax xdomain),
356+ y |> Axis.LinearAxis.style( Anchor= StyleParam.AxisAnchorId.X index, Domain= StyleParam.Range.MinMax ydomain),
357+ layout
358+ | None, None ->
359+ Axis.LinearAxis.init( Anchor= StyleParam.AxisAnchorId.Y index, Domain= StyleParam.Range.MinMax xdomain),
360+ Axis.LinearAxis.init( Anchor= StyleParam.AxisAnchorId.X index, Domain= StyleParam.Range.MinMax ydomain),
361+ layout
362+
363+ ch
364+ |> GenericChart.setLayout layout
365+ |> Chart.withAxisAnchor( X= index, Y= index)
366+ |> Chart.withX_ Axis( xaxis, index)
367+ |> Chart.withY_ Axis( yaxis, index)
368+ )
369+
370+ |> Chart.Combine
371+ )
372+
373+
307374 /// Save chart as html single page
308375 static member SaveHtmlAs pathName ( ch : GenericChart ,? Verbose ) =
309376 let html = GenericChart.toEmbeddedHTML ch
0 commit comments