Skip to content

Commit bebe507

Browse files
committed
plotlyjs 2.26: Add "top left" & "top center" side options to legend title
1 parent d1c63b9 commit bebe507

File tree

4 files changed

+94
-11
lines changed

4 files changed

+94
-11
lines changed

src/Plotly.NET/CommonAbstractions/StyleParams.fs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3069,6 +3069,8 @@ module StyleParam =
30693069
type Side =
30703070
| Top
30713071
| TopLeft
3072+
| TopCenter
3073+
| TopRight
30723074
| Bottom
30733075
| Left
30743076
| Right
@@ -3077,6 +3079,8 @@ module StyleParam =
30773079
function
30783080
| Top -> "top"
30793081
| TopLeft -> "top left"
3082+
| TopCenter -> "top center"
3083+
| TopRight -> "top right"
30803084
| Bottom -> "bottom"
30813085
| Left -> "left"
30823086
| Right -> "right"

tests/Common/FSharpTestBase/TestCharts/UpstreamFeatures/2.26.fs

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,4 +164,50 @@ module ``N-sigma (std deviations) box plots`` =
164164
Trace2DStyle.BoxPlot(
165165
SDMultiple = 2.
166166
)
167-
)
167+
)
168+
169+
module ``New Side options for (legend) titles`` =
170+
171+
let ``Point charts with horizontal legend title top left`` =
172+
[
173+
Chart.Point([1,2], UseDefaults = false)
174+
Chart.Point([3,4], UseDefaults = false)
175+
]
176+
|> Chart.combine
177+
|> Chart.withLegendStyle(
178+
Title = Title.init(
179+
Text = "Legend title (top left)",
180+
Side = StyleParam.Side.TopLeft
181+
),
182+
Orientation = StyleParam.Orientation.Horizontal
183+
)
184+
185+
let ``Point charts with horizontal legend title top center`` =
186+
[
187+
Chart.Point([1,2], UseDefaults = false)
188+
Chart.Point([3,4], UseDefaults = false)
189+
]
190+
|> Chart.combine
191+
|> Chart.withLegendStyle(
192+
Title = Title.init(
193+
Text = "Legend title (top center)",
194+
Side = StyleParam.Side.TopCenter
195+
),
196+
Orientation = StyleParam.Orientation.Horizontal
197+
)
198+
199+
let ``Point charts with horizontal legend title top right`` =
200+
[
201+
Chart.Point([1,2], UseDefaults = false)
202+
Chart.Point([3,4], UseDefaults = false)
203+
]
204+
|> Chart.combine
205+
|> Chart.withLegendStyle(
206+
Title = Title.init(
207+
Text = "Legend title (top right)",
208+
Side = StyleParam.Side.TopRight
209+
),
210+
Orientation = StyleParam.Orientation.Horizontal
211+
)
212+
213+

tests/ConsoleApps/FSharpConsole/Program.fs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,17 @@ open Newtonsoft.Json
1111

1212
[<EntryPoint>]
1313
let main argv =
14-
Chart.BoxPlot(
15-
data = [-20; 1; 2; 3; 1; 2; 3; 3; 3; 3; 3; 1; 5; 20],
16-
orientation = StyleParam.Orientation.Vertical,
17-
SizeMode = StyleParam.BoxSizeMode.SD,
18-
UseDefaults = false
19-
)
20-
|> GenericChart.mapTrace (
21-
Trace2DStyle.BoxPlot(
22-
SDMultiple = 2.
23-
)
14+
[
15+
Chart.Point([1,2], UseDefaults = false)
16+
Chart.Point([3,4], UseDefaults = false)
17+
]
18+
|> Chart.combine
19+
|> Chart.withLegendStyle(
20+
Title = Title.init(
21+
Text = "Legend title (top right)",
22+
Side = StyleParam.Side.TopRight
23+
),
24+
Orientation = StyleParam.Orientation.Horizontal
2425
)
2526
|> Chart.show
2627
0

tests/CoreTests/CoreTests/UpstreamFeatures/2.26.fs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,36 @@ module ``N-sigma (std deviations) box plots`` =
8181
emptyLayout ``N-sigma (std deviations) box plots``.``2-sigma BoxPlot``
8282
)
8383
]
84+
]
85+
86+
module ``New Side options for (legend) titles`` =
87+
[<Tests>]
88+
let ``New Title Side options`` =
89+
testList "UpstreamFeatures.PlotlyJS_2_26" [
90+
testList "New Side options for (legend) titles" [
91+
testCase "top left data" ( fun () ->
92+
"""var data = [{"type":"scatter","mode":"markers","x":[1],"y":[2],"marker":{},"line":{}},{"type":"scatter","mode":"markers","x":[3],"y":[4],"marker":{},"line":{}}];"""
93+
|> chartGeneratedContains ``New Side options for (legend) titles``.``Point charts with horizontal legend title top left``
94+
)
95+
testCase "top left layout" ( fun () ->
96+
"""var layout = {"legend":{"orientation":"h","title":{"text":"Legend title (top left)","side":"top left"}}};"""
97+
|> chartGeneratedContains ``New Side options for (legend) titles``.``Point charts with horizontal legend title top left``
98+
)
99+
testCase "top center data" ( fun () ->
100+
"""var data = [{"type":"scatter","mode":"markers","x":[1],"y":[2],"marker":{},"line":{}},{"type":"scatter","mode":"markers","x":[3],"y":[4],"marker":{},"line":{}}];"""
101+
|> chartGeneratedContains ``New Side options for (legend) titles``.``Point charts with horizontal legend title top center``
102+
)
103+
testCase "top center layout" ( fun () ->
104+
"""var layout = {"legend":{"orientation":"h","title":{"text":"Legend title (top center)","side":"top center"}}};"""
105+
|> chartGeneratedContains ``New Side options for (legend) titles``.``Point charts with horizontal legend title top center``
106+
)
107+
testCase "top right data" ( fun () ->
108+
"""var data = [{"type":"scatter","mode":"markers","x":[1],"y":[2],"marker":{},"line":{}},{"type":"scatter","mode":"markers","x":[3],"y":[4],"marker":{},"line":{}}];"""
109+
|> chartGeneratedContains ``New Side options for (legend) titles``.``Point charts with horizontal legend title top right``
110+
)
111+
testCase "top right layout" ( fun () ->
112+
"""var layout = {"legend":{"orientation":"h","title":{"text":"Legend title (top right)","side":"top right"}}};"""
113+
|> chartGeneratedContains ``New Side options for (legend) titles``.``Point charts with horizontal legend title top right``
114+
)
115+
]
84116
]

0 commit comments

Comments
 (0)