Skip to content

Commit f5fd138

Browse files
committed
Add carpet tests
1 parent e177eeb commit f5fd138

File tree

3 files changed

+190
-62
lines changed

3 files changed

+190
-62
lines changed

src/Plotly.NET/Playground.fsx

Lines changed: 48 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,6 @@ open FSharpAux
159159
open System
160160
open System.IO
161161

162-
let a = [4.; 5.; 5.; 6.]
163-
let b = [1.; 1.; 2.; 3.]
164-
let sizes = [5; 10; 15; 20]
165-
166162
[
167163
Chart.Carpet(
168164
"contour",
@@ -185,75 +181,65 @@ let sizes = [5; 10; 15; 20]
185181
)
186182
Chart.ContourCarpet(
187183
"contour",
184+
[1.; 1.96; 2.56; 3.0625; 4.; 5.0625; 1.; 7.5625; 9.; 12.25; 15.21; 14.0625],
188185
A = [0; 1; 2; 3; 0; 1; 2; 3; 0; 1; 2; 3],
189-
B = [4; 4; 4; 4; 5; 5; 5; 5; 6; 6; 6; 6],
190-
Z = [1.; 1.96; 2.56; 3.0625; 4.; 5.0625; 1.; 7.5625; 9.; 12.25; 15.21; 14.0625]
186+
B = [4; 4; 4; 4; 5; 5; 5; 5; 6; 6; 6; 6]
191187
)
192188
]
193189
|> Chart.combine
194190
|> Chart.show
195191

192+
let a = [4.; 4.; 4.; 4.5; 4.5; 4.5; 5.; 5.; 5.; 6.; 6.; 6.]
193+
let b = [1.; 2.; 3.; 1.; 2.; 3.; 1.; 2.; 3.; 1.; 2.; 3.]
194+
let y = [2.; 3.5; 4.; 3.; 4.5; 5.; 5.5; 6.5; 7.5; 8.; 8.5; 10.]
195+
196196
let carpets =
197197
[
198-
Chart.Carpet(
198+
Chart.Carpet("carpet1",A = a, B = b, Y = y)
199+
Chart.Carpet("carpet2",A = (a |> List.rev) , B = (b |> List.rev), Y = (y |> List.map (fun x -> x + 10.)))
200+
Chart.Carpet("carpet3",A = a, B = b, Y = (y |> List.map (fun x -> x + 20.)))
201+
Chart.Carpet("carpet4",A = (a |> List.rev) , B = (b |> List.rev), Y = (y |> List.map (fun x -> x + 30.)))
202+
Chart.Carpet("carpet5",A = a, B = b, Y = (y |> List.map (fun x -> x + 40.)))
203+
]
204+
205+
let aData = [4.; 5.; 5.; 6.]
206+
let bData = [1.; 1.; 2.; 3.]
207+
let sizes = [5; 10; 15; 20]
208+
209+
let carpetCharts =
210+
[
211+
Chart.ScatterCarpet(
212+
aData,bData,
213+
StyleParam.Mode.Lines_Markers,
199214
"carpet1",
200-
A= [4.; 4.; 4.; 4.5; 4.5; 4.5; 5.; 5.; 5.; 6.; 6.; 6.],
201-
B= [1.; 2.; 3.; 1.; 2.; 3.; 1.; 2.; 3.; 1.; 2.; 3.],
202-
Y= [2.; 3.5; 4.; 3.; 4.5; 5.; 5.5; 6.5; 7.5; 8.; 8.5; 10.]
203-
)
204-
Chart.Carpet(
205-
"carpet2",
206-
A= ([4.; 4.; 4.; 4.5; 4.5; 4.5; 5.; 5.; 5.; 6.; 6.; 6.] |> List.rev),
207-
B= ([1.; 2.; 3.; 1.; 2.; 3.; 1.; 2.; 3.; 1.; 2.; 3.]|> List.rev),
208-
Y= ([2.; 3.5; 4.; 3.; 4.5; 5.; 5.5; 6.5; 7.5; 8.; 8.5; 10.] |> List.map (fun x -> x + 10.))
209-
)
210-
Chart.Carpet(
211-
"carpet3",
212-
A= [4.; 4.; 4.; 4.5; 4.5; 4.5; 5.; 5.; 5.; 6.; 6.; 6.],
213-
B= [1.; 2.; 3.; 1.; 2.; 3.; 1.; 2.; 3.; 1.; 2.; 3.],
214-
Y= ([2.; 3.5; 4.; 3.; 4.5; 5.; 5.5; 6.5; 7.5; 8.; 8.5; 10.] |> List.map (fun x -> x + 20.))
215-
)
216-
Chart.Carpet(
217-
"carpet4",
218-
A= ([4.; 4.; 4.; 4.5; 4.5; 4.5; 5.; 5.; 5.; 6.; 6.; 6.] |> List.rev),
219-
B= ([1.; 2.; 3.; 1.; 2.; 3.; 1.; 2.; 3.; 1.; 2.; 3.]|> List.rev),
220-
Y= ([2.; 3.5; 4.; 3.; 4.5; 5.; 5.5; 6.5; 7.5; 8.; 8.5; 10.] |> List.map (fun x -> x + 30.))
221-
)
222-
Chart.Carpet(
223-
"carpet5",
224-
A= ([4.; 4.; 4.; 4.5; 4.5; 4.5; 5.; 5.; 5.; 6.; 6.; 6.] |> List.rev),
225-
B= ([1.; 2.; 3.; 1.; 2.; 3.; 1.; 2.; 3.; 1.; 2.; 3.]|> List.rev),
226-
Y= ([2.; 3.5; 4.; 3.; 4.5; 5.; 5.5; 6.5; 7.5; 8.; 8.5; 10.] |> List.map (fun x -> x + 40.))
227-
)
215+
Name = "Scatter",
216+
MultiMarkerSymbol =[
217+
StyleParam.MarkerSymbol.ArrowDown
218+
StyleParam.MarkerSymbol.TriangleNW
219+
StyleParam.MarkerSymbol.DiamondX
220+
StyleParam.MarkerSymbol.Hexagon2
221+
],
222+
MultiSize = sizes,
223+
Color = Color.fromColors ([Red; Blue; Green; Yellow] |> List.map Color.fromKeyword)
224+
)
225+
Chart.PointCarpet(aData,bData,"carpet2",Name = "Point")
226+
Chart.LineCarpet(aData,bData,"carpet3",Name = "Line")
227+
Chart.SplineCarpet(aData,bData,"carpet4",Name = "Spline")
228+
Chart.BubbleCarpet((Seq.zip3 aData bData sizes),"carpet5",Name = "Bubble")
228229
]
229-
|> Chart.combine
230230

