Skip to content

Commit

Permalink
plotlyjs v2.15: Add entrywidth and entrywidthmode to legend (plotly/p…
Browse files Browse the repository at this point in the history
…lotly.js#6202), reflect changes in Chart.withLayoutStyle
  • Loading branch information
kMutagene committed Feb 8, 2023
1 parent 9be3f62 commit b9dffc3
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 7 deletions.
9 changes: 6 additions & 3 deletions src/Plotly.NET/ChartAPI/Chart.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2565,7 +2565,9 @@ type Chart =
(
[<Optional; DefaultParameterValue(null)>] ?BGColor: Color,
[<Optional; DefaultParameterValue(null)>] ?BorderColor: Color,
[<Optional; DefaultParameterValue(null)>] ?Borderwidth: float,
[<Optional; DefaultParameterValue(null)>] ?BorderWidth: float,
[<Optional; DefaultParameterValue(null)>] ?EntryWidth: float,
[<Optional; DefaultParameterValue(null)>] ?EntryWidthMode: StyleParam.EntryWidthMode,
[<Optional; DefaultParameterValue(null)>] ?Font: Font,
[<Optional; DefaultParameterValue(null)>] ?GroupClick: StyleParam.TraceGroupClickOptions,
[<Optional; DefaultParameterValue(null)>] ?GroupTitleFont: Font,
Expand All @@ -2589,7 +2591,9 @@ type Chart =
Legend.init (
?BGColor = BGColor,
?BorderColor = BorderColor,
?Borderwidth = Borderwidth,
?BorderWidth = BorderWidth,
?EntryWidth = EntryWidth,
?EntryWidthMode = EntryWidthMode,
?Font = Font,
?GroupClick = GroupClick,
?GroupTitleFont = GroupTitleFont,
Expand All @@ -2607,7 +2611,6 @@ type Chart =
?XAnchor = XAnchor,
?Y = Y,
?YAnchor = YAnchor

)

ch |> Chart.withLegend legend)
Expand Down
15 changes: 15 additions & 0 deletions src/Plotly.NET/CommonAbstractions/StyleParams.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1069,6 +1069,21 @@ module StyleParam =
// #E#
//--------------------------

[<RequireQualifiedAccess>]
type EntryWidthMode =
| Fraction
| Pixels

static member toString =
function
| Fraction -> "fraction"
| Pixels -> "pixels"


static member convert = EntryWidthMode.toString >> box
override this.ToString() = this |> EntryWidthMode.toString
member this.Convert() = this |> EntryWidthMode.convert

[<RequireQualifiedAccess>]
type ErrorType =
| Percent
Expand Down
20 changes: 16 additions & 4 deletions src/Plotly.NET/Layout/ObjectAbstractions/Common/Legend.fs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ type Legend() =
/// </summary>
/// <param name="BGColor">Sets the legend background color. Defaults to `layout.paper_bgcolor`.</param>
/// <param name="BorderColor">Sets the color of the border enclosing the legend.</param>
/// <param name="EntryWidth">Sets the width (in px or fraction) of the legend. Use 0 to size the entry based on the text width, when `entrywidthmode` is set to "pixels".</param>
/// <param name="EntryWidthMode">Determines what entrywidth means.</param>
/// <param name="Borderwidth">Sets the width (in px) of the border enclosing the legend.</param>
/// <param name="Font">Sets the font used to text the legend items.</param>
/// <param name="GroupClick">Determines the behavior on legend group item click. "toggleitem" toggles the visibility of the individual item clicked on the graph. "togglegroup" toggles the visibility of all items in the same legendgroup as the item clicked on the graph.</param>
Expand All @@ -36,7 +38,9 @@ type Legend() =
(
[<Optional; DefaultParameterValue(null)>] ?BGColor: Color,
[<Optional; DefaultParameterValue(null)>] ?BorderColor: Color,
[<Optional; DefaultParameterValue(null)>] ?Borderwidth: float,
[<Optional; DefaultParameterValue(null)>] ?BorderWidth: float,
[<Optional; DefaultParameterValue(null)>] ?EntryWidth: float,
[<Optional; DefaultParameterValue(null)>] ?EntryWidthMode: StyleParam.EntryWidthMode,
[<Optional; DefaultParameterValue(null)>] ?Font: Font,
[<Optional; DefaultParameterValue(null)>] ?GroupClick: StyleParam.TraceGroupClickOptions,
[<Optional; DefaultParameterValue(null)>] ?GroupTitleFont: Font,
Expand All @@ -59,7 +63,9 @@ type Legend() =
|> Legend.style (
?BGColor = BGColor,
?BorderColor = BorderColor,
?Borderwidth = Borderwidth,
?BorderWidth = BorderWidth,
?EntryWidth = EntryWidth,
?EntryWidthMode = EntryWidthMode,
?Font = Font,
?GroupClick = GroupClick,
?GroupTitleFont = GroupTitleFont,
Expand All @@ -85,6 +91,8 @@ type Legend() =
/// <param name="BGColor">Sets the legend background color. Defaults to `layout.paper_bgcolor`.</param>
/// <param name="BorderColor">Sets the color of the border enclosing the legend.</param>
/// <param name="Borderwidth">Sets the width (in px) of the border enclosing the legend.</param>
/// <param name="EntryWidth">Sets the width (in px or fraction) of the legend. Use 0 to size the entry based on the text width, when `entrywidthmode` is set to "pixels".</param>
/// <param name="EntryWidthMode">Determines what entrywidth means.</param>
/// <param name="Font">Sets the font used to text the legend items.</param>
/// <param name="GroupClick">Determines the behavior on legend group item click. "toggleitem" toggles the visibility of the individual item clicked on the graph. "togglegroup" toggles the visibility of all items in the same legendgroup as the item clicked on the graph.</param>
/// <param name="GroupTitleFont">Sets the font for group titles in legend. Defaults to `legend.font` with its size increased about 10%.</param>
Expand All @@ -106,7 +114,9 @@ type Legend() =
(
[<Optional; DefaultParameterValue(null)>] ?BGColor: Color,
[<Optional; DefaultParameterValue(null)>] ?BorderColor: Color,
[<Optional; DefaultParameterValue(null)>] ?Borderwidth: float,
[<Optional; DefaultParameterValue(null)>] ?BorderWidth: float,
[<Optional; DefaultParameterValue(null)>] ?EntryWidth: float,
[<Optional; DefaultParameterValue(null)>] ?EntryWidthMode: StyleParam.EntryWidthMode,
[<Optional; DefaultParameterValue(null)>] ?Font: Font,
[<Optional; DefaultParameterValue(null)>] ?GroupClick: StyleParam.TraceGroupClickOptions,
[<Optional; DefaultParameterValue(null)>] ?GroupTitleFont: Font,
Expand All @@ -128,7 +138,9 @@ type Legend() =
(fun (legend: Legend) ->
BGColor |> DynObj.setValueOpt legend "bgcolor"
BorderColor |> DynObj.setValueOpt legend "bordercolor"
Borderwidth |> DynObj.setValueOpt legend "font"
BorderWidth |> DynObj.setValueOpt legend "font"
EntryWidth|> DynObj.setValueOpt legend "entrywidth"
EntryWidthMode|> DynObj.setValueOptBy legend "entrywidthmode" StyleParam.EntryWidthMode.convert
Font |> DynObj.setValueOpt legend "borderwidth"
GroupClick |> DynObj.setValueOptBy legend "groupclick" StyleParam.TraceGroupClickOptions.convert
GroupTitleFont |> DynObj.setValueOpt legend "grouptitlefont"
Expand Down

0 comments on commit b9dffc3

Please sign in to comment.