forked from plotly/Plotly.NET
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGenericChartExtensions.fs
More file actions
678 lines (608 loc) · 31.1 KB
/
GenericChartExtensions.fs
File metadata and controls
678 lines (608 loc) · 31.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
namespace Plotly.NET
open System
open System.IO
open GenericChart
open System.Runtime.InteropServices
open System.Runtime.CompilerServices
///Extension methods for providing a Plotly.NET fluent interface pattern for C#
[<Extension>]
module GenericChartExtensions =
type GenericChart with
[<CompiledName("WithTraceName")>]
[<Extension>]
member this.WithTraceName
(
[<Optional;DefaultParameterValue(null)>] ?Name,
[<Optional;DefaultParameterValue(null)>] ?Showlegend,
[<Optional;DefaultParameterValue(null)>] ?Legendgroup,
[<Optional;DefaultParameterValue(null)>] ?Visible
) =
this |> Chart.withTraceName(?Name=Name,?Showlegend=Showlegend,?Legendgroup=Legendgroup,?Visible=Visible)
/// Set the axis anchor id the trace is belonging to
[<CompiledName("WithAxisAnchor")>]
[<Extension>]
member this.WithAxisAnchor
(
[<Optional;DefaultParameterValue(null)>] ?X,
[<Optional;DefaultParameterValue(null)>] ?Y,
[<Optional;DefaultParameterValue(null)>] ?Z
) =
let idx = if X.IsSome then Some (StyleParam.AxisAnchorId.X X.Value) else None
let idy = if Y.IsSome then Some (StyleParam.AxisAnchorId.Y Y.Value) else None
let idz = if Z.IsSome then Some (StyleParam.AxisAnchorId.Z Z.Value) else None
this
|> mapTrace (fun trace ->
trace
|> Trace.TraceStyle.SetAxisAnchor(?X=idx,?Y=idy,?Z=idz)
)
/// Apply styling to the Marker(s) of the chart as Object.
[<CompiledName("WithMarker")>]
[<Extension>]
member this.WithMarker(marker:Marker) =
this |> mapTrace (Trace.TraceStyle.SetMarker(marker))
/// Apply styling to the Marker(s) of the chart.
[<CompiledName("WithMarkerStyle")>]
[<Extension>]
member this.WithMarkerStyle
(
[<Optional;DefaultParameterValue(null)>] ?Size,
[<Optional;DefaultParameterValue(null)>] ?Color,
[<Optional;DefaultParameterValue(null)>] ?Symbol,
[<Optional;DefaultParameterValue(null)>] ?Opacity
) =
let marker =
Marker.init (
?Size=Size,?Color=Color,?Symbol=Symbol,?Opacity=Opacity
)
this |> Chart.withMarker(marker)
/// Apply styling to the Line(s) of the chart as Object.
[<CompiledName("WithLine")>]
[<Extension>]
member this.WithLine(line:Line) =
this |> mapTrace (Trace.TraceStyle.SetLine(line))
/// Apply styling to the Line(s) of the chart.
[<CompiledName("WithLineStyle")>]
[<Extension>]
member this.WithLineStyle
(
[<Optional;DefaultParameterValue(null)>] ?Width,
[<Optional;DefaultParameterValue(null)>] ?Color,
[<Optional;DefaultParameterValue(null)>] ?Shape,
[<Optional;DefaultParameterValue(null)>] ?Dash,
[<Optional;DefaultParameterValue(null)>] ?Smoothing,
[<Optional;DefaultParameterValue(null)>] ?Colorscale
) =
let line =
Line.init (
?Width=Width,?Color=Color,?Shape=Shape,?Dash=Dash,?Smoothing=Smoothing,?Colorscale=Colorscale)
this |> Chart.withLine(line)
/// Apply styling to the xError(s) of the chart as Object
[<CompiledName("WithXError")>]
[<Extension>]
member this.WithXError(xError:Error) =
this |> mapTrace (Trace.TraceStyle.SetErrorX(xError))
/// Apply styling to the xError(s) of the chart as Object
[<CompiledName("WithXErrorStyle")>]
[<Extension>]
member this.WithXErrorStyle
(
[<Optional;DefaultParameterValue(null)>] ?Array,
[<Optional;DefaultParameterValue(null)>] ?Arrayminus,
[<Optional;DefaultParameterValue(null)>] ?Symmetric,
[<Optional;DefaultParameterValue(null)>] ?Color,
[<Optional;DefaultParameterValue(null)>] ?Thickness,
[<Optional;DefaultParameterValue(null)>] ?Width
) =
let error = Error.init(?Array=Array,?Arrayminus=Arrayminus,?Symmetric=Symmetric,?Color=Color,?Thickness=Thickness,?Width=Width)
this |> Chart.withXError error
/// Apply styling to the yError(s) of the chart as Object
[<CompiledName("WithYError")>]
[<Extension>]
member this.WithYError(yError:Error) =
this |> mapTrace (Trace.TraceStyle.SetErrorY(yError))
/// Apply styling to the yError(s) of the chart as Object
[<CompiledName("WithYErrorStyle")>]
[<Extension>]
member this.WithYErrorStyle
(
[<Optional;DefaultParameterValue(null)>] ?Array,
[<Optional;DefaultParameterValue(null)>] ?Arrayminus,
[<Optional;DefaultParameterValue(null)>] ?Symmetric,
[<Optional;DefaultParameterValue(null)>] ?Color,
[<Optional;DefaultParameterValue(null)>] ?Thickness,
[<Optional;DefaultParameterValue(null)>] ?Width
) =
let error = Error.init(?Array=Array,?Arrayminus=Arrayminus,?Symmetric=Symmetric,?Color=Color,?Thickness=Thickness,?Width=Width)
this |> Chart.withYError error
/// Apply styling to the zError(s) of the chart as Object
[<CompiledName("WithZError")>]
[<Extension>]
member this.WithZError(zError:Error) =
this |> mapTrace (Trace.TraceStyle.SetErrorZ(zError))
/// Apply styling to the zError(s) of the chart as Object
[<CompiledName("WithZErrorStyle")>]
[<Extension>]
member this.WithZErrorStyle
(
[<Optional;DefaultParameterValue(null)>] ?Array,
[<Optional;DefaultParameterValue(null)>] ?Arrayminus,
[<Optional;DefaultParameterValue(null)>] ?Symmetric,
[<Optional;DefaultParameterValue(null)>] ?Color,
[<Optional;DefaultParameterValue(null)>] ?Thickness,
[<Optional;DefaultParameterValue(null)>] ?Width
) =
let error = Error.init(?Array=Array,?Arrayminus=Arrayminus,?Symmetric=Symmetric,?Color=Color,?Thickness=Thickness,?Width=Width)
this |> Chart.withZError error
// ############################################################
// ####################### Apply to layout
// Sets x-Axis of 2d and 3d- Charts
[<CompiledName("WithX_Axis")>]
[<Extension>]
member this.WithX_Axis(xAxis:Axis.LinearAxis,[<Optional;DefaultParameterValue(null)>] ?Id) =
let contains3d =
this
|> existsTrace (fun t ->
match t with
| :? Trace3d -> true
| _ -> false)
match contains3d with
| false ->
let layout =
let id = if Id.IsSome then StyleParam.AxisId.X Id.Value else StyleParam.AxisId.X 1
GenericChart.getLayout this
|> Layout.UpdateLinearAxisById(id,axis=xAxis)
GenericChart.setLayout layout this
| true ->
let layout =
Layout()
|> Layout.style (Scene=Scene.init( xAxis=xAxis) )
GenericChart.addLayout layout this
// Sets x-Axis of 2d and 3d- Charts
[<CompiledName("WithX_AxisStyle")>]
[<Extension>]
member this.WithX_AxisStyle(title,
[<Optional;DefaultParameterValue(null)>] ?MinMax,
[<Optional;DefaultParameterValue(null)>] ?Showgrid,
[<Optional;DefaultParameterValue(null)>] ?Showline,
[<Optional;DefaultParameterValue(null)>] ?Side,
[<Optional;DefaultParameterValue(null)>] ?Overlaying,
[<Optional;DefaultParameterValue(null)>] ?Id,
[<Optional;DefaultParameterValue(null)>] ?Domain,
[<Optional;DefaultParameterValue(null)>] ?Position,
[<Optional;DefaultParameterValue(null)>] ?Zeroline,
[<Optional;DefaultParameterValue(null)>] ?Anchor) =
let range = if MinMax.IsSome then Some (StyleParam.Range.MinMax (MinMax.Value)) else None
let domain = if Domain.IsSome then Some (StyleParam.Range.MinMax (Domain.Value)) else None
let xaxis = Axis.LinearAxis.init(Title=title,?Range=range,?Showgrid=Showgrid,?Showline=Showline,
?Anchor=Anchor,?Side=Side,?Domain=domain,?Overlaying=Overlaying,?Position=Position,?Zeroline=Zeroline)
this |> Chart.withX_Axis(xaxis,?Id=Id)
/// Sets the range slider for the xAxis
[<CompiledName("WithX_AxisRangeSlider")>]
[<Extension>]
member this.WithX_AxisRangeSlider(rangeSlider:RangeSlider,
[<Optional;DefaultParameterValue(null)>] ?Id) =
let xaxis = Axis.LinearAxis.init(RangeSlider = rangeSlider)
this |> Chart.withX_Axis(xaxis,?Id=Id)
// Sets y-Axis of 2d and 3d- Charts
[<CompiledName("WithY_Axis")>]
[<Extension>]
member this.WithY_Axis(yAxis:Axis.LinearAxis,[<Optional;DefaultParameterValue(null)>] ?Id) =
let contains3d =
this
|> existsTrace (fun t ->
match t with
| :? Trace3d -> true
| _ -> false)
match contains3d with
| false ->
let layout =
let id = if Id.IsSome then StyleParam.AxisId.Y Id.Value else StyleParam.AxisId.Y 1
GenericChart.getLayout this
|> Layout.UpdateLinearAxisById(id,axis=yAxis)
GenericChart.setLayout layout this
| true ->
let layout =
Layout()
|> Layout.style(Scene=Scene.init(yAxis=yAxis) )
GenericChart.addLayout layout this
// Sets y-Axis of 3d- Charts
[<CompiledName("WithY_AxisStyle")>]
[<Extension>]
member this.WithY_AxisStyle(title,
[<Optional;DefaultParameterValue(null)>] ?MinMax,
[<Optional;DefaultParameterValue(null)>] ?Showgrid,
[<Optional;DefaultParameterValue(null)>] ?Showline,
[<Optional;DefaultParameterValue(null)>] ?Side,
[<Optional;DefaultParameterValue(null)>] ?Overlaying,
[<Optional;DefaultParameterValue(null)>] ?Id,
[<Optional;DefaultParameterValue(null)>] ?Domain,
[<Optional;DefaultParameterValue(null)>] ?Position,
[<Optional;DefaultParameterValue(null)>] ?Zeroline,
[<Optional;DefaultParameterValue(null)>] ?Anchor) =
let range = if MinMax.IsSome then Some (StyleParam.Range.MinMax (MinMax.Value)) else None
let domain = if Domain.IsSome then Some (StyleParam.Range.MinMax (Domain.Value)) else None
let yaxis = Axis.LinearAxis.init(Title=title,?Range=range,?Showgrid=Showgrid,
?Showline=Showline,?Anchor=Anchor,?Side=Side,?Domain=domain,?Overlaying=Overlaying,?Position=Position,?Zeroline=Zeroline)
this |> Chart.withY_Axis(yaxis,?Id=Id)
// Sets z-Axis of 3d- Charts
[<CompiledName("WithZ_Axis")>]
[<Extension>]
member this.WithZ_Axis(zAxis:Axis.LinearAxis) =
let layout =
Layout()
|> Layout.style(Scene=Scene.init(zAxis=zAxis))
GenericChart.addLayout layout this
// Sets z-Axis style with ...
[<CompiledName("WithZ_AxisStyle")>]
[<Extension>]
member this.WithZ_AxisStyle(title,
[<Optional;DefaultParameterValue(null)>] ?MinMax,
[<Optional;DefaultParameterValue(null)>] ?Showgrid,
[<Optional;DefaultParameterValue(null)>] ?Showline,
[<Optional;DefaultParameterValue(null)>] ?Domain,
[<Optional;DefaultParameterValue(null)>] ?Anchor) =
let range = if MinMax.IsSome then Some (StyleParam.Range.MinMax (MinMax.Value)) else None
let domain = if Domain.IsSome then Some (StyleParam.Range.MinMax (Domain.Value)) else None
let zaxis = Axis.LinearAxis.init(Title=title,?Range=range,?Showgrid=Showgrid,?Showline=Showline,?Anchor=Anchor,?Domain=domain)
this |> Chart.withZ_Axis(zaxis)
[<CompiledName("WithColorBar")>]
[<Extension>]
member this.withColorBar(colorbar:Colorbar) =
this
|> GenericChart.mapTrace(fun t ->
colorbar |> DynObj.setValue t "colorbar"
t
)
[<CompiledName("WithColorbar")>]
[<Extension>]
member this.WithColorBarStyle(title,
[<Optional;DefaultParameterValue(null)>] ?TitleSide: StyleParam.Side,
[<Optional;DefaultParameterValue(null)>] ?TitleFont: Font,
[<Optional;DefaultParameterValue(null)>] ?Length,
[<Optional;DefaultParameterValue(null)>] ?OutlineColor,
[<Optional;DefaultParameterValue(null)>] ?BorderColor,
[<Optional;DefaultParameterValue(null)>] ?BGColor) =
let colorbar = Colorbar.init(Title=title,?Titleside=TitleSide,?Titlefont=TitleFont,?Len = Length,?Outlinecolor=OutlineColor,?Bgcolor=BGColor,?Bordercolor=BorderColor)
this |> Chart.withColorBar(colorbar)
// Set the Layout options of a Chart
[<CompiledName("WithLayout")>]
[<Extension>]
member this.WithLayout(layout:Layout) =
GenericChart.addLayout layout this
// Set the LayoutGrid options of a Chart
[<CompiledName("WithLayoutGrid")>]
[<Extension>]
member this.WithLayoutGrid(layoutGrid:LayoutGrid) =
let layout =
GenericChart.getLayout this
|> Layout.SetLayoutGrid layoutGrid
GenericChart.setLayout layout this
// Set the LayoutGrid options of a Chart
[<CompiledName("WithLegend")>]
member this.WithLegend(legend:Legend) =
let layout =
GenericChart.getLayout this
|> Layout.setLegend legend
GenericChart.setLayout layout this
/// Sets a map for the given chart (will only work with traces supporting geo, e.g. choropleth, scattergeo)
[<CompiledName("WithMap")>]
[<Extension>]
member this.WithMap(map:Geo,[<Optional;DefaultParameterValue(null)>] ?Id ) =
let layout =
let id = defaultArg Id 1
GenericChart.getLayout this
|> Layout.UpdateMapById(id,map)
GenericChart.setLayout layout this
/// Sets the map style for the given chart (will only work with traces supporting geo, e.g. choropleth, scattergeo)
///
/// Parameters :
///
/// FitBounds : Determines if and how this subplot's view settings are auto-computed to fit trace data
///
/// Resolution : Sets the resolution of the base layers
///
/// Scope : Set the scope of the map.
///
/// Projection : Determines the type of projection used to display the map
///
/// Center : Sets the (lon,lat) coordinates of the map's center. By default, the map's longitude center lies at the middle of the longitude range for scoped projection and above `projection.rotation.lon` otherwise. For all projection types, the map's latitude center lies at the middle of the latitude range by default.
///
/// Visible : Wether or not the base layers are visible
///
/// Domain : The domain of this geo subplot
///
/// ShowCoastLine : Sets whether or not the coastlines are drawn.
///
/// CoastLineColor : Sets the coastline color.
///
/// CoastLineWidth : Sets the coastline stroke width (in px).
///
/// ShowLand : Sets whether or not land masses are filled in color.
///
/// LandColor : Sets the land mass color.
///
/// ShowOcean : Sets whether or not oceans are filled in color.
///
/// OceanColor : Sets the ocean color
///
/// ShowLakes : Sets whether or not lakes are drawn.
///
/// LakeColor : Sets the color of the lakes.
///
/// ShowRivers : Sets whether or not rivers are drawn.
///
/// RiverColor : Sets color of the rivers.
///
/// RiverWidth : Sets the stroke width (in px) of the rivers.
///
/// ShowCountries : Sets whether or not country boundaries are drawn.
///
/// CountryColor : Sets line color of the country boundaries.
///
/// CountryWidth : Sets line width (in px) of the country boundaries.
///
/// ShowSubunits : Sets whether or not boundaries of subunits within countries (e.g. states, provinces) are drawn.
///
/// SubunitColor : Sets the color of the subunits boundaries.
///
/// SubunitWidth : Sets the stroke width (in px) of the subunits boundaries.
///
/// ShowFrame : Sets whether or not a frame is drawn around the map.
///
/// FrameColor : Sets the color the frame.
///
/// FrameWidth : Sets the stroke width (in px) of the frame.
///
/// BgColor : Set the background color of the map
///
/// LatAxis : Sets the latitudinal axis for this geo trace
///
/// LonAxis : Sets the longitudinal axis for this geo trace
[<CompiledName("WithMapStyle")>]
[<Extension>]
member this.WithMapStyle([<Optional;DefaultParameterValue(null)>] ?Id,
[<Optional;DefaultParameterValue(null)>]?FitBounds : StyleParam.GeoFitBounds,
[<Optional;DefaultParameterValue(null)>]?Resolution : StyleParam.GeoResolution,
[<Optional;DefaultParameterValue(null)>]?Scope : StyleParam.GeoScope,
[<Optional;DefaultParameterValue(null)>]?Projection : GeoProjection,
[<Optional;DefaultParameterValue(null)>]?Center : (float*float),
[<Optional;DefaultParameterValue(null)>]?Visible : bool,
[<Optional;DefaultParameterValue(null)>]?Domain : Domain,
[<Optional;DefaultParameterValue(null)>]?ShowCoastLines : bool,
[<Optional;DefaultParameterValue(null)>]?CoastLineColor,
[<Optional;DefaultParameterValue(null)>]?CoastLineWidth : float,
[<Optional;DefaultParameterValue(null)>]?ShowLand : bool,
[<Optional;DefaultParameterValue(null)>]?LandColor,
[<Optional;DefaultParameterValue(null)>]?ShowOcean : bool,
[<Optional;DefaultParameterValue(null)>]?OceanColor,
[<Optional;DefaultParameterValue(null)>]?ShowLakes : bool,
[<Optional;DefaultParameterValue(null)>]?LakeColor,
[<Optional;DefaultParameterValue(null)>]?ShowRivers : bool,
[<Optional;DefaultParameterValue(null)>]?RiverColor,
[<Optional;DefaultParameterValue(null)>]?RiverWidth : float,
[<Optional;DefaultParameterValue(null)>]?ShowCountries : bool,
[<Optional;DefaultParameterValue(null)>]?CountryColor,
[<Optional;DefaultParameterValue(null)>]?CountryWidth : float,
[<Optional;DefaultParameterValue(null)>]?ShowSubunits : bool,
[<Optional;DefaultParameterValue(null)>]?SubunitColor,
[<Optional;DefaultParameterValue(null)>]?SubunitWidth : float,
[<Optional;DefaultParameterValue(null)>]?ShowFrame : bool,
[<Optional;DefaultParameterValue(null)>]?FrameColor,
[<Optional;DefaultParameterValue(null)>]?FrameWidth : float,
[<Optional;DefaultParameterValue(null)>]?BgColor,
[<Optional;DefaultParameterValue(null)>]?LatAxis : Axis.LinearAxis,
[<Optional;DefaultParameterValue(null)>]?LonAxis : Axis.LinearAxis
) =
let map =
Geo.init(
?FitBounds = FitBounds ,
?Resolution = Resolution ,
?Scope = Scope ,
?Projection = Projection ,
?Center = Center ,
?Visible = Visible ,
?Domain = Domain ,
?ShowCoastLines = ShowCoastLines,
?CoastLineColor = CoastLineColor,
?CoastLineWidth = CoastLineWidth,
?ShowLand = ShowLand ,
?LandColor = LandColor ,
?ShowOcean = ShowOcean ,
?OceanColor = OceanColor ,
?ShowLakes = ShowLakes ,
?LakeColor = LakeColor ,
?ShowRivers = ShowRivers ,
?RiverColor = RiverColor ,
?RiverWidth = RiverWidth ,
?ShowCountries = ShowCountries ,
?CountryColor = CountryColor ,
?CountryWidth = CountryWidth ,
?ShowSubunits = ShowSubunits ,
?SubunitColor = SubunitColor ,
?SubunitWidth = SubunitWidth ,
?ShowFrame = ShowFrame ,
?FrameColor = FrameColor ,
?FrameWidth = FrameWidth ,
?BgColor = BgColor ,
?LatAxis = LatAxis ,
?LonAxis = LonAxis
) in
let id = defaultArg Id 1 in
this |> Chart.withMap(map,id)
[<CompiledName("WithMapProjection")>]
[<Extension>]
member this.WithMapProjection(projectionType : StyleParam.GeoProjectionType,
[<Optional;DefaultParameterValue(null)>]?Rotation ,
[<Optional;DefaultParameterValue(null)>]?Parallels,
[<Optional;DefaultParameterValue(null)>]?Scale ,
[<Optional;DefaultParameterValue(null)>]?Id
) =
let projection =
GeoProjection.init(
projectionType = projectionType,
?Rotation = Rotation ,
?Parallels = Parallels ,
?Scale = Scale
)
let map = Geo.init(Projection = projection)
let id = defaultArg Id 1
this |> Chart.withMap(map,id)
// Set the LayoutGrid options of a Chart
[<CompiledName("WithLayoutGridStyle")>]
[<Extension>]
member this.WithLayoutGridStyle([<Optional;DefaultParameterValue(null)>]?SubPlots : StyleParam.AxisId [] [],
[<Optional;DefaultParameterValue(null)>]?XAxes : StyleParam.AxisId [],
[<Optional;DefaultParameterValue(null)>]?YAxes : StyleParam.AxisId [],
[<Optional;DefaultParameterValue(null)>]?Rows : int,
[<Optional;DefaultParameterValue(null)>]?Columns : int,
[<Optional;DefaultParameterValue(null)>]?RowOrder : StyleParam.LayoutGridRowOrder,
[<Optional;DefaultParameterValue(null)>]?Pattern : StyleParam.LayoutGridPattern,
[<Optional;DefaultParameterValue(null)>]?XGap : float,
[<Optional;DefaultParameterValue(null)>]?YGap : float,
[<Optional;DefaultParameterValue(null)>]?Domain : Domain,
[<Optional;DefaultParameterValue(null)>]?XSide : StyleParam.LayoutGridXSide,
[<Optional;DefaultParameterValue(null)>]?YSide : StyleParam.LayoutGridYSide
) =
let layout = GenericChart.getLayout this in
let updatedGrid =
let currentGrid =
match layout.TryGetTypedValue<LayoutGrid> "grid" with
| Some grid -> grid
| None -> LayoutGrid()
currentGrid
|> LayoutGrid.style(
?SubPlots = SubPlots,
?XAxes = XAxes ,
?YAxes = YAxes ,
?Rows = Rows ,
?Columns = Columns ,
?RowOrder = RowOrder,
?Pattern = Pattern ,
?XGap = XGap ,
?YGap = YGap ,
?Domain = Domain ,
?XSide = XSide ,
?YSide = YSide
) in
let updatedLayout = layout |> Layout.SetLayoutGrid updatedGrid in
GenericChart.setLayout updatedLayout this
[<CompiledName("WithConfig")>]
[<Extension>]
member this.WithConfig (config:Config) =
GenericChart.setConfig config this
[<CompiledName("WithAnnotations")>]
[<Extension>]
member this.WithAnnotations(annotations:seq<Annotation>) =
this
|> GenericChart.mapLayout
(Layout.style (Annotations = annotations))
// Set the title of a Chart
[<CompiledName("WithTitle")>]
[<Extension>]
member this.WithTitle(title,[<Optional;DefaultParameterValue(null)>] ?Titlefont) =
let layout =
Layout()
|> Layout.style(Title=title,?Titlefont=Titlefont)
GenericChart.addLayout layout this
// Set showLegend of a Chart
[<CompiledName("WithLegend")>]
[<Extension>]
member this.WithLegend(showlegend) =
let layout =
Layout()
|> Layout.style(Showlegend=showlegend)
GenericChart.addLayout layout this
// Set the size of a Chart
[<CompiledName("WithSize")>]
[<Extension>]
member this.WithSize(width,height) =
let layout =
GenericChart.getLayout this
|> Layout.style (Width=width,Height=height)
GenericChart.setLayout layout this
// Set the margin of a Chart
[<CompiledName("WithMargin")>]
[<Extension>]
member this.WithMargin(margin:Margin) =
let layout =
GenericChart.getLayout this
|> Layout.style (Margin=margin)
GenericChart.setLayout layout this
// Set the margin of a Chart
[<CompiledName("WithMarginSize")>]
[<Extension>]
member this.WithMarginSize
(
[<Optional;DefaultParameterValue(null)>] ?Left,
[<Optional;DefaultParameterValue(null)>] ?Right,
[<Optional;DefaultParameterValue(null)>] ?Top,
[<Optional;DefaultParameterValue(null)>] ?Bottom,
[<Optional;DefaultParameterValue(null)>] ?Pad,
[<Optional;DefaultParameterValue(null)>] ?Autoexpand
) =
let margin =
Margin.init ( ?Left=Left,?Right=Right,?Top=Top,?Bottom=Bottom,?Pad=Pad,?Autoexpand=Autoexpand )
this |> Chart.withMargin(margin)
[<CompiledName("WithTemplate")>]
[<Extension>]
member this.WithTemplate(template: Template) =
this
|> GenericChart.mapLayout (fun l ->
template |> DynObj.setValue l "template"
l
)
// TODO: Include withLegend & withLegendStyle
//Specifies the shape type to be drawn. If "line", a line is drawn from (`x0`,`y0`) to (`x1`,`y1`) If "circle", a circle is drawn from
//((`x0`+`x1`)/2, (`y0`+`y1`)/2)) with radius (|(`x0`+`x1`)/2 - `x0`|, |(`y0`+`y1`)/2 -`y0`)|) If "rect", a rectangle is drawn linking
//(`x0`,`y0`), (`x1`,`y0`), (`x1`,`y1`), (`x0`,`y1`), (`x0`,`y0`)
[<CompiledName("WithShape")>]
[<Extension>]
member this.WithShape(shape:Shape) =
let layout =
GenericChart.getLayout this
|> Layout.style (Shapes=[shape])
GenericChart.setLayout layout this
[<CompiledName("WithShapes")>]
[<Extension>]
member this.WithShapes(shapes:Shape seq) =
let layout =
GenericChart.getLayout this
|> Layout.style (Shapes=shapes)
GenericChart.setLayout layout this
// ############################################################
// ####################### Apply to DisplayOptions
/// Show chart in browser
[<CompiledName("WithDescription")>]
[<Extension>]
member this.WithDescription (description:ChartDescription) =
this |> Chart.WithDescription description
/// Adds the given additional script tags on the chart's DisplayOptions. They will be included in the document's <head>
[<CompiledName("WithAdditionalHeadTags")>]
[<Extension>]
member this.WithAdditionalHeadTags (additionalHeadTags:seq<string>) =
this |> Chart.WithAdditionalHeadTags additionalHeadTags
/// Sets the given additional script tags on the chart's DisplayOptions. They will be included in the document's <head>
[<CompiledName("WithHeadTags")>]
[<Extension>]
member this.WithHeadTags (headTags:seq<string>) =
this |> Chart.WithHeadTags headTags
/// Adds the necessary script tags to render tex strings to the chart's DisplayOptions
[<CompiledName("WithMathTex")>]
[<Extension>]
member this.WithMathTex([<Optional;DefaultParameterValue(true)>]?AppendTags:bool) =
let append = Option.defaultValue true AppendTags
this |> Chart.WithMathTex(append)
/// Save chart as html single page
[<CompiledName("SaveHtmlAs")>]
[<Extension>]
member this.SaveHtmlAs (pathName:string, [<Optional;DefaultParameterValue(null)>] ?Verbose) =
Chart.SaveHtmlAs pathName this
/// Show chart in browser
[<CompiledName("Show")>]
[<Extension>]
member this.Show() = this |> Chart.Show
/// Show chart in browser
[<CompiledName("ShowAsImage")>]
[<Extension>]
member this.ShowAsImage (format:StyleParam.ImageFormat) =
this |> Chart.ShowAsImage format