Skip to content

Commit 02614cb

Browse files
committed
Add tests layout for adding upstream features from plotlyjs, add tests for shapelabel
1 parent 7918c8e commit 02614cb

File tree

6 files changed

+144
-32
lines changed

6 files changed

+144
-32
lines changed

2.19.fs

Whitespace-only changes.

tests/Common/FSharpTestBase/FSharpTestBase.fsproj

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
<Compile Include="TestCharts\ChartCarpetTestCharts.fs" />
2222
<Compile Include="TestCharts\ChartDomainTestCharts.fs" />
2323
<Compile Include="TestCharts\ChartSmithTestCharts.fs" />
24+
<Compile Include="TestCharts\UpstreamFeatures\2.19.fs" />
2425
</ItemGroup>
2526

2627
<ItemGroup>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
module PlotlyJS_2_19_TestCharts
2+
3+
open Plotly.NET
4+
open Plotly.NET.TraceObjects
5+
open Plotly.NET.LayoutObjects
6+
7+
module ShapeLabel =
8+
9+
let internal x = [1.; 2.; 3.; 4.; 5.; 6.; 7.; 8.; 9.; 10.; ]
10+
let internal y = [2.; 1.5; 5.; 1.5; 3.; 2.5; 2.5; 1.5; 3.5; 1.]
11+
12+
let internal shapes =
13+
[
14+
Shape.init(
15+
ShapeType=StyleParam.ShapeType.Rectangle,
16+
X0=2.,X1=4.,Y0=3.,Y1=4.,
17+
Opacity=0.3,
18+
FillColor=Color.fromHex "#d3d3d3",
19+
Label = ShapeLabel.init(Text="Rectangle")
20+
)
21+
Shape.init(
22+
ShapeType=StyleParam.ShapeType.Circle,
23+
X0=5.,X1=7.,Y0=3.,Y1=4.,
24+
Opacity=0.3,
25+
FillColor=Color.fromHex "#d3d3d3",
26+
Label = ShapeLabel.init(Text="Circle", Padding = 20)
27+
)
28+
Shape.init(
29+
ShapeType=StyleParam.ShapeType.Line,
30+
X0=1.,X1=2.,Y0=1.,Y1=2.,
31+
Opacity=0.3,
32+
FillColor=Color.fromHex "#d3d3d3",
33+
Label = ShapeLabel.init(Text="Line")
34+
)
35+
Shape.init(
36+
ShapeType=StyleParam.ShapeType.SvgPath,
37+
Path=" M 3,7 L2,8 L2,9 L3,10, L4,10 L5,9 L5,8 L4,7 Z",
38+
Label = ShapeLabel.init(Text="SVGPath", TextAngle = StyleParam.TextAngle.Degrees 33)
39+
)
40+
]
41+
42+
43+
let ``Rectangular shape with label`` =
44+
Chart.Line(x = x,y = y, UseDefaults = false)
45+
|> Chart.withShape(shapes[0])
46+
47+
let ``Circular shape with label and padding`` =
48+
Chart.Line(x = x,y = y, UseDefaults = false)
49+
|> Chart.withShape(shapes[1])
50+
51+
let ``Line shape with label`` =
52+
Chart.Line(x = x,y = y, UseDefaults = false)
53+
|> Chart.withShape(shapes[2])
54+
55+
let ``SVGPath shape with angled label`` =
56+
Chart.Line(x = x,y = y, UseDefaults = false)
57+
|> Chart.withShape(shapes[3])

tests/ConsoleApps/FSharpConsole/Program.fs

