Skip to content

Commit f107eba

Browse files
committed
fix #414 :
- UpdateMenuButton Args is now a collection of DynamicObj - Add tests
1 parent 17b6e35 commit f107eba

File tree

6 files changed

+133
-7
lines changed

6 files changed

+133
-7
lines changed

src/Plotly.NET/Layout/ObjectAbstractions/Common/UpdateMenu.fs

+4-4
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ type UpdateMenuButton() =
1010

1111
static member init
1212
(
13-
[<Optional; DefaultParameterValue(null)>] ?Args: seq<string>,
14-
[<Optional; DefaultParameterValue(null)>] ?Args2: seq<string>,
13+
[<Optional; DefaultParameterValue(null)>] ?Args: seq<DynamicObj>,
14+
[<Optional; DefaultParameterValue(null)>] ?Args2: seq<DynamicObj>,
1515
[<Optional; DefaultParameterValue(null)>] ?Execute: bool,
1616
[<Optional; DefaultParameterValue(null)>] ?Label: string,
1717
[<Optional; DefaultParameterValue(null)>] ?Method: StyleParam.UpdateMethod,
@@ -34,8 +34,8 @@ type UpdateMenuButton() =
3434

3535
static member style
3636
(
37-
[<Optional; DefaultParameterValue(null)>] ?Args: seq<string>,
38-
[<Optional; DefaultParameterValue(null)>] ?Args2: seq<string>,
37+
[<Optional; DefaultParameterValue(null)>] ?Args: seq<DynamicObj>,
38+
[<Optional; DefaultParameterValue(null)>] ?Args2: seq<DynamicObj>,
3939
[<Optional; DefaultParameterValue(null)>] ?Execute: bool,
4040
[<Optional; DefaultParameterValue(null)>] ?Label: string,
4141
[<Optional; DefaultParameterValue(null)>] ?Method: StyleParam.UpdateMethod,

tests/Common/FSharpTestBase/FSharpTestBase.fsproj

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
</ItemGroup>
1313

1414
<ItemGroup>
15+
<Compile Include="TestCharts\FeatureAdditions\UpdateMenuButton_Args.fs" />
1516
<Compile Include="TestCharts\FeatureAdditions\Accessible_Contours.fs" />
1617
<Compile Include="TestCharts\UpstreamFeatures\2.27.fs" />
1718
<Compile Include="TestCharts\UpstreamFeatures\2.26.fs" />
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
module UpdateMenuButton_Args_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/414
9+
10+
module ``UpdateMenuButton Args as DynamicObj collection #414`` =
11+
12+
let ``Simple point chart with update buttons triggerin relayout for x axis range`` =
13+
let buttons =
14+
[ for i in 0 .. 9 ->
15+
UpdateMenuButton.init(
16+
Label = $"0 - {i}",
17+
Name = $"{i}",
18+
Visible = true,
19+
Method = StyleParam.UpdateMethod.Relayout,
20+
Args = (
21+
let tmp = DynamicObj()
22+
tmp?("xaxis.range") <- [0; i]
23+
[tmp]
24+
)
25+
)
26+
]
27+
28+
Chart.Point(
29+
x = [0 .. 10],
30+
y = [0 .. 10],
31+
UseDefaults = false
32+
)
33+
|> Chart.withUpdateMenu(
34+
UpdateMenu.init(
35+
Buttons = buttons
36+
)
37+
)
38+
39+
let ``Simple point chart with update buttons triggerin relayout for x and y axis range`` =
40+
41+
let buttons =
42+
[ for i in 0 .. 9 ->
43+
UpdateMenuButton.init(
44+
Label = $"0 - {i}",
45+
Name = $"{i}",
46+
Visible = true,
47+
Method = StyleParam.UpdateMethod.Relayout,
48+
Args = (
49+
let tmp = DynamicObj()
50+
tmp?("xaxis.range") <- [0; i]
51+
tmp?("yaxis.range") <- [0; i]
52+
[tmp]
53+
)
54+
)
55+
]
56+
57+
Chart.Point(
58+
59+
x = [0 .. 10],
60+
y = [0 .. 10],
61+
UseDefaults = false
62+
)
63+
|> Chart.withUpdateMenu(
64+
UpdateMenu.init(
65+
Buttons = buttons
66+
)
67+
)

tests/ConsoleApps/FSharpConsole/Program.fs

+26-3
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,33 @@ let getZeroCollection n : float []=
1414

1515
[<EntryPoint>]
1616
let main argv =
17-
Chart.Histogram2DContour(
18-
MultiX = [["A";"A";"A";"B";"B"];["AA"; "AA"; "AB"; "BA"; "BB"]],
19-
MultiY = [["A";"A";"A";"B";"B"];["AA"; "AA"; "AB"; "BA"; "BB"]],
17+
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],
2038
UseDefaults = false
2139
)
40+
|> Chart.withUpdateMenu(
41+
UpdateMenu.init(
42+
Buttons = buttons
43+
)
44+
)
2245
|> Chart.show
2346
0

tests/CoreTests/CoreTests/CoreTests.fsproj

+1
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\UpdateMenuButton_Args.fs" />
4849
<Compile Include="FeatureAdditions\Accessible_Contours.fs" />
4950
<Compile Include="Main.fs" />
5051
</ItemGroup>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// https://github.com/plotly/Plotly.NET/issues/414
2+
3+
module CoreTests.UpdateMenuButton_Args
4+
5+
open Expecto
6+
open Plotly.NET
7+
open Plotly.NET.LayoutObjects
8+
open Plotly.NET.TraceObjects
9+
10+
open TestUtils.HtmlCodegen
11+
open UpdateMenuButton_Args_TestCharts
12+
13+
module ``UpdateMenuButton Args as DynamicObj collection #414`` =
14+
15+
[<Tests>]
16+
let ``UpdateMenuButton Args as DynamicObj collection #414`` =
17+
testList "FeatureAddition.UpdateMenuButton Args must be DynamicObj collection" [
18+
test "relayout x axis range data" {
19+
"""var data = [{"type":"scatter","mode":"markers","x":[0,1,2,3,4,5,6,7,8,9,10],"y":[0,1,2,3,4,5,6,7,8,9,10],"marker":{},"line":{}}];"""
20+
|> chartGeneratedContains ``UpdateMenuButton Args as DynamicObj collection #414``.``Simple point chart with update buttons triggerin relayout for x axis range``
21+
}
22+
test "relayout x axis range layout" {
23+
"""var layout = {"updatemenus":[{"buttons":[{"args":[{"xaxis.range":[0,0]}],"label":"0 - 0","method":"relayout","name":"0","visible":true},{"args":[{"xaxis.range":[0,1]}],"label":"0 - 1","method":"relayout","name":"1","visible":true},{"args":[{"xaxis.range":[0,2]}],"label":"0 - 2","method":"relayout","name":"2","visible":true},{"args":[{"xaxis.range":[0,3]}],"label":"0 - 3","method":"relayout","name":"3","visible":true},{"args":[{"xaxis.range":[0,4]}],"label":"0 - 4","method":"relayout","name":"4","visible":true},{"args":[{"xaxis.range":[0,5]}],"label":"0 - 5","method":"relayout","name":"5","visible":true},{"args":[{"xaxis.range":[0,6]}],"label":"0 - 6","method":"relayout","name":"6","visible":true},{"args":[{"xaxis.range":[0,7]}],"label":"0 - 7","method":"relayout","name":"7","visible":true},{"args":[{"xaxis.range":[0,8]}],"label":"0 - 8","method":"relayout","name":"8","visible":true},{"args":[{"xaxis.range":[0,9]}],"label":"0 - 9","method":"relayout","name":"9","visible":true}]}]};"""
24+
|> chartGeneratedContains ``UpdateMenuButton Args as DynamicObj collection #414``.``Simple point chart with update buttons triggerin relayout for x axis range``
25+
}
26+
test "relayout x and y axis range data" {
27+
"""var data = [{"type":"scatter","mode":"markers","x":[0,1,2,3,4,5,6,7,8,9,10],"y":[0,1,2,3,4,5,6,7,8,9,10],"marker":{},"line":{}}];"""
28+
|> chartGeneratedContains ``UpdateMenuButton Args as DynamicObj collection #414``.``Simple point chart with update buttons triggerin relayout for x and y axis range``
29+
}
30+
test "relayout x and y axis range layout" {
31+
"""var layout = {"updatemenus":[{"buttons":[{"args":[{"xaxis.range":[0,0],"yaxis.range":[0,0]}],"label":"0 - 0","method":"relayout","name":"0","visible":true},{"args":[{"xaxis.range":[0,1],"yaxis.range":[0,1]}],"label":"0 - 1","method":"relayout","name":"1","visible":true},{"args":[{"xaxis.range":[0,2],"yaxis.range":[0,2]}],"label":"0 - 2","method":"relayout","name":"2","visible":true},{"args":[{"xaxis.range":[0,3],"yaxis.range":[0,3]}],"label":"0 - 3","method":"relayout","name":"3","visible":true},{"args":[{"xaxis.range":[0,4],"yaxis.range":[0,4]}],"label":"0 - 4","method":"relayout","name":"4","visible":true},{"args":[{"xaxis.range":[0,5],"yaxis.range":[0,5]}],"label":"0 - 5","method":"relayout","name":"5","visible":true},{"args":[{"xaxis.range":[0,6],"yaxis.range":[0,6]}],"label":"0 - 6","method":"relayout","name":"6","visible":true},{"args":[{"xaxis.range":[0,7],"yaxis.range":[0,7]}],"label":"0 - 7","method":"relayout","name":"7","visible":true},{"args":[{"xaxis.range":[0,8],"yaxis.range":[0,8]}],"label":"0 - 8","method":"relayout","name":"8","visible":true},{"args":[{"xaxis.range":[0,9],"yaxis.range":[0,9]}],"label":"0 - 9","method":"relayout","name":"9","visible":true}]}]};"""
32+
|> chartGeneratedContains ``UpdateMenuButton Args as DynamicObj collection #414``.``Simple point chart with update buttons triggerin relayout for x and y axis range``
33+
}
34+
]

0 commit comments

Comments
 (0)