Skip to content

Commit c14a2ed

Browse files
committed
Add all Pie trace parameters (fixes #157, fixes #16)
1 parent bd5c696 commit c14a2ed

9 files changed

Lines changed: 270 additions & 136 deletions

File tree

docs/2_5_pie-doughnut-charts.fsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ let doughnut1 =
6161
values,
6262
labels,
6363
Hole=0.3,
64-
Textinfo=labels
64+
TextLabels=labels
6565
)
6666

6767
(*** condition: ipynb ***)

src/Plotly.NET/ChartAPI/ChartDomain.fs

Lines changed: 121 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -20,73 +20,138 @@ module ChartDomain =
2020

2121
/// Shows how proportions of data, shown as pie-shaped pieces, contribute to the data.
2222
[<Extension>]
23-
static member Pie(values,
24-
[<Optional;DefaultParameterValue(null)>] ?Labels:seq<'IConvertible>,
25-
[<Optional;DefaultParameterValue(null)>] ?Name,
26-
[<Optional;DefaultParameterValue(null)>] ?Showlegend,
27-
[<Optional;DefaultParameterValue(null)>] ?Color,
28-
[<Optional;DefaultParameterValue(null)>] ?TextPosition,
29-
[<Optional;DefaultParameterValue(null)>] ?TextFont,
30-
[<Optional;DefaultParameterValue(null)>] ?Hoverinfo,
31-
[<Optional;DefaultParameterValue(null)>] ?Textinfo,
32-
[<Optional;DefaultParameterValue(null)>] ?Opacity) =
33-
TraceDomain.initPie (TraceDomainStyle.Pie(Values=values,?Labels=Labels,?Textinfo=Textinfo))
34-
|> TraceStyle.TraceInfo(?Name=Name,?Showlegend=Showlegend,?Opacity=Opacity,?Hoverinfo=Hoverinfo)
35-
|> TraceStyle.Marker(?Color=Color)
36-
|> TraceStyle.TextLabel(?Text=Labels,?Textposition=TextPosition,?Textfont=TextFont)
37-
|> GenericChart.ofTraceObject
38-
23+
static member Pie
24+
(
25+
values : seq<#IConvertible>,
26+
labels : seq<#IConvertible>,
27+
[<Optional;DefaultParameterValue(null)>] ?Name : string,
28+
[<Optional;DefaultParameterValue(null)>] ?TextLabels : seq<#IConvertible>,
29+
[<Optional;DefaultParameterValue(null)>] ?TextPosition : StyleParam.TextPosition,
30+
[<Optional;DefaultParameterValue(null)>] ?Direction : StyleParam.Direction,
31+
[<Optional;DefaultParameterValue(null)>] ?Pull : float,
32+
[<Optional;DefaultParameterValue(null)>] ?ShowLegend : bool,
33+
[<Optional;DefaultParameterValue(null)>] ?SectionColors : seq<Color>,
34+
[<Optional;DefaultParameterValue(null)>] ?Opacity : float,
35+
[<Optional;DefaultParameterValue(null)>] ?Sort : bool
36+
) =
37+
TraceDomain.initPie(
38+
TraceDomainStyle.Pie(
39+
Values = values,
40+
Labels = labels,
41+
?Name = Name,
42+
?Text = TextLabels,
43+
?TextPosition = TextPosition,
44+
?Direction = Direction,
45+
?Pull = Pull,
46+
?ShowLegend = ShowLegend,
47+
?Opacity = Opacity,
48+
?Sort = Sort
49+
)
50+
)
51+
|> TraceStyle.Marker(?Colors=SectionColors)
52+
|> TraceStyle.TextLabel(Text=(TextLabels |> Option.defaultValue labels),?Textposition=TextPosition)
53+
|> GenericChart.ofTraceObject
3954

