Skip to content

Commit f7d24df

Browse files
committed
plotlyjs 2.27: Add insiderange to cartesian axes
1 parent 5ba77a0 commit f7d24df

File tree

7 files changed

+127
-7
lines changed

7 files changed

+127
-7
lines changed

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ type LinearAxis() =
6969
/// <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>
7070
/// <param name="TickFormatStops">Set rules for customizing TickFormat on different zoom levels</param>
7171
/// <param name="HoverFormat">Sets the hover text 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>
72+
/// <param name="InsideRange">Could be used to set the desired inside range of this axis (excluding the labels) when `ticklabelposition` of the anchored axis has "inside". Not implemented for axes with `type` "log". This would be ignored when `range` is provided.</param>
7273
/// <param name="ShowLine">Determines whether or not a line bounding this axis is drawn.</param>
7374
/// <param name="LineColor">Sets the axis line color.</param>
7475
/// <param name="LineWidth">Sets the width (in px) of the axis line.</param>
@@ -157,6 +158,7 @@ type LinearAxis() =
157158
[<Optional; DefaultParameterValue(null)>] ?TickFormat: string,
158159
[<Optional; DefaultParameterValue(null)>] ?TickFormatStops: seq<TickFormatStop>,
159160
[<Optional; DefaultParameterValue(null)>] ?HoverFormat: string,
161+
[<Optional; DefaultParameterValue(null)>] ?InsideRange: StyleParam.Range,
160162
[<Optional; DefaultParameterValue(null)>] ?ShowLine: bool,
161163
[<Optional; DefaultParameterValue(null)>] ?LineColor: Color,
162164
[<Optional; DefaultParameterValue(null)>] ?LineWidth: float,
@@ -246,6 +248,7 @@ type LinearAxis() =
246248
?TickFormat = TickFormat,
247249
?TickFormatStops = TickFormatStops,
248250
?HoverFormat = HoverFormat,
251+
?InsideRange = InsideRange,
249252
?ShowLine = ShowLine,
250253
?LineColor = LineColor,
251254
?LineWidth = LineWidth,
@@ -848,8 +851,9 @@ type LinearAxis() =
848851
/// <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>
849852
/// <param name="TickFormatStops">Set rules for customizing TickFormat on different zoom levels</param>
850853
/// <param name="HoverFormat">Sets the hover text 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>
851-
/// <param name="ShowLine">Determines whether or not a line bounding this axis is drawn.</param>
854+
/// <param name="InsideRange">Could be used to set the desired inside range of this axis (excluding the labels) when `ticklabelposition` of the anchored axis has "inside". Not implemented for axes with `type` "log". This would be ignored when `range` is provided.</param>
852855
/// <param name="LineColor">Sets the axis line color.</param>
856+
/// <param name="ShowLine">Determines whether or not a line bounding this axis is drawn.</param>
853857
/// <param name="LineWidth">Sets the width (in px) of the axis line.</param>
854858
/// <param name="ShowGrid">Determines whether or not grid lines are drawn. If "true", the grid lines are drawn at every tick mark.</param>
855859
/// <param name="GridColor">Sets the color of the grid lines.</param>
@@ -953,6 +957,7 @@ type LinearAxis() =
953957
[<Optional; DefaultParameterValue(null)>] ?TickFormat: string,
954958
[<Optional; DefaultParameterValue(null)>] ?TickFormatStops: seq<TickFormatStop>,
955959
[<Optional; DefaultParameterValue(null)>] ?HoverFormat: string,
960+
[<Optional; DefaultParameterValue(null)>] ?InsideRange: StyleParam.Range,
956961
[<Optional; DefaultParameterValue(null)>] ?ShowLine: bool,
957962
[<Optional; DefaultParameterValue(null)>] ?LineColor: Color,
958963
[<Optional; DefaultParameterValue(null)>] ?LineWidth: float,
@@ -1059,6 +1064,7 @@ type LinearAxis() =
10591064
TickFormat |> DynObj.setValueOpt axis "tickformat"
10601065
TickFormatStops |> DynObj.setValueOpt axis "tickformatstops"
10611066
HoverFormat |> DynObj.setValueOpt axis "hoverformat"
1067+
InsideRange |> DynObj.setValueOptBy axis "insiderange" StyleParam.Range.convert
10621068
ShowLine |> DynObj.setValueOpt axis "showline"
10631069
LineColor |> DynObj.setValueOpt axis "linecolor"
10641070
LineWidth |> DynObj.setValueOpt axis "linewidth"

