Skip to content

Commit fe740ec

Browse files
committed
fix #426:
- 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)
1 parent bf30212 commit fe740ec

File tree

12 files changed

+450
-226
lines changed

12 files changed

+450
-226
lines changed

src/Plotly.NET.CSharp/ChartAPI/Chart2D.cs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1961,10 +1961,10 @@ public static GenericChart Histogram2DContour<XType, YType, ZType>(
19611961
YBinGroup: YBinGroup.ToOption(),
19621962
YBins: YBins.ToOption(),
19631963
Marker: Marker.ToOption(),
1964-
ContourLineColor: ContourLineColor.ToOption(),
1965-
ContourLineDash: ContourLineDash.ToOption(),
1966-
ContourLineSmoothing: ContourLineSmoothing.ToOption(),
1967-
ContourLine: ContourLine.ToOption(),
1964+
ContourLinesColor: ContourLineColor.ToOption(),
1965+
ContourLinesDash: ContourLineDash.ToOption(),
1966+
ContourLinesSmoothing: ContourLineSmoothing.ToOption(),
1967+
ContourLines: ContourLine.ToOption(),
19681968
ColorBar: ColorBar.ToOption(),
19691969
ColorScale: ColorScale.ToOption(),
19701970
ShowScale: ShowScale.ToOption(),
@@ -2246,15 +2246,15 @@ public static GenericChart Contour<ZType, XType, YType, TextType>(
22462246
ShowScale: ShowScale.ToOption(),
22472247
ReverseScale: ReverseScale.ToOption(),
22482248
Transpose: Transpose.ToOption(),
2249-
ContourLineColor: ContourLineColor.ToOption(),
2250-
ContourLineDash: ContourLineDash.ToOption(),
2251-
ContourLineSmoothing: ContourLineSmoothing.ToOption(),
2252-
ContourLine: ContourLine.ToOption(),
2249+
ContourLinesColor: ContourLineColor.ToOption(),
2250+
ContourLinesDash: ContourLineDash.ToOption(),
2251+
ContourLinesSmoothing: ContourLineSmoothing.ToOption(),
2252+
ContourLines: ContourLine.ToOption(),
22532253
ContoursColoring: ContoursColoring.ToOption(),
22542254
ContoursOperation: ContoursOperation.ToOption(),
22552255
ContoursType: ContoursType.ToOption(),
2256-
ShowContourLabels: ShowContourLabels.ToOption(),
2257-
ContourLabelFont: ContourLabelFont.ToOption(),
2256+
ShowContoursLabels: ShowContourLabels.ToOption(),
2257+
ContoursLabelFont: ContourLabelFont.ToOption(),
22582258
Contours: Contours.ToOption(),
22592259
FillColor: FillColor.ToOption(),
22602260
NContours: NContours.ToOption(),
@@ -2512,12 +2512,12 @@ public static GenericChart PointDensity<XType, YType>(
25122512
PointMarkerColor: PointMarkerColor.ToOption(),
25132513
PointMarkerSymbol: PointMarkerSymbol.ToOption(),
25142514
PointMarkerSize: PointMarkerSize.ToOption(),
2515-
ContourLineColor: ContourLineColor.ToOption(),
2516-
ContourLineSmoothing: ContourLineSmoothing.ToOption(),
2517-
ContourLineWidth: ContourLineWidth.ToOption(),
2515+
ContourLinesColor: ContourLineColor.ToOption(),
2516+
ContourLinesSmoothing: ContourLineSmoothing.ToOption(),
2517+
ContourLinesWidth: ContourLineWidth.ToOption(),
25182518
ShowContourLines: ShowContourLines.ToOption(),
2519-
ShowContourLabels: ShowContourLabels.ToOption(),
2520-
ContourColoring: ContourColoring.ToOption(),
2519+
ShowContoursLabels: ShowContourLabels.ToOption(),
2520+
ContoursColoring: ContourColoring.ToOption(),
25212521
NContours: NContours.ToOption(),
25222522
HistNorm: HistNorm.ToOption(),
25232523
ContourOpacity: ContourOpacity.ToOption(),

src/Plotly.NET/ChartAPI/Chart2D.fs

Lines changed: 270 additions & 162 deletions
Large diffs are not rendered by default.

src/Plotly.NET/RELEASE_NOTES.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
- [Add "top left" & "top center" side options to legend title](https://github.com/plotly/Plotly.NET/commit/bebe507963c4af2a37ec6ad5afd960e1543c161a)
2222
- [Add "false" option to scaleanchor](https://github.com/plotly/Plotly.NET/commit/bad6d531501e37f27b16b11bf83d8711640a7605)
2323
- v2.27:
24-
- []()
24+
- [Add insiderange to cartesian axes](https://github.com/plotly/Plotly.NET/commit/f7d24df0e76130a323c52f8f4d57cdbe8622d241)
2525

2626
- [Plotly.NET.ImageExport (4.0.0 -> 5.0.0)](https://github.com/plotly/Plotly.NET/blob/dev/src/Plotly.NET.ImageExport/RELEASE_NOTES.md)
2727
- [Plotly.NET.Interactive (4.1.0 -> 4.2.0)](https://github.com/plotly/Plotly.NET/blob/dev/src/Plotly.NET.Interactive/RELEASE_NOTES.md)

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\FeatureAdditions\Accessible_Contours.fs" />
1516
<Compile Include="TestCharts\UpstreamFeatures\2.27.fs" />
1617
<Compile Include="TestCharts\UpstreamFeatures\2.26.fs" />
1718
<Compile Include="TestUtils.fs" />

tests/Common/FSharpTestBase/TestCharts/Chart2DTestCharts.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ module Histogram2DContour =
283283
let x = Array.init n (fun i -> ((step i)**3.) + (0.3 * (normal (rnd) 0. 2.) ))
284284
let y = Array.init n (fun i -> ((step i)**6.) + (0.3 * (normal (rnd) 0. 2.) ))
285285
[
286-
Chart.Histogram2DContour (x = x, y = y,ContourLine=Line.init(Width=0.), UseDefaults = false)
286+
Chart.Histogram2DContour (x = x, y = y,ContourLines=Line.init(Width=0.), UseDefaults = false)
287287
Chart.Point(x = x,y = y,Opacity=0.3, UseDefaults = false)
288288
]
289289
|> Chart.combine
@@ -476,6 +476,6 @@ module PointDensity =
476476
PointMarkerSize = 4,
477477
ColorScale = StyleParam.Colorscale.Viridis,
478478
ColorBar = ColorBar.init(Title = Title.init("Density")),
479-
ShowContourLabels = true,
479+
ShowContoursLabels = true,
480480
UseDefaults = false
481481
)
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
module Accessible_Contrours_TestCharts
2+
3+
open Plotly.NET
4+
open Plotly.NET.TraceObjects
5+
open Plotly.NET.LayoutObjects
6+
7+
// https://github.com/plotly/Plotly.NET/issues/426
8+
9+
module ``Contours should be accessible #426`` =
10+
11+
let ``Contour chart with more contours settings`` =
12+
// max z is 10
13+
Chart.Contour(
14+
zData = [
15+
[5;2;3]
16+
[10;2;1]
17+
[0;5;1]
18+
],
19+
ShowContoursLabels = true,
20+
ShowContourLines = true,
21+
ContoursStart = 0,
22+
ContoursEnd = 15,
23+
UseDefaults = false
24+
)
25+
|> Chart.withColorAxisAnchor(1)
26+
27+
28+
let ``Histogram2DContour chart with more contours settings`` =
29+
// max z is 5
30+
Chart.Histogram2DContour(
31+
X = [1;1;2;2;2;2;2;3;4;5],
32+
Y = [1;1;2;2;2;2;2;3;4;5],
33+
ShowContoursLabels = true,
34+
ShowContourLines = true,
35+
ContoursStart = 0,
36+
ContoursEnd = 15,
37+
UseDefaults = false
38+
)
39+
|> Chart.withColorAxisAnchor(1)
40+
41+
42+
let ``PointDensity chart with accessible contours settings`` =
43+
// max z is 15
44+
Chart.PointDensity(
45+
x = [1;1;2;2;2;2;2;2;2;2;2;2;2;2;2;2;2;3;4;5],
46+
y = [1;1;2;2;2;2;2;2;2;2;2;2;2;2;2;2;2;3;4;5],
47+
ShowContoursLabels = true,
48+
ShowContourLines = true,
49+
ContoursStart = 0,
50+
ContoursEnd = 15,
51+
UseDefaults = false
52+
)
53+
|> Chart.withColorAxisAnchor(1)
54+
55+
let ``Contours trace Grid chart with shared color axis and adapted contours ranges`` =
56+
[
57+
// max z is 10
58+
Chart.Contour(
59+
zData = [
60+
[5;2;3]
61+
[10;2;1]
62+
[0;5;1]
63+
],
64+
ShowContoursLabels = true,
65+
ShowContourLines = true,
66+
ContoursStart = 0,
67+
ContoursEnd = 15,
68+
UseDefaults = false
69+
)
70+
|> Chart.withColorAxisAnchor(1)
71+
72+
// max z is 5
73+
Chart.Histogram2DContour(
74+
X = [1;1;2;2;2;2;2;3;4;5],
75+
Y = [1;1;2;2;2;2;2;3;4;5],
76+
ShowContoursLabels = true,
77+
ShowContourLines = true,
78+
ContoursStart = 0,
79+
ContoursEnd = 15,
80+
UseDefaults = false
81+
)
82+
|> Chart.withColorAxisAnchor(1)
83+
84+
// max z is 15
85+
Chart.PointDensity(
86+
x = [1;1;2;2;2;2;2;2;2;2;2;2;2;2;2;2;2;3;4;5],
87+
y = [1;1;2;2;2;2;2;2;2;2;2;2;2;2;2;2;2;3;4;5],
88+
ShowContoursLabels = true,
89+
ShowContourLines = true,
90+
ContoursStart = 0,
91+
ContoursEnd = 15,
92+
UseDefaults = false
93+
)
94+
|> Chart.withColorAxisAnchor(1)
95+
]
96+
|> Chart.Grid(2,2)

tests/ConsoleApps/FSharpConsole/Program.fs

Lines changed: 6 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -9,44 +9,15 @@ open DynamicObj
99
open Giraffe.ViewEngine
1010
open Newtonsoft.Json
1111

12+
let getZeroCollection n : float []=
13+
Array.zeroCreate n
14+
1215
[<EntryPoint>]
1316
let main argv =
14-
Chart.Line(
15-
x = [1; 2; 3; 4],
16-
y = [1; 1; 2; 3],
17-
UseDefaults = false
18-
)
19-
|> Chart.withXAxis(
20-
LinearAxis.init(
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],
17+
Chart.Histogram2DContour(
18+
MultiX = [["A";"A";"A";"B";"B"];["AA"; "AA"; "AB"; "BA"; "BB"]],
19+
MultiY = [["A";"A";"A";"B";"B"];["AA"; "AA"; "AB"; "BA"; "BB"]],
3620
UseDefaults = false
3721
)
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
49-
)
50-
)
5122
|> Chart.show
5223
0

tests/CoreTests/CoreTests/CoreTests.fsproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
<Compile Include="UpstreamFeatures\2.21.fs" />
4646
<Compile Include="UpstreamFeatures\2.20.fs" />
4747
<Compile Include="UpstreamFeatures\2.19.fs" />
48+
<Compile Include="FeatureAdditions\Accessible_Contours.fs" />
4849
<Compile Include="Main.fs" />
4950
</ItemGroup>
5051

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// https://github.com/plotly/Plotly.NET/issues/426
2+
3+
module CoreTests.Accessible_Contours
4+
5+
open Expecto
6+
open Plotly.NET
7+
open Plotly.NET.LayoutObjects
8+
open Plotly.NET.TraceObjects
9+
10+
open TestUtils.HtmlCodegen
11+
open Accessible_Contrours_TestCharts
12+
13+
module ``Contours should be accessible #426`` =
14+
15+
[<Tests>]
16+
let ``Contours should be accessible #426`` =
17+
testList "FeatureAddition.Contours should be accessible" [
18+
test "more contours settings on Contour data" {
19+
"""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"}];"""
20+
|> chartGeneratedContains ``Contours should be accessible #426``.``Contour chart with more contours settings``
21+
}
22+
test "more contours settings on Contour layout" {
23+
emptyLayout ``Contours should be accessible #426``.``Contour chart with more contours settings``
24+
}
25+
test "more contours settings on Histogram2DContour data" {
26+
"""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"}];"""
27+
|> chartGeneratedContains ``Contours should be accessible #426``.``Histogram2DContour chart with more contours settings``
28+
}
29+
test "more contours settings on Histogram2DContour layout" {
30+
emptyLayout ``Contours should be accessible #426``.``Histogram2DContour chart with more contours settings``
31+
}
32+
test "Accessible contours settings on PointDensity data" {
33+
"""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"}];"""
34+
|> chartGeneratedContains ``Contours should be accessible #426``.``PointDensity chart with accessible contours settings``
35+
}
36+
test "Accessible contours settings on PointDensity layout" {
37+
emptyLayout ``Contours should be accessible #426``.``PointDensity chart with accessible contours settings``
38+
}
39+
test "Chart Grid with shared color axis and corrected contours ranges data" {
40+
"""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"}];"""
41+
|> chartGeneratedContains ``Contours should be accessible #426``.``Contours trace Grid chart with shared color axis and adapted contours ranges``
42+
}
43+
test "Chart Grid with shared color axis and corrected contours ranges layout" {
44+
"""var layout = {"xaxis":{},"yaxis":{},"xaxis2":{},"yaxis2":{},"xaxis3":{},"yaxis3":{},"grid":{"rows":2,"columns":2,"pattern":"independent"}};"""
45+
|> chartGeneratedContains ``Contours should be accessible #426``.``Contours trace Grid chart with shared color axis and adapted contours ranges``
46+
}
47+
]

0 commit comments

Comments
 (0)