Skip to content

Commit 488568c

Browse files
committed
fix #374 :
- Expand DisplayOptions object with `DocumentTitle`, `DocumentCharset`, `DocumentDescription`, and `DocumentFavicon` fields - these are overwritten with the fields of the second object on combine - this makes `AdditionalHeadTags` clearer, as now nothing will accumulate on the head tag on combine that is on any doc by default - add tests
1 parent c26f0c2 commit 488568c

File tree

6 files changed

+353
-66
lines changed

6 files changed

+353
-66
lines changed

src/Plotly.NET/ChartAPI/Chart.fs

+9-5
Original file line numberDiff line numberDiff line change
@@ -3532,25 +3532,29 @@ type Chart =
35323532
static member withDisplayOptionsStyle
35333533
(
35343534
[<Optional; DefaultParameterValue(null)>] ?AdditionalHeadTags: XmlNode list,
3535-
[<Optional; DefaultParameterValue(null)>] ?Description: XmlNode list,
3535+
[<Optional; DefaultParameterValue(null)>] ?ChartDescription: XmlNode list,
35363536
[<Optional; DefaultParameterValue(null)>] ?PlotlyJSReference: PlotlyJSReference
35373537
) =
35383538
(fun (ch: GenericChart) ->
35393539

35403540
let displayOpts' =
35413541
DisplayOptions.init (
35423542
?AdditionalHeadTags = AdditionalHeadTags,
3543-
?Description = Description,
3543+
?ChartDescription = ChartDescription,
35443544
?PlotlyJSReference = PlotlyJSReference
35453545
)
35463546

35473547
GenericChart.addDisplayOptions displayOpts' ch)
35483548

35493549

3550-
/// Show chart in browser
3550+
/// <summary>
3551+
/// Adds the given chart deycription the to chart's DisplayOptions. They will be included in the document's head
3552+
/// </summary>
3553+
/// <param name="chartDescription">The chart description to add to the given chart's DisplayOptions object</param>
3554+
/// <param name="ch">The chart to add a description to</param>
35513555
[<CompiledName("WithDescription")>]
3552-
static member withDescription (description: XmlNode list) (ch: GenericChart) =
3553-
ch |> GenericChart.mapDisplayOptions (DisplayOptions.addDescription description)
3556+
static member withDescription (chartDescription: XmlNode list) (ch: GenericChart) =
3557+
ch |> GenericChart.mapDisplayOptions (DisplayOptions.addChartDescription chartDescription)
35543558

35553559
/// Adds the given additional html tags on the chart's DisplayOptions. They will be included in the document's head
35563560
[<CompiledName("WithAdditionalHeadTags")>]

src/Plotly.NET/ChartAPI/GenericChart.fs

+22-6
Original file line numberDiff line numberDiff line change
@@ -296,8 +296,8 @@ type GenericChart =
296296

297297
let displayOpts = GenericChart.getDisplayOptions gChart
298298

299-
let description =
300-
displayOpts |> DisplayOptions.getDescription
299+
let chartDescription =
300+
displayOpts |> DisplayOptions.getChartDescription
301301

302302
let plotlyReference =
303303
displayOpts |> DisplayOptions.getPlotlyReference
@@ -312,7 +312,7 @@ type GenericChart =
312312
config = configJson,
313313
plotlyReference = plotlyReference
314314
)
315-
yield! description
315+
yield! chartDescription
316316
]
317317

318318
/// <summary>
@@ -349,16 +349,32 @@ type GenericChart =
349349

350350
let displayOpts = GenericChart.getDisplayOptions gChart
351351

352+
let documentTitle =
353+
(displayOpts |> DisplayOptions.getDocumentTitle)
354+
355+
let documentDescription =
356+
(displayOpts |> DisplayOptions.getDocumentDescription)
357+
358+
let documentCharset =
359+
(displayOpts |> DisplayOptions.getDocumentCharset)
360+
361+
let documentFavicon =
362+
(displayOpts |> DisplayOptions.getDocumentFavicon)
363+
352364
let additionalHeadTags =
353365
(displayOpts |> DisplayOptions.getAdditionalHeadTags)
354366