tests/Common/FSharpTestBase/FSharpTestBase.fsproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
</ItemGroup>
1313

1414
<ItemGroup>
15+
<Compile Include="TestCharts\UpstreamFeatures\2.27.fs" />
1516
<Compile Include="TestCharts\UpstreamFeatures\2.26.fs" />
1617
<Compile Include="TestUtils.fs" />
1718
<Compile Include="TestCharts\Chart2DTestCharts.fs" />
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
module PlotlyJS_2_27_TestCharts
2+
3+
open Plotly.NET
4+
open Plotly.NET.TraceObjects
5+
open Plotly.NET.LayoutObjects
6+
7+
8+
module ``InsideRange for linear axes`` =
9+
10+
let ``Inside range for y axis`` =
11+
Chart.Line(
12+
x = [1; 2; 3; 4],
13+
y = [1; 1; 2; 3],
14+
UseDefaults = false
15+
)
16+
|> Chart.withXAxis(
17+
LinearAxis.init(
18+
Anchor = StyleParam.LinearAxisId.Y 1,
19+
Ticks = StyleParam.TickOptions.Inside,
20+
TickLabelPosition = StyleParam.TickLabelPosition.Inside
21+
)
22+
)
23+
|> Chart.withYAxis(
24+
LinearAxis.init(
25+
Anchor = StyleParam.LinearAxisId.X 1,
26+
InsideRange = StyleParam.Range.ofMinMax(1, 3)
27+
)
28+
)
29+
30+
let ``Inside range for x axis`` =
31+
Chart.Line(
32+
x = [1; 2; 3; 4],
33+
y = [1; 1; 2; 3],
34+
UseDefaults = false
35+
)
36+
|> Chart.withXAxis(
37+
LinearAxis.init(
38+
Anchor = StyleParam.LinearAxisId.Y 1,
39+
InsideRange = StyleParam.Range.ofMinMax(1, 3)
40+
)
41+
)
42+
|> Chart.withYAxis(
43+
LinearAxis.init(
44+
Anchor = StyleParam.LinearAxisId.X 1,
45+
Ticks = StyleParam.TickOptions.Inside,
46+
TickLabelPosition = StyleParam.TickLabelPosition.Inside
47+
)
48+
)

tests/ConsoleApps/FSharpConsole/Program.fs

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,41 @@ open Newtonsoft.Json
1111

1212
[<EntryPoint>]
1313
let main argv =
14-
Chart.Point([1,2], UseDefaults = false)
14+
Chart.Line(
15+
x = [1; 2; 3; 4],
16+
y = [1; 1; 2; 3],
17+
UseDefaults = false
18+
)
1519
|> Chart.withXAxis(
1620
LinearAxis.init(
17-
ScaleAnchor = StyleParam.ScaleAnchor.False
21+
Anchor = StyleParam.LinearAxisId.Y 1,
22+
Ticks = StyleParam.TickOptions.Inside,
23+
TickLabelPosition = StyleParam.TickLabelPosition.Inside
24+
)
25+
)
26+
|> Chart.withYAxis(
27+
LinearAxis.init(
28+
Anchor = StyleParam.LinearAxisId.X 1,
29+
InsideRange = StyleParam.Range.ofMinMax(1, 3)
30+
)
31+
)
32+
|> Chart.show
33+
Chart.Line(
34+
x = [1; 2; 3; 4],
35+
y = [1; 1; 2; 3],
36+
UseDefaults = false
37+
)
38+
|> Chart.withXAxis(
39+
LinearAxis.init(
40+
Anchor = StyleParam.LinearAxisId.Y 1,
41+
InsideRange = StyleParam.Range.ofMinMax(1, 3)
42+
)
43+
)
44+
|> Chart.withYAxis(
45+
LinearAxis.init(
46+
Anchor = StyleParam.LinearAxisId.X 1,
47+
Ticks = StyleParam.TickOptions.Inside,
48+
TickLabelPosition = StyleParam.TickLabelPosition.Inside
1849
)
1950
)
2051
|> Chart.show

