Skip to content

Commit 4093086

Browse files
committed
Add missing Annotation parameters (fixes #147)
1 parent 417b88f commit 4093086

6 files changed

Lines changed: 238 additions & 101 deletions

File tree

docs/1_4_annotations.fsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ let y' = [2.; 1.5; 5.; 1.5; 3.; 2.5; 2.5; 1.5; 3.5; 1.]
4343
use the `Annotation.init` function to generate a shape, and either the `Chart.withAnnotation` or the `Chart.withAnnotations` function to add
4444
multiple annotations at once.
4545
46-
**Attention**: Adding an annotation after you added a previous one currently removes the old one. This is a bug and will be fixed
4746
*)
4847

4948
open Plotly.NET.LayoutObjects

src/Plotly.NET/ChartAPI/Chart.fs

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -792,12 +792,36 @@ type Chart =
792792
(fun (ch:GenericChart) ->
793793
GenericChart.setConfig config ch)
794794

795+
/// <summary>
796+
///
797+
/// </summary>
798+
/// <param name="annotations">The annotations to add to the input charts layout</param>
799+
/// <param name="Append">If true, the input annotations will be appended to existing annotations, otherwise existing annotations will be removed (default: true)</param>
795800
[<CompiledName("WithAnnotations")>]
796-
static member withAnnotations(annotations:seq<Annotation>) =
797-
(fun (ch:GenericChart) ->
798-
ch
799-
|> GenericChart.mapLayout
800-
(Layout.style (Annotations = annotations)))
801+
static member withAnnotations
802+
(
803+
annotations:seq<Annotation>,
804+
[<Optional;DefaultParameterValue(true)>] ?Append: bool
805+
) =
806+
let append = defaultArg Append true
807+
808+
fun (ch:GenericChart) ->
809+
810+
let annotations' =
811+
812+
if append then
813+
814+
let layout = GenericChart.getLayout ch
815+
816+
layout.TryGetTypedValue<seq<Annotation>>("annotations")
817+
|> Option.defaultValue Seq.empty
818+
|> Seq.append annotations
819+
820+
else annotations
821+
822+
ch
823+
|> GenericChart.mapLayout
824+
(Layout.style (Annotations = annotations'))
801825

802826
// Set the title of a Chart
803827
[<CompiledName("WithTitle")>]

src/Plotly.NET/CommonAbstractions/StyleParams.fs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,31 @@ module StyleParam =
1313
// #A#
1414
//--------------------------
1515

16+
[<RequireQualifiedAccess>]
17+
type ArrowSide =
18+
| Start | End | StartEnd | None
19+
20+
static member toString = function
21+
| Start -> "start"
22+
| End -> "end"
23+
| StartEnd -> "startend"
24+
| None -> "none"
25+
static member convert = ArrowSide.toString >> box
26+
override this.ToString() = this |> ArrowSide.toString
27+
member this.Convert() = this |> ArrowSide.convert
28+
29+
[<RequireQualifiedAccess>]
30+
type AnnotationAlignment =
31+
| Left | Center | Right
32+
33+
static member toString = function
34+
| Left -> "left"
35+
| Center-> "center"
36+
| Right -> "right"
37+
static member convert = AnnotationAlignment.toString >> box
38+
override this.ToString() = this |> AnnotationAlignment.toString
39+
member this.Convert() = this |> AnnotationAlignment.convert
40+
1641
[<RequireQualifiedAccess>]
1742
type AspectMode =
1843
| Auto | Cube | Data | Manual
@@ -289,6 +314,19 @@ module StyleParam =
289314
// #C#
290315
//--------------------------
291316

317+
[<RequireQualifiedAccess>]
318+
type ClickToShow =
319+
| False | OnOff | OnOut
320+
321+
static member toString = function
322+
| False -> "false"
323+
| OnOff -> "onoff"
324+
| OnOut -> "onout"
325+
326+
static member convert = ClickToShow.toString >> box
327+
override this.ToString() = this |> ClickToShow.toString
328+
member this.Convert() = this |> ClickToShow.convert
329+
292330
[<RequireQualifiedAccess>]
293331
type ConstrainText =
294332
| Inside

0 commit comments

Comments
 (0)