Skip to content

Commit bad6d53

Browse files
committed
plotlyjs 2.26: Add "false" option to scaleanchor
- Add proper StyleParam for `ScaleAnchor`
1 parent bebe507 commit bad6d53

File tree

6 files changed

+51
-19
lines changed

6 files changed

+51
-19
lines changed

src/Plotly.NET/CommonAbstractions/StyleParams.fs

+14
Original file line numberDiff line numberDiff line change
@@ -2661,6 +2661,20 @@ module StyleParam =
26612661
// #S#
26622662
//--------------------------
26632663

2664+
[<RequireQualifiedAccess>]
2665+
type ScaleAnchor =
2666+
| False
2667+
| X of int
2668+
| Y of int
2669+
2670+
static member convert =
2671+
function
2672+
| False -> box false
2673+
| X id -> (if id < 2 then "x" else sprintf "x%i" id) |> box
2674+
| Y id -> (if id < 2 then "y" else sprintf "y%i" id) |> box
2675+
2676+
member this.Convert() = this |> ScaleAnchor.convert
2677+
26642678
[<RequireQualifiedAccess>]
26652679
type ScrollZoom =
26662680
| Cartesian

src/Plotly.NET/Layout/ObjectAbstractions/Common/LinearAxis.fs

+7-7
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ type LinearAxis() =
2323
/// <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>
2424
/// <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>
2525
/// <param name="FixedRange">Determines whether or not this axis is zoom-able. If true, then zoom is disabled.</param>
26-
/// <param name="ScaleAnchor">If set to another axis id (e.g. `x2`, `y`), the range of this axis changes together with the range of the corresponding axis such that the scale of pixels per unit is in a constant ratio. Both axes are still zoomable, but when you zoom one, the other will zoom the same amount, keeping a fixed midpoint. `constrain` and `constraintoward` determine how we enforce the constraint. You can chain these, ie `yaxis: {scaleanchor: "x"}, xaxis2: {scaleanchor: "y"}` but you can only link axes of the same `type`. The linked axis can have the opposite letter (to constrain the aspect ratio) or the same letter (to match scales across subplots). Loops (`yaxis: {scaleanchor: "x"}, xaxis: {scaleanchor: "y"}` or longer) are redundant and the last constraint encountered will be ignored to avoid possible inconsistent constraints via `scaleratio`. Note that setting axes simultaneously in both a `scaleanchor` and a `matches` constraint is currently forbidden.</param>
26+
/// <param name="ScaleAnchor">If set to another axis id (e.g. `x2`, `y`), the range of this axis changes together with the range of the corresponding axis such that the scale of pixels per unit is in a constant ratio. Both axes are still zoomable, but when you zoom one, the other will zoom the same amount, keeping a fixed midpoint. `constrain` and `constraintoward` determine how we enforce the constraint. You can chain these, ie `yaxis: {scaleanchor: "x"}, xaxis2: {scaleanchor: "y"}` but you can only link axes of the same `type`. The linked axis can have the opposite letter (to constrain the aspect ratio) or the same letter (to match scales across subplots). Loops (`yaxis: {scaleanchor: "x"}, xaxis: {scaleanchor: "y"}` or longer) are redundant and the last constraint encountered will be ignored to avoid possible inconsistent constraints via `scaleratio`. Note that setting axes simultaneously in both a `scaleanchor` and a `matches` constraint is currently forbidden. Setting `false` allows to remove a default constraint (occasionally, you may need to prevent a default `scaleanchor` constraint from being applied, eg. when having an image trace `yaxis: {scaleanchor: "x"}` is set automatically in order for pixels to be rendered as squares, setting `yaxis: {scaleanchor: false}` allows to remove the constraint).</param>
2727
/// <param name="ScaleRatio">If this axis is linked to another by `scaleanchor`, this determines the pixel to unit scale ratio. For example, if this value is 10, then every unit on this axis spans 10 times the number of pixels as a unit on the linked axis. Use this for example to create an elevation profile where the vertical scale is exaggerated a fixed amount with respect to the horizontal.</param>
2828
/// <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>
2929
/// <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>
@@ -111,7 +111,7 @@ type LinearAxis() =
111111
[<Optional; DefaultParameterValue(null)>] ?RangeMode: StyleParam.RangeMode,
112112
[<Optional; DefaultParameterValue(null)>] ?Range: StyleParam.Range,
113113
[<Optional; DefaultParameterValue(null)>] ?FixedRange: bool,
114-
[<Optional; DefaultParameterValue(null)>] ?ScaleAnchor: StyleParam.LinearAxisId,
114+
[<Optional; DefaultParameterValue(null)>] ?ScaleAnchor: StyleParam.ScaleAnchor,
115115
[<Optional; DefaultParameterValue(null)>] ?ScaleRatio: float,
116116
[<Optional; DefaultParameterValue(null)>] ?Constrain: StyleParam.AxisConstraint,
117117
[<Optional; DefaultParameterValue(null)>] ?ConstrainToward: StyleParam.AxisConstraintDirection,
@@ -290,7 +290,7 @@ type LinearAxis() =
290290
/// <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>
291291
/// <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>
292292
/// <param name="FixedRange">Determines whether or not this axis is zoom-able. If true, then zoom is disabled.</param>
293-
/// <param name="ScaleAnchor">If set to another axis id (e.g. `x2`, `y`), the range of this axis changes together with the range of the corresponding axis such that the scale of pixels per unit is in a constant ratio. Both axes are still zoomable, but when you zoom one, the other will zoom the same amount, keeping a fixed midpoint. `constrain` and `constraintoward` determine how we enforce the constraint. You can chain these, ie `yaxis: {scaleanchor: "x"}, xaxis2: {scaleanchor: "y"}` but you can only link axes of the same `type`. The linked axis can have the opposite letter (to constrain the aspect ratio) or the same letter (to match scales across subplots). Loops (`yaxis: {scaleanchor: "x"}, xaxis: {scaleanchor: "y"}` or longer) are redundant and the last constraint encountered will be ignored to avoid possible inconsistent constraints via `scaleratio`. Note that setting axes simultaneously in both a `scaleanchor` and a `matches` constraint is currently forbidden.</param>
293+
/// <param name="ScaleAnchor">If set to another axis id (e.g. `x2`, `y`), the range of this axis changes together with the range of the corresponding axis such that the scale of pixels per unit is in a constant ratio. Both axes are still zoomable, but when you zoom one, the other will zoom the same amount, keeping a fixed midpoint. `constrain` and `constraintoward` determine how we enforce the constraint. You can chain these, ie `yaxis: {scaleanchor: "x"}, xaxis2: {scaleanchor: "y"}` but you can only link axes of the same `type`. The linked axis can have the opposite letter (to constrain the aspect ratio) or the same letter (to match scales across subplots). Loops (`yaxis: {scaleanchor: "x"}, xaxis: {scaleanchor: "y"}` or longer) are redundant and the last constraint encountered will be ignored to avoid possible inconsistent constraints via `scaleratio`. Note that setting axes simultaneously in both a `scaleanchor` and a `matches` constraint is currently forbidden. Setting `false` allows to remove a default constraint (occasionally, you may need to prevent a default `scaleanchor` constraint from being applied, eg. when having an image trace `yaxis: {scaleanchor: "x"}` is set automatically in order for pixels to be rendered as squares, setting `yaxis: {scaleanchor: false}` allows to remove the constraint).</param>
294294
/// <param name="ScaleRatio">If this axis is linked to another by `scaleanchor`, this determines the pixel to unit scale ratio. For example, if this value is 10, then every unit on this axis spans 10 times the number of pixels as a unit on the linked axis. Use this for example to create an elevation profile where the vertical scale is exaggerated a fixed amount with respect to the horizontal.</param>
295295
/// <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>
296296
/// <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>
@@ -371,7 +371,7 @@ type LinearAxis() =
371371
[<Optional; DefaultParameterValue(null)>] ?RangeMode: StyleParam.RangeMode,
372372
[<Optional; DefaultParameterValue(null)>] ?Range: StyleParam.Range,
373373
[<Optional; DefaultParameterValue(null)>] ?FixedRange: bool,
374-
[<Optional; DefaultParameterValue(null)>] ?ScaleAnchor: StyleParam.LinearAxisId,
374+
[<Optional; DefaultParameterValue(null)>] ?ScaleAnchor: StyleParam.ScaleAnchor,
375375
[<Optional; DefaultParameterValue(null)>] ?ScaleRatio: float,
376376
[<Optional; DefaultParameterValue(null)>] ?Constrain: StyleParam.AxisConstraint,
377377
[<Optional; DefaultParameterValue(null)>] ?ConstrainToward: StyleParam.AxisConstraintDirection,
@@ -802,7 +802,7 @@ type LinearAxis() =
802802
/// <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>
803803
/// <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>
804804
/// <param name="FixedRange">Determines whether or not this axis is zoom-able. If true, then zoom is disabled.</param>
805-
/// <param name="ScaleAnchor">If set to another axis id (e.g. `x2`, `y`), the range of this axis changes together with the range of the corresponding axis such that the scale of pixels per unit is in a constant ratio. Both axes are still zoomable, but when you zoom one, the other will zoom the same amount, keeping a fixed midpoint. `constrain` and `constraintoward` determine how we enforce the constraint. You can chain these, ie `yaxis: {scaleanchor: "x"}, xaxis2: {scaleanchor: "y"}` but you can only link axes of the same `type`. The linked axis can have the opposite letter (to constrain the aspect ratio) or the same letter (to match scales across subplots). Loops (`yaxis: {scaleanchor: "x"}, xaxis: {scaleanchor: "y"}` or longer) are redundant and the last constraint encountered will be ignored to avoid possible inconsistent constraints via `scaleratio`. Note that setting axes simultaneously in both a `scaleanchor` and a `matches` constraint is currently forbidden.</param>
805+
/// <param name="ScaleAnchor">If set to another axis id (e.g. `x2`, `y`), the range of this axis changes together with the range of the corresponding axis such that the scale of pixels per unit is in a constant ratio. Both axes are still zoomable, but when you zoom one, the other will zoom the same amount, keeping a fixed midpoint. `constrain` and `constraintoward` determine how we enforce the constraint. You can chain these, ie `yaxis: {scaleanchor: "x"}, xaxis2: {scaleanchor: "y"}` but you can only link axes of the same `type`. The linked axis can have the opposite letter (to constrain the aspect ratio) or the same letter (to match scales across subplots). Loops (`yaxis: {scaleanchor: "x"}, xaxis: {scaleanchor: "y"}` or longer) are redundant and the last constraint encountered will be ignored to avoid possible inconsistent constraints via `scaleratio`. Note that setting axes simultaneously in both a `scaleanchor` and a `matches` constraint is currently forbidden. Setting `false` allows to remove a default constraint (occasionally, you may need to prevent a default `scaleanchor` constraint from being applied, eg. when having an image trace `yaxis: {scaleanchor: "x"}` is set automatically in order for pixels to be rendered as squares, setting `yaxis: {scaleanchor: false}` allows to remove the constraint).</param>
806806
/// <param name="ScaleRatio">If this axis is linked to another by `scaleanchor`, this determines the pixel to unit scale ratio. For example, if this value is 10, then every unit on this axis spans 10 times the number of pixels as a unit on the linked axis. Use this for example to create an elevation profile where the vertical scale is exaggerated a fixed amount with respect to the horizontal.</param>
807807
/// <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>
808808
/// <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>
@@ -907,7 +907,7 @@ type LinearAxis() =
907907
[<Optional; DefaultParameterValue(null)>] ?RangeMode: StyleParam.RangeMode,
908908
[<Optional; DefaultParameterValue(null)>] ?Range: StyleParam.Range,
909909
[<Optional; DefaultParameterValue(null)>] ?FixedRange: bool,
910-
[<Optional; DefaultParameterValue(null)>] ?ScaleAnchor: StyleParam.LinearAxisId,
910+
[<Optional; DefaultParameterValue(null)>] ?ScaleAnchor: StyleParam.ScaleAnchor,
911911
[<Optional; DefaultParameterValue(null)>] ?ScaleRatio: float,
912912
[<Optional; DefaultParameterValue(null)>] ?Constrain: StyleParam.AxisConstraint,
913913
[<Optional; DefaultParameterValue(null)>] ?ConstrainToward: StyleParam.AxisConstraintDirection,
@@ -1013,7 +1013,7 @@ type LinearAxis() =
10131013
RangeMode |> DynObj.setValueOptBy axis "rangemode" StyleParam.RangeMode.convert
10141014
Range |> DynObj.setValueOptBy axis "range" StyleParam.Range.convert
10151015
FixedRange |> DynObj.setValueOpt axis "fixedrange"
1016-
ScaleAnchor |> DynObj.setValueOptBy axis "scaleanchor" StyleParam.LinearAxisId.convert
1016+
ScaleAnchor |> DynObj.setValueOptBy axis "scaleanchor" StyleParam.ScaleAnchor.convert
10171017
ScaleRatio |> DynObj.setValueOpt axis "scaleratio"
10181018
Constrain |> DynObj.setValueOptBy axis "constrain" StyleParam.AxisConstraint.convert
10191019
ConstrainToward |> DynObj.setValueOptBy axis "constraintoward" StyleParam.AxisConstraintDirection.convert

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

