Skip to content

Commit

Permalink
plotlyjs 2.27: Add insiderange to cartesian axes
Browse files Browse the repository at this point in the history
  • Loading branch information
kMutagene committed Dec 8, 2023
1 parent 5ba77a0 commit f7d24df
Show file tree
Hide file tree
Showing 7 changed files with 127 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ type LinearAxis() =
/// <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>
/// <param name="TickFormatStops">Set rules for customizing TickFormat on different zoom levels</param>
/// <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>
/// <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>
/// <param name="ShowLine">Determines whether or not a line bounding this axis is drawn.</param>
/// <param name="LineColor">Sets the axis line color.</param>
/// <param name="LineWidth">Sets the width (in px) of the axis line.</param>
Expand Down Expand Up @@ -157,6 +158,7 @@ type LinearAxis() =
[<Optional; DefaultParameterValue(null)>] ?TickFormat: string,
[<Optional; DefaultParameterValue(null)>] ?TickFormatStops: seq<TickFormatStop>,
[<Optional; DefaultParameterValue(null)>] ?HoverFormat: string,
[<Optional; DefaultParameterValue(null)>] ?InsideRange: StyleParam.Range,
[<Optional; DefaultParameterValue(null)>] ?ShowLine: bool,
[<Optional; DefaultParameterValue(null)>] ?LineColor: Color,
[<Optional; DefaultParameterValue(null)>] ?LineWidth: float,
Expand Down Expand Up @@ -246,6 +248,7 @@ type LinearAxis() =
?TickFormat = TickFormat,
?TickFormatStops = TickFormatStops,
?HoverFormat = HoverFormat,
?InsideRange = InsideRange,
?ShowLine = ShowLine,
?LineColor = LineColor,
?LineWidth = LineWidth,
Expand Down Expand Up @@ -848,8 +851,9 @@ type LinearAxis() =
/// <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>
/// <param name="TickFormatStops">Set rules for customizing TickFormat on different zoom levels</param>
/// <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>
/// <param name="ShowLine">Determines whether or not a line bounding this axis is drawn.</param>
/// <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>
/// <param name="LineColor">Sets the axis line color.</param>
/// <param name="ShowLine">Determines whether or not a line bounding this axis is drawn.</param>
/// <param name="LineWidth">Sets the width (in px) of the axis line.</param>
/// <param name="ShowGrid">Determines whether or not grid lines are drawn. If "true", the grid lines are drawn at every tick mark.</param>
/// <param name="GridColor">Sets the color of the grid lines.</param>
Expand Down Expand Up @@ -953,6 +957,7 @@ type LinearAxis() =
[<Optional; DefaultParameterValue(null)>] ?TickFormat: string,
[<Optional; DefaultParameterValue(null)>] ?TickFormatStops: seq<TickFormatStop>,
[<Optional; DefaultParameterValue(null)>] ?HoverFormat: string,
[<Optional; DefaultParameterValue(null)>] ?InsideRange: StyleParam.Range,
[<Optional; DefaultParameterValue(null)>] ?ShowLine: bool,
[<Optional; DefaultParameterValue(null)>] ?LineColor: Color,
[<Optional; DefaultParameterValue(null)>] ?LineWidth: float,
Expand Down Expand Up @@ -1059,6 +1064,7 @@ type LinearAxis() =
TickFormat |> DynObj.setValueOpt axis "tickformat"
TickFormatStops |> DynObj.setValueOpt axis "tickformatstops"
HoverFormat |> DynObj.setValueOpt axis "hoverformat"
InsideRange |> DynObj.setValueOptBy axis "insiderange" StyleParam.Range.convert
ShowLine |> DynObj.setValueOpt axis "showline"
LineColor |> DynObj.setValueOpt axis "linecolor"
LineWidth |> DynObj.setValueOpt axis "linewidth"
Expand Down
1 change: 1 addition & 0 deletions tests/Common/FSharpTestBase/FSharpTestBase.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
</ItemGroup>

<ItemGroup>
<Compile Include="TestCharts\UpstreamFeatures\2.27.fs" />
<Compile Include="TestCharts\UpstreamFeatures\2.26.fs" />
<Compile Include="TestUtils.fs" />
<Compile Include="TestCharts\Chart2DTestCharts.fs" />
Expand Down
48 changes: 48 additions & 0 deletions tests/Common/FSharpTestBase/TestCharts/UpstreamFeatures/2.27.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
module PlotlyJS_2_27_TestCharts

open Plotly.NET
open Plotly.NET.TraceObjects
open Plotly.NET.LayoutObjects


module ``InsideRange for linear axes`` =

let ``Inside range for y axis`` =
Chart.Line(
x = [1; 2; 3; 4],
y = [1; 1; 2; 3],
UseDefaults = false
)
|> Chart.withXAxis(
LinearAxis.init(
Anchor = StyleParam.LinearAxisId.Y 1,
Ticks = StyleParam.TickOptions.Inside,
TickLabelPosition = StyleParam.TickLabelPosition.Inside
)
)
|> Chart.withYAxis(
LinearAxis.init(
Anchor = StyleParam.LinearAxisId.X 1,
InsideRange = StyleParam.Range.ofMinMax(1, 3)
)
)

let ``Inside range for x axis`` =
Chart.Line(
x = [1; 2; 3; 4],
y = [1; 1; 2; 3],
UseDefaults = false
)
|> Chart.withXAxis(
LinearAxis.init(
Anchor = StyleParam.LinearAxisId.Y 1,
InsideRange = StyleParam.Range.ofMinMax(1, 3)
)
)
|> Chart.withYAxis(
LinearAxis.init(
Anchor = StyleParam.LinearAxisId.X 1,
Ticks = StyleParam.TickOptions.Inside,
TickLabelPosition = StyleParam.TickLabelPosition.Inside
)
)
35 changes: 33 additions & 2 deletions tests/ConsoleApps/FSharpConsole/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,41 @@ open Newtonsoft.Json