4055
/// Shows how proportions of data, shown as pie-shaped pieces, contribute to the data.
4156
[<Extension>]
42-
static member Pie(data:seq<#IConvertible*#IConvertible>,
43-
[<Optional;DefaultParameterValue(null)>] ?Name,
44-
[<Optional;DefaultParameterValue(null)>] ?Showlegend,
45-
[<Optional;DefaultParameterValue(null)>] ?Color,
46-
[<Optional;DefaultParameterValue(null)>] ?TextPosition,
47-
[<Optional;DefaultParameterValue(null)>] ?TextFont,
48-
[<Optional;DefaultParameterValue(null)>] ?Hoverinfo,
49-
[<Optional;DefaultParameterValue(null)>] ?Textinfo,
50-
[<Optional;DefaultParameterValue(null)>] ?Opacity) =
51-
let values,labels = Seq.unzip data
52-
Chart.Pie(values,Labels=labels,?Name=Name,?Showlegend=Showlegend,?Color=Color,?TextPosition=TextPosition,?TextFont=TextFont,?Hoverinfo=Hoverinfo,?Textinfo=Textinfo,?Opacity=Opacity)
57+
static member Pie
58+
(
59+
valuesLabels:seq<#IConvertible*#IConvertible>,
60+
[<Optional;DefaultParameterValue(null)>] ?Name : string,
61+
[<Optional;DefaultParameterValue(null)>] ?TextLabels : seq<#IConvertible>,
62+
[<Optional;DefaultParameterValue(null)>] ?TextPosition : StyleParam.TextPosition,
63+
[<Optional;DefaultParameterValue(null)>] ?Direction : StyleParam.Direction,
64+
[<Optional;DefaultParameterValue(null)>] ?Pull : float,
65+
[<Optional;DefaultParameterValue(null)>] ?ShowLegend : bool,
66+
[<Optional;DefaultParameterValue(null)>] ?SectionColors : seq<Color>,
67+
[<Optional;DefaultParameterValue(null)>] ?Opacity : float,
68+
[<Optional;DefaultParameterValue(null)>] ?Sort : bool
69+
) =
70+
let values,labels = Seq.unzip valuesLabels
71+
Chart.Pie(
72+
values,
73+
labels,
74+
?Name = Name ,
75+
?TextLabels = TextLabels ,
76+
?TextPosition = TextPosition ,
77+
?Direction = Direction ,
78+
?Pull = Pull ,
79+
?ShowLegend = ShowLegend ,
80+
?SectionColors = SectionColors,
81+
?Opacity = Opacity ,
82+
?Sort = Sort
83+
)
5384

5485

