Skip to content

Commit 50afa5f

Browse files
committed
WIP: Add image export docs
1 parent 4734fdd commit 50afa5f

File tree

4 files changed

+122
-2
lines changed

4 files changed

+122
-2
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,3 +190,4 @@ temp/gh-pages
190190
/src/Plotly.NET.ImageExport/.local-chromium
191191
/src/Plotly.NET.ImageExport/testrenders
192192
/src/Plotly.NET.Interactive/.local-chromium/
193+
/docs/.local-chromium/

Plotly.NET.sln

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ EndProject
5151
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "content", "content", "{60FB82C0-F472-494E-BCF7-7B3C54212406}"
5252
ProjectSection(SolutionItems) = preProject
5353
docs\0_0_basics.fsx = docs\0_0_basics.fsx
54+
docs\0_1_image-export.fsx = docs\0_1_image-export.fsx
5455
docs\1_0_axis-styling.fsx = docs\1_0_axis-styling.fsx
5556
docs\1_1_errorbars.fsx = docs\1_1_errorbars.fsx
5657
docs\1_2_multiple-charts.fsx = docs\1_2_multiple-charts.fsx
@@ -102,7 +103,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "img", "img", "{CDB973F2-0F6
102103
docs\img\logo.png = docs\img\logo.png
103104
EndProjectSection
104105
EndProject
105-
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Plotly.NET.ImageExport", "src\Plotly.NET.ImageExport\Plotly.NET.ImageExport.fsproj", "{6CFC629E-1A0C-4EF3-8495-BA00A356A381}"
106+
Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "Plotly.NET.ImageExport", "src\Plotly.NET.ImageExport\Plotly.NET.ImageExport.fsproj", "{6CFC629E-1A0C-4EF3-8495-BA00A356A381}"
106107
EndProject
107108
Global
108109
GlobalSection(SolutionConfigurationPlatforms) = preSolution

docs/0_1_image-export.fsx

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
(**
2+
---
3+
title: Basics
4+
category: General
5+
categoryindex: 1
6+
index: 2
7+
---
8+
*)
9+
10+
11+
(*** hide ***)
12+
13+
(*** condition: prepare ***)
14+
#r "nuget: Newtonsoft.JSON, 12.0.3"
15+
#r "nuget: PuppeteerSharp"
16+
#r "../bin/Plotly.NET/netstandard2.0/Plotly.NET.dll"
17+
#r "../bin/Plotly.NET.ImageExport/netstandard2.0/Plotly.NET.ImageExport.dll"
18+
19+
(*** condition: ipynb ***)
20+
#if IPYNB
21+
#r "nuget: Plotly.NET, {{fsdocs-package-version}}"
22+
#r "nuget: Plotly.NET.Interactive, {{fsdocs-package-version}}"
23+
#r "nuget: Plotly.NET.ImageExport, {{fsdocs-package-version}}"
24+
#endif // IPYNB
25+
26+
27+
(**
28+
[![Binder]({{root}}img/badge-binder.svg)](https://mybinder.org/v2/gh/plotly/Plotly.NET/gh-pages?filepath={{fsdocs-source-basename}}.ipynb) 
29+
[![Script]({{root}}img/badge-script.svg)]({{root}}{{fsdocs-source-basename}}.fsx) 
30+
[![Notebook]({{root}}img/badge-notebook.svg)]({{root}}{{fsdocs-source-basename}}.ipynb)
31+
32+
# Static image export
33+
34+
The supported image types are:
35+
- jpg via `Chart.SaveJPG`
36+
- png via `Chart.SavePNG`
37+
- svg via `Chart.SaveSVG`
38+
39+
The parameters for all three functions are exactly the same.
40+
*)
41+
42+
open Plotly.NET
43+
open Plotly.NET.ImageExport
44+
45+
let exampleChart =
46+
Chart.Histogram2dContour(
47+
[1.;2.;2.;4.;5.],
48+
[1.;2.;2.;4.;5.]
49+
)
50+
51+
(***do-not-eval***)
52+
exampleChart
53+
|> Chart.saveJPG(
54+
"/your/path/without/extension/here",
55+
Width=300,
56+
Height=300
57+
)
58+
59+
#if IPYNB
60+
61+
let imgString = $"""<img
62+
src= "{exampleChart|> Chart.toBase64JPGString(Width=300,Height=300)}"
63+
/>"""
64+
65+
DisplayExtensions.DisplayAs(imgString,"text/html")
66+
67+
#endif // IPYNB
68+
69+
(***hide***)
70+
$"""<img
71+
src= "{exampleChart|> Chart.toBase64JPGString(Width=300,Height=300)}"
72+
/>"""
73+
74+
(***include-it-raw***)
75+
76+
(**
77+
78+
*)
79+
80+
let base64JPG =
81+
exampleChart
82+
|> Chart.toBase64PNGString(
83+
Width=300,
84+
Height=300
85+
)
86+
87+
#if IPYNB
88+
89+
let imgString = $"""<img
90+
src= "{base64JPG}"
91+
/>"""
92+
93+
DisplayExtensions.DisplayAs(imgString,"text/html")
94+
95+
#endif // IPYNB
96+
97+
$"""<img
98+
src= "{base64JPG}"
99+
/>"""
100+
(***include-it-raw***)
101+
102+
103+
(**
104+
*)
105+
106+
let svgString =
107+
exampleChart
108+
|> Chart.toSVGString(
109+
Width=300,
110+
Height=300
111+
)
112+
113+
#if IPYNB
114+
DisplayExtensions.DisplayAs(svgString,"image/svg+xml")
115+
#endif // IPYNB
116+
117+
svgString
118+
(***include-it-raw***)

src/Plotly.NET.ImageExport/Plotly.NET.ImageExport.fsproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net5.0</TargetFramework>
4+
<TargetFrameworks>net5.0; netstandard2.0</TargetFrameworks>
55
<GenerateDocumentationFile>true</GenerateDocumentationFile>
66
<WarnOn>3390;$(WarnOn)</WarnOn>
77
</PropertyGroup>

0 commit comments

Comments
 (0)