Skip to content

Commit

Permalink
Fix #446, add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kMutagene committed Mar 13, 2024
1 parent a1b438a commit 290bfc6
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 30 deletions.
11 changes: 9 additions & 2 deletions src/Plotly.NET/CommonAbstractions/StyleParams.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1557,40 +1557,47 @@ module StyleParam =
// #H#
//--------------------------

[<RequireQualifiedAccess>]
type HoverInfo =
| X
| XY
| XYZ
| XYZText
| XYZTextName
| Y
| YZ
| YZText
| YZTextNames
| YZTextName
| Z
| ZText
| ZTextName
| Text
| TextName
| Name
| All
| None
| Skip

static member toString =
function
| X -> "x"
| XY -> "x+y"
| XYZ -> "x+y+z"
| XYZText -> "x+y+z+text"
| XYZTextName -> "x+y+z+text+name"
| Y -> "y"
| YZ -> "y+z"
| YZText -> "y+z+text"
| YZTextNames -> "y+z+text+name"
| YZTextName -> "y+z+text+name"
| Z -> "z"
| ZText -> "z+text"
| ZTextName -> "z+text+name"
| Text -> "text"
| TextName -> "text+name"
| Name -> "name"
| All -> "all"
| None -> "none"
| Skip -> "skip"

static member convert = HoverInfo.toString >> box
override this.ToString() = this |> HoverInfo.toString
Expand Down
1 change: 1 addition & 0 deletions tests/Common/FSharpTestBase/FSharpTestBase.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
</ItemGroup>

<ItemGroup>
<Compile Include="TestCharts\FeatureAdditions\Fix_HoverInfo.fs" />
<Compile Include="TestCharts\FeatureAdditions\UpdateMenuButton_Args.fs" />
<Compile Include="TestCharts\FeatureAdditions\Accessible_Contours.fs" />
<Compile Include="TestCharts\UpstreamFeatures\2.27.fs" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
module Fix_HoverInfo_TestCharts

open Plotly.NET
open Plotly.NET.TraceObjects
open Plotly.NET.LayoutObjects
open DynamicObj

// https://github.com/plotly/Plotly.NET/issues/446

module ``Fix missing HoverInfo bindings #446`` =

let ``Point3D charts with all possible hoverinfo combinations`` =
[
StyleParam.HoverInfo.X
StyleParam.HoverInfo.XY
StyleParam.HoverInfo.XYZ
StyleParam.HoverInfo.XYZText
StyleParam.HoverInfo.XYZTextName
StyleParam.HoverInfo.Y
StyleParam.HoverInfo.YZ
StyleParam.HoverInfo.YZText
StyleParam.HoverInfo.YZTextName
StyleParam.HoverInfo.Z
StyleParam.HoverInfo.ZText
StyleParam.HoverInfo.ZTextName
StyleParam.HoverInfo.Text
StyleParam.HoverInfo.TextName
StyleParam.HoverInfo.Name
StyleParam.HoverInfo.All
StyleParam.HoverInfo.None
StyleParam.HoverInfo.Skip
]
|> List.mapi (fun i hi ->
Chart.Point3D(
xyz = [i + 1, i + 2, i + 3],
Name = $"NAME: trace with {hi.ToString()}",
Text = $"TEXT: trace with {hi.ToString()}",
UseDefaults = false
)
|> GenericChart.mapTrace (Trace3DStyle.Scatter3D(HoverInfo = hi))
)
|> Chart.combine
|> Chart.withSize(1000,1000)
57 changes: 29 additions & 28 deletions tests/ConsoleApps/FSharpConsole/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -9,38 +9,39 @@ open DynamicObj
open Giraffe.ViewEngine
open Newtonsoft.Json

let getZeroCollection n : float []=
Array.zeroCreate n

[<EntryPoint>]
let main argv =

let buttons =
[ for i in 0 .. 9 ->
UpdateMenuButton.init(
Label = $"0 - {i}",
Name = $"{i}",
Visible = true,
Method = StyleParam.UpdateMethod.Relayout,
Args = (
let tmp = DynamicObj()
tmp?("xaxis.range") <- [0; i]
tmp?("yaxis.range") <- [0; i]
[tmp]
)
)
]

Chart.Point(

x = [0 .. 10],
y = [0 .. 10],
UseDefaults = false
)
|> Chart.withUpdateMenu(
UpdateMenu.init(
Buttons = buttons
[
StyleParam.HoverInfo.X
StyleParam.HoverInfo.XY
StyleParam.HoverInfo.XYZ
StyleParam.HoverInfo.XYZText
StyleParam.HoverInfo.XYZTextName
StyleParam.HoverInfo.Y
StyleParam.HoverInfo.YZ
StyleParam.HoverInfo.YZText
StyleParam.HoverInfo.YZTextName
StyleParam.HoverInfo.Z
StyleParam.HoverInfo.ZText
StyleParam.HoverInfo.ZTextName
StyleParam.HoverInfo.Text
StyleParam.HoverInfo.TextName
StyleParam.HoverInfo.Name
StyleParam.HoverInfo.All
StyleParam.HoverInfo.None
StyleParam.HoverInfo.Skip
]
|> List.mapi (fun i hi ->
Chart.Point3D(
xyz = [i + 1, i + 2, i + 3],
Name = $"NAME: trace with {hi.ToString()}",
Text = $"TEXT: trace with {hi.ToString()}",
UseDefaults = false
)
|> GenericChart.mapTrace (Trace3DStyle.Scatter3D(HoverInfo = hi))
)
|> Chart.combine
|> Chart.withSize(1000,1000)
|> Chart.show
0
1 change: 1 addition & 0 deletions tests/CoreTests/CoreTests/CoreTests.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
<Compile Include="UpstreamFeatures\2.21.fs" />
<Compile Include="UpstreamFeatures\2.20.fs" />
<Compile Include="UpstreamFeatures\2.19.fs" />
<Compile Include="FeatureAdditions\Fix_HoverInfo.fs" />
<Compile Include="FeatureAdditions\UpdateMenuButton_Args.fs" />
<Compile Include="FeatureAdditions\Accessible_Contours.fs" />
<Compile Include="Main.fs" />
Expand Down
24 changes: 24 additions & 0 deletions tests/CoreTests/CoreTests/FeatureAdditions/Fix_HoverInfo.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
module CoreTests.Fix_HoverInfo

open Expecto
open Plotly.NET
open Plotly.NET.LayoutObjects
open Plotly.NET.TraceObjects

open TestUtils.HtmlCodegen
open Fix_HoverInfo_TestCharts

module ``Fix missing HoverInfo bindings #446`` =

[<Tests>]
let ``Implement all HoverInfo options for #446`` =
testList "FeatureAddition.Fix missing HoverInfo bindings" [
test "all hoverinfo options combined data" {
"""var data = [{"type":"scatter3d","name":"NAME: trace with x","mode":"markers","x":[1],"y":[2],"z":[3],"text":"TEXT: trace with x","marker":{},"line":{},"hoverinfo":"x"},{"type":"scatter3d","name":"NAME: trace with x+y","mode":"markers","x":[2],"y":[3],"z":[4],"text":"TEXT: trace with x+y","marker":{},"line":{},"hoverinfo":"x+y"},{"type":"scatter3d","name":"NAME: trace with x+y+z","mode":"markers","x":[3],"y":[4],"z":[5],"text":"TEXT: trace with x+y+z","marker":{},"line":{},"hoverinfo":"x+y+z"},{"type":"scatter3d","name":"NAME: trace with x+y+z+text","mode":"markers","x":[4],"y":[5],"z":[6],"text":"TEXT: trace with x+y+z+text","marker":{},"line":{},"hoverinfo":"x+y+z+text"},{"type":"scatter3d","name":"NAME: trace with x+y+z+text+name","mode":"markers","x":[5],"y":[6],"z":[7],"text":"TEXT: trace with x+y+z+text+name","marker":{},"line":{},"hoverinfo":"x+y+z+text+name"},{"type":"scatter3d","name":"NAME: trace with y","mode":"markers","x":[6],"y":[7],"z":[8],"text":"TEXT: trace with y","marker":{},"line":{},"hoverinfo":"y"},{"type":"scatter3d","name":"NAME: trace with y+z","mode":"markers","x":[7],"y":[8],"z":[9],"text":"TEXT: trace with y+z","marker":{},"line":{},"hoverinfo":"y+z"},{"type":"scatter3d","name":"NAME: trace with y+z+text","mode":"markers","x":[8],"y":[9],"z":[10],"text":"TEXT: trace with y+z+text","marker":{},"line":{},"hoverinfo":"y+z+text"},{"type":"scatter3d","name":"NAME: trace with y+z+text+name","mode":"markers","x":[9],"y":[10],"z":[11],"text":"TEXT: trace with y+z+text+name","marker":{},"line":{},"hoverinfo":"y+z+text+name"},{"type":"scatter3d","name":"NAME: trace with z","mode":"markers","x":[10],"y":[11],"z":[12],"text":"TEXT: trace with z","marker":{},"line":{},"hoverinfo":"z"},{"type":"scatter3d","name":"NAME: trace with z+text","mode":"markers","x":[11],"y":[12],"z":[13],"text":"TEXT: trace with z+text","marker":{},"line":{},"hoverinfo":"z+text"},{"type":"scatter3d","name":"NAME: trace with z+text+name","mode":"markers","x":[12],"y":[13],"z":[14],"text":"TEXT: trace with z+text+name","marker":{},"line":{},"hoverinfo":"z+text+name"},{"type":"scatter3d","name":"NAME: trace with text","mode":"markers","x":[13],"y":[14],"z":[15],"text":"TEXT: trace with text","marker":{},"line":{},"hoverinfo":"text"},{"type":"scatter3d","name":"NAME: trace with text+name","mode":"markers","x":[14],"y":[15],"z":[16],"text":"TEXT: trace with text+name","marker":{},"line":{},"hoverinfo":"text+name"},{"type":"scatter3d","name":"NAME: trace with name","mode":"markers","x":[15],"y":[16],"z":[17],"text":"TEXT: trace with name","marker":{},"line":{},"hoverinfo":"name"},{"type":"scatter3d","name":"NAME: trace with all","mode":"markers","x":[16],"y":[17],"z":[18],"text":"TEXT: trace with all","marker":{},"line":{},"hoverinfo":"all"},{"type":"scatter3d","name":"NAME: trace with none","mode":"markers","x":[17],"y":[18],"z":[19],"text":"TEXT: trace with none","marker":{},"line":{},"hoverinfo":"none"},{"type":"scatter3d","name":"NAME: trace with skip","mode":"markers","x":[18],"y":[19],"z":[20],"text":"TEXT: trace with skip","marker":{},"line":{},"hoverinfo":"skip"}];"""
|> chartGeneratedContains ``Fix missing HoverInfo bindings #446``.``Point3D charts with all possible hoverinfo combinations``
}
test "all hoverinfo options combined layout" {
"""var layout = {"scene":{"camera":{"projection":{"type":"perspective"}}},"width":1000,"height":1000};"""
|> chartGeneratedContains ``Fix missing HoverInfo bindings #446``.``Point3D charts with all possible hoverinfo combinations``
}
]

0 comments on commit 290bfc6

Please sign in to comment.