Skip to content

Commit 1e5fec1

Browse files
committed
#369: fix how FinanceMarker styles are applied
1 parent 8affb4f commit 1e5fec1

File tree

3 files changed

+44
-13
lines changed

3 files changed

+44
-13
lines changed

Diff for: src/Plotly.NET/Traces/ObjectAbstractions/FinanceMarker.fs

+9-4
Original file line numberDiff line numberDiff line change
@@ -9,37 +9,42 @@ open System.Runtime.InteropServices
99
type FinanceMarker() =
1010
inherit DynamicObj()
1111

12+
[<Obsolete("the argument 'MarkerColor' is obsolete and will be dropped in the next major release")>]
1213
static member init
1314
(
1415
[<Optional; DefaultParameterValue(null)>] ?MarkerColor: Color,
16+
[<Optional; DefaultParameterValue(null)>] ?FillColor: Color,
1517
[<Optional; DefaultParameterValue(null)>] ?LineColor: Color,
1618
[<Optional; DefaultParameterValue(null)>] ?LineWidth: float,
1719
[<Optional; DefaultParameterValue(null)>] ?LineDash: StyleParam.DrawingStyle
1820
) =
1921
FinanceMarker()
2022
|> FinanceMarker.style (
2123
?MarkerColor = MarkerColor,
24+
?FillColor = FillColor,
2225
?LineColor = LineColor,
2326
?LineWidth = LineWidth,
2427
?LineDash = LineDash
2528

2629
)
2730

31+
[<Obsolete("the argument 'MarkerColor' is obsolete and will be dropped in the next major release")>]
2832
static member style
2933
(
3034
[<Optional; DefaultParameterValue(null)>] ?MarkerColor: Color,
35+
[<Optional; DefaultParameterValue(null)>] ?FillColor: Color,
3136
[<Optional; DefaultParameterValue(null)>] ?LineColor: Color,
3237
[<Optional; DefaultParameterValue(null)>] ?LineWidth: float,
3338
[<Optional; DefaultParameterValue(null)>] ?LineDash: StyleParam.DrawingStyle
3439
) =
3540
(fun (financeMarker: FinanceMarker) ->
36-
let marker =
37-
Marker.init (?Color = MarkerColor)
3841

3942
let line =
40-
Line.init (?Color = LineColor, ?Width = LineWidth, ?Dash = LineDash)
43+
financeMarker.TryGetTypedValue<Line>("line")
44+
|> Option.defaultValue(Plotly.NET.Line.init())
45+
|> Line.style (?Color = LineColor, ?Width = LineWidth, ?Dash = LineDash)
4146

42-
marker |> DynObj.setValue financeMarker "marker"
47+
FillColor |> DynObj.setValueOpt financeMarker "fillcolor"
4348
line |> DynObj.setValue financeMarker "line"
4449

4550
financeMarker)

Diff for: tests/Plotly.NET.Tests/HtmlCodegen/FinanceCharts.fs

+33-7
Original file line numberDiff line numberDiff line change
@@ -24,29 +24,55 @@ let candles =
2424
|]
2525
|> Array.map (fun (d,o,h,l,c)->System.DateTime.Parse d, StockData.Create(o,h,l,c))
2626

27-
let candles1Chart = Chart.Candlestick(stockTimeSeries = candles, UseDefaults = false)
27+
let ohlc1Chart = Chart.OHLC(stockTimeSeries = candles, UseDefaults = false)
28+
29+
let ohlc2Chart =
30+
Chart.OHLC(stockTimeSeries = candles, ShowXAxisRangeSlider = false, UseDefaults = false)
2831

2932

