Skip to content

Commit baeb996

Browse files
committed
Add carpet trace/chart and respective axis constructors
1 parent c5f6fbb commit baeb996

7 files changed

Lines changed: 536 additions & 152 deletions

File tree

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
namespace Plotly.NET
2+
3+
open Plotly.NET.LayoutObjects
4+
open Plotly.NET.TraceObjects
5+
6+
open DynamicObj
7+
open System
8+
open System.IO
9+
10+
open GenericChart
11+
open StyleParam
12+
open System.Runtime.InteropServices
13+
open System.Runtime.CompilerServices
14+
15+
[<AutoOpen>]
16+
module ChartCarpet =
17+
18+
[<Extension>]
19+
type Chart =
20+
21+
/// Shows how proportions of data, shown as pie-shaped pieces, contribute to the data.
22+
[<Extension>]
23+
static member Carpet
24+
(
25+
carpetId: string,
26+
[<Optional;DefaultParameterValue(null)>] ?Name : string,
27+
[<Optional;DefaultParameterValue(null)>] ?ShowLegend : bool,
28+
[<Optional;DefaultParameterValue(null)>] ?Opacity : float,
29+
[<Optional;DefaultParameterValue(null)>] ?X : seq<#IConvertible>,
30+
[<Optional;DefaultParameterValue(null)>] ?MultiX : seq<#seq<#IConvertible>>,
31+
[<Optional;DefaultParameterValue(null)>] ?Y : seq<#IConvertible>,
32+
[<Optional;DefaultParameterValue(null)>] ?MultiY : seq<#seq<#IConvertible>>,
33+
[<Optional;DefaultParameterValue(null)>] ?A : seq<#IConvertible>,
34+
[<Optional;DefaultParameterValue(null)>] ?B : seq<#IConvertible>,
35+
[<Optional;DefaultParameterValue(null)>] ?AAxis : LinearAxis,
36+
[<Optional;DefaultParameterValue(null)>] ?BAxis : LinearAxis,
37+
[<Optional;DefaultParameterValue(null)>] ?XAxis : StyleParam.SubPlotId,
38+
[<Optional;DefaultParameterValue(null)>] ?YAxis : StyleParam.SubPlotId,
39+
[<Optional;DefaultParameterValue(null)>] ?Color : Color,
40+
[<Optional;DefaultParameterValue(null)>] ?CheaterSlope : float
41+
) =
42+
TraceCarpet.initCarpet(
43+
TraceCarpetStyle.Carpet(
44+
Carpet = StyleParam.SubPlotId.Carpet carpetId,
45+
?Name = Name ,
46+
?ShowLegend = ShowLegend ,
47+
?Opacity = Opacity ,
48+
?X = X ,
49+
?MultiX = MultiX ,
50+
?Y = Y ,
51+
?MultiY = MultiY ,
52+
?A = A ,
53+
?B = B ,
54+
?AAxis = AAxis ,
55+
?BAxis = BAxis ,
56+
?XAxis = XAxis ,
57+
?YAxis = YAxis ,
58+
?Color = Color ,
59+
?CheaterSlope = CheaterSlope
60+
)
61+
)
62+
|> GenericChart.ofTraceObject

src/Plotly.NET/CommonAbstractions/StyleParams.fs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ module StyleParam =
136136
| Polar of int
137137
| Ternary of int
138138
| Scene of int
139+
| Carpet of string
139140

140141
static member toString = function
141142
| XAxis id -> if id < 2 then "xaxis" else sprintf "xaxis%i" id
@@ -146,6 +147,7 @@ module StyleParam =
146147
| Polar id -> if id < 2 then "polar" else sprintf "polar%i" id
147148
| Ternary id -> if id < 2 then "ternary" else sprintf "ternary%i" id
148149
| Scene id -> if id < 2 then "scene" else sprintf "scene%i" id
150+
| Carpet id -> id
149151

150152
static member convert = SubPlotId.toString >> box
151153
override this.ToString() = this |> SubPlotId.toString
@@ -315,6 +317,19 @@ module StyleParam =
315317
//--------------------------
316318

317319

320+
[<RequireQualifiedAccess>]
321+
type CheaterType =
322+
| Index
323+
| Value
324+
325+
static member toString = function
326+
| Index -> "index"
327+
| Value -> "value"
328+
329+
static member convert = CheaterType.toString >> box
330+
override this.ToString() = this |> CheaterType.toString
331+
member this.Convert() = this |> CheaterType.convert
332+
318333
[<RequireQualifiedAccess>]
319334
type ColorModel =
320335
| RGB

src/Plotly.NET/InternalUtils.fs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,16 @@ module internal InternalUtils
1717
multi |> DynObj.setValueOptBy dyn propName (Seq.map f)
1818
else
1919
single |> DynObj.setValueOptBy dyn propName f
20+
21+
let setSingleOrAnyOpt (dyn:#DynamicObj) (propName:string) (single:'A option, any:'B option) =
22+
if any.IsSome then
23+
any |> DynObj.setValueOpt dyn propName
24+
else
25+
single |> DynObj.setValueOpt dyn propName
26+
27+
let setSingleOrAnyOptBy (dyn:#DynamicObj) (propName:string) (singleF:'A -> 'C) (anyF:'B -> 'D) (single:'A option, any:'B option) =
28+
if any.IsSome then
29+
any |> DynObj.setValueOptBy dyn propName anyF
30+
else
31+
single |> DynObj.setValueOptBy dyn propName singleF
32+

0 commit comments

Comments
 (0)