diff --git a/src/Plotly.NET/Chart.fs b/src/Plotly.NET/Chart.fs index 360090719..52636ca88 100644 --- a/src/Plotly.NET/Chart.fs +++ b/src/Plotly.NET/Chart.fs @@ -1994,6 +1994,104 @@ 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. + /// + /// Parameters: + /// + /// x : Sets the x coordinates. + /// + /// y : Sets the y coordinates. + /// + /// 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 + /// + /// Labels : Sets text elements associated with each (x,y) pair. If a single string, the same string appears over all the data points. If an array of string, the items are mapped in order to the this trace's (x,y) coordinates. If trace `hoverinfo` contains a "text" flag and "hovertext" is not set, these elements will be seen in the hover labels. + /// + /// TextPosition : Sets the positions of the `text` elements with respects to the (x,y) coordinates. + /// + /// TextFont : Sets the text font of this trace + /// + /// Color : Sets Marker Color + /// + /// Line : Line type + /// + /// x0 : Alternate to `x`. Builds a linear space of x coordinates. Use with `dx` where `x0` is the starting coordinate and `dx` the step. + /// + /// dX : Sets the x coordinate step. See `x0` for more info. + /// + /// y0 : Alternate to `y`. Builds a linear space of y coordinates. Use with `dy` where `y0` is the starting coordinate and `dy` the step. + /// + /// dY : Sets the y coordinate step. See `y0` for more info. + /// + /// Width : Sets the bar width (in position axis units). + /// + /// Offset : Shifts the position where the bar is drawn (in position axis units). In "group" barmode, traces that set "offset" will be excluded and drawn in "overlay" mode instead. + /// + /// Orientation : Sets the orientation of the funnels. With "v" ("h"), the value of the each bar spans along the vertical (horizontal). By default funnels are tend to be oriented horizontally; unless only "y" array is presented or orientation is set to "v". Also regarding graphs including only 'horizontal' funnels, "autorange" on the "y-axis" are set to "reversed". + /// + /// Alignmentgroup : Set several traces linked to the same position axis or matching axes to the same alignmentgroup. This controls whether bars compute their positional range dependently or independently. + /// + /// Offsetgroup : Set several traces linked to the same position axis or matching axes to the same offsetgroup where bars of the same position coordinate will line up. + /// + /// Cliponaxis : Determines whether the text nodes are clipped about the subplot axes. To show the text nodes above axis lines and tick labels, make sure to set `xaxis.layer` and `yaxis.layer` to "below traces". + /// + /// Connector : Connector type + /// + /// Insidetextfont : Sets the font used for `text` lying inside the bar. + /// + /// Outsidetextfont: Sets the font used for `text` lying outside the bar. + static member Funnel (x, y, + [] ?Name , + [] ?Showlegend , + [] ?Opacity , + [] ?Labels , + [] ?TextPosition , + [] ?TextFont , + [] ?Color , + [] ?Line , + [] ?x0 , + [] ?dX , + [] ?y0 , + [] ?dY , + [] ?Width , + [] ?Offset , + [] ?Orientation , + [] ?Alignmentgroup , + [] ?Offsetgroup , + [] ?Cliponaxis , + [] ?Connector , + [] ?Insidetextfont , + [] ?Outsidetextfont + ) = + + Trace.initFunnel( + TraceStyle.Funnel( + x = x , + y = y , + ?x0 = x0 , + ?dX = dX , + ?y0 = y0 , + ?dY = dY , + ?Width = Width , + ?Offset = Offset , + ?Orientation = Orientation , + ?Alignmentgroup = Alignmentgroup , + ?Offsetgroup = Offsetgroup , + ?Cliponaxis = Cliponaxis , + ?Connector = Connector , + ?Insidetextfont = Insidetextfont , + ?Outsidetextfont = Outsidetextfont + ) + ) + |> TraceStyle.TraceInfo(?Name=Name,?Showlegend=Showlegend,?Opacity=Opacity) + |> TraceStyle.Marker(?Color=Color,?Line=Line) + |> TraceStyle.TextLabel(?Text=Labels,?Textposition=TextPosition,?Textfont=TextFont) + |> 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 /// diff --git a/src/Plotly.NET/FunnelConnector.fs b/src/Plotly.NET/FunnelConnector.fs new file mode 100644 index 000000000..062834dd3 --- /dev/null +++ b/src/Plotly.NET/FunnelConnector.fs @@ -0,0 +1,43 @@ +namespace Plotly.NET + +/// Styles for connector lines in Funnel Charts. +/// +/// Parameters: +/// +/// Line : Sets the Line style for this WaterfallConnector +/// +/// Visible : Wether or not connectors are visible +/// +/// ConnectorMode : Sets the shape of connector lines. +type FunnelConnector () = + inherit DynamicObj () + + static member init + ( + ?Fillcolor : string, + ?Line : Line, + ?Visible : bool + ) = + + FunnelConnector() + |> FunnelConnector.style + ( + ?Fillcolor = Fillcolor, + ?Line = Line , + ?Visible = Visible + ) + + static member style + ( + ?Fillcolor , + ?Line : Line, + ?Visible : bool + ) = + (fun (connector:FunnelConnector) -> + + Fillcolor |> DynObj.setValueOpt connector "fillcolor" + Line |> DynObj.setValueOpt connector "line" + Visible |> DynObj.setValueOpt connector "visible" + + connector + ) diff --git a/src/Plotly.NET/Playground.fsx b/src/Plotly.NET/Playground.fsx index d62bc1de9..23498ec89 100644 --- a/src/Plotly.NET/Playground.fsx +++ b/src/Plotly.NET/Playground.fsx @@ -15,6 +15,7 @@ #load "Domain.fs" #load "Line.fs" #load "WaterfallConnector.fs" +#load "FunnelConnector.fs" #load "Box.fs" #load "Meanline.fs" #load "Marker.fs" @@ -569,4 +570,15 @@ let doughnut1 = Colors=cols, Textinfo=labels ) + |> Chart.Show + +// Funnel example 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.|] + let line = Line.init(Width=2.,Color="3E4E88") + let connectorLine = Line.init (Color="royalblue", Dash=StyleParam.DrawingStyle.Dot, Width=3.) + let connector = FunnelConnector.init(Line=connectorLine) + Chart.Funnel (x,y,Color="59D4E8", Line=line, Connector=connector) + |> Chart.withMarginSize(Left=100) |> Chart.Show \ No newline at end of file diff --git a/src/Plotly.NET/Plotly.NET.fsproj b/src/Plotly.NET/Plotly.NET.fsproj index ebb5eb085..0f06135e0 100644 --- a/src/Plotly.NET/Plotly.NET.fsproj +++ b/src/Plotly.NET/Plotly.NET.fsproj @@ -51,6 +51,7 @@ + diff --git a/src/Plotly.NET/Trace.fs b/src/Plotly.NET/Trace.fs index cd3f8506f..0be296803 100644 --- a/src/Plotly.NET/Trace.fs +++ b/src/Plotly.NET/Trace.fs @@ -1443,6 +1443,46 @@ module Trace = trace ) + static member Funnel + ( + x : seq<#IConvertible>, + y : seq<#IConvertible>, + ?x0, + ?dX : float, + ?y0, + ?dY : float, + ?Width : float, + ?Offset : float, + ?Orientation : StyleParam.Orientation, + ?Alignmentgroup : string, + ?Offsetgroup : string, + ?Cliponaxis : bool, + ?Connector : FunnelConnector, + ?Insidetextfont : Font, + ?Outsidetextfont: Font + ) = + (fun (trace:('T :> Trace)) -> + + x |> DynObj.setValue trace "x" + y |> DynObj.setValue trace "y" + x0 |> DynObj.setValueOpt trace "x0" + dX |> DynObj.setValueOpt trace "dx" + y0 |> DynObj.setValueOpt trace "y0" + dY |> DynObj.setValueOpt trace "dy" + Width |> DynObj.setValueOpt trace "width" + Offset |> DynObj.setValueOpt trace "offset" + Orientation |> DynObj.setValueOptBy trace "orientation" StyleParam.Orientation.convert + Alignmentgroup |> DynObj.setValueOpt trace "alignmentgroup" + Offsetgroup |> DynObj.setValueOpt trace "offsetgroup" + Cliponaxis |> DynObj.setValueOpt trace "cliponaxis" + Connector |> DynObj.setValueOpt trace "connector" + Insidetextfont |> DynObj.setValueOpt trace "insidetextfont" + Outsidetextfont |> DynObj.setValueOpt trace "insidetextfont" + + trace + + ) + static member ScatterGeo ( mode : StyleParam.Mode,