Skip to content

Commit 2518abd

Browse files
committed
Refactor FinanceChart tests
1 parent 4308d80 commit 2518abd

File tree

6 files changed

+198
-214
lines changed

6 files changed

+198
-214
lines changed

tests/Common/FSharpTestBase/TestCharts/Chart2DTestCharts.fs

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,22 @@ module StackedArea =
135135
]
136136
|> Chart.combine
137137

138-
module Funnel = ()
138+
module Funnel =
139+
140+
let ``Simple funnel chart`` =
141+
let y = [|"Sales person A"; "Sales person B"; "Sales person C"; "Sales person D"; "Sales person E"|]
142+
let x = [|1200.; 909.4; 600.6; 300.; 80.|]
143+
144+
// Customize the connector lines used to connect the funnel bars
145+
let connectorLine = Line.init (Color=Color.fromString "royalblue", Dash=StyleParam.DrawingStyle.Dot, Width=3.)
146+
let connector = FunnelConnector.init(Line=connectorLine)
147+
148+
// Customize the outline of the funnel bars
149+
let line = Line.init(Width=2.,Color=Color.fromString "3E4E88")
150+
151+
Chart.Funnel (x = x, y = y,MarkerColor=Color.fromString "59D4E8", MarkerOutline=line, Connector=connector, UseDefaults = false)
152+
|> Chart.withMarginSize(Left=100)
153+
139154

140155
module StackedFunnel = ()
141156

@@ -398,9 +413,33 @@ module Contour =
398413
Chart.Contour(zData = z, UseDefaults = false)
399414
|> Chart.withSize(600.,600.)
400415

401-
module OHLC = ()
416+
module OHLC =
417+
418+
let internal candles =
419+
[|("2020-01-17T13:40:00", 0.68888, 0.68888, 0.68879, 0.6888);
420+
("2020-01-17T13:41:00", 0.68883, 0.68884, 0.68875, 0.68877);
421+
("2020-01-17T13:42:00", 0.68878, 0.68889, 0.68878, 0.68886);
422+
("2020-01-17T13:43:00", 0.68886, 0.68886, 0.68876, 0.68879);
423+
("2020-01-17T13:44:00", 0.68879, 0.68879, 0.68873, 0.68874);
424+
("2020-01-17T13:45:00", 0.68875, 0.68877, 0.68867, 0.68868);
425+
("2020-01-17T13:46:00", 0.68869, 0.68887, 0.68869, 0.68883);
426+
("2020-01-17T13:47:00", 0.68883, 0.68899, 0.68883, 0.68899);
427+
("2020-01-17T13:48:00", 0.68898, 0.689, 0.68885, 0.68889);
428+
("2020-01-17T13:49:00", 0.68889, 0.68893, 0.68881, 0.68893);
429+
("2020-01-17T13:50:00", 0.68891, 0.68896, 0.68886, 0.68891);
430+
|]
431+
|> Array.map (fun (d,o,h,l,c)->System.DateTime.Parse d, StockData.Create(o,h,l,c))
432+
433+
let ``Simple OHLC chart`` = Chart.OHLC(stockTimeSeries = candles, UseDefaults = false)
434+
435+
let ``Simple OHLC chart without range slider`` = Chart.OHLC(stockTimeSeries = candles, ShowXAxisRangeSlider = false, UseDefaults = false)
436+
437+
module Candlestick =
438+
439+
let ``Simple candlestick chart`` = Chart.Candlestick(stockTimeSeries = OHLC.candles, UseDefaults = false)
440+
441+
let ``Simple candlestick chart without range slider`` = Chart.Candlestick(stockTimeSeries = OHLC.candles, ShowXAxisRangeSlider = false, UseDefaults = false)
402442

403-
module Candlestick = ()
404443

405444
module Splom =
406445

tests/Common/FSharpTestBase/TestCharts/ChartDomainTestCharts.fs