355-
let description =
356-
(displayOpts |> DisplayOptions.getDescription)
367+
let chartDescription =
368+
(displayOpts |> DisplayOptions.getChartDescription)
357369

358370
let plotlyReference =
359371
displayOpts |> DisplayOptions.getPlotlyReference
360372

361373
HTML.Doc(
374+
documentTitle = documentTitle,
375+
documentDescription = documentDescription,
376+
documentCharset = documentCharset,
377+
documentFavicon = documentFavicon,
362378
chart =
363379
HTML.CreateChartHTML(
364380
data = tracesJson,
@@ -368,7 +384,7 @@ type GenericChart =
368384
),
369385
plotlyReference = plotlyReference,
370386
AdditionalHeadTags = additionalHeadTags,
371-
Description = description
387+
ChartDescription = chartDescription
372388
)
373389
|> RenderView.AsString.htmlDocument
374390

src/Plotly.NET/ChartAPI/HTML.fs

+20-3
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,20 @@ type HTML() =
4343
]
4444

4545

46-
static member Doc(chart, plotlyReference: PlotlyJSReference, ?AdditionalHeadTags, ?Description) =
46+
static member Doc(
47+
chart,
48+
documentTitle: string,
49+
documentDescription: string,
50+
documentCharset: string,
51+
documentFavicon: XmlNode,
52+
plotlyReference: PlotlyJSReference,
53+
?AdditionalHeadTags,
54+
?ChartDescription
55+
) =
4756
let additionalHeadTags =
4857
defaultArg AdditionalHeadTags []
4958

50-
let description = defaultArg Description []
59+
let chartDescription = defaultArg ChartDescription []
5160

5261
let plotlyScriptRef =
5362
match plotlyReference with
@@ -68,9 +77,17 @@ type HTML() =
6877
[]
6978
[
7079
plotlyScriptRef
80+
title [] [ str documentTitle ]
81+
meta [ _charset documentCharset ]
82+
meta
83+
[
84+
_name "description"
85+
_content documentDescription
86+
]
87+
documentFavicon
7188
yield! additionalHeadTags
7289
]
73-
body [] [ yield! chart; yield! description ]
90+
body [] [ yield! chart; yield! chartDescription ]
7491
]
7592

7693
static member CreateChartHTML(data: string, layout: string, config: string, plotlyReference: PlotlyJSReference) =

src/Plotly.NET/Defaults.fs

+11-18
Original file line numberDiff line numberDiff line change
@@ -26,24 +26,17 @@ module Defaults =
2626

2727
let mutable DefaultDisplayOptions =
2828
DisplayOptions.init (
29-
PlotlyJSReference = CDN $"https://cdn.plot.ly/plotly-{Globals.PLOTLYJS_VERSION}.min.js",
30-
AdditionalHeadTags =
31-
[
32-
title [] [ str "Plotly.NET Datavisualization" ]
33-
meta [ _charset "UTF-8" ]
34-
meta
35-
[
36-
_name "description"
37-
_content "A plotly.js graph generated with Plotly.NET"
38-
]
39-
link
40-
[
41-
_id "favicon"
42-
_rel "shortcut icon"
43-
_type "image/png"
44-
_href $"data:image/png;base64,{Globals.LOGO_BASE64}"
45-
]
46-
]
29+
DocumentTitle = "Plotly.NET Datavisualization",
30+
DocumentDescription = "A plotly.js graph generated with Plotly.NET",
31+
DocumentCharset = "UTF-8",
32+
DocumentFavicon =
33+
(link [
34+
_id "favicon"
35+
_rel "shortcut icon"
36+
_type "image/png"
37+
_href $"data:image/png;base64,{Globals.LOGO_BASE64}"
38+
]),
39+
PlotlyJSReference = CDN $"https://cdn.plot.ly/plotly-{Globals.PLOTLYJS_VERSION}.min.js"
4740
)
4841

4942
/// The default chart template. Default: ChartTemplates.plotly

0 commit comments

Comments
 (0)