Skip to content

Commit 8d017b6

Browse files
committed
Add Smith chart tests
1 parent b75cf59 commit 8d017b6

File tree

4 files changed

+133
-149
lines changed

4 files changed

+133
-149
lines changed

src/Plotly.NET/Playground.fsx

Lines changed: 34 additions & 146 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,12 @@
6262
#load "RadialAxis.fs"
6363
#load "Polar.fs"
6464

65+
#I "Layout/ObjectAbstractions/Smith"
66+
67+
#load "ImaginaryAxis.fs"
68+
#load "RealAxis.fs"
69+
#load "Smith.fs"
70+
6571
#I "Layout/ObjectAbstractions/Ternary"
6672

6773
#load "Ternary.fs"
@@ -118,6 +124,7 @@
118124
#load "TraceTernary.fs"
119125
#load "TraceCarpet.fs"
120126
#load "TraceDomain.fs"
127+
#load "TraceSmith.fs"
121128
#load "TraceID.fs"
122129

123130
#I "Config/ObjectAbstractions"
@@ -150,6 +157,7 @@
150157
#load "ChartTernary.fs"
151158
#load "ChartCarpet.fs"
152159
#load "ChartDomain.fs"
160+
#load "ChartSmith.fs"
153161

154162
#I "CSharpLayer"
155163

@@ -177,158 +185,38 @@ open Plotly.NET
177185
open System
178186
open Plotly.NET
179187