+8
Original file line numberDiff line numberDiff line change
@@ -211,3 +211,11 @@ module ``New Side options for (legend) titles`` =
211211
)
212212

213213

214+
module ``New scaleanchor option for linear axes`` =
215+
let ``Point chart with scaleanchor=false`` =
216+
Chart.Point([1,2], UseDefaults = false)
217+
|> Chart.withXAxis(
218+
LinearAxis.init(
219+
ScaleAnchor = StyleParam.ScaleAnchor.False
220+
)
221+
)

tests/ConsoleApps/FSharpConsole/Program.fs

+5-11
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,11 @@ open Newtonsoft.Json
1111

1212
[<EntryPoint>]
1313
let main argv =
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
14+
Chart.Point([1,2], UseDefaults = false)
15+
|> Chart.withXAxis(
16+
LinearAxis.init(
17+
ScaleAnchor = StyleParam.ScaleAnchor.False
18+
)
2519
)
2620
|> Chart.show
2721
0

tests/CoreTests/CoreTests/LayoutObjects/LinearAxis.fs

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ let fullAxis =
1919
RangeMode = StyleParam.RangeMode.Normal,
2020
Range = StyleParam.Range.MinMax (-1.,1.),
2121
FixedRange = true ,
22-
ScaleAnchor = StyleParam.LinearAxisId.X 1,
22+
ScaleAnchor = StyleParam.ScaleAnchor.X 1,
2323
ScaleRatio = 6.9,
2424
Constrain = StyleParam.AxisConstraint.Range,
2525
ConstrainToward = StyleParam.AxisConstraintDirection.Bottom,

