Skip to content

Add FunnelArea chart #85

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 14, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 84 additions & 1 deletion src/Plotly.NET/Chart.fs
Original file line number Diff line number Diff line change
@@ -1995,7 +1995,7 @@ type Chart =
|> GenericChart.ofTraceObject

/// Creates a Funnel chart.
/// 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.
/// 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.
///
/// Parameters:
///
@@ -2092,6 +2092,89 @@ type Chart =
|> TraceStyle.TextLabel(?Text=Labels,?Textposition=TextPosition,?Textfont=TextFont)
|> GenericChart.ofTraceObject

/// Creates a FunnelArea chart.
/// 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.
///
/// Parameters:
///
/// Values : Sets the values of the sectors. If omitted, we count occurrences of each label.
///
/// 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.
///
/// dLabel : Sets the label step. See `label0` for more info.
///
/// Label0 : Alternate to `labels`. Builds a numeric set of labels. Use with `dlabel` where `label0` is the starting label and `dlabel` the step.
///
/// Name : Sets the trace name. The trace name appear as the legend item and on hover.
///
/// Showlegend : Determines whether or not an item corresponding to this trace is shown in the legend.
///
/// Opacity : Sets the opacity of the trace.
///
/// Color : Sets Marker Color
///
/// Line : Line type
///
/// 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.
///
/// TextPosition : Specifies the location of the `textinfo`.
///
/// X : Sets the horizontal domain of this funnelarea trace (in plot fraction).
///
/// Y : Sets the vertical domain of this funnelarea trace (in plot fraction).
///
/// Row : If there is a layout grid, use the domain for this row in the grid for this funnelarea trace .
///
/// Column : If there is a layout grid, use the domain for this column in the grid for this funnelarea trace .
///
/// Aspectratio : Sets the ratio between height and width
///
/// Baseratio : Sets the ratio between bottom length and maximum top length.
///
/// Insidetextfont: Sets the font used for `textinfo` lying inside the sector.
///
/// 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.
static member FunnelArea
(
[<Optional;DefaultParameterValue(null)>] ?Values ,
[<Optional;DefaultParameterValue(null)>] ?Labels ,
[<Optional;DefaultParameterValue(null)>] ?dLabel ,
[<Optional;DefaultParameterValue(null)>] ?Label0 ,
[<Optional;DefaultParameterValue(null)>] ?Name ,
[<Optional;DefaultParameterValue(null)>] ?Showlegend ,
[<Optional;DefaultParameterValue(null)>] ?Opacity ,
[<Optional;DefaultParameterValue(null)>] ?Color ,
[<Optional;DefaultParameterValue(null)>] ?Line ,
[<Optional;DefaultParameterValue(null)>] ?Text ,
[<Optional;DefaultParameterValue(null)>] ?TextPosition ,
[<Optional;DefaultParameterValue(null)>] ?X ,
[<Optional;DefaultParameterValue(null)>] ?Y ,
[<Optional;DefaultParameterValue(null)>] ?Row ,
[<Optional;DefaultParameterValue(null)>] ?Column ,
[<Optional;DefaultParameterValue(null)>] ?Aspectratio ,
[<Optional;DefaultParameterValue(null)>] ?Baseratio ,
[<Optional;DefaultParameterValue(null)>] ?Insidetextfont,
[<Optional;DefaultParameterValue(null)>] ?Scalegroup
) =

Trace.initFunnelArea(
TraceStyle.FunnelArea(
?Values = Values ,
?Labels = Labels ,
?dLabel = dLabel ,
?Label0 = Label0 ,
?Aspectratio = Aspectratio ,
?Baseratio = Baseratio ,
?Insidetextfont = Insidetextfont,
?Scalegroup = Scalegroup
)
)
|> TraceStyle.TraceInfo(?Name=Name,?Showlegend=Showlegend,?Opacity=Opacity)
|> TraceStyle.Marker(?Color=Color,?Line=Line)
|> TraceStyle.Domain(?X=X,?Y=Y,?Row=Row,?Column=Column)
|> TraceStyle.TextLabel(?Text=Text,?Textposition=TextPosition)
|> GenericChart.ofTraceObject

/// Creates a ScatterGeo chart, where data is visualized on a geographic map.
/// 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
///
14 changes: 13 additions & 1 deletion src/Plotly.NET/Playground.fsx
Original file line number Diff line number Diff line change
@@ -572,7 +572,7 @@ let doughnut1 =
)
|> Chart.Show

// Funnel example adapted from Plotly docs: https://plotly.com/javascript/funnel-charts/
// Funnel examples adapted from Plotly docs: https://plotly.com/javascript/funnel-charts/
let funnel =
let y = [|"Sales person A"; "Sales person B"; "Sales person C"; "Sales person D"; "Sales person E"|]
let x = [|1200.; 909.4; 600.6; 300.; 80.|]
@@ -581,4 +581,16 @@ let funnel =
let connector = FunnelConnector.init(Line=connectorLine)
Chart.Funnel (x,y,Color="59D4E8", Line=line, Connector=connector)
|> Chart.withMarginSize(Left=100)
|> Chart.Show

let funnelArea =
let values = [|5; 4; 3; 2; 1|]
let text = [|"The 1st"; "The 2nd"; "The 3rd"; "The 4th"; "The 5th"|]
let line = Line.init (Color="purple", Width=3.)
Chart.FunnelArea(Values=values, Text=text, Line=line)
|> Chart.Show

let funnelArea2 =
let labels = [|1;2;2;3;3;3|]
Chart.FunnelArea(Labels=labels)
|> Chart.Show
59 changes: 58 additions & 1 deletion src/Plotly.NET/Trace.fs
Original file line number Diff line number Diff line change
@@ -374,6 +374,37 @@ module Trace =

)

/// Sets the given domain on a Trace object.
static member SetDomain
(
domain:Domain
) =
(fun (trace:('T :> Trace)) ->

trace.SetValue("domain", domain)
trace
)

/// Sets the given Domain styles on the domain property of a Trace object
static member Domain
(
?X : StyleParam.Range,
?Y : StyleParam.Range,
?Row : int,
?Column: int
) =
(fun (trace:('T :> Trace)) ->
let domain =
match (trace.TryGetValue "domain") with
| Some m -> m :?> Domain
| None -> Domain ()

|> Domain.style(?X=X,?Y=Y,?Row=Row,?Column=Column)

trace.SetValue("domain", domain)
trace
)

// Sets the X-Error an a Trace object.
static member SetErrorX
(
@@ -1477,7 +1508,33 @@ module Trace =
Cliponaxis |> DynObj.setValueOpt trace "cliponaxis"
Connector |> DynObj.setValueOpt trace "connector"
Insidetextfont |> DynObj.setValueOpt trace "insidetextfont"
Outsidetextfont |> DynObj.setValueOpt trace "insidetextfont"
Outsidetextfont |> DynObj.setValueOpt trace "outsidetextfont"

trace

)

static member FunnelArea
(
?Values : seq<#IConvertible>,
?Labels : seq<#IConvertible>,
?dLabel : float,
?Label0 : float,
?Aspectratio : float,
?Baseratio : float,
?Insidetextfont: Font,
?Scalegroup : string
) =
(fun (trace:('T :> Trace)) ->

Values |> DynObj.setValueOpt trace "values"
Labels |> DynObj.setValueOpt trace "labels"
dLabel |> DynObj.setValueOpt trace "dlabel"
Label0 |> DynObj.setValueOpt trace "label0"
Aspectratio |> DynObj.setValueOpt trace "aspectratio"
Baseratio |> DynObj.setValueOpt trace "baseratio"
Insidetextfont |> DynObj.setValueOpt trace "insidetextfont"
Scalegroup |> DynObj.setValueOpt trace "scalegroup"

trace