Skip to content

fix data property of chart templates #233

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions src/Plotly.NET/Playground.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,30 @@ open FSharpAux
open System
open System.IO

let layout =
Layout.init (Font = Font.init (Family = StyleParam.FontFamily.Raleway, Size = 14.))

let traceTemplates = [
Trace2D.initScatter (
Trace2DStyle.Scatter(Marker = Marker.init (Symbol = StyleParam.MarkerSymbol.Diamond, Size = 20))
)
Trace2D.initScatter (
Trace2DStyle.Scatter(Marker = Marker.init (Symbol = StyleParam.MarkerSymbol.ArrowBarLeft, Size = 10))
)
]

let template = Template.init (layout, traceTemplates)

[
Chart.Scatter(x = [ 0; 1; 2 ], y = [ 2; 1; 3 ], mode = StyleParam.Mode.Markers)
Chart.Scatter(x = [ 0; 1; 2 ], y = [ 1; 2; 4 ], mode = StyleParam.Mode.Markers)
]
|> Chart.combine
|> Chart.withLayout (Layout.init (Title = Title.init ("Figure Title")))
|> Chart.withTemplate template
//|> GenericChart.mapTrace (fun t -> t.Remove("marker"); t)
|> Chart.show

let y=[2.37; 2.16; 4.82; 1.73; 1.04; 0.23; 1.32; 2.91; 0.11; 4.51; 0.51; 3.75; 1.35; 2.98; 4.50; 0.18; 4.66; 1.30; 2.06; 1.19]

[
Expand Down
36 changes: 33 additions & 3 deletions src/Plotly.NET/Template/Template.fs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ type Template() =
static member init
(
layoutTemplate: Layout ,
[<Optional;DefaultParameterValue(null)>] ?TraceTemplates: #Trace []
[<Optional;DefaultParameterValue(null)>] ?TraceTemplates: seq<#Trace>
) =
Template()
|> Template.style
Expand All @@ -24,11 +24,41 @@ type Template() =
static member style
(
layoutTemplate: Layout ,
[<Optional;DefaultParameterValue(null)>] ?TraceTemplates: #Trace []
[<Optional;DefaultParameterValue(null)>] ?TraceTemplates: seq<#Trace>
) =
(fun (template:Template) ->

let traceTemplates =
TraceTemplates
|> Option.map (fun traceTemplates ->
traceTemplates
|> Seq.groupBy (fun t -> t.``type``)
|> (fun groupedTemplates ->
groupedTemplates
|> Seq.map (fun (id, templates) ->
id,
templates
|> Seq.map (fun t ->
let tmp = DynamicObj()
t.CopyDynamicPropertiesTo(tmp)
tmp
)

)
)
)
|> fun traceTemplates ->
let tmp = DynamicObj()
traceTemplates
|> Option.iter (Seq.iter (fun (id,traceTemplate) ->
traceTemplate |> DynObj.setValue tmp id
)
)
tmp


layoutTemplate |> DynObj.setValue template "layout"
TraceTemplates |> DynObj.setValueOpt template "data"
traceTemplates |> DynObj.setValue template "data"

template
)
Expand Down