Skip to content

Commit 266facf

Browse files
authored
Merge pull request #85 from Joott/FunnelArea
Add FunnelArea chart
2 parents ad4f4d5 + aae24a7 commit 266facf

File tree

3 files changed

+155
-3
lines changed

3 files changed

+155
-3
lines changed

Diff for: src/Plotly.NET/Chart.fs

+84-1
Original file line numberDiff line numberDiff line change
@@ -1995,7 +1995,7 @@ type Chart =
19951995
|> GenericChart.ofTraceObject
19961996

19971997
/// Creates a Funnel chart.
1998-
/// Funnel charts Visualize stages in a process using length-encoded bars. This trace can be used to show data in either a part-to-whole representation wherein each item appears in a single stage, or in a "drop-off" representation wherein each item appears in each stage it traversed. See also the "funnelarea" trace type for a different approach to visualizing funnel data.
1998+
/// Funnel charts visualize stages in a process using length-encoded bars. This trace can be used to show data in either a part-to-whole representation wherein each item appears in a single stage, or in a "drop-off" representation wherein each item appears in each stage it traversed. See also the "funnelarea" trace type for a different approach to visualizing funnel data.
19991999
///
20002000
/// Parameters:
20012001
///
@@ -2092,6 +2092,89 @@ type Chart =
20922092
|> TraceStyle.TextLabel(?Text=Labels,?Textposition=TextPosition,?Textfont=TextFont)
20932093
|> GenericChart.ofTraceObject
20942094

2095+
/// Creates a FunnelArea chart.
2096+
/// FunnelArea charts visualize stages in a process using area-encoded trapezoids. This trace can be used to show data in a part-to-whole representation similar to a "pie" trace, wherein each item appears in a single stage. See also the "funnel" trace type for a different approach to visualizing funnel data.
2097+
///
2098+
/// Parameters:
2099+
///
2100+
/// Values : Sets the values of the sectors. If omitted, we count occurrences of each label.
2101+
///
2102+
/// Labels : Sets the sector labels. If `labels` entries are duplicated, we sum associated `values` or simply count occurrences if `values` is not provided. For other array attributes (including color) we use the first non-empty entry among all occurrences of the label.
2103+
///
2104+
/// dLabel : Sets the label step. See `label0` for more info.
2105+
///
2106+
/// Label0 : Alternate to `labels`. Builds a numeric set of labels. Use with `dlabel` where `label0` is the starting label and `dlabel` the step.
2107+
///
2108+
/// Name : Sets the trace name. The trace name appear as the legend item and on hover.
2109+
///
2110+
/// Showlegend : Determines whether or not an item corresponding to this trace is shown in the legend.
2111+
///
2112+
/// Opacity : Sets the opacity of the trace.
2113+
///
2114+
/// Color : Sets Marker Color
2115+
///
2116+
/// Line : Line type
2117+
///
2118+
/// Text : Sets text elements associated with each sector. If trace `textinfo` contains a "text" flag, these elements will be seen on the chart. If trace `hoverinfo` contains a "text" flag and "hovertext" is not set, these elements will be seen in the hover labels.
2119+
///
2120+
/// TextPosition : Specifies the location of the `textinfo`.
2121+
///
2122+
/// X : Sets the horizontal domain of this funnelarea trace (in plot fraction).
2123+
///
2124+
/// Y : Sets the vertical domain of this funnelarea trace (in plot fraction).
2125+
///
2126+
/// Row : If there is a layout grid, use the domain for this row in the grid for this funnelarea trace .
2127+
///
2128+
/// Column : If there is a layout grid, use the domain for this column in the grid for this funnelarea trace .
2129+
///
2130+
/// Aspectratio : Sets the ratio between height and width
2131+
///
2132+
/// Baseratio : Sets the ratio between bottom length and maximum top length.
2133+
///
2134+
/// Insidetextfont: Sets the font used for `textinfo` lying inside the sector.
2135+
///
2136+
/// Scalegroup : If there are multiple funnelareas that should be sized according to their totals, link them by providing a non-empty group id here shared by every trace in the same group.
2137+
static member FunnelArea
2138+
(
2139+
[<Optional;DefaultParameterValue(null)>] ?Values ,
2140+
[<Optional;DefaultParameterValue(null)>] ?Labels ,
2141+
[<Optional;DefaultParameterValue(null)>] ?dLabel ,
2142+
[<Optional;DefaultParameterValue(null)>] ?Label0 ,
2143+
[<Optional;DefaultParameterValue(null)>] ?Name ,
2144+
[<Optional;DefaultParameterValue(null)>] ?Showlegend ,
2145+
[<Optional;DefaultParameterValue(null)>] ?Opacity ,
2146+
[<Optional;DefaultParameterValue(null)>] ?Color ,
2147+
[<Optional;DefaultParameterValue(null)>] ?Line ,
2148+
[<Optional;DefaultParameterValue(null)>] ?Text ,
2149+
[<Optional;DefaultParameterValue(null)>] ?TextPosition ,
2150+
[<Optional;DefaultParameterValue(null)>] ?X ,
2151+
[<Optional;DefaultParameterValue(null)>] ?Y ,
2152+
[<Optional;DefaultParameterValue(null)>] ?Row ,
2153+
[<Optional;DefaultParameterValue(null)>] ?Column ,
2154+
[<Optional;DefaultParameterValue(null)>] ?Aspectratio ,
2155+
[<Optional;DefaultParameterValue(null)>] ?Baseratio ,
2156+
[<Optional;DefaultParameterValue(null)>] ?Insidetextfont,
2157+
[<Optional;DefaultParameterValue(null)>] ?Scalegroup
2158+
) =
2159+
2160+
Trace.initFunnelArea(
2161+
TraceStyle.FunnelArea(
2162+
?Values = Values ,
2163+
?Labels = Labels ,
2164+
?dLabel = dLabel ,
2165+
?Label0 = Label0 ,
2166+
?Aspectratio = Aspectratio ,
2167+
?Baseratio = Baseratio ,
2168+
?Insidetextfont = Insidetextfont,
2169+
?Scalegroup = Scalegroup
2170+
)
2171+
)
2172+
|> TraceStyle.TraceInfo(?Name=Name,?Showlegend=Showlegend,?Opacity=Opacity)
2173+
|> TraceStyle.Marker(?Color=Color,?Line=Line)
2174+
|> TraceStyle.Domain(?X=X,?Y=Y,?Row=Row,?Column=Column)
2175+
|> TraceStyle.TextLabel(?Text=Text,?Textposition=TextPosition)
2176+
|> GenericChart.ofTraceObject
2177+
20952178
/// Creates a ScatterGeo chart, where data is visualized on a geographic map.
20962179
/// ScatterGeo charts are the basis of GeoPoint, GeoLine, and GeoBubble Charts, and can be customized as such. We also provide abstractions for those: Chart.GeoPoint, Chart.GeoLine, Chart.GeoBubble
20972180
///

