Skip to content

Commit 7bf912e

Browse files
committed
#293: Add plotly cdn option to display options, refactor Display options and object combine functions
1 parent 778d8e5 commit 7bf912e

File tree

8 files changed

+376
-183
lines changed

8 files changed

+376
-183
lines changed

src/Plotly.NET/ChartAPI/Chart.fs

Lines changed: 90 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -739,7 +739,7 @@ type Chart =
739739
/// <summary>
740740
/// Applies the given styles to the chart's Layout object. Overwrites attributes with the same name that are already set.
741741
/// </summary>
742-
/// <param name="Title">Sets the title of the layout.</param>
742+
/// <param name="Title">Sets the title of the layout.</param>
743743
/// <param name="ShowLegend">Determines whether or not a legend is drawn. Default is `true` if there is a trace to show and any of these: a) Two or more traces would by default be shown in the legend. b) One pie trace is shown in the legend. c) One trace is explicitly given with `showlegend: true`.</param>
744744
/// <param name="Legend">Sets the legend styles of the layout.</param>
745745
/// <param name="Margin">Sets the margins around the layout.</param>
@@ -3191,53 +3191,6 @@ type Chart =
31913191
?YSide = YSide
31923192
)
31933193

3194-
// ############################################################
3195-
// ####################### Apply to DisplayOptions
3196-
3197-
/// Show chart in browser
3198-
[<CompiledName("WithDescription")>]
3199-
static member withDescription (description: XmlNode list) (ch: GenericChart) =
3200-
ch |> mapDisplayOptions (DisplayOptions.addDescription description)
3201-
3202-
3203-
3204-
/// Adds the given additional html tags on the chart's DisplayOptions. They will be included in the document's <head>
3205-
[<CompiledName("WithAdditionalHeadTags")>]
3206-
static member withAdditionalHeadTags (additionalHeadTags: XmlNode list) (ch: GenericChart) =
3207-
ch |> mapDisplayOptions (DisplayOptions.addAdditionalHeadTags additionalHeadTags)
3208-
3209-
/// Sets the given additional head tags on the chart's DisplayOptions. They will be included in the document's <head>
3210-
[<CompiledName("WithHeadTags")>]
3211-
static member withHeadTags (headTags: XmlNode list) (ch: GenericChart) =
3212-
ch |> mapDisplayOptions (fun d -> {d with AdditionalHeadTags = headTags})
3213-
3214-
3215-
/// Adds the necessary script tags to render tex strings to the chart's DisplayOptions
3216-
[<CompiledName("WithMathTex")>]
3217-
static member withMathTex(
3218-
[<Optional; DefaultParameterValue(true)>] ?AppendTags: bool,
3219-
[<Optional; DefaultParameterValue(3)>] ?MathJaxVersion: int
3220-
) =
3221-
let version = MathJaxVersion |> Option.defaultValue 3
3222-
3223-
let tags =
3224-
if version = 2 then
3225-
Globals.MATHJAX_V2_TAGS
3226-
else
3227-
Globals.MATHJAX_V3_TAGS
3228-
3229-
(fun (ch: GenericChart) ->
3230-
3231-
if (AppendTags |> Option.defaultValue true) then
3232-
ch
3233-
|> Chart.withAdditionalHeadTags tags
3234-
|> Chart.withConfigStyle(TypesetMath=true)
3235-
else
3236-
ch
3237-
|> Chart.withHeadTags tags
3238-
|> Chart.withConfigStyle(TypesetMath=true)
3239-
)
3240-
32413194

32423195
/// Sets the color axis with the given id on the chart layout
32433196
[<CompiledName("WithColorAxis")>]
@@ -3323,3 +3276,92 @@ type Chart =
33233276

