Skip to content

Commit eccddd0

Browse files
committed
Add Chart.withTernary and fluid equivalent
1 parent 6512e2e commit eccddd0

File tree

4 files changed

+69
-1
lines changed

4 files changed

+69
-1
lines changed

src/Plotly.NET/CSharpLayer/GenericChartExtensions.fs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -659,3 +659,8 @@ module GenericChartExtensions =
659659
member this.WithScene(scene:Scene, [<Optional;DefaultParameterValue(null)>] ?Id) =
660660
this |> Chart.withScene(scene,?Id=Id)
661661

662+
/// Sets the scene object with the given id on the chart layout
663+
[<CompiledName("WithTernary")>]
664+
member this.WithTernary(ternary:Ternary, [<Optional;DefaultParameterValue(null)>] ?Id) =
665+
this |> Chart.withTernary(ternary,?Id=Id)
666+

src/Plotly.NET/ChartAPI/Chart.fs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1420,3 +1420,14 @@ type Chart =
14201420
|> Layout.updateSceneById(id,scene)
14211421
GenericChart.setLayout layout ch
14221422
)
1423+
1424+
/// Sets the scene with the given id on the chart layout
1425+
[<CompiledName("WithTernary")>]
1426+
static member withTernary(ternary:Ternary, [<Optional;DefaultParameterValue(null)>] ?Id) =
1427+
(fun (ch:GenericChart) ->
1428+
let layout =
1429+
let id = defaultArg Id (StyleParam.SubPlotId.Ternary 1)
1430+
GenericChart.getLayout ch
1431+
|> Layout.updateTernaryById(id,ternary)
1432+
GenericChart.setLayout layout ch
1433+
)

src/Plotly.NET/Layout/Layout.fs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,30 @@ type Layout() =
460460
layout
461461
)
462462

463+
static member tryGetTernaryById (id:StyleParam.SubPlotId) =
464+
(fun (layout:Layout) ->
465+
layout.TryGetTypedValue<Ternary>(StyleParam.SubPlotId.toString id)
466+
)
467+
468+
/// Updates the style of current polar object with given Id.
469+
/// If there does not exist a polar object with the given id, sets it with the given polar object
470+
static member updateTernaryById
471+
(
472+
id : StyleParam.SubPlotId,
473+
ternary : Ternary
474+
) =
475+
(fun (layout:Layout) ->
476+
477+
let ternary' =
478+
match layout |> Layout.tryGetTernaryById(id) with
479+
| Some a -> DynObj.combine (unbox a) ternary
480+
| None -> ternary :> DynamicObj
481+
482+
ternary' |> DynObj.setValue layout (StyleParam.SubPlotId.toString id)
483+
484+
layout
485+
)
486+
463487
static member SetLayoutGrid
464488
(
465489
grid: LayoutGrid

src/Plotly.NET/Playground.fsx

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@
5757
#load "RadialAxis.fs"
5858
#load "Polar.fs"
5959

60+
#I "Layout/ObjectAbstractions/Ternary"
61+
62+
#load "Ternary.fs"
63+
6064
#load "Layout/Layout.fs"
6165

6266
#I "Traces/ObjectAbstractions"
@@ -167,6 +171,13 @@ Chart.LineTernary(
167171
ShowMarkers = true,
168172
Dash = StyleParam.DrawingStyle.DashDot
169173
)
174+
|> Chart.withTernary(
175+
Ternary.init(
176+
AAxis = LinearAxis.init(Color = Color.fromKeyword ColorKeyword.DarkOrchid),
177+
BAxis = LinearAxis.init(Color = Color.fromKeyword ColorKeyword.DarkMagenta),
178+
CAxis = LinearAxis.init(Color = Color.fromKeyword ColorKeyword.DarkCyan)
179+
)
180+
)
170181
|> Chart.show
171182

172183
let doughnutChart =
@@ -407,6 +418,23 @@ let gridNew (nRows: int) (nCols: int) =
407418
|> TraceDomainStyle.SetDomain newDomain
408419
:> Trace
409420
)
421+
422+
| TraceIDLocal.Ternary ->
423+
424+
let ternary =
425+
layout.TryGetTypedValue<Ternary> "ternary" |> Option.defaultValue (Ternary.init())
426+
|> Ternary.style(Domain = Domain.init(Row = rowIndex - 1, Column = colIndex - 1))
427+
428+
let ternaryAnchor = StyleParam.SubPlotId.Ternary (i+1)
429+
430+
gChart
431+
|> GenericChart.mapTrace(fun t ->
432+
t
433+
:?> TraceTernary
434+
|> TraceTernaryStyle.SetTernary ternaryAnchor
435+
:> Trace
436+
)
437+
|> Chart.withTernary(ternary,ternaryAnchor)
410438
)
411439
|> Chart.combine
412440
|> Chart.withLayoutGrid (
@@ -458,7 +486,7 @@ gridNew 3 3 [
458486
]
459487
|> Chart.combine
460488
Chart.PointPolar([1,2])
461-
Chart.PointGeo([1,2])
489+
Chart.PointTernary([1,2,3])
462490
Chart.PointMapbox([1,2]) |> Chart.withMapbox(Mapbox.init(Style = StyleParam.MapboxStyle.OpenStreetMap))
463491
Chart.Sunburst(
464492
["A";"B";"C";"D";"E"],

0 commit comments

Comments
 (0)