From dbdf8b61931cee6b39239d8a3f45e952f4a5742c Mon Sep 17 00:00:00 2001 From: Kevin Schneider Date: Wed, 16 Oct 2024 13:50:01 +0200 Subject: [PATCH] various final adjustments to source, typos, and tests --- src/Plotly.NET/ChartAPI/Chart.fs | 71 ++++++++++--------- src/Plotly.NET/Config/Config.fs | 2 +- .../DisplayOptions/DisplayOptions.fs | 2 +- src/Plotly.NET/Globals.fs | 6 +- src/Plotly.NET/Layout/Layout.fs | 36 ++++++---- .../ObjectAbstractions/Common/NewSelection.fs | 2 +- .../Layout/ObjectAbstractions/Common/Shape.fs | 40 +++++------ src/Plotly.NET/Plotly.NET.fsproj | 2 +- .../Traces/ObjectAbstractions/Dimensions.fs | 2 +- .../Traces/ObjectAbstractions/Sankey.fs | 1 + src/Plotly.NET/Traces/Trace.fs | 14 ++-- src/Plotly.NET/Traces/Trace2D.fs | 4 +- tests/Common/FSharpTestBase/TestUtils.fs | 12 ++++ .../FSharpConsole/FSharpConsole.fsproj | 1 + tests/ConsoleApps/FSharpConsole/Program.fs | 20 +----- .../FeatureAdditions/Grid_SubPlotTitles.fs | 5 +- .../CoreTests/HTMLCodegen/ChartDomain.fs | 5 +- .../CoreTests/Traces/TraceStaticMembers.fs | 2 +- 18 files changed, 121 insertions(+), 106 deletions(-) diff --git a/src/Plotly.NET/ChartAPI/Chart.fs b/src/Plotly.NET/ChartAPI/Chart.fs index c56332d0..0eef89cd 100644 --- a/src/Plotly.NET/ChartAPI/Chart.fs +++ b/src/Plotly.NET/ChartAPI/Chart.fs @@ -1751,7 +1751,7 @@ type Chart = let currentAxis = polar |> Polar.getAngularAxis - let updatedAxis = DynObj.combine currentAxis angularAxis + let updatedAxis = DynObj.combine currentAxis angularAxis |> unbox let updatedPolar = polar |> Polar.setAngularAxis updatedAxis @@ -1810,7 +1810,7 @@ type Chart = polar |> Polar.getRadialAxis let updatedAxis = - DynObj.combine currentAxis radialAxis + DynObj.combine currentAxis radialAxis |> unbox let updatedPolar = polar |> Polar.setRadialAxis updatedAxis @@ -1925,10 +1925,10 @@ type Chart = let currentAxis = smith |> Smith.getImaginaryAxis - let updatedAxis = DynObj.combine currentAxis imaginaryAxis + let updatedAxis = DynObj.combine currentAxis imaginaryAxis |> unbox let updatedSmith = - smith |> Smith.setImaginaryAxis updatedAxis + smith |> Smith.setImaginaryAxis updatedAxis layout |> Layout.updateSmithById (id, updatedSmith) @@ -1982,10 +1982,10 @@ type Chart = if combine then let currentAxis = smith |> Smith.getRealAxis - let updatedAxis = DynObj.combine currentAxis realAxis + let updatedAxis = DynObj.combine currentAxis realAxis |> unbox let updatedSmith = - smith |> Smith.setRealAxis updatedAxis + smith |> Smith.setRealAxis updatedAxis layout |> Layout.updateSmithById (id, updatedSmith) @@ -2364,10 +2364,10 @@ type Chart = let currentAxis = ternary |> Ternary.getAAxis - let updatedAxis = DynObj.combine currentAxis aAxis + let updatedAxis = DynObj.combine currentAxis aAxis |> unbox let updatedTernary = - ternary |> Ternary.setAAxis updatedAxis + ternary |> Ternary.setAAxis updatedAxis layout |> Layout.updateTernaryById (id, updatedTernary) @@ -2423,7 +2423,7 @@ type Chart = let currentAxis = ternary |> Ternary.getBAxis - let updatedAxis = DynObj.combine currentAxis bAxis + let updatedAxis = DynObj.combine currentAxis bAxis |> unbox let updatedTernary = ternary |> Ternary.setBAxis updatedAxis @@ -2482,7 +2482,7 @@ type Chart = let currentAxis = ternary |> Ternary.getCAxis - let updatedAxis = DynObj.combine currentAxis cAxis + let updatedAxis = DynObj.combine currentAxis cAxis |> unbox let updatedTernary = ternary |> Ternary.setCAxis updatedAxis @@ -3176,8 +3176,9 @@ type Chart = calculateSubplotTitlePositions 0. 1. xGap yGap nRows nCols reversed titles - |> Seq.zip positions[0 .. (Seq.length titles) - 1] - |> Seq.map (fun (((rowIndex, colIndex), (x, y)), title) -> + |> Array.ofSeq + |> Array.zip positions[0 .. (Seq.length titles) - 1] + |> Array.map (fun (((rowIndex, colIndex), (x, y)), title) -> Annotation.init( X = x, XRef = "paper", @@ -3199,7 +3200,8 @@ type Chart = gCharts |> Seq.zip gridCoordinates - |> Seq.mapi (fun i ((rowIndex, colIndex), gChart) -> + |> Array.ofSeq + |> Array.mapi (fun i ((rowIndex, colIndex), gChart) -> let layout = gChart |> GenericChart.getLayout @@ -3217,12 +3219,12 @@ type Chart = let yAxis = layout.TryGetTypedPropertyValue "yaxis" |> Option.defaultValue (LinearAxis.init ()) - let allXAxes = Layout.getXAxes layout |> Seq.map fst - let allYAxes = Layout.getYAxes layout |> Seq.map fst + let allXAxes = Layout.getXAxes layout |> Array.map fst + let allYAxes = Layout.getYAxes layout |> Array.map fst // remove all axes from layout. Only cartesian axis in each dimension is supported per grid cell, and leaving anything else on this layout may lead to property name clashes on combine. - allXAxes |> Seq.iter (fun propName -> layout.RemoveProperty(propName) |> ignore) - allYAxes |> Seq.iter (fun propName -> layout.RemoveProperty(propName) |> ignore) + allXAxes |> Array.iter (fun propName -> layout.RemoveProperty(propName) |> ignore) + allYAxes |> Array.iter (fun propName -> layout.RemoveProperty(propName) |> ignore) let xAnchor, yAnchor = if hasSharedAxes then @@ -3230,11 +3232,12 @@ type Chart = else i + 1, i + 1 - gChart - |> Chart.withAxisAnchor (xAnchor, yAnchor) // set adapted axis anchors - |> Chart.withXAxis (xAxis, (StyleParam.SubPlotId.XAxis(i + 1))) // set previous axis with adapted id (one individual axis for each subplot, whether or not they will be used later) - |> Chart.withYAxis (yAxis, (StyleParam.SubPlotId.YAxis(i + 1))) // set previous axis with adapted id (one individual axis for each subplot, whether or not they will be used later) - + let lol = + gChart + |> Chart.withAxisAnchor (xAnchor, yAnchor) // set adapted axis anchors + |> Chart.withXAxis (xAxis, (StyleParam.SubPlotId.XAxis(i + 1))) // set previous axis with adapted id (one individual axis for each subplot, whether or not they will be used later) + |> Chart.withYAxis (yAxis, (StyleParam.SubPlotId.YAxis(i + 1))) // set previous axis with adapted id (one individual axis for each subplot, whether or not they will be used later) + lol | TraceID.Cartesian3D -> let scene = @@ -3242,10 +3245,10 @@ type Chart = |> Option.defaultValue (Scene.init ()) |> Scene.style (Domain = LayoutObjects.Domain.init (Row = rowIndex - 1, Column = colIndex - 1)) - let allScenes = Layout.getScenes layout |> Seq.map fst + let allScenes = Layout.getScenes layout |> Array.map fst // remove all scenes from layout. Only one scene is supported per grid cell, and leaving anything else on this layout may lead to property name clashes on combine. - allScenes |> Seq.iter (fun propName -> layout.RemoveProperty(propName) |> ignore) + allScenes |> Array.iter (fun propName -> layout.RemoveProperty(propName) |> ignore) let sceneAnchor = StyleParam.SubPlotId.Scene(i + 1) @@ -3260,10 +3263,10 @@ type Chart = |> Option.defaultValue (Polar.init ()) |> Polar.style (Domain = LayoutObjects.Domain.init (Row = rowIndex - 1, Column = colIndex - 1)) - let allPolars = Layout.getPolars layout |> Seq.map fst + let allPolars = Layout.getPolars layout |> Array.map fst // remove all polar subplots from layout. Only one polar subplot is supported per grid cell, and leaving anything else on this layout may lead to property name clashes on combine. - allPolars |> Seq.iter (fun propName -> layout.RemoveProperty(propName) |> ignore) + allPolars |> Array.iter (fun propName -> layout.RemoveProperty(propName) |> ignore) let polarAnchor = StyleParam.SubPlotId.Polar(i + 1) @@ -3280,10 +3283,10 @@ type Chart = |> Option.defaultValue (Smith.init ()) |> Smith.style (Domain = LayoutObjects.Domain.init (Row = rowIndex - 1, Column = colIndex - 1)) - let allSmiths = Layout.getSmiths layout |> Seq.map fst + let allSmiths = Layout.getSmiths layout |> Array.map fst // remove all smith subplots from layout. Only one smith subplot is supported per grid cell, and leaving anything else on this layout may lead to property name clashes on combine. - allSmiths |> Seq.iter (fun propName -> layout.RemoveProperty(propName) |> ignore) + allSmiths |> Array.iter (fun propName -> layout.RemoveProperty(propName) |> ignore) let polarAnchor = StyleParam.SubPlotId.Smith(i + 1) @@ -3299,10 +3302,10 @@ type Chart = |> Option.defaultValue (Geo.init ()) |> Geo.style (Domain = LayoutObjects.Domain.init (Row = rowIndex - 1, Column = colIndex - 1)) - let allGeos = Layout.getGeos layout |> Seq.map fst + let allGeos = Layout.getGeos layout |> Array.map fst // remove all geo subplots from layout. Only one geo subplot is supported per grid cell, and leaving anything else on this layout may lead to property name clashes on combine. - allGeos |> Seq.iter (fun propName -> layout.RemoveProperty(propName) |> ignore) + allGeos |> Array.iter (fun propName -> layout.RemoveProperty(propName) |> ignore) let geoAnchor = StyleParam.SubPlotId.Geo(i + 1) @@ -3319,10 +3322,10 @@ type Chart = Domain = LayoutObjects.Domain.init (Row = rowIndex - 1, Column = colIndex - 1) ) - let allMapboxes = Layout.getMapboxes layout |> Seq.map fst + let allMapboxes = Layout.getMapboxes layout |> Array.map fst // remove all mapbox subplots from layout. Only one mapbox subplot is supported per grid cell, and leaving anything else on this layout may lead to property name clashes on combine. - allMapboxes |> Seq.iter (fun propName -> layout.RemoveProperty(propName) |> ignore) + allMapboxes |> Array.iter (fun propName -> layout.RemoveProperty(propName) |> ignore) let geoAnchor = StyleParam.SubPlotId.Geo(i + 1) @@ -3344,10 +3347,10 @@ type Chart = Domain = LayoutObjects.Domain.init (Row = rowIndex - 1, Column = colIndex - 1) ) - let allTernaries = Layout.getTernaries layout |> Seq.map fst + let allTernaries = Layout.getTernaries layout |> Array.map fst // remove all ternary subplots from layout. Only one ternary subplot is supported per grid cell, and leaving anything else on this layout may lead to property name clashes on combine. - allTernaries |> Seq.iter (fun propName -> layout.RemoveProperty(propName) |> ignore) + allTernaries |> Array.iter (fun propName -> layout.RemoveProperty(propName) |> ignore) let ternaryAnchor = StyleParam.SubPlotId.Ternary(i + 1) diff --git a/src/Plotly.NET/Config/Config.fs b/src/Plotly.NET/Config/Config.fs index 01b2e043..c6c85d14 100644 --- a/src/Plotly.NET/Config/Config.fs +++ b/src/Plotly.NET/Config/Config.fs @@ -334,7 +334,7 @@ type Config() = (second.TryGetTypedPropertyValue>>("modeBarButtons")) DynObj.combine first second - |> unbox + |> unbox |> Config.style ( ?ModeBarButtonsToRemove = (modeBarButtonsToRemove |> Option.map (Seq.map StyleParam.ModeBarButton.ofString)), ?ModeBarButtonsToAdd = (modeBarButtonsToAdd |> Option.map (Seq.map StyleParam.ModeBarButton.ofString)), diff --git a/src/Plotly.NET/DisplayOptions/DisplayOptions.fs b/src/Plotly.NET/DisplayOptions/DisplayOptions.fs index 1821fb2d..27bf8202 100644 --- a/src/Plotly.NET/DisplayOptions/DisplayOptions.fs +++ b/src/Plotly.NET/DisplayOptions/DisplayOptions.fs @@ -107,7 +107,7 @@ type DisplayOptions() = (second.TryGetTypedPropertyValue("ChartDescription")) DynObj.combine first second - |> unbox + |> unbox |> DisplayOptions.style (?AdditionalHeadTags = additionalHeadTags, ?ChartDescription = description) /// diff --git a/src/Plotly.NET/Globals.fs b/src/Plotly.NET/Globals.fs index 86934d90..fbe2cac6 100644 --- a/src/Plotly.NET/Globals.fs +++ b/src/Plotly.NET/Globals.fs @@ -52,11 +52,11 @@ let LOGO_BASE64 = """iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAMAAACdt4HsAAAA1VBMVEVHcEwQnv+gCXURnf+gCXURnf8Rnf+gCXURnf+gCXWgCXURnf+gCHURnf+gCXURnf+gCXURnf+gCXUwke5YVbykBXEijO+gCXURnf8Rnf8Rnf8Rnf8Rnf8Rnf+gCXWIIoygCXUohekRnf8Rnf8Qn/+gCXUQnf8SoP////8ijO+PG4agAnGQLY6gEnrP7f94yP8aof8YwP/DY6jJcrDuz+RlwP/owt0Urv8k/v4e4v9Nr9F1XaSxMoyx3/9rc7Ayq/98UZ3gr9L8+v05rv9Fv9rF5/+7T52h9OprAAAAJHRSTlMAINTUgPmA+gYGNbu7NR9PR/xP/hoh/o74f471R3x8uie60TS1lKLVAAABzUlEQVRYw83X2XKCMBQGYOyK3RdL9x0ChVCkVAHFfXn/RyphKSIBE85Mp8woV/8HOUByIgj/+mg2yb8o1s4/nZHTw2NNobmzf0HOp/d7Ys18Apzv1hHCvJICqIZA8hnAL0T5FYBXiPOrAJ+Q5HMAj5Dm8wC78JtfA1iFLK8oeYBNWM1vvQitltB4QxxCLn8gXD2/NoTjbXZhLX9ypH8c8giFvKJLiEMo5gnALlDyEcAq0PIxwCZQ8wnAItDzKbBZKObNBJDlMCFvEor5YQ8buDfUJdt3kevb1QLl+j2vb4y9OZZ8z0a251feA238uG8qZh/rkmurSLXdqjrQ62eQn5EWsaqS9Dweh3ewDOI7aHdG5ULJ8yM1WE67cQ0604FaJqx/v0leGc6x8aV94+gpWNqiTR3FrShcU68fHqYSA3J47Qwgwnsm3NxtBtR2NVA2BKcbxIC1mFUOoaSIZldzIuDyU+tkAPtjoAMcLwIV4HkVaQDXx0ABOD9HZxIYwcTRJWswQrOBxT8hpBMKIi+xWmdK4pvS4JMqfFqHLyzwpQ2+uMKXd3iDAW9x4E0WvM2DN5rwVhfebMPbffiGA77lgW+64Ns++MYTvvX9m+MHc8vmMWg2fMUAAAAASUVORK5CYII=""" /// -let internal JSON_CONFIG = +let JSON_CONFIG = JsonSerializerSettings(ReferenceLoopHandling = ReferenceLoopHandling.Serialize) /// the mathjax v2 tags to add to html docs for rendering latex -let internal MATHJAX_V2_TAGS = +let MATHJAX_V2_TAGS = [ script [ @@ -76,7 +76,7 @@ let internal MATHJAX_V2_TAGS = ] /// the mathjax v3 tags to add to html docs for rendering latex -let internal MATHJAX_V3_TAGS = +let MATHJAX_V3_TAGS = [ script [] diff --git a/src/Plotly.NET/Layout/Layout.fs b/src/Plotly.NET/Layout/Layout.fs index 4a432270..a0ad6ac9 100644 --- a/src/Plotly.NET/Layout/Layout.fs +++ b/src/Plotly.NET/Layout/Layout.fs @@ -525,7 +525,7 @@ type Layout() = (second.TryGetTypedPropertyValue>("updatemenus")) DynObj.combine first second - |> unbox + |> unbox |> Layout.style ( ?Annotations = annotations, ?Shapes = shapes, @@ -562,7 +562,7 @@ type Layout() = | StyleParam.SubPlotId.YAxis _ -> let axis' = match Layout.tryGetLinearAxisById id layout with - | Some a -> DynObj.combine a axis + | Some a -> DynObj.combine a axis |> unbox | None -> axis layout |> DynObj.withProperty (StyleParam.SubPlotId.toString id) axis' @@ -585,7 +585,8 @@ type Layout() = /// The layout to get the x axes from static member getXAxes (layout: Layout) = layout.GetProperties(includeInstanceProperties = false) - |> Seq.choose (fun kv -> + |> Array.ofSeq + |> Array.choose (fun kv -> if StyleParam.SubPlotId.isValidXAxisId kv.Key then match layout.TryGetTypedPropertyValue(kv.Key) with | Some axis -> Some (kv.Key, axis) @@ -599,7 +600,8 @@ type Layout() = /// The layout to get the y axes from static member getYAxes (layout: Layout) = layout.GetProperties(includeInstanceProperties = false) - |> Seq.choose (fun kv -> + |> Array.ofSeq + |> Array.choose (fun kv -> if StyleParam.SubPlotId.isValidYAxisId kv.Key then match layout.TryGetTypedPropertyValue(kv.Key) with | Some axis -> Some (kv.Key, axis) @@ -661,7 +663,8 @@ type Layout() = /// The layout to get the scenes from static member getScenes (layout: Layout) = layout.GetProperties(includeInstanceProperties = false) - |> Seq.choose (fun kv -> + |> Array.ofSeq + |> Array.choose (fun kv -> if StyleParam.SubPlotId.isValidSceneId kv.Key then match layout.TryGetTypedPropertyValue(kv.Key) with | Some scene -> Some (kv.Key, scene) @@ -716,7 +719,8 @@ type Layout() = /// The layout to get the geos from static member getGeos (layout: Layout) = layout.GetProperties(includeInstanceProperties = false) - |> Seq.choose (fun kv -> + |> Array.ofSeq + |> Array.choose (fun kv -> if StyleParam.SubPlotId.isValidGeoId kv.Key then match layout.TryGetTypedPropertyValue(kv.Key) with | Some geo -> Some (kv.Key, geo) @@ -771,7 +775,8 @@ type Layout() = /// The layout to get the mapboxes from static member getMapboxes (layout: Layout) = layout.GetProperties(includeInstanceProperties = false) - |> Seq.choose (fun kv -> + |> Array.ofSeq + |> Array.choose (fun kv -> if StyleParam.SubPlotId.isValidMapboxId kv.Key then match layout.TryGetTypedPropertyValue(kv.Key) with | Some mapbox -> Some (kv.Key, mapbox) @@ -827,7 +832,8 @@ type Layout() = /// The layout to get the polars from static member getPolars (layout: Layout) = layout.GetProperties(includeInstanceProperties = false) - |> Seq.choose (fun kv -> + |> Array.ofSeq + |> Array.choose (fun kv -> if StyleParam.SubPlotId.isValidPolarId kv.Key then match layout.TryGetTypedPropertyValue(kv.Key) with | Some polar -> Some (kv.Key, polar) @@ -883,7 +889,8 @@ type Layout() = /// The layout to get the smiths from static member getSmiths (layout: Layout) = layout.GetProperties(includeInstanceProperties = false) - |> Seq.choose (fun kv -> + |> Array.ofSeq + |> Array.choose (fun kv -> if StyleParam.SubPlotId.isValidSmithId kv.Key then match layout.TryGetTypedPropertyValue(kv.Key) with | Some smith -> Some (kv.Key, smith) @@ -939,7 +946,8 @@ type Layout() = /// The layout to get the color axes from static member getColorAxes (layout: Layout) = layout.GetProperties(includeInstanceProperties = false) - |> Seq.choose (fun kv -> + |> Array.ofSeq + |> Array.choose (fun kv -> if StyleParam.SubPlotId.isValidColorAxisId kv.Key then match layout.TryGetTypedPropertyValue(kv.Key) with | Some colorAxis -> Some (kv.Key, colorAxis) @@ -995,7 +1003,8 @@ type Layout() = /// The layout to get the ternaries from static member getTernaries (layout: Layout) = layout.GetProperties(includeInstanceProperties = false) - |> Seq.choose (fun kv -> + |> Array.ofSeq + |> Array.choose (fun kv -> if StyleParam.SubPlotId.isValidTernaryId kv.Key then match layout.TryGetTypedPropertyValue(kv.Key) with | Some ternary -> Some (kv.Key, ternary) @@ -1038,7 +1047,7 @@ type Layout() = static member updateLayoutGrid(layoutGrid: LayoutGrid) = (fun (layout: Layout) -> let combined = - DynObj.combine (layout |> Layout.getLayoutGrid) layoutGrid + DynObj.combine (layout |> Layout.getLayoutGrid) layoutGrid |> unbox layout |> Layout.setLayoutGrid combined) @@ -1055,7 +1064,8 @@ type Layout() = /// The layout to get the color axes from static member getLegends (layout: Layout) = layout.GetProperties(includeInstanceProperties = false) - |> Seq.choose (fun kv -> + |> Array.ofSeq + |> Array.choose (fun kv -> if StyleParam.SubPlotId.isValidLegendId kv.Key then match layout.TryGetTypedPropertyValue(kv.Key) with | Some legend -> Some (kv.Key, legend) diff --git a/src/Plotly.NET/Layout/ObjectAbstractions/Common/NewSelection.fs b/src/Plotly.NET/Layout/ObjectAbstractions/Common/NewSelection.fs index 8ddb48c3..c3f1c19f 100644 --- a/src/Plotly.NET/Layout/ObjectAbstractions/Common/NewSelection.fs +++ b/src/Plotly.NET/Layout/ObjectAbstractions/Common/NewSelection.fs @@ -46,5 +46,5 @@ type NewSelection() = newSelection |> DynObj.withProperty "line" line - |> DynObj.setOptionalPropertyBy "mode" Mode StyleParam.NewSelectionMode.convert + |> DynObj.withOptionalPropertyBy "mode" Mode StyleParam.NewSelectionMode.convert ) diff --git a/src/Plotly.NET/Layout/ObjectAbstractions/Common/Shape.fs b/src/Plotly.NET/Layout/ObjectAbstractions/Common/Shape.fs index 0e4675b4..3c346a4d 100644 --- a/src/Plotly.NET/Layout/ObjectAbstractions/Common/Shape.fs +++ b/src/Plotly.NET/Layout/ObjectAbstractions/Common/Shape.fs @@ -200,31 +200,31 @@ type Shape() = fun (shape: Shape) -> shape - |> DynObj.withProperty "editable" Editable - |> DynObj.withProperty "fillcolor" FillColor + |> DynObj.withOptionalProperty "editable" Editable + |> DynObj.withOptionalProperty "fillcolor" FillColor |> DynObj.withOptionalPropertyBy "fillrule" FillRule StyleParam.FillRule.convert - |> DynObj.withProperty "label" Label - |> DynObj.withProperty "showlegend" ShowLegend + |> DynObj.withOptionalProperty "label" Label + |> DynObj.withOptionalProperty "showlegend" ShowLegend |> DynObj.withOptionalPropertyBy "legend" Legend StyleParam.SubPlotId.convert - |> DynObj.withProperty "legendrank" LegendRank - |> DynObj.withProperty "legendgroup" LegendGroup - |> DynObj.withProperty "legendgrouptitle" LegendGroupTitle - |> DynObj.withProperty "legendwidth" LegendWidth + |> DynObj.withOptionalProperty "legendrank" LegendRank + |> DynObj.withOptionalProperty "legendgroup" LegendGroup + |> DynObj.withOptionalProperty "legendgrouptitle" LegendGroupTitle + |> DynObj.withOptionalProperty "legendwidth" LegendWidth |> DynObj.withOptionalPropertyBy "layer" Layer StyleParam.Layer.convert - |> DynObj.withProperty "line" Line - |> DynObj.withProperty "name" Name - |> DynObj.withProperty "opacity" Opacity - |> DynObj.withProperty "path" Path - |> DynObj.withProperty "templateitemname" TemplateItemName + |> DynObj.withOptionalProperty "line" Line + |> DynObj.withOptionalProperty "name" Name + |> DynObj.withOptionalProperty "opacity" Opacity + |> DynObj.withOptionalProperty "path" Path + |> DynObj.withOptionalProperty "templateitemname" TemplateItemName |> DynObj.withOptionalPropertyBy "type" ShapeType StyleParam.ShapeType.convert - |> DynObj.withProperty "visible" Visible - |> DynObj.withProperty "x0" X0 - |> DynObj.withProperty "x1" X1 + |> DynObj.withOptionalProperty "visible" Visible + |> DynObj.withOptionalProperty "x0" X0 + |> DynObj.withOptionalProperty "x1" X1 |> DynObj.withOptionalPropertyBy "xanchor" XAnchor StyleParam.LinearAxisId.convert - |> DynObj.withProperty "xref" Xref + |> DynObj.withOptionalProperty "xref" Xref |> DynObj.withOptionalPropertyBy "xsizemode" XSizeMode StyleParam.ShapeSizeMode.convert - |> DynObj.withProperty "y0" Y0 - |> DynObj.withProperty "y1" Y1 + |> DynObj.withOptionalProperty "y0" Y0 + |> DynObj.withOptionalProperty "y1" Y1 |> DynObj.withOptionalPropertyBy "yanchor" YAnchor StyleParam.LinearAxisId.convert - |> DynObj.withProperty "yref" Yref + |> DynObj.withOptionalProperty "yref" Yref |> DynObj.withOptionalPropertyBy "ysizemode" YSizeMode StyleParam.ShapeSizeMode.convert diff --git a/src/Plotly.NET/Plotly.NET.fsproj b/src/Plotly.NET/Plotly.NET.fsproj index 92720c05..4431ce9e 100644 --- a/src/Plotly.NET/Plotly.NET.fsproj +++ b/src/Plotly.NET/Plotly.NET.fsproj @@ -168,7 +168,7 @@ - + diff --git a/src/Plotly.NET/Traces/ObjectAbstractions/Dimensions.fs b/src/Plotly.NET/Traces/ObjectAbstractions/Dimensions.fs index 533e4483..bdb06a8f 100644 --- a/src/Plotly.NET/Traces/ObjectAbstractions/Dimensions.fs +++ b/src/Plotly.NET/Traces/ObjectAbstractions/Dimensions.fs @@ -87,7 +87,7 @@ type Dimension() = let axis = LinearAxis.init (?AxisType = AxisType) - |> DynObj.setOptionalProperty "matches" AxisMatches + |> DynObj.withOptionalProperty "matches" AxisMatches dims |> DynObj.withOptionalProperty "label" Label diff --git a/src/Plotly.NET/Traces/ObjectAbstractions/Sankey.fs b/src/Plotly.NET/Traces/ObjectAbstractions/Sankey.fs index ddf32856..bf3067ba 100644 --- a/src/Plotly.NET/Traces/ObjectAbstractions/Sankey.fs +++ b/src/Plotly.NET/Traces/ObjectAbstractions/Sankey.fs @@ -186,4 +186,5 @@ type SankeyLinks() = |> DynObj.withOptionalProperty "line" Line |> DynObj.withOptionalProperty "source" Source |> DynObj.withOptionalProperty "target" Target + |> DynObj.withOptionalProperty "value" Value diff --git a/src/Plotly.NET/Traces/Trace.fs b/src/Plotly.NET/Traces/Trace.fs index 4ebca7a9..d9eb9e73 100644 --- a/src/Plotly.NET/Traces/Trace.fs +++ b/src/Plotly.NET/Traces/Trace.fs @@ -49,7 +49,7 @@ type Trace(traceTypeName: string) = static member updateMarker(marker: Marker) = (fun (trace: #Trace) -> let combined = - (DynObj.combine (trace |> Trace.getMarker) marker) + (DynObj.combine (trace |> Trace.getMarker) marker) |> unbox trace |> Trace.setMarker combined) @@ -78,7 +78,7 @@ type Trace(traceTypeName: string) = static member updateLine(line: Line) = (fun (trace: #Trace) -> let combined = - (DynObj.combine (trace |> Trace.getLine) line) + (DynObj.combine (trace |> Trace.getLine) line) |> unbox trace |> Trace.setLine combined) @@ -107,7 +107,7 @@ type Trace(traceTypeName: string) = static member updateXError(error: Error) = (fun (trace: #Trace) -> let combined = - (DynObj.combine (trace |> Trace.getXError) error) + (DynObj.combine (trace |> Trace.getXError) error) |> unbox trace |> Trace.setXError combined) @@ -136,7 +136,7 @@ type Trace(traceTypeName: string) = static member updateYError(error: Error) = (fun (trace: #Trace) -> let combined = - (DynObj.combine (trace |> Trace.getYError) error) + (DynObj.combine (trace |> Trace.getYError) error) |> unbox trace |> Trace.setYError combined) @@ -165,7 +165,7 @@ type Trace(traceTypeName: string) = static member updateZError(error: Error) = (fun (trace: #Trace) -> let combined = - (DynObj.combine (trace |> Trace.getZError) error) + (DynObj.combine (trace |> Trace.getZError) error) |> unbox trace |> Trace.setZError combined) @@ -248,7 +248,7 @@ type Trace(traceTypeName: string) = static member updateDomain(domain: Domain) = (fun (trace: #Trace) -> let combined = - (DynObj.combine (trace |> Trace.getDomain) domain) + (DynObj.combine (trace |> Trace.getDomain) domain) |> unbox trace |> Trace.setDomain combined) @@ -296,7 +296,7 @@ type Trace(traceTypeName: string) = static member updateColorBar(colorBar: ColorBar) = (fun (trace: #Trace) -> let combined = - DynObj.combine (trace |> Trace.getColorBar) colorBar + DynObj.combine (trace |> Trace.getColorBar) colorBar |> unbox trace |> Trace.setColorBar combined) diff --git a/src/Plotly.NET/Traces/Trace2D.fs b/src/Plotly.NET/Traces/Trace2D.fs index f193e02f..aa6e7dbf 100644 --- a/src/Plotly.NET/Traces/Trace2D.fs +++ b/src/Plotly.NET/Traces/Trace2D.fs @@ -105,8 +105,8 @@ type Trace2DStyle() = ) = fun (trace: Trace2D) -> trace - |> DynObj.withOptionalProperty "xaxis" X - |> DynObj.withOptionalProperty "yaxis" Y + |> DynObj.withOptionalPropertyBy "xaxis" X StyleParam.LinearAxisId.convert + |> DynObj.withOptionalPropertyBy "yaxis" Y StyleParam.LinearAxisId.convert /// /// Create a function that applies the styles of a scatter plot to a Trace object diff --git a/tests/Common/FSharpTestBase/TestUtils.fs b/tests/Common/FSharpTestBase/TestUtils.fs index fe10a58d..1b754de4 100644 --- a/tests/Common/FSharpTestBase/TestUtils.fs +++ b/tests/Common/FSharpTestBase/TestUtils.fs @@ -213,6 +213,18 @@ module JsonGen = let json = chart |> GenericChart.toFigureJson Expect.equal json expected $"JSON not equal to expected value." + let layoutJsonIs chart expected = + let json = + let layout = GenericChart.getLayout chart + JsonConvert.SerializeObject(layout, Globals.JSON_CONFIG) + Expect.equal json expected $"Layout JSON not equal to expected value." + + let tracesJsonIs (expectedJson: string) (chart: GenericChart) = + let json = + let traces = GenericChart.getTraces chart + JsonConvert.SerializeObject(traces, Globals.JSON_CONFIG) + Expect.equal json expectedJson $"Traces JSON not equal to expected value" + module Objects = let jsonFieldIsSetWith fieldName expected (object:#DynamicObj) = diff --git a/tests/ConsoleApps/FSharpConsole/FSharpConsole.fsproj b/tests/ConsoleApps/FSharpConsole/FSharpConsole.fsproj index 8ca3ea8e..0e9fd6d5 100644 --- a/tests/ConsoleApps/FSharpConsole/FSharpConsole.fsproj +++ b/tests/ConsoleApps/FSharpConsole/FSharpConsole.fsproj @@ -15,6 +15,7 @@ + diff --git a/tests/ConsoleApps/FSharpConsole/Program.fs b/tests/ConsoleApps/FSharpConsole/Program.fs index 09bf2e52..ef6f626d 100644 --- a/tests/ConsoleApps/FSharpConsole/Program.fs +++ b/tests/ConsoleApps/FSharpConsole/Program.fs @@ -11,22 +11,8 @@ open Newtonsoft.Json [] let main args = - let x = [1.; 2.; 3.; 4.; 5.; 6.; 7.; 8.; 9.; 10.; ] - let y = [2.; 1.5; 5.; 1.5; 3.; 2.5; 2.5; 1.5; 3.5; 1.] - [ - Chart.Point(x = x, y = y, UseDefaults = false) - |> Chart.withYAxisStyle("This title must") - - Chart.Line(x = x, y = y, UseDefaults = false) - |> Chart.withYAxisStyle("be set on the",ZeroLine=false) - - Chart.Spline(x = x, y = y, UseDefaults = false) - |> Chart.withYAxisStyle("respective subplots",ZeroLine=false) - ] - |> Chart.SingleStack(Pattern = StyleParam.LayoutGridPattern.Coupled) - //move xAxis to bottom and increase spacing between plots by using the withLayoutGridStyle function - |> Chart.withLayoutGridStyle(XSide=StyleParam.LayoutGridXSide.Bottom,YGap= 0.1) - |> Chart.withTitle("Hi i am the new SingleStackChart") - |> Chart.withXAxisStyle("im the shared xAxis") + + ChartDomainTestCharts.Sankey.``Styled sankey chart`` + |> Chart.show 0 \ No newline at end of file diff --git a/tests/CoreTests/CoreTests/FeatureAdditions/Grid_SubPlotTitles.fs b/tests/CoreTests/CoreTests/FeatureAdditions/Grid_SubPlotTitles.fs index bcb68542..59619a44 100644 --- a/tests/CoreTests/CoreTests/FeatureAdditions/Grid_SubPlotTitles.fs +++ b/tests/CoreTests/CoreTests/FeatureAdditions/Grid_SubPlotTitles.fs @@ -5,6 +5,7 @@ open Plotly.NET open Plotly.NET.LayoutObjects open Plotly.NET.TraceObjects +open TestUtils open TestUtils.HtmlCodegen open Grid_SubPlotTitles_TestCharts @@ -14,8 +15,8 @@ module ``Add logic for positioning subplot titles in LayoutGrid #388`` = let ``Add subplot titles`` = testList "FeatureAddition.Add subplot titles in LayoutGrid" [ test "cartesian 2x2 grid data" { - """var data = [{"type":"scatter","mode":"markers","x":[1],"y":[2],"marker":{},"line":{},"xaxis":"x","yaxis":"y"},{"type":"scatter","mode":"markers","x":[1],"y":[2],"marker":{},"line":{},"xaxis":"x2","yaxis":"y2"},{"type":"scatter","mode":"markers","x":[1],"y":[2],"marker":{},"line":{},"xaxis":"x3","yaxis":"y3"},{"type":"scatter","mode":"markers","x":[1],"y":[2],"marker":{},"line":{},"xaxis":"x4","yaxis":"y4"}];""" - |> chartGeneratedContains ``Add logic for positioning subplot titles in LayoutGrid #388``.``cartesian 2x2 grid with subplot titles`` + ``Add logic for positioning subplot titles in LayoutGrid #388``.``cartesian 2x2 grid with subplot titles`` + |> JsonGen.tracesJsonIs """[{"type":"scatter","mode":"markers","x":[1],"y":[2],"marker":{},"line":{},"xaxis":"x","yaxis":"y"},{"type":"scatter","mode":"markers","x":[1],"y":[2],"marker":{},"line":{},"xaxis":"x2","yaxis":"y2"},{"type":"scatter","mode":"markers","x":[1],"y":[2],"marker":{},"line":{},"xaxis":"x3","yaxis":"y3"},{"type":"scatter","mode":"markers","x":[1],"y":[2],"marker":{},"line":{},"xaxis":"x4","yaxis":"y4"}]""" } test "cartesian 2x2 grid layout" { """var layout = {"xaxis":{},"yaxis":{},"xaxis2":{},"yaxis2":{},"xaxis3":{},"yaxis3":{},"xaxis4":{},"yaxis4":{},"annotations":[{"x":0.22222222222222224,"y":1.0,"showarrow":false,"text":"1,1","xanchor":"center","xref":"paper","yanchor":"bottom","yref":"paper"},{"x":0.7777777777777778,"y":1.0,"showarrow":false,"text":"1,2","xanchor":"center","xref":"paper","yanchor":"bottom","yref":"paper"},{"x":0.22222222222222224,"y":0.4117647058823529,"showarrow":false,"text":"2,1","xanchor":"center","xref":"paper","yanchor":"bottom","yref":"paper"},{"x":0.7777777777777778,"y":0.4117647058823529,"showarrow":false,"text":"2,2","xanchor":"center","xref":"paper","yanchor":"bottom","yref":"paper"}],"grid":{"rows":2,"columns":2,"roworder":"top to bottom","pattern":"independent"}};""" diff --git a/tests/CoreTests/CoreTests/HTMLCodegen/ChartDomain.fs b/tests/CoreTests/CoreTests/HTMLCodegen/ChartDomain.fs index 27a5ee80..61c1a03b 100644 --- a/tests/CoreTests/CoreTests/HTMLCodegen/ChartDomain.fs +++ b/tests/CoreTests/CoreTests/HTMLCodegen/ChartDomain.fs @@ -6,6 +6,7 @@ open Plotly.NET.LayoutObjects open Plotly.NET.TraceObjects +open TestUtils open TestUtils.HtmlCodegen open ChartDomainTestCharts @@ -155,8 +156,8 @@ module Sankey = testList "HTMLCodegen.ChartDomain" [ testList "Sankey" [ testCase "Sankey data" ( fun () -> - """var data = [{"type":"sankey","node":{"label":["A1","A2","B1","B2","C1","C2","D1"],"line":{"color":"rgba(0, 0, 0, 1.0)","width":1.0}},"link":{"color":["rgba(130, 139, 251, 1.0)","rgba(130, 139, 251, 1.0)","rgba(242, 119, 98, 1.0)","rgba(51, 214, 171, 1.0)","rgba(188, 130, 251, 1.0)","rgba(188, 130, 251, 1.0)","rgba(255, 180, 123, 1.0)","rgba(71, 220, 245, 1.0)"],"line":{"color":"rgba(0, 0, 0, 1.0)","width":1.0},"source":[0,0,1,2,3,3,4,5],"target":[2,3,3,4,4,5,6,6],"value":[8,4,2,7,3,2,5,2]}}];""" - |> chartGeneratedContains Sankey.``Styled sankey chart`` + Sankey.``Styled sankey chart`` + |> JsonGen.tracesJsonIs """[{"type":"sankey","node":{"label":["A1","A2","B1","B2","C1","C2","D1"],"line":{"color":"rgba(0, 0, 0, 1.0)","width":1.0}},"link":{"color":["rgba(130, 139, 251, 1.0)","rgba(130, 139, 251, 1.0)","rgba(242, 119, 98, 1.0)","rgba(51, 214, 171, 1.0)","rgba(188, 130, 251, 1.0)","rgba(188, 130, 251, 1.0)","rgba(255, 180, 123, 1.0)","rgba(71, 220, 245, 1.0)"],"line":{"color":"rgba(0, 0, 0, 1.0)","width":1.0},"source":[0,0,1,2,3,3,4,5],"target":[2,3,3,4,4,5,6,6],"value":[8,4,2,7,3,2,5,2]}}]""" ) testCase "Sankey layout" ( fun () -> emptyLayout Sankey.``Styled sankey chart`` diff --git a/tests/CoreTests/CoreTests/Traces/TraceStaticMembers.fs b/tests/CoreTests/CoreTests/Traces/TraceStaticMembers.fs index 2693b4c2..fbc0b975 100644 --- a/tests/CoreTests/CoreTests/Traces/TraceStaticMembers.fs +++ b/tests/CoreTests/CoreTests/Traces/TraceStaticMembers.fs @@ -87,7 +87,7 @@ let ``TraceStyle tests`` = ) let colorAxisAnchor = StyleParam.SubPlotId.ColorAxis 69 - let colorAxisAnchorTrace = Trace2D.initScatter(Trace2DStyle.Heatmap(ColorAxis = colorAxisAnchor)) + let colorAxisAnchorTrace = Trace2D.initHeatmap(Trace2DStyle.Heatmap(ColorAxis = colorAxisAnchor)) testCase "getColorAxisAnchor" (fun _ -> Expect.equal