Skip to content

Commit 7ed80eb

Browse files
committed
plotlyjs v2.12.0: Implement various options to position and style minor ticks and grid lines on cartesian axis types (plotly/plotly.js#6166)
1 parent 6711ecf commit 7ed80eb

File tree

3 files changed

+119
-0
lines changed

3 files changed

+119
-0
lines changed

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

+9
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ type LinearAxis() =
6060
/// <param name="ShowExponent">If "all", all exponents are shown besides their significands. If "first", only the exponent of the first tick is shown. If "last", only the exponent of the last tick is shown. If "none", no exponents appear.</param>
6161
/// <param name="ExponentFormat">Determines a formatting rule for the tick exponents. For example, consider the number 1,000,000,000. If "none", it appears as 1,000,000,000. If "e", 1e+9. If "E", 1E+9. If "power", 1x10^9 (with 9 in a super script). If "SI", 1G. If "B", 1B.</param>
6262
/// <param name="MinExponent">Hide SI prefix for 10^n if |n| is below this number. This only has an effect when `TickFormat` is "SI" or "B".</param>
63+
/// <param name="Minor">Holds various parameters to style minor ticks on this axis.</param>
6364
/// <param name="SeparateThousands">If "true", even 4-digit integers are separated</param>
6465
/// <param name="TickFormat">Sets the tick label formatting rule using d3 formatting mini-languages which are very similar to those in Python. For numbers, see: https://github.com/d3/d3-3.x-api-reference/blob/master/Formatting.md#d3_format. And for dates see: https://github.com/d3/d3-time-format#locale_format. We add two items to d3's date formatter: "%h" for half of the year as a decimal number as well as "%{n}f" for fractional seconds with n digits. For example, "2016-10-13 09:15:23.456" with TickFormat "%H~%M~%S.%2f" would display "09~15~23.46"</param>
6566
/// <param name="TickFormatStops">Set rules for customizing TickFormat on different zoom levels</param>
@@ -141,6 +142,7 @@ type LinearAxis() =
141142
[<Optional; DefaultParameterValue(null)>] ?ShowExponent: StyleParam.ShowExponent,
142143
[<Optional; DefaultParameterValue(null)>] ?ExponentFormat: StyleParam.ExponentFormat,
143144
[<Optional; DefaultParameterValue(null)>] ?MinExponent: float,
145+
[<Optional; DefaultParameterValue(null)>] ?Minor: Minor,
144146
[<Optional; DefaultParameterValue(null)>] ?SeparateThousands: bool,
145147
[<Optional; DefaultParameterValue(null)>] ?TickFormat: string,
146148
[<Optional; DefaultParameterValue(null)>] ?TickFormatStops: seq<TickFormatStop>,
@@ -223,6 +225,7 @@ type LinearAxis() =
223225
?ShowExponent = ShowExponent,
224226
?ExponentFormat = ExponentFormat,
225227
?MinExponent = MinExponent,
228+
?Minor = Minor,
226229
?SeparateThousands = SeparateThousands,
227230
?TickFormat = TickFormat,
228231
?TickFormatStops = TickFormatStops,
@@ -306,6 +309,7 @@ type LinearAxis() =
306309
/// <param name="ShowExponent">If "all", all exponents are shown besides their significands. If "first", only the exponent of the first tick is shown. If "last", only the exponent of the last tick is shown. If "none", no exponents appear.</param>
307310
/// <param name="ExponentFormat">Determines a formatting rule for the tick exponents. For example, consider the number 1,000,000,000. If "none", it appears as 1,000,000,000. If "e", 1e+9. If "E", 1E+9. If "power", 1x10^9 (with 9 in a super script). If "SI", 1G. If "B", 1B.</param>
308311
/// <param name="MinExponent">Hide SI prefix for 10^n if |n| is below this number. This only has an effect when `TickFormat` is "SI" or "B".</param>
312+
/// <param name="Minor">Holds various parameters to style minor ticks on this axis.</param>
309313
/// <param name="SeparateThousands">If "true", even 4-digit integers are separated</param>
310314
/// <param name="TickFormat">Sets the tick label formatting rule using d3 formatting mini-languages which are very similar to those in Python. For numbers, see: https://github.com/d3/d3-3.x-api-reference/blob/master/Formatting.md#d3_format. And for dates see: https://github.com/d3/d3-time-format#locale_format. We add two items to d3's date formatter: "%h" for half of the year as a decimal number as well as "%{n}f" for fractional seconds with n digits. For example, "2016-10-13 09:15:23.456" with TickFormat "%H~%M~%S.%2f" would display "09~15~23.46"</param>
311315
/// <param name="TickFormatStops">Set rules for customizing TickFormat on different zoom levels</param>
@@ -383,6 +387,7 @@ type LinearAxis() =
383387
[<Optional; DefaultParameterValue(null)>] ?ShowExponent: StyleParam.ShowExponent,
384388
[<Optional; DefaultParameterValue(null)>] ?ExponentFormat: StyleParam.ExponentFormat,
385389
[<Optional; DefaultParameterValue(null)>] ?MinExponent: float,
390+
[<Optional; DefaultParameterValue(null)>] ?Minor: Minor,
386391
[<Optional; DefaultParameterValue(null)>] ?SeparateThousands: bool,
387392
[<Optional; DefaultParameterValue(null)>] ?TickFormat: string,
388393
[<Optional; DefaultParameterValue(null)>] ?TickFormatStops: seq<TickFormatStop>,
@@ -462,6 +467,7 @@ type LinearAxis() =
462467
?ShowExponent = ShowExponent,
463468
?ExponentFormat = ExponentFormat,
464469
?MinExponent = MinExponent,
470+
?Minor = Minor,
465471
?SeparateThousands = SeparateThousands,
466472
?TickFormat = TickFormat,
467473
?TickFormatStops = TickFormatStops,
@@ -800,6 +806,7 @@ type LinearAxis() =
800806
/// <param name="ShowExponent">If "all", all exponents are shown besides their significands. If "first", only the exponent of the first tick is shown. If "last", only the exponent of the last tick is shown. If "none", no exponents appear.</param>
801807
/// <param name="ExponentFormat">Determines a formatting rule for the tick exponents. For example, consider the number 1,000,000,000. If "none", it appears as 1,000,000,000. If "e", 1e+9. If "E", 1E+9. If "power", 1x10^9 (with 9 in a super script). If "SI", 1G. If "B", 1B.</param>
802808
/// <param name="MinExponent">Hide SI prefix for 10^n if |n| is below this number. This only has an effect when `TickFormat` is "SI" or "B".</param>
809+
/// <param name="Minor">Holds various parameters to style minor ticks on this axis.</param>
803810
/// <param name="SeparateThousands">If "true", even 4-digit integers are separated</param>
804811
/// <param name="TickFormat">Sets the tick label formatting rule using d3 formatting mini-languages which are very similar to those in Python. For numbers, see: https://github.com/d3/d3-3.x-api-reference/blob/master/Formatting.md#d3_format. And for dates see: https://github.com/d3/d3-time-format#locale_format. We add two items to d3's date formatter: "%h" for half of the year as a decimal number as well as "%{n}f" for fractional seconds with n digits. For example, "2016-10-13 09:15:23.456" with TickFormat "%H~%M~%S.%2f" would display "09~15~23.46"</param>
805812
/// <param name="TickFormatStops">Set rules for customizing TickFormat on different zoom levels</param>
@@ -898,6 +905,7 @@ type LinearAxis() =
898905
[<Optional; DefaultParameterValue(null)>] ?ShowExponent: StyleParam.ShowExponent,
899906
[<Optional; DefaultParameterValue(null)>] ?ExponentFormat: StyleParam.ExponentFormat,
900907
[<Optional; DefaultParameterValue(null)>] ?MinExponent: float,
908+
[<Optional; DefaultParameterValue(null)>] ?Minor: Minor,
901909
[<Optional; DefaultParameterValue(null)>] ?SeparateThousands: bool,
902910
[<Optional; DefaultParameterValue(null)>] ?TickFormat: string,
903911
[<Optional; DefaultParameterValue(null)>] ?TickFormatStops: seq<TickFormatStop>,
@@ -997,6 +1005,7 @@ type LinearAxis() =
9971005
ShowExponent |> DynObj.setValueOptBy axis "showexponent" StyleParam.ShowExponent.convert
9981006
ExponentFormat |> DynObj.setValueOptBy axis "exponentformat" StyleParam.ExponentFormat.convert
9991007
MinExponent |> DynObj.setValueOpt axis "minexponent"
1008+
Minor |> DynObj.setValueOpt axis "minor"
10001009
SeparateThousands |> DynObj.setValueOpt axis "separatethousands"
10011010
TickFormat |> DynObj.setValueOpt axis "tickformat"
10021011
TickFormatStops |> DynObj.setValueOpt axis "tickformatstops"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
namespace Plotly.NET.LayoutObjects
2+
3+
open Plotly.NET
4+
open DynamicObj
5+
open System
6+
open System.Runtime.InteropServices
7+
8+
///<summary>The Minor object holds various parameters to style minor ticks on cartesian axes</summary>
9+
type Minor() =
10+
inherit DynamicObj()
11+
12+
/// <summary>
13+
/// Initialize a Minor object that holds various parameters to style minor ticks on cartesian axes.
14+
/// </summary>
15+
/// <param name="DTick">Sets the step in-between ticks on this axis. Use with `tick0`. Must be a positive number, or special strings available to "log" and "date" axes. If the axis `type` is "log", then ticks are set every 10^(n"dtick) where n is the tick number. For example, to set a tick mark at 1, 10, 100, 1000, ... set dtick to 1. To set tick marks at 1, 100, 10000, ... set dtick to 2. To set tick marks at 1, 5, 25, 125, 625, 3125, ... set dtick to log_10(5), or 0.69897000433. "log" has several special values; "L&lt;f&gt;", where `f` is a positive number, gives ticks linearly spaced in value (but not position). For example `tick0` = 0.1, `dtick` = "L0.5" will put ticks at 0.1, 0.6, 1.1, 1.6 etc. To show powers of 10 plus small digits between, use "D1" (all digits) or "D2" (only 2 and 5). `tick0` is ignored for "D1" and "D2". If the axis `type` is "date", then you must convert the time to milliseconds. For example, to set the interval between ticks to one day, set `dtick` to 86400000.0. "date" also has special values "M&lt;n&gt;" gives ticks spaced by a number of months. `n` must be a positive integer. To set ticks on the 15th of every third month, set `tick0` to "2000-01-15" and `dtick` to "M3". To set ticks every 4 years, set `dtick` to "M48"</param>
16+
/// <param name="GridColor">Sets the color of the grid lines.</param
17+
/// <param name="GridDash">Sets the dash style of lines. Set to a dash type string ("solid", "dot", "dash", "longdash", "dashdot", or "longdashdot") or a dash length list in px (eg "5px,10px,2px,2px").</param
18+
/// <param name="GridWidth">Sets the width (in px) of the grid lines.</param
19+
/// <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
20+
/// <param name="ShowGrid">Determines whether or not grid lines are drawn. If "true", the grid lines are drawn at every tick mark.</param
21+
/// <param name="Tick0">Sets the placement of the first tick on this axis. Use with `dtick`. If the axis `type` is "log", then you must take the log of your starting tick (e.g. to set the starting tick to 100, set the `tick0` to 2) except when `dtick`="L&lt;f&gt;" (see `dtick` for more info). If the axis `type` is "date", it should be a date string, like date data. If the axis `type` is "category", it should be a number, using the scale where each category is assigned a serial number from zero in the order it appears.</param>
22+
/// <param name="TickColor">Sets the tick color.</param
23+
/// <param name="TickLen">Sets the tick length (in px).</param
24+
/// <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
25+
/// <param name="Ticks">Determines whether ticks are drawn or not. If "", this axis' ticks are not drawn. If "outside" ("inside"), this axis' are drawn outside (inside) the axis lines.</param
26+
/// <param name="TickVals">Sets the values at which ticks on this axis appear. Only has an effect if `tickmode` is set to "array". Used with `ticktext`.</param
27+
/// <param name="TickWidth">Sets the tick width (in px).</param
28+
static member init
29+
(
30+
[<Optional; DefaultParameterValue(null)>] ?DTick: #IConvertible,
31+
[<Optional; DefaultParameterValue(null)>] ?GridColor: Color,
32+
[<Optional; DefaultParameterValue(null)>] ?GridDash: StyleParam.DrawingStyle,
33+
[<Optional; DefaultParameterValue(null)>] ?GridWidth: float,
34+
[<Optional; DefaultParameterValue(null)>] ?NTicks: int,
35+
[<Optional; DefaultParameterValue(null)>] ?ShowGrid: bool,
36+
[<Optional; DefaultParameterValue(null)>] ?Tick0: #IConvertible,
37+
[<Optional; DefaultParameterValue(null)>] ?TickColor: Color,
38+
[<Optional; DefaultParameterValue(null)>] ?TickLen: int,
39+
[<Optional; DefaultParameterValue(null)>] ?TickMode: StyleParam.TickMode,
40+
[<Optional; DefaultParameterValue(null)>] ?Ticks: StyleParam.TickOptions,
41+
[<Optional; DefaultParameterValue(null)>] ?TickVals: seq<#IConvertible>,
42+
[<Optional; DefaultParameterValue(null)>] ?TickWidth: int
43+
) =
44+
Minor()
45+
|> Minor.style (
46+
?DTick = DTick,
47+
?GridColor = GridColor,
48+
?GridDash = GridDash,
49+
?GridWidth = GridWidth,
50+
?NTicks = NTicks,
51+
?ShowGrid = ShowGrid,
52+
?Tick0 = Tick0,
53+
?TickColor = TickColor,
54+
?TickLen = TickLen,
55+
?TickMode = TickMode,
56+
?Ticks = Ticks,
57+
?TickVals = TickVals,
58+
?TickWidth = TickWidth
59+
)
60+
61+
/// <summary>
62+
/// Creates a function that applies the given style parameters to a Minor object
63+
/// </summary>
64+
/// <param name="DTick">Sets the step in-between ticks on this axis. Use with `tick0`. Must be a positive number, or special strings available to "log" and "date" axes. If the axis `type` is "log", then ticks are set every 10^(n"dtick) where n is the tick number. For example, to set a tick mark at 1, 10, 100, 1000, ... set dtick to 1. To set tick marks at 1, 100, 10000, ... set dtick to 2. To set tick marks at 1, 5, 25, 125, 625, 3125, ... set dtick to log_10(5), or 0.69897000433. "log" has several special values; "L&lt;f&gt;", where `f` is a positive number, gives ticks linearly spaced in value (but not position). For example `tick0` = 0.1, `dtick` = "L0.5" will put ticks at 0.1, 0.6, 1.1, 1.6 etc. To show powers of 10 plus small digits between, use "D1" (all digits) or "D2" (only 2 and 5). `tick0` is ignored for "D1" and "D2". If the axis `type` is "date", then you must convert the time to milliseconds. For example, to set the interval between ticks to one day, set `dtick` to 86400000.0. "date" also has special values "M&lt;n&gt;" gives ticks spaced by a number of months. `n` must be a positive integer. To set ticks on the 15th of every third month, set `tick0` to "2000-01-15" and `dtick` to "M3". To set ticks every 4 years, set `dtick` to "M48"</param>
65+
/// <param name="GridColor">Sets the color of the grid lines.</param
66+
/// <param name="GridDash">Sets the dash style of lines. Set to a dash type string ("solid", "dot", "dash", "longdash", "dashdot", or "longdashdot") or a dash length list in px (eg "5px,10px,2px,2px").</param
67+
/// <param name="GridWidth">Sets the width (in px) of the grid lines.</param
68+
/// <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
69+
/// <param name="ShowGrid">Determines whether or not grid lines are drawn. If "true", the grid lines are drawn at every tick mark.</param
70+
/// <param name="Tick0">Sets the placement of the first tick on this axis. Use with `dtick`. If the axis `type` is "log", then you must take the log of your starting tick (e.g. to set the starting tick to 100, set the `tick0` to 2) except when `dtick`="L&lt;f&gt;" (see `dtick` for more info). If the axis `type` is "date", it should be a date string, like date data. If the axis `type` is "category", it should be a number, using the scale where each category is assigned a serial number from zero in the order it appears.</param>
71+
/// <param name="TickColor">Sets the tick color.</param
72+
/// <param name="TickLen">Sets the tick length (in px).</param
73+
/// <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
74+
/// <param name="Ticks">Determines whether ticks are drawn or not. If "", this axis' ticks are not drawn. If "outside" ("inside"), this axis' are drawn outside (inside) the axis lines.</param
75+
/// <param name="TickVals">Sets the values at which ticks on this axis appear. Only has an effect if `tickmode` is set to "array". Used with `ticktext`.</param
76+
/// <param name="TickWidth">Sets the tick width (in px).</param
77+
static member style
78+
(
79+
[<Optional; DefaultParameterValue(null)>] ?DTick: #IConvertible,
80+
[<Optional; DefaultParameterValue(null)>] ?GridColor: Color,
81+
[<Optional; DefaultParameterValue(null)>] ?GridDash: StyleParam.DrawingStyle,
82+
[<Optional; DefaultParameterValue(null)>] ?GridWidth: float,
83+
[<Optional; DefaultParameterValue(null)>] ?NTicks: int,
84+
[<Optional; DefaultParameterValue(null)>] ?ShowGrid: bool,
85+
[<Optional; DefaultParameterValue(null)>] ?Tick0: #IConvertible,
86+
[<Optional; DefaultParameterValue(null)>] ?TickColor: Color,
87+
[<Optional; DefaultParameterValue(null)>] ?TickLen: int,
88+
[<Optional; DefaultParameterValue(null)>] ?TickMode: StyleParam.TickMode,
89+
[<Optional; DefaultParameterValue(null)>] ?Ticks: StyleParam.TickOptions,
90+
[<Optional; DefaultParameterValue(null)>] ?TickVals: seq<#IConvertible>,
91+
[<Optional; DefaultParameterValue(null)>] ?TickWidth: int
92+
) =
93+
(fun (minor: Minor) ->
94+
95+
DTick |> DynObj.setValueOpt minor "dtick"
96+
GridColor |> DynObj.setValueOpt minor "gridcolor"
97+
GridDash |> DynObj.setValueOptBy minor "griddash" StyleParam.DrawingStyle.convert
98+
GridWidth |> DynObj.setValueOpt minor "gridwidth"
99+
NTicks |> DynObj.setValueOpt minor "nticks"
100+
ShowGrid |> DynObj.setValueOpt minor "showgrid"
101+
Tick0 |> DynObj.setValueOpt minor "tick0"
102+
TickColor |> DynObj.setValueOpt minor "tickcolor"
103+
TickLen |> DynObj.setValueOpt minor "ticklen"
104+
TickMode |> DynObj.setValueOptBy minor "tickmode" StyleParam.TickMode.convert
105+
Ticks |> DynObj.setValueOptBy minor "ticks" StyleParam.TickOptions.convert
106+
TickVals |> DynObj.setValueOpt minor "tickvals"
107+
TickWidth |> DynObj.setValueOpt minor "tickwidth"
108+
109+
minor)

src/Plotly.NET/Plotly.NET.fsproj

+1
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
<Compile Include="Layout\ObjectAbstractions\Common\LayoutGrid.fs" />
6565
<Compile Include="Layout\ObjectAbstractions\Common\Legend.fs" />
6666
<Compile Include="Layout\ObjectAbstractions\Common\Rangebreak.fs" />
67+
<Compile Include="Layout\ObjectAbstractions\Common\Minor.fs" />
6768
<Compile Include="Layout\ObjectAbstractions\Common\LinearAxis.fs" />
6869
<Compile Include="Layout\ObjectAbstractions\Common\ColorAxis.fs" />
6970
<Compile Include="Layout\ObjectAbstractions\Common\UpdateMenu.fs" />

0 commit comments

Comments
 (0)