Skip to content

Commit 39dcefa

Browse files
committed
#406: Add tests, remove legacy withLegend function
- fix `font` and `borderwidth` attributes of legends having switched names - this commit contains backwards incompatible changes
1 parent a776f77 commit 39dcefa

File tree

8 files changed

+90
-20
lines changed

8 files changed

+90
-20
lines changed

src/Plotly.NET/ChartAPI/Chart.fs

-10
Original file line numberDiff line numberDiff line change
@@ -2675,16 +2675,6 @@ type Chart =
26752675

26762676
GenericChart.addLayout layout ch)
26772677

2678-
// Set showLegend of a Chart
2679-
[<CompiledName("WithLegend")>]
2680-
static member withLegend(showlegend) =
2681-
(fun (ch: GenericChart) ->
2682-
let layout =
2683-
Layout() |> Layout.style (ShowLegend = showlegend)
2684-
2685-
GenericChart.addLayout layout ch)
2686-
2687-
26882678
/// Sets the size of a Chart (in pixels)
26892679
[<CompiledName("WithSize")>]
26902680
static member withSize

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,10 @@ type Legend() =
143143
(fun (legend: Legend) ->
144144
BGColor |> DynObj.setValueOpt legend "bgcolor"
145145
BorderColor |> DynObj.setValueOpt legend "bordercolor"
146-
BorderWidth |> DynObj.setValueOpt legend "font"
146+
BorderWidth |> DynObj.setValueOpt legend "borderwidth"
147147
EntryWidth |> DynObj.setValueOpt legend "entrywidth"
148148
EntryWidthMode |> DynObj.setValueOptBy legend "entrywidthmode" StyleParam.EntryWidthMode.convert
149-
Font |> DynObj.setValueOpt legend "borderwidth"
149+
Font |> DynObj.setValueOpt legend "font"
150150
GroupClick |> DynObj.setValueOptBy legend "groupclick" StyleParam.TraceGroupClickOptions.convert
151151
GroupTitleFont |> DynObj.setValueOpt legend "grouptitlefont"
152152
ItemClick |> DynObj.setValueOptBy legend "itemclick" StyleParam.TraceItemClickOptions.convert

tests/Common/FSharpTestBase/FSharpTestBase.fsproj

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
<Compile Include="TestCharts\ChartCarpetTestCharts.fs" />
2222
<Compile Include="TestCharts\ChartDomainTestCharts.fs" />
2323
<Compile Include="TestCharts\ChartSmithTestCharts.fs" />
24+
<Compile Include="TestCharts\UpstreamFeatures\2.22.0.fs" />
2425
<Compile Include="TestCharts\UpstreamFeatures\2.21.fs" />
2526
<Compile Include="TestCharts\UpstreamFeatures\2.20.fs" />
2627
<Compile Include="TestCharts\UpstreamFeatures\2.19.fs" />

tests/Common/FSharpTestBase/TestCharts/ChartMapTestCharts.fs

+2-2
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ module LineGeo =
134134
)
135135
)
136136
|> Chart.combine
137-
|> Chart.withLegend(false)
137+
|> Chart.withLayoutStyle(ShowLegend = false)
138138
|> Chart.withGeoStyle(
139139
Scope=StyleParam.GeoScope.NorthAmerica,
140140
Projection=GeoProjection.init(StyleParam.GeoProjectionType.AzimuthalEqualArea),
@@ -210,7 +210,7 @@ module LineMapbox =
210210
)
211211
)
212212
|> Chart.combine
213-
|> Chart.withLegend(false)
213+
|> Chart.withLayoutStyle(ShowLegend = false)
214214
|> Chart.withMapbox(
215215
Mapbox.init(
216216
Center=(-97.0372,32.8959)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
module PlotlyJS_2_22_TestCharts
2+
3+
open Plotly.NET
4+
open Plotly.NET.TraceObjects
5+
open Plotly.NET.LayoutObjects
6+
7+
8+
module MultiLegends =
9+
10+
let ``Two Line traces with one styled legend each``=
11+
[
12+
Chart.Point([1,2], UseDefaults = false)
13+
|> Chart.withLegendAnchor 1
14+
Chart.Point([100,200], UseDefaults = false)
15+
|> Chart.withLegendAnchor 2
16+
]
17+
|> Chart.combine
18+
|> Chart.withLegend(
19+
Legend.init(
20+
X = 0.25,
21+
Y = 0.25,
22+
BorderColor = Color.fromKeyword Blue,
23+
BorderWidth = 2,
24+
Title = Title.init(
25+
Text = "Legend 1"
26+
)
27+
),
28+
Id = 1
29+
)
30+
|> Chart.withLegend(
31+
Legend.init(
32+
X = 0.75,
33+
Y = 0.75,
34+
BorderColor = Color.fromKeyword Red,
35+
BorderWidth = 2,
36+
Title = Title.init(
37+
Text = "Legend 2"
38+
)
39+
),
40+
Id = 2
41+
)

tests/ConsoleApps/FSharpConsole/Program.fs

+16-6
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,33 @@ open Newtonsoft.Json
1212
[<EntryPoint>]
1313
let main argv =
1414
[
15-
Chart.Point([1,20], UseDefaults = false)
15+
Chart.Point([1,2], UseDefaults = false)
1616
|> Chart.withLegendAnchor 1
17-
Chart.Point([1,30], UseDefaults = false)
17+
Chart.Point([100,200], UseDefaults = false)
1818
|> Chart.withLegendAnchor 2
1919
]
2020
|> Chart.combine
2121
|> Chart.withLegend(
2222
Legend.init(
23-
X = 0,
24-
Y = 1
23+
X = 0.25,
24+
Y = 0.25,
25+
BorderColor = Color.fromKeyword Blue,
26+
BorderWidth = 2,
27+
Title = Title.init(
28+
Text = "Legend 1"
29+
)
2530
),
2631
Id = 1
2732
)
2833
|> Chart.withLegend(
2934
Legend.init(
30-
X = 0,
31-
Y = 0
35+
X = 0.75,
36+
Y = 0.75,
37+
BorderColor = Color.fromKeyword Red,
38+
BorderWidth = 2,
39+
Title = Title.init(
40+
Text = "Legend 2"
41+
)
3242
),
3343
Id = 2
3444
)

tests/CoreTests/CoreTests/CoreTests.fsproj

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
<Compile Include="Traces\TraceStaticMembers.fs" />
3737
<Compile Include="Traces\TraceStyle.fs" />
3838
<Compile Include="Traces\TraceID.fs" />
39+
<Compile Include="UpstreamFeatures\2.22.fs" />
3940
<Compile Include="UpstreamFeatures\2.21.fs" />
4041
<Compile Include="UpstreamFeatures\2.20.fs" />
4142
<Compile Include="UpstreamFeatures\2.19.fs" />
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
module CoreTests.UpstreamFeatures.PlotlyJS_2_22
2+
3+
open Expecto
4+
open Plotly.NET
5+
open Plotly.NET.LayoutObjects
6+
open Plotly.NET.TraceObjects
7+
8+
9+
open TestUtils.HtmlCodegen
10+
open PlotlyJS_2_22_TestCharts
11+
12+
module MultiLegends =
13+
14+
[<Tests>]
15+
let ``Multi legend chart HTML codegeneration tests`` =
16+
testList "UpstreamFeatures.PlotlyJS_2_22" [
17+
testList "Multi Legends" [
18+
testCase "Two Line traces with one styled legend each data" ( fun () ->
19+
"""var data = [{"type":"scatter","mode":"markers","x":[1],"y":[2],"marker":{},"line":{},"legend":"legend"},{"type":"scatter","mode":"markers","x":[100],"y":[200],"marker":{},"line":{},"legend":"legend2"}];"""
20+
|> chartGeneratedContains MultiLegends.``Two Line traces with one styled legend each``
21+
)
22+
testCase "Two Line traces with one styled legend each layout" ( fun () ->
23+
"""var layout = {"legend":{"bordercolor":"rgba(0, 0, 255, 1.0)","borderwidth":2.0,"title":{"text":"Legend 1"},"x":0.25,"y":0.25},"legend2":{"bordercolor":"rgba(255, 0, 0, 1.0)","borderwidth":2.0,"title":{"text":"Legend 2"},"x":0.75,"y":0.75}};"""
24+
|> chartGeneratedContains MultiLegends.``Two Line traces with one styled legend each``
25+
)
26+
]
27+
]

0 commit comments

Comments
 (0)