Lines changed: 74 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,35 @@ module Doughnut =
5252
UseDefaults = false
5353
)
5454

55-
module FunnelArea = ()
55+
module FunnelArea =
56+
57+
let ``Simple funnelarea chart`` =
58+
let values = [|5; 4; 3; 2; 1|]
59+
let text = [|"The 1st"; "The 2nd"; "The 3rd"; "The 4th"; "The 5th"|]
60+
let line = Line.init (Color=Color.fromString "purple", Width=3.)
61+
Chart.FunnelArea(values=values, MultiText=text, SectionOutline=line, UseDefaults = false)
62+
63+
64+
65+
let ``Styled funnelarea chart`` =
66+
let values = [|5; 4; 3|]
67+
let labels = [|"The 1st"; "The 2nd"; "The 3rd"|]
68+
69+
Chart.FunnelArea(
70+
values = values,
71+
Labels = labels,
72+
MultiText = labels,
73+
SectionColors = [
74+
Color.fromKeyword Aqua
75+
Color.fromKeyword Salmon
76+
Color.fromKeyword Tan
77+
],
78+
SectionOutlineColor = Color.fromKeyword Black,
79+
SectionOutlineWidth = 2.,
80+
AspectRatio = 0.75,
81+
BaseRatio = 0.1,
82+
UseDefaults = false
83+
)
5684

5785
module Sunburst = ()
5886

@@ -203,6 +231,50 @@ module Table =
203231
|> Chart.withSize(Width=chartwidth)
204232
|> Chart.withTitle "Sequence A"
205233

206-
module Indicator = ()
234+
module Indicator =
235+
236+
open Plotly.NET.TraceObjects
237+
open Plotly.NET.LayoutObjects
238+
239+
let ``Angular gauge indicator`` =
240+
ChartDomain.Chart.Indicator(
241+
value = 200.,
242+
mode = StyleParam.IndicatorMode.NumberDeltaGauge,
243+
Delta = IndicatorDelta.init(Reference=160),
244+
Range = StyleParam.Range.MinMax(0., 250.),
245+
Domain = Domain.init(Row = 0, Column = 0),
246+
UseDefaults = false
247+
)
248+
249+
let ``Bullet gauge indicator`` =
250+
Chart.Indicator(
251+
value = 120,
252+
mode = StyleParam.IndicatorMode.NumberDeltaGauge,
253+
DeltaReference = 90,
254+
Range = StyleParam.Range.MinMax(-200., 200.),
255+
GaugeShape = StyleParam.IndicatorGaugeShape.Bullet,
256+
ShowGaugeAxis = false,
257+
Domain = Domain.init(Row = 0, Column = 1),
258+
UseDefaults = false
259+
)
260+
261+
let ``Delta indicator with reference`` =
262+
Chart.Indicator(
263+
value = "300",
264+
mode = StyleParam.IndicatorMode.NumberDelta,
265+
DeltaReference = 90.,
266+
Domain = Domain.init(Row = 1, Column = 0),
267+
UseDefaults = false
268+
)
269+
270+
let ``Delta indicator`` =
271+
Chart.Indicator(
272+
value = 40.,
273+
mode = StyleParam.IndicatorMode.Delta,
274+
DeltaReference = 90.,
275+
Domain = Domain.init(Row = 1, Column = 1),
276+
UseDefaults = false
277+
)
278+
207279

208280
module Icicle = ()

tests/CoreTests/CoreTests/CoreTests.fsproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
<Compile Include="Traces\TraceID.fs" />
3131
<Compile Include="HtmlCodegen\SimpleTests.fs" />
3232
<Compile Include="HtmlCodegen\ChartLayout.fs" />
33-
<Compile Include="HtmlCodegen\FinanceCharts.fs" />
3433
<Compile Include="HtmlCodegen\PolarCharts.fs" />
3534
<Compile Include="HtmlCodegen\TernaryCharts.fs" />
3635
<Compile Include="HtmlCodegen\CarpetCharts.fs" />

