Skip to content

Commit

Permalink
plotlyjs 2.26: Add "top left" & "top center" side options to legend t…
Browse files Browse the repository at this point in the history
…itle
  • Loading branch information
kMutagene committed Dec 7, 2023
1 parent d1c63b9 commit bebe507
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 11 deletions.
4 changes: 4 additions & 0 deletions src/Plotly.NET/CommonAbstractions/StyleParams.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3069,6 +3069,8 @@ module StyleParam =
type Side =
| Top
| TopLeft
| TopCenter
| TopRight
| Bottom
| Left
| Right
Expand All @@ -3077,6 +3079,8 @@ module StyleParam =
function
| Top -> "top"
| TopLeft -> "top left"
| TopCenter -> "top center"
| TopRight -> "top right"
| Bottom -> "bottom"
| Left -> "left"
| Right -> "right"
Expand Down
48 changes: 47 additions & 1 deletion tests/Common/FSharpTestBase/TestCharts/UpstreamFeatures/2.26.fs
Original file line number Diff line number Diff line change
Expand Up @@ -164,4 +164,50 @@ module ``N-sigma (std deviations) box plots`` =
Trace2DStyle.BoxPlot(
SDMultiple = 2.
)
)
)

module ``New Side options for (legend) titles`` =

let ``Point charts with horizontal legend title top left`` =
[
Chart.Point([1,2], UseDefaults = false)
Chart.Point([3,4], UseDefaults = false)
]
|> Chart.combine
|> Chart.withLegendStyle(
Title = Title.init(
Text = "Legend title (top left)",
Side = StyleParam.Side.TopLeft
),
Orientation = StyleParam.Orientation.Horizontal
)

let ``Point charts with horizontal legend title top center`` =
[
Chart.Point([1,2], UseDefaults = false)
Chart.Point([3,4], UseDefaults = false)
]
|> Chart.combine
|> Chart.withLegendStyle(
Title = Title.init(
Text = "Legend title (top center)",
Side = StyleParam.Side.TopCenter
),
Orientation = StyleParam.Orientation.Horizontal
)

let ``Point charts with horizontal legend title top right`` =
[
Chart.Point([1,2], UseDefaults = false)
Chart.Point([3,4], UseDefaults = false)
]
|> Chart.combine
|> Chart.withLegendStyle(
Title = Title.init(
Text = "Legend title (top right)",
Side = StyleParam.Side.TopRight
),
Orientation = StyleParam.Orientation.Horizontal
)


21 changes: 11 additions & 10 deletions tests/ConsoleApps/FSharpConsole/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,17 @@ open Newtonsoft.Json

[<EntryPoint>]
let main argv =
Chart.BoxPlot(
data = [-20; 1; 2; 3; 1; 2; 3; 3; 3; 3; 3; 1; 5; 20],
orientation = StyleParam.Orientation.Vertical,
SizeMode = StyleParam.BoxSizeMode.SD,
UseDefaults = false
)
|> GenericChart.mapTrace (
Trace2DStyle.BoxPlot(
SDMultiple = 2.
)
[
Chart.Point([1,2], UseDefaults = false)
Chart.Point([3,4], UseDefaults = false)
]
|> Chart.combine
|> Chart.withLegendStyle(
Title = Title.init(
Text = "Legend title (top right)",
Side = StyleParam.Side.TopRight
),
Orientation = StyleParam.Orientation.Horizontal
)
|> Chart.show
0
32 changes: 32 additions & 0 deletions tests/CoreTests/CoreTests/UpstreamFeatures/2.26.fs
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,36 @@ module ``N-sigma (std deviations) box plots`` =
emptyLayout ``N-sigma (std deviations) box plots``.``2-sigma BoxPlot``
)
]
]

module ``New Side options for (legend) titles`` =
[<Tests>]
let ``New Title Side options`` =
testList "UpstreamFeatures.PlotlyJS_2_26" [
testList "New Side options for (legend) titles" [
testCase "top left data" ( fun () ->
"""var data = [{"type":"scatter","mode":"markers","x":[1],"y":[2],"marker":{},"line":{}},{"type":"scatter","mode":"markers","x":[3],"y":[4],"marker":{},"line":{}}];"""
|> chartGeneratedContains ``New Side options for (legend) titles``.``Point charts with horizontal legend title top left``
)
testCase "top left layout" ( fun () ->
"""var layout = {"legend":{"orientation":"h","title":{"text":"Legend title (top left)","side":"top left"}}};"""
|> chartGeneratedContains ``New Side options for (legend) titles``.``Point charts with horizontal legend title top left``
)
testCase "top center data" ( fun () ->
"""var data = [{"type":"scatter","mode":"markers","x":[1],"y":[2],"marker":{},"line":{}},{"type":"scatter","mode":"markers","x":[3],"y":[4],"marker":{},"line":{}}];"""
|> chartGeneratedContains ``New Side options for (legend) titles``.``Point charts with horizontal legend title top center``
)
testCase "top center layout" ( fun () ->
"""var layout = {"legend":{"orientation":"h","title":{"text":"Legend title (top center)","side":"top center"}}};"""
|> chartGeneratedContains ``New Side options for (legend) titles``.``Point charts with horizontal legend title top center``
)
testCase "top right data" ( fun () ->
"""var data = [{"type":"scatter","mode":"markers","x":[1],"y":[2],"marker":{},"line":{}},{"type":"scatter","mode":"markers","x":[3],"y":[4],"marker":{},"line":{}}];"""
|> chartGeneratedContains ``New Side options for (legend) titles``.``Point charts with horizontal legend title top right``
)
testCase "top right layout" ( fun () ->
"""var layout = {"legend":{"orientation":"h","title":{"text":"Legend title (top right)","side":"top right"}}};"""
|> chartGeneratedContains ``New Side options for (legend) titles``.``Point charts with horizontal legend title top right``
)
]
]

0 comments on commit bebe507

Please sign in to comment.