Skip to content

Commit 290bfc6

Browse files
committed
Fix #446, add tests
1 parent a1b438a commit 290bfc6

File tree

6 files changed

+107
-30
lines changed

6 files changed

+107
-30
lines changed

src/Plotly.NET/CommonAbstractions/StyleParams.fs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1557,40 +1557,47 @@ module StyleParam =
15571557
// #H#
15581558
//--------------------------
15591559

1560+
[<RequireQualifiedAccess>]
15601561
type HoverInfo =
15611562
| X
15621563
| XY
15631564
| XYZ
15641565
| XYZText
1566+
| XYZTextName
15651567
| Y
15661568
| YZ
15671569
| YZText
1568-
| YZTextNames
1570+
| YZTextName
15691571
| Z
15701572
| ZText
15711573
| ZTextName
15721574
| Text
15731575
| TextName
15741576
| Name
15751577
| All
1578+
| None
1579+
| Skip
15761580

15771581
static member toString =
15781582
function
15791583
| X -> "x"
15801584
| XY -> "x+y"
15811585
| XYZ -> "x+y+z"
15821586
| XYZText -> "x+y+z+text"
1587+
| XYZTextName -> "x+y+z+text+name"
15831588
| Y -> "y"
15841589
| YZ -> "y+z"
15851590
| YZText -> "y+z+text"
1586-
| YZTextNames -> "y+z+text+name"
1591+
| YZTextName -> "y+z+text+name"
15871592
| Z -> "z"
15881593
| ZText -> "z+text"
15891594
| ZTextName -> "z+text+name"
15901595
| Text -> "text"
15911596
| TextName -> "text+name"
15921597
| Name -> "name"
15931598
| All -> "all"
1599+
| None -> "none"
1600+
| Skip -> "skip"
15941601

15951602
static member convert = HoverInfo.toString >> box
15961603
override this.ToString() = this |> HoverInfo.toString

tests/Common/FSharpTestBase/FSharpTestBase.fsproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
</ItemGroup>
1313

1414
<ItemGroup>
15+
<Compile Include="TestCharts\FeatureAdditions\Fix_HoverInfo.fs" />
1516
<Compile Include="TestCharts\FeatureAdditions\UpdateMenuButton_Args.fs" />
1617
<Compile Include="TestCharts\FeatureAdditions\Accessible_Contours.fs" />
1718
<Compile Include="TestCharts\UpstreamFeatures\2.27.fs" />
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
module Fix_HoverInfo_TestCharts
2+
3+
open Plotly.NET
4+
open Plotly.NET.TraceObjects
5+
open Plotly.NET.LayoutObjects
6+
open DynamicObj
7+
8+
// https://github.com/plotly/Plotly.NET/issues/446
9+
10+
module ``Fix missing HoverInfo bindings #446`` =
11+
12+
let ``Point3D charts with all possible hoverinfo combinations`` =
13+
[
14+
StyleParam.HoverInfo.X
15+
StyleParam.HoverInfo.XY
16+
StyleParam.HoverInfo.XYZ
17+
StyleParam.HoverInfo.XYZText
18+
StyleParam.HoverInfo.XYZTextName
19+
StyleParam.HoverInfo.Y
20+
StyleParam.HoverInfo.YZ
21+
StyleParam.HoverInfo.YZText
22+
StyleParam.HoverInfo.YZTextName
23+
StyleParam.HoverInfo.Z
24+
StyleParam.HoverInfo.ZText
25+
StyleParam.HoverInfo.ZTextName
26+
StyleParam.HoverInfo.Text
27+
StyleParam.HoverInfo.TextName
28+
StyleParam.HoverInfo.Name
29+
StyleParam.HoverInfo.All
30+
StyleParam.HoverInfo.None
31+
StyleParam.HoverInfo.Skip
32+
]
33+
|> List.mapi (fun i hi ->
34+
Chart.Point3D(
35+
xyz = [i + 1, i + 2, i + 3],
36+
Name = $"NAME: trace with {hi.ToString()}",
37+
Text = $"TEXT: trace with {hi.ToString()}",
38+
UseDefaults = false
39+
)
40+
|> GenericChart.mapTrace (Trace3DStyle.Scatter3D(HoverInfo = hi))
41+
)
42+
|> Chart.combine
43+
|> Chart.withSize(1000,1000)

tests/ConsoleApps/FSharpConsole/Program.fs

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -9,38 +9,39 @@ open DynamicObj
99
open Giraffe.ViewEngine
1010
open Newtonsoft.Json
1111

12-
let getZeroCollection n : float []=
13-
Array.zeroCreate n
14-
1512
[<EntryPoint>]
1613
let main argv =
1714

18-
let buttons =
19-
[ for i in 0 .. 9 ->
20-
UpdateMenuButton.init(
21-
Label = $"0 - {i}",
22-
Name = $"{i}",
23-
Visible = true,
24-
Method = StyleParam.UpdateMethod.Relayout,
25-
Args = (
26-
let tmp = DynamicObj()
27-
tmp?("xaxis.range") <- [0; i]
28-
tmp?("yaxis.range") <- [0; i]
29-
[tmp]
30-
)
31-
)
32-
]
33-
34-
Chart.Point(
35-
36-
x = [0 .. 10],
37-
y = [0 .. 10],
38-
UseDefaults = false
39-
)
40-
|> Chart.withUpdateMenu(
41-
UpdateMenu.init(
42-
Buttons = buttons
15+
[
16+
StyleParam.HoverInfo.X
17+
StyleParam.HoverInfo.XY
18+
StyleParam.HoverInfo.XYZ
19+
StyleParam.HoverInfo.XYZText
20+
StyleParam.HoverInfo.XYZTextName
21+
StyleParam.HoverInfo.Y
22+
StyleParam.HoverInfo.YZ
23+
StyleParam.HoverInfo.YZText
24+
StyleParam.HoverInfo.YZTextName
25+
StyleParam.HoverInfo.Z
26+
StyleParam.HoverInfo.ZText
27+
StyleParam.HoverInfo.ZTextName
28+
StyleParam.HoverInfo.Text
29+
StyleParam.HoverInfo.TextName
30+
StyleParam.HoverInfo.Name
31+
StyleParam.HoverInfo.All
32+
StyleParam.HoverInfo.None
33+
StyleParam.HoverInfo.Skip
34+
]
35+
|> List.mapi (fun i hi ->
36+
Chart.Point3D(
37+
xyz = [i + 1, i + 2, i + 3],
38+
Name = $"NAME: trace with {hi.ToString()}",
39+
Text = $"TEXT: trace with {hi.ToString()}",
40+
UseDefaults = false
4341
)
42+
|> GenericChart.mapTrace (Trace3DStyle.Scatter3D(HoverInfo = hi))
4443
)
44+
|> Chart.combine
45+
|> Chart.withSize(1000,1000)
4546
|> Chart.show
4647
0

tests/CoreTests/CoreTests/CoreTests.fsproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
<Compile Include="UpstreamFeatures\2.21.fs" />
4646
<Compile Include="UpstreamFeatures\2.20.fs" />
4747
<Compile Include="UpstreamFeatures\2.19.fs" />
48+
<Compile Include="FeatureAdditions\Fix_HoverInfo.fs" />
4849
<Compile Include="FeatureAdditions\UpdateMenuButton_Args.fs" />
4950
<Compile Include="FeatureAdditions\Accessible_Contours.fs" />
5051
<Compile Include="Main.fs" />
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
module CoreTests.Fix_HoverInfo
2+
3+
open Expecto
4+
open Plotly.NET
5+
open Plotly.NET.LayoutObjects
6+
open Plotly.NET.TraceObjects
7+
8+
open TestUtils.HtmlCodegen
9+
open Fix_HoverInfo_TestCharts
10+
11+
module ``Fix missing HoverInfo bindings #446`` =
12+
13+
[<Tests>]
14+
let ``Implement all HoverInfo options for #446`` =
15+
testList "FeatureAddition.Fix missing HoverInfo bindings" [
16+
test "all hoverinfo options combined data" {
17+
"""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"}];"""
18+
|> chartGeneratedContains ``Fix missing HoverInfo bindings #446``.``Point3D charts with all possible hoverinfo combinations``
19+
}
20+
test "all hoverinfo options combined layout" {
21+
"""var layout = {"scene":{"camera":{"projection":{"type":"perspective"}}},"width":1000,"height":1000};"""
22+
|> chartGeneratedContains ``Fix missing HoverInfo bindings #446``.``Point3D charts with all possible hoverinfo combinations``
23+
}
24+
]

0 commit comments

Comments
 (0)