tests/CoreTests/CoreTests/HTMLCodegen/Chart2D.fs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,14 @@ module Funnel =
149149
let ``Funnel chart HTML codegeneration tests`` =
150150
testList "HTMLCodegen.Chart2D" [
151151
testList "Funnel" [
152+
testCase "Funnel data" ( fun () ->
153+
"""var data = [{"type":"funnel","x":[1200.0,909.4,600.6,300.0,80.0],"y":["Sales person A","Sales person B","Sales person C","Sales person D","Sales person E"],"marker":{"color":"59D4E8","line":{"color":"3E4E88","width":2.0}},"connector":{"line":{"color":"royalblue","width":3.0,"dash":"dot"}}}];"""
154+
|> chartGeneratedContains Funnel.``Simple funnel chart``
155+
);
156+
testCase "Funnel layout" ( fun () ->
157+
"var layout = {\"margin\":{\"l\":100}};"
158+
|> chartGeneratedContains Funnel.``Simple funnel chart``
159+
);
152160
]
153161
]
154162

@@ -442,6 +450,22 @@ module OHLC =
442450
let ``OHLC chart HTML codegeneration tests`` =
443451
testList "HTMLCodegen.Chart2D" [
444452
testList "OHLC" [
453+
testCase "simple OHLC data" ( fun () ->
454+
"""var data = [{"type":"ohlc","x":["2020-01-17T13:40:00","2020-01-17T13:41:00","2020-01-17T13:42:00","2020-01-17T13:43:00","2020-01-17T13:44:00","2020-01-17T13:45:00","2020-01-17T13:46:00","2020-01-17T13:47:00","2020-01-17T13:48:00","2020-01-17T13:49:00","2020-01-17T13:50:00"],"close":[0.6888,0.68877,0.68886,0.68879,0.68874,0.68868,0.68883,0.68899,0.68889,0.68893,0.68891],"open":[0.68888,0.68883,0.68878,0.68886,0.68879,0.68875,0.68869,0.68883,0.68898,0.68889,0.68891],"high":[0.68888,0.68884,0.68889,0.68886,0.68879,0.68877,0.68887,0.68899,0.689,0.68893,0.68896],"low":[0.68879,0.68875,0.68878,0.68876,0.68873,0.68867,0.68869,0.68883,0.68885,0.68881,0.68886],"increasing":{"line":{}},"decreasing":{"line":{}}}];"""
455+
|> chartGeneratedContains OHLC.``Simple OHLC chart``
456+
);
457+
testCase "simple OHLC layout" ( fun () ->
458+
"""var layout = {"xaxis":{"rangeslider":{"yaxis":{}}}};"""
459+
|> chartGeneratedContains OHLC.``Simple OHLC chart``
460+
);
461+
testCase "OHLC no range slider data" ( fun () ->
462+
"""var data = [{"type":"ohlc","x":["2020-01-17T13:40:00","2020-01-17T13:41:00","2020-01-17T13:42:00","2020-01-17T13:43:00","2020-01-17T13:44:00","2020-01-17T13:45:00","2020-01-17T13:46:00","2020-01-17T13:47:00","2020-01-17T13:48:00","2020-01-17T13:49:00","2020-01-17T13:50:00"],"close":[0.6888,0.68877,0.68886,0.68879,0.68874,0.68868,0.68883,0.68899,0.68889,0.68893,0.68891],"open":[0.68888,0.68883,0.68878,0.68886,0.68879,0.68875,0.68869,0.68883,0.68898,0.68889,0.68891],"high":[0.68888,0.68884,0.68889,0.68886,0.68879,0.68877,0.68887,0.68899,0.689,0.68893,0.68896],"low":[0.68879,0.68875,0.68878,0.68876,0.68873,0.68867,0.68869,0.68883,0.68885,0.68881,0.68886],"increasing":{"line":{}},"decreasing":{"line":{}}}];"""
463+
|> chartGeneratedContains OHLC.``Simple OHLC chart without range slider``
464+
);
465+
testCase "OHLC no range slider layout" ( fun () ->
466+
"""var layout = {"xaxis":{"rangeslider":{"visible":false,"yaxis":{}}}};"""
467+
|> chartGeneratedContains OHLC.``Simple OHLC chart without range slider``
468+
);
445469
]
446470
]
447471

