Skip to content

Commit a7a45dd

Browse files
committed
Add Chart.withA/B/CAxis for ternary plots
1 parent eccddd0 commit a7a45dd

File tree

2 files changed

+67
-1
lines changed

2 files changed

+67
-1
lines changed

src/Plotly.NET/ChartAPI/Chart.fs

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1431,3 +1431,63 @@ type Chart =
14311431
|> Layout.updateTernaryById(id,ternary)
14321432
GenericChart.setLayout layout ch
14331433
)
1434+
1435+
/// Sets the A-Axis of the ternary coordinate system with the given id on the chart layout
1436+
[<CompiledName("WithAAxis")>]
1437+
static member withAAxis(aAxis:LinearAxis, [<Optional;DefaultParameterValue(null)>] ?Id) =
1438+
(fun (ch:GenericChart) ->
1439+
let id = defaultArg Id (StyleParam.SubPlotId.Ternary 1)
1440+
let layout = GenericChart.getLayout ch
1441+
1442+
let updatedTernary =
1443+
layout
1444+
|> Layout.tryGetTernaryById(id)
1445+
|> Option.defaultValue (Ternary.init())
1446+
|> Ternary.style(AAxis = aAxis)
1447+
1448+
let updatedLayout =
1449+
layout
1450+
|> Layout.updateTernaryById(id,updatedTernary)
1451+
1452+
GenericChart.setLayout updatedLayout ch
1453+
)
1454+
1455+
/// Sets the A-Axis of the ternary coordinate system with the given id on the chart layout
1456+
[<CompiledName("WithBAxis")>]
1457+
static member withBAxis(bAxis:LinearAxis, [<Optional;DefaultParameterValue(null)>] ?Id) =
1458+
(fun (ch:GenericChart) ->
1459+
let id = defaultArg Id (StyleParam.SubPlotId.Ternary 1)
1460+
let layout = GenericChart.getLayout ch
1461+
1462+
let updatedTernary =
1463+
layout
1464+
|> Layout.tryGetTernaryById(id)
1465+
|> Option.defaultValue (Ternary.init())
1466+
|> Ternary.style(BAxis = bAxis)
1467+
1468+
let updatedLayout =
1469+
layout
1470+
|> Layout.updateTernaryById(id,updatedTernary)
1471+
1472+
GenericChart.setLayout updatedLayout ch
1473+
)
1474+
1475+
/// Sets the A-Axis of the ternary coordinate system with the given id on the chart layout
1476+
[<CompiledName("WithCAxis")>]
1477+
static member withCAxis(cAxis:LinearAxis, [<Optional;DefaultParameterValue(null)>] ?Id) =
1478+
(fun (ch:GenericChart) ->
1479+
let id = defaultArg Id (StyleParam.SubPlotId.Ternary 1)
1480+
let layout = GenericChart.getLayout ch
1481+
1482+
let updatedTernary =
1483+
layout
1484+
|> Layout.tryGetTernaryById(id)
1485+
|> Option.defaultValue (Ternary.init())
1486+
|> Ternary.style(CAxis = cAxis)
1487+
1488+
let updatedLayout =
1489+
layout
1490+
|> Layout.updateTernaryById(id,updatedTernary)
1491+
1492+
GenericChart.setLayout updatedLayout ch
1493+
)

src/Plotly.NET/Playground.fsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,12 +174,18 @@ Chart.LineTernary(
174174
|> Chart.withTernary(
175175
Ternary.init(
176176
AAxis = LinearAxis.init(Color = Color.fromKeyword ColorKeyword.DarkOrchid),
177-
BAxis = LinearAxis.init(Color = Color.fromKeyword ColorKeyword.DarkMagenta),
177+
BAxis = LinearAxis.init(Color = Color.fromKeyword ColorKeyword.DarkRed),
178178
CAxis = LinearAxis.init(Color = Color.fromKeyword ColorKeyword.DarkCyan)
179179
)
180180
)
181181
|> Chart.show
182182

183+
Chart.PointTernary([1,2,3])
184+
|> Chart.withAAxis(LinearAxis.init(Title = Title.init("A"), Color = Color.fromKeyword ColorKeyword.DarkOrchid))
185+
|> Chart.withBAxis(LinearAxis.init(Title = Title.init("B"), Color = Color.fromKeyword ColorKeyword.DarkRed))
186+
|> Chart.withCAxis(LinearAxis.init(Title = Title.init("C"), Color = Color.fromKeyword ColorKeyword.DarkCyan))
187+
|> Chart.show
188+
183189
let doughnutChart =
184190
let values = [19; 26; 55;]
185191
let labels = ["Residential"; "Non-Residential"; "Utility"]

0 commit comments

Comments
 (0)