Skip to content

Commit

Permalink
#369: fix how FinanceMarker styles are applied
Browse files Browse the repository at this point in the history
  • Loading branch information
kMutagene committed Feb 26, 2023
1 parent 8affb4f commit 1e5fec1
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 13 deletions.
13 changes: 9 additions & 4 deletions src/Plotly.NET/Traces/ObjectAbstractions/FinanceMarker.fs
Original file line number Diff line number Diff line change
Expand Up @@ -9,37 +9,42 @@ open System.Runtime.InteropServices
type FinanceMarker() =
inherit DynamicObj()

[<Obsolete("the argument 'MarkerColor' is obsolete and will be dropped in the next major release")>]
static member init
(
[<Optional; DefaultParameterValue(null)>] ?MarkerColor: Color,
[<Optional; DefaultParameterValue(null)>] ?FillColor: Color,
[<Optional; DefaultParameterValue(null)>] ?LineColor: Color,
[<Optional; DefaultParameterValue(null)>] ?LineWidth: float,
[<Optional; DefaultParameterValue(null)>] ?LineDash: StyleParam.DrawingStyle
) =
FinanceMarker()
|> FinanceMarker.style (
?MarkerColor = MarkerColor,
?FillColor = FillColor,
?LineColor = LineColor,
?LineWidth = LineWidth,
?LineDash = LineDash

)

[<Obsolete("the argument 'MarkerColor' is obsolete and will be dropped in the next major release")>]
static member style
(
[<Optional; DefaultParameterValue(null)>] ?MarkerColor: Color,
[<Optional; DefaultParameterValue(null)>] ?FillColor: Color,
[<Optional; DefaultParameterValue(null)>] ?LineColor: Color,
[<Optional; DefaultParameterValue(null)>] ?LineWidth: float,
[<Optional; DefaultParameterValue(null)>] ?LineDash: StyleParam.DrawingStyle
) =
(fun (financeMarker: FinanceMarker) ->
let marker =
Marker.init (?Color = MarkerColor)

let line =
Line.init (?Color = LineColor, ?Width = LineWidth, ?Dash = LineDash)
financeMarker.TryGetTypedValue<Line>("line")
|> Option.defaultValue(Plotly.NET.Line.init())
|> Line.style (?Color = LineColor, ?Width = LineWidth, ?Dash = LineDash)

marker |> DynObj.setValue financeMarker "marker"
FillColor |> DynObj.setValueOpt financeMarker "fillcolor"
line |> DynObj.setValue financeMarker "line"

financeMarker)
40 changes: 33 additions & 7 deletions tests/Plotly.NET.Tests/HtmlCodegen/FinanceCharts.fs
Original file line number Diff line number Diff line change
Expand Up @@ -24,29 +24,55 @@ let candles =
|]
|> Array.map (fun (d,o,h,l,c)->System.DateTime.Parse d, StockData.Create(o,h,l,c))

let candles1Chart = Chart.Candlestick(stockTimeSeries = candles, UseDefaults = false)
let ohlc1Chart = Chart.OHLC(stockTimeSeries = candles, UseDefaults = false)

let ohlc2Chart =
Chart.OHLC(stockTimeSeries = candles, ShowXAxisRangeSlider = false, UseDefaults = false)


[<Tests>]
let ``OHLC charts`` =
testList "FinanceCharts.OHLC charts" [
testCase "OHLC 1 data" ( fun () ->
"""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":{}}}];"""
|> chartGeneratedContains ohlc1Chart
);
testCase "OHLC 1 layout" ( fun () ->
"""var layout = {"xaxis":{"rangeslider":{"yaxis":{}}}};"""
|> chartGeneratedContains ohlc1Chart
);
testCase "OHLC 2 data" ( fun () ->
"""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":{}}}];"""
|> chartGeneratedContains ohlc2Chart
);
testCase "OHLC 2 layout" ( fun () ->
"""var layout = {"xaxis":{"rangeslider":{"visible":false,"yaxis":{}}}};"""
|> chartGeneratedContains ohlc2Chart
);
]

let candles1Chart = Chart.Candlestick(stockTimeSeries = candles, UseDefaults = false)

let candles2Chart =
Chart.Candlestick(stockTimeSeries = candles, ShowXAxisRangeSlider = false, UseDefaults = false)


[<Tests>]
let ``Candlestick charts`` =
testList "FinanceCharts.Candlestick charts" [
testCase "Finance 1 data" ( fun () ->
"""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":{}}}];"""
testCase "Candlestick 1 data" ( fun () ->
"""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":{}}}];"""
|> chartGeneratedContains candles1Chart
);
testCase "Finance 1 layout" ( fun () ->
testCase "Candlestick 1 layout" ( fun () ->
"""var layout = {"xaxis":{"rangeslider":{"yaxis":{}}}};"""
|> chartGeneratedContains candles1Chart
);
testCase "Finance 2 data" ( fun () ->
"""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":{}}}];"""
testCase "Candlestick 2 data" ( fun () ->
"""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":{}}}];"""
|> chartGeneratedContains candles2Chart
);
testCase "Finance 2 layout" ( fun () ->
testCase "Candlestick 2 layout" ( fun () ->
"""var layout = {"xaxis":{"rangeslider":{"visible":false,"yaxis":{}}}};"""
|> chartGeneratedContains candles2Chart
);
Expand Down
4 changes: 2 additions & 2 deletions tests/Plotly.NET.Tests/HtmlCodegen/MulticategoryData.fs
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ let multicategoryOHLC =
let ``Multicategory ohlc tests`` =
testList "MulticategoryData.OHLC" [
testCase "Multicategory ohlc data" ( fun () ->
"""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":{}}}];"""
"""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":{}}}];"""
|> chartGeneratedContains multicategoryOHLC
);
testCase "Multicategory ohlc layout" ( fun () ->
Expand All @@ -294,7 +294,7 @@ let multicategoryCandlestick =
let ``Multicategory candlestick tests`` =
testList "MulticategoryData.Candlestick" [
testCase "Multicategory candlestick data" ( fun () ->
"""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":{}}}];"""
"""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":{}}}];"""
|> chartGeneratedContains multicategoryCandlestick
);
testCase "Multicategory candlestick layout" ( fun () ->
Expand Down

0 comments on commit 1e5fec1

Please sign in to comment.