tests/CoreTests/CoreTests/UpstreamFeatures/2.26.fs

+16
Original file line numberDiff line numberDiff line change
@@ -113,4 +113,20 @@ module ``New Side options for (legend) titles`` =
113113
|> chartGeneratedContains ``New Side options for (legend) titles``.``Point charts with horizontal legend title top right``
114114
)
115115
]
116+
]
117+
118+
module ``New scaleanchor option for linear axes`` =
119+
[<Tests>]
120+
let ``New ScaleAnchor option`` =
121+
testList "UpstreamFeatures.PlotlyJS_2_26" [
122+
testList "New scaleanchor option for linear axes" [
123+
testCase "scaleanchor=false data" ( fun () ->
124+
"""var data = [{"type":"scatter","mode":"markers","x":[1],"y":[2],"marker":{},"line":{}}];"""
125+
|> chartGeneratedContains ``New scaleanchor option for linear axes``.``Point chart with scaleanchor=false``
126+
)
127+
testCase "scaleanchor=false layout" ( fun () ->
128+
"""var layout = {"xaxis":{"scaleanchor":false}};"""
129+
|> chartGeneratedContains ``New scaleanchor option for linear axes``.``Point chart with scaleanchor=false``
130+
)
131+
]
116132
]

0 commit comments

Comments
 (0)