From 5bedd42fadcb6fce9ca18f4764bd36056e0acac7 Mon Sep 17 00:00:00 2001 From: Kevin Schneider Date: Tue, 21 Sep 2021 15:19:13 +0200 Subject: [PATCH 01/12] Add internal utils for multivalues, update deps --- .../Plotly.NET.ImageExport.fsproj | 2 +- src/Plotly.NET/InternalUtils.fs | 19 +++++++++++++++++++ src/Plotly.NET/Plotly.NET.fsproj | 6 ++++-- 3 files changed, 24 insertions(+), 3 deletions(-) create mode 100644 src/Plotly.NET/InternalUtils.fs diff --git a/src/Plotly.NET.ImageExport/Plotly.NET.ImageExport.fsproj b/src/Plotly.NET.ImageExport/Plotly.NET.ImageExport.fsproj index 8f13dcc79..bab29dea8 100644 --- a/src/Plotly.NET.ImageExport/Plotly.NET.ImageExport.fsproj +++ b/src/Plotly.NET.ImageExport/Plotly.NET.ImageExport.fsproj @@ -37,7 +37,7 @@ - + diff --git a/src/Plotly.NET/InternalUtils.fs b/src/Plotly.NET/InternalUtils.fs new file mode 100644 index 000000000..6696fac8d --- /dev/null +++ b/src/Plotly.NET/InternalUtils.fs @@ -0,0 +1,19 @@ +[] +module internal InternalUtils + + open DynamicObj + + [] + module DynObj = + + let setSingleOrMultiOpt (dyn:#DynamicObj) (propName:string) (single:'A option, multi:seq<'A> option) = + if multi.IsSome then + multi |> DynObj.setValueOpt dyn propName + else + single |> DynObj.setValueOpt dyn propName + + let setSingleOrMultiOptBy (dyn:#DynamicObj) (propName:string) (f:'A -> 'B) (single:'A option, multi:seq<'A> option) = + if multi.IsSome then + multi |> DynObj.setValueOptBy dyn propName (Seq.map f) + else + single |> DynObj.setValueOptBy dyn propName f diff --git a/src/Plotly.NET/Plotly.NET.fsproj b/src/Plotly.NET/Plotly.NET.fsproj index 5ca1a0253..6a441a657 100644 --- a/src/Plotly.NET/Plotly.NET.fsproj +++ b/src/Plotly.NET/Plotly.NET.fsproj @@ -34,6 +34,7 @@ + @@ -75,6 +76,7 @@ + @@ -126,8 +128,8 @@ - - + + From e8e445551228aa98990b67548b2215e77e6f725d Mon Sep 17 00:00:00 2001 From: Kevin Schneider Date: Tue, 21 Sep 2021 15:19:32 +0200 Subject: [PATCH 02/12] Rework marker object --- docs/02_0_line-scatter-plots.fsx | 2 +- src/Plotly.NET/ChartAPI/Chart2D.fs | 2 +- src/Plotly.NET/ChartAPI/ChartDomain.fs | 2 +- src/Plotly.NET/ChartAPI/ChartTernary.fs | 12 +- src/Plotly.NET/CommonAbstractions/Line.fs | 50 +++-- .../CommonAbstractions/StyleParams.fs | 189 +++++++++++++----- src/Plotly.NET/Playground.fsx | 25 ++- .../Traces/ObjectAbstractions/Gradient.fs | 39 ++++ .../Traces/ObjectAbstractions/Marker.fs | 184 +++++++++-------- src/Plotly.NET/Traces/Trace.fs | 81 +++++--- .../HtmlCodegen/SimpleCharts.fs | 2 +- 11 files changed, 395 insertions(+), 193 deletions(-) create mode 100644 src/Plotly.NET/Traces/ObjectAbstractions/Gradient.fs diff --git a/docs/02_0_line-scatter-plots.fsx b/docs/02_0_line-scatter-plots.fsx index 93fb66702..5ece9f57a 100644 --- a/docs/02_0_line-scatter-plots.fsx +++ b/docs/02_0_line-scatter-plots.fsx @@ -52,7 +52,7 @@ let line1 = x,y, Name="line", ShowMarkers=true, - MarkerSymbol=StyleParam.Symbol.Square) + MarkerSymbol=StyleParam.MarkerSymbol.Square) |> Chart.withLineStyle(Width=2.,Dash=StyleParam.DrawingStyle.Dot) (*** condition: ipynb ***) diff --git a/src/Plotly.NET/ChartAPI/Chart2D.fs b/src/Plotly.NET/ChartAPI/Chart2D.fs index 48d9a5dce..1320eff9a 100644 --- a/src/Plotly.NET/ChartAPI/Chart2D.fs +++ b/src/Plotly.NET/ChartAPI/Chart2D.fs @@ -880,7 +880,7 @@ module Chart2D = ) ) |> TraceStyle.TraceInfo(?Name=Name,?ShowLegend=ShowLegend,?Opacity=Opacity) - |> TraceStyle.Marker(?Color=Color,?Line=Line) + |> TraceStyle.Marker(?Color=Color,?Outline=Line) |> TraceStyle.TextLabel(?Text=Labels,?Textposition=TextPosition,?Textfont=TextFont) |> GenericChart.ofTraceObject diff --git a/src/Plotly.NET/ChartAPI/ChartDomain.fs b/src/Plotly.NET/ChartAPI/ChartDomain.fs index 8a999ecaf..368a6d558 100644 --- a/src/Plotly.NET/ChartAPI/ChartDomain.fs +++ b/src/Plotly.NET/ChartAPI/ChartDomain.fs @@ -234,7 +234,7 @@ module ChartDomain = ) ) |> TraceStyle.TraceInfo(?Name=Name,?ShowLegend=ShowLegend,?Opacity=Opacity) - |> TraceStyle.Marker(?Color=Color,?Line=Line) + |> TraceStyle.Marker(?Color=Color,?Outline=Line) |> TraceStyle.Domain(?X=X,?Y=Y,?Row=Row,?Column=Column) |> TraceStyle.TextLabel(?Text=Text,?Textposition=TextPosition) |> GenericChart.ofTraceObject diff --git a/src/Plotly.NET/ChartAPI/ChartTernary.fs b/src/Plotly.NET/ChartAPI/ChartTernary.fs index 09fa1b22f..53a10ef2a 100644 --- a/src/Plotly.NET/ChartAPI/ChartTernary.fs +++ b/src/Plotly.NET/ChartAPI/ChartTernary.fs @@ -28,7 +28,7 @@ module ChartTernary = [] ?Labels : seq<#IConvertible>, [] ?Name : string, [] ?ShowLegend : bool, - [] ?MarkerSymbol : StyleParam.Symbol, + [] ?MarkerSymbol : StyleParam.MarkerSymbol, [] ?Color : Color, [] ?Opacity : float, [] ?TextPosition : StyleParam.TextPosition, @@ -60,7 +60,7 @@ module ChartTernary = [] ?Labels : seq<#IConvertible>, [] ?Name : string, [] ?ShowLegend : bool, - [] ?MarkerSymbol : StyleParam.Symbol, + [] ?MarkerSymbol : StyleParam.MarkerSymbol, [] ?Color : Color, [] ?Opacity : float, [] ?TextPosition : StyleParam.TextPosition, @@ -96,7 +96,7 @@ module ChartTernary = [] ?Labels : seq<#IConvertible>, [] ?Name : string, [] ?ShowLegend : bool, - [] ?MarkerSymbol : StyleParam.Symbol, + [] ?MarkerSymbol : StyleParam.MarkerSymbol, [] ?Color : Color, [] ?Opacity : float, [] ?TextPosition : StyleParam.TextPosition, @@ -125,7 +125,7 @@ module ChartTernary = [] ?Labels : seq<#IConvertible>, [] ?Name : string, [] ?ShowLegend : bool, - [] ?MarkerSymbol : StyleParam.Symbol, + [] ?MarkerSymbol : StyleParam.MarkerSymbol, [] ?Color : Color, [] ?Opacity : float, [] ?TextPosition : StyleParam.TextPosition, @@ -160,7 +160,7 @@ module ChartTernary = [] ?ShowMarkers : bool, [] ?Dash : StyleParam.DrawingStyle, [] ?Width : float, - [] ?MarkerSymbol : StyleParam.Symbol, + [] ?MarkerSymbol : StyleParam.MarkerSymbol, [] ?Color : Color, [] ?Opacity : float, [] ?TextPosition : StyleParam.TextPosition, @@ -199,7 +199,7 @@ module ChartTernary = [] ?ShowMarkers : bool, [] ?Dash : StyleParam.DrawingStyle, [] ?Width : float, - [] ?MarkerSymbol : StyleParam.Symbol, + [] ?MarkerSymbol : StyleParam.MarkerSymbol, [] ?Color : Color, [] ?Opacity : float, [] ?TextPosition : StyleParam.TextPosition, diff --git a/src/Plotly.NET/CommonAbstractions/Line.fs b/src/Plotly.NET/CommonAbstractions/Line.fs index 97ce39de2..f7b95b640 100644 --- a/src/Plotly.NET/CommonAbstractions/Line.fs +++ b/src/Plotly.NET/CommonAbstractions/Line.fs @@ -38,26 +38,42 @@ type Line () = // Applies the styles to Line() static member style ( - [] ?Width:float, - [] ?Color:Color, - [] ?Shape:StyleParam.Shape, - [] ?Dash:StyleParam.DrawingStyle, - [] ?Smoothing:float, - [] ?Colorscale:StyleParam.Colorscale, - [] ?OutlierColor:Color, - [] ?OutlierWidth:float + [] ?Color : Color, + [] ?Width : float, + [] ?MultiWidths : seq, + [] ?Shape : StyleParam.Shape, + [] ?Dash : StyleParam.DrawingStyle, + [] ?Smoothing : float, + [] ?OutlierColor : Color, + [] ?OutlierWidth : float, + [] ?AutoColorScale : bool, + [] ?CAuto : bool, + [] ?CMax : float, + [] ?CMid : float, + [] ?CMin : float, + [] ?ColorAxis : StyleParam.SubPlotId, + [] ?Colorscale : StyleParam.Colorscale, + [] ?ReverseScale : bool ) = (fun (line:Line) -> - Color |> DynObj.setValueOpt line "color" - Width |> DynObj.setValueOpt line "width" - Shape |> DynObj.setValueOptBy line "shape" StyleParam.Shape.convert - Smoothing |> DynObj.setValueOpt line "smoothing" - Dash |> DynObj.setValueOptBy line "dash" StyleParam.DrawingStyle.convert - Colorscale |> DynObj.setValueOptBy line "colorscale" StyleParam.Colorscale.convert - OutlierColor |> DynObj.setValueOpt line "outliercolor" - OutlierWidth |> DynObj.setValueOpt line "outlierwidth" - + Color |> DynObj.setValueOpt line "color" + (Width,MultiWidths) |> DynObj.setSingleOrMultiOpt line "width" + Shape |> DynObj.setValueOptBy line "shape" StyleParam.Shape.convert + Smoothing |> DynObj.setValueOpt line "smoothing" + Dash |> DynObj.setValueOptBy line "dash" StyleParam.DrawingStyle.convert + OutlierColor |> DynObj.setValueOpt line "outliercolor" + OutlierWidth |> DynObj.setValueOpt line "outlierwidth" + AutoColorScale |> DynObj.setValueOpt line "autocolorscale" + CAuto |> DynObj.setValueOpt line "cauto" + CMax |> DynObj.setValueOpt line "cmax" + CMid |> DynObj.setValueOpt line "cmid" + CMin |> DynObj.setValueOpt line "cmin" + Color |> DynObj.setValueOpt line "color" + ColorAxis |> DynObj.setValueOptBy line "coloraxis" StyleParam.SubPlotId.convert + Colorscale |> DynObj.setValueOptBy line "colorscale" StyleParam.Colorscale.convert + ReverseScale |> DynObj.setValueOpt line "reversescale" + // out -> line ) diff --git a/src/Plotly.NET/CommonAbstractions/StyleParams.fs b/src/Plotly.NET/CommonAbstractions/StyleParams.fs index 6fe57ac23..e5d86b1f1 100644 --- a/src/Plotly.NET/CommonAbstractions/StyleParams.fs +++ b/src/Plotly.NET/CommonAbstractions/StyleParams.fs @@ -813,6 +813,21 @@ module StyleParam = // #G# //-------------------------- + [] + type GradientType = + | Radial | Horizontal | Vertical | None + + static member toString = function + | Radial -> "radial" + | Horizontal -> "horizontal" + | Vertical -> "vertical" + | None -> "none" + + static member convert = GradientType.toString >> box + override this.ToString() = this |> GradientType.toString + member this.Convert() = this |> GradientType.convert + + [] type GroupNorm = | None | Fraction | Percent @@ -1736,63 +1751,137 @@ module StyleParam = | Open | Dot | OpenDot + static member toString = function - | Open -> "Open" - | Dot -> "Dot" - | OpenDot -> "OpenDot" + | Open -> "open" + | Dot -> "dot" + | OpenDot -> "open-dot" + + static member toModifier = function + | Open -> 100 + | Dot -> 200 + | OpenDot -> 300 static member convert = SymbolStyle.toString >> box override this.ToString() = this |> SymbolStyle.toString member this.Convert() = this |> SymbolStyle.convert [] - type Symbol = - | Circle = 0 - | Square = 1 - | Diamond = 2 - | Cross = 3 - | X = 4 - | TriangleUp = 5 - | TriangleDown = 6 - | TriangleLeft = 7 - | TriangleRight = 8 - | TriangleNE = 9 - | TriangleSE = 10 - | TriangleSW = 11 - | TriangleNW = 12 - | Pentagon = 13 - | Hexagon = 14 - | Hexagon2 = 15 - | Octagon = 16 - | Star = 17 - | Hexagram = 18 - | StarTriangleUp = 19 - | StarTriangleDown = 20 - | StarSquare = 21 - | StarDiamond = 22 - | DiamondTall = 23 - | DiamondWide = 24 - | Hourglass = 25 - | Bowtie = 26 - | CircleCross = 27 - | CircleX = 28 - | SquareCross = 29 - | SquareX = 30 - | DiamondCross = 31 - | DiamondX = 32 - | CrossThin = 33 - | XThin = 34 - | Asterisk = 35 - | Hash = 36 - | YUp = 37 - | YDown = 38 - | YLeft = 39 - | YRight = 40 - | LineEW = 41 - | LineNS = 42 - | LineNE = 43 - | LineNW = 44 - + type MarkerSymbol = + | Modified of MarkerSymbol * SymbolStyle + | Circle + | Square + | Diamond + | Cross + | X + | TriangleUp + | TriangleDown + | TriangleLeft + | TriangleRight + | TriangleNE + | TriangleSE + | TriangleSW + | TriangleNW + | Pentagon + | Hexagon + | Hexagon2 + | Octagon + | Star + | Hexagram + | StarTriangleUp + | StarTriangleDown + | StarSquare + | StarDiamond + | DiamondTall + | DiamondWide + | Hourglass + | Bowtie + | CircleCross + | CircleX + | SquareCross + | SquareX + | DiamondCross + | DiamondX + | CrossThin + | XThin + | Asterisk + | Hash + | YUp + | YDown + | YLeft + | YRight + | LineEW + | LineNS + | LineNE + | LineNW + | ArrowUp + | ArrowDown + | ArrowLeft + | ArrowRight + | ArrowBarUp + | ArrowBarDown + | ArrowBarLeft + | ArrowBarRight + + static member toInteger = function + | Modified (symbol, modifier) -> (symbol |> MarkerSymbol.toInteger) + SymbolStyle.toModifier modifier + | Circle -> 0 + | Square -> 1 + | Diamond -> 2 + | Cross -> 3 + | X -> 4 + | TriangleUp -> 5 + | TriangleDown -> 6 + | TriangleLeft -> 7 + | TriangleRight -> 8 + | TriangleNE -> 9 + | TriangleSE -> 10 + | TriangleSW -> 11 + | TriangleNW -> 12 + | Pentagon -> 13 + | Hexagon -> 14 + | Hexagon2 -> 15 + | Octagon -> 16 + | Star -> 17 + | Hexagram -> 18 + | StarTriangleUp -> 19 + | StarTriangleDown -> 20 + | StarSquare -> 21 + | StarDiamond -> 22 + | DiamondTall -> 23 + | DiamondWide -> 24 + | Hourglass -> 25 + | Bowtie -> 26 + | CircleCross -> 27 + | CircleX -> 28 + | SquareCross -> 29 + | SquareX -> 30 + | DiamondCross -> 31 + | DiamondX -> 32 + | CrossThin -> 33 + | XThin -> 34 + | Asterisk -> 35 + | Hash -> 36 + | YUp -> 37 + | YDown -> 38 + | YLeft -> 39 + | YRight -> 40 + | LineEW -> 41 + | LineNS -> 42 + | LineNE -> 43 + | LineNW -> 44 + | ArrowUp -> 45 + | ArrowDown -> 46 + | ArrowLeft -> 47 + | ArrowRight -> 48 + | ArrowBarUp -> 49 + | ArrowBarDown -> 50 + | ArrowBarLeft -> 51 + | ArrowBarRight -> 52 + + static member convert = MarkerSymbol.toInteger >> string >> box + override this.ToString() = this |> MarkerSymbol.toInteger |> string + member this.Convert() = this |> MarkerSymbol.toInteger |> string |> box /// Determines the line shape. With "spline" the lines are drawn using spline interpolation. The other available values correspond to step-wise line shapes. [] diff --git a/src/Plotly.NET/Playground.fsx b/src/Plotly.NET/Playground.fsx index b579e132a..b0b488ad6 100644 --- a/src/Plotly.NET/Playground.fsx +++ b/src/Plotly.NET/Playground.fsx @@ -4,6 +4,8 @@ #r "nuget: DynamicObj" #r "nuget: Newtonsoft.Json, 13.0.1" +#load "InternalUtils.fs" + #I "CommonAbstractions" #load "StyleParams.fs" @@ -66,6 +68,7 @@ #I "Traces/ObjectAbstractions" +#load "Gradient.fs" #load "Marker.fs" #load "Projection.fs" #load "Surface.fs" @@ -154,6 +157,26 @@ open FSharpAux open System open System.IO +let crazyMarker = + Marker.init( + MultiSymbols = [ + StyleParam.MarkerSymbol.ArrowBarDown + StyleParam.MarkerSymbol.Modified(StyleParam.MarkerSymbol.DiamondCross, StyleParam.SymbolStyle.OpenDot) + StyleParam.MarkerSymbol.Modified(StyleParam.MarkerSymbol.Square, StyleParam.SymbolStyle.Open) + StyleParam.MarkerSymbol.Modified(StyleParam.MarkerSymbol.Hexagon2, StyleParam.SymbolStyle.Dot) + ], + MultiSizes = [50;60;100;70], + MultiOpacities = [0.3; 0.6; 0.9; 1.], + Color = Color.fromColorScaleValues [0.; 0.5; 1.; 0.8], + Colorscale = StyleParam.Colorscale.Viridis, + ShowScale = true + ) + +Chart.Point [1,1; 2,2; 3,3; 4,4] +|> Chart.withMarker crazyMarker +|> Chart.show + + Chart.Line([0.; 0.5; 1.; 2.; 2.2], y=[1.23; 2.5; 0.42; 3.; 1.]) |> Chart.withLayoutImage( LayoutImage.init( @@ -210,7 +233,7 @@ Chart.ScatterTernary( TextPosition = StyleParam.TextPosition.BottomCenter ) |> Chart.withLineStyle(Shape=StyleParam.Shape.Spline) -|> Chart.withMarkerStyle(Symbol = StyleParam.Symbol.Cross) +|> Chart.withMarkerStyle(Symbol = StyleParam.MarkerSymbol.Cross) |> Chart.show Chart.LineTernary( diff --git a/src/Plotly.NET/Traces/ObjectAbstractions/Gradient.fs b/src/Plotly.NET/Traces/ObjectAbstractions/Gradient.fs new file mode 100644 index 000000000..99ddb5b9b --- /dev/null +++ b/src/Plotly.NET/Traces/ObjectAbstractions/Gradient.fs @@ -0,0 +1,39 @@ +namespace Plotly.NET.TraceObjects + +open Plotly.NET +open Plotly.NET.LayoutObjects +open DynamicObj +open System +open System.Runtime.InteropServices + +type Gradient () = + inherit DynamicObj () + + static member init + ( + [] ?Color : Color, + [] ?Type : StyleParam.GradientType, + [] ?MultiTypes: seq + ) = + Gradient() + |> Gradient.style + ( + ?Color = Color, + ?Type = Type, + ?MultiTypes = MultiTypes + ) + + static member style + ( + [] ?Color : Color, + [] ?Type : StyleParam.GradientType, + [] ?MultiTypes: seq + ) = + + fun (gradient: Gradient) -> + + (Type,MultiTypes) |> DynObj.setSingleOrMultiOpt gradient "type" + + Color |> DynObj.setValueOpt gradient "color" + + gradient diff --git a/src/Plotly.NET/Traces/ObjectAbstractions/Marker.fs b/src/Plotly.NET/Traces/ObjectAbstractions/Marker.fs index a4db0cfca..960c9c5a5 100644 --- a/src/Plotly.NET/Traces/ObjectAbstractions/Marker.fs +++ b/src/Plotly.NET/Traces/ObjectAbstractions/Marker.fs @@ -13,104 +13,116 @@ type Marker () = /// Initialized Marker object static member init ( - [] ?Size, - [] ?Opacity, - [] ?Color, - [] ?Symbol, - [] ?MultiSizes, - [] ?Line, - [] ?ColorBar, - [] ?Colorscale, - [] ?Colors: seq, - [] ?OutlierColor, - [] ?Maxdisplayed, - [] ?Sizeref, - [] ?Sizemin, - [] ?Sizemode, - [] ?Cauto, - [] ?Cmax, - [] ?Cmin, - [] ?Cmid, - [] ?Autocolorscale, - [] ?Reversescale, - [] ?Showscale + [] ?AutoColorScale : bool, + [] ?CAuto : bool, + [] ?CMax : float, + [] ?CMid : float, + [] ?CMin : float, + [] ?Color : Color, + [] ?Colors : seq, + [] ?ColorAxis : StyleParam.SubPlotId, + [] ?ColorBar : ColorBar, + [] ?Colorscale : StyleParam.Colorscale, + [] ?Gradient : Gradient, + [] ?Outline : Line, + [] ?Size : int, + [] ?MultiSizes : seq, + [] ?Opacity : float, + [] ?MultiOpacities : seq, + [] ?Symbol : StyleParam.MarkerSymbol, + [] ?MultiSymbols : seq, + [] ?OutlierColor : Color, + [] ?Maxdisplayed : int, + [] ?ReverseScale : bool, + [] ?ShowScale : bool, + [] ?SizeMin : int, + [] ?SizeMode : StyleParam.MarkerSizeMode, + [] ?SizeRef : int ) = Marker () |> Marker.style ( - ?Size = Size , - ?Color = Color , - ?Symbol = Symbol , - ?Opacity = Opacity , - ?MultiSizes = MultiSizes , - ?Line = Line , - ?ColorBar = ColorBar , - ?Colorscale = Colorscale , - //?Colors = Colors , - ?OutlierColor = OutlierColor , - - ?Maxdisplayed = Maxdisplayed , - ?Sizeref = Sizeref , - ?Sizemin = Sizemin , - ?Sizemode = Sizemode , - ?Cauto = Cauto , - ?Cmax = Cmax , - ?Cmid = Cmid , - ?Cmin = Cmin , - ?Autocolorscale= Autocolorscale , - ?Reversescale = Reversescale , - ?Showscale = Showscale - + ?AutoColorScale = AutoColorScale, + ?CAuto = CAuto , + ?CMax = CMax , + ?CMid = CMid , + ?CMin = CMin , + ?Color = Color , + ?Colors = Colors , + ?ColorAxis = ColorAxis , + ?ColorBar = ColorBar , + ?Colorscale = Colorscale , + ?Gradient = Gradient , + ?Outline = Outline , + ?Size = Size , + ?MultiSizes = MultiSizes , + ?Opacity = Opacity , + ?MultiOpacities = MultiOpacities, + ?Symbol = Symbol , + ?MultiSymbols = MultiSymbols , + ?OutlierColor = OutlierColor , + ?Maxdisplayed = Maxdisplayed , + ?ReverseScale = ReverseScale , + ?ShowScale = ShowScale , + ?SizeMin = SizeMin , + ?SizeMode = SizeMode , + ?SizeRef = SizeRef ) // Applies the styles to Marker() static member style ( - [] ?Size: int, - [] ?Opacity: float, - [] ?Color: Color, - [] ?Symbol: StyleParam.Symbol, - [] ?MultiSizes: seq<#IConvertible>, - [] ?Line: Line, - [] ?ColorBar: ColorBar, - [] ?Colorscale : StyleParam.Colorscale, - [] ?Colors: seq, - [] ?OutlierColor:Color, - [] ?Maxdisplayed: int, - [] ?Sizeref: float, - [] ?Sizemin: float, - [] ?Sizemode: StyleParam.MarkerSizeMode, - [] ?Cauto: bool, - [] ?Cmax: float, - [] ?Cmin: float, - [] ?Cmid: float, - [] ?Autocolorscale: bool, - [] ?Reversescale: bool, - [] ?Showscale: bool + [] ?AutoColorScale : bool, + [] ?CAuto : bool, + [] ?CMax : float, + [] ?CMid : float, + [] ?CMin : float, + [] ?Color : Color, + [] ?Colors : seq, + [] ?ColorAxis : StyleParam.SubPlotId, + [] ?ColorBar : ColorBar, + [] ?Colorscale : StyleParam.Colorscale, + [] ?Gradient : Gradient, + [] ?Outline : Line, + [] ?Size : int, + [] ?MultiSizes : seq, + [] ?Opacity : float, + [] ?MultiOpacities : seq, + [] ?Symbol : StyleParam.MarkerSymbol, + [] ?MultiSymbols : seq, + [] ?OutlierColor : Color, + [] ?Maxdisplayed : int, + [] ?ReverseScale : bool, + [] ?ShowScale : bool, + [] ?SizeMin : int, + [] ?SizeMode : StyleParam.MarkerSizeMode, + [] ?SizeRef : int ) = (fun (marker: Marker) -> - Size |> DynObj.setValueOpt marker "size" - Color |> DynObj.setValueOpt marker "color" - Symbol |> DynObj.setValueOpt marker "symbol" - Opacity |> DynObj.setValueOpt marker "opacity" - MultiSizes |> DynObj.setValueOpt marker "size" - Line |> DynObj.setValueOpt marker "line" - ColorBar |> DynObj.setValueOpt marker "colorbar" - Colorscale |> DynObj.setValueOptBy marker "colorscale" StyleParam.Colorscale.convert - Colors |> DynObj.setValueOpt marker "colors" - OutlierColor |> DynObj.setValueOpt marker "outliercolor" - Maxdisplayed |> DynObj.setValueOpt marker "maxdisplayed" - Sizeref |> DynObj.setValueOpt marker "sizeref" - Sizemin |> DynObj.setValueOpt marker "sizemin" - Sizemode |> DynObj.setValueOptBy marker "sizemode" StyleParam.MarkerSizeMode.convert - Cauto |> DynObj.setValueOpt marker "cauto" - Cmax |> DynObj.setValueOpt marker "cmax" - Cmid |> DynObj.setValueOpt marker "cmid" - Cmin |> DynObj.setValueOpt marker "cmin" - Autocolorscale |> DynObj.setValueOpt marker "autocolorscale" - Reversescale |> DynObj.setValueOpt marker "reversescale" - Showscale |> DynObj.setValueOpt marker "showscale" + + AutoColorScale |> DynObj.setValueOpt marker "autocolorscale" + CAuto |> DynObj.setValueOpt marker "cauto" + CMax |> DynObj.setValueOpt marker "cmax" + CMid |> DynObj.setValueOpt marker "cmid" + CMin |> DynObj.setValueOpt marker "cmin" + Color |> DynObj.setValueOpt marker "color" + Colors |> DynObj.setValueOpt marker "colors" + ColorAxis |> DynObj.setValueOptBy marker "coloraxis" StyleParam.SubPlotId.convert + ColorBar |> DynObj.setValueOpt marker "colorbar" + Colorscale |> DynObj.setValueOptBy marker "colorscale" StyleParam.Colorscale.convert + Gradient |> DynObj.setValueOpt marker "gradient" + Outline |> DynObj.setValueOpt marker "line" + (Size, MultiSizes) |> DynObj.setSingleOrMultiOpt marker "size" + (Opacity, MultiOpacities) |> DynObj.setSingleOrMultiOpt marker "opacity" + (Symbol, MultiSymbols) |> DynObj.setSingleOrMultiOptBy marker "symbol" StyleParam.MarkerSymbol.convert + OutlierColor |> DynObj.setValueOpt marker "outliercolor" + Maxdisplayed |> DynObj.setValueOpt marker "maxdisplayed" + ReverseScale |> DynObj.setValueOpt marker "reversescale" + ShowScale |> DynObj.setValueOpt marker "showscale" + SizeMin |> DynObj.setValueOpt marker "sizemin" + SizeMode |> DynObj.setValueOpt marker "sizemode" + SizeRef |> DynObj.setValueOpt marker "sizeref" marker ) diff --git a/src/Plotly.NET/Traces/Trace.fs b/src/Plotly.NET/Traces/Trace.fs index 0c4bb0ae7..1743cba09 100644 --- a/src/Plotly.NET/Traces/Trace.fs +++ b/src/Plotly.NET/Traces/Trace.fs @@ -134,28 +134,31 @@ type TraceStyle() = /// Sets the given Marker styles on the marker property of a Trace object static member Marker ( - [] ?Size: int, - [] ?Opacity: float, - [] ?Color: Color, - [] ?Symbol: StyleParam.Symbol, - [] ?MultiSizes: seq<#IConvertible>, - [] ?Line: Line, - [] ?ColorBar: ColorBar, - [] ?Colorscale : StyleParam.Colorscale, - [] ?Colors: seq, - [] ?OutlierColor:Color, - [] ?Maxdisplayed: int, - [] ?Sizeref: float, - [] ?Sizemin: float, - [] ?Sizemode: StyleParam.MarkerSizeMode, - [] ?Cauto: bool, - [] ?Cmax: float, - [] ?Cmin: float, - [] ?Cmid: float, - [] ?Autocolorscale: bool, - [] ?Reversescale: bool, - [] ?Showscale: bool - + [] ?AutoColorScale : bool, + [] ?CAuto : bool, + [] ?CMax : float, + [] ?CMid : float, + [] ?CMin : float, + [] ?Color : Color, + [] ?Colors : seq, + [] ?ColorAxis : StyleParam.SubPlotId, + [] ?ColorBar : ColorBar, + [] ?Colorscale : StyleParam.Colorscale, + [] ?Gradient : Gradient, + [] ?Outline : Line, + [] ?Size : int, + [] ?MultiSizes : seq, + [] ?Opacity : float, + [] ?MultiOpacities : seq, + [] ?Symbol : StyleParam.MarkerSymbol, + [] ?MultiSymbols : seq, + [] ?OutlierColor : Color, + [] ?Maxdisplayed : int, + [] ?ReverseScale : bool, + [] ?ShowScale : bool, + [] ?SizeMin : int, + [] ?SizeMode : StyleParam.MarkerSizeMode, + [] ?SizeRef : int ) = (fun (trace:('T :> Trace)) -> let marker = @@ -163,13 +166,33 @@ type TraceStyle() = | Some m -> m :?> Marker | None -> Marker () - |> Marker.style(?Size=Size,?Color=Color,?Colors=Colors,?Symbol=Symbol, - ?Opacity=Opacity,?MultiSizes=MultiSizes,?Line=Line, - ?ColorBar=ColorBar,?Colorscale=Colorscale,?OutlierColor=OutlierColor, - ?Maxdisplayed=Maxdisplayed,?Sizeref=Sizeref,?Sizemin=Sizemin, - ?Sizemode=Sizemode,?Cauto=Cauto,?Cmax=Cmax,?Cmin=Cmin,?Cmid=Cmid, - ?Autocolorscale=Autocolorscale,?Reversescale=Reversescale,?Showscale=Showscale - ) + |> Marker.style( + ?AutoColorScale = AutoColorScale, + ?CAuto = CAuto , + ?CMax = CMax , + ?CMid = CMid , + ?CMin = CMin , + ?Color = Color , + ?Colors = Colors , + ?ColorAxis = ColorAxis , + ?ColorBar = ColorBar , + ?Colorscale = Colorscale , + ?Gradient = Gradient , + ?Outline = Outline , + ?Size = Size , + ?MultiSizes = MultiSizes , + ?Opacity = Opacity , + ?MultiOpacities = MultiOpacities, + ?Symbol = Symbol , + ?MultiSymbols = MultiSymbols , + ?OutlierColor = OutlierColor , + ?Maxdisplayed = Maxdisplayed , + ?ReverseScale = ReverseScale , + ?ShowScale = ShowScale , + ?SizeMin = SizeMin , + ?SizeMode = SizeMode , + ?SizeRef = SizeRef + ) trace.SetValue("marker", marker) trace diff --git a/tests/Plotly.NET.Tests/HtmlCodegen/SimpleCharts.fs b/tests/Plotly.NET.Tests/HtmlCodegen/SimpleCharts.fs index 6d78c2cbd..f17097049 100644 --- a/tests/Plotly.NET.Tests/HtmlCodegen/SimpleCharts.fs +++ b/tests/Plotly.NET.Tests/HtmlCodegen/SimpleCharts.fs @@ -16,7 +16,7 @@ let withLineStyleChart = x,y, Name="line", ShowMarkers=true, - MarkerSymbol=StyleParam.Symbol.Square) + MarkerSymbol=StyleParam.MarkerSymbol.Square) |> Chart.withLineStyle(Width=2.,Dash=StyleParam.DrawingStyle.Dot) From f226e9554c466a09a33c59f761b6d67db49e30a0 Mon Sep 17 00:00:00 2001 From: Kevin Schneider Date: Tue, 21 Sep 2021 15:24:05 +0200 Subject: [PATCH 03/12] Fix marker test --- tests/Plotly.NET.Tests/HtmlCodegen/SimpleCharts.fs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Plotly.NET.Tests/HtmlCodegen/SimpleCharts.fs b/tests/Plotly.NET.Tests/HtmlCodegen/SimpleCharts.fs index f17097049..f5bce67c2 100644 --- a/tests/Plotly.NET.Tests/HtmlCodegen/SimpleCharts.fs +++ b/tests/Plotly.NET.Tests/HtmlCodegen/SimpleCharts.fs @@ -45,7 +45,7 @@ let textLabelChart = let ``Line and scatter plots`` = testList "SimpleCharts.Line and scatter plots" [ testCase "With LineStyle data" ( fun () -> - """var data = [{"type":"scatter","mode":"lines+markers","x":[1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0,10.0],"y":[2.0,1.5,5.0,1.5,3.0,2.5,2.5,1.5,3.5,1.0],"line":{"width":2.0,"dash":"dot"},"name":"line","marker":{"symbol":1}}];""" + """var data = [{"type":"scatter","mode":"lines+markers","x":[1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0,10.0],"y":[2.0,1.5,5.0,1.5,3.0,2.5,2.5,1.5,3.5,1.0],"line":{"width":2.0,"dash":"dot"},"name":"line","marker":{"symbol":"1"}}];""" |> chartGeneratedContains withLineStyleChart ); testCase "With LineStyle layout" ( fun () -> From db36958511bdf92c48402eb3e9066564ffa5973f Mon Sep 17 00:00:00 2001 From: Kevin Schneider Date: Wed, 22 Sep 2021 10:57:24 +0200 Subject: [PATCH 04/12] Further rework Marker, add multi support for Bar Charts, fix Chart.withMarkerStyle overriding exisitng markers --- .../CSharpLayer/GenericChartExtensions.fs | 60 ++++++- src/Plotly.NET/ChartAPI/Chart.fs | 80 +++++++-- src/Plotly.NET/ChartAPI/Chart2D.fs | 160 ++++++++++++++---- src/Plotly.NET/ChartAPI/Chart3D.fs | 2 +- src/Plotly.NET/ChartAPI/ChartPolar.fs | 2 +- .../CommonAbstractions/StyleParams.fs | 40 +++++ src/Plotly.NET/Playground.fsx | 43 ++++- src/Plotly.NET/Plotly.NET.fsproj | 2 + .../Traces/ObjectAbstractions/Marker.fs | 20 ++- .../Traces/ObjectAbstractions/Pattern.fs | 73 ++++++++ src/Plotly.NET/Traces/Trace.fs | 23 +-- src/Plotly.NET/Traces/Trace2D.fs | 133 ++++++++------- .../HtmlCodegen/SimpleCharts.fs | 8 +- 13 files changed, 515 insertions(+), 131 deletions(-) create mode 100644 src/Plotly.NET/Traces/ObjectAbstractions/Pattern.fs diff --git a/src/Plotly.NET/CSharpLayer/GenericChartExtensions.fs b/src/Plotly.NET/CSharpLayer/GenericChartExtensions.fs index bae45b65c..3366e2882 100644 --- a/src/Plotly.NET/CSharpLayer/GenericChartExtensions.fs +++ b/src/Plotly.NET/CSharpLayer/GenericChartExtensions.fs @@ -48,17 +48,61 @@ module GenericChartExtensions = [] member this.WithMarkerStyle ( - [] ?Size, - [] ?Color, - [] ?Symbol, - [] ?Opacity + [] ?AutoColorScale : bool, + [] ?CAuto : bool, + [] ?CMax : float, + [] ?CMid : float, + [] ?CMin : float, + [] ?Color : Color, + [] ?Colors : seq, + [] ?ColorAxis : StyleParam.SubPlotId, + [] ?ColorBar : ColorBar, + [] ?Colorscale : StyleParam.Colorscale, + [] ?Gradient : Gradient, + [] ?Outline : Line, + [] ?Size : int, + [] ?MultiSize : seq, + [] ?Opacity : float, + [] ?MultiOpacity : seq, + [] ?Pattern : Pattern, + [] ?Symbol : StyleParam.MarkerSymbol, + [] ?MultiSymbols : seq, + [] ?OutlierColor : Color, + [] ?Maxdisplayed : int, + [] ?ReverseScale : bool, + [] ?ShowScale : bool, + [] ?SizeMin : int, + [] ?SizeMode : StyleParam.MarkerSizeMode, + [] ?SizeRef : int ) = this |> Chart.withMarkerStyle( - ?Size=Size, - ?Color=Color, - ?Symbol=Symbol, - ?Opacity=Opacity + ?AutoColorScale = AutoColorScale , + ?CAuto = CAuto , + ?CMax = CMax , + ?CMid = CMid , + ?CMin = CMin , + ?Color = Color , + ?Colors = Colors , + ?ColorAxis = ColorAxis , + ?ColorBar = ColorBar , + ?Colorscale = Colorscale , + ?Gradient = Gradient , + ?Outline = Outline , + ?Size = Size , + ?MultiSize = MultiSize , + ?Opacity = Opacity , + ?MultiOpacity = MultiOpacity , + ?Pattern = Pattern , + ?Symbol = Symbol , + ?MultiSymbols = MultiSymbols , + ?OutlierColor = OutlierColor , + ?Maxdisplayed = Maxdisplayed , + ?ReverseScale = ReverseScale , + ?ShowScale = ShowScale , + ?SizeMin = SizeMin , + ?SizeMode = SizeMode , + ?SizeRef = SizeRef ) /// Apply styling to the Line(s) of the chart as Object. diff --git a/src/Plotly.NET/ChartAPI/Chart.fs b/src/Plotly.NET/ChartAPI/Chart.fs index adef70048..5d3518784 100644 --- a/src/Plotly.NET/ChartAPI/Chart.fs +++ b/src/Plotly.NET/ChartAPI/Chart.fs @@ -121,16 +121,65 @@ type Chart = [] static member withMarkerStyle ( - [] ?Size, - [] ?Color, - [] ?Symbol, - [] ?Opacity + [] ?AutoColorScale : bool, + [] ?CAuto : bool, + [] ?CMax : float, + [] ?CMid : float, + [] ?CMin : float, + [] ?Color : Color, + [] ?Colors : seq, + [] ?ColorAxis : StyleParam.SubPlotId, + [] ?ColorBar : ColorBar, + [] ?Colorscale : StyleParam.Colorscale, + [] ?Gradient : Gradient, + [] ?Outline : Line, + [] ?Size : int, + [] ?MultiSize : seq, + [] ?Opacity : float, + [] ?MultiOpacity : seq, + [] ?Pattern : Pattern, + [] ?Symbol : StyleParam.MarkerSymbol, + [] ?MultiSymbols : seq, + [] ?OutlierColor : Color, + [] ?Maxdisplayed : int, + [] ?ReverseScale : bool, + [] ?ShowScale : bool, + [] ?SizeMin : int, + [] ?SizeMode : StyleParam.MarkerSizeMode, + [] ?SizeRef : int ) = - let marker = - Marker.init ( - ?Size=Size,?Color=Color,?Symbol=Symbol,?Opacity=Opacity + fun (ch:GenericChart) -> + ch + |> mapTrace ( + TraceStyle.Marker( + ?AutoColorScale = AutoColorScale, + ?CAuto = CAuto , + ?CMax = CMax , + ?CMid = CMid , + ?CMin = CMin , + ?Color = Color , + ?Colors = Colors , + ?ColorAxis = ColorAxis , + ?ColorBar = ColorBar , + ?Colorscale = Colorscale , + ?Gradient = Gradient , + ?Outline = Outline , + ?Size = Size , + ?MultiSize = MultiSize , + ?Opacity = Opacity , + ?MultiOpacity = MultiOpacity, + ?Pattern = Pattern, + ?Symbol = Symbol , + ?MultiSymbols = MultiSymbols , + ?OutlierColor = OutlierColor , + ?Maxdisplayed = Maxdisplayed , + ?ReverseScale = ReverseScale , + ?ShowScale = ShowScale , + ?SizeMin = SizeMin , + ?SizeMode = SizeMode , + ?SizeRef = SizeRef ) - Chart.withMarker(marker) + ) /// Apply styling to the Line(s) of the chart as Object. [] @@ -148,12 +197,21 @@ type Chart = [] ?Shape, [] ?Dash, [] ?Smoothing, - [] ?Colorscale + [] ?Colorscale, + [] ?OutlierColor, + [] ?OutlierWidth ) = let line = Line.init ( - ?Width=Width,?Color=Color,?Shape=Shape,?Dash=Dash,?Smoothing=Smoothing,?Colorscale=Colorscale) - + ?Width = Width, + ?Color = Color, + ?Shape = Shape, + ?Dash = Dash, + ?Smoothing = Smoothing, + ?Colorscale = Colorscale, + ?OutlierColor = OutlierColor, + ?OutlierWidth = OutlierWidth + ) Chart.withLine(line) /// Apply styling to the xError(s) of the chart as Object diff --git a/src/Plotly.NET/ChartAPI/Chart2D.fs b/src/Plotly.NET/ChartAPI/Chart2D.fs index 1320eff9a..6e55a1677 100644 --- a/src/Plotly.NET/ChartAPI/Chart2D.fs +++ b/src/Plotly.NET/ChartAPI/Chart2D.fs @@ -521,7 +521,7 @@ module Chart2D = ?Orientation= Orientation, ?GroupNorm = GroupNorm) >> TraceStyle.TraceInfo(?Name=Name,?ShowLegend=ShowLegend,?Opacity=Opacity) - >> TraceStyle.Marker(?Color=Color,?Symbol=MarkerSymbol, MultiSizes=sizes) + >> TraceStyle.Marker(?Color=Color,?Symbol=MarkerSymbol, MultiSize=sizes) >> TraceStyle.TextLabel(?Text=Labels,?Textposition=TextPosition,?Textfont=TextFont) let useWebGL = defaultArg UseWebGL false @@ -1062,38 +1062,140 @@ module Chart2D = /// Illustrates comparisons among individual items [] - static member Bar(keys, values, - [] ?Name, - [] ?ShowLegend, - [] ?Color, - [] ?Opacity, - [] ?Labels, - [] ?TextPosition, - [] ?TextFont, - [] ?Marker) = - let marker = - match Marker with - | Some marker -> marker |> TraceObjects.Marker.style(?Color=Color) - | Option.None -> TraceObjects.Marker.init (?Color=Color) - Trace2D.initBar (Trace2DStyle.Bar(X = values,Y = keys,Marker=marker,Orientation = StyleParam.Orientation.Horizontal)) - |> TraceStyle.TraceInfo(?Name=Name,?ShowLegend=ShowLegend,?Opacity=Opacity) - |> TraceStyle.TextLabel(?Text=Labels,?Textposition=TextPosition,?Textfont=TextFont) - |> GenericChart.ofTraceObject + static member Bar + ( + [] ?X : seq<#IConvertible>, + [] ?Y : seq<#IConvertible>, + [] ?Name : string , + [] ?ShowLegend : bool, + [] ?Color : Color , + [] ?Pattern : Pattern, + [] ?Base : #IConvertible, + [] ?Width : #IConvertible, + [] ?MultiWidth : seq<#IConvertible>, + [] ?Opacity : float, + [] ?MultiOpacity : seq, + [] ?Text : #IConvertible, + [] ?MultiText : seq<#IConvertible>, + [] ?TextPosition : StyleParam.TextPosition, + [] ?MultiTextPosition : seq, + [] ?TextFont : Font, + [] ?Marker : Marker + ) = + + let marker = + Marker + |> Option.defaultValue (TraceObjects.Marker.init()) + |> TraceObjects.Marker.style( + ?Color = Color, + ?Pattern = Pattern, + ?MultiOpacity = MultiOpacity + ) + Trace2D.initBar ( + Trace2DStyle.Bar( + ?X = X, + ?Y = Y, + Orientation = StyleParam.Orientation.Horizontal, + ?Name = Name , + ?ShowLegend = ShowLegend , + ?Base = Base , + ?Width = Width , + ?MultiWidth = MultiWidth , + ?Opacity = Opacity , + ?Text = Text , + ?MultiText = MultiText , + ?TextPosition = TextPosition , + ?MultiTextPosition = MultiTextPosition , + ?TextFont = TextFont , + Marker = marker + ) + ) + |> GenericChart.ofTraceObject + + [] + static member Bar + ( + keys: seq<#IConvertible>, + values: seq<#IConvertible>, + [] ?Name : string , + [] ?ShowLegend : bool, + [] ?Color : Color , + [] ?Pattern : Pattern, + [] ?Base : #IConvertible, + [] ?Width : #IConvertible, + [] ?MultiWidth : seq<#IConvertible>, + [] ?Opacity : float, + [] ?MultiOpacity : seq, + [] ?Text : #IConvertible, + [] ?MultiText : seq<#IConvertible>, + [] ?TextPosition : StyleParam.TextPosition, + [] ?MultiTextPosition : seq, + [] ?TextFont : Font, + [] ?Marker : Marker + ) = + Chart.Bar ( + X = values , + Y = keys , + ?Name = Name , + ?ShowLegend = ShowLegend , + ?Color = Color , + ?Pattern = Pattern , + ?Base = Base , + ?Width = Width , + ?MultiWidth = MultiWidth , + ?Opacity = Opacity , + ?MultiOpacity = MultiOpacity , + ?Text = Text , + ?MultiText = MultiText , + ?TextPosition = TextPosition , + ?MultiTextPosition = MultiTextPosition, + ?TextFont = TextFont , + ?Marker = Marker + ) + /// Illustrates comparisons among individual items [] - static member Bar(keysvalues, - [] ?Name, - [] ?ShowLegend, - [] ?Color, - [] ?Opacity, - [] ?Labels, - [] ?TextPosition, - [] ?TextFont, - [] ?Marker) = - let keys,values = Seq.unzip keysvalues - Chart.Bar(keys, values, ?Name=Name,?ShowLegend=ShowLegend,?Color=Color,?Opacity=Opacity,?Labels=Labels,?TextPosition=TextPosition,?TextFont=TextFont,?Marker=Marker) + static member Bar + ( + keysValues: seq<#IConvertible * #IConvertible>, + [] ?Name : string , + [] ?ShowLegend : bool, + [] ?Color : Color , + [] ?Pattern : Pattern, + [] ?Base : #IConvertible, + [] ?Width : #IConvertible, + [] ?MultiWidth : seq<#IConvertible>, + [] ?Opacity : float, + [] ?MultiOpacity : seq, + [] ?Text : #IConvertible, + [] ?MultiText : seq<#IConvertible>, + [] ?TextPosition : StyleParam.TextPosition, + [] ?MultiTextPosition : seq, + [] ?TextFont : Font, + [] ?Marker : Marker + ) = + let keys,values = Seq.unzip keysValues + Chart.Bar( + X = values , + Y = keys , + ?Name = Name , + ?ShowLegend = ShowLegend , + ?Color = Color , + ?Pattern = Pattern , + ?Base = Base , + ?Width = Width , + ?MultiWidth = MultiWidth , + ?Opacity = Opacity , + ?MultiOpacity = MultiOpacity , + ?Text = Text , + ?MultiText = MultiText , + ?TextPosition = TextPosition , + ?MultiTextPosition = MultiTextPosition, + ?TextFont = TextFont , + ?Marker = Marker + ) /// Displays series of tcolumn chart type as stacked bars. diff --git a/src/Plotly.NET/ChartAPI/Chart3D.fs b/src/Plotly.NET/ChartAPI/Chart3D.fs index 5b8ebc6d2..4b80768a7 100644 --- a/src/Plotly.NET/ChartAPI/Chart3D.fs +++ b/src/Plotly.NET/ChartAPI/Chart3D.fs @@ -221,7 +221,7 @@ module Chart3D = ) ) |> TraceStyle.TraceInfo(?Name=Name,?ShowLegend=ShowLegend,?Opacity=Opacity) - |> TraceStyle.Marker(?Color=Color,?Symbol=MarkerSymbol, MultiSizes=sizes) + |> TraceStyle.Marker(?Color=Color,?Symbol=MarkerSymbol, MultiSize=sizes) |> TraceStyle.TextLabel(?Text=Labels,?Textposition=TextPosition,?Textfont=TextFont) |> GenericChart.ofTraceObject diff --git a/src/Plotly.NET/ChartAPI/ChartPolar.fs b/src/Plotly.NET/ChartAPI/ChartPolar.fs index 70bfe8477..3d9febcf7 100644 --- a/src/Plotly.NET/ChartAPI/ChartPolar.fs +++ b/src/Plotly.NET/ChartAPI/ChartPolar.fs @@ -337,7 +337,7 @@ module ChartPolar = Mode = changeMode StyleParam.Mode.Markers ) >> TraceStyle.TraceInfo(?Name=Name,?ShowLegend=ShowLegend,?Opacity=Opacity) - >> TraceStyle.Marker(?Color=Color,?Symbol=MarkerSymbol,MultiSizes=sizes) + >> TraceStyle.Marker(?Color=Color,?Symbol=MarkerSymbol,MultiSize=sizes) >> TraceStyle.TextLabel(?Text=Labels,?Textposition=TextPosition,?Textfont=TextFont) let useWebGL = defaultArg UseWebGL false diff --git a/src/Plotly.NET/CommonAbstractions/StyleParams.fs b/src/Plotly.NET/CommonAbstractions/StyleParams.fs index e5d86b1f1..9a807288b 100644 --- a/src/Plotly.NET/CommonAbstractions/StyleParams.fs +++ b/src/Plotly.NET/CommonAbstractions/StyleParams.fs @@ -1602,6 +1602,46 @@ module StyleParam = // #P# //-------------------------- + + [] + type PatternFillMode = + | Replace | Overlay + + static member toString = function + | Replace -> "replace" + | Overlay -> "overlay" + + static member convert = PatternFillMode.toString >> box + override this.ToString() = this |> PatternFillMode.toString + member this.Convert() = this |> PatternFillMode.convert + + + [] + type PatternShape = + | None + | DiagonalDescending + | DiagonalAscending + | DiagonalChecked + | HorizontalLines + | VerticalLines + | Checked + | Dots + + static member toString = function + | None -> "" + | DiagonalDescending -> "/" + | DiagonalAscending -> """\""" + | DiagonalChecked -> "x" + | HorizontalLines -> "-" + | VerticalLines -> "|" + | Checked -> "+" + | Dots -> "." + + static member convert = PatternShape.toString >> box + override this.ToString() = this |> PatternShape.toString + member this.Convert() = this |> PatternShape.convert + + [] type PeriodAlignment = | Start | Middle | End diff --git a/src/Plotly.NET/Playground.fsx b/src/Plotly.NET/Playground.fsx index b0b488ad6..871c87c81 100644 --- a/src/Plotly.NET/Playground.fsx +++ b/src/Plotly.NET/Playground.fsx @@ -69,6 +69,7 @@ #I "Traces/ObjectAbstractions" #load "Gradient.fs" +#load "Pattern.fs" #load "Marker.fs" #load "Projection.fs" #load "Surface.fs" @@ -165,8 +166,8 @@ let crazyMarker = StyleParam.MarkerSymbol.Modified(StyleParam.MarkerSymbol.Square, StyleParam.SymbolStyle.Open) StyleParam.MarkerSymbol.Modified(StyleParam.MarkerSymbol.Hexagon2, StyleParam.SymbolStyle.Dot) ], - MultiSizes = [50;60;100;70], - MultiOpacities = [0.3; 0.6; 0.9; 1.], + MultiSize = [50;60;100;70], + MultiOpacity = [0.3; 0.6; 0.9; 1.], Color = Color.fromColorScaleValues [0.; 0.5; 1.; 0.8], Colorscale = StyleParam.Colorscale.Viridis, ShowScale = true @@ -177,6 +178,44 @@ Chart.Point [1,1; 2,2; 3,3; 4,4] |> Chart.show +let labels, values = + [ + "A", 1 + "B", 3 + "C", 2 + "D", 4 + "E", 6 + "F", 5 + "G", 7 + "H", 8 + ] + |> List.unzip + +Chart.Bar( + keys = labels, + values = values, + Color = Color.fromColorScaleValues values +) +|> Chart.withMarkerStyle( + Colorscale = StyleParam.Colorscale.Viridis, + ShowScale = true, + Pattern = Pattern.init( + MultiShapes = [ + StyleParam.PatternShape.None + StyleParam.PatternShape.DiagonalDescending + StyleParam.PatternShape.DiagonalAscending + StyleParam.PatternShape.DiagonalChecked + StyleParam.PatternShape.HorizontalLines + StyleParam.PatternShape.VerticalLines + StyleParam.PatternShape.Checked + StyleParam.PatternShape.Dots + ] + ) +) +|> Chart.show + + + Chart.Line([0.; 0.5; 1.; 2.; 2.2], y=[1.23; 2.5; 0.42; 3.; 1.]) |> Chart.withLayoutImage( LayoutImage.init( diff --git a/src/Plotly.NET/Plotly.NET.fsproj b/src/Plotly.NET/Plotly.NET.fsproj index 6a441a657..86d45c8a5 100644 --- a/src/Plotly.NET/Plotly.NET.fsproj +++ b/src/Plotly.NET/Plotly.NET.fsproj @@ -76,7 +76,9 @@ + + diff --git a/src/Plotly.NET/Traces/ObjectAbstractions/Marker.fs b/src/Plotly.NET/Traces/ObjectAbstractions/Marker.fs index 960c9c5a5..55e71d880 100644 --- a/src/Plotly.NET/Traces/ObjectAbstractions/Marker.fs +++ b/src/Plotly.NET/Traces/ObjectAbstractions/Marker.fs @@ -26,9 +26,10 @@ type Marker () = [] ?Gradient : Gradient, [] ?Outline : Line, [] ?Size : int, - [] ?MultiSizes : seq, + [] ?MultiSize : seq, [] ?Opacity : float, - [] ?MultiOpacities : seq, + [] ?Pattern : Pattern, + [] ?MultiOpacity : seq, [] ?Symbol : StyleParam.MarkerSymbol, [] ?MultiSymbols : seq, [] ?OutlierColor : Color, @@ -56,9 +57,10 @@ type Marker () = ?Gradient = Gradient , ?Outline = Outline , ?Size = Size , - ?MultiSizes = MultiSizes , + ?MultiSize = MultiSize , ?Opacity = Opacity , - ?MultiOpacities = MultiOpacities, + ?Pattern = Pattern , + ?MultiOpacity = MultiOpacity , ?Symbol = Symbol , ?MultiSymbols = MultiSymbols , ?OutlierColor = OutlierColor , @@ -86,9 +88,10 @@ type Marker () = [] ?Gradient : Gradient, [] ?Outline : Line, [] ?Size : int, - [] ?MultiSizes : seq, + [] ?MultiSize : seq, [] ?Opacity : float, - [] ?MultiOpacities : seq, + [] ?MultiOpacity : seq, + [] ?Pattern : Pattern, [] ?Symbol : StyleParam.MarkerSymbol, [] ?MultiSymbols : seq, [] ?OutlierColor : Color, @@ -113,8 +116,9 @@ type Marker () = Colorscale |> DynObj.setValueOptBy marker "colorscale" StyleParam.Colorscale.convert Gradient |> DynObj.setValueOpt marker "gradient" Outline |> DynObj.setValueOpt marker "line" - (Size, MultiSizes) |> DynObj.setSingleOrMultiOpt marker "size" - (Opacity, MultiOpacities) |> DynObj.setSingleOrMultiOpt marker "opacity" + (Size, MultiSize) |> DynObj.setSingleOrMultiOpt marker "size" + (Opacity, MultiOpacity) |> DynObj.setSingleOrMultiOpt marker "opacity" + Pattern |> DynObj.setValueOpt marker "pattern" (Symbol, MultiSymbols) |> DynObj.setSingleOrMultiOptBy marker "symbol" StyleParam.MarkerSymbol.convert OutlierColor |> DynObj.setValueOpt marker "outliercolor" Maxdisplayed |> DynObj.setValueOpt marker "maxdisplayed" diff --git a/src/Plotly.NET/Traces/ObjectAbstractions/Pattern.fs b/src/Plotly.NET/Traces/ObjectAbstractions/Pattern.fs new file mode 100644 index 000000000..417fb8526 --- /dev/null +++ b/src/Plotly.NET/Traces/ObjectAbstractions/Pattern.fs @@ -0,0 +1,73 @@ +namespace Plotly.NET.TraceObjects + +open Plotly.NET +open Plotly.NET.LayoutObjects +open DynamicObj +open System +open System.Runtime.InteropServices + +type Pattern () = + inherit DynamicObj () + + /// + /// + /// + /// When there is no colorscale sets the color of background pattern fill. Defaults to a `marker.color` background when `fillmode` is "overlay". Otherwise, defaults to a transparent background. + /// When there is no colorscale sets the color of foreground pattern fill. Defaults to a `marker.color` background when `fillmode` is "replace". Otherwise, defaults to dark grey or white to increase contrast with the `bgcolor`. + /// Sets the opacity of the foreground pattern fill. Defaults to a 0.5 when `fillmode` is "overlay". Otherwise, defaults to 1. + /// Determines whether `marker.color` should be used as a default to `bgcolor` or a `fgcolor`. + /// Sets the shape of the pattern fill. By default, no pattern is used for filling the area. + /// Sets the shape of the pattern fill. By default, no pattern is used for filling the area. + /// Sets the size of unit squares of the pattern fill in pixels, which corresponds to the interval of repetition of the pattern. + /// Sets the size of unit squares of the pattern fill in pixels, which corresponds to the interval of repetition of the pattern. + /// Sets the solidity of the pattern fill. Solidity is roughly the fraction of the area filled by the pattern. Solidity of 0 shows only the background color without pattern and solidty of 1 shows only the foreground color without pattern. + static member init + ( + ?BGColor : Color, + ?FGColor : Color, + ?FGOpacity : float, + ?FillMode : StyleParam.PatternFillMode, + ?Shape : StyleParam.PatternShape, + ?MultiShapes: seq, + ?Size : int, + ?MultiSize : seq, + ?Solidity : float + ) = + Pattern() + |> Pattern.style + ( + ?BGColor = BGColor , + ?FGColor = FGColor , + ?FGOpacity = FGOpacity , + ?FillMode = FillMode , + ?Shape = Shape , + ?MultiShapes = MultiShapes, + ?Size = Size , + ?MultiSize = MultiSize , + ?Solidity = Solidity + ) + + static member style + ( + ?BGColor : Color, + ?FGColor : Color, + ?FGOpacity : float, + ?FillMode : StyleParam.PatternFillMode, + ?Shape : StyleParam.PatternShape, + ?MultiShapes: seq, + ?Size : int, + ?MultiSize : seq, + ?Solidity : float + ) = + + fun (pattern: Pattern) -> + + BGColor |> DynObj.setValueOpt pattern "bgcolor" + FGColor |> DynObj.setValueOpt pattern "fgcolor" + FGOpacity |> DynObj.setValueOpt pattern "fgopacity" + FillMode |> DynObj.setValueOptBy pattern "fillmode" StyleParam.PatternFillMode.convert + (Shape, MultiShapes)|> DynObj.setSingleOrMultiOptBy pattern "shape" StyleParam.PatternShape.convert + (Size, MultiSize) |> DynObj.setSingleOrMultiOpt pattern "size" + Solidity |> DynObj.setValueOpt pattern "solidity" + + pattern diff --git a/src/Plotly.NET/Traces/Trace.fs b/src/Plotly.NET/Traces/Trace.fs index 1743cba09..0a89251c2 100644 --- a/src/Plotly.NET/Traces/Trace.fs +++ b/src/Plotly.NET/Traces/Trace.fs @@ -13,6 +13,9 @@ type Trace (traceTypeName) = // Implictit ITrace member val ``type`` = traceTypeName with get,set + static member tryGetTypedMember<'T> (propName:string) (trace: Trace) = + trace.TryGetTypedValue<'T>(propName) + //------------------------------------------------------------------------------------------------------------------------------------------------- /// Functions provide the styling of the Chart objects /// These functions are used internally to style traces of Chart objects. Users are usually pointed @@ -130,7 +133,6 @@ type TraceStyle() = trace ) - /// Sets the given Marker styles on the marker property of a Trace object static member Marker ( @@ -147,9 +149,10 @@ type TraceStyle() = [] ?Gradient : Gradient, [] ?Outline : Line, [] ?Size : int, - [] ?MultiSizes : seq, + [] ?MultiSize : seq, [] ?Opacity : float, - [] ?MultiOpacities : seq, + [] ?MultiOpacity : seq, + [] ?Pattern : Pattern, [] ?Symbol : StyleParam.MarkerSymbol, [] ?MultiSymbols : seq, [] ?OutlierColor : Color, @@ -162,10 +165,9 @@ type TraceStyle() = ) = (fun (trace:('T :> Trace)) -> let marker = - match (trace.TryGetValue "marker") with - | Some m -> m :?> Marker - | None -> Marker () - + trace + |> Trace.tryGetTypedMember "marker" + |> Option.defaultValue (Marker.init()) |> Marker.style( ?AutoColorScale = AutoColorScale, ?CAuto = CAuto , @@ -180,9 +182,10 @@ type TraceStyle() = ?Gradient = Gradient , ?Outline = Outline , ?Size = Size , - ?MultiSizes = MultiSizes , + ?MultiSize = MultiSize , ?Opacity = Opacity , - ?MultiOpacities = MultiOpacities, + ?MultiOpacity = MultiOpacity , + ?Pattern = Pattern , ?Symbol = Symbol , ?MultiSymbols = MultiSymbols , ?OutlierColor = OutlierColor , @@ -191,7 +194,7 @@ type TraceStyle() = ?ShowScale = ShowScale , ?SizeMin = SizeMin , ?SizeMode = SizeMode , - ?SizeRef = SizeRef + ?SizeRef = SizeRef ) trace.SetValue("marker", marker) diff --git a/src/Plotly.NET/Traces/Trace2D.fs b/src/Plotly.NET/Traces/Trace2D.fs index cc2fba620..52cde67f6 100644 --- a/src/Plotly.NET/Traces/Trace2D.fs +++ b/src/Plotly.NET/Traces/Trace2D.fs @@ -147,11 +147,16 @@ type Trace2DStyle() = /// Alternate to `y`. Builds a linear space of y coordinates. Use with `dy` where `y0` is the starting coordinate and `dy` the step. /// Sets the y coordinate step. See `y0` for more info. /// 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. + /// 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. /// Sets the positions of the `text` elements with respects to the (x,y) coordinates. + /// Sets the positions of the `text` elements with respects to the (x,y) coordinates. /// Template string used for rendering the information text that appear on points. Note that this will override `textinfo`. Variables are inserted using %{variable}, for example "y: %{y}". Numbers are formatted using d3-format's syntax %{variable:d3-format}, for example "Price: %{y:$.2f}". https://github.com/d3/d3-format/tree/v1.4.5#d3-format for details on the formatting syntax. Dates are formatted using d3-time-format's syntax %{variable|d3-time-format}, for example "Day: %{2019-01-01|%A}". https://github.com/d3/d3-time-format/tree/v2.2.3#locale_format for details on the date formatting syntax. Every attributes that can be specified per-point (the ones that are `arrayOk: true`) are available. + /// Template string used for rendering the information text that appear on points. Note that this will override `textinfo`. Variables are inserted using %{variable}, for example "y: %{y}". Numbers are formatted using d3-format's syntax %{variable:d3-format}, for example "Price: %{y:$.2f}". https://github.com/d3/d3-format/tree/v1.4.5#d3-format for details on the formatting syntax. Dates are formatted using d3-time-format's syntax %{variable|d3-time-format}, for example "Day: %{2019-01-01|%A}". https://github.com/d3/d3-time-format/tree/v2.2.3#locale_format for details on the date formatting syntax. Every attributes that can be specified per-point (the ones that are `arrayOk: true`) are available. /// Sets hover 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. To be seen, trace `hoverinfo` must contain a "text" flag. + /// Sets hover 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. To be seen, trace `hoverinfo` must contain a "text" flag. /// Determines which trace information appear on hover. If `none` or `skip` are set, no information is displayed upon hovering. But, if `none` is set, click and hover events are still fired. /// Template string used for rendering the information that appear on hover box. Note that this will override `hoverinfo`. Variables are inserted using %{variable}, for example "y: %{y}" as well as %{xother}, {%_xother}, {%_xother_}, {%xother_}. When showing info for several points, "xother" will be added to those with different x positions from the first point. An underscore before or after "(x|y)other" will add a space on that side, only when this field is shown. Numbers are formatted using d3-format's syntax %{variable:d3-format}, for example "Price: %{y:$.2f}". https://github.com/d3/d3-format/tree/v1.4.5#d3-format for details on the formatting syntax. Dates are formatted using d3-time-format's syntax %{variable|d3-time-format}, for example "Day: %{2019-01-01|%A}". https://github.com/d3/d3-time-format/tree/v2.2.3#locale_format for details on the date formatting syntax. The variables available in `hovertemplate` are the ones emitted as event data described at this link https://plotly.com/javascript/plotlyjs-events/#event-data. Additionally, every attributes that can be specified per-point (the ones that are `arrayOk: true`) are available. variable `norm` Anything contained in tag `<extra>` is displayed in the secondary box, for example "<extra>{fullData.name}</extra>". To hide the secondary box completely, use an empty tag `<extra></extra>`. + /// Template string used for rendering the information that appear on hover box. Note that this will override `hoverinfo`. Variables are inserted using %{variable}, for example "y: %{y}" as well as %{xother}, {%_xother}, {%_xother_}, {%xother_}. When showing info for several points, "xother" will be added to those with different x positions from the first point. An underscore before or after "(x|y)other" will add a space on that side, only when this field is shown. Numbers are formatted using d3-format's syntax %{variable:d3-format}, for example "Price: %{y:$.2f}". https://github.com/d3/d3-format/tree/v1.4.5#d3-format for details on the formatting syntax. Dates are formatted using d3-time-format's syntax %{variable|d3-time-format}, for example "Day: %{2019-01-01|%A}". https://github.com/d3/d3-time-format/tree/v2.2.3#locale_format for details on the date formatting syntax. The variables available in `hovertemplate` are the ones emitted as event data described at this link https://plotly.com/javascript/plotlyjs-events/#event-data. Additionally, every attributes that can be specified per-point (the ones that are `arrayOk: true`) are available. variable `norm` Anything contained in tag `<extra>` is displayed in the secondary box, for example "<extra>{fullData.name}</extra>". To hide the secondary box completely, use an empty tag `<extra></extra>`. /// Sets the hover text formatting rulefor `x` using d3 formatting mini-languages which are very similar to those in Python. For numbers, see: https://github.com/d3/d3-format/tree/v1.4.5#d3-format. And for dates see: https://github.com/d3/d3-time-format/tree/v2.2.3#locale_format. We add two items to d3's date formatter: "%h" for half of the year as a decimal number as well as "%{n}f" for fractional seconds with n digits. For example, "2016-10-13 09:15:23.456" with tickformat "%H~%M~%S.%2f" would display "09~15~23.46"By default the values are formatted using `xaxis.hoverformat`. /// Sets the hover text formatting rulefor `y` using d3 formatting mini-languages which are very similar to those in Python. For numbers, see: https://github.com/d3/d3-format/tree/v1.4.5#d3-format. And for dates see: https://github.com/d3/d3-time-format/tree/v2.2.3#locale_format. We add two items to d3's date formatter: "%h" for half of the year as a decimal number as well as "%{n}f" for fractional seconds with n digits. For example, "2016-10-13 09:15:23.456" with tickformat "%H~%M~%S.%2f" would display "09~15~23.46"By default the values are formatted using `xaxis.hoverformat`. /// Assigns extra meta information associated with this trace that can be used in various text attributes. Attributes such as trace `name`, graph, axis and colorbar `title.text`, annotation `text` `rangeselector`, `updatemenues` and `sliders` `label` text all support `meta`. To access the trace `meta` values in an attribute in the same trace, simply use `%{meta[i]}` where `i` is the index or key of the `meta` item in question. To access trace `meta` in layout attributes, use `%{data[n[.meta[i]}` where `i` is the index or key of the `meta` and `n` is the trace index. @@ -185,7 +190,7 @@ type Trace2DStyle() = /// Sets the calendar system to use with `x` date data. /// Sets the calendar system to use with `y` date data. /// Controls persistence of some user-driven changes to the trace: `constraintrange` in `parcoords` traces, as well as some `editable: true` modifications such as `name` and `colorbar.title`. Defaults to `layout.uirevision`. Note that other user-driven trace attribute changes are controlled by `layout` attributes: `trace.visible` is controlled by `layout.legend.uirevision`, `selectedpoints` is controlled by `layout.selectionrevision`, and `colorbar.(x|y)` (accessible with `config: {editable: true}`) is controlled by `layout.editrevision`. Trace changes are tracked by `uid`, which only falls back on trace index if no `uid` is provided. So if your app can add/remove traces before the end of the `data` array, such that the same trace has a different index, you can still preserve user-driven changes if you give each trace a `uid` that stays with it as it moves. - static member inline Scatter + static member Scatter ( [] ?Name : string, [] ?Visible : StyleParam.Visible, @@ -202,12 +207,17 @@ type Trace2DStyle() = [] ?Y : seq<#IConvertible>, [] ?Y0 : #IConvertible, [] ?DY : #IConvertible, - [] ?Text : seq<#IConvertible>, + [] ?Text : #IConvertible, + [] ?MultiText : seq<#IConvertible>, [] ?TextPosition : StyleParam.TextPosition, + [] ?MultiTextPosition : seq, [] ?TextTemplate : string, + [] ?MultiTextTemplate : seq, [] ?HoverText : string, + [] ?MultiHoverText : seq, [] ?HoverInfo : StyleParam.HoverInfo, [] ?HoverTemplate : string, + [] ?MultiHoverTemplate : seq, [] ?XHoverFormat : string, [] ?YHoverFormat : string, [] ?Meta : string, @@ -244,60 +254,60 @@ type Trace2DStyle() = ) = (fun (trace:('T :> Trace)) -> - Name |> DynObj.setValueOpt trace "name" - Visible |> DynObj.setValueOptBy trace "visible" StyleParam.Visible.convert - ShowLegend |> DynObj.setValueOpt trace "showlegend" - LegendRank |> DynObj.setValueOpt trace "legendrank" - LegendGroup |> DynObj.setValueOpt trace "legendgroup" - LegendGroupTitle |> DynObj.setValueOpt trace "legendgrouptitle" - Opacity |> DynObj.setValueOpt trace "opacity" - Mode |> DynObj.setValueOptBy trace "mode" StyleParam.Mode.convert - Ids |> DynObj.setValueOpt trace "ids" - X |> DynObj.setValueOpt trace "x" - X0 |> DynObj.setValueOpt trace "x0" - DX |> DynObj.setValueOpt trace "dx" - Y |> DynObj.setValueOpt trace "y" - Y0 |> DynObj.setValueOpt trace "y0" - DY |> DynObj.setValueOpt trace "dy" - Text |> DynObj.setValueOpt trace "text" - TextPosition |> DynObj.setValueOptBy trace "textposition" StyleParam.TextPosition.convert - TextTemplate |> DynObj.setValueOpt trace "texttemplate" - HoverText |> DynObj.setValueOpt trace "hovertext" - HoverInfo |> DynObj.setValueOptBy trace "hoverinfo" StyleParam.HoverInfo.convert - HoverTemplate |> DynObj.setValueOpt trace "hovertemplate" - XHoverFormat |> DynObj.setValueOpt trace "xhoverformat" - YHoverFormat |> DynObj.setValueOpt trace "yhoverformat" - Meta |> DynObj.setValueOpt trace "meta" - CustomData |> DynObj.setValueOpt trace "customdata" - XAxis |> DynObj.setValueOptBy trace "xaxis" StyleParam.LinearAxisId.convert - YAxis |> DynObj.setValueOptBy trace "yaxis" StyleParam.LinearAxisId.convert - Orientation |> DynObj.setValueOptBy trace "orientation" StyleParam.Orientation.convert - GroupNorm |> DynObj.setValueOptBy trace "groupnorm" StyleParam.GroupNorm.convert - StackGroup |> DynObj.setValueOpt trace "stackgroup" - XPeriod |> DynObj.setValueOpt trace "xperiod" - XPeriodAlignment |> DynObj.setValueOptBy trace "xperiodalignment" StyleParam.PeriodAlignment.convert - XPeriod0 |> DynObj.setValueOpt trace "xperiod0" - YPeriod |> DynObj.setValueOpt trace "yperiod" - YPeriodAlignment |> DynObj.setValueOptBy trace "yperiodalignment" StyleParam.PeriodAlignment.convert - YPeriod0 |> DynObj.setValueOpt trace "yperiod0" - Marker |> DynObj.setValueOpt trace "marker" - Line |> DynObj.setValueOpt trace "line" - TextFont |> DynObj.setValueOpt trace "textfont" - ErrorX |> DynObj.setValueOpt trace "error_x" - ErrorY |> DynObj.setValueOpt trace "error_y" - SelectedPoints |> DynObj.setValueOpt trace "selectedpoints" - Selected |> DynObj.setValueOpt trace "selected" - Unselected |> DynObj.setValueOpt trace "unselected" - ClipOnAxis |> DynObj.setValueOpt trace "cliponaxis" - ConnectGaps |> DynObj.setValueOpt trace "connectgaps" - Fill |> DynObj.setValueOptBy trace "fill" StyleParam.Fill.convert - FillColor |> DynObj.setValueOpt trace "fillcolor" - HoverLabel |> DynObj.setValueOpt trace "hoverlabel" - HoverOn |> DynObj.setValueOptBy trace "hoveron" StyleParam.HoverOn.convert - StackGaps |> DynObj.setValueOptBy trace "stackgaps" StyleParam.StackGaps.convert - XCalendar |> DynObj.setValueOptBy trace "xcalendar" StyleParam.Calendar.convert - YCalendar |> DynObj.setValueOptBy trace "ycalendar" StyleParam.Calendar.convert - UIRevision |> DynObj.setValueOpt trace "uirevision" + Name |> DynObj.setValueOpt trace "name" + Visible |> DynObj.setValueOptBy trace "visible" StyleParam.Visible.convert + ShowLegend |> DynObj.setValueOpt trace "showlegend" + LegendRank |> DynObj.setValueOpt trace "legendrank" + LegendGroup |> DynObj.setValueOpt trace "legendgroup" + LegendGroupTitle |> DynObj.setValueOpt trace "legendgrouptitle" + Opacity |> DynObj.setValueOpt trace "opacity" + Mode |> DynObj.setValueOptBy trace "mode" StyleParam.Mode.convert + Ids |> DynObj.setValueOpt trace "ids" + X |> DynObj.setValueOpt trace "x" + X0 |> DynObj.setValueOpt trace "x0" + DX |> DynObj.setValueOpt trace "dx" + Y |> DynObj.setValueOpt trace "y" + Y0 |> DynObj.setValueOpt trace "y0" + DY |> DynObj.setValueOpt trace "dy" + (Text, MultiText) |> DynObj.setSingleOrMultiOpt trace "text" + (TextPosition, MultiTextPosition) |> DynObj.setSingleOrMultiOptBy trace "textposition" StyleParam.TextPosition.convert + (TextTemplate, MultiTextTemplate) |> DynObj.setSingleOrMultiOpt trace "texttemplate" + (HoverText, MultiHoverText) |> DynObj.setSingleOrMultiOpt trace "hovertext" + HoverInfo |> DynObj.setValueOptBy trace "hoverinfo" StyleParam.HoverInfo.convert + (HoverTemplate, MultiHoverTemplate) |> DynObj.setSingleOrMultiOpt trace "hovertemplate" + XHoverFormat |> DynObj.setValueOpt trace "xhoverformat" + YHoverFormat |> DynObj.setValueOpt trace "yhoverformat" + Meta |> DynObj.setValueOpt trace "meta" + CustomData |> DynObj.setValueOpt trace "customdata" + XAxis |> DynObj.setValueOptBy trace "xaxis" StyleParam.LinearAxisId.convert + YAxis |> DynObj.setValueOptBy trace "yaxis" StyleParam.LinearAxisId.convert + Orientation |> DynObj.setValueOptBy trace "orientation" StyleParam.Orientation.convert + GroupNorm |> DynObj.setValueOptBy trace "groupnorm" StyleParam.GroupNorm.convert + StackGroup |> DynObj.setValueOpt trace "stackgroup" + XPeriod |> DynObj.setValueOpt trace "xperiod" + XPeriodAlignment |> DynObj.setValueOptBy trace "xperiodalignment" StyleParam.PeriodAlignment.convert + XPeriod0 |> DynObj.setValueOpt trace "xperiod0" + YPeriod |> DynObj.setValueOpt trace "yperiod" + YPeriodAlignment |> DynObj.setValueOptBy trace "yperiodalignment" StyleParam.PeriodAlignment.convert + YPeriod0 |> DynObj.setValueOpt trace "yperiod0" + Marker |> DynObj.setValueOpt trace "marker" + Line |> DynObj.setValueOpt trace "line" + TextFont |> DynObj.setValueOpt trace "textfont" + ErrorX |> DynObj.setValueOpt trace "error_x" + ErrorY |> DynObj.setValueOpt trace "error_y" + SelectedPoints |> DynObj.setValueOpt trace "selectedpoints" + Selected |> DynObj.setValueOpt trace "selected" + Unselected |> DynObj.setValueOpt trace "unselected" + ClipOnAxis |> DynObj.setValueOpt trace "cliponaxis" + ConnectGaps |> DynObj.setValueOpt trace "connectgaps" + Fill |> DynObj.setValueOptBy trace "fill" StyleParam.Fill.convert + FillColor |> DynObj.setValueOpt trace "fillcolor" + HoverLabel |> DynObj.setValueOpt trace "hoverlabel" + HoverOn |> DynObj.setValueOptBy trace "hoveron" StyleParam.HoverOn.convert + StackGaps |> DynObj.setValueOptBy trace "stackgaps" StyleParam.StackGaps.convert + XCalendar |> DynObj.setValueOptBy trace "xcalendar" StyleParam.Calendar.convert + YCalendar |> DynObj.setValueOptBy trace "ycalendar" StyleParam.Calendar.convert + UIRevision |> DynObj.setValueOpt trace "uirevision" trace ) @@ -320,12 +330,21 @@ type Trace2DStyle() = [] ?Y0 : #IConvertible, [] ?DY : #IConvertible, [] ?Base : #IConvertible, - [] ?Text : seq<#IConvertible>, + [] ?Width : #IConvertible, + [] ?MultiWidth : seq<#IConvertible>, + [] ?Offset : #IConvertible, + [] ?MultiOffset : seq<#IConvertible>, + [] ?Text : #IConvertible, + [] ?MultiText : seq<#IConvertible>, [] ?TextPosition : StyleParam.TextPosition, + [] ?MultiTextPosition : seq, [] ?TextTemplate : string, + [] ?MultiTextTemplate : seq, [] ?HoverText : string, + [] ?MultiHoverText : seq, [] ?HoverInfo : StyleParam.HoverInfo, [] ?HoverTemplate : string, + [] ?MultiHoverTemplate: seq, [] ?XHoverFormat : string, [] ?YHoverFormat : string, [] ?Meta : string, diff --git a/tests/Plotly.NET.Tests/HtmlCodegen/SimpleCharts.fs b/tests/Plotly.NET.Tests/HtmlCodegen/SimpleCharts.fs index f5bce67c2..3c366b44c 100644 --- a/tests/Plotly.NET.Tests/HtmlCodegen/SimpleCharts.fs +++ b/tests/Plotly.NET.Tests/HtmlCodegen/SimpleCharts.fs @@ -78,19 +78,19 @@ let ``Line and scatter plots`` = let columnChart = let values = [20; 14; 23;] let keys = ["Product A"; "Product B"; "Product C";] - Chart.Column(keys, values) + Chart.Column(keys = keys, values = values) let barChart = let values = [20; 14; 23;] let keys = ["Product A"; "Product B"; "Product C";] - Chart.Bar(keys, values) + Chart.Bar(keys = keys, values = values) let stackedBarChart = let values = [20; 14; 23;] let keys = ["Product A"; "Product B"; "Product C";] [ - Chart.StackedBar(keys,values,Name="old"); - Chart.StackedBar(keys,[8; 21; 13;],Name="new") + Chart.StackedBar(keys = keys, values = values,Name="old"); + Chart.StackedBar(keys = keys, values = [8; 21; 13;],Name="new") ] |> Chart.combine From dd1549190bd9f0d79b49df12c0e7532af9119b30 Mon Sep 17 00:00:00 2001 From: Kevin Schneider Date: Wed, 22 Sep 2021 11:17:32 +0200 Subject: [PATCH 05/12] Fix Bar overload signatures --- src/Plotly.NET/ChartAPI/Chart2D.fs | 53 ++++-------------------------- src/Plotly.NET/Playground.fsx | 3 +- 2 files changed, 7 insertions(+), 49 deletions(-) diff --git a/src/Plotly.NET/ChartAPI/Chart2D.fs b/src/Plotly.NET/ChartAPI/Chart2D.fs index 6e55a1677..96b89eb1a 100644 --- a/src/Plotly.NET/ChartAPI/Chart2D.fs +++ b/src/Plotly.NET/ChartAPI/Chart2D.fs @@ -1064,8 +1064,8 @@ module Chart2D = [] static member Bar ( - [] ?X : seq<#IConvertible>, - [] ?Y : seq<#IConvertible>, + values: seq<#IConvertible>, + [] ?Keys : seq<#IConvertible>, [] ?Name : string , [] ?ShowLegend : bool, [] ?Color : Color , @@ -1095,8 +1095,8 @@ module Chart2D = Trace2D.initBar ( Trace2DStyle.Bar( - ?X = X, - ?Y = Y, + X = values, + ?Y = Keys, Orientation = StyleParam.Orientation.Horizontal, ?Name = Name , ?ShowLegend = ShowLegend , @@ -1114,47 +1114,6 @@ module Chart2D = ) |> GenericChart.ofTraceObject - [] - static member Bar - ( - keys: seq<#IConvertible>, - values: seq<#IConvertible>, - [] ?Name : string , - [] ?ShowLegend : bool, - [] ?Color : Color , - [] ?Pattern : Pattern, - [] ?Base : #IConvertible, - [] ?Width : #IConvertible, - [] ?MultiWidth : seq<#IConvertible>, - [] ?Opacity : float, - [] ?MultiOpacity : seq, - [] ?Text : #IConvertible, - [] ?MultiText : seq<#IConvertible>, - [] ?TextPosition : StyleParam.TextPosition, - [] ?MultiTextPosition : seq, - [] ?TextFont : Font, - [] ?Marker : Marker - ) = - Chart.Bar ( - X = values , - Y = keys , - ?Name = Name , - ?ShowLegend = ShowLegend , - ?Color = Color , - ?Pattern = Pattern , - ?Base = Base , - ?Width = Width , - ?MultiWidth = MultiWidth , - ?Opacity = Opacity , - ?MultiOpacity = MultiOpacity , - ?Text = Text , - ?MultiText = MultiText , - ?TextPosition = TextPosition , - ?MultiTextPosition = MultiTextPosition, - ?TextFont = TextFont , - ?Marker = Marker - ) - /// Illustrates comparisons among individual items [] static member Bar @@ -1178,8 +1137,8 @@ module Chart2D = ) = let keys,values = Seq.unzip keysValues Chart.Bar( - X = values , - Y = keys , + values, + keys, ?Name = Name , ?ShowLegend = ShowLegend , ?Color = Color , diff --git a/src/Plotly.NET/Playground.fsx b/src/Plotly.NET/Playground.fsx index 871c87c81..1370199db 100644 --- a/src/Plotly.NET/Playground.fsx +++ b/src/Plotly.NET/Playground.fsx @@ -192,8 +192,7 @@ let labels, values = |> List.unzip Chart.Bar( - keys = labels, - values = values, + values, Color = Color.fromColorScaleValues values ) |> Chart.withMarkerStyle( From c9b90e12ba3539fff8c1c7eb30f5fff94351463d Mon Sep 17 00:00:00 2001 From: Kevin Schneider Date: Thu, 23 Sep 2021 09:24:54 +0200 Subject: [PATCH 06/12] Remove duplicate file reference --- src/Plotly.NET/Plotly.NET.fsproj | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Plotly.NET/Plotly.NET.fsproj b/src/Plotly.NET/Plotly.NET.fsproj index 86d45c8a5..2cfa6ae19 100644 --- a/src/Plotly.NET/Plotly.NET.fsproj +++ b/src/Plotly.NET/Plotly.NET.fsproj @@ -78,7 +78,6 @@ - From cf2d92734d0883dba433fe81d1c2712285cb28d8 Mon Sep 17 00:00:00 2001 From: Kevin Schneider Date: Thu, 23 Sep 2021 09:47:05 +0200 Subject: [PATCH 07/12] Add multiValue support for bar traces --- src/Plotly.NET/Traces/Trace2D.fs | 108 ++++++++++++++++--------------- 1 file changed, 55 insertions(+), 53 deletions(-) diff --git a/src/Plotly.NET/Traces/Trace2D.fs b/src/Plotly.NET/Traces/Trace2D.fs index 52cde67f6..194fbe6d7 100644 --- a/src/Plotly.NET/Traces/Trace2D.fs +++ b/src/Plotly.NET/Traces/Trace2D.fs @@ -381,59 +381,61 @@ type Trace2DStyle() = ) = (fun (bar:('T :> Trace)) -> - Name |> DynObj.setValueOpt bar "name" - Visible |> DynObj.setValueOptBy bar "visible" StyleParam.Visible.convert - ShowLegend |> DynObj.setValueOpt bar "showlegend" - LegendRank |> DynObj.setValueOpt bar "legendrank" - LegendGroup |> DynObj.setValueOpt bar "legendgroup" - LegendGroupTitle |> DynObj.setValueOpt bar "legendgrouptitle" - Opacity |> DynObj.setValueOpt bar "opacity" - Ids |> DynObj.setValueOpt bar "ids" - X |> DynObj.setValueOpt bar "x" - X0 |> DynObj.setValueOpt bar "x0" - DX |> DynObj.setValueOpt bar "dx" - Y |> DynObj.setValueOpt bar "y" - Y0 |> DynObj.setValueOpt bar "y0" - DY |> DynObj.setValueOpt bar "dy" - Base |> DynObj.setValueOpt bar "base" - Text |> DynObj.setValueOpt bar "text" - TextPosition |> DynObj.setValueOptBy bar "textposition" StyleParam.TextPosition.convert - TextTemplate |> DynObj.setValueOpt bar "texttemplate" - HoverText |> DynObj.setValueOpt bar "hovertext" - HoverInfo |> DynObj.setValueOptBy bar "hoverinfo" StyleParam.HoverInfo.convert - HoverTemplate |> DynObj.setValueOpt bar "hovertemplate" - XHoverFormat |> DynObj.setValueOpt bar "xhoverformat" - YHoverFormat |> DynObj.setValueOpt bar "yhoverformat" - Meta |> DynObj.setValueOpt bar "meta" - CustomData |> DynObj.setValueOpt bar "customdata" - XAxis |> DynObj.setValueOptBy bar "xaxis" StyleParam.LinearAxisId.convert - YAxis |> DynObj.setValueOptBy bar "yaxis" StyleParam.LinearAxisId.convert - Orientation |> DynObj.setValueOptBy bar "orientation" StyleParam.Orientation.convert - AlignmentGroup |> DynObj.setValueOpt bar "alignmentgroup" - OffsetGroup |> DynObj.setValueOpt bar "offsetgroup" - XPeriod |> DynObj.setValueOpt bar "xperiod" - XPeriodAlignment |> DynObj.setValueOptBy bar "xperiodalignment" StyleParam.PeriodAlignment.convert - XPeriod0 |> DynObj.setValueOpt bar "xperiod0" - YPeriod |> DynObj.setValueOpt bar "yperiod" - YPeriodAlignment |> DynObj.setValueOptBy bar "yperiodalignment" StyleParam.PeriodAlignment.convert - YPeriod0 |> DynObj.setValueOpt bar "yperiod0" - Marker |> DynObj.setValueOpt bar "marker" - TextAngle |> DynObj.setValueOpt bar "textangle" - TextFont |> DynObj.setValueOpt bar "textfont" - ErrorX |> DynObj.setValueOpt bar "errorx" - ErrorY |> DynObj.setValueOpt bar "errory" - SelectedPoints |> DynObj.setValueOpt bar "selectedpoints" - Selected |> DynObj.setValueOpt bar "selected" - Unselected |> DynObj.setValueOpt bar "unselected" - ClipOnAxis |> DynObj.setValueOpt bar "cliponaxis" - Constraintext |> DynObj.setValueOptBy bar "constraintext" StyleParam.ConstrainText.convert - HoverLabel |> DynObj.setValueOpt bar "hoverlabel" - InsideTextAnchor |> DynObj.setValueOptBy bar "insidetextanchor" StyleParam.InsideTextAnchor.convert - InsideTextFont |> DynObj.setValueOpt bar "insidetextfont" - OutsideTextFont |> DynObj.setValueOpt bar "outsidetextfont" - XCalendar |> DynObj.setValueOptBy bar "xcalendar" StyleParam.Calendar.convert - YCalendar |> DynObj.setValueOptBy bar "ycalendar" StyleParam.Calendar.convert - UIRevision |> DynObj.setValueOpt bar "uirevision" + Name |> DynObj.setValueOpt bar "name" + Visible |> DynObj.setValueOptBy bar "visible" StyleParam.Visible.convert + ShowLegend |> DynObj.setValueOpt bar "showlegend" + LegendRank |> DynObj.setValueOpt bar "legendrank" + LegendGroup |> DynObj.setValueOpt bar "legendgroup" + LegendGroupTitle |> DynObj.setValueOpt bar "legendgrouptitle" + Opacity |> DynObj.setValueOpt bar "opacity" + Ids |> DynObj.setValueOpt bar "ids" + X |> DynObj.setValueOpt bar "x" + X0 |> DynObj.setValueOpt bar "x0" + DX |> DynObj.setValueOpt bar "dx" + Y |> DynObj.setValueOpt bar "y" + Y0 |> DynObj.setValueOpt bar "y0" + DY |> DynObj.setValueOpt bar "dy" + Base |> DynObj.setValueOpt bar "base" + (Width, MultiWidth) |> DynObj.setSingleOrMultiOpt bar "width" + (Offset, MultiOffset) |> DynObj.setSingleOrMultiOpt bar "offset" + (Text, MultiText) |> DynObj.setSingleOrMultiOpt bar "text" + (TextPosition, MultiTextPosition) |> DynObj.setSingleOrMultiOptBy bar "textposition" StyleParam.TextPosition.convert + (TextTemplate, MultiTextTemplate) |> DynObj.setSingleOrMultiOpt bar "texttemplate" + (HoverText, MultiHoverText) |> DynObj.setSingleOrMultiOpt bar "hovertext" + HoverInfo |> DynObj.setValueOptBy bar "hoverinfo" StyleParam.HoverInfo.convert + (HoverTemplate, MultiHoverTemplate) |> DynObj.setSingleOrMultiOpt bar "hovertemplate" + XHoverFormat |> DynObj.setValueOpt bar "xhoverformat" + YHoverFormat |> DynObj.setValueOpt bar "yhoverformat" + Meta |> DynObj.setValueOpt bar "meta" + CustomData |> DynObj.setValueOpt bar "customdata" + XAxis |> DynObj.setValueOptBy bar "xaxis" StyleParam.LinearAxisId.convert + YAxis |> DynObj.setValueOptBy bar "yaxis" StyleParam.LinearAxisId.convert + Orientation |> DynObj.setValueOptBy bar "orientation" StyleParam.Orientation.convert + AlignmentGroup |> DynObj.setValueOpt bar "alignmentgroup" + OffsetGroup |> DynObj.setValueOpt bar "offsetgroup" + XPeriod |> DynObj.setValueOpt bar "xperiod" + XPeriodAlignment |> DynObj.setValueOptBy bar "xperiodalignment" StyleParam.PeriodAlignment.convert + XPeriod0 |> DynObj.setValueOpt bar "xperiod0" + YPeriod |> DynObj.setValueOpt bar "yperiod" + YPeriodAlignment |> DynObj.setValueOptBy bar "yperiodalignment" StyleParam.PeriodAlignment.convert + YPeriod0 |> DynObj.setValueOpt bar "yperiod0" + Marker |> DynObj.setValueOpt bar "marker" + TextAngle |> DynObj.setValueOpt bar "textangle" + TextFont |> DynObj.setValueOpt bar "textfont" + ErrorX |> DynObj.setValueOpt bar "errorx" + ErrorY |> DynObj.setValueOpt bar "errory" + SelectedPoints |> DynObj.setValueOpt bar "selectedpoints" + Selected |> DynObj.setValueOpt bar "selected" + Unselected |> DynObj.setValueOpt bar "unselected" + ClipOnAxis |> DynObj.setValueOpt bar "cliponaxis" + Constraintext |> DynObj.setValueOptBy bar "constraintext" StyleParam.ConstrainText.convert + HoverLabel |> DynObj.setValueOpt bar "hoverlabel" + InsideTextAnchor |> DynObj.setValueOptBy bar "insidetextanchor" StyleParam.InsideTextAnchor.convert + InsideTextFont |> DynObj.setValueOpt bar "insidetextfont" + OutsideTextFont |> DynObj.setValueOpt bar "outsidetextfont" + XCalendar |> DynObj.setValueOptBy bar "xcalendar" StyleParam.Calendar.convert + YCalendar |> DynObj.setValueOptBy bar "ycalendar" StyleParam.Calendar.convert + UIRevision |> DynObj.setValueOpt bar "uirevision" bar From b2274835d55246b7e244054be0bde7cb97d3447d Mon Sep 17 00:00:00 2001 From: Kevin Schneider Date: Thu, 23 Sep 2021 09:47:25 +0200 Subject: [PATCH 08/12] Rework Column Chart constructors --- src/Plotly.NET/ChartAPI/Chart2D.fs | 362 +++++++++++++++++++++-------- 1 file changed, 261 insertions(+), 101 deletions(-) diff --git a/src/Plotly.NET/ChartAPI/Chart2D.fs b/src/Plotly.NET/ChartAPI/Chart2D.fs index 96b89eb1a..e558d2e99 100644 --- a/src/Plotly.NET/ChartAPI/Chart2D.fs +++ b/src/Plotly.NET/ChartAPI/Chart2D.fs @@ -982,87 +982,195 @@ module Chart2D = ) |> GenericChart.ofTraceObject - /// Illustrates comparisons among individual items [] - static member Column(keys, values, - [] ?Name, - [] ?ShowLegend, - [] ?Color, - [] ?Opacity, - [] ?Labels, - [] ?TextPosition, - [] ?TextFont, - [] ?Marker: Marker) = + static member Bar + ( + values: seq<#IConvertible>, + [] ?Keys : seq<#IConvertible>, + [] ?Name : string , + [] ?ShowLegend : bool, + [] ?Color : Color , + [] ?Pattern : Pattern, + [] ?Base : #IConvertible, + [] ?Width : #IConvertible, + [] ?MultiWidth : seq<#IConvertible>, + [] ?Opacity : float, + [] ?MultiOpacity : seq, + [] ?Text : #IConvertible, + [] ?MultiText : seq<#IConvertible>, + [] ?TextPosition : StyleParam.TextPosition, + [] ?MultiTextPosition : seq, + [] ?TextFont : Font, + [] ?Marker : Marker + ) = + + let marker = + Marker + |> Option.defaultValue (TraceObjects.Marker.init()) + |> TraceObjects.Marker.style( + ?Color = Color, + ?Pattern = Pattern, + ?MultiOpacity = MultiOpacity + ) - let marker = - match Marker with - | Some marker -> marker |> TraceObjects.Marker.style(?Color=Color) - | Option.None -> TraceObjects.Marker.init (?Color=Color) - - Trace2D.initBar (Trace2DStyle.Bar(X = keys,Y = values,Marker=marker)) - |> TraceStyle.TraceInfo(?Name=Name,?ShowLegend=ShowLegend,?Opacity=Opacity) - |> TraceStyle.TextLabel(?Text=Labels,?Textposition=TextPosition,?Textfont=TextFont) - |> GenericChart.ofTraceObject - + + Trace2D.initBar ( + Trace2DStyle.Bar( + X = values, + ?Y = Keys, + Orientation = StyleParam.Orientation.Horizontal, + ?Name = Name , + ?ShowLegend = ShowLegend , + ?Base = Base , + ?Width = Width , + ?MultiWidth = MultiWidth , + ?Opacity = Opacity , + ?Text = Text , + ?MultiText = MultiText , + ?TextPosition = TextPosition , + ?MultiTextPosition = MultiTextPosition , + ?TextFont = TextFont , + Marker = marker + ) + ) + |> GenericChart.ofTraceObject /// Illustrates comparisons among individual items [] - static member Column(keysvalues, - [] ?Name, - [] ?ShowLegend, - [] ?Color, - [] ?Opacity, - [] ?Labels, - [] ?TextPosition, - [] ?TextFont, - [] ?Marker) = - let keys,values = Seq.unzip keysvalues - Chart.Column(keys, values, ?Name=Name,?ShowLegend=ShowLegend,?Color=Color,?Opacity=Opacity,?Labels=Labels,?TextPosition=TextPosition,?TextFont=TextFont,?Marker=Marker) + static member Bar + ( + keysValues: seq<#IConvertible * #IConvertible>, + [] ?Name : string , + [] ?ShowLegend : bool, + [] ?Color : Color , + [] ?Pattern : Pattern, + [] ?Base : #IConvertible, + [] ?Width : #IConvertible, + [] ?MultiWidth : seq<#IConvertible>, + [] ?Opacity : float, + [] ?MultiOpacity : seq, + [] ?Text : #IConvertible, + [] ?MultiText : seq<#IConvertible>, + [] ?TextPosition : StyleParam.TextPosition, + [] ?MultiTextPosition : seq, + [] ?TextFont : Font, + [] ?Marker : Marker + ) = + let keys,values = Seq.unzip keysValues + Chart.Bar( + values, + keys, + ?Name = Name , + ?ShowLegend = ShowLegend , + ?Color = Color , + ?Pattern = Pattern , + ?Base = Base , + ?Width = Width , + ?MultiWidth = MultiWidth , + ?Opacity = Opacity , + ?MultiOpacity = MultiOpacity , + ?Text = Text , + ?MultiText = MultiText , + ?TextPosition = TextPosition , + ?MultiTextPosition = MultiTextPosition, + ?TextFont = TextFont , + ?Marker = Marker + ) - /// Displays series of column chart type as stacked columns. + /// Displays series of tcolumn chart type as stacked bars. [] - static member StackedColumn(keys, values, - [] ?Name, - [] ?ShowLegend, - [] ?Color, - [] ?Opacity, - [] ?Labels, - [] ?TextPosition, - [] ?TextFont, - [] ?Marker) = - let marker = - match Marker with - | Some marker -> marker |> TraceObjects.Marker.style(?Color=Color) - | Option.None -> TraceObjects.Marker.init (?Color=Color) - - Trace2D.initBar (Trace2DStyle.Bar(X = keys,Y = values,Marker=marker)) - |> TraceStyle.TraceInfo(?Name=Name,?ShowLegend=ShowLegend,?Opacity=Opacity) - |> TraceStyle.TextLabel(?Text=Labels,?Textposition=TextPosition,?Textfont=TextFont) - |> GenericChart.ofTraceObject - //|> GenericChart.setLayout (Layout.init (Layout.style(Barmode=StyleParam.Barmode.Stack))) - |> GenericChart.setLayout (Layout.init (BarMode=StyleParam.BarMode.Stack)) + static member StackedBar + ( + values: seq<#IConvertible>, + [] ?Keys : seq<#IConvertible>, + [] ?Name : string , + [] ?ShowLegend : bool, + [] ?Color : Color , + [] ?Pattern : Pattern, + [] ?Base : #IConvertible, + [] ?Width : #IConvertible, + [] ?MultiWidth : seq<#IConvertible>, + [] ?Opacity : float, + [] ?MultiOpacity : seq, + [] ?Text : #IConvertible, + [] ?MultiText : seq<#IConvertible>, + [] ?TextPosition : StyleParam.TextPosition, + [] ?MultiTextPosition : seq, + [] ?TextFont : Font, + [] ?Marker : Marker + ) = - /// Displays series of column chart type as stacked columns. - [] - static member StackedColumn(keysvalues, - [] ?Name, - [] ?ShowLegend, - [] ?Color, - [] ?Opacity, - [] ?Labels, - [] ?TextPosition, - [] ?TextFont, - [] ?Marker) = - let keys,values = Seq.unzip keysvalues - Chart.StackedColumn(keys, values,?Name=Name,?ShowLegend=ShowLegend,?Color=Color,?Opacity=Opacity,?Labels=Labels,?TextPosition=TextPosition,?TextFont=TextFont,?Marker=Marker) + Chart.Bar( + values, + ?Keys = Keys, + ?Name = Name , + ?ShowLegend = ShowLegend , + ?Color = Color , + ?Pattern = Pattern , + ?Base = Base , + ?Width = Width , + ?MultiWidth = MultiWidth , + ?Opacity = Opacity , + ?MultiOpacity = MultiOpacity , + ?Text = Text , + ?MultiText = MultiText , + ?TextPosition = TextPosition , + ?MultiTextPosition = MultiTextPosition, + ?TextFont = TextFont , + ?Marker = Marker + ) + |> GenericChart.mapLayout (Layout.style (BarMode=StyleParam.BarMode.Stack)) + /// Displays series of tcolumn chart type as stacked bars. + [] + static member StackedBar + ( + keysValues: seq<#IConvertible * #IConvertible>, + [] ?Name : string , + [] ?ShowLegend : bool, + [] ?Color : Color , + [] ?Pattern : Pattern, + [] ?Base : #IConvertible, + [] ?Width : #IConvertible, + [] ?MultiWidth : seq<#IConvertible>, + [] ?Opacity : float, + [] ?MultiOpacity : seq, + [] ?Text : #IConvertible, + [] ?MultiText : seq<#IConvertible>, + [] ?TextPosition : StyleParam.TextPosition, + [] ?MultiTextPosition : seq, + [] ?TextFont : Font, + [] ?Marker : Marker + ) = + + let keys,values = Seq.unzip keysValues + Chart.StackedBar( + values, + keys, + ?Name = Name , + ?ShowLegend = ShowLegend , + ?Color = Color , + ?Pattern = Pattern , + ?Base = Base , + ?Width = Width , + ?MultiWidth = MultiWidth , + ?Opacity = Opacity , + ?MultiOpacity = MultiOpacity , + ?Text = Text , + ?MultiText = MultiText , + ?TextPosition = TextPosition , + ?MultiTextPosition = MultiTextPosition, + ?TextFont = TextFont , + ?Marker = Marker + ) + /// Illustrates comparisons among individual items [] - static member Bar + static member Column ( values: seq<#IConvertible>, [] ?Keys : seq<#IConvertible>, @@ -1095,9 +1203,9 @@ module Chart2D = Trace2D.initBar ( Trace2DStyle.Bar( - X = values, - ?Y = Keys, - Orientation = StyleParam.Orientation.Horizontal, + Y = values, + ?X = Keys, + Orientation = StyleParam.Orientation.Vertical, ?Name = Name , ?ShowLegend = ShowLegend , ?Base = Base , @@ -1116,7 +1224,7 @@ module Chart2D = /// Illustrates comparisons among individual items [] - static member Bar + static member Column ( keysValues: seq<#IConvertible * #IConvertible>, [] ?Name : string , @@ -1136,7 +1244,7 @@ module Chart2D = [] ?Marker : Marker ) = let keys,values = Seq.unzip keysValues - Chart.Bar( + Chart.Column( values, keys, ?Name = Name , @@ -1159,40 +1267,92 @@ module Chart2D = /// Displays series of tcolumn chart type as stacked bars. [] - static member StackedBar(keys, values, - [] ?Name, - [] ?ShowLegend, - [] ?Color, - [] ?Opacity, - [] ?Labels, - [] ?TextPosition, - [] ?TextFont, - [] ?Marker) = - let marker = - match Marker with - | Some marker -> marker |> TraceObjects.Marker.style(?Color=Color) - | Option.None -> TraceObjects.Marker.init (?Color=Color) - Trace2D.initBar (Trace2DStyle.Bar(X = values,Y = keys,Marker=marker,Orientation = StyleParam.Orientation.Horizontal)) - |> TraceStyle.TraceInfo(?Name=Name,?ShowLegend=ShowLegend,?Opacity=Opacity) - |> TraceStyle.TextLabel(?Text=Labels,?Textposition=TextPosition,?Textfont=TextFont) - |> GenericChart.ofTraceObject - //|> GenericChart.setLayout (Layout.init (Layout.style(Barmode=StyleParam.Barmode.Stack))) - |> GenericChart.setLayout (Layout.init (BarMode=StyleParam.BarMode.Stack)) + static member StackedColumn + ( + values: seq<#IConvertible>, + [] ?Keys : seq<#IConvertible>, + [] ?Name : string , + [] ?ShowLegend : bool, + [] ?Color : Color , + [] ?Pattern : Pattern, + [] ?Base : #IConvertible, + [] ?Width : #IConvertible, + [] ?MultiWidth : seq<#IConvertible>, + [] ?Opacity : float, + [] ?MultiOpacity : seq, + [] ?Text : #IConvertible, + [] ?MultiText : seq<#IConvertible>, + [] ?TextPosition : StyleParam.TextPosition, + [] ?MultiTextPosition : seq, + [] ?TextFont : Font, + [] ?Marker : Marker + + ) = + + Chart.Column( + values, + ?Keys = Keys, + ?Name = Name , + ?ShowLegend = ShowLegend , + ?Color = Color , + ?Pattern = Pattern , + ?Base = Base , + ?Width = Width , + ?MultiWidth = MultiWidth , + ?Opacity = Opacity , + ?MultiOpacity = MultiOpacity , + ?Text = Text , + ?MultiText = MultiText , + ?TextPosition = TextPosition , + ?MultiTextPosition = MultiTextPosition, + ?TextFont = TextFont , + ?Marker = Marker + ) + |> GenericChart.mapLayout (Layout.style (BarMode=StyleParam.BarMode.Stack)) /// Displays series of tcolumn chart type as stacked bars. [] - static member StackedBar(keysvalues, - [] ?Name, - [] ?ShowLegend, - [] ?Color, - [] ?Opacity, - [] ?Labels, - [] ?TextPosition, - [] ?TextFont, - [] ?Marker) = - let keys,values = Seq.unzip keysvalues - Chart.StackedBar(keys, values, ?Name=Name,?ShowLegend=ShowLegend,?Color=Color,?Opacity=Opacity,?Labels=Labels,?TextPosition=TextPosition,?TextFont=TextFont,?Marker=Marker) + static member StackedColumn + ( + keysValues: seq<#IConvertible * #IConvertible>, + [] ?Name : string , + [] ?ShowLegend : bool, + [] ?Color : Color , + [] ?Pattern : Pattern, + [] ?Base : #IConvertible, + [] ?Width : #IConvertible, + [] ?MultiWidth : seq<#IConvertible>, + [] ?Opacity : float, + [] ?MultiOpacity : seq, + [] ?Text : #IConvertible, + [] ?MultiText : seq<#IConvertible>, + [] ?TextPosition : StyleParam.TextPosition, + [] ?MultiTextPosition : seq, + [] ?TextFont : Font, + [] ?Marker : Marker + ) = + + let keys,values = Seq.unzip keysValues + Chart.StackedColumn( + values, + keys, + ?Name = Name , + ?ShowLegend = ShowLegend , + ?Color = Color , + ?Pattern = Pattern , + ?Base = Base , + ?Width = Width , + ?MultiWidth = MultiWidth , + ?Opacity = Opacity , + ?MultiOpacity = MultiOpacity , + ?Text = Text , + ?MultiText = MultiText , + ?TextPosition = TextPosition , + ?MultiTextPosition = MultiTextPosition, + ?TextFont = TextFont , + ?Marker = Marker + ) /// Computes a histogram with auto-determined the bin size. [] From 13a3b95a3b304f49df59561328dddd88b2852e25 Mon Sep 17 00:00:00 2001 From: Kevin Schneider Date: Thu, 23 Sep 2021 09:47:40 +0200 Subject: [PATCH 09/12] Fix Bar trace tests --- .../HtmlCodegen/SimpleCharts.fs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/tests/Plotly.NET.Tests/HtmlCodegen/SimpleCharts.fs b/tests/Plotly.NET.Tests/HtmlCodegen/SimpleCharts.fs index 3c366b44c..ff4f8bfa7 100644 --- a/tests/Plotly.NET.Tests/HtmlCodegen/SimpleCharts.fs +++ b/tests/Plotly.NET.Tests/HtmlCodegen/SimpleCharts.fs @@ -78,19 +78,19 @@ let ``Line and scatter plots`` = let columnChart = let values = [20; 14; 23;] let keys = ["Product A"; "Product B"; "Product C";] - Chart.Column(keys = keys, values = values) + Chart.Column(values, keys) let barChart = let values = [20; 14; 23;] let keys = ["Product A"; "Product B"; "Product C";] - Chart.Bar(keys = keys, values = values) + Chart.Bar(values, keys) let stackedBarChart = let values = [20; 14; 23;] let keys = ["Product A"; "Product B"; "Product C";] [ - Chart.StackedBar(keys = keys, values = values,Name="old"); - Chart.StackedBar(keys = keys, values = [8; 21; 13;],Name="new") + Chart.StackedBar(values, keys, Name="old"); + Chart.StackedBar([8; 21; 13;], keys, Name="new") ] |> Chart.combine @@ -98,8 +98,8 @@ let stackedColumnChart = let values = [20; 14; 23;] let keys = ["Product A"; "Product B"; "Product C";] [ - Chart.StackedColumn(keys,values,Name="old"); - Chart.StackedColumn(keys,[8; 21; 13;],Name="new") + Chart.StackedColumn(values,keys,Name="old"); + Chart.StackedColumn([8; 21; 13;],keys,Name="new") ] |> Chart.combine @@ -107,7 +107,7 @@ let stackedColumnChart = let ``Bar and column charts`` = testList "SimpleCharts.Bar and column charts" [ testCase "Column chart data" ( fun () -> - "var data = [{\"type\":\"bar\",\"x\":[\"Product A\",\"Product B\",\"Product C\"],\"y\":[20,14,23],\"marker\":{}}];" + """var data = [{"type":"bar","x":["Product A","Product B","Product C"],"y":[20,14,23],"orientation":"v","marker":{}}];""" |> chartGeneratedContains columnChart ); testCase "Column chart layout" ( fun () -> @@ -121,7 +121,7 @@ let ``Bar and column charts`` = emptyLayout barChart ); testCase "Stacked bar data" ( fun () -> - "var data = [{\"type\":\"bar\",\"x\":[20,14,23],\"y\":[\"Product A\",\"Product B\",\"Product C\"],\"orientation\":\"h\",\"marker\":{},\"name\":\"old\"},{\"type\":\"bar\",\"x\":[8,21,13],\"y\":[\"Product A\",\"Product B\",\"Product C\"],\"orientation\":\"h\",\"marker\":{},\"name\":\"new\"}];" + """var data = [{"type":"bar","name":"old","x":[20,14,23],"y":["Product A","Product B","Product C"],"orientation":"h","marker":{}},{"type":"bar","name":"new","x":[8,21,13],"y":["Product A","Product B","Product C"],"orientation":"h","marker":{}}];""" |> chartGeneratedContains stackedBarChart ); testCase "Stacked bar layout" ( fun () -> @@ -129,7 +129,7 @@ let ``Bar and column charts`` = |> chartGeneratedContains stackedColumnChart ); testCase "Stacked column data" ( fun () -> - "var data = [{\"type\":\"bar\",\"x\":[\"Product A\",\"Product B\",\"Product C\"],\"y\":[20,14,23],\"marker\":{},\"name\":\"old\"},{\"type\":\"bar\",\"x\":[\"Product A\",\"Product B\",\"Product C\"],\"y\":[8,21,13],\"marker\":{},\"name\":\"new\"}];" + """var data = [{"type":"bar","name":"old","x":["Product A","Product B","Product C"],"y":[20,14,23],"orientation":"v","marker":{}},{"type":"bar","name":"new","x":["Product A","Product B","Product C"],"y":[8,21,13],"orientation":"v","marker":{}}];""" |> chartGeneratedContains stackedColumnChart ); testCase "Stacked column layout" ( fun () -> From 1d10820ab18ba170b34e85c9c682fa8528a8120d Mon Sep 17 00:00:00 2001 From: Kevin Schneider Date: Thu, 23 Sep 2021 09:54:28 +0200 Subject: [PATCH 10/12] Fix some properties on Error and ColorAxis --- .../CommonAbstractions/StyleParams.fs | 16 ++++++++++ .../ObjectAbstractions/Common/ColorAxis.fs | 4 +-- .../Traces/ObjectAbstractions/Error.fs | 32 ++++++++++++------- 3 files changed, 39 insertions(+), 13 deletions(-) diff --git a/src/Plotly.NET/CommonAbstractions/StyleParams.fs b/src/Plotly.NET/CommonAbstractions/StyleParams.fs index 9a807288b..e518b352f 100644 --- a/src/Plotly.NET/CommonAbstractions/StyleParams.fs +++ b/src/Plotly.NET/CommonAbstractions/StyleParams.fs @@ -715,6 +715,22 @@ module StyleParam = // #E# //-------------------------- + [] + type ErrorType = + | Percent | Constant| Sqrt | Data + + static member toString = function + | Percent -> "percent" + | Constant -> "constant" + | Sqrt -> "sqrt" + | Data -> "data" + + + static member convert = ErrorType.toString >> box + override this.ToString() = this |> ErrorType.toString + member this.Convert() = this |> ErrorType.convert + + /// Determines a formatting rule for the tick exponents. For example, consider the number 1,000,000,000. If "none", it appears as 1,000,000,000. If "e", 1e+9. If "E", 1E+9. /// If "power", 1x10^9 (with 9 in a super script). If "SI", 1G. If "B", 1B. [] diff --git a/src/Plotly.NET/Layout/ObjectAbstractions/Common/ColorAxis.fs b/src/Plotly.NET/Layout/ObjectAbstractions/Common/ColorAxis.fs index c88a6ff48..f74cc3627 100644 --- a/src/Plotly.NET/Layout/ObjectAbstractions/Common/ColorAxis.fs +++ b/src/Plotly.NET/Layout/ObjectAbstractions/Common/ColorAxis.fs @@ -78,8 +78,8 @@ type ColorAxis() = CMid |> DynObj.setValueOpt ca "cmid" CMax |> DynObj.setValueOpt ca "cmax" ColorBar |> DynObj.setValueOpt ca "colorbar" - ColorScale |> DynObj.setValueOpt ca "colorscale" - ShowScale |> DynObj.setValueOpt ca "showscale" + ColorScale |> DynObj.setValueOptBy ca "colorscale" StyleParam.Colorscale.convert + ShowScale |> DynObj.setValueOpt ca "showscale" ReverseScale |> DynObj.setValueOpt ca "reversescale" ca \ No newline at end of file diff --git a/src/Plotly.NET/Traces/ObjectAbstractions/Error.fs b/src/Plotly.NET/Traces/ObjectAbstractions/Error.fs index 3cbb26e51..ae52768d0 100644 --- a/src/Plotly.NET/Traces/ObjectAbstractions/Error.fs +++ b/src/Plotly.NET/Traces/ObjectAbstractions/Error.fs @@ -11,6 +11,8 @@ type Error () = inherit DynamicObj () /// Init Error type + /// Determines whether or not this set of error bars is visible. + /// Determines the rule used to generate the error bars. If "constant`, the bar lengths are of a constant value. Set this constant in `value`. If "percent", the bar lengths correspond to a percentage of underlying data. Set this percentage in `value`. If "sqrt", the bar lengths correspond to the square of the underlying data. If "data", the bar lengths are set with data set `array`. /// Determines whether or not the error bars have the same length in both direction (top/bottom for vertical bars, left/right for horizontal bars. /// Sets the data corresponding the length of each error bar. Values are plotted relative to the underlying data. /// Sets the data corresponding the length of each error bar in the bottom (left) direction for vertical (horizontal) bars Values are plotted relative to the underlying data. @@ -24,6 +26,8 @@ type Error () = /// Sets the width (in px) of the cross-bar at both ends of the error bars. static member init ( + [] ?Visible: bool, + [] ?Type: StyleParam.ErrorType, [] ?Symmetric: bool, [] ?Array: seq<#IConvertible>, [] ?Arrayminus: seq<#IConvertible>, @@ -53,6 +57,8 @@ type Error () = ) /// Creates a function that applies the given style parameters to an Error object + /// Determines whether or not this set of error bars is visible. + /// Determines the rule used to generate the error bars. If "constant`, the bar lengths are of a constant value. Set this constant in `value`. If "percent", the bar lengths correspond to a percentage of underlying data. Set this percentage in `value`. If "sqrt", the bar lengths correspond to the square of the underlying data. If "data", the bar lengths are set with data set `array`. /// Determines whether or not the error bars have the same length in both direction (top/bottom for vertical bars, left/right for horizontal bars. /// Sets the data corresponding the length of each error bar. Values are plotted relative to the underlying data. /// Sets the data corresponding the length of each error bar in the bottom (left) direction for vertical (horizontal) bars Values are plotted relative to the underlying data. @@ -66,6 +72,8 @@ type Error () = /// Sets the width (in px) of the cross-bar at both ends of the error bars. static member style ( + [] ?Visible: bool, + [] ?Type: StyleParam.ErrorType, [] ?Symmetric: bool, [] ?Array: seq<#IConvertible>, [] ?Arrayminus: seq<#IConvertible>, @@ -80,17 +88,19 @@ type Error () = ) = (fun (error:Error) -> - Symmetric |> DynObj.setValueOpt error "symmetric" - Array |> DynObj.setValueOpt error "array" - Arrayminus |> DynObj.setValueOpt error "arrayminus" - Value |> DynObj.setValueOpt error "value" - Valueminus |> DynObj.setValueOpt error "valueminus" - Traceref |> DynObj.setValueOpt error "traceref" - Tracerefminus |> DynObj.setValueOpt error "tracerefminus" - Copy_ystyle |> DynObj.setValueOpt error "copy_ystyle" - Color |> DynObj.setValueOpt error "color" - Thickness |> DynObj.setValueOpt error "thickness" - Width |> DynObj.setValueOpt error "width" + Visible |> DynObj.setValueOpt error "visible" + Type |> DynObj.setValueOptBy error "type" StyleParam.ErrorType.convert + Symmetric |> DynObj.setValueOpt error "symmetric" + Array |> DynObj.setValueOpt error "array" + Arrayminus |> DynObj.setValueOpt error "arrayminus" + Value |> DynObj.setValueOpt error "value" + Valueminus |> DynObj.setValueOpt error "valueminus" + Traceref |> DynObj.setValueOpt error "traceref" + Tracerefminus |> DynObj.setValueOpt error "tracerefminus" + Copy_ystyle |> DynObj.setValueOpt error "copy_ystyle" + Color |> DynObj.setValueOpt error "color" + Thickness |> DynObj.setValueOpt error "thickness" + Width |> DynObj.setValueOpt error "width" // out -> error From da3ffc4ac7b95807d80d464c1f0a8f88c551d75c Mon Sep 17 00:00:00 2001 From: Kevin Schneider Date: Thu, 23 Sep 2021 10:07:05 +0200 Subject: [PATCH 11/12] Add Pattern/MultiPattern to all Bar/Column chart constructors --- src/Plotly.NET/ChartAPI/Chart2D.fs | 47 +++++++++++++++++-- .../Traces/ObjectAbstractions/Pattern.fs | 14 +++--- .../HtmlCodegen/SimpleCharts.fs | 8 ++-- 3 files changed, 55 insertions(+), 14 deletions(-) diff --git a/src/Plotly.NET/ChartAPI/Chart2D.fs b/src/Plotly.NET/ChartAPI/Chart2D.fs index e558d2e99..0cdcde1a6 100644 --- a/src/Plotly.NET/ChartAPI/Chart2D.fs +++ b/src/Plotly.NET/ChartAPI/Chart2D.fs @@ -991,6 +991,8 @@ module Chart2D = [] ?Name : string , [] ?ShowLegend : bool, [] ?Color : Color , + [] ?PatternShape : StyleParam.PatternShape, + [] ?MultiPatternShape : seq, [] ?Pattern : Pattern, [] ?Base : #IConvertible, [] ?Width : #IConvertible, @@ -1005,12 +1007,19 @@ module Chart2D = [] ?Marker : Marker ) = + let pattern = + Pattern + |> Option.defaultValue (TraceObjects.Pattern.init()) + |> TraceObjects.Pattern.style( + ?Shape = PatternShape, + ?MultiShape = MultiPatternShape + ) let marker = Marker |> Option.defaultValue (TraceObjects.Marker.init()) |> TraceObjects.Marker.style( ?Color = Color, - ?Pattern = Pattern, + Pattern = pattern, ?MultiOpacity = MultiOpacity ) @@ -1044,6 +1053,8 @@ module Chart2D = [] ?Name : string , [] ?ShowLegend : bool, [] ?Color : Color , + [] ?PatternShape : StyleParam.PatternShape, + [] ?MultiPatternShape : seq, [] ?Pattern : Pattern, [] ?Base : #IConvertible, [] ?Width : #IConvertible, @@ -1064,6 +1075,8 @@ module Chart2D = ?Name = Name , ?ShowLegend = ShowLegend , ?Color = Color , + ?PatternShape = PatternShape , + ?MultiPatternShape = MultiPatternShape, ?Pattern = Pattern , ?Base = Base , ?Width = Width , @@ -1088,6 +1101,8 @@ module Chart2D = [] ?Name : string , [] ?ShowLegend : bool, [] ?Color : Color , + [] ?PatternShape : StyleParam.PatternShape, + [] ?MultiPatternShape : seq, [] ?Pattern : Pattern, [] ?Base : #IConvertible, [] ?Width : #IConvertible, @@ -1109,6 +1124,8 @@ module Chart2D = ?Name = Name , ?ShowLegend = ShowLegend , ?Color = Color , + ?PatternShape = PatternShape , + ?MultiPatternShape = MultiPatternShape, ?Pattern = Pattern , ?Base = Base , ?Width = Width , @@ -1133,6 +1150,8 @@ module Chart2D = [] ?Name : string , [] ?ShowLegend : bool, [] ?Color : Color , + [] ?PatternShape : StyleParam.PatternShape, + [] ?MultiPatternShape : seq, [] ?Pattern : Pattern, [] ?Base : #IConvertible, [] ?Width : #IConvertible, @@ -1155,6 +1174,8 @@ module Chart2D = ?ShowLegend = ShowLegend , ?Color = Color , ?Pattern = Pattern , + ?PatternShape = PatternShape , + ?MultiPatternShape = MultiPatternShape, ?Base = Base , ?Width = Width , ?MultiWidth = MultiWidth , @@ -1178,6 +1199,8 @@ module Chart2D = [] ?ShowLegend : bool, [] ?Color : Color , [] ?Pattern : Pattern, + [] ?PatternShape : StyleParam.PatternShape, + [] ?MultiPatternShape : seq, [] ?Base : #IConvertible, [] ?Width : #IConvertible, [] ?MultiWidth : seq<#IConvertible>, @@ -1191,16 +1214,22 @@ module Chart2D = [] ?Marker : Marker ) = + let pattern = + Pattern + |> Option.defaultValue (TraceObjects.Pattern.init()) + |> TraceObjects.Pattern.style( + ?Shape = PatternShape, + ?MultiShape = MultiPatternShape + ) let marker = Marker |> Option.defaultValue (TraceObjects.Marker.init()) |> TraceObjects.Marker.style( ?Color = Color, - ?Pattern = Pattern, + Pattern = pattern, ?MultiOpacity = MultiOpacity ) - Trace2D.initBar ( Trace2DStyle.Bar( Y = values, @@ -1230,6 +1259,8 @@ module Chart2D = [] ?Name : string , [] ?ShowLegend : bool, [] ?Color : Color , + [] ?PatternShape : StyleParam.PatternShape, + [] ?MultiPatternShape : seq, [] ?Pattern : Pattern, [] ?Base : #IConvertible, [] ?Width : #IConvertible, @@ -1251,6 +1282,8 @@ module Chart2D = ?ShowLegend = ShowLegend , ?Color = Color , ?Pattern = Pattern , + ?PatternShape = PatternShape , + ?MultiPatternShape = MultiPatternShape, ?Base = Base , ?Width = Width , ?MultiWidth = MultiWidth , @@ -1274,6 +1307,8 @@ module Chart2D = [] ?Name : string , [] ?ShowLegend : bool, [] ?Color : Color , + [] ?PatternShape : StyleParam.PatternShape, + [] ?MultiPatternShape : seq, [] ?Pattern : Pattern, [] ?Base : #IConvertible, [] ?Width : #IConvertible, @@ -1295,6 +1330,8 @@ module Chart2D = ?Name = Name , ?ShowLegend = ShowLegend , ?Color = Color , + ?PatternShape = PatternShape , + ?MultiPatternShape = MultiPatternShape, ?Pattern = Pattern , ?Base = Base , ?Width = Width , @@ -1320,6 +1357,8 @@ module Chart2D = [] ?ShowLegend : bool, [] ?Color : Color , [] ?Pattern : Pattern, + [] ?PatternShape : StyleParam.PatternShape, + [] ?MultiPatternShape : seq, [] ?Base : #IConvertible, [] ?Width : #IConvertible, [] ?MultiWidth : seq<#IConvertible>, @@ -1340,6 +1379,8 @@ module Chart2D = ?Name = Name , ?ShowLegend = ShowLegend , ?Color = Color , + ?PatternShape = PatternShape , + ?MultiPatternShape = MultiPatternShape, ?Pattern = Pattern , ?Base = Base , ?Width = Width , diff --git a/src/Plotly.NET/Traces/ObjectAbstractions/Pattern.fs b/src/Plotly.NET/Traces/ObjectAbstractions/Pattern.fs index 417fb8526..71fe813f1 100644 --- a/src/Plotly.NET/Traces/ObjectAbstractions/Pattern.fs +++ b/src/Plotly.NET/Traces/ObjectAbstractions/Pattern.fs @@ -17,7 +17,7 @@ type Pattern () = /// Sets the opacity of the foreground pattern fill. Defaults to a 0.5 when `fillmode` is "overlay". Otherwise, defaults to 1. /// Determines whether `marker.color` should be used as a default to `bgcolor` or a `fgcolor`. /// Sets the shape of the pattern fill. By default, no pattern is used for filling the area. - /// Sets the shape of the pattern fill. By default, no pattern is used for filling the area. + /// Sets the shape of the pattern fill. By default, no pattern is used for filling the area. /// Sets the size of unit squares of the pattern fill in pixels, which corresponds to the interval of repetition of the pattern. /// Sets the size of unit squares of the pattern fill in pixels, which corresponds to the interval of repetition of the pattern. /// Sets the solidity of the pattern fill. Solidity is roughly the fraction of the area filled by the pattern. Solidity of 0 shows only the background color without pattern and solidty of 1 shows only the foreground color without pattern. @@ -28,7 +28,7 @@ type Pattern () = ?FGOpacity : float, ?FillMode : StyleParam.PatternFillMode, ?Shape : StyleParam.PatternShape, - ?MultiShapes: seq, + ?MultiShape : seq, ?Size : int, ?MultiSize : seq, ?Solidity : float @@ -41,7 +41,7 @@ type Pattern () = ?FGOpacity = FGOpacity , ?FillMode = FillMode , ?Shape = Shape , - ?MultiShapes = MultiShapes, + ?MultiShape = MultiShape , ?Size = Size , ?MultiSize = MultiSize , ?Solidity = Solidity @@ -54,9 +54,9 @@ type Pattern () = ?FGOpacity : float, ?FillMode : StyleParam.PatternFillMode, ?Shape : StyleParam.PatternShape, - ?MultiShapes: seq, + ?MultiShape : seq, ?Size : int, - ?MultiSize : seq, + ?MultiSize : seq, ?Solidity : float ) = @@ -66,8 +66,8 @@ type Pattern () = FGColor |> DynObj.setValueOpt pattern "fgcolor" FGOpacity |> DynObj.setValueOpt pattern "fgopacity" FillMode |> DynObj.setValueOptBy pattern "fillmode" StyleParam.PatternFillMode.convert - (Shape, MultiShapes)|> DynObj.setSingleOrMultiOptBy pattern "shape" StyleParam.PatternShape.convert - (Size, MultiSize) |> DynObj.setSingleOrMultiOpt pattern "size" + (Shape, MultiShape) |> DynObj.setSingleOrMultiOptBy pattern "shape" StyleParam.PatternShape.convert + (Size, MultiSize) |> DynObj.setSingleOrMultiOpt pattern "size" Solidity |> DynObj.setValueOpt pattern "solidity" pattern diff --git a/tests/Plotly.NET.Tests/HtmlCodegen/SimpleCharts.fs b/tests/Plotly.NET.Tests/HtmlCodegen/SimpleCharts.fs index ff4f8bfa7..c86868a9b 100644 --- a/tests/Plotly.NET.Tests/HtmlCodegen/SimpleCharts.fs +++ b/tests/Plotly.NET.Tests/HtmlCodegen/SimpleCharts.fs @@ -107,21 +107,21 @@ let stackedColumnChart = let ``Bar and column charts`` = testList "SimpleCharts.Bar and column charts" [ testCase "Column chart data" ( fun () -> - """var data = [{"type":"bar","x":["Product A","Product B","Product C"],"y":[20,14,23],"orientation":"v","marker":{}}];""" + """var data = [{"type":"bar","x":["Product A","Product B","Product C"],"y":[20,14,23],"orientation":"v","marker":{"pattern":{}}}];""" |> chartGeneratedContains columnChart ); testCase "Column chart layout" ( fun () -> emptyLayout columnChart ); testCase "Bar chart data" ( fun () -> - "var data = [{\"type\":\"bar\",\"x\":[20,14,23],\"y\":[\"Product A\",\"Product B\",\"Product C\"],\"orientation\":\"h\",\"marker\":{}}];" + """var data = [{"type":"bar","x":[20,14,23],"y":["Product A","Product B","Product C"],"orientation":"h","marker":{"pattern":{}}}];""" |> chartGeneratedContains barChart ); testCase "Bar chart layout" ( fun () -> emptyLayout barChart ); testCase "Stacked bar data" ( fun () -> - """var data = [{"type":"bar","name":"old","x":[20,14,23],"y":["Product A","Product B","Product C"],"orientation":"h","marker":{}},{"type":"bar","name":"new","x":[8,21,13],"y":["Product A","Product B","Product C"],"orientation":"h","marker":{}}];""" + """var data = [{"type":"bar","name":"old","x":[20,14,23],"y":["Product A","Product B","Product C"],"orientation":"h","marker":{"pattern":{}}},{"type":"bar","name":"new","x":[8,21,13],"y":["Product A","Product B","Product C"],"orientation":"h","marker":{"pattern":{}}}];""" |> chartGeneratedContains stackedBarChart ); testCase "Stacked bar layout" ( fun () -> @@ -129,7 +129,7 @@ let ``Bar and column charts`` = |> chartGeneratedContains stackedColumnChart ); testCase "Stacked column data" ( fun () -> - """var data = [{"type":"bar","name":"old","x":["Product A","Product B","Product C"],"y":[20,14,23],"orientation":"v","marker":{}},{"type":"bar","name":"new","x":["Product A","Product B","Product C"],"y":[8,21,13],"orientation":"v","marker":{}}];""" + """var data = [{"type":"bar","name":"old","x":["Product A","Product B","Product C"],"y":[20,14,23],"orientation":"v","marker":{"pattern":{}}},{"type":"bar","name":"new","x":["Product A","Product B","Product C"],"y":[8,21,13],"orientation":"v","marker":{"pattern":{}}}];""" |> chartGeneratedContains stackedColumnChart ); testCase "Stacked column layout" ( fun () -> From 916b125ad4f5b808c1bf9956e412936a7d1a12bd Mon Sep 17 00:00:00 2001 From: Kevin Schneider Date: Thu, 23 Sep 2021 10:25:56 +0200 Subject: [PATCH 12/12] Update basic C# examples on doc index page --- docs/index.fsx | 98 ++++++++++++------- .../Plotly.NET.Tests.CSharpConsole/Program.cs | 32 +++++- 2 files changed, 90 insertions(+), 40 deletions(-) diff --git a/docs/index.fsx b/docs/index.fsx index bd25a3207..4b8a104da 100644 --- a/docs/index.fsx +++ b/docs/index.fsx @@ -219,17 +219,28 @@ One of the main design points of Plotly.NET it is to provide support for multipl ### Fluent interface style in C#: ``` -static void Main(string[] args) +using System; +using Plotly.NET; +using Microsoft.FSharp.Core; // use this for less verbose and more helpful intellisense + +namespace Plotly.NET.Tests.CSharp { - double[] x = new double[] { 1, 2 }; - double[] y = new double[] { 5, 10 }; - GenericChart.GenericChart chart = Chart.Point(x: x, y: y); - chart - .WithTraceName("Hello from C#", true) - .withXAxisStyle(title: "xAxis", Showgrid: false, Showline: true) - .withYAxisStyle(title: "yAxis", Showgrid: false, Showline: true) - .Show(); + class Program + { + static void Main(string[] args) + { + double[] x = new double[] { 1, 2 }; + double[] y = new double[] { 5, 10 }; + GenericChart.GenericChart chart = Chart2D.Chart.Point(x: x, y: y); + chart + .WithTraceName("Hello from C#", true) + .WithXAxisStyle(title: Title.init("xAxis"), ShowGrid: false, ShowLine: true) + .WithYAxisStyle(title: Title.init("yAxis"), ShowGrid: false, ShowLine: true) + .Show(); + } + } } + ``` ### Declarative style in F# using the underlying `DynamicObj`: @@ -273,36 +284,47 @@ GenericChart.ofTraceObject(trace) ### Declarative style in C# using the underlying `DynamicObj`: ``` -static void Main(string[] args) +using System; +using Plotly.NET; +using Microsoft.FSharp.Core; // use this for less verbose and more helpful intellisense +using Plotly.NET.LayoutObjects; + +namespace Plotly.NET.Tests.CSharp { - double[] x = new double[] { 1, 2 }; - double[] y = new double[] { 5, 10 }; - - Axis.LinearAxis xAxis = new Axis.LinearAxis(); - xAxis.SetValue("title", "xAxis"); - xAxis.SetValue("showgrid", false); - xAxis.SetValue("showline", true); - - Axis.LinearAxis yAxis = new Axis.LinearAxis(); - yAxis.SetValue("title", "yAxis"); - yAxis.SetValue("showgrid", false); - yAxis.SetValue("showline", true); - - Layout layout = new Layout(); - layout.SetValue("xaxis", xAxis); - layout.SetValue("yaxis", yAxis); - layout.SetValue("showlegend", true); - - Trace trace = new Trace("scatter"); - trace.SetValue("x", x); - trace.SetValue("y", y); - trace.SetValue("mode", "markers"); - trace.SetValue("name", "Hello from C#"); - - GenericChart - .ofTraceObject(trace) - .WithLayout(layout) - .Show(); + class Program + { + static void Main(string[] args) + { + double[] x = new double[] { 1, 2 }; + double[] y = new double[] { 5, 10 }; + + LinearAxis xAxis = new LinearAxis(); + xAxis.SetValue("title", "xAxis"); + xAxis.SetValue("showgrid", false); + xAxis.SetValue("showline", true); + + LinearAxis yAxis = new LinearAxis(); + yAxis.SetValue("title", "yAxis"); + yAxis.SetValue("showgrid", false); + yAxis.SetValue("showline", true); + + Layout layout = new Layout(); + layout.SetValue("xaxis", xAxis); + layout.SetValue("yaxis", yAxis); + layout.SetValue("showlegend", true); + + Trace trace = new Trace("scatter"); + trace.SetValue("x", x); + trace.SetValue("y", y); + trace.SetValue("mode", "markers"); + trace.SetValue("name", "Hello from C#"); + + GenericChart + .ofTraceObject(trace) + .WithLayout(layout) + .Show(); + } + } } ``` diff --git a/tests/Plotly.NET.Tests.CSharpConsole/Program.cs b/tests/Plotly.NET.Tests.CSharpConsole/Program.cs index 5d479fd04..c366fa8fb 100644 --- a/tests/Plotly.NET.Tests.CSharpConsole/Program.cs +++ b/tests/Plotly.NET.Tests.CSharpConsole/Program.cs @@ -1,5 +1,7 @@ using System; using Plotly.NET; +using Microsoft.FSharp.Core; // use this for less verbose and more helpful intellisense +using Plotly.NET.LayoutObjects; namespace Plotly.NET.Tests.CSharp { @@ -7,8 +9,34 @@ class Program { static void Main(string[] args) { - Console.WriteLine(StyleParam.TextPosition.MiddleRight.ToString()); - Console.WriteLine(StyleParam.TextPosition.MiddleRight.Convert()); + double[] x = new double[] { 1, 2 }; + double[] y = new double[] { 5, 10 }; + + LinearAxis xAxis = new LinearAxis(); + xAxis.SetValue("title", "xAxis"); + xAxis.SetValue("showgrid", false); + xAxis.SetValue("showline", true); + + LinearAxis yAxis = new LinearAxis(); + yAxis.SetValue("title", "yAxis"); + yAxis.SetValue("showgrid", false); + yAxis.SetValue("showline", true); + + Layout layout = new Layout(); + layout.SetValue("xaxis", xAxis); + layout.SetValue("yaxis", yAxis); + layout.SetValue("showlegend", true); + + Trace trace = new Trace("scatter"); + trace.SetValue("x", x); + trace.SetValue("y", y); + trace.SetValue("mode", "markers"); + trace.SetValue("name", "Hello from C#"); + + GenericChart + .ofTraceObject(trace) + .WithLayout(layout) + .Show(); } } }