[<EntryPoint>]
let main argv =
Chart.Point([1,2], UseDefaults = false)
Chart.Line(
x = [1; 2; 3; 4],
y = [1; 1; 2; 3],
UseDefaults = false
)
|> Chart.withXAxis(
LinearAxis.init(
ScaleAnchor = StyleParam.ScaleAnchor.False
Anchor = StyleParam.LinearAxisId.Y 1,
Ticks = StyleParam.TickOptions.Inside,
TickLabelPosition = StyleParam.TickLabelPosition.Inside
)
)
|> Chart.withYAxis(
LinearAxis.init(
Anchor = StyleParam.LinearAxisId.X 1,
InsideRange = StyleParam.Range.ofMinMax(1, 3)
)
)
|> Chart.show
Chart.Line(
x = [1; 2; 3; 4],
y = [1; 1; 2; 3],
UseDefaults = false
)
|> Chart.withXAxis(
LinearAxis.init(
Anchor = StyleParam.LinearAxisId.Y 1,
InsideRange = StyleParam.Range.ofMinMax(1, 3)
)
)
|> Chart.withYAxis(
LinearAxis.init(
Anchor = StyleParam.LinearAxisId.X 1,
Ticks = StyleParam.TickOptions.Inside,
TickLabelPosition = StyleParam.TickLabelPosition.Inside
)
)
|> Chart.show
Expand Down
1 change: 1 addition & 0 deletions tests/CoreTests/CoreTests/CoreTests.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
<Compile Include="Traces\TraceStaticMembers.fs" />
<Compile Include="Traces\TraceStyle.fs" />
<Compile Include="Traces\TraceID.fs" />
<Compile Include="UpstreamFeatures\2.27.fs" />
<Compile Include="UpstreamFeatures\2.26.fs" />
<Compile Include="UpstreamFeatures\2.25.fs" />
<Compile Include="UpstreamFeatures\2.24.fs" />
Expand Down
8 changes: 4 additions & 4 deletions tests/CoreTests/CoreTests/UpstreamFeatures/2.26.fs
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,11 @@ module ``AutoRangeOptions`` =
]
]

module ``N-sigma (std deviations) box plots`` =
module ``N-sigma box plots`` =
[<Tests>]
let ``Sigma boxplots`` =
testList "UpstreamFeatures.PlotlyJS_2_26" [
testList "N-sigma (std deviations) box plots" [
testList "N-sigma box plots" [
testCase "2-Sigma box plot data" ( fun () ->
"""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}];"""
|> chartGeneratedContains ``N-sigma (std deviations) box plots``.``2-sigma BoxPlot``
Expand All @@ -83,11 +83,11 @@ module ``N-sigma (std deviations) box plots`` =
]
]

module ``New Side options for (legend) titles`` =
module ``New Side options for legend titles`` =
[<Tests>]
let ``New Title Side options`` =
testList "UpstreamFeatures.PlotlyJS_2_26" [
testList "New Side options for (legend) titles" [
testList "New Side options for legend titles" [
testCase "top left data" ( fun () ->
"""var data = [{"type":"scatter","mode":"markers","x":[1],"y":[2],"marker":{},"line":{}},{"type":"scatter","mode":"markers","x":[3],"y":[4],"marker":{},"line":{}}];"""
|> chartGeneratedContains ``New Side options for (legend) titles``.``Point charts with horizontal legend title top left``
Expand Down
33 changes: 33 additions & 0 deletions tests/CoreTests/CoreTests/UpstreamFeatures/2.27.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
module CoreTests.UpstreamFeatures.PlotlyJS_2_27

open Expecto
open Plotly.NET
open Plotly.NET.LayoutObjects
open Plotly.NET.TraceObjects

open TestUtils.HtmlCodegen
open PlotlyJS_2_27_TestCharts

module ``InsideRange for linear axes`` =
[<Tests>]
let ``InsideRange for linear axes tests`` =
testList "UpstreamFeatures.PlotlyJS_2_27" [
testList "InsideRange for linear axes" [
testCase "Inside range for x axis data" ( fun () ->
"""var data = [{"type":"scatter","mode":"lines","x":[1,2,3,4],"y":[1,1,2,3],"marker":{},"line":{}}];"""
|> chartGeneratedContains ``InsideRange for linear axes``.``Inside range for x axis``
)
testCase "Inside range for x axis layout" ( fun () ->
"""var layout = {"xaxis":{"insiderange":[1,3],"anchor":"y"},"yaxis":{"ticks":"inside","ticklabelposition":"inside","anchor":"x"}};"""
|> chartGeneratedContains ``InsideRange for linear axes``.``Inside range for x axis``
)
testCase "Inside range for y axis data" ( fun () ->
"""var data = [{"type":"scatter","mode":"lines","x":[1,2,3,4],"y":[1,1,2,3],"marker":{},"line":{}}];"""
|> chartGeneratedContains ``InsideRange for linear axes``.``Inside range for y axis``
)
testCase "Inside range for y axis layout" ( fun () ->
"""var layout = {"xaxis":{"ticks":"inside","ticklabelposition":"inside","anchor":"y"},"yaxis":{"insiderange":[1,3],"anchor":"x"}};"""
|> chartGeneratedContains ``InsideRange for linear axes``.``Inside range for y axis``
)
]
]

0 comments on commit f7d24df

Please sign in to comment.