Skip to content

Commit c82633a

Browse files
committed
plotlyjs 2.20.0: Add automargin support to plot titles (plotly/plotly.js#6428)
1 parent 723e83b commit c82633a

File tree

12 files changed

+132
-85
lines changed

12 files changed

+132
-85
lines changed

Diff for: 2.19.fs

Whitespace-only changes.

Diff for: src/Plotly.NET/CommonAbstractions/Title.fs

+59-3
Original file line numberDiff line numberDiff line change
@@ -7,33 +7,89 @@ open DynamicObj
77
type Title() =
88
inherit DynamicObj()
99

10+
/// <summary>
11+
/// Returns a new Title object with the given styles. Note that this is a multi-purpose object that can be used as plot or different axis titles, with some attributes being only used in some layouts.
12+
/// </summary>
13+
/// <param name="Text">For all titles: Sets the plot's title. Note that before the existence of `title.text`, the title's contents used to be defined as the `title` attribute itself. This behavior has been deprecated.</param>
14+
/// <param name="AutoMargin">For plot titles: Determines whether the title can automatically push the figure margins. If `yref='paper'` then the margin will expand to ensure that the title doesn’t overlap with the edges of the container. If `yref='container'` then the margins will ensure that the title doesn’t overlap with the plot area, tick labels, and axis titles. If `automargin=true` and the margins need to be expanded, then y will be set to a default 1 and yanchor will be set to an appropriate default to ensure that minimal margin space is needed. Note that when `yref='paper'`, only 1 or 0 are allowed y values. Invalid values will be reset to the default 1.</param>
15+
/// <param name="Font">For all titles: Sets the title font. Note that the title's font used to be customized by the now deprecated `titlefont` attribute.</param>
16+
/// <param name="Standoff">For axis titles: Sets the standoff distance (in px) between the axis labels and the title text The default value is a function of the axis tick labels, the title `font.size` and the axis `linewidth`. Note that the axis title position is always constrained within the margins, so the actual standoff distance is always less than the set or default value. By setting `standoff` and turning on `automargin`, plotly.js will push the margins to fit the axis title at given standoff distance.</param>
17+
/// <param name="Side">For colorbar titles: Determines the location of color bar's title with respect to the color bar. Defaults to "top" when `orientation` if "v" and defaults to "right" when `orientation` if "h". Note that the title's location used to be set by the now deprecated `titleside` attribute.</param>
18+
/// <param name="X">For plot titles: Sets the x position with respect to `xref` in normalized coordinates from "0" (left) to "1" (right).</param>
19+
/// <param name="XAnchor">For plot titles: Sets the title's horizontal alignment with respect to its x position. "left" means that the title starts at x, "right" means that the title ends at x and "center" means that the title's center is at x. "auto" divides `xref` by three and calculates the `xanchor` value automatically based on the value of `x`.</param>
20+
/// <param name="XRef">For plot titles: 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>
21+
/// <param name="Y">For plot titles: Sets the y position with respect to `yref` in normalized coordinates from "0" (bottom) to "1" (top). "auto" places the baseline of the title onto the vertical center of the top margin.</param>
22+
/// <param name="YAnchor">For plot titles: Sets the title's vertical alignment with respect to its y position. "top" means that the title's cap line is at y, "bottom" means that the title's baseline is at y and "middle" means that the title's midline is at y. "auto" divides `yref` by three and calculates the `yanchor` value automatically based on the value of `y`.</param>
23+
/// <param name="YRef">For plot titles: 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>
1024
static member init
1125
(
1226
[<Optional; DefaultParameterValue(null)>] ?Text: string,
27+
[<Optional; DefaultParameterValue(null)>] ?AutoMargin: bool,
1328
[<Optional; DefaultParameterValue(null)>] ?Font: Font,
1429
[<Optional; DefaultParameterValue(null)>] ?Standoff: int,
1530
[<Optional; DefaultParameterValue(null)>] ?Side: StyleParam.Side,
1631
[<Optional; DefaultParameterValue(null)>] ?X: float,
17-
[<Optional; DefaultParameterValue(null)>] ?Y: float
32+
[<Optional; DefaultParameterValue(null)>] ?XAnchor: StyleParam.XAnchorPosition,
33+
[<Optional; DefaultParameterValue(null)>] ?XRef: string,
34+
[<Optional; DefaultParameterValue(null)>] ?Y: float,
35+
[<Optional; DefaultParameterValue(null)>] ?YAnchor: StyleParam.YAnchorPosition,
36+
[<Optional; DefaultParameterValue(null)>] ?YRef: string
1837
) =
19-
Title() |> Title.style (?Text = Text, ?Font = Font, ?Standoff = Standoff, ?Side = Side, ?X = X, ?Y = Y)
38+
Title()
39+
|> Title.style (
40+
?Text = Text,
41+
?AutoMargin = AutoMargin,
42+
?Font = Font,
43+
?Standoff = Standoff,
44+
?Side = Side,
45+
?X = X,
46+
?XAnchor = XAnchor,
47+
?XRef = XRef,
48+
?Y = Y,
49+
?YAnchor = YAnchor,
50+
?YRef = YRef
51+
)
2052

53+
/// <summary>
54+
/// Returns a function that applies the given styles to a Title object. Note that this is a multi-purpose object that can be used as plot or different axis titles, with some attributes being only used in some layouts
55+
/// </summary>
56+
/// <param name="Text">For all titles: Sets the plot's title. Note that before the existence of `title.text`, the title's contents used to be defined as the `title` attribute itself. This behavior has been deprecated.</param>
57+
/// <param name="AutoMargin">For plot titles: Determines whether the title can automatically push the figure margins. If `yref='paper'` then the margin will expand to ensure that the title doesn’t overlap with the edges of the container. If `yref='container'` then the margins will ensure that the title doesn’t overlap with the plot area, tick labels, and axis titles. If `automargin=true` and the margins need to be expanded, then y will be set to a default 1 and yanchor will be set to an appropriate default to ensure that minimal margin space is needed. Note that when `yref='paper'`, only 1 or 0 are allowed y values. Invalid values will be reset to the default 1.</param>
58+
/// <param name="Font">For all titles: Sets the title font. Note that the title's font used to be customized by the now deprecated `titlefont` attribute.</param>
59+
/// <param name="Standoff">For axis titles: Sets the standoff distance (in px) between the axis labels and the title text The default value is a function of the axis tick labels, the title `font.size` and the axis `linewidth`. Note that the axis title position is always constrained within the margins, so the actual standoff distance is always less than the set or default value. By setting `standoff` and turning on `automargin`, plotly.js will push the margins to fit the axis title at given standoff distance.</param>
60+
/// <param name="Side">For colorbar titles: Determines the location of color bar's title with respect to the color bar. Defaults to "top" when `orientation` if "v" and defaults to "right" when `orientation` if "h". Note that the title's location used to be set by the now deprecated `titleside` attribute.</param>
61+
/// <param name="X">For plot titles: Sets the x position with respect to `xref` in normalized coordinates from "0" (left) to "1" (right).</param>
62+
/// <param name="XAnchor">For plot titles: Sets the title's horizontal alignment with respect to its x position. "left" means that the title starts at x, "right" means that the title ends at x and "center" means that the title's center is at x. "auto" divides `xref` by three and calculates the `xanchor` value automatically based on the value of `x`.</param>
63+
/// <param name="XRef">For plot titles: 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>
64+
/// <param name="Y">For plot titles: Sets the y position with respect to `yref` in normalized coordinates from "0" (bottom) to "1" (top). "auto" places the baseline of the title onto the vertical center of the top margin.</param>
65+
/// <param name="YAnchor">For plot titles: Sets the title's vertical alignment with respect to its y position. "top" means that the title's cap line is at y, "bottom" means that the title's baseline is at y and "middle" means that the title's midline is at y. "auto" divides `yref` by three and calculates the `yanchor` value automatically based on the value of `y`.</param>
66+
/// <param name="YRef">For plot titles: 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>
2167
static member style
2268
(
2369
[<Optional; DefaultParameterValue(null)>] ?Text: string,
70+
[<Optional; DefaultParameterValue(null)>] ?AutoMargin: bool,
2471
[<Optional; DefaultParameterValue(null)>] ?Font: Font,
2572
[<Optional; DefaultParameterValue(null)>] ?Standoff: int,
2673
[<Optional; DefaultParameterValue(null)>] ?Side: StyleParam.Side,
2774
[<Optional; DefaultParameterValue(null)>] ?X: float,
28-
[<Optional; DefaultParameterValue(null)>] ?Y: float
75+
[<Optional; DefaultParameterValue(null)>] ?XAnchor: StyleParam.XAnchorPosition,
76+
[<Optional; DefaultParameterValue(null)>] ?XRef: string,
77+
[<Optional; DefaultParameterValue(null)>] ?Y: float,
78+
[<Optional; DefaultParameterValue(null)>] ?YAnchor: StyleParam.YAnchorPosition,
79+
[<Optional; DefaultParameterValue(null)>] ?YRef: string
2980
) =
3081
(fun (title: Title) ->
3182

3283
Text |> DynObj.setValueOpt title "text"
84+
AutoMargin |> DynObj.setValueOpt title "automargin"
3385
Font |> DynObj.setValueOpt title "font"
3486
Standoff |> DynObj.setValueOpt title "standoff"
3587
Side |> DynObj.setValueOptBy title "side" StyleParam.Side.convert
3688
X |> DynObj.setValueOpt title "x"
89+
XAnchor |> DynObj.setValueOptBy title "xanchor" StyleParam.XAnchorPosition.convert
90+
XRef |> DynObj.setValueOpt title "xref"
3791
Y |> DynObj.setValueOpt title "y"
92+
YAnchor |> DynObj.setValueOptBy title "yanchor" StyleParam.YAnchorPosition.convert
93+
YRef |> DynObj.setValueOpt title "yref"
3894

3995
title)

Diff for: 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.19.1"
10+
let PLOTLYJS_VERSION = "2.20.0"
1111

1212
[<Literal>]
1313
let SCRIPT_TEMPLATE =

Diff for: 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.19.1.min.js" />
44-
<EmbeddedResource Include="plotly-2.19.1.min.js.LICENSE.txt" />
43+
<EmbeddedResource Include="plotly-2.20.0.min.js" />
44+
<EmbeddedResource Include="plotly-2.20.0.min.js.LICENSE.txt" />
4545
<Compile Include="Globals.fs" />
4646
<Compile Include="InternalUtils.fs" />
4747
<Compile Include="CommonAbstractions\ColorKeyword.fs" />

Diff for: src/Plotly.NET/plotly-2.19.1.min.js

-8
This file was deleted.

Diff for: src/Plotly.NET/plotly-2.20.0.min.js

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

Diff for: tests/Common/FSharpTestBase/FSharpTestBase.fsproj

+3-2
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.19.1.min.js" />
11-
<EmbeddedResource Include="..\..\..\src\Plotly.NET\plotly-2.19.1.min.js.LICENSE.txt" />
10+
<EmbeddedResource Include="..\..\..\src\Plotly.NET\plotly-2.20.0.min.js" />
11+
<EmbeddedResource Include="..\..\..\src\Plotly.NET\plotly-2.20.0.min.js.LICENSE.txt" />
1212
</ItemGroup>
1313

1414
<ItemGroup>
@@ -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.20.fs" />
2425
<Compile Include="TestCharts\UpstreamFeatures\2.19.fs" />
2526
</ItemGroup>
2627

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
module PlotlyJS_2_20_TestCharts
2+
3+
open Plotly.NET
4+
open Plotly.NET.TraceObjects
5+
open Plotly.NET.LayoutObjects
6+
7+
8+
module TitleAutoMargin =
9+
let ``Title with AutoMargin`` =
10+
Chart.Point(
11+
[1,2],
12+
UseDefaults = false
13+
)
14+
|> Chart.withTitle(
15+
Title.init(
16+
Text = """Lorem ipsum dolor sit amet, <br>consetetur sadipscing elitr, sed diam nonumy eirmod <br>tempor invidunt ut labore et dolore magna aliquyam erat, <br>sed diam voluptua. At vero eos et accusam et justo <br>duo dolores et ea rebum. Stet clita kasd gubergren,<br>no sea takimata sanctus est Lorem ipsum dolor sit amet. <br>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, <br>sed diam nonumy eirmod tempor invidunt ut labore et <br>dolore magna aliquyam erat, sed diam voluptua. <br>At vero eos et accusam et justo duo dolores et ea rebum. <br>Stet clita kasd gubergren, no sea takimata sanctus est <br>Lorem ipsum dolor sit amet.""",
17+
AutoMargin = true
18+
)
19+
)

Diff for: tests/ConsoleApps/FSharpConsole/Program.fs

+10-67
Original file line numberDiff line numberDiff line change
@@ -11,72 +11,15 @@ open Newtonsoft.Json
1111

1212
[<EntryPoint>]
1313
let main argv =
14-
15-
let labelAlias = DynamicObj()
16-
labelAlias?("1") <- "<b>ONE</b>"
17-
labelAlias?("0\u00B0") <- "<b>ZERO</b>"
18-
19-
let linAxis = LinearAxis.init(LabelAlias=labelAlias)
20-
let angularAxis = AngularAxis.init(LabelAlias=labelAlias)
21-
let radialAxis = RadialAxis.init(LabelAlias=labelAlias)
22-
let imaginaryAxis = ImaginaryAxis.init(LabelAlias=labelAlias)
23-
let realAxis = RealAxis.init(LabelAlias=labelAlias)
24-
let colorBar = ColorBar.init(LabelAlias=labelAlias)
25-
26-
[
27-
Chart.Point([1,1], UseDefaults = false)
28-
|> Chart.withXAxis(linAxis)
29-
|> Chart.withYAxis(linAxis)
30-
31-
Chart.Point3D([1,1,1], UseDefaults = false)
32-
|> Chart.withXAxis(linAxis, Id = StyleParam.SubPlotId.Scene 1)
33-
|> Chart.withYAxis(linAxis, Id = StyleParam.SubPlotId.Scene 1)
34-
|> Chart.withZAxis(linAxis)
35-
36-
Chart.PointPolar([1,1], UseDefaults = false)
37-
|> Chart.withAngularAxis(angularAxis)
38-
|> Chart.withRadialAxis(radialAxis)
39-
40-
Chart.PointTernary([1,1,1], UseDefaults = false)
41-
|> Chart.withAAxis(linAxis)
42-
|> Chart.withBAxis(linAxis)
43-
|> Chart.withCAxis(linAxis)
44-
45-
46-
[
47-
Chart.Carpet(
48-
carpetId = "carpet1",
49-
A = [4.; 4.; 4.; 4.5; 4.5; 4.5; 5.; 5.; 5.; 6.; 6.; 6.],
50-
B = [1.; 2.; 3.; 1.; 2.; 3.; 1.; 2.; 3.; 1.; 2.; 3.],
51-
Y = [2.; 3.5; 4.; 3.; 4.5; 5.; 5.5; 6.5; 7.5; 8.; 8.5; 10.],
52-
AAxis = linAxis,
53-
BAxis = linAxis,
54-
UseDefaults = false
55-
)
56-
57-
]
58-
|> Chart.combine
59-
60-
Chart.Heatmap([[1;2];[3;4]], UseDefaults = false)
61-
|> Chart.withXAxis(linAxis)
62-
|> Chart.withYAxis(linAxis)
63-
|> Chart.withColorBar(colorBar)
64-
65-
Chart.PointSmith([1,2], UseDefaults = false)
66-
|> Chart.withImaginaryAxis(imaginaryAxis)
67-
|> Chart.withRealAxis(realAxis)
68-
69-
Chart.Indicator(
70-
value = 1,
71-
mode = StyleParam.IndicatorMode.NumberDeltaGauge,
72-
DeltaReference = 0,
73-
Range = StyleParam.Range.MinMax(-1., 1.),
74-
GaugeShape = StyleParam.IndicatorGaugeShape.Bullet,
75-
ShowGaugeAxis = true,
76-
GaugeAxis = linAxis,
77-
UseDefaults = false
14+
Chart.Point(
15+
[1,2],
16+
UseDefaults = false
17+
)
18+
|> Chart.withTitle(
19+
Title.init(
20+
Text = """Lorem ipsum dolor sit amet, <br>consetetur sadipscing elitr, sed diam nonumy eirmod <br>tempor invidunt ut labore et dolore magna aliquyam erat, <br>sed diam voluptua. At vero eos et accusam et justo <br>duo dolores et ea rebum. Stet clita kasd gubergren,<br>no sea takimata sanctus est Lorem ipsum dolor sit amet. <br>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, <br>sed diam nonumy eirmod tempor invidunt ut labore et <br>dolore magna aliquyam erat, sed diam voluptua. <br>At vero eos et accusam et justo duo dolores et ea rebum. <br>Stet clita kasd gubergren, no sea takimata sanctus est <br>Lorem ipsum dolor sit amet.""",
21+
AutoMargin = true
7822
)
79-
80-
]
81-
|> List.iter Chart.show
23+
)
24+
|> Chart.show
8225
0

Diff for: 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.19.1.min.js" />
12-
<EmbeddedResource Include="..\..\..\src\Plotly.NET\plotly-2.19.1.min.js.LICENSE.txt" />
11+
<EmbeddedResource Include="..\..\..\src\Plotly.NET\plotly-2.20.0.min.js" />
12+
<EmbeddedResource Include="..\..\..\src\Plotly.NET\plotly-2.20.0.min.js.LICENSE.txt" />
1313
<!--HTMLCodegen-->
1414
<Compile Include="HTMLCodegen\Chart2D.fs" />
1515
<Compile Include="HTMLCodegen\Chart3D.fs" />
@@ -34,6 +34,7 @@
3434
<Compile Include="Traces\TraceStaticMembers.fs" />
3535
<Compile Include="Traces\TraceStyle.fs" />
3636
<Compile Include="Traces\TraceID.fs" />
37+
<Compile Include="UpstreamFeatures\2.20.fs" />
3738
<Compile Include="UpstreamFeatures\2.19.fs" />
3839
<Compile Include="Main.fs" />
3940
</ItemGroup>

Diff for: tests/CoreTests/CoreTests/UpstreamFeatures/2.20.fs

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
module CoreTests.UpstreamFeatures.PlotlyJS_2_20
2+
3+
open Expecto
4+
open Plotly.NET
5+
open Plotly.NET.LayoutObjects
6+
open Plotly.NET.TraceObjects
7+
open Plotly.NET.GenericChart
8+
9+
open TestUtils.HtmlCodegen
10+
open PlotlyJS_2_20_TestCharts
11+
12+
module TitleAutoMargin =
13+
14+
[<Tests>]
15+
let ``Title AutoMargin chart HTML codegeneration tests`` =
16+
testList "UpstreamFeatures.PlotlyJS_2_20" [
17+
testList "TitleAutoMargin" [
18+
testCase "Title AutoMargin data" ( fun () ->
19+
"""var data = [{"type":"scatter","mode":"markers","x":[1],"y":[2],"marker":{},"line":{}}];"""
20+
|> chartGeneratedContains TitleAutoMargin.``Title with AutoMargin``
21+
)
22+
testCase "Title AutoMargin layout" ( fun () ->
23+
"""var layout = {"title":{"text":"Lorem ipsum dolor sit amet, <br>consetetur sadipscing elitr, sed diam nonumy eirmod <br>tempor invidunt ut labore et dolore magna aliquyam erat, <br>sed diam voluptua. At vero eos et accusam et justo <br>duo dolores et ea rebum. Stet clita kasd gubergren,<br>no sea takimata sanctus est Lorem ipsum dolor sit amet. <br>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, <br>sed diam nonumy eirmod tempor invidunt ut labore et <br>dolore magna aliquyam erat, sed diam voluptua. <br>At vero eos et accusam et justo duo dolores et ea rebum. <br>Stet clita kasd gubergren, no sea takimata sanctus est <br>Lorem ipsum dolor sit amet.","automargin":true}};"""
24+
|> chartGeneratedContains TitleAutoMargin.``Title with AutoMargin``
25+
)
26+
]
27+
]

0 commit comments

Comments
 (0)