Skip to content

Commit

Permalink
fix #414 :
Browse files Browse the repository at this point in the history
- UpdateMenuButton Args is now a collection of DynamicObj
- Add tests
  • Loading branch information
kMutagene committed Jan 26, 2024
1 parent 17b6e35 commit f107eba
Show file tree
Hide file tree
Showing 6 changed files with 133 additions and 7 deletions.
8 changes: 4 additions & 4 deletions src/Plotly.NET/Layout/ObjectAbstractions/Common/UpdateMenu.fs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ type UpdateMenuButton() =

static member init
(
[<Optional; DefaultParameterValue(null)>] ?Args: seq<string>,
[<Optional; DefaultParameterValue(null)>] ?Args2: seq<string>,
[<Optional; DefaultParameterValue(null)>] ?Args: seq<DynamicObj>,
[<Optional; DefaultParameterValue(null)>] ?Args2: seq<DynamicObj>,
[<Optional; DefaultParameterValue(null)>] ?Execute: bool,
[<Optional; DefaultParameterValue(null)>] ?Label: string,
[<Optional; DefaultParameterValue(null)>] ?Method: StyleParam.UpdateMethod,
Expand All @@ -34,8 +34,8 @@ type UpdateMenuButton() =

static member style
(
[<Optional; DefaultParameterValue(null)>] ?Args: seq<string>,
[<Optional; DefaultParameterValue(null)>] ?Args2: seq<string>,
[<Optional; DefaultParameterValue(null)>] ?Args: seq<DynamicObj>,
[<Optional; DefaultParameterValue(null)>] ?Args2: seq<DynamicObj>,
[<Optional; DefaultParameterValue(null)>] ?Execute: bool,
[<Optional; DefaultParameterValue(null)>] ?Label: string,
[<Optional; DefaultParameterValue(null)>] ?Method: StyleParam.UpdateMethod,
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\UpdateMenuButton_Args.fs" />
<Compile Include="TestCharts\FeatureAdditions\Accessible_Contours.fs" />
<Compile Include="TestCharts\UpstreamFeatures\2.27.fs" />
<Compile Include="TestCharts\UpstreamFeatures\2.26.fs" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
module UpdateMenuButton_Args_TestCharts

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

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

module ``UpdateMenuButton Args as DynamicObj collection #414`` =

let ``Simple point chart with update buttons triggerin relayout for x axis range`` =
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]
)
)
]

Chart.Point(
x = [0 .. 10],
y = [0 .. 10],
UseDefaults = false
)
|> Chart.withUpdateMenu(
UpdateMenu.init(
Buttons = buttons
)
)

let ``Simple point chart with update buttons triggerin relayout for x and y axis range`` =

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
)
)
29 changes: 26 additions & 3 deletions tests/ConsoleApps/FSharpConsole/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,33 @@ let getZeroCollection n : float []=

[<EntryPoint>]
let main argv =
Chart.Histogram2DContour(
MultiX = [["A";"A";"A";"B";"B"];["AA"; "AA"; "AB"; "BA"; "BB"]],
MultiY = [["A";"A";"A";"B";"B"];["AA"; "AA"; "AB"; "BA"; "BB"]],

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
)
)
|> 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\UpdateMenuButton_Args.fs" />
<Compile Include="FeatureAdditions\Accessible_Contours.fs" />
<Compile Include="Main.fs" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// https://github.com/plotly/Plotly.NET/issues/414

module CoreTests.UpdateMenuButton_Args

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

open TestUtils.HtmlCodegen
open UpdateMenuButton_Args_TestCharts

module ``UpdateMenuButton Args as DynamicObj collection #414`` =

[<Tests>]
let ``UpdateMenuButton Args as DynamicObj collection #414`` =
testList "FeatureAddition.UpdateMenuButton Args must be DynamicObj collection" [
test "relayout x axis range data" {
"""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":{}}];"""
|> chartGeneratedContains ``UpdateMenuButton Args as DynamicObj collection #414``.``Simple point chart with update buttons triggerin relayout for x axis range``
}
test "relayout x axis range layout" {
"""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}]}]};"""
|> chartGeneratedContains ``UpdateMenuButton Args as DynamicObj collection #414``.``Simple point chart with update buttons triggerin relayout for x axis range``
}
test "relayout x and y axis range data" {
"""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":{}}];"""
|> chartGeneratedContains ``UpdateMenuButton Args as DynamicObj collection #414``.``Simple point chart with update buttons triggerin relayout for x and y axis range``
}
test "relayout x and y axis range layout" {
"""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}]}]};"""
|> chartGeneratedContains ``UpdateMenuButton Args as DynamicObj collection #414``.``Simple point chart with update buttons triggerin relayout for x and y axis range``
}
]

0 comments on commit f107eba

Please sign in to comment.