Skip to content

Commit

Permalink
plotlyjs v2.26: add new autorange options
Browse files Browse the repository at this point in the history
- Add new options to the AutoRange StyleParam
- Add `maxallowed` and `minallowed` to cartesian and radial axes
- add new `AutoRangeOptions` object and respective settings to cartesian and radial axes
- fix dependencies of tests projects: Expecto v10, F# update to 7 made tests undiscoverable
  • Loading branch information
kMutagene committed Nov 5, 2023
1 parent b64e942 commit 92f92a5
Show file tree
Hide file tree
Showing 12 changed files with 481 additions and 33 deletions.
61 changes: 61 additions & 0 deletions src/Plotly.NET/CommonAbstractions/AutoRangeOptions.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
namespace Plotly.NET

open Plotly.NET
open DynamicObj
open System
open System.Runtime.InteropServices

type AutoRangeOptions() =
inherit DynamicObj()

/// <summary>
/// Returns a new AutoRangeOptions object with the given styling.
/// </summary>
/// <param name="ClipMax">Clip autorange maximum if it goes beyond this value. Has no effect when `autorangeoptions.maxallowed` is provided.</param>
/// <param name="ClipMin">Clip autorange minimum if it goes beyond this value. Has no effect when `autorangeoptions.minallowed` is provided.</param>
/// <param name="Include">Ensure this value is included in autorange.</param>
/// <param name="MaxAllowed">Use this value exactly as autorange maximum.</param>
/// <param name="MinAllowed">Use this value exactly as autorange minimum.</param>
static member init
(
[<Optional; DefaultParameterValue(null)>] ?ClipMax: #IConvertible,
[<Optional; DefaultParameterValue(null)>] ?ClipMin: #IConvertible,
[<Optional; DefaultParameterValue(null)>] ?Include: #IConvertible,
[<Optional; DefaultParameterValue(null)>] ?MaxAllowed: #IConvertible,
[<Optional; DefaultParameterValue(null)>] ?MinAllowed: #IConvertible
) =
AutoRangeOptions()
|> AutoRangeOptions.style (
?ClipMax = ClipMax,
?ClipMin = ClipMin,
?Include = Include,
?MaxAllowed = MaxAllowed,
?MinAllowed = MinAllowed
)

/// <summary>
/// Returns a function that applies the given styles to a AutoRangeOptions object.
/// </summary>
/// <param name="ClipMax">Clip autorange maximum if it goes beyond this value. Has no effect when `autorangeoptions.maxallowed` is provided.</param>
/// <param name="ClipMin">Clip autorange minimum if it goes beyond this value. Has no effect when `autorangeoptions.minallowed` is provided.</param>
/// <param name="Include">Ensure this value is included in autorange.</param>
/// <param name="MaxAllowed">Use this value exactly as autorange maximum.</param>
/// <param name="MinAllowed">Use this value exactly as autorange minimum.</param>
static member style
(
[<Optional; DefaultParameterValue(null)>] ?ClipMax: #IConvertible,
[<Optional; DefaultParameterValue(null)>] ?ClipMin: #IConvertible,
[<Optional; DefaultParameterValue(null)>] ?Include: #IConvertible,
[<Optional; DefaultParameterValue(null)>] ?MaxAllowed: #IConvertible,
[<Optional; DefaultParameterValue(null)>] ?MinAllowed: #IConvertible

) =
(fun (autoRangeOptions: AutoRangeOptions) ->

ClipMax |> DynObj.setValueOpt autoRangeOptions "clipmax"
ClipMin |> DynObj.setValueOpt autoRangeOptions "clipmin"
Include |> DynObj.setValueOpt autoRangeOptions "include"
MaxAllowed |> DynObj.setValueOpt autoRangeOptions "maxallowed"
MinAllowed |> DynObj.setValueOpt autoRangeOptions "minallowed"

autoRangeOptions)
12 changes: 11 additions & 1 deletion src/Plotly.NET/CommonAbstractions/StyleParams.fs
Original file line number Diff line number Diff line change
Expand Up @@ -124,18 +124,28 @@ module StyleParam =
override this.ToString() = this |> Align.toString
member this.Convert() = this |> Align.convert