@@ -450,6 +474,22 @@ module Candlestick =
450474
let ``Candlestick chart HTML codegeneration tests`` =
451475
testList "HTMLCodegen.Chart2D" [
452476
testList "Candlestick" [
477+
testCase "simple Candlestick data" ( fun () ->
478+
"""var data = [{"type":"candlestick","x":["2020-01-17T13:40:00","2020-01-17T13:41:00","2020-01-17T13:42:00","2020-01-17T13:43:00","2020-01-17T13:44:00","2020-01-17T13:45:00","2020-01-17T13:46:00","2020-01-17T13:47:00","2020-01-17T13:48:00","2020-01-17T13:49:00","2020-01-17T13:50:00"],"close":[0.6888,0.68877,0.68886,0.68879,0.68874,0.68868,0.68883,0.68899,0.68889,0.68893,0.68891],"open":[0.68888,0.68883,0.68878,0.68886,0.68879,0.68875,0.68869,0.68883,0.68898,0.68889,0.68891],"high":[0.68888,0.68884,0.68889,0.68886,0.68879,0.68877,0.68887,0.68899,0.689,0.68893,0.68896],"low":[0.68879,0.68875,0.68878,0.68876,0.68873,0.68867,0.68869,0.68883,0.68885,0.68881,0.68886],"increasing":{"line":{}},"decreasing":{"line":{}}}];"""
479+
|> chartGeneratedContains Candlestick.``Simple candlestick chart``
480+
);
481+
testCase "simple Candlestick layout" ( fun () ->
482+
"""var layout = {"xaxis":{"rangeslider":{"yaxis":{}}}};"""
483+
|> chartGeneratedContains Candlestick.``Simple candlestick chart``
484+
);
485+
testCase "Candlestick no range slider data" ( fun () ->
486+
"""var data = [{"type":"candlestick","x":["2020-01-17T13:40:00","2020-01-17T13:41:00","2020-01-17T13:42:00","2020-01-17T13:43:00","2020-01-17T13:44:00","2020-01-17T13:45:00","2020-01-17T13:46:00","2020-01-17T13:47:00","2020-01-17T13:48:00","2020-01-17T13:49:00","2020-01-17T13:50:00"],"close":[0.6888,0.68877,0.68886,0.68879,0.68874,0.68868,0.68883,0.68899,0.68889,0.68893,0.68891],"open":[0.68888,0.68883,0.68878,0.68886,0.68879,0.68875,0.68869,0.68883,0.68898,0.68889,0.68891],"high":[0.68888,0.68884,0.68889,0.68886,0.68879,0.68877,0.68887,0.68899,0.689,0.68893,0.68896],"low":[0.68879,0.68875,0.68878,0.68876,0.68873,0.68867,0.68869,0.68883,0.68885,0.68881,0.68886],"increasing":{"line":{}},"decreasing":{"line":{}}}];"""
487+
|> chartGeneratedContains Candlestick.``Simple candlestick chart without range slider``
488+
);
489+
testCase "Candlestick no range slider layout" ( fun () ->
490+
"""var layout = {"xaxis":{"rangeslider":{"visible":false,"yaxis":{}}}};"""
491+
|> chartGeneratedContains Candlestick.``Simple candlestick chart without range slider``
492+
);
453493
]
454494
]
455495