tests/CoreTests/CoreTests/CoreTests.fsproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
<Compile Include="Traces\TraceStaticMembers.fs" />
3737
<Compile Include="Traces\TraceStyle.fs" />
3838
<Compile Include="Traces\TraceID.fs" />
39+
<Compile Include="UpstreamFeatures\2.27.fs" />
3940
<Compile Include="UpstreamFeatures\2.26.fs" />
4041
<Compile Include="UpstreamFeatures\2.25.fs" />
4142
<Compile Include="UpstreamFeatures\2.24.fs" />

tests/CoreTests/CoreTests/UpstreamFeatures/2.26.fs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,11 @@ module ``AutoRangeOptions`` =
6868
]
6969
]
7070

71-
module ``N-sigma (std deviations) box plots`` =
71+
module ``N-sigma box plots`` =
7272
[<Tests>]
7373
let ``Sigma boxplots`` =
7474
testList "UpstreamFeatures.PlotlyJS_2_26" [
75-
testList "N-sigma (std deviations) box plots" [
75+
testList "N-sigma box plots" [
7676
testCase "2-Sigma box plot data" ( fun () ->
7777
"""var data = [{"type":"box","marker":{},"line":{},"sizemode":"sd","y":[-20,1,2,3,1,2,3,3,3,3,3,1,5,20],"sdmultiple":2.0}];"""
7878
|> chartGeneratedContains ``N-sigma (std deviations) box plots``.``2-sigma BoxPlot``
@@ -83,11 +83,11 @@ module ``N-sigma (std deviations) box plots`` =
8383
]
8484
]
8585

86-
module ``New Side options for (legend) titles`` =
86+
module ``New Side options for legend titles`` =
8787
[<Tests>]
8888
let ``New Title Side options`` =
8989
testList "UpstreamFeatures.PlotlyJS_2_26" [
90-
testList "New Side options for (legend) titles" [
90+
testList "New Side options for legend titles" [
9191
testCase "top left data" ( fun () ->
9292
"""var data = [{"type":"scatter","mode":"markers","x":[1],"y":[2],"marker":{},"line":{}},{"type":"scatter","mode":"markers","x":[3],"y":[4],"marker":{},"line":{}}];"""
9393
|> chartGeneratedContains ``New Side options for (legend) titles``.``Point charts with horizontal legend title top left``
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
module CoreTests.UpstreamFeatures.PlotlyJS_2_27
2+
3+
open Expecto
4+
open Plotly.NET
5+
open Plotly.NET.LayoutObjects
6+
open Plotly.NET.TraceObjects
7+
8+
open TestUtils.HtmlCodegen
9+
open PlotlyJS_2_27_TestCharts
10+
11+
module ``InsideRange for linear axes`` =
12+
[<Tests>]
13+
let ``InsideRange for linear axes tests`` =
14+
testList "UpstreamFeatures.PlotlyJS_2_27" [
15+
testList "InsideRange for linear axes" [
16+
testCase "Inside range for x axis data" ( fun () ->
17+
"""var data = [{"type":"scatter","mode":"lines","x":[1,2,3,4],"y":[1,1,2,3],"marker":{},"line":{}}];"""
18+
|> chartGeneratedContains ``InsideRange for linear axes``.``Inside range for x axis``
19+
)
20+
testCase "Inside range for x axis layout" ( fun () ->
21+
"""var layout = {"xaxis":{"insiderange":[1,3],"anchor":"y"},"yaxis":{"ticks":"inside","ticklabelposition":"inside","anchor":"x"}};"""
22+
|> chartGeneratedContains ``InsideRange for linear axes``.``Inside range for x axis``
23+
)
24+
testCase "Inside range for y axis data" ( fun () ->
25+
"""var data = [{"type":"scatter","mode":"lines","x":[1,2,3,4],"y":[1,1,2,3],"marker":{},"line":{}}];"""
26+
|> chartGeneratedContains ``InsideRange for linear axes``.``Inside range for y axis``
27+
)
28+
testCase "Inside range for y axis layout" ( fun () ->
29+
"""var layout = {"xaxis":{"ticks":"inside","ticklabelposition":"inside","anchor":"y"},"yaxis":{"insiderange":[1,3],"anchor":"x"}};"""
30+
|> chartGeneratedContains ``InsideRange for linear axes``.``Inside range for y axis``
31+
)
32+
]
33+
]

0 commit comments

Comments
 (0)