Skip to content

Commit b65ad7d

Browse files
committed
Add 3D chart tests
1 parent 417e123 commit b65ad7d

File tree

1 file changed

+159
-16
lines changed

1 file changed

+159
-16
lines changed

tests/Plotly.NET.Tests/HtmlCodegen/Charts3D.fs

Lines changed: 159 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,23 @@ open TestUtils
66
open Plotly.NET.GenericChart
77
open System
88

9+
//---------------------- Generate linearly spaced vector ----------------------
10+
let linspace (min,max,n) =
11+
if n <= 2 then failwithf "n needs to be larger then 2"
12+
let bw = float (max - min) / (float n - 1.)
13+
Array.init n (fun i -> min + (bw * float i))
14+
15+
//-------------------- Generate linearly spaced mesh grid ---------------------
16+
let mgrid (min,max,n) =
17+
18+
let data = linspace(min,max,n)
19+
20+
let z = [|for i in 1 .. n do [|for i in 1 .. n do yield data|]|]
21+
let x = [|for i in 1 .. n do [|for j in 1 .. n do yield [|for k in 1 .. n do yield data.[i-1]|]|]|]
22+
let y = [|for i in 1 .. n do [|for j in 1 .. n do yield [|for k in 1 .. n do yield data.[j-1]|]|]|]
23+
24+
x,y,z
25+
926
let scatterChart =
1027
let x = [19; 26; 55;]
1128
let y = [19; 26; 55;]
@@ -30,6 +47,30 @@ let ``3D Scatter charts`` =
3047
);
3148
]
3249

50+
let pointChart =
51+
let x = [19; 26; 55;]
52+
let y = [19; 26; 55;]
53+
let z = [19; 26; 55;]
54+
55+
Chart.Point3d(x,y,z)
56+
|> Chart.withXAxisStyle("my x-axis", Id=StyleParam.SubPlotId.Scene 1)
57+
|> Chart.withYAxisStyle("my y-axis", Id=StyleParam.SubPlotId.Scene 1)
58+
|> Chart.withZAxisStyle("my z-axis")
59+
|> Chart.withSize(800.,800.)
60+
61+
[<Tests>]
62+
let ``3D Point charts`` =
63+
testList "Charts3D.3D Point charts" [
64+
testCase "3D Point charts data" ( fun () ->
65+
"""var data = [{"type":"scatter3d","mode":"markers","x":[19,26,55],"y":[19,26,55],"z":[19,26,55],"line":{},"marker":{}}]"""
66+
|> chartGeneratedContains pointChart
67+
);
68+
testCase "3D Point charts layout" ( fun () ->
69+
"""var layout = {"scene":{"xaxis":{"title":{"text":"my x-axis"}},"yaxis":{"title":{"text":"my y-axis"}},"zaxis":{"title":{"text":"my z-axis"}}},"width":800.0,"height":800.0};"""
70+
|> chartGeneratedContains pointChart
71+
);
72+
]
73+
3374
let lineChart =
3475
let c = [0. .. 0.5 .. 15.]
3576

@@ -46,13 +87,12 @@ let lineChart =
4687
)
4788
|> List.unzip3
4889

49-
Chart.Scatter3d(x, y, z, StyleParam.Mode.Lines_Markers)
90+
Chart.Line3d(x, y, z, ShowMarkers=true)
5091
|> Chart.withXAxisStyle("x-axis", Id=StyleParam.SubPlotId.Scene 1)
5192
|> Chart.withYAxisStyle("y-axis", Id=StyleParam.SubPlotId.Scene 1)
5293
|> Chart.withZAxisStyle("z-axis")
5394
|> Chart.withSize(800., 800.)
5495

55-
5696
[<Tests>]
5797
let ``Line charts`` =
5898
testList "Charts3D.Line charts" [
@@ -66,13 +106,33 @@ let ``Line charts`` =
66106
);
67107
]
68108

