Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add Chart.withA/B/CAxis for ternary plots
  • Loading branch information
kMutagene committed Sep 15, 2021
commit a7a45ddda82a85d5ebebb3c4f1f5644dbfc64683
60 changes: 60 additions & 0 deletions src/Plotly.NET/ChartAPI/Chart.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1431,3 +1431,63 @@ type Chart =
|> Layout.updateTernaryById(id,ternary)
GenericChart.setLayout layout ch
)

/// Sets the A-Axis of the ternary coordinate system with the given id on the chart layout
[<CompiledName("WithAAxis")>]
static member withAAxis(aAxis:LinearAxis, [<Optional;DefaultParameterValue(null)>] ?Id) =
(fun (ch:GenericChart) ->
let id = defaultArg Id (StyleParam.SubPlotId.Ternary 1)
let layout = GenericChart.getLayout ch

let updatedTernary =
layout
|> Layout.tryGetTernaryById(id)
|> Option.defaultValue (Ternary.init())
|> Ternary.style(AAxis = aAxis)

let updatedLayout =
layout
|> Layout.updateTernaryById(id,updatedTernary)

GenericChart.setLayout updatedLayout ch
)

/// Sets the A-Axis of the ternary coordinate system with the given id on the chart layout
[<CompiledName("WithBAxis")>]
static member withBAxis(bAxis:LinearAxis, [<Optional;DefaultParameterValue(null)>] ?Id) =
(fun (ch:GenericChart) ->
let id = defaultArg Id (StyleParam.SubPlotId.Ternary 1)
let layout = GenericChart.getLayout ch

let updatedTernary =
layout
|> Layout.tryGetTernaryById(id)
|> Option.defaultValue (Ternary.init())
|> Ternary.style(BAxis = bAxis)

let updatedLayout =
layout
|> Layout.updateTernaryById(id,updatedTernary)

GenericChart.setLayout updatedLayout ch
)

/// Sets the A-Axis of the ternary coordinate system with the given id on the chart layout
[<CompiledName("WithCAxis")>]
static member withCAxis(cAxis:LinearAxis, [<Optional;DefaultParameterValue(null)>] ?Id) =
(fun (ch:GenericChart) ->
let id = defaultArg Id (StyleParam.SubPlotId.Ternary 1)
let layout = GenericChart.getLayout ch

let updatedTernary =
layout
|> Layout.tryGetTernaryById(id)
|> Option.defaultValue (Ternary.init())
|> Ternary.style(CAxis = cAxis)

let updatedLayout =
layout
|> Layout.updateTernaryById(id,updatedTernary)

GenericChart.setLayout updatedLayout ch
)
8 changes: 7 additions & 1 deletion src/Plotly.NET/Playground.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -174,12 +174,18 @@ Chart.LineTernary(
|> Chart.withTernary(
Ternary.init(
AAxis = LinearAxis.init(Color = Color.fromKeyword ColorKeyword.DarkOrchid),
BAxis = LinearAxis.init(Color = Color.fromKeyword ColorKeyword.DarkMagenta),
BAxis = LinearAxis.init(Color = Color.fromKeyword ColorKeyword.DarkRed),
CAxis = LinearAxis.init(Color = Color.fromKeyword ColorKeyword.DarkCyan)
)
)
|> Chart.show

Chart.PointTernary([1,2,3])
|> Chart.withAAxis(LinearAxis.init(Title = Title.init("A"), Color = Color.fromKeyword ColorKeyword.DarkOrchid))
|> Chart.withBAxis(LinearAxis.init(Title = Title.init("B"), Color = Color.fromKeyword ColorKeyword.DarkRed))
|> Chart.withCAxis(LinearAxis.init(Title = Title.init("C"), Color = Color.fromKeyword ColorKeyword.DarkCyan))
|> Chart.show

let doughnutChart =
let values = [19; 26; 55;]
let labels = ["Residential"; "Non-Residential"; "Utility"]
Expand Down