Skip to content

Commit b75cf59

Browse files
committed
Add Smith Chart API
1 parent 7a3ae6c commit b75cf59

File tree

3 files changed

+912
-10
lines changed

3 files changed

+912
-10
lines changed

src/Plotly.NET/ChartAPI/Chart.fs

Lines changed: 201 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1529,7 +1529,7 @@ type Chart =
15291529
ch |> Chart.withScene (scene, ?Id = Id))
15301530

15311531
/// <summary>
1532-
/// Sets the given Polar object with the given id on the input chart's layout.
1532+
/// Sets the given Smith object with the given id on the input chart's layout.
15331533
/// </summary>
15341534
/// <param name="polar">The Polar object to set on the chart's layout</param>
15351535
/// <param name="id">The target polar id with which the Polar object should be set.</param>
@@ -1723,6 +1723,180 @@ type Chart =
17231723

17241724
(fun (ch: GenericChart) -> ch |> Chart.setRadialAxis (radialAxis, id, true))
17251725

1726+
/// <summary>
1727+
/// Sets the given Smith object with the given id on the input chart's layout.
1728+
/// </summary>
1729+
/// <param name="smith">The Smith object to set on the chart's layout</param>
1730+
/// <param name="id">The target smith id with which the Smith object should be set.</param>
1731+
/// <param name="Combine">Wether or not to combine the objects if there is already an Smith set (default is false)</param>
1732+
[<CompiledName("SetSmith")>]
1733+
static member setSmith
1734+
(
1735+
smith: Smith,
1736+
id: StyleParam.SubPlotId,
1737+
[<Optional; DefaultParameterValue(null)>] ?Combine: bool
1738+
) =
1739+
1740+
let combine = defaultArg Combine false
1741+
1742+
(fun (ch: GenericChart) ->
1743+
if combine then
1744+
ch |> GenericChart.mapLayout (Layout.updateSmithById (id, smith))
1745+
else
1746+
ch |> GenericChart.mapLayout (Layout.setSmith (id, smith)))
1747+
1748+
/// <summary>
1749+
/// Sets the Smith for the chart's layout
1750+
///
1751+
/// If there is already a Smith set, the objects are combined.
1752+
/// </summary>
1753+
/// <param name="smith">The new Smith for the chart's layout</param>
1754+
/// <param name="Id">The target smith id on which the smith object should be set. Default is 1.</param>
1755+
[<CompiledName("WithSmith")>]
1756+
static member withSmith(smith: Smith, [<Optional; DefaultParameterValue(null)>] ?Id: int) =
1757+
let id =
1758+
Id |> Option.defaultValue 1 |> StyleParam.SubPlotId.Smith
1759+
1760+
(fun (ch: GenericChart) -> ch |> Chart.setSmith (smith, id, true))
1761+
1762+
/// <summary>
1763+
/// Sets the given Smith styles on the target Smith object on the input chart's layout.
1764+
///
1765+
/// If there is already a Smith set, the styles are applied to it. If there is no Smith present, a new Smith object with the given styles will be set.
1766+
/// </summary>
1767+
1768+
[<CompiledName("WithSmithStyle")>]
1769+
static member withSmithStyle
1770+
(
1771+
[<Optional; DefaultParameterValue(null)>] ?BGColor: Color,
1772+
[<Optional; DefaultParameterValue(null)>] ?Domain: Domain,
1773+
[<Optional; DefaultParameterValue(null)>] ?ImaginaryAxis: ImaginaryAxis,
1774+
[<Optional; DefaultParameterValue(null)>] ?RealAxis: RealAxis,
1775+
[<Optional; DefaultParameterValue(null)>] ?Id: int
1776+
) =
1777+
(fun (ch: GenericChart) ->
1778+
let smith =
1779+
Smith.init (?BGColor = BGColor, ?Domain = Domain, ?ImaginaryAxis = ImaginaryAxis, ?RealAxis = RealAxis)
1780+
1781+
ch |> Chart.withSmith (smith, ?Id = Id))
1782+
1783+
/// <summary>
1784+
/// Sets the imaginary Axis on the polar object with the given id on the input chart's layout.
1785+
/// </summary>
1786+
/// <param name="angularAxis">The ImaginaryAxis to set on the target polar object on the chart's layout</param>
1787+
/// <param name="id">The target polar id with which the ImaginaryAxis should be set.(default is 1)</param>
1788+
/// <param name="Combine">Wether or not to combine the objects if there is already an axis set (default is false)</param>
1789+
[<CompiledName("SetImaginaryAxis")>]
1790+
static member setImaginaryAxis
1791+
(
1792+
imaginaryAxis: ImaginaryAxis,
1793+
id: StyleParam.SubPlotId,
1794+
[<Optional; DefaultParameterValue(null)>] ?Combine: bool
1795+
) =
1796+
1797+
fun (ch: GenericChart) ->
1798+
1799+
let combine = defaultArg Combine false
1800+
1801+
match id with
1802+
| StyleParam.SubPlotId.Smith _ ->
1803+
1804+
ch
1805+
|> GenericChart.mapLayout
1806+
(fun layout ->
1807+
let smith = layout |> Layout.getSmithById id
1808+
1809+
if combine then
1810+
let currentAxis = smith |> Smith.getImaginaryAxis
1811+
1812+
let updatedAxis =
1813+
(DynObj.combine currentAxis imaginaryAxis) :?> ImaginaryAxis
1814+
1815+
let updatedSmith =
1816+
smith |> Smith.setImaginaryAxis updatedAxis
1817+
1818+
layout |> Layout.updateSmithById (id, updatedSmith)
1819+
1820+
else
1821+
let updatedSmith =
1822+
layout |> Layout.getSmithById id |> Smith.setImaginaryAxis imaginaryAxis
1823+
1824+
layout |> Layout.updateSmithById (id, updatedSmith))
1825+
1826+
| _ -> failwith $"{StyleParam.SubPlotId.toString id} is an invalid subplot id for setting an imaginary Axis"
1827+
1828+
/// <summary>
1829+
/// Sets the ImaginaryAxis on the smith object with the given id on the input chart's layout.
1830+
///
1831+
/// If there is already a ImaginaryAxis set on the smith object, the ImaginaryAxis objects are combined.
1832+
/// </summary>
1833+
/// <param name="imaginaryAxis">The new ImaginaryAxis for the chart layout's smith object</param>
1834+
/// <param name="Id">The target smith id on which the ImaginaryAxis should be set. Default is 1.</param>
1835+
[<CompiledName("WithImaginaryAxis")>]
1836+
static member withImaginaryAxis(imaginaryAxis: ImaginaryAxis, [<Optional; DefaultParameterValue(null)>] ?Id: int) =
1837+
let id =
1838+
Id |> Option.defaultValue 1 |> StyleParam.SubPlotId.Smith
1839+
1840+
(fun (ch: GenericChart) -> ch |> Chart.setImaginaryAxis (imaginaryAxis, id, true))
1841+
1842+
/// <summary>
1843+
/// Sets the RealAxis on the smith object with the given id on the input chart's layout.
1844+
/// </summary>
1845+
/// <param name="realAxis">The RealAxis to set on the target smith object on the chart's layout</param>
1846+
/// <param name="id">The target smith id with which the RealAxis should be set.(default is 1)</param>
1847+
/// <param name="Combine">Wether or not to combine the objects if there is already an axis set (default is false)</param>
1848+
[<CompiledName("SetRealAxis")>]
1849+
static member setRealAxis
1850+
(
1851+
realAxis: RealAxis,
1852+
id: StyleParam.SubPlotId,
1853+
[<Optional; DefaultParameterValue(null)>] ?Combine: bool
1854+
) =
1855+
1856+
fun (ch: GenericChart) ->
1857+
1858+
let combine = defaultArg Combine false
1859+
1860+
match id with
1861+
| StyleParam.SubPlotId.Smith _ ->
1862+
1863+
ch
1864+
|> GenericChart.mapLayout
1865+
(fun layout ->
1866+
let smith = layout |> Layout.getSmithById id
1867+
1868+
if combine then
1869+
let currentAxis = smith |> Smith.getRealAxis
1870+
1871+
let updatedAxis =
1872+
(DynObj.combine currentAxis realAxis) :?> RealAxis
1873+
1874+
let updatedSmith = smith |> Smith.setRealAxis updatedAxis
1875+
1876+
layout |> Layout.updateSmithById (id, updatedSmith)
1877+
1878+
else
1879+
let updatedSmith =
1880+
layout |> Layout.getSmithById id |> Smith.setRealAxis realAxis
1881+
1882+
layout |> Layout.updateSmithById (id, updatedSmith))
1883+
1884+
| _ -> failwith $"{StyleParam.SubPlotId.toString id} is an invalid subplot id for setting an real axis"
1885+
1886+
/// <summary>
1887+
/// Sets the RealAxis on the smith object with the given id on the input chart's layout.
1888+
///
1889+
/// If there is already a RealAxis set on the smith object, the RealAxis objects are combined.
1890+
/// </summary>
1891+
/// <param name="realAxis">The new RealAxis for the chart layout's smith object</param>
1892+
/// <param name="Id">The target smith id on which the RealAxis should be set. Default is 1.</param>
1893+
[<CompiledName("WithRealAxis")>]
1894+
static member withRealAxis(realAxis: RealAxis, [<Optional; DefaultParameterValue(null)>] ?Id: int) =
1895+
let id =
1896+
Id |> Option.defaultValue 1 |> StyleParam.SubPlotId.Smith
1897+
1898+
(fun (ch: GenericChart) -> ch |> Chart.setRealAxis (realAxis, id, true))
1899+
17261900
/// <summary>
17271901
/// Sets the given Geo object with the given id on the input chart's layout.
17281902
/// </summary>
@@ -2070,15 +2244,15 @@ type Chart =
20702244
ch
20712245
|> GenericChart.mapLayout
20722246
(fun layout ->
2073-
let polar = layout |> Layout.getTernaryById id
2247+
let ternary = layout |> Layout.getTernaryById id
20742248

20752249
if combine then
2076-
let currentAxis = polar |> Ternary.getAAxis
2250+
let currentAxis = ternary |> Ternary.getAAxis
20772251

20782252
let updatedAxis =
20792253
(DynObj.combine currentAxis aAxis) :?> LinearAxis
20802254

2081-
let updatedTernary = polar |> Ternary.setAAxis updatedAxis
2255+
let updatedTernary = ternary |> Ternary.setAAxis updatedAxis
20822256

20832257
layout |> Layout.updateTernaryById (id, updatedTernary)
20842258

@@ -2128,15 +2302,15 @@ type Chart =
21282302
ch
21292303
|> GenericChart.mapLayout
21302304
(fun layout ->
2131-
let polar = layout |> Layout.getTernaryById id
2305+
let ternary = layout |> Layout.getTernaryById id
21322306

21332307
if combine then
2134-
let currentAxis = polar |> Ternary.getBAxis
2308+
let currentAxis = ternary |> Ternary.getBAxis
21352309

21362310
let updatedAxis =
21372311
(DynObj.combine currentAxis bAxis) :?> LinearAxis
21382312

2139-
let updatedTernary = polar |> Ternary.setBAxis updatedAxis
2313+
let updatedTernary = ternary |> Ternary.setBAxis updatedAxis
21402314

21412315
layout |> Layout.updateTernaryById (id, updatedTernary)
21422316

@@ -2186,15 +2360,15 @@ type Chart =
21862360
ch
21872361
|> GenericChart.mapLayout
21882362
(fun layout ->
2189-
let polar = layout |> Layout.getTernaryById id
2363+
let ternary = layout |> Layout.getTernaryById id
21902364

21912365
if combine then
2192-
let currentAxis = polar |> Ternary.getCAxis
2366+
let currentAxis = ternary |> Ternary.getCAxis
21932367

21942368
let updatedAxis =
21952369
(DynObj.combine currentAxis cAxis) :?> LinearAxis
21962370

2197-
let updatedTernary = polar |> Ternary.setCAxis updatedAxis
2371+
let updatedTernary = ternary |> Ternary.setCAxis updatedAxis
21982372

21992373
layout |> Layout.updateTernaryById (id, updatedTernary)
22002374

@@ -2737,6 +2911,23 @@ type Chart =
27372911
|> GenericChart.mapTrace
27382912
(fun t -> t :?> TracePolar |> TracePolarStyle.SetPolar polarAnchor :> Trace)
27392913
|> Chart.withPolar (polar, (i + 1))
2914+
2915+
| TraceID.Smith ->
2916+
2917+
let smith =
2918+
layout.TryGetTypedValue<Smith> "smith"
2919+
|> Option.defaultValue (Smith.init ())
2920+
|> Smith.style (
2921+
Domain = LayoutObjects.Domain.init (Row = rowIndex - 1, Column = colIndex - 1)
2922+
)
2923+
2924+
let polarAnchor = StyleParam.SubPlotId.Smith(i + 1)
2925+
2926+
gChart
2927+
|> GenericChart.mapTrace
2928+
(fun t -> t :?> TraceSmith |> TraceSmithStyle.SetSmith polarAnchor :> Trace)
2929+
|> Chart.withSmith (smith, (i + 1))
2930+
27402931
| TraceID.Geo ->
27412932
let geo =
27422933
layout.TryGetTypedValue<Geo> "geo"

0 commit comments

Comments
 (0)