231-
[
232-
carpets
233-
Chart.ScatterCarpet(
234-
a,b,
235-
StyleParam.Mode.Lines_Markers,
236-
"carpet1",
237-
Name = "Scatter",
238-
MultiMarkerSymbol =[
239-
StyleParam.MarkerSymbol.ArrowDown
240-
StyleParam.MarkerSymbol.TriangleNW
241-
StyleParam.MarkerSymbol.DiamondX
242-
StyleParam.MarkerSymbol.Hexagon2
243-
],
244-
MultiSize = [
245-
10; 15; 20; 25
246-
],
247-
Color = Color.fromColors ([Red; Blue; Green; Yellow] |> List.map Color.fromKeyword)
248-
)
249-
Chart.PointCarpet(a,b,"carpet2",Name = "Point")
250-
Chart.LineCarpet(a,b,"carpet3",Name = "Line")
251-
Chart.SplineCarpet(a,b,"carpet4",Name = "Spline")
252-
Chart.BubbleCarpet((Seq.zip3 a b sizes),"carpet5",Name = "Spline")
253-
]
254-
|> Chart.combine
255-
|> Chart.withSize(Height=1000)
256-
|> Chart.show
231+
let scatter = Chart.combine [carpets.[0]; carpetCharts.[0]]
232+
let point = Chart.combine [carpets.[1]; carpetCharts.[1]]
233+
let line = Chart.combine [carpets.[2]; carpetCharts.[2]]
234+
let spline = Chart.combine [carpets.[3]; carpetCharts.[3]]
235+
let bubble = Chart.combine [carpets.[4]; carpetCharts.[4]]
236+
237+
scatter |> Chart.show
238+
point |> Chart.show
239+
line |> Chart.show
240+
spline |> Chart.show
241+
bubble |> Chart.show
242+
257243