180-
181-
let y = [2.; 1.5; 5.; 1.5; 3.; 2.5; 2.5; 1.5; 3.5; 1.]
182-
let x = ["bin1";"bin2";"bin1";"bin2";"bin1";"bin2";"bin1";"bin1";"bin2";"bin1"]
183-
184-
let y2 = [2.; 1.5; 5.; 1.5; 3.; 2.5; 2.5; 1.5; 3.5; 1.]
185-
let x2 = ["bin3";"bin4";"bin3";"bin4";"bin3";"bin4";"bin3";"bin3";"bin4";"bin3"]
186-
187-
let violin1 =
188-
Chart.Violin (
189-
x,y,
190-
ShowBox = true,
191-
BoxFillColor = Color.fromKeyword ColorKeyword.Red
192-
)
193-
|> Chart.withConfigStyle(
194-
StaticPlot = false,
195-
Editable= true,
196-
PlotlyServerUrl = "https://chart-studio.plotly.com",
197-
ModeBarButtonsToAdd = [
198-
StyleParam.ModeBarButton.DrawRect
199-
]
200-
)
201-
202-
let violin2 =
203-
Chart.Violin (
204-
x2,y2,
205-
ShowBox = true,
206-
BoxFillColor = Color.fromKeyword ColorKeyword.Green
207-
)
208-
|> Chart.withConfigStyle(
209-
ShowEditInChartStudio = true,
210-
ModeBarButtonsToAdd = [
211-
StyleParam.ModeBarButton.DrawLine
212-
]
213-
)
214-
215-
violin2
216-
|> GenericChart.getConfig
217-
|> DynObj.print
218-
219-
violin1
220-
|> GenericChart.getConfig
221-
|> DynObj.print
222-
223-
[
224-
violin1
225-
violin2
226-
]
227-
|> Chart.combine
228-
|> Chart.withTraceInfo(
229-
Name = "violins",
230-
LegendGroup = "violins",
231-
LegendGroupTitle = Title.init("Some violins m8")
188+
Chart.ScatterSmith(
189+
[0.5; 1.; 2.; 3.],
190+
[0.5; 1.; 2.; 3.],
191+
StyleParam.Mode.Lines_Markers_Text,
192+
MultiText = ["Pretty"; "Cool"; "Plot"; "Huh?"],
193+
TextPosition = StyleParam.TextPosition.TopCenter,
194+
UseDefaults = false
232195
)
233196
|> Chart.show
234197

235-
let table1 =
236-
let header = ["<b>RowIndex</b>";"A";"simple";"table"]
237-
let rows =
238-
[
239-
["0";"I" ;"am" ;"a"]
240-
["1";"little";"example";"!"]
241-
]
242-
Chart.Table(header, rows)
243-
|> Chart.show
244-
245-
Trace2D.initHistogram(
246-
Trace2DStyle.Histogram(
247-
Y = [1;2;3;3;4;4;4;5;6;6;7]
248-
)
198+
Chart.PointSmith(
199+
[0.5; 1.; 2.; 3.],
200+
[0.5; 1.; 2.; 3.],
201+
UseDefaults = false
249202
)
250-
|> GenericChart.ofTraceObject true
251203
|> Chart.show
252204

253-
let contour =
254-
[
255-
Chart.Carpet(
256-
"contour",
257-
A = [0.; 1.; 2.; 3.; 0.; 1.; 2.; 3.; 0.; 1.; 2.; 3.],
258-
B = [4.; 4.; 4.; 4.; 5.; 5.; 5.; 5.; 6.; 6.; 6.; 6.],
259-
X = [2.; 3.; 4.; 5.; 2.2; 3.1; 4.1; 5.1; 1.5; 2.5; 3.5; 4.5],
260-
Y = [1.; 1.4; 1.6; 1.75; 2.; 2.5; 2.7; 2.75; 3.; 3.5; 3.7; 3.75],
261-
AAxis = LinearAxis.initCarpet(
262-
TickPrefix = "a = ",
263-
Smoothing = 0.,
264-
MinorGridCount = 9,
265-
AxisType = StyleParam.AxisType.Linear
266-
),
267-
BAxis = LinearAxis.initCarpet(
268-
TickPrefix = "b = ",
269-
Smoothing = 0.,
270-
MinorGridCount = 9,
271-
AxisType = StyleParam.AxisType.Linear
272-
),
273-
UseDefaults = false,
274-
Opacity = 0.75
275-
)
276-
Chart.ContourCarpet(
277-
[1.; 1.96; 2.56; 3.0625; 4.; 5.0625; 1.; 7.5625; 9.; 12.25; 15.21; 14.0625],
278-
"contour",
279-
A = [0; 1; 2; 3; 0; 1; 2; 3; 0; 1; 2; 3],
280-
B = [4; 4; 4; 4; 5; 5; 5; 5; 6; 6; 6; 6],
281-
UseDefaults = false,
282-
ContourLineColor = Color.fromKeyword White,
283-
ShowContourLabels = true
284-
)
285-
]
286-
|> Chart.combine
287-
|> Chart.show
288-
289-
Chart.BubbleTernary(
290-
[
291-
1,2,3,5
292-
2,2,2,15
293-
3,2,1,25
294-
]
205+
Chart.LineSmith(
206+
[0.5; 1.; 2.; 3.],
207+
[0.5; 1.; 2.; 3.],
208+
LineDash = StyleParam.DrawingStyle.DashDot,
209+
LineColor = Color.fromKeyword Purple,
210+
UseDefaults = false
295211
)
296212
|> Chart.show
297213

298-
let multiTraceGrid =
299-
[
300-
Chart.Point([1,2; 2,3], UseDefaults = false)
301-
Chart.PointTernary([1,2,3; 2,3,4], UseDefaults = false)
302-
Chart.Heatmap([[1; 2];[3; 4]], ShowScale=false, UseDefaults = false)
303-
Chart.Point3D([1,3,2], UseDefaults = false)
304-
Chart.PointMapbox([1,2], UseDefaults = false) |> Chart.withMapbox(Mapbox.init(Style = StyleParam.MapboxStyle.OpenStreetMap))
305-
[
306-
// you can use nested combined charts, but they have to have the same trace type (Cartesian2D in this case)
307-
let y = [2.; 1.5; 5.; 1.5; 2.; 2.5; 2.1; 2.5; 1.5; 1.;2.; 1.5; 5.; 1.5; 3.; 2.5; 2.5; 1.5; 3.5; 1.]
308-
Chart.BoxPlot("y" ,y,Name="bin1",Jitter=0.1,BoxPoints=StyleParam.BoxPoints.All, UseDefaults = false);
309-
Chart.BoxPlot("y'",y,Name="bin2",Jitter=0.1,BoxPoints=StyleParam.BoxPoints.All, UseDefaults = false);
310-
]
311-
|> Chart.combine
312-
]
313-
|> Chart.Grid(2,3)
314-
|> Chart.withSize(1000,1000)
315-
|> Chart.show
316-
317-
let multiTraceSingleStack =
318-
[
319-
Chart.Point([1,2; 2,3], UseDefaults = false)
320-
Chart.PointTernary([1,2,3; 2,3,4], UseDefaults = false)
321-
Chart.Heatmap([[1; 2];[3; 4]], ShowScale=false, UseDefaults = false)
322-
Chart.Point3D([1,3,2], UseDefaults = false)
323-
Chart.PointMapbox([1,2], UseDefaults = false) |> Chart.withMapbox(Mapbox.init(Style = StyleParam.MapboxStyle.OpenStreetMap))
324-
[
325-
// you can use nested combined charts, but they have to have the same trace type (Cartesian2D in this case)
326-
let y = [2.; 1.5; 5.; 1.5; 2.; 2.5; 2.1; 2.5; 1.5; 1.;2.; 1.5; 5.; 1.5; 3.; 2.5; 2.5; 1.5; 3.5; 1.]
327-
Chart.BoxPlot("y" ,y,Name="bin1",Jitter=0.1,BoxPoints=StyleParam.BoxPoints.All, UseDefaults = false);
328-
Chart.BoxPlot("y'",y,Name="bin2",Jitter=0.1,BoxPoints=StyleParam.BoxPoints.All, UseDefaults = false);
329-
]
330-
|> Chart.combine
331-
]
332-
|> Chart.SingleStack()
333-
|> Chart.withSize(1000,1000)
334-
|> Chart.show
214+
Chart.BubbleSmith(
215+
[0.5; 1.; 2.; 3.],
216+
[0.5; 1.; 2.; 3.],
217+
sizes = [10;20;30;40],
218+
MultiText=["one";"two";"three";"four";"five";"six";"seven"],
219+
TextPosition=StyleParam.TextPosition.TopCenter,
220+
UseDefaults = false
221+
)
222+
|> Chart.show

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -271,12 +271,12 @@ let streamTubeChart =
271271

272272
[<Tests>]
273273
let ``StreamTube charts`` =
274-
testList "StreamTube.Volume charts" [
275-
testCase "Volume data" ( fun () ->
274+
testList "Charts3D.StreamTube charts" [
275+
testCase "StreamTube data" ( fun () ->
276276
"""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"}];"""
277277
|> chartGeneratedContains streamTubeChart
278278
);
279-
testCase "Volume layout" ( fun () ->
279+
testCase "StreamTube layout" ( fun () ->
280280
emptyLayout streamTubeChart
281281
);
282282
]
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
module Tests.SmithCharts
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 scatterSmithChart =
13+
Chart.ScatterSmith(
14+
[0.5; 1.; 2.; 3.],
15+
[0.5; 1.; 2.; 3.],
16+
StyleParam.Mode.Lines_Markers_Text,
17+
MultiText = ["Pretty"; "Cool"; "Plot"; "Huh?"],
18+
TextPosition = StyleParam.TextPosition.TopCenter,
19+
UseDefaults = false
20+
)
21+
22+
let pointSmithChart =
23+
Chart.PointSmith(
24+
[0.5; 1.; 2.; 3.],
25+
[0.5; 1.; 2.; 3.],
26+
UseDefaults = false
27+
)
28+
29+
let lineSmithChart =
30+
Chart.LineSmith(
31+
[0.5; 1.; 2.; 3.],
32+
[0.5; 1.; 2.; 3.],
33+
LineDash = StyleParam.DrawingStyle.DashDot,
34+
LineColor = Color.fromKeyword Purple,
35+
UseDefaults = false
36+
)
37+
38+
let bubbleSmithChart =
39+
Chart.BubbleSmith(
40+
[0.5; 1.; 2.; 3.],
41+
[0.5; 1.; 2.; 3.],
42+
sizes = [10;20;30;40],
43+
MultiText=["one";"two";"three";"four";"five";"six";"seven"],
44+
TextPosition=StyleParam.TextPosition.TopCenter,
45+
UseDefaults = false
46+
)
47+
48+
49+
[<Tests>]
50+
let ``Smith Scatter charts`` =
51+
testList "SmithCharts.Scatter charts" [
52+
testCase "Scatter data" ( fun () ->
53+
"""var data = [{"type":"scattersmith","mode":"lines+markers+text","imag":[0.5,1.0,2.0,3.0],"real":[0.5,1.0,2.0,3.0],"text":["Pretty","Cool","Plot","Huh?"],"textposition":"top center","marker":{},"line":{}}];"""
54+
|> chartGeneratedContains scatterSmithChart
55+
)
56+
testCase "Scatter layout" ( fun () ->
57+
emptyLayout scatterSmithChart
58+
)
59+
]
60+
61+
[<Tests>]
62+
let ``Smith Point charts`` =
63+
testList "SmithCharts.Point charts" [
64+
testCase "Point data" ( fun () ->
65+
"""var data = [{"type":"scattersmith","mode":"markers","imag":[0.5,1.0,2.0,3.0],"real":[0.5,1.0,2.0,3.0],"marker":{},"line":{}}];"""
66+
|> chartGeneratedContains pointSmithChart
67+
)
68+
testCase "Point layout" ( fun () ->
69+
emptyLayout pointSmithChart
70+
)
71+
]
72+
73+
[<Tests>]
74+
let ``Smith Line charts`` =
75+
testList "SmithCharts.Line charts" [
76+
testCase "Line data" ( fun () ->
77+
"""var data = [{"type":"scattersmith","mode":"lines","imag":[0.5,1.0,2.0,3.0],"real":[0.5,1.0,2.0,3.0],"marker":{},"line":{"color":"rgba(128, 0, 128, 1.0)","dash":"dashdot"}}];"""
78+
|> chartGeneratedContains lineSmithChart
79+
)
80+
testCase "Line layout" ( fun () ->
81+
emptyLayout lineSmithChart
82+
)
83+
]
84+
85+
[<Tests>]
86+
let ``Smith Bubble charts`` =
87+
testList "SmithCharts.Bubble charts" [
88+
testCase "Bubble data" ( fun () ->
89+
"""var data = [{"type":"scattersmith","mode":"markers+text","imag":[0.5,1.0,2.0,3.0],"real":[0.5,1.0,2.0,3.0],"text":["one","two","three","four","five","six","seven"],"textposition":"top center","marker":{"size":[10,20,30,40]},"line":{}}];"""
90+
|> chartGeneratedContains bubbleSmithChart
91+
)
92+
testCase "Bubble layout" ( fun () ->
93+
emptyLayout bubbleSmithChart
94+
)
95+
]

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
<Compile Include="HtmlCodegen\TernaryCharts.fs" />
3030
<Compile Include="HtmlCodegen\CarpetCharts.fs" />
3131
<Compile Include="HtmlCodegen\CategoricalCharts.fs" />
32+
<Compile Include="HtmlCodegen\SmithCharts.fs" />
3233
<Compile Include="Main.fs" />
3334
</ItemGroup>
3435

0 commit comments

Comments
 (0)