33243277
[<CompiledName("WithSlider")>]
33253278
static member withSlider(slider: Slider) = Chart.withSliders ([ slider ])
3279+
3280+
3281+
// ############################################################
3282+
// ####################### Apply to DisplayOptions
3283+
3284+
// <summary>
3285+
/// Sets the given DisplayOptions on the input chart.
3286+
///
3287+
/// If there is already an DisplayOptions set, the object is replaced.
3288+
/// </summary>
3289+
[<CompiledName("SetDisplayOptions")>]
3290+
static member setDisplayOptions(displayOpts: DisplayOptions) =
3291+
(fun (ch: GenericChart) -> GenericChart.setDisplayOptions displayOpts ch)
3292+
3293+
/// <summary>
3294+
/// Sets the given DisplayOptions on the input chart.
3295+
///
3296+
/// If there is already an DisplayOptions set, the objects are combined.
3297+
/// </summary>
3298+
[<CompiledName("WithDisplayOptions")>]
3299+
static member withDisplayOptions(displayOpts: DisplayOptions) =
3300+
(fun (ch: GenericChart) -> GenericChart.addDisplayOptions displayOpts ch)
3301+
3302+
/// <summary>
3303+
/// Applies the given styles to the chart's DisplayOptions object. Overwrites attributes with the same name that are already set.
3304+
/// </summary>
3305+
/// <param name="AdditionalHeadTags">Additional tags that will be included in the document's head </param>
3306+
/// <param name="Description">HTML tags that appear below the chart in HTML docs</param>
3307+
/// <param name="PlotlyCDN">The PlotlyCDN address used in html docs</param>
3308+
[<CompiledName("WithDisplayOptionsStyle")>]
3309+
static member withDisplayOptionsStyle
3310+
(
3311+
[<Optional; DefaultParameterValue(null)>] ?AdditionalHeadTags: XmlNode list,
3312+
[<Optional; DefaultParameterValue(null)>] ?Description: XmlNode list,
3313+
[<Optional; DefaultParameterValue(null)>] ?PlotlyCDN: string
3314+
) =
3315+
(fun (ch: GenericChart) ->
3316+
3317+
let displayOpts' =
3318+
DisplayOptions.init (
3319+
?AdditionalHeadTags = AdditionalHeadTags,
3320+
?Description = Description,
3321+
?PlotlyCDN = PlotlyCDN
3322+
)
3323+
3324+
GenericChart.addDisplayOptions displayOpts' ch)
3325+
3326+
3327+
/// Show chart in browser
3328+
[<CompiledName("WithDescription")>]
3329+
static member withDescription (description: XmlNode list) (ch: GenericChart) =
3330+
ch |> mapDisplayOptions (DisplayOptions.addDescription description)
3331+
3332+
/// Adds the given additional html tags on the chart's DisplayOptions. They will be included in the document's head
3333+
[<CompiledName("WithAdditionalHeadTags")>]
3334+
static member withAdditionalHeadTags (additionalHeadTags: XmlNode list) (ch: GenericChart) =
3335+
ch |> mapDisplayOptions (DisplayOptions.addAdditionalHeadTags additionalHeadTags)
3336+
3337+
/// Sets the given additional head tags on the chart's DisplayOptions. They will be included in the document's head
3338+
[<CompiledName("WithHeadTags")>]
3339+
static member withHeadTags (additionalHeadTags: XmlNode list) (ch: GenericChart) =
3340+
ch |> mapDisplayOptions (DisplayOptions.setAdditionalHeadTags additionalHeadTags)
3341+
3342+
3343+
/// Adds the necessary script tags to render tex strings to the chart's DisplayOptions
3344+
[<CompiledName("WithMathTex")>]
3345+
static member withMathTex(
3346+
[<Optional; DefaultParameterValue(true)>] ?AppendTags: bool,
3347+
[<Optional; DefaultParameterValue(3)>] ?MathJaxVersion: int
3348+
) =
3349+
let version = MathJaxVersion |> Option.defaultValue 3
3350+
3351+
let tags =
3352+
if version = 2 then
3353+
Globals.MATHJAX_V2_TAGS
3354+
else
3355+
Globals.MATHJAX_V3_TAGS
3356+
3357+
(fun (ch: GenericChart) ->
3358+
3359+
if (AppendTags |> Option.defaultValue true) then
3360+
ch
3361+
|> Chart.withAdditionalHeadTags tags
3362+
|> Chart.withConfigStyle(TypesetMath=true)
3363+
else
3364+
ch
3365+
|> Chart.withHeadTags tags
3366+
|> Chart.withConfigStyle(TypesetMath=true)
3367+
)

0 commit comments

Comments
 (0)