Skip to content

Commit a3e1abc

Browse files
committed
plotly.js v2.23: add xref and yref attributes for Legend and ColorBar
- add tests - add attributes to Chart API functions `withLegendStyle` and `withColorBarStyle`
1 parent 39dcefa commit a3e1abc

File tree

15 files changed

+261
-38
lines changed

15 files changed

+261
-38
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
[![Build and test](https://github.com/plotly/Plotly.NET/actions/workflows/build-and-test.yml/badge.svg)](https://github.com/plotly/Plotly.NET/actions/workflows/build-and-test.yml)
55
[![](https://img.shields.io/nuget/vpre/Plotly.NET)](https://www.nuget.org/packages/Plotly.NET/)
66
[![Discord](https://img.shields.io/discord/836161044501889064?color=purple&label=Join%20our%20Discord%21&logo=discord&logoColor=white)](https://discord.gg/k3kUtFY8DB)
7-
![](https://img.shields.io/badge/supported%20plotly.js%20version-2.21.0-blue)
7+
![](https://img.shields.io/badge/supported%20plotly.js%20version-2.23.2-blue)
88
[![DOI](https://img.shields.io/badge/DOI-10.12688%2Ff1000research.123971.1-brightgreen)](https://doi.org/10.12688/f1000research.123971.1)
99

1010
### Table of contents

src/Plotly.NET/ChartAPI/Chart.fs

+117-15
Large diffs are not rendered by default.

src/Plotly.NET/CommonAbstractions/ColorBar.fs

+13-3
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,11 @@ type ColorBar() =
5252
/// <param name="X">Sets the x position of the color bar (in plot fraction).</param>
5353
/// <param name="XAnchor">Sets this color bar's horizontal position anchor. This anchor binds the `x` position to the "left", "center" or "right" of the color bar.</param>
5454
/// <param name="XPad">Sets the amount of padding (in px) along the x direction.</param>
55+
/// <param name="XRef">Sets the container `x` refers to. "container" spans the entire `width` of the plot. "paper" refers to the width of the plotting area only.</param>
5556
/// <param name="Y">Sets the y position of the color bar (in plot fraction).</param>
5657
/// <param name="YAnchor">Sets this color bar's vertical position anchor This anchor binds the `y` position to the "top", "middle" or "bottom" of the color bar.</param>
5758
/// <param name="YPad">Sets the amount of padding (in px) along the y direction.</param>
59+
/// <param name="YRef">Sets the container `y` refers to. "container" spans the entire `height` of the plot. "paper" refers to the height of the plotting area only.</param>
5860
static member init
5961
(
6062
[<Optional; DefaultParameterValue(null)>] ?BGColor: Color,
@@ -98,9 +100,11 @@ type ColorBar() =
98100
[<Optional; DefaultParameterValue(null)>] ?X: float,
99101
[<Optional; DefaultParameterValue(null)>] ?XAnchor: StyleParam.HorizontalAlign,
100102
[<Optional; DefaultParameterValue(null)>] ?XPad: float,
103+
[<Optional; DefaultParameterValue(null)>] ?XRef: string,
101104
[<Optional; DefaultParameterValue(null)>] ?Y: float,
102105
[<Optional; DefaultParameterValue(null)>] ?YAnchor: StyleParam.VerticalAlign,
103-
[<Optional; DefaultParameterValue(null)>] ?YPad: float
106+
[<Optional; DefaultParameterValue(null)>] ?YPad: float,
107+
[<Optional; DefaultParameterValue(null)>] ?YRef: string
104108
) =
105109
ColorBar()
106110
|> ColorBar.style (
@@ -145,9 +149,11 @@ type ColorBar() =
145149
?X = X,
146150
?XAnchor = XAnchor,
147151
?XPad = XPad,
152+
?XRef = XRef,
148153
?Y = Y,
149154
?YAnchor = YAnchor,
150-
?YPad = YPad
155+
?YPad = YPad,
156+
?YRef = YRef
151157
)
152158

153159

@@ -240,9 +246,11 @@ type ColorBar() =
240246
[<Optional; DefaultParameterValue(null)>] ?X: float,
241247
[<Optional; DefaultParameterValue(null)>] ?XAnchor: StyleParam.HorizontalAlign,
242248
[<Optional; DefaultParameterValue(null)>] ?XPad: float,
249+
[<Optional; DefaultParameterValue(null)>] ?XRef: string,
243250
[<Optional; DefaultParameterValue(null)>] ?Y: float,
244251
[<Optional; DefaultParameterValue(null)>] ?YAnchor: StyleParam.VerticalAlign,
245-
[<Optional; DefaultParameterValue(null)>] ?YPad: float
252+
[<Optional; DefaultParameterValue(null)>] ?YPad: float,
253+
[<Optional; DefaultParameterValue(null)>] ?YRef: string
246254
) =
247255

248256
(fun (colorBar: ColorBar) ->
@@ -288,8 +296,10 @@ type ColorBar() =
288296
X |> DynObj.setValueOpt colorBar "x"
289297
XAnchor |> DynObj.setValueOptBy colorBar "xanchor" StyleParam.HorizontalAlign.convert
290298
XPad |> DynObj.setValueOpt colorBar "xpad"
299+
XRef |> DynObj.setValueOpt colorBar "xref"
291300
Y |> DynObj.setValueOpt colorBar "y"
292301
YAnchor |> DynObj.setValueOptBy colorBar "yanchor" StyleParam.VerticalAlign.convert
293302
YPad |> DynObj.setValueOpt colorBar "ypad"
303+
YRef |> DynObj.setValueOpt colorBar "yref"
294304

295305
colorBar)

src/Plotly.NET/Globals.fs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ open Giraffe.ViewEngine
77

88
/// The plotly js version loaded from cdn in rendered html docs
99
[<Literal>]
10-
let PLOTLYJS_VERSION = "2.22.0"
10+
let PLOTLYJS_VERSION = "2.23.2"
1111

1212
[<Literal>]
1313
let SCRIPT_TEMPLATE =

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

+15-3
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,10 @@ type Legend() =
3333
/// <param name="Visible">Determines whether or not this legend is visible.</param>
3434
/// <param name="X">Sets the x position (in normalized coordinates) of the legend. Defaults to "1.02" for vertical legends and defaults to "0" for horizontal legends.</param>
3535
/// <param name="XAnchor">Sets the legend's horizontal position anchor. This anchor binds the `x` position to the "left", "center" or "right" of the legend. Value "auto" anchors legends to the right for `x` values greater than or equal to 2/3, anchors legends to the left for `x` values less than or equal to 1/3 and anchors legends with respect to their center otherwise.</param>
36+
/// <param name="XRef">Sets the container `x` refers to. "container" spans the entire `width` of the plot. "paper" refers to the width of the plotting area only.</param>
3637
/// <param name="Y">Sets the y position (in normalized coordinates) of the legend. Defaults to "1" for vertical legends, defaults to "-0.1" for horizontal legends on graphs w/o range sliders and defaults to "1.1" for horizontal legends on graph with one or multiple range sliders.</param>
3738
/// <param name="YAnchor">Sets the legend's vertical position anchor This anchor binds the `y` position to the "top", "middle" or "bottom" of the legend. Value "auto" anchors legends at their bottom for `y` values less than or equal to 1/3, anchors legends to at their top for `y` values greater than or equal to 2/3 and anchors legends with respect to their middle otherwise.</param>
39+
/// <param name="YRef">Sets the container `y` refers to. "container" spans the entire `height` of the plot. "paper" refers to the height of the plotting area only.</param>
3840
static member init
3941
(
4042
[<Optional; DefaultParameterValue(null)>] ?BGColor: Color,
@@ -58,8 +60,10 @@ type Legend() =
5860
[<Optional; DefaultParameterValue(null)>] ?Visible: bool,
5961
[<Optional; DefaultParameterValue(null)>] ?X: float,
6062
[<Optional; DefaultParameterValue(null)>] ?XAnchor: StyleParam.XAnchorPosition,
63+
[<Optional; DefaultParameterValue(null)>] ?XRef: string,
6164
[<Optional; DefaultParameterValue(null)>] ?Y: float,
62-
[<Optional; DefaultParameterValue(null)>] ?YAnchor: StyleParam.YAnchorPosition
65+
[<Optional; DefaultParameterValue(null)>] ?YAnchor: StyleParam.YAnchorPosition,
66+
[<Optional; DefaultParameterValue(null)>] ?YRef: string
6367
) =
6468
Legend()
6569
|> Legend.style (
@@ -84,8 +88,10 @@ type Legend() =
8488
?Visible = Visible,
8589
?X = X,
8690
?XAnchor = XAnchor,
91+
?XRef = XRef,
8792
?Y = Y,
88-
?YAnchor = YAnchor
93+
?YAnchor = YAnchor,
94+
?YRef = YRef
8995
)
9096

9197
/// <summary>
@@ -112,8 +118,10 @@ type Legend() =
112118
/// <param name="Visible">Determines whether or not this legend is visible.</param>
113119
/// <param name="X">Sets the x position (in normalized coordinates) of the legend. Defaults to "1.02" for vertical legends and defaults to "0" for horizontal legends.</param>
114120
/// <param name="XAnchor">Sets the legend's horizontal position anchor. This anchor binds the `x` position to the "left", "center" or "right" of the legend. Value "auto" anchors legends to the right for `x` values greater than or equal to 2/3, anchors legends to the left for `x` values less than or equal to 1/3 and anchors legends with respect to their center otherwise.</param>
121+
/// <param name="XRef">Sets the container `x` refers to. "container" spans the entire `width` of the plot. "paper" refers to the width of the plotting area only.</param>
115122
/// <param name="Y">Sets the y position (in normalized coordinates) of the legend. Defaults to "1" for vertical legends, defaults to "-0.1" for horizontal legends on graphs w/o range sliders and defaults to "1.1" for horizontal legends on graph with one or multiple range sliders.</param>
116123
/// <param name="YAnchor">Sets the legend's vertical position anchor This anchor binds the `y` position to the "top", "middle" or "bottom" of the legend. Value "auto" anchors legends at their bottom for `y` values less than or equal to 1/3, anchors legends to at their top for `y` values greater than or equal to 2/3 and anchors legends with respect to their middle otherwise.</param>
124+
/// <param name="YRef">Sets the container `y` refers to. "container" spans the entire `height` of the plot. "paper" refers to the height of the plotting area only.</param>
117125
static member style
118126
(
119127
[<Optional; DefaultParameterValue(null)>] ?BGColor: Color,
@@ -137,8 +145,10 @@ type Legend() =
137145
[<Optional; DefaultParameterValue(null)>] ?Visible: bool,
138146
[<Optional; DefaultParameterValue(null)>] ?X: float,
139147
[<Optional; DefaultParameterValue(null)>] ?XAnchor: StyleParam.XAnchorPosition,
148+
[<Optional; DefaultParameterValue(null)>] ?XRef: string,
140149
[<Optional; DefaultParameterValue(null)>] ?Y: float,
141-
[<Optional; DefaultParameterValue(null)>] ?YAnchor: StyleParam.YAnchorPosition
150+
[<Optional; DefaultParameterValue(null)>] ?YAnchor: StyleParam.YAnchorPosition,
151+
[<Optional; DefaultParameterValue(null)>] ?YRef: string
142152
) =
143153
(fun (legend: Legend) ->
144154
BGColor |> DynObj.setValueOpt legend "bgcolor"
@@ -162,8 +172,10 @@ type Legend() =
162172
Visible |> DynObj.setValueOpt legend "visible"
163173
X |> DynObj.setValueOpt legend "x"
164174
XAnchor |> DynObj.setValueOptBy legend "xanchor" StyleParam.XAnchorPosition.convert
175+
XRef |> DynObj.setValueOpt legend "xref"
165176
Y |> DynObj.setValueOpt legend "y"
166177
YAnchor |> DynObj.setValueOptBy legend "yanchor" StyleParam.YAnchorPosition.convert
178+
YRef |> DynObj.setValueOpt legend "yref"
167179

168180

169181

src/Plotly.NET/Plotly.NET.fsproj

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@
4040
<ItemGroup>
4141
<None Include="RELEASE_NOTES.md" />
4242
<None Include="..\..\docs\img\logo.png" Pack="true" PackagePath="\" />
43-
<EmbeddedResource Include="plotly-2.22.0.min.js" />
44-
<EmbeddedResource Include="plotly-2.22.0.min.js.LICENSE.txt" />
43+
<EmbeddedResource Include="plotly-2.23.2.min.js" />
44+
<EmbeddedResource Include="plotly-2.23.2.min.js.LICENSE.txt" />
4545
<Compile Include="Globals.fs" />
4646
<Compile Include="InternalUtils.fs" />
4747
<Compile Include="CommonAbstractions\ColorKeyword.fs" />

src/Plotly.NET/RELEASE_NOTES.md

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
[Milestone link with all the fixed/closed issues](https://github.com/plotly/Plotly.NET/milestone/5)
44

55
- Keep up with plotlyjs 2.x incremental updates:
6+
- v2.22:
7+
- [Implement multi legend support](https://github.com/plotly/Plotly.NET/issues/406)
68

79
### 4.2.0 - August 02 2023
810

src/Plotly.NET/plotly-2.22.0.min.js

-8
This file was deleted.

src/Plotly.NET/plotly-2.23.2.min.js

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/Common/FSharpTestBase/FSharpTestBase.fsproj

+4-3
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77

88
<ItemGroup>
99
<EmbeddedResource Include="..\..\..\docs\img\logo.png" />
10-
<EmbeddedResource Include="..\..\..\src\Plotly.NET\plotly-2.22.0.min.js" />
11-
<EmbeddedResource Include="..\..\..\src\Plotly.NET\plotly-2.22.0.min.js.LICENSE.txt" />
10+
<EmbeddedResource Include="..\..\..\src\Plotly.NET\plotly-2.23.2.min.js" />
11+
<EmbeddedResource Include="..\..\..\src\Plotly.NET\plotly-2.23.2.min.js.LICENSE.txt" />
1212
</ItemGroup>
1313

1414
<ItemGroup>
@@ -21,7 +21,8 @@
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" />
24+
<Compile Include="TestCharts\UpstreamFeatures\2.23.fs" />
25+
<Compile Include="TestCharts\UpstreamFeatures\2.22.fs" />
2526
<Compile Include="TestCharts\UpstreamFeatures\2.21.fs" />
2627
<Compile Include="TestCharts\UpstreamFeatures\2.20.fs" />
2728
<Compile Include="TestCharts\UpstreamFeatures\2.19.fs" />
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
module PlotlyJS_2_23_TestCharts
2+
3+
open Plotly.NET
4+
open Plotly.NET.TraceObjects
5+
open Plotly.NET.LayoutObjects
6+
7+
8+
module ``Colorbar X and Y ref`` =
9+
10+
let ``Heatmap with horizontal colorbar with x/yref = container`` =
11+
Chart.Heatmap(
12+
[
13+
[1; 2; 3]
14+
[3; 2; 1]
15+
],
16+
UseDefaults = false
17+
)
18+
|> Chart.withColorBar(
19+
ColorBar.init(
20+
X = 0.5,
21+
Y = 0.1,
22+
Orientation = StyleParam.Orientation.Horizontal,
23+
XRef = "container",
24+
YRef = "container",
25+
Title = Title.init(
26+
Text = "Colorbar 1"
27+
)
28+
)
29+
)
30+
31+
module ``Legend X and Y ref`` =
32+
33+
let ``Point chart with horizontal legend with x/yref = container`` =
34+
Chart.Point(
35+
[1,2],
36+
ShowLegend = true,
37+
UseDefaults = false
38+
)
39+
|> Chart.withLegend(
40+
Legend.init(
41+
X = 0.5,
42+
Y = 0.1,
43+
Orientation = StyleParam.Orientation.Horizontal,
44+
XRef = "container",
45+
YRef = "container",
46+
BorderColor = Color.fromKeyword Blue,
47+
BorderWidth = 2,
48+
Title = Title.init(
49+
Text = "Legend 1"
50+
)
51+
)
52+
)

tests/CoreTests/CoreTests/CoreTests.fsproj

+3-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
</PropertyGroup>
99

1010
<ItemGroup>
11-
<EmbeddedResource Include="..\..\..\src\Plotly.NET\plotly-2.22.0.min.js" />
12-
<EmbeddedResource Include="..\..\..\src\Plotly.NET\plotly-2.22.0.min.js.LICENSE.txt" />
11+
<EmbeddedResource Include="..\..\..\src\Plotly.NET\plotly-2.23.2.min.js" />
12+
<EmbeddedResource Include="..\..\..\src\Plotly.NET\plotly-2.23.2.min.js.LICENSE.txt" />
1313
<!--HTMLCodegen-->
1414
<Compile Include="HTMLCodegen\Chart2D.fs" />
1515
<Compile Include="HTMLCodegen\Chart3D.fs" />
@@ -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.23.fs" />
3940
<Compile Include="UpstreamFeatures\2.22.fs" />
4041
<Compile Include="UpstreamFeatures\2.21.fs" />
4142
<Compile Include="UpstreamFeatures\2.20.fs" />
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
module CoreTests.UpstreamFeatures.PlotlyJS_2_23
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_23_TestCharts
11+
12+
module ``Colorbar X and Y ref`` =
13+
14+
[<Tests>]
15+
let ``Colorbar X/YRef HTML codegeneration tests`` =
16+
testList "UpstreamFeatures.PlotlyJS_2_23" [
17+
testList "Colorbar X/YRef" [
18+
testCase "Heatmap with horizontal colorbar with x/yref = container data" ( fun () ->
19+
"""var data = [{"type":"heatmap","z":[[1,2,3],[3,2,1]],"colorbar":{"orientation":"h","title":{"text":"Colorbar 1"},"x":0.5,"xref":"container","y":0.1,"yref":"container"}}];"""
20+
|> chartGeneratedContains ``Colorbar X and Y ref``.``Heatmap with horizontal colorbar with x/yref = container``
21+
)
22+
testCase "Heatmap with horizontal colorbar with x/yref = container layout" ( fun () ->
23+
emptyLayout ``Colorbar X and Y ref``.``Heatmap with horizontal colorbar with x/yref = container``
24+
)
25+
]
26+
]
27+
28+
module ``Legend X and Y ref`` =
29+
30+
[<Tests>]
31+
let ``Legend X/YRef HTML codegeneration tests`` =
32+
testList "UpstreamFeatures.PlotlyJS_2_23" [
33+
testList "Legend X/YRef" [
34+
testCase "Point chart with horizontal legend with x/yref = container data" ( fun () ->
35+
"""var data = [{"type":"scatter","showlegend":true,"mode":"markers","x":[1],"y":[2],"marker":{},"line":{}}];"""
36+
|> chartGeneratedContains ``Legend X and Y ref``.``Point chart with horizontal legend with x/yref = container``
37+
)
38+
testCase "Point chart with horizontal legend with x/yref = container layout" ( fun () ->
39+
"""var layout = {"legend":{"bordercolor":"rgba(0, 0, 255, 1.0)","borderwidth":2.0,"orientation":"h","title":{"text":"Legend 1"},"x":0.5,"xref":"container","y":0.1,"yref":"container"}};"""
40+
|> chartGeneratedContains ``Legend X and Y ref``.``Point chart with horizontal legend with x/yref = container``
41+
)
42+
]
43+
]

0 commit comments

Comments
 (0)