258244
let crazyMarker =
259245
Marker.init(
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
module Tests.CarpetCharts
2+
3+
open Expecto
4+
open Plotly.NET
5+
open Plotly.NET.LayoutObjects
6+
open Plotly.NET.TraceObjects
7+
open Plotly.NET.GenericChart
8+
open System
9+
10+
open TestUtils.HtmlCodegen
11+
12+
let a = [4.; 4.; 4.; 4.5; 4.5; 4.5; 5.; 5.; 5.; 6.; 6.; 6.]
13+
let b = [1.; 2.; 3.; 1.; 2.; 3.; 1.; 2.; 3.; 1.; 2.; 3.]
14+
let y = [2.; 3.5; 4.; 3.; 4.5; 5.; 5.5; 6.5; 7.5; 8.; 8.5; 10.]
15+
16+
let carpets =
17+
[
18+
Chart.Carpet("carpet1",A = a, B = b, Y = y)
19+
Chart.Carpet("carpet2",A = (a |> List.rev) , B = (b |> List.rev), Y = (y |> List.map (fun x -> x + 10.)))
20+
Chart.Carpet("carpet3",A = a, B = b, Y = (y |> List.map (fun x -> x + 20.)))
21+
Chart.Carpet("carpet4",A = (a |> List.rev) , B = (b |> List.rev), Y = (y |> List.map (fun x -> x + 30.)))
22+
Chart.Carpet("carpet5",A = a, B = b, Y = (y |> List.map (fun x -> x + 40.)))
23+
]
24+
25+
let aData = [4.; 5.; 5.; 6.]
26+
let bData = [1.; 1.; 2.; 3.]
27+
let sizes = [5; 10; 15; 20]
28+
29+
30+
let carpetCharts =
31+
[
32+
Chart.ScatterCarpet(
33+
aData,bData,
34+
StyleParam.Mode.Lines_Markers,
35+
"carpet1",
36+
Name = "Scatter",
37+
MultiMarkerSymbol =[
38+
StyleParam.MarkerSymbol.ArrowDown
39+
StyleParam.MarkerSymbol.TriangleNW
40+
StyleParam.MarkerSymbol.DiamondX
41+
StyleParam.MarkerSymbol.Hexagon2
42+
],
43+
MultiSize = sizes,
44+
Color = Color.fromColors ([Red; Blue; Green; Yellow] |> List.map Color.fromKeyword)
45+
)
46+
Chart.PointCarpet(aData,bData,"carpet2",Name = "Point")
47+
Chart.LineCarpet(aData,bData,"carpet3",Name = "Line")
48+
Chart.SplineCarpet(aData,bData,"carpet4",Name = "Spline")
49+
Chart.BubbleCarpet((Seq.zip3 aData bData sizes),"carpet5",Name = "Bubble")
50+
]
51+
52+
let scatter = Chart.combine [carpets.[0]; carpetCharts.[0]]
53+
let point = Chart.combine [carpets.[1]; carpetCharts.[1]]
54+
let line = Chart.combine [carpets.[2]; carpetCharts.[2]]
55+
let spline = Chart.combine [carpets.[3]; carpetCharts.[3]]
56+
let bubble = Chart.combine [carpets.[4]; carpetCharts.[4]]
57+
58+
59+
[<Tests>]
60+
let ``ScatterCarpet and derived Charts`` =
61+
testList "CarpetCharts.ScatterCarpet and derived Charts" [
62+
testCase "ScatterCarpet data" ( fun () ->
63+
"""var data = [{"type":"carpet","y":[2.0,3.5,4.0,3.0,4.5,5.0,5.5,6.5,7.5,8.0,8.5,10.0],"a":[4.0,4.0,4.0,4.5,4.5,4.5,5.0,5.0,5.0,6.0,6.0,6.0],"b":[1.0,2.0,3.0,1.0,2.0,3.0,1.0,2.0,3.0,1.0,2.0,3.0],"carpet":"carpet1"},{"type":"scattercarpet","name":"Scatter","mode":"lines+markers","a":[4.0,5.0,5.0,6.0],"b":[1.0,1.0,2.0,3.0],"carpet":"carpet1","marker":{"color":["rgba(255, 0, 0, 1.0)","rgba(0, 0, 255, 1.0)","rgba(0, 128, 0, 1.0)","rgba(255, 255, 0, 1.0)"],"size":[5,10,15,20],"symbol":["46","12","32","15"]},"line":{"color":["rgba(255, 0, 0, 1.0)","rgba(0, 0, 255, 1.0)","rgba(0, 128, 0, 1.0)","rgba(255, 255, 0, 1.0)"]}}];"""
64+
|> chartGeneratedContains scatter
65+
);
66+
testCase "ScatterCarpet layout" ( fun () ->
67+
emptyLayout scatter
68+
);
69+
testCase "PointCarpet data" ( fun () ->
70+
"""var data = [{"type":"carpet","y":[12.0,13.5,14.0,13.0,14.5,15.0,15.5,16.5,17.5,18.0,18.5,20.0],"a":[6.0,6.0,6.0,5.0,5.0,5.0,4.5,4.5,4.5,4.0,4.0,4.0],"b":[3.0,2.0,1.0,3.0,2.0,1.0,3.0,2.0,1.0,3.0,2.0,1.0],"carpet":"carpet2"},{"type":"scattercarpet","name":"Point","mode":"markers","a":[4.0,5.0,5.0,6.0],"b":[1.0,1.0,2.0,3.0],"carpet":"carpet2","marker":{}}];"""
71+
|> chartGeneratedContains point
72+
);
73+
testCase "PointCarpet layout" ( fun () ->
74+
emptyLayout point
75+
);
76+
testCase "LineCarpet data" ( fun () ->
77+
"""var data = [{"type":"carpet","y":[22.0,23.5,24.0,23.0,24.5,25.0,25.5,26.5,27.5,28.0,28.5,30.0],"a":[4.0,4.0,4.0,4.5,4.5,4.5,5.0,5.0,5.0,6.0,6.0,6.0],"b":[1.0,2.0,3.0,1.0,2.0,3.0,1.0,2.0,3.0,1.0,2.0,3.0],"carpet":"carpet3"},{"type":"scattercarpet","name":"Line","mode":"lines","a":[4.0,5.0,5.0,6.0],"b":[1.0,1.0,2.0,3.0],"carpet":"carpet3","marker":{},"line":{}}];"""
78+
|> chartGeneratedContains line
79+
);
80+
testCase "LineCarpet layout" ( fun () ->
81+
emptyLayout line
82+
);
83+
testCase "SplineCarpet data" ( fun () ->
84+
"""var data = [{"type":"carpet","y":[32.0,33.5,34.0,33.0,34.5,35.0,35.5,36.5,37.5,38.0,38.5,40.0],"a":[6.0,6.0,6.0,5.0,5.0,5.0,4.5,4.5,4.5,4.0,4.0,4.0],"b":[3.0,2.0,1.0,3.0,2.0,1.0,3.0,2.0,1.0,3.0,2.0,1.0],"carpet":"carpet4"},{"type":"scattercarpet","name":"Spline","mode":"lines","a":[4.0,5.0,5.0,6.0],"b":[1.0,1.0,2.0,3.0],"carpet":"carpet4","marker":{},"line":{"shape":"spline"}}];"""
85+
|> chartGeneratedContains spline
86+
);
87+
testCase "SplineCarpet layout" ( fun () ->
88+
emptyLayout spline
89+
);
90+
testCase "BubbleCarpet data" ( fun () ->
91+
"""var data = [{"type":"carpet","y":[42.0,43.5,44.0,43.0,44.5,45.0,45.5,46.5,47.5,48.0,48.5,50.0],"a":[4.0,4.0,4.0,4.5,4.5,4.5,5.0,5.0,5.0,6.0,6.0,6.0],"b":[1.0,2.0,3.0,1.0,2.0,3.0,1.0,2.0,3.0,1.0,2.0,3.0],"carpet":"carpet5"},{"type":"scattercarpet","name":"Bubble","mode":"markers","a":[4.0,5.0,5.0,6.0],"b":[1.0,1.0,2.0,3.0],"carpet":"carpet5","marker":{"size":[5,10,15,20]}}];"""
92+
|> chartGeneratedContains bubble
93+
);
94+
testCase "BubbleCarpet layout" ( fun () ->
95+
emptyLayout bubble
96+
);
97+
98+
]
99+
100+
101+
let contour =
102+
[
103+
Chart.Carpet(
104+
"contour",
105+
A = [0.; 1.; 2.; 3.; 0.; 1.; 2.; 3.; 0.; 1.; 2.; 3.],
106+
B = [4.; 4.; 4.; 4.; 5.; 5.; 5.; 5.; 6.; 6.; 6.; 6.],
107+
X = [2.; 3.; 4.; 5.; 2.2; 3.1; 4.1; 5.1; 1.5; 2.5; 3.5; 4.5],
108+
Y = [1.; 1.4; 1.6; 1.75; 2.; 2.5; 2.7; 2.75; 3.; 3.5; 3.7; 3.75],
109+
AAxis = LinearAxis.initCarpet(
110+
TickPrefix = "a = ",
111+
Smoothing = 0.,
112+
MinorGridCount = 9,
113+
AxisType = StyleParam.AxisType.Linear
114+
),
115+
BAxis = LinearAxis.initCarpet(
116+
TickPrefix = "b = ",
117+
Smoothing = 0.,
118+
MinorGridCount = 9,
119+
AxisType = StyleParam.AxisType.Linear
120+
)
121+
)
122+
Chart.ContourCarpet(
123+
"contour",
124+
[1.; 1.96; 2.56; 3.0625; 4.; 5.0625; 1.; 7.5625; 9.; 12.25; 15.21; 14.0625],
125+
A = [0; 1; 2; 3; 0; 1; 2; 3; 0; 1; 2; 3],
126+
B = [4; 4; 4; 4; 5; 5; 5; 5; 6; 6; 6; 6]
127+
)
128+
]
129+
|> Chart.combine
130+
131+
[<Tests>]
132+
let ``ContourCarpet Charts`` =
133+
testList "CarpetCharts.ContourCarpet Charts" [
134+
testCase "ScatterCarpet data" ( fun () ->
135+
"""var data = [{"type":"carpet","x":[2.0,3.0,4.0,5.0,2.2,3.1,4.1,5.1,1.5,2.5,3.5,4.5],"y":[1.0,1.4,1.6,1.75,2.0,2.5,2.7,2.75,3.0,3.5,3.7,3.75],"a":[0.0,1.0,2.0,3.0,0.0,1.0,2.0,3.0,0.0,1.0,2.0,3.0],"b":[4.0,4.0,4.0,4.0,5.0,5.0,5.0,5.0,6.0,6.0,6.0,6.0],"aaxis":{"type":"linear","tickprefix":"a = ","minorgridcount":9,"smoothing":0.0},"baxis":{"type":"linear","tickprefix":"b = ","minorgridcount":9,"smoothing":0.0},"carpet":"contour"},{"type":"contourcarpet","z":[1.0,1.96,2.56,3.0625,4.0,5.0625,1.0,7.5625,9.0,12.25,15.21,14.0625],"a":[0,1,2,3,0,1,2,3,0,1,2,3],"b":[4,4,4,4,5,5,5,5,6,6,6,6],"carpet":"contour","line":{}}];"""
136+
|> chartGeneratedContains contour
137+
);
138+
testCase "ScatterCarpet layout" ( fun () ->
139+
emptyLayout contour
140+
);
141+
]

tests/Plotly.NET.Tests/Plotly.NET.Tests.fsproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
<Compile Include="HtmlCodegen\FinanceCharts.fs" />
2121
<Compile Include="HtmlCodegen\PolarCharts.fs" />
2222
<Compile Include="HtmlCodegen\TernaryCharts.fs" />
23+
<Compile Include="HtmlCodegen\CarpetCharts.fs" />
2324
<Compile Include="HtmlCodegen\CategoricalCharts.fs" />
2425
<Compile Include="ImageExport.fs" />
2526
<Compile Include="Main.fs" />

0 commit comments

Comments
 (0)