33+
[<Tests>]
34+
let ``OHLC charts`` =
35+
testList "FinanceCharts.OHLC charts" [
36+
testCase "OHLC 1 data" ( fun () ->
37+
"""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":{}}}];"""
38+
|> chartGeneratedContains ohlc1Chart
39+
);
40+
testCase "OHLC 1 layout" ( fun () ->
41+
"""var layout = {"xaxis":{"rangeslider":{"yaxis":{}}}};"""
42+
|> chartGeneratedContains ohlc1Chart
43+
);
44+
testCase "OHLC 2 data" ( fun () ->
45+
"""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":{}}}];"""
46+
|> chartGeneratedContains ohlc2Chart
47+
);
48+
testCase "OHLC 2 layout" ( fun () ->
49+
"""var layout = {"xaxis":{"rangeslider":{"visible":false,"yaxis":{}}}};"""
50+
|> chartGeneratedContains ohlc2Chart
51+
);
52+
]
53+
54+
let candles1Chart = Chart.Candlestick(stockTimeSeries = candles, UseDefaults = false)
55+
3056
let candles2Chart =
3157
Chart.Candlestick(stockTimeSeries = candles, ShowXAxisRangeSlider = false, UseDefaults = false)
3258

3359

3460
[<Tests>]
3561
let ``Candlestick charts`` =
3662
testList "FinanceCharts.Candlestick charts" [
37-
testCase "Finance 1 data" ( fun () ->
38-
"""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":{"marker":{},"line":{}},"decreasing":{"marker":{},"line":{}}}];"""
63+
testCase "Candlestick 1 data" ( fun () ->
64+
"""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":{}}}];"""
3965
|> chartGeneratedContains candles1Chart
4066
);
41-
testCase "Finance 1 layout" ( fun () ->
67+
testCase "Candlestick 1 layout" ( fun () ->
4268
"""var layout = {"xaxis":{"rangeslider":{"yaxis":{}}}};"""
4369
|> chartGeneratedContains candles1Chart
4470
);
45-
testCase "Finance 2 data" ( fun () ->
46-
"""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":{"marker":{},"line":{}},"decreasing":{"marker":{},"line":{}}}];"""
71+
testCase "Candlestick 2 data" ( fun () ->
72+
"""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":{}}}];"""
4773
|> chartGeneratedContains candles2Chart
4874
);
49-
testCase "Finance 2 layout" ( fun () ->
75+
testCase "Candlestick 2 layout" ( fun () ->
5076
"""var layout = {"xaxis":{"rangeslider":{"visible":false,"yaxis":{}}}};"""
5177
|> chartGeneratedContains candles2Chart
5278
);

Diff for: tests/Plotly.NET.Tests/HtmlCodegen/MulticategoryData.fs

+2-2
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ let multicategoryOHLC =
271271
let ``Multicategory ohlc tests`` =
272272
testList "MulticategoryData.OHLC" [
273273
testCase "Multicategory ohlc data" ( fun () ->
274-
"""var data = [{"type":"ohlc","x":[["A","A"],["AA","AB"]],"close":[0.5,1.0],"open":[1,2],"high":[3,4],"low":[0,1],"increasing":{"marker":{},"line":{}},"decreasing":{"marker":{},"line":{}}}];"""
274+
"""var data = [{"type":"ohlc","x":[["A","A"],["AA","AB"]],"close":[0.5,1.0],"open":[1,2],"high":[3,4],"low":[0,1],"increasing":{"line":{}},"decreasing":{"line":{}}}];"""
275275
|> chartGeneratedContains multicategoryOHLC
276276
);
277277
testCase "Multicategory ohlc layout" ( fun () ->
@@ -294,7 +294,7 @@ let multicategoryCandlestick =
294294
let ``Multicategory candlestick tests`` =
295295
testList "MulticategoryData.Candlestick" [
296296
testCase "Multicategory candlestick data" ( fun () ->
297-
"""var data = [{"type":"candlestick","x":[["A","A"],["AA","AB"]],"close":[0.5,1.0],"open":[1,2],"high":[3,4],"low":[0,1],"increasing":{"marker":{},"line":{}},"decreasing":{"marker":{},"line":{}}}];"""
297+
"""var data = [{"type":"candlestick","x":[["A","A"],["AA","AB"]],"close":[0.5,1.0],"open":[1,2],"high":[3,4],"low":[0,1],"increasing":{"line":{}},"decreasing":{"line":{}}}];"""
298298
|> chartGeneratedContains multicategoryCandlestick
299299
);
300300
testCase "Multicategory candlestick layout" ( fun () ->

0 commit comments

Comments
 (0)