+35-32
Original file line numberDiff line numberDiff line change
@@ -12,38 +12,41 @@ open Newtonsoft.Json
1212
[<EntryPoint>]
1313
let main argv =
1414
let x = [1.; 2.; 3.; 4.; 5.; 6.; 7.; 8.; 9.; 10.; ]
15-
let y' = [2.; 1.5; 5.; 1.5; 3.; 2.5; 2.5; 1.5; 3.5; 1.]
16-
let s1 =
17-
Shape.init(
18-
ShapeType=StyleParam.ShapeType.Rectangle,
19-
X0=2.,X1=4.,Y0=3.,Y1=4.,
20-
Opacity=0.3,
21-
FillColor=Color.fromHex "#d3d3d3",
22-
Label = ShapeLabel.init(Text="Rectangle")
23-
)
24-
let s2 =
25-
Shape.init(
26-
ShapeType=StyleParam.ShapeType.Circle,
27-
X0=5.,X1=7.,Y0=3.,Y1=4.,
28-
Opacity=0.3,
29-
FillColor=Color.fromHex "#d3d3d3",
30-
Label = ShapeLabel.init(Text="Circle")
31-
)
32-
let s3 =
33-
Shape.init(
34-
ShapeType=StyleParam.ShapeType.Line,
35-
X0=1.,X1=2.,Y0=1.,Y1=2.,
15+
let y = [2.; 1.5; 5.; 1.5; 3.; 2.5; 2.5; 1.5; 3.5; 1.]
16+
17+
let shapes =
18+
[
19+
Shape.init(
20+
ShapeType=StyleParam.ShapeType.Rectangle,
21+
X0=2.,X1=4.,Y0=3.,Y1=4.,
3622
Opacity=0.3,
3723
FillColor=Color.fromHex "#d3d3d3",
38-
Label = ShapeLabel.init(Text="Line")
39-
)
40-
let s4 =
41-
Shape.init(
42-
ShapeType=StyleParam.ShapeType.SvgPath,
43-
Path=" M 3,7 L2,8 L2,9 L3,10, L4,10 L5,9 L5,8 L4,7 Z",
44-
Label = ShapeLabel.init(Text="SVGPath", TextAngle = StyleParam.TextAngle.Degrees 33)
45-
)
46-
Chart.Line(x = x,y = y',Name="line", UseDefaults = false)
47-
|> Chart.withShapes([s1;s2;s3;s4])
48-
|> Chart.show
24+
Label = ShapeLabel.init(Text="Rectangle")
25+
)
26+
Shape.init(
27+
ShapeType=StyleParam.ShapeType.Circle,
28+
X0=5.,X1=7.,Y0=3.,Y1=4.,
29+
Opacity=0.3,
30+
FillColor=Color.fromHex "#d3d3d3",
31+
Label = ShapeLabel.init(Text="Circle", Padding = 20)
32+
)
33+
Shape.init(
34+
ShapeType=StyleParam.ShapeType.Line,
35+
X0=1.,X1=2.,Y0=1.,Y1=2.,
36+
Opacity=0.3,
37+
FillColor=Color.fromHex "#d3d3d3",
38+
Label = ShapeLabel.init(Text="Line")
39+
)
40+
Shape.init(
41+
ShapeType=StyleParam.ShapeType.SvgPath,
42+
Path=" M 3,7 L2,8 L2,9 L3,10, L4,10 L5,9 L5,8 L4,7 Z",
43+
Label = ShapeLabel.init(Text="SVGPath", TextAngle = StyleParam.TextAngle.Degrees 33)
44+
)
45+
]
46+
shapes
47+
|> Seq.iter (fun shape ->
48+
Chart.Line(x = x,y = y, UseDefaults = false)
49+
|> Chart.withShape(shape)
50+
|> Chart.show
51+
)
4952
0

tests/CoreTests/CoreTests/CoreTests.fsproj

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
<Compile Include="Traces\TraceStaticMembers.fs" />
3535
<Compile Include="Traces\TraceStyle.fs" />
3636
<Compile Include="Traces\TraceID.fs" />
37+
<Compile Include="UpstreamFeatures\2.19.fs" />
3738
<Compile Include="Main.fs" />
3839
</ItemGroup>
3940

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
module CoreTests.UpstreamFeatures.PlotlyJS_2_19
2+
3+
open Expecto
4+
open Plotly.NET
5+
open Plotly.NET.LayoutObjects
6+
open Plotly.NET.TraceObjects
7+
open Plotly.NET.GenericChart
8+
9+
open TestUtils.HtmlCodegen
10+
open PlotlyJS_2_19_TestCharts
11+
12+
module ShapeLabel =
13+
[<Tests>]
14+
let ``ShapeLabel chart HTML codegeneration tests`` =
15+
testList "UpstreamFeatures.PlotlyJS_2_19" [
16+
testList "ShapeLabel" [
17+
testCase "Rectangular shape label data" ( fun () ->
18+
"""var data = [{"type":"scatter","mode":"lines","x":[1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0,10.0],"y":[2.0,1.5,5.0,1.5,3.0,2.5,2.5,1.5,3.5,1.0],"marker":{},"line":{}}];"""
19+
|> chartGeneratedContains ShapeLabel.``Rectangular shape with label``
20+
)
21+
testCase "Rectangular shape label layout" ( fun () ->
22+
"""var layout = {"shapes":[{"fillcolor":"rgba(211, 211, 211, 1.0)","label":{"text":"Rectangle"},"opacity":0.3,"type":"rect","x0":2.0,"x1":4.0,"y0":3.0,"y1":4.0}]};"""
23+
|> chartGeneratedContains ShapeLabel.``Rectangular shape with label``
24+
)
25+
testCase "Circular shape label with padding data" ( fun () ->
26+
"""var data = [{"type":"scatter","mode":"lines","x":[1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0,10.0],"y":[2.0,1.5,5.0,1.5,3.0,2.5,2.5,1.5,3.5,1.0],"marker":{},"line":{}}];"""
27+
|> chartGeneratedContains ShapeLabel.``Circular shape with label and padding``
28+
)
29+
testCase "Circular shape label with padding layout" ( fun () ->
30+
"""var layout = {"shapes":[{"fillcolor":"rgba(211, 211, 211, 1.0)","label":{"padding":20,"text":"Circle"},"opacity":0.3,"type":"circle","x0":5.0,"x1":7.0,"y0":3.0,"y1":4.0}]};"""
31+
|> chartGeneratedContains ShapeLabel.``Circular shape with label and padding``
32+
)
33+
testCase "Line shape label data" ( fun () ->
34+
"""var data = [{"type":"scatter","mode":"lines","x":[1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0,10.0],"y":[2.0,1.5,5.0,1.5,3.0,2.5,2.5,1.5,3.5,1.0],"marker":{},"line":{}}];"""
35+
|> chartGeneratedContains ShapeLabel.``Line shape with label``
36+
)
37+
testCase "Line shape label layout" ( fun () ->
38+
"""var layout = {"shapes":[{"fillcolor":"rgba(211, 211, 211, 1.0)","label":{"text":"Line"},"opacity":0.3,"type":"line","x0":1.0,"x1":2.0,"y0":1.0,"y1":2.0}]};"""
39+
|> chartGeneratedContains ShapeLabel.``Line shape with label``
40+
)
41+
testCase "SVGPath angled shape label data" ( fun () ->
42+
"""var data = [{"type":"scatter","mode":"lines","x":[1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0,10.0],"y":[2.0,1.5,5.0,1.5,3.0,2.5,2.5,1.5,3.5,1.0],"marker":{},"line":{}}];"""
43+
|> chartGeneratedContains ShapeLabel.``SVGPath shape with angled label``
44+
)
45+
testCase "SVGPath angled shape label layout" ( fun () ->
46+
"""var layout = {"shapes":[{"label":{"text":"SVGPath","textangle":33.0},"path":" M 3,7 L2,8 L2,9 L3,10, L4,10 L5,9 L5,8 L4,7 Z","type":"path"}]};"""
47+
|> chartGeneratedContains ShapeLabel.``SVGPath shape with angled label``
48+
)
49+
]
50+
]

0 commit comments

Comments
 (0)