/// Determines whether or not the range of this axis is computed in relation to the input data. See `rangemode` for more info. If `range` is provided, then `autorange` is set to "false".
/// <summary>
/// Determines whether or not the range of this axis is computed in relation to the input data. See `rangemode` for more info. If `range` is provided and it has a value for both the lower and upper bound, `autorange` is set to "false". Using "min" applies autorange only to set the minimum. Using "max" applies autorange only to set the maximum. Using "min reversed" applies autorange only to set the minimum on a reversed axis. Using "max reversed" applies autorange only to set the maximum on a reversed axis. Using "reversed" applies autorange on both ends and reverses the axis direction.
/// </summary>
[<RequireQualifiedAccess>]
type AutoRange =
| True
| False
| Reversed
| MinReversed
| MaxReversed
| Min
| Max

static member convert =
function
| True -> box true
| False -> box false
| Reversed -> box "reversed"
| MinReversed -> box "min reversed"
| MaxReversed -> box "max reversed"
| Min -> box "min"
| Max -> box "max"

member this.Convert() = this |> AutoRange.convert

Expand Down
18 changes: 18 additions & 0 deletions src/Plotly.NET/Layout/ObjectAbstractions/Common/LinearAxis.fs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type LinearAxis() =
/// <param name="AxisType">Sets the axis type. By default, plotly attempts to determined the axis type by looking into the data of the traces that referenced the axis in question.</param>
/// <param name="AutoTypeNumbers">Using "strict" a numeric string in trace data is not converted to a number. Using "convert types" a numeric string in trace data may be treated as a number during automatic axis `type` detection. Defaults to layout.autotypenumbers.</param>
/// <param name="AutoRange">Determines whether or not the range of this axis is computed in relation to the input data. See `rangemode` for more info. If `range` is provided, then `autorange` is set to "false".</param>
/// <param name="AutoRangeOptions">Additional options for bounding the autorange</param>
/// <param name="AutoShift">Automatically reposition the axis to avoid overlap with other axes with the same `overlaying` value. This repositioning will account for any `shift` amount applied to other axes on the same side with `autoshift` is set to true. Only has an effect if `anchor` is set to "free".</param>
/// <param name="RangeMode">If "normal", the range is computed in relation to the extrema of the input data. If "tozero"`, the range extends to 0, regardless of the input data If "nonnegative", the range is non-negative, regardless of the input data. Applies only to linear axes.</param>
/// <param name="Range">Sets the range of this axis. If the axis `type` is "log", then you must take the log of your desired range (e.g. to set the range from 1 to 100, set the range from 0 to 2). If the axis `type` is "date", it should be date strings, like date data, though Date objects and unix milliseconds will be accepted and converted to strings. If the axis `type` is "category", it should be numbers, using the scale where each category is assigned a serial number from zero in the order it appears.</param>
Expand All @@ -27,6 +28,8 @@ type LinearAxis() =
/// <param name="Constrain">If this axis needs to be compressed (either due to its own `scaleanchor` and `scaleratio` or those of the other axis), determines how that happens: by increasing the "range", or by decreasing the "domain". Default is "domain" for axes containing image traces, "range" otherwise.</param>
/// <param name="ConstrainToward">If this axis needs to be compressed (either due to its own `scaleanchor` and `scaleratio` or those of the other axis), determines which direction we push the originally specified plot area. Options are "left", "center" (default), and "right" for x axes, and "top", "middle" (default), and "bottom" for y axes.</param>
/// <param name="Matches">If set to another axis id (e.g. `x2`, `y`), the range of this axis will match the range of the corresponding axis in data-coordinates space. Moreover, matching axes share auto-range values, category lists and histogram auto-bins. Note that setting axes simultaneously in both a `scaleanchor` and a `matches` constraint is currently forbidden. Moreover, note that matching axes must have the same `type`.</param>
/// <param name="MaxAllowed">Determines the maximum range of this axis.</param>
/// <param name="MinAllowed">Determines the minimum range of this axis.</param>
/// <param name="Rangebreaks">Sets breaks in the axis range</param>
/// <param name="TickMode">Sets the tick mode for this axis. If "auto", the number of ticks is set via `nticks`. If "linear", the placement of the ticks is determined by a starting position `tick0` and a tick step `dtick` ("linear" is the default value if `tick0` and `dtick` are provided). If "array", the placement of the ticks is set via `tickvals` and the tick text is `ticktext`. ("array" is the default value if `tickvals` is provided). If "sync", the number of ticks will sync with the overlayed axis set by `overlaying` property.</param>
/// <param name="NTicks">Specifies the maximum number of ticks for the particular axis. The actual number of ticks will be chosen automatically to be less than or equal to `nticks`. Has an effect only if `tickmode` is set to "auto".</param>
Expand Down Expand Up @@ -103,6 +106,7 @@ type LinearAxis() =
[<Optional; DefaultParameterValue(null)>] ?AxisType: StyleParam.AxisType,
[<Optional; DefaultParameterValue(null)>] ?AutoTypeNumbers: StyleParam.AutoTypeNumbers,
[<Optional; DefaultParameterValue(null)>] ?AutoRange: StyleParam.AutoRange,
[<Optional; DefaultParameterValue(null)>] ?AutoRangeOptions: AutoRangeOptions,
[<Optional; DefaultParameterValue(null)>] ?AutoShift: bool,
[<Optional; DefaultParameterValue(null)>] ?RangeMode: StyleParam.RangeMode,
[<Optional; DefaultParameterValue(null)>] ?Range: StyleParam.Range,
Expand All @@ -112,6 +116,8 @@ type LinearAxis() =
[<Optional; DefaultParameterValue(null)>] ?Constrain: StyleParam.AxisConstraint,
[<Optional; DefaultParameterValue(null)>] ?ConstrainToward: StyleParam.AxisConstraintDirection,
[<Optional; DefaultParameterValue(null)>] ?Matches: StyleParam.LinearAxisId,
[<Optional; DefaultParameterValue(null)>] ?MaxAllowed: #IConvertible,
[<Optional; DefaultParameterValue(null)>] ?MinAllowed: #IConvertible,
[<Optional; DefaultParameterValue(null)>] ?Rangebreaks: seq<Rangebreak>,
[<Optional; DefaultParameterValue(null)>] ?TickMode: StyleParam.TickMode,
[<Optional; DefaultParameterValue(null)>] ?NTicks: int,
Expand Down Expand Up @@ -189,6 +195,7 @@ type LinearAxis() =
?AxisType = AxisType,
?AutoTypeNumbers = AutoTypeNumbers,
?AutoRange = AutoRange,
?AutoRangeOptions = AutoRangeOptions,
?AutoShift = AutoShift,
?RangeMode = RangeMode,
?Range = Range,
Expand All @@ -198,6 +205,8 @@ type LinearAxis() =
?Constrain = Constrain,
?ConstrainToward = ConstrainToward,
?Matches = Matches,
?MinAllowed = MinAllowed,
?MaxAllowed = MaxAllowed,
?Rangebreaks = Rangebreaks,
?TickMode = TickMode,
?NTicks = NTicks,
Expand Down Expand Up @@ -789,6 +798,7 @@ type LinearAxis() =
/// <param name="AutoTypeNumbers">Using "strict" a numeric string in trace data is not converted to a number. Using "convert types" a numeric string in trace data may be treated as a number during automatic axis `type` detection. Defaults to layout.autotypenumbers.</param>
/// <param name="AutoShift">Automatically reposition the axis to avoid overlap with other axes with the same `overlaying` value. This repositioning will account for any `shift` amount applied to other axes on the same side with `autoshift` is set to true. Only has an effect if `anchor` is set to "free".</param>
/// <param name="AutoRange">Determines whether or not the range of this axis is computed in relation to the input data. See `rangemode` for more info. If `range` is provided, then `autorange` is set to "false".</param>
/// <param name="AutoRangeOptions">Additional options for bounding the autorange</param>
/// <param name="RangeMode">If "normal", the range is computed in relation to the extrema of the input data. If "tozero"`, the range extends to 0, regardless of the input data If "nonnegative", the range is non-negative, regardless of the input data. Applies only to linear axes.</param>
/// <param name="Range">Sets the range of this axis. If the axis `type` is "log", then you must take the log of your desired range (e.g. to set the range from 1 to 100, set the range from 0 to 2). If the axis `type` is "date", it should be date strings, like date data, though Date objects and unix milliseconds will be accepted and converted to strings. If the axis `type` is "category", it should be numbers, using the scale where each category is assigned a serial number from zero in the order it appears.</param>
/// <param name="FixedRange">Determines whether or not this axis is zoom-able. If true, then zoom is disabled.</param>
Expand All @@ -797,6 +807,8 @@ type LinearAxis() =
/// <param name="Constrain">If this axis needs to be compressed (either due to its own `scaleanchor` and `scaleratio` or those of the other axis), determines how that happens: by increasing the "range", or by decreasing the "domain". Default is "domain" for axes containing image traces, "range" otherwise.</param>
/// <param name="ConstrainToward">If this axis needs to be compressed (either due to its own `scaleanchor` and `scaleratio` or those of the other axis), determines which direction we push the originally specified plot area. Options are "left", "center" (default), and "right" for x axes, and "top", "middle" (default), and "bottom" for y axes.</param>
/// <param name="Matches">If set to another axis id (e.g. `x2`, `y`), the range of this axis will match the range of the corresponding axis in data-coordinates space. Moreover, matching axes share auto-range values, category lists and histogram auto-bins. Note that setting axes simultaneously in both a `scaleanchor` and a `matches` constraint is currently forbidden. Moreover, note that matching axes must have the same `type`.</param>
/// <param name="MaxAllowed">Determines the maximum range of this axis.</param>
/// <param name="MinAllowed">Determines the minimum range of this axis.</param>
/// <param name="Rangebreaks">Sets breaks in the axis range</param>
/// <param name="TickMode">Sets the tick mode for this axis. If "auto", the number of ticks is set via `nticks`. If "linear", the placement of the ticks is determined by a starting position `tick0` and a tick step `dtick` ("linear" is the default value if `tick0` and `dtick` are provided). If "array", the placement of the ticks is set via `TickVals` and the tick text is `TickText`. ("array" is the default value if `TickVals` is provided).</param>
/// <param name="NTicks">Specifies the maximum number of ticks for the particular axis. The actual number of ticks will be chosen automatically to be less than or equal to `nticks`. Has an effect only if `tickmode` is set to "auto".</param>
Expand Down Expand Up @@ -890,6 +902,7 @@ type LinearAxis() =
[<Optional; DefaultParameterValue(null)>] ?AxisType: StyleParam.AxisType,
[<Optional; DefaultParameterValue(null)>] ?AutoTypeNumbers: StyleParam.AutoTypeNumbers,
[<Optional; DefaultParameterValue(null)>] ?AutoRange: StyleParam.AutoRange,
[<Optional; DefaultParameterValue(null)>] ?AutoRangeOptions: AutoRangeOptions,
[<Optional; DefaultParameterValue(null)>] ?AutoShift: bool,
[<Optional; DefaultParameterValue(null)>] ?RangeMode: StyleParam.RangeMode,
[<Optional; DefaultParameterValue(null)>] ?Range: StyleParam.Range,
Expand All @@ -899,6 +912,8 @@ type LinearAxis() =
[<Optional; DefaultParameterValue(null)>] ?Constrain: StyleParam.AxisConstraint,
[<Optional; DefaultParameterValue(null)>] ?ConstrainToward: StyleParam.AxisConstraintDirection,
[<Optional; DefaultParameterValue(null)>] ?Matches: StyleParam.LinearAxisId,
[<Optional; DefaultParameterValue(null)>] ?MaxAllowed: #IConvertible,
[<Optional; DefaultParameterValue(null)>] ?MinAllowed: #IConvertible,
[<Optional; DefaultParameterValue(null)>] ?Rangebreaks: seq<Rangebreak>,
[<Optional; DefaultParameterValue(null)>] ?TickMode: StyleParam.TickMode,
[<Optional; DefaultParameterValue(null)>] ?NTicks: int,
Expand Down Expand Up @@ -993,6 +1008,7 @@ type LinearAxis() =
AxisType |> DynObj.setValueOptBy axis "type" StyleParam.AxisType.convert
AutoTypeNumbers |> DynObj.setValueOptBy axis "autotypenumbers" StyleParam.AutoTypeNumbers.convert
AutoRange |> DynObj.setValueOptBy axis "autorange" StyleParam.AutoRange.convert
AutoRangeOptions |> DynObj.setValueOpt axis "autorangeoptions"
AutoShift |> DynObj.setValueOpt axis "autoshift"
RangeMode |> DynObj.setValueOptBy axis "rangemode" StyleParam.RangeMode.convert
Range |> DynObj.setValueOptBy axis "range" StyleParam.Range.convert
Expand All @@ -1002,6 +1018,8 @@ type LinearAxis() =
Constrain |> DynObj.setValueOptBy axis "constrain" StyleParam.AxisConstraint.convert
ConstrainToward |> DynObj.setValueOptBy axis "constraintoward" StyleParam.AxisConstraintDirection.convert
Matches |> DynObj.setValueOptBy axis "matches" StyleParam.LinearAxisId.convert
MaxAllowed |> DynObj.setValueOpt axis "maxallowed"
MinAllowed |> DynObj.setValueOpt axis "minallowed"
Rangebreaks |> DynObj.setValueOpt axis "rangebreaks"
TickMode |> DynObj.setValueOptBy axis "tickmode" StyleParam.TickMode.convert
NTicks |> DynObj.setValueOpt axis "nticks"
Expand Down
Loading

0 comments on commit 92f92a5

Please sign in to comment.