5586
/// Shows how proportions of data, shown as pie-shaped pieces, contribute to the data as a whole.
5687
[<Extension>]
57-
static member Doughnut(values,
58-
[<Optional;DefaultParameterValue(null)>] ?Labels,
59-
[<Optional;DefaultParameterValue(null)>] ?Name,
60-
[<Optional;DefaultParameterValue(null)>] ?Showlegend,
61-
[<Optional;DefaultParameterValue(null)>] ?Color,
62-
[<Optional;DefaultParameterValue(null)>] ?Hole,
63-
[<Optional;DefaultParameterValue(null)>] ?TextPosition,
64-
[<Optional;DefaultParameterValue(null)>] ?TextFont,
65-
[<Optional;DefaultParameterValue(null)>] ?Hoverinfo,
66-
[<Optional;DefaultParameterValue(null)>] ?Textinfo,
67-
[<Optional;DefaultParameterValue(null)>] ?Opacity) =
68-
let hole' = if Hole.IsSome then Hole.Value else 0.4
69-
TraceDomain.initPie (TraceDomainStyle.Pie(Values=values,?Labels=Labels,?Textinfo=Textinfo,Hole=hole'))
70-
|> TraceStyle.TraceInfo(?Name=Name,?Showlegend=Showlegend,?Opacity=Opacity,?Hoverinfo=Hoverinfo)
71-
|> TraceStyle.Marker(?Color=Color)
72-
|> TraceStyle.TextLabel(?Text=Labels,?Textposition=TextPosition,?Textfont=TextFont)
73-
|> GenericChart.ofTraceObject
88+
static member Doughnut
89+
(
90+
values : seq<#IConvertible>,
91+
labels : seq<#IConvertible>,
92+
[<Optional;DefaultParameterValue(null)>] ?Hole : float,
93+
[<Optional;DefaultParameterValue(null)>] ?Name : string,
94+
[<Optional;DefaultParameterValue(null)>] ?TextLabels : seq<#IConvertible>,
95+
[<Optional;DefaultParameterValue(null)>] ?TextPosition : StyleParam.TextPosition,
96+
[<Optional;DefaultParameterValue(null)>] ?Direction : StyleParam.Direction,
97+
[<Optional;DefaultParameterValue(null)>] ?Pull : float,
98+
[<Optional;DefaultParameterValue(null)>] ?ShowLegend : bool,
99+
[<Optional;DefaultParameterValue(null)>] ?SectionColors : seq<Color>,
100+
[<Optional;DefaultParameterValue(null)>] ?Opacity : float,
101+
[<Optional;DefaultParameterValue(null)>] ?Sort : bool
102+
) =
103+
let hole' = Option.defaultValue 0.4 Hole
104+
TraceDomain.initPie(
105+
TraceDomainStyle.Pie(
106+
Values = values,
107+
Labels = labels,
108+
?Name = Name,
109+
?Text = TextLabels,
110+
?TextPosition = TextPosition,
111+
?Direction = Direction,
112+
?Pull = Pull,
113+
?ShowLegend = ShowLegend,
114+
?Opacity = Opacity,
115+
Hole = hole',
116+
?Sort = Sort
117+
)
118+
)
119+
|> TraceStyle.Marker(?Colors=SectionColors)
120+
|> TraceStyle.TextLabel(Text=(TextLabels |> Option.defaultValue labels),?Textposition=TextPosition)
121+
|> GenericChart.ofTraceObject
74122

75123

76124
/// Shows how proportions of data, shown as pie-shaped pieces, contribute to the data as a whole.
77125
[<Extension>]
78-
static member Doughnut(data:seq<#IConvertible*#IConvertible>,
79-
[<Optional;DefaultParameterValue(null)>] ?Name,
80-
[<Optional;DefaultParameterValue(null)>] ?Showlegend,
81-
[<Optional;DefaultParameterValue(null)>] ?Color,
82-
[<Optional;DefaultParameterValue(null)>] ?Hole,
83-
[<Optional;DefaultParameterValue(null)>] ?TextPosition,
84-
[<Optional;DefaultParameterValue(null)>] ?TextFont,
85-
[<Optional;DefaultParameterValue(null)>] ?Hoverinfo,
86-
[<Optional;DefaultParameterValue(null)>] ?Textinfo,
87-
[<Optional;DefaultParameterValue(null)>] ?Opacity) =
88-
let values,labels = Seq.unzip data
89-
Chart.Doughnut(values,Labels=labels,?Name=Name,?Showlegend=Showlegend,?Color=Color,?Hole=Hole,?TextPosition=TextPosition,?TextFont=TextFont,?Hoverinfo=Hoverinfo,?Textinfo=Textinfo,?Opacity=Opacity)
126+
static member Doughnut
127+
(
128+
valuesLabels:seq<#IConvertible*#IConvertible>,
129+
[<Optional;DefaultParameterValue(null)>] ?Hole : float,
130+
[<Optional;DefaultParameterValue(null)>] ?Name : string,
131+
[<Optional;DefaultParameterValue(null)>] ?TextLabels : seq<#IConvertible>,
132+
[<Optional;DefaultParameterValue(null)>] ?TextPosition : StyleParam.TextPosition,
133+
[<Optional;DefaultParameterValue(null)>] ?Direction : StyleParam.Direction,
134+
[<Optional;DefaultParameterValue(null)>] ?Pull : float,
135+
[<Optional;DefaultParameterValue(null)>] ?ShowLegend : bool,
136+
[<Optional;DefaultParameterValue(null)>] ?SectionColors : seq<Color>,
137+
[<Optional;DefaultParameterValue(null)>] ?Opacity : float,
138+
[<Optional;DefaultParameterValue(null)>] ?Sort : bool
139+
) =
140+
let values,labels = Seq.unzip valuesLabels
141+
Chart.Doughnut(
142+
values,
143+
labels,
144+
?Name = Name ,
145+
?TextLabels = TextLabels ,
146+
?TextPosition = TextPosition ,
147+
?Direction = Direction ,
148+
?Pull = Pull ,
149+
?ShowLegend = ShowLegend ,
150+
?SectionColors = SectionColors,
151+
?Opacity = Opacity ,
152+
?Hole = Hole ,
153+
?Sort = Sort
154+
)
90155

91156

92157

src/Plotly.NET/CommonAbstractions/StyleParams.fs

Lines changed: 38 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -962,6 +962,21 @@ module StyleParam =
962962
// #I#
963963
//--------------------------
964964

965+
966+
967+
[<RequireQualifiedAccess>]
968+
type InsideTextOrientation =
969+
| Horizontal | Radial | Tangential | Auto
970+
static member toString = function
971+
| Horizontal -> "horizontal"
972+
| Radial -> "radial"
973+
| Tangential -> "tangential"
974+
| Auto -> "auto"
975+
976+
static member convert = InsideTextOrientation.toString >> box
977+
override this.ToString() = this |> InsideTextOrientation.toString
978+
member this.Convert() = this |> InsideTextOrientation.convert
979+
965980
[<RequireQualifiedAccess>]
966981
type ImageFormat =
967982
| SVG | PNG | JPEG
@@ -1949,21 +1964,31 @@ module StyleParam =
19491964
override this.ToString() = this |> TransitionOrdering.toString
19501965
member this.Convert() = this |> TransitionOrdering.convert
19511966

1952-
/// Sets the positions of the `text` elements with respects to the (x,y) coordinates. (default: MiddleCenter)
1967+
/// Sets the positions of the `text` elements. Note that not all options work for every type of trace, e.g. Pie Charts only support "inside" | "outside" | "auto" | "none"
1968+
///
1969+
/// - Cartesian plots: Sets the positions of the `text` elements with respects to the (x,y) coordinates.
1970+
///
1971+
/// - Pie Charts and derivatives: Specifies the location of the text with respects to the sector.
1972+
19531973
[<RequireQualifiedAccess>]
19541974
type TextPosition =
1955-
| TopLeft | TopCenter | TopRight | MiddleLeft | MiddleCenter | MiddleRight | BottomLeft | BottomCenter | BottomRight | Auto
1956-
static member toString = function
1957-
| TopLeft -> "top left"
1958-
| TopCenter -> "top center"
1959-
| TopRight -> "top right"
1960-
| MiddleLeft -> "middle left"
1961-
| MiddleCenter -> "middle center"
1962-
| MiddleRight -> "middle right"
1963-
| BottomLeft -> "bottom left"
1964-
| BottomCenter -> "bottom center"
1965-
| BottomRight -> "bottom right"
1966-
| Auto -> "auto"
1975+
| TopLeft | TopCenter | TopRight | MiddleLeft | MiddleCenter | MiddleRight | BottomLeft | BottomCenter | BottomRight
1976+
| Auto | Inside | Outside | None
1977+
1978+
static member toString = function
1979+
| TopLeft -> "top left"
1980+
| TopCenter -> "top center"
1981+
| TopRight -> "top right"
1982+
| MiddleLeft -> "middle left"
1983+
| MiddleCenter -> "middle center"
1984+
| MiddleRight -> "middle right"
1985+
| BottomLeft -> "bottom left"
1986+
| BottomCenter -> "bottom center"
1987+
| BottomRight -> "bottom right"
1988+
| Auto -> "auto"
1989+
| Inside -> "inside"
1990+
| Outside -> "outside"
1991+
| None -> "none"
19671992

19681993
static member convert = TextPosition.toString >> box
19691994
override this.ToString() = this |> TextPosition.toString
@@ -1991,21 +2016,6 @@ module StyleParam =
19912016
static member toConcatString (o:seq<TextInfo>) =
19922017
o |> Seq.map TextInfo.toString |> String.concat "+"
19932018

1994-
/// Specifies the location of the `textinfo`.
1995-
[<RequireQualifiedAccess>]
1996-
type TextInfoPosition =
1997-
| Auto | Inside | Outside | None
1998-
1999-
static member toString = function
2000-
| Auto -> "auto"
2001-
| Inside -> "inside"
2002-
| Outside -> "outside"
2003-
| None -> "none"
2004-
2005-
static member convert = TextInfoPosition.toString >> box
2006-
override this.ToString() = this |> TextInfoPosition.toString
2007-
member this.Convert() = this |> TextInfoPosition.convert
2008-
20092019
/// Sets the tick mode for this axis. If "auto", the number of ticks is set via `nticks`. If "linear", the placement of the ticks is determined by a starting position `tick0` and a tick step `dtick` ("linear" is the default value if `tick0` and `dtick` are provided).
20102020
/// If "array", the placement of the ticks is set via `tickvals` and the tick text is `ticktext`. ("array" is the default value if `tickvals` is provided).
20112021
[<RequireQualifiedAccess>]

src/Plotly.NET/Playground.fsx

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,34 @@ open FSharpAux
147147

148148
open System
149149

150+
let doughnutChart =
151+
let values = [19; 26; 55;]
152+
let labels = ["Residential"; "Non-Residential"; "Utility"]
153+
Chart.Doughnut(
154+
values,
155+
labels,
156+
Hole=0.3,
157+
TextLabels=labels
158+
)
159+
|> Chart.show
160+
161+
Chart.Doughnut(
162+
values = [10; 15; 15; 30; 22],
163+
labels = ["some"; "random"; "slice"; "labels"; "bruh"],
164+
TextLabels = ["text"; "labels"; "are"; "different"; "thing"],
165+
TextPosition = StyleParam.TextPosition.Outside,
166+
Direction = StyleParam.Direction.CounterClockwise,
167+
Pull = 0.1,
168+
SectionColors = [
169+
Color.fromKeyword ColorKeyword.DarkCyan
170+
Color.fromKeyword ColorKeyword.DarkOrchid
171+
Color.fromKeyword ColorKeyword.DarkKhaki
172+
Color.fromKeyword ColorKeyword.DarkGoldenRod
173+
Color.fromKeyword ColorKeyword.Darkolivegreen
174+
],
175+
Sort = false
176+
)
177+
|> Chart.show
150178

151179
let tableColorDependentChart =
152180
let header2 = ["Identifier";"T0";"T1";"T2";"T3"]

src/Plotly.NET/Traces/ObjectAbstractions/Marker.fs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ type Marker () =
2121
[<Optional;DefaultParameterValue(null)>] ?Line,
2222
[<Optional;DefaultParameterValue(null)>] ?ColorBar,
2323
[<Optional;DefaultParameterValue(null)>] ?Colorscale,
24-
//[<Optional;DefaultParameterValue(null)>] ?Colors: seq<string>,
24+
[<Optional;DefaultParameterValue(null)>] ?Colors: seq<Color>,
2525
[<Optional;DefaultParameterValue(null)>] ?OutlierColor,
2626
[<Optional;DefaultParameterValue(null)>] ?Maxdisplayed,
2727
[<Optional;DefaultParameterValue(null)>] ?Sizeref,
@@ -75,7 +75,7 @@ type Marker () =
7575
[<Optional;DefaultParameterValue(null)>] ?Line: Line,
7676
[<Optional;DefaultParameterValue(null)>] ?ColorBar: ColorBar,
7777
[<Optional;DefaultParameterValue(null)>] ?Colorscale : StyleParam.Colorscale,
78-
//[<Optional;DefaultParameterValue(null)>] ?Colors: seq<string>,
78+
[<Optional;DefaultParameterValue(null)>] ?Colors: seq<Color>,
7979
[<Optional;DefaultParameterValue(null)>] ?OutlierColor:Color,
8080
[<Optional;DefaultParameterValue(null)>] ?Maxdisplayed: int,
8181
[<Optional;DefaultParameterValue(null)>] ?Sizeref: float,
@@ -98,7 +98,7 @@ type Marker () =
9898
Line |> DynObj.setValueOpt marker "line"
9999
ColorBar |> DynObj.setValueOpt marker "colorbar"
100100
Colorscale |> DynObj.setValueOptBy marker "colorscale" StyleParam.Colorscale.convert
101-
//Colors |> DynObj.setValueOpt marker "colors"
101+
Colors |> DynObj.setValueOpt marker "colors"
102102
OutlierColor |> DynObj.setValueOpt marker "outliercolor"
103103
Maxdisplayed |> DynObj.setValueOpt marker "maxdisplayed"
104104
Sizeref |> DynObj.setValueOpt marker "sizeref"

0 commit comments

Comments
 (0)