Skip to content

Commit 75275ee

Browse files
committed
Refactor Chart3D html codegen tests
1 parent c849e78 commit 75275ee

6 files changed

Lines changed: 382 additions & 335 deletions

File tree

tests/Common/FSharpTestBase/FSharpTestBase.fsproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@
1313

1414
<ItemGroup>
1515
<Compile Include="TestUtils.fs" />
16-
<Compile Include="TestCharts\ChartDomainTestCharts.fs" />
1716
<Compile Include="TestCharts\Chart2DTestCharts.fs" />
17+
<Compile Include="TestCharts\Chart3DTestCharts.fs" />
18+
<Compile Include="TestCharts\ChartDomainTestCharts.fs" />
1819
</ItemGroup>
1920

2021
<ItemGroup>
Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
module Chart3DTestCharts
2+
3+
open Plotly.NET
4+
open Plotly.NET.TraceObjects
5+
open System
6+
7+
open TestUtils.DataGeneration
8+
9+
module Scatter3D =
10+
11+
let ``Simple scatter3d chart with axis titles`` =
12+
let x = [19; 26; 55;]
13+
let y = [19; 26; 55;]
14+
let z = [19; 26; 55;]
15+
16+
Chart.Scatter3D(x = x,y = y,z = z, mode = StyleParam.Mode.Markers, UseDefaults = false)
17+
|> Chart.withXAxisStyle("my x-axis", Id=StyleParam.SubPlotId.Scene 1)
18+
|> Chart.withYAxisStyle("my y-axis", Id=StyleParam.SubPlotId.Scene 1)
19+
|> Chart.withZAxisStyle("my z-axis")
20+
|> Chart.withSize(800,800)
21+
22+
module Point3D =
23+
24+
let ``Simple Point3D chart with axis titles`` =
25+
let x = [19; 26; 55;]
26+
let y = [19; 26; 55;]
27+
let z = [19; 26; 55;]
28+
29+
Chart.Point3D(x = x,y = y,z = z, UseDefaults = false)
30+
|> Chart.withXAxisStyle("my x-axis", Id=StyleParam.SubPlotId.Scene 1)
31+
|> Chart.withYAxisStyle("my y-axis", Id=StyleParam.SubPlotId.Scene 1)
32+
|> Chart.withZAxisStyle("my z-axis")
33+
|> Chart.withSize(800,800)
34+
35+
36+
37+
module Line3D =
38+
let ``Upwards spiral line 3D chart with markers`` =
39+
let c = [0. .. 0.5 .. 15.]
40+
41+
let x, y, z =
42+
c
43+
|> List.map (fun i ->
44+
let i' = float i
45+
let r = 10. * Math.Cos (i' / 10.)
46+
(r * Math.Cos i', r * Math.Sin i', i')
47+
|> fun (x,y,z) ->
48+
Math.Round(x,3),
49+
Math.Round(y,3),
50+
Math.Round(z,3)
51+
)
52+
|> List.unzip3
53+
54+
Chart.Line3D(x = x, y = y, z = z, ShowMarkers=true, UseDefaults = false)
55+
|> Chart.withXAxisStyle("x-axis", Id=StyleParam.SubPlotId.Scene 1)
56+
|> Chart.withYAxisStyle("y-axis", Id=StyleParam.SubPlotId.Scene 1)
57+
|> Chart.withZAxisStyle("z-axis")
58+
|> Chart.withSize(800, 800)
59+
60+
61+
module Bubble3D =
62+
63+
let ``Simple Bubble3D chart with axis titles`` =
64+
Chart.Bubble3D(
65+
xyz = [1,3,2; 6,5,4; 7,9,8],
66+
sizes = [20; 40; 30],
67+
MultiText = ["A"; "B"; "C"],
68+
TextPosition = StyleParam.TextPosition.TopLeft,
69+
UseDefaults = false
70+
)
71+
|> Chart.withXAxisStyle("x-axis", Id=StyleParam.SubPlotId.Scene 1)
72+
|> Chart.withYAxisStyle("y-axis", Id=StyleParam.SubPlotId.Scene 1)
73+
|> Chart.withZAxisStyle("z-axis")
74+
75+
module Surface =
76+
77+
let ``Peak and sink surface plot`` =
78+
79+
//---------------------- Create example data ----------------------
80+
let size = 100
81+
let x = linspace(-2. * Math.PI, 2. * Math.PI, size)
82+
let y = linspace(-2. * Math.PI, 2. * Math.PI, size)
83+
84+
let f x y = - (5. * x / (x**2. + y**2. + 1.) )
85+
86+
let z =
87+
Array.init size (fun i ->
88+
Array.init size (fun j -> f x.[j] y.[i] )
89+
)
90+
91+
Chart.Surface(zData = z, UseDefaults = false)
92+
93+
let ``Surface plot with x/y indices mapping to z matrix with contours`` =
94+
let x' = [0.;2.5]
95+
let y' = [0.;2.5]
96+
let z' = [
97+
[1.;1.;]; // row wise (length x)
98+
[1.;2.;];
99+
] // column (length y)
100+
101+
Chart.Surface(zData = z', X = x', Y = y', Opacity=0.5, Contours=Contours.initXyz(Show=true), UseDefaults = false)
102+
103+
104+
module Mesh3D =
105+
106+
let ``Mesh3D chart with random x/x/z data`` =
107+
108+
let rnd = System.Random(5)
109+
let x = Array.init 50 (fun _ -> rnd.NextDouble())
110+
let y = Array.init 50 (fun _ -> rnd.NextDouble())
111+
let z = Array.init 50 (fun _ -> rnd.NextDouble())
112+
113+
Chart.Mesh3D(
114+
x = x,
115+
y = y,
116+
z = z,
117+
FlatShading = true,
118+
Contour = Contour.init(Show = true),
119+
UseDefaults = false
120+
)
121+
122+
module Cone =
123+
124+
let ``Simple cone chart`` =
125+
Chart.Cone(
126+
x = [1; 1; 1],
127+
y = [1; 2; 3],
128+
z = [1; 1; 1],
129+
u = [1; 2; 3],
130+
v = [1; 1; 2],
131+
w = [4; 4; 1],
132+
ColorScale = StyleParam.Colorscale.Viridis,
133+
UseDefaults = false
134+
)
135+
136+
module StreamTube =
137+
138+
let ``Simple StreamTube chart `` =
139+
Chart.StreamTube(
140+
x = [0; 0; 0],
141+
y = [0; 1; 2],
142+
z = [0; 0; 0],
143+
u = [0; 0; 0],
144+
v = [1; 1; 1],
145+
w = [0; 0; 0],
146+
ColorScale = StyleParam.Colorscale.Viridis,
147+
UseDefaults = false
148+
)
149+
150+
module Volume =
151+
152+
let ``Fancy mgrid based volume chart`` =
153+
let x,y,z = mgrid(1.,2.,4)
154+
Chart.Volume(
155+
x = (x |> Array.concat |> Array.concat |> Array.map (fun x -> Math.Round(x,3))),
156+
y = (y |> Array.concat |> Array.concat |> Array.map (fun x -> Math.Round(x,3))),
157+
z = (z |> Array.concat |> Array.concat |> Array.map (fun x -> Math.Round(x,3))),
158+
value = (z |> Array.concat |> Array.concat |> Array.map (fun x -> Math.Round(x,3))),
159+
ColorScale = StyleParam.Colorscale.Viridis,
160+
UseDefaults = false
161+
)
162+
163+
module IsoSurface =
164+
165+
let ``Fancy mgrid based isosurface chart`` =
166+
let x,y,z = mgrid(1.,2.,4)
167+
Chart.IsoSurface(
168+
x = (x |> Array.concat |> Array.concat |> Array.map (fun x -> Math.Round(x,3))),
169+
y = (y |> Array.concat |> Array.concat |> Array.map (fun x -> Math.Round(x,3))),
170+
z = (z |> Array.concat |> Array.concat |> Array.map (fun x -> Math.Round(x,3))),
171+
value = (z |> Array.concat |> Array.concat |> Array.map (fun x -> Math.Round(x,3))),
172+
ColorScale = StyleParam.Colorscale.Viridis,
173+
UseDefaults = false
174+
)

tests/Common/FSharpTestBase/TestUtils.fs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,25 @@ open Plotly.NET
77
open DynamicObj
88
open Newtonsoft.Json
99

10+
module DataGeneration =
11+
12+
//---------------------- Generate linearly spaced vector ----------------------
13+
let linspace (min,max,n) =
14+
if n <= 2 then failwithf "n needs to be larger then 2"
15+
let bw = float (max - min) / (float n - 1.)
16+
Array.init n (fun i -> min + (bw * float i))
17+
18+
//-------------------- Generate linearly spaced mesh grid ---------------------
19+
let mgrid (min,max,n) =
20+
21+
let data = linspace(min,max,n)
22+
23+
let z = [|for i in 1 .. n do [|for i in 1 .. n do yield data|]|]
24+
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]|]|]|]
25+
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]|]|]|]
26+
27+
x,y,z
28+
1029
module HtmlCodegen =
1130

1231
let getLogoPNG() =

tests/CoreTests/CoreTests/CoreTests.fsproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
<EmbeddedResource Include="..\..\..\src\Plotly.NET\plotly-2.19.1.min.js.LICENSE.txt" />
1313
<!--Test charts-->
1414
<Compile Include="HTMLCodegen\Chart2D.fs" />
15+
<Compile Include="HtmlCodegen\Chart3D.fs" />
1516
<Compile Include="HtmlCodegen\ChartDomain.fs" />
1617
<!--HTMLCodegen-->
1718

@@ -28,7 +29,6 @@
2829
<Compile Include="Traces\TraceID.fs" />
2930
<Compile Include="HtmlCodegen\SimpleTests.fs" />
3031
<Compile Include="HtmlCodegen\ChartLayout.fs" />
31-
<Compile Include="HtmlCodegen\Charts3D.fs" />
3232
<Compile Include="HtmlCodegen\DistributionCharts.fs" />
3333
<Compile Include="HtmlCodegen\GeoMapCharts.fs" />
3434
<Compile Include="HtmlCodegen\MapboxMapCharts.fs" />

0 commit comments

Comments
 (0)