109+
let bubbleChart =
110+
Chart.Bubble3d(
111+
[1,3,2; 6,5,4; 7,9,8],
112+
[20; 40; 30],
113+
Labels = ["A"; "B"; "C"],
114+
TextPosition = StyleParam.TextPosition.TopLeft
115+
)
116+
|> Chart.withXAxisStyle("x-axis", Id=StyleParam.SubPlotId.Scene 1)
117+
|> Chart.withYAxisStyle("y-axis", Id=StyleParam.SubPlotId.Scene 1)
118+
|> Chart.withZAxisStyle("z-axis")
119+
120+
[<Tests>]
121+
let ``Bubble charts`` =
122+
testList "Charts3D.Bubble charts" [
123+
testCase "Bubble data" ( fun () ->
124+
"""var data = [{"type":"scatter3d","mode":"markers+text","x":[1,6,7],"y":[3,5,9],"z":[2,4,8],"marker":{"size":[20,40,30]},"text":["A","B","C"],"textposition":"top left"}];"""
125+
|> chartGeneratedContains bubbleChart
126+
);
127+
testCase "Bubble layout" ( fun () ->
128+
"""var layout = {"scene":{"xaxis":{"title":{"text":"x-axis"}},"yaxis":{"title":{"text":"y-axis"}},"zaxis":{"title":{"text":"z-axis"}}}};"""
129+
|> chartGeneratedContains bubbleChart
130+
);
131+
]
132+
133+
69134
let firstSurfaceChart =
70-
//---------------------- Generate linearly spaced vector ----------------------
71-
let linspace (min,max,n) =
72-
if n <= 2 then failwithf "n needs to be larger then 2"
73-
let bw = float (max - min) / (float n - 1.)
74-
Array.init n (fun i -> min + (bw * float i))
75-
135+
76136
//---------------------- Create example data ----------------------
77137
let size = 100
78138
let x = linspace(-2. * Math.PI, 2. * Math.PI, size)
@@ -127,13 +187,6 @@ let ``Surface charts`` =
127187

128188

129189
let meshChart =
130-
let linspace (min,max,n) =
131-
if n <= 2 then failwithf "n needs to be larger then 2"
132-
let bw = float (max - min) / (float n - 1.)
133-
Array.init n (fun i -> min + (bw * float i))
134-
//[|min ..bw ..max|]
135-
136-
//---------------------- Create example data ----------------------
137190
let size = 100
138191
let x = linspace(-2. * Math.PI, 2. * Math.PI, size)
139192
let y = linspace(-2. * Math.PI, 2. * Math.PI, size)
@@ -173,4 +226,94 @@ let ``Mesh charts`` =
173226
testCase "Mesh layout" ( fun () ->
174227
emptyLayout meshChart
175228
);
176-
]
229+
]
230+
231+
let coneChart =
232+
Chart.Cone(
233+
x = [1; 1; 1],
234+
y = [1; 2; 3],
235+
z = [1; 1; 1],
236+
u = [1; 2; 3],
237+
v = [1; 1; 2],
238+
w = [4; 4; 1],
239+
ColorScale = StyleParam.Colorscale.Viridis
240+
)
241+
242+
[<Tests>]
243+
let ``Cone charts`` =
244+
testList "Charts3D.Cone charts" [
245+
testCase "Cone data" ( fun () ->
246+
"""var data = [{"type":"cone","x":[1,1,1],"y":[1,2,3],"z":[1,1,1],"u":[1,2,3],"v":[1,1,2],"w":[4,4,1],"colorscale":"Viridis"}];"""
247+
|> chartGeneratedContains coneChart
248+
);
249+
testCase "Cone layout" ( fun () ->
250+
emptyLayout coneChart
251+
);
252+
]
253+
254+
let streamTubeChart =
255+
Chart.StreamTube(
256+
x = [0; 0; 0],
257+
y = [0; 1; 2],
258+
z = [0; 0; 0],
259+
u = [0; 0; 0],
260+
v = [1; 1; 1],
261+
w = [0; 0; 0],
262+
ColorScale = StyleParam.Colorscale.Viridis
263+
)
264+
265+
[<Tests>]
266+
let ``StreamTube charts`` =
267+
testList "StreamTube.Volume charts" [
268+
testCase "Volume data" ( fun () ->
269+
"""var data = [{"type":"streamtube","x":[0,0,0],"y":[0,1,2],"z":[0,0,0],"u":[0,0,0],"v":[1,1,1],"w":[0,0,0],"colorscale":"Viridis"}];"""
270+
|> chartGeneratedContains streamTubeChart
271+
);
272+
testCase "Volume layout" ( fun () ->
273+
emptyLayout streamTubeChart
274+
);
275+
]
276+
277+
let volumeChart =
278+
let x,y,z = mgrid(1.,2.,4)
279+
Chart.Volume(
280+
x |> Array.concat |> Array.concat |> Array.map (fun x -> Math.Round(x,3)),
281+
y |> Array.concat |> Array.concat |> Array.map (fun x -> Math.Round(x,3)),
282+
z |> Array.concat |> Array.concat |> Array.map (fun x -> Math.Round(x,3)),
283+
z |> Array.concat |> Array.concat |> Array.map (fun x -> Math.Round(x,3)),
284+
ColorScale = StyleParam.Colorscale.Viridis
285+
)
286+
287+
[<Tests>]
288+
let ``Volume charts`` =
289+
testList "Charts3D.Volume charts" [
290+
testCase "Volume data" ( fun () ->
291+
"""var data = [{"type":"volume","x":[1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.333,1.333,1.333,1.333,1.333,1.333,1.333,1.333,1.333,1.333,1.333,1.333,1.333,1.333,1.333,1.333,1.667,1.667,1.667,1.667,1.667,1.667,1.667,1.667,1.667,1.667,1.667,1.667,1.667,1.667,1.667,1.667,2.0,2.0,2.0,2.0,2.0,2.0,2.0,2.0,2.0,2.0,2.0,2.0,2.0,2.0,2.0,2.0],"y":[1.0,1.0,1.0,1.0,1.333,1.333,1.333,1.333,1.667,1.667,1.667,1.667,2.0,2.0,2.0,2.0,1.0,1.0,1.0,1.0,1.333,1.333,1.333,1.333,1.667,1.667,1.667,1.667,2.0,2.0,2.0,2.0,1.0,1.0,1.0,1.0,1.333,1.333,1.333,1.333,1.667,1.667,1.667,1.667,2.0,2.0,2.0,2.0,1.0,1.0,1.0,1.0,1.333,1.333,1.333,1.333,1.667,1.667,1.667,1.667,2.0,2.0,2.0,2.0],"z":[1.0,1.333,1.667,2.0,1.0,1.333,1.667,2.0,1.0,1.333,1.667,2.0,1.0,1.333,1.667,2.0,1.0,1.333,1.667,2.0,1.0,1.333,1.667,2.0,1.0,1.333,1.667,2.0,1.0,1.333,1.667,2.0,1.0,1.333,1.667,2.0,1.0,1.333,1.667,2.0,1.0,1.333,1.667,2.0,1.0,1.333,1.667,2.0,1.0,1.333,1.667,2.0,1.0,1.333,1.667,2.0,1.0,1.333,1.667,2.0,1.0,1.333,1.667,2.0],"value":[1.0,1.333,1.667,2.0,1.0,1.333,1.667,2.0,1.0,1.333,1.667,2.0,1.0,1.333,1.667,2.0,1.0,1.333,1.667,2.0,1.0,1.333,1.667,2.0,1.0,1.333,1.667,2.0,1.0,1.333,1.667,2.0,1.0,1.333,1.667,2.0,1.0,1.333,1.667,2.0,1.0,1.333,1.667,2.0,1.0,1.333,1.667,2.0,1.0,1.333,1.667,2.0,1.0,1.333,1.667,2.0,1.0,1.333,1.667,2.0,1.0,1.333,1.667,2.0],"colorscale":"Viridis"}];"""
292+
|> chartGeneratedContains volumeChart
293+
);
294+
testCase "Volume layout" ( fun () ->
295+
emptyLayout volumeChart
296+
);
297+
]
298+
299+
let isoSurfaceChart =
300+
let x,y,z = mgrid(1.,2.,4)
301+
Chart.IsoSurface(
302+
x |> Array.concat |> Array.concat |> Array.map (fun x -> Math.Round(x,3)),
303+
y |> Array.concat |> Array.concat |> Array.map (fun x -> Math.Round(x,3)),
304+
z |> Array.concat |> Array.concat |> Array.map (fun x -> Math.Round(x,3)),
305+
z |> Array.concat |> Array.concat |> Array.map (fun x -> Math.Round(x,3)),
306+
ColorScale = StyleParam.Colorscale.Viridis
307+
)
308+
309+
[<Tests>]
310+
let ``IsoSurface charts`` =
311+
testList "Charts3D.IsoSurface charts" [
312+
testCase "IsoSurface data" ( fun () ->
313+
"""var data = [{"type":"isosurface","x":[1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.333,1.333,1.333,1.333,1.333,1.333,1.333,1.333,1.333,1.333,1.333,1.333,1.333,1.333,1.333,1.333,1.667,1.667,1.667,1.667,1.667,1.667,1.667,1.667,1.667,1.667,1.667,1.667,1.667,1.667,1.667,1.667,2.0,2.0,2.0,2.0,2.0,2.0,2.0,2.0,2.0,2.0,2.0,2.0,2.0,2.0,2.0,2.0],"y":[1.0,1.0,1.0,1.0,1.333,1.333,1.333,1.333,1.667,1.667,1.667,1.667,2.0,2.0,2.0,2.0,1.0,1.0,1.0,1.0,1.333,1.333,1.333,1.333,1.667,1.667,1.667,1.667,2.0,2.0,2.0,2.0,1.0,1.0,1.0,1.0,1.333,1.333,1.333,1.333,1.667,1.667,1.667,1.667,2.0,2.0,2.0,2.0,1.0,1.0,1.0,1.0,1.333,1.333,1.333,1.333,1.667,1.667,1.667,1.667,2.0,2.0,2.0,2.0],"z":[1.0,1.333,1.667,2.0,1.0,1.333,1.667,2.0,1.0,1.333,1.667,2.0,1.0,1.333,1.667,2.0,1.0,1.333,1.667,2.0,1.0,1.333,1.667,2.0,1.0,1.333,1.667,2.0,1.0,1.333,1.667,2.0,1.0,1.333,1.667,2.0,1.0,1.333,1.667,2.0,1.0,1.333,1.667,2.0,1.0,1.333,1.667,2.0,1.0,1.333,1.667,2.0,1.0,1.333,1.667,2.0,1.0,1.333,1.667,2.0,1.0,1.333,1.667,2.0],"value":[1.0,1.333,1.667,2.0,1.0,1.333,1.667,2.0,1.0,1.333,1.667,2.0,1.0,1.333,1.667,2.0,1.0,1.333,1.667,2.0,1.0,1.333,1.667,2.0,1.0,1.333,1.667,2.0,1.0,1.333,1.667,2.0,1.0,1.333,1.667,2.0,1.0,1.333,1.667,2.0,1.0,1.333,1.667,2.0,1.0,1.333,1.667,2.0,1.0,1.333,1.667,2.0,1.0,1.333,1.667,2.0,1.0,1.333,1.667,2.0,1.0,1.333,1.667,2.0],"colorscale":"Viridis"}];"""
314+
|> chartGeneratedContains isoSurfaceChart
315+
);
316+
testCase "IsoSurface layout" ( fun () ->
317+
emptyLayout isoSurfaceChart
318+
);
319+
]

0 commit comments

Comments
 (0)