Diff for: src/Plotly.NET/Playground.fsx

+13-1
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,7 @@ let doughnut1 =
572572
)
573573
|> Chart.Show
574574

575-
// Funnel example adapted from Plotly docs: https://plotly.com/javascript/funnel-charts/
575+
// Funnel examples adapted from Plotly docs: https://plotly.com/javascript/funnel-charts/
576576
let funnel =
577577
let y = [|"Sales person A"; "Sales person B"; "Sales person C"; "Sales person D"; "Sales person E"|]
578578
let x = [|1200.; 909.4; 600.6; 300.; 80.|]
@@ -581,4 +581,16 @@ let funnel =
581581
let connector = FunnelConnector.init(Line=connectorLine)
582582
Chart.Funnel (x,y,Color="59D4E8", Line=line, Connector=connector)
583583
|> Chart.withMarginSize(Left=100)
584+
|> Chart.Show
585+
586+
let funnelArea =
587+
let values = [|5; 4; 3; 2; 1|]
588+
let text = [|"The 1st"; "The 2nd"; "The 3rd"; "The 4th"; "The 5th"|]
589+
let line = Line.init (Color="purple", Width=3.)
590+
Chart.FunnelArea(Values=values, Text=text, Line=line)
591+
|> Chart.Show
592+
593+
let funnelArea2 =
594+
let labels = [|1;2;2;3;3;3|]
595+
Chart.FunnelArea(Labels=labels)
584596
|> Chart.Show

Diff for: src/Plotly.NET/Trace.fs

+58-1
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,37 @@ module Trace =
374374

375375
)
376376

377+
/// Sets the given domain on a Trace object.
378+
static member SetDomain
379+
(
380+
domain:Domain
381+
) =
382+
(fun (trace:('T :> Trace)) ->
383+
384+
trace.SetValue("domain", domain)
385+
trace
386+
)
387+
388+
/// Sets the given Domain styles on the domain property of a Trace object
389+
static member Domain
390+
(
391+
?X : StyleParam.Range,
392+
?Y : StyleParam.Range,
393+
?Row : int,
394+
?Column: int
395+
) =
396+
(fun (trace:('T :> Trace)) ->
397+
let domain =
398+
match (trace.TryGetValue "domain") with
399+
| Some m -> m :?> Domain
400+
| None -> Domain ()
401+
402+
|> Domain.style(?X=X,?Y=Y,?Row=Row,?Column=Column)
403+
404+
trace.SetValue("domain", domain)
405+
trace
406+
)
407+
377408
// Sets the X-Error an a Trace object.
378409
static member SetErrorX
379410
(
@@ -1477,7 +1508,33 @@ module Trace =
14771508
Cliponaxis |> DynObj.setValueOpt trace "cliponaxis"
14781509
Connector |> DynObj.setValueOpt trace "connector"
14791510
Insidetextfont |> DynObj.setValueOpt trace "insidetextfont"
1480-
Outsidetextfont |> DynObj.setValueOpt trace "insidetextfont"
1511+
Outsidetextfont |> DynObj.setValueOpt trace "outsidetextfont"
1512+
1513+
trace
1514+
1515+
)
1516+
1517+
static member FunnelArea
1518+
(
1519+
?Values : seq<#IConvertible>,
1520+
?Labels : seq<#IConvertible>,
1521+
?dLabel : float,
1522+
?Label0 : float,
1523+
?Aspectratio : float,
1524+
?Baseratio : float,
1525+
?Insidetextfont: Font,
1526+
?Scalegroup : string
1527+
) =
1528+
(fun (trace:('T :> Trace)) ->
1529+
1530+
Values |> DynObj.setValueOpt trace "values"
1531+
Labels |> DynObj.setValueOpt trace "labels"
1532+
dLabel |> DynObj.setValueOpt trace "dlabel"
1533+
Label0 |> DynObj.setValueOpt trace "label0"
1534+
Aspectratio |> DynObj.setValueOpt trace "aspectratio"
1535+
Baseratio |> DynObj.setValueOpt trace "baseratio"
1536+
Insidetextfont |> DynObj.setValueOpt trace "insidetextfont"
1537+
Scalegroup |> DynObj.setValueOpt trace "scalegroup"
14811538

14821539
trace
14831540

0 commit comments

Comments
 (0)