tests/CoreTests/CoreTests/HTMLCodegen/ChartDomain.fs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,20 @@ module FunnelArea =
5151
let ``FunnelArea chart HTML codegeneration tests`` =
5252
testList "HTMLCodegen.ChartDomain" [
5353
testList "FunnelArea" [
54+
testCase "Funnel area data" ( fun () ->
55+
"""var data = [{"type":"funnelarea","values":[5,4,3,2,1],"text":["The 1st","The 2nd","The 3rd","The 4th","The 5th"],"marker":{"line":{"color":"purple","width":3.0}}}];"""
56+
|> chartGeneratedContains FunnelArea.``Simple funnelarea chart``
57+
);
58+
testCase "Funnel area layout" ( fun () ->
59+
emptyLayout FunnelArea.``Simple funnelarea chart``
60+
);
61+
testCase "Funnel area styled data" ( fun () ->
62+
"""var data = [{"type":"funnelarea","values":[5,4,3],"labels":["The 1st","The 2nd","The 3rd"],"text":["The 1st","The 2nd","The 3rd"],"marker":{"colors":["rgba(0, 255, 255, 1.0)","rgba(250, 128, 114, 1.0)","rgba(210, 180, 140, 1.0)"],"line":{"color":"rgba(0, 0, 0, 1.0)","width":2.0}},"aspectratio":0.75,"baseratio":0.1}];"""
63+
|> chartGeneratedContains FunnelArea.``Styled funnelarea chart``
64+
);
65+
testCase "Funnel area styled layout" ( fun () ->
66+
emptyLayout FunnelArea.``Styled funnelarea chart``
67+
);
5468
]
5569
]
5670

@@ -136,6 +150,34 @@ module Indicator =
136150
let ``Indicator chart HTML codegeneration tests`` =
137151
testList "HTMLCodegen.ChartDomain" [
138152
testList "Indicator" [
153+
testCase "Angular gauge indicator data" ( fun () ->
154+
"""var data = [{"type":"indicator","mode":"number+delta+gauge","value":200.0,"domain":{"row":0,"column":0},"delta":{"reference":160},"gauge":{"axis":{"range":[0.0,250.0]}}}];"""
155+
|> chartGeneratedContains Indicator.``Angular gauge indicator``
156+
);
157+
testCase "Angular gauge indicator layout" ( fun () ->
158+
emptyLayout Indicator.``Angular gauge indicator``
159+
);
160+
testCase "Bullet gauge indicator data" ( fun () ->
161+
"""var data = [{"type":"indicator","mode":"number+delta+gauge","value":120,"domain":{"row":0,"column":1},"delta":{"reference":90},"gauge":{"axis":{"visible":false,"range":[-200.0,200.0]},"shape":"bullet"}}];"""
162+
|> chartGeneratedContains Indicator.``Bullet gauge indicator``
163+
);
164+
testCase "Bullet gauge indicator layout" ( fun () ->
165+
emptyLayout Indicator.``Bullet gauge indicator``
166+
);
167+
testCase "Delta indicator with reference data" ( fun () ->
168+
"""var data = [{"type":"indicator","mode":"number+delta","value":"300","domain":{"row":1,"column":0},"delta":{"reference":90.0},"gauge":{"axis":{}}}];"""
169+
|> chartGeneratedContains Indicator.``Delta indicator with reference``
170+
);
171+
testCase "Delta indicator with reference layout" ( fun () ->
172+
emptyLayout Indicator.``Delta indicator with reference``
173+
);
174+
testCase "Delta indicator data" ( fun () ->
175+
"""var data = [{"type":"indicator","mode":"delta","value":40.0,"domain":{"row":1,"column":1},"delta":{"reference":90.0},"gauge":{"axis":{}}}];"""
176+
|> chartGeneratedContains Indicator.``Delta indicator``
177+
);
178+
testCase "Delta indicator layout" ( fun () ->
179+
emptyLayout Indicator.``Delta indicator``
180+
);
139181
]
140182
]
141183

0 commit comments

Comments
 (0)