Skip to content

Commit

Permalink
fix #426:
Browse files Browse the repository at this point in the history
- Add more direct contours styling options to Chart.Contour and Histogram2DContour
- Add all these settings to Chart.PointDensity as well to style the contours part of that plot
- add tests and adapt existing ones
- reflect API changes on Plotly.NET.CSharp (note that these should be re-generated soon)
  • Loading branch information
kMutagene committed Jan 3, 2024
1 parent bf30212 commit fe740ec
Show file tree
Hide file tree
Showing 12 changed files with 450 additions and 226 deletions.
30 changes: 15 additions & 15 deletions src/Plotly.NET.CSharp/ChartAPI/Chart2D.cs
Expand Up @@ -1961,10 +1961,10 @@ IEnumerable<TLabel> labels
YBinGroup: YBinGroup.ToOption(),
YBins: YBins.ToOption(),
Marker: Marker.ToOption(),
ContourLineColor: ContourLineColor.ToOption(),
ContourLineDash: ContourLineDash.ToOption(),
ContourLineSmoothing: ContourLineSmoothing.ToOption(),
ContourLine: ContourLine.ToOption(),
ContourLinesColor: ContourLineColor.ToOption(),
ContourLinesDash: ContourLineDash.ToOption(),
ContourLinesSmoothing: ContourLineSmoothing.ToOption(),
ContourLines: ContourLine.ToOption(),
ColorBar: ColorBar.ToOption(),
ColorScale: ColorScale.ToOption(),
ShowScale: ShowScale.ToOption(),
Expand Down Expand Up @@ -2246,15 +2246,15 @@ IEnumerable<TLabel> labels
ShowScale: ShowScale.ToOption(),
ReverseScale: ReverseScale.ToOption(),
Transpose: Transpose.ToOption(),
ContourLineColor: ContourLineColor.ToOption(),
ContourLineDash: ContourLineDash.ToOption(),
ContourLineSmoothing: ContourLineSmoothing.ToOption(),
ContourLine: ContourLine.ToOption(),
ContourLinesColor: ContourLineColor.ToOption(),
ContourLinesDash: ContourLineDash.ToOption(),
ContourLinesSmoothing: ContourLineSmoothing.ToOption(),
ContourLines: ContourLine.ToOption(),
ContoursColoring: ContoursColoring.ToOption(),
ContoursOperation: ContoursOperation.ToOption(),
ContoursType: ContoursType.ToOption(),
ShowContourLabels: ShowContourLabels.ToOption(),
ContourLabelFont: ContourLabelFont.ToOption(),
ShowContoursLabels: ShowContourLabels.ToOption(),
ContoursLabelFont: ContourLabelFont.ToOption(),
Contours: Contours.ToOption(),
FillColor: FillColor.ToOption(),
NContours: NContours.ToOption(),
Expand Down Expand Up @@ -2512,12 +2512,12 @@ IEnumerable<TLabel> labels
PointMarkerColor: PointMarkerColor.ToOption(),
PointMarkerSymbol: PointMarkerSymbol.ToOption(),
PointMarkerSize: PointMarkerSize.ToOption(),
ContourLineColor: ContourLineColor.ToOption(),
ContourLineSmoothing: ContourLineSmoothing.ToOption(),
ContourLineWidth: ContourLineWidth.ToOption(),
ContourLinesColor: ContourLineColor.ToOption(),
ContourLinesSmoothing: ContourLineSmoothing.ToOption(),
ContourLinesWidth: ContourLineWidth.ToOption(),
ShowContourLines: ShowContourLines.ToOption(),
ShowContourLabels: ShowContourLabels.ToOption(),
ContourColoring: ContourColoring.ToOption(),
ShowContoursLabels: ShowContourLabels.ToOption(),
ContoursColoring: ContourColoring.ToOption(),
NContours: NContours.ToOption(),
HistNorm: HistNorm.ToOption(),
ContourOpacity: ContourOpacity.ToOption(),
Expand Down
432 changes: 270 additions & 162 deletions src/Plotly.NET/ChartAPI/Chart2D.fs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/Plotly.NET/RELEASE_NOTES.md
Expand Up @@ -21,7 +21,7 @@
- [Add "top left" & "top center" side options to legend title](https://github.com/plotly/Plotly.NET/commit/bebe507963c4af2a37ec6ad5afd960e1543c161a)
- [Add "false" option to scaleanchor](https://github.com/plotly/Plotly.NET/commit/bad6d531501e37f27b16b11bf83d8711640a7605)
- v2.27:
- []()
- [Add insiderange to cartesian axes](https://github.com/plotly/Plotly.NET/commit/f7d24df0e76130a323c52f8f4d57cdbe8622d241)

- [Plotly.NET.ImageExport (4.0.0 -> 5.0.0)](https://github.com/plotly/Plotly.NET/blob/dev/src/Plotly.NET.ImageExport/RELEASE_NOTES.md)
- [Plotly.NET.Interactive (4.1.0 -> 4.2.0)](https://github.com/plotly/Plotly.NET/blob/dev/src/Plotly.NET.Interactive/RELEASE_NOTES.md)
Expand Down
1 change: 1 addition & 0 deletions tests/Common/FSharpTestBase/FSharpTestBase.fsproj
Expand Up @@ -12,6 +12,7 @@
</ItemGroup>

<ItemGroup>
<Compile Include="TestCharts\FeatureAdditions\Accessible_Contours.fs" />
<Compile Include="TestCharts\UpstreamFeatures\2.27.fs" />
<Compile Include="TestCharts\UpstreamFeatures\2.26.fs" />
<Compile Include="TestUtils.fs" />
Expand Down
4 changes: 2 additions & 2 deletions tests/Common/FSharpTestBase/TestCharts/Chart2DTestCharts.fs
Expand Up @@ -283,7 +283,7 @@ module Histogram2DContour =
let x = Array.init n (fun i -> ((step i)**3.) + (0.3 * (normal (rnd) 0. 2.) ))
let y = Array.init n (fun i -> ((step i)**6.) + (0.3 * (normal (rnd) 0. 2.) ))
[
Chart.Histogram2DContour (x = x, y = y,ContourLine=Line.init(Width=0.), UseDefaults = false)
Chart.Histogram2DContour (x = x, y = y,ContourLines=Line.init(Width=0.), UseDefaults = false)
Chart.Point(x = x,y = y,Opacity=0.3, UseDefaults = false)
]
|> Chart.combine
Expand Down Expand Up @@ -476,6 +476,6 @@ module PointDensity =
PointMarkerSize = 4,
ColorScale = StyleParam.Colorscale.Viridis,
ColorBar = ColorBar.init(Title = Title.init("Density")),
ShowContourLabels = true,
ShowContoursLabels = true,
UseDefaults = false
)
@@ -0,0 +1,96 @@
module Accessible_Contrours_TestCharts

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

// https://github.com/plotly/Plotly.NET/issues/426

module ``Contours should be accessible #426`` =

let ``Contour chart with more contours settings`` =
// max z is 10
Chart.Contour(
zData = [
[5;2;3]
[10;2;1]
[0;5;1]
],
ShowContoursLabels = true,
ShowContourLines = true,
ContoursStart = 0,
ContoursEnd = 15,
UseDefaults = false
)
|> Chart.withColorAxisAnchor(1)


let ``Histogram2DContour chart with more contours settings`` =
// max z is 5
Chart.Histogram2DContour(
X = [1;1;2;2;2;2;2;3;4;5],
Y = [1;1;2;2;2;2;2;3;4;5],
ShowContoursLabels = true,
ShowContourLines = true,
ContoursStart = 0,
ContoursEnd = 15,
UseDefaults = false
)
|> Chart.withColorAxisAnchor(1)


let ``PointDensity chart with accessible contours settings`` =
// max z is 15
Chart.PointDensity(
x = [1;1;2;2;2;2;2;2;2;2;2;2;2;2;2;2;2;3;4;5],
y = [1;1;2;2;2;2;2;2;2;2;2;2;2;2;2;2;2;3;4;5],
ShowContoursLabels = true,
ShowContourLines = true,
ContoursStart = 0,
ContoursEnd = 15,
UseDefaults = false
)
|> Chart.withColorAxisAnchor(1)

let ``Contours trace Grid chart with shared color axis and adapted contours ranges`` =
[
// max z is 10
Chart.Contour(
zData = [
[5;2;3]
[10;2;1]
[0;5;1]
],
ShowContoursLabels = true,
ShowContourLines = true,
ContoursStart = 0,
ContoursEnd = 15,
UseDefaults = false
)
|> Chart.withColorAxisAnchor(1)

// max z is 5
Chart.Histogram2DContour(
X = [1;1;2;2;2;2;2;3;4;5],
Y = [1;1;2;2;2;2;2;3;4;5],
ShowContoursLabels = true,
ShowContourLines = true,
ContoursStart = 0,
ContoursEnd = 15,
UseDefaults = false
)
|> Chart.withColorAxisAnchor(1)

// max z is 15
Chart.PointDensity(
x = [1;1;2;2;2;2;2;2;2;2;2;2;2;2;2;2;2;3;4;5],
y = [1;1;2;2;2;2;2;2;2;2;2;2;2;2;2;2;2;3;4;5],
ShowContoursLabels = true,
ShowContourLines = true,
ContoursStart = 0,
ContoursEnd = 15,
UseDefaults = false
)
|> Chart.withColorAxisAnchor(1)
]
|> Chart.Grid(2,2)
41 changes: 6 additions & 35 deletions tests/ConsoleApps/FSharpConsole/Program.fs
Expand Up @@ -9,44 +9,15 @@ open DynamicObj
open Giraffe.ViewEngine
open Newtonsoft.Json

let getZeroCollection n : float []=
Array.zeroCreate n

[<EntryPoint>]
let main argv =
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)
)
)
|> Chart.show
Chart.Line(
x = [1; 2; 3; 4],
y = [1; 1; 2; 3],
Chart.Histogram2DContour(
MultiX = [["A";"A";"A";"B";"B"];["AA"; "AA"; "AB"; "BA"; "BB"]],
MultiY = [["A";"A";"A";"B";"B"];["AA"; "AA"; "AB"; "BA"; "BB"]],
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
0
1 change: 1 addition & 0 deletions tests/CoreTests/CoreTests/CoreTests.fsproj
Expand Up @@ -45,6 +45,7 @@
<Compile Include="UpstreamFeatures\2.21.fs" />
<Compile Include="UpstreamFeatures\2.20.fs" />
<Compile Include="UpstreamFeatures\2.19.fs" />
<Compile Include="FeatureAdditions\Accessible_Contours.fs" />
<Compile Include="Main.fs" />
</ItemGroup>

Expand Down
47 changes: 47 additions & 0 deletions tests/CoreTests/CoreTests/FeatureAdditions/Accessible_Contours.fs
@@ -0,0 +1,47 @@
// https://github.com/plotly/Plotly.NET/issues/426

module CoreTests.Accessible_Contours

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

open TestUtils.HtmlCodegen
open Accessible_Contrours_TestCharts

module ``Contours should be accessible #426`` =

[<Tests>]
let ``Contours should be accessible #426`` =
testList "FeatureAddition.Contours should be accessible" [
test "more contours settings on Contour data" {
"""var data = [{"type":"contour","z":[[5,2,3],[10,2,1],[0,5,1]],"line":{"width":0.0},"contours":{"end":15.0,"showlabels":true,"start":0.0},"coloraxis":"coloraxis"}];"""
|> chartGeneratedContains ``Contours should be accessible #426``.``Contour chart with more contours settings``
}
test "more contours settings on Contour layout" {
emptyLayout ``Contours should be accessible #426``.``Contour chart with more contours settings``
}
test "more contours settings on Histogram2DContour data" {
"""var data = [{"type":"histogram2dcontour","x":[1,1,2,2,2,2,2,3,4,5],"y":[1,1,2,2,2,2,2,3,4,5],"line":{"width":0.0},"contours":{"end":15.0,"showlabels":true,"start":0.0},"coloraxis":"coloraxis"}];"""
|> chartGeneratedContains ``Contours should be accessible #426``.``Histogram2DContour chart with more contours settings``
}
test "more contours settings on Histogram2DContour layout" {
emptyLayout ``Contours should be accessible #426``.``Histogram2DContour chart with more contours settings``
}
test "Accessible contours settings on PointDensity data" {
"""var data = [{"type":"histogram2dcontour","x":[1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,3,4,5],"y":[1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,3,4,5],"line":{"width":0.0},"contours":{"coloring":"fill","end":15.0,"showlabels":true,"start":0.0},"coloraxis":"coloraxis"},{"type":"scatter","opacity":0.3,"mode":"markers","x":[1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,3,4,5],"y":[1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,3,4,5],"marker":{},"coloraxis":"coloraxis"}];"""
|> chartGeneratedContains ``Contours should be accessible #426``.``PointDensity chart with accessible contours settings``
}
test "Accessible contours settings on PointDensity layout" {
emptyLayout ``Contours should be accessible #426``.``PointDensity chart with accessible contours settings``
}
test "Chart Grid with shared color axis and corrected contours ranges data" {
"""var data = [{"type":"contour","z":[[5,2,3],[10,2,1],[0,5,1]],"line":{"width":0.0},"contours":{"end":15.0,"showlabels":true,"start":0.0},"coloraxis":"coloraxis","xaxis":"x","yaxis":"y"},{"type":"histogram2dcontour","x":[1,1,2,2,2,2,2,3,4,5],"y":[1,1,2,2,2,2,2,3,4,5],"line":{"width":0.0},"contours":{"end":15.0,"showlabels":true,"start":0.0},"coloraxis":"coloraxis","xaxis":"x2","yaxis":"y2"},{"type":"histogram2dcontour","x":[1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,3,4,5],"y":[1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,3,4,5],"line":{"width":0.0},"contours":{"coloring":"fill","end":15.0,"showlabels":true,"start":0.0},"coloraxis":"coloraxis","xaxis":"x3","yaxis":"y3"},{"type":"scatter","opacity":0.3,"mode":"markers","x":[1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,3,4,5],"y":[1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,3,4,5],"marker":{},"coloraxis":"coloraxis","xaxis":"x3","yaxis":"y3"}];"""
|> chartGeneratedContains ``Contours should be accessible #426``.``Contours trace Grid chart with shared color axis and adapted contours ranges``
}
test "Chart Grid with shared color axis and corrected contours ranges layout" {
"""var layout = {"xaxis":{},"yaxis":{},"xaxis2":{},"yaxis2":{},"xaxis3":{},"yaxis3":{},"grid":{"rows":2,"columns":2,"pattern":"independent"}};"""
|> chartGeneratedContains ``Contours should be accessible #426``.``Contours trace Grid chart with shared color axis and adapted contours ranges``
}
]

0 comments on commit fe740ec

Please sign in to comment.