Skip to content

Commit 9fda3a8

Browse files
committed
Add GenericChart3d and Scatter3d
1 parent 2710cf3 commit 9fda3a8

13 files changed

+1402
-727
lines changed

FSharp.Plotly.sln

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ EndProject
2929
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "content", "content", "{8E6D5255-776D-4B61-85F9-73C37AA1FB9A}"
3030
ProjectSection(SolutionItems) = preProject
3131
docs\content\2d-histograms.fsx = docs\content\2d-histograms.fsx
32+
docs\content\3d-line-plots.fsx = docs\content\3d-line-plots.fsx
33+
docs\content\3d-scatter-plots.fsx = docs\content\3d-scatter-plots.fsx
34+
docs\content\3d-surface-plots.fsx = docs\content\3d-surface-plots.fsx
3235
docs\content\area-plots.fsx = docs\content\area-plots.fsx
3336
docs\content\bar-charts.fsx = docs\content\bar-charts.fsx
3437
docs\content\box-plots.fsx = docs\content\box-plots.fsx

docs/content/3d-line-plots.fsx

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
(*** hide ***)
2+
#r "../../bin/Newtonsoft.Json.dll"
3+
#r "../../bin/FSharp.Plotly.dll"
4+
5+
(**
6+
# FSharp.Plotly: Pie and Doughnut Charts
7+
8+
*Summary:* This example shows how to create pie and doughnut charts in F#.
9+
10+
A pie or a doughnut chart can be created using the `Chart.Pie` and `Chart.Doughnut` functions.
11+
When creating pie or doughnut charts, it is usually desirable to provide both labels and
12+
values.
13+
*)
14+
15+
open FSharp.Plotly
16+
17+
let values = [19; 26; 55;]
18+
let labels = ["Residential"; "Non-Residential"; "Utility"]
19+
20+
(*** define-output:pie1 ***)
21+
Chart.Pie(values,labels)
22+
(*** include-it:pie1 ***)
23+
24+
(*** define-output:doughnut1 ***)
25+
Chart.Doughnut(values,labels,Hole=0.3)
26+
(*** include-it:doughnut1 ***)

docs/content/3d-scatter-plots.fsx

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
(*** hide ***)
2+
#r "../../bin/Newtonsoft.Json.dll"
3+
#r "../../bin/FSharp.Plotly.dll"
4+
5+
(**
6+
# FSharp.Plotly: Pie and Doughnut Charts
7+
8+
*Summary:* This example shows how to create pie and doughnut charts in F#.
9+
10+
A pie or a doughnut chart can be created using the `Chart.Pie` and `Chart.Doughnut` functions.
11+
When creating pie or doughnut charts, it is usually desirable to provide both labels and
12+
values.
13+
*)
14+
15+
open FSharp.Plotly
16+
17+
let x = [19; 26; 55;]
18+
let y = [19; 26; 55;]
19+
let z = [19; 26; 55;]
20+
21+
22+
(*** define-output:scatter3d_1 ***)
23+
Chart3d.Scatter(x,y,z,StyleOption.Mode.Markers)
24+
(*** include-it:scatter3d_1 ***)
25+
|> Chart3d.withSize(900.,900.)
26+
|> Chart3d.Show
27+
28+
29+
30+
31+

docs/content/3d-surface-plots.fsx

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
(*** hide ***)
2+
#r "../../bin/Newtonsoft.Json.dll"
3+
#r "../../bin/FSharp.Plotly.dll"
4+
5+
(**
6+
# FSharp.Plotly: Pie and Doughnut Charts
7+
8+
*Summary:* This example shows how to create pie and doughnut charts in F#.
9+
10+
A pie or a doughnut chart can be created using the `Chart.Pie` and `Chart.Doughnut` functions.
11+
When creating pie or doughnut charts, it is usually desirable to provide both labels and
12+
values.
13+
*)
14+
15+
open FSharp.Plotly
16+
17+
let values = [19; 26; 55;]
18+
let labels = ["Residential"; "Non-Residential"; "Utility"]
19+
20+
(*** define-output:pie1 ***)
21+
Chart.Pie(values,labels)
22+
(*** include-it:pie1 ***)
23+
24+
(*** define-output:doughnut1 ***)
25+
Chart.Doughnut(values,labels,Hole=0.3)
26+
(*** include-it:doughnut1 ***)

docs/content/getting-started.fsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ open FSharp.Plotly
1919

2020
let trace =
2121
Scatter(
22+
2223
x = [1; 2; 3; 4],
2324
y = [12; 9; 15; 12],
2425
mode = "lines+markers"
@@ -28,6 +29,9 @@ let trace =
2829
let layout =
2930
Layout()
3031

32+
trace.get_type
33+
34+
3135
GenericChart.ofTraceObject trace layout
3236
|> Chart.Show
3337

src/FSharp.Plotly/Chart.fs

Lines changed: 41 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,24 +20,48 @@ type Chart =
2020
|> Options.ITextLabel(?Text=Labels,?Textposition=TextPosition,?Textfont=TextFont)
2121
GenericChart.Chart (trace,None)
2222

23+
/// Uses points, line or both depending on the mode to represent data points
24+
static member Scatter(xy, mode, ?Name,?Showlegend,?MarkerSymbol,?Color,?Opacity,?Labels,?TextPosition,?TextFont,?Dash,?Width) =
25+
let x,y = Seq.unzip xy
26+
Chart.Scatter(x, y, mode, ?Name=Name,?Showlegend=Showlegend,?MarkerSymbol=MarkerSymbol,?Color=Color,?Opacity=Opacity,?Labels=Labels,?TextPosition=TextPosition,?TextFont=TextFont,?Dash=Dash,?Width=Width)
27+
28+
/// Uses points to represent data points
29+
static member Point(x, y, ?Name,?Showlegend,?MarkerSymbol,?Color,?Opacity,?Labels,?TextPosition,?TextFont,?Dash,?Width) =
30+
let trace =
31+
TraceObjects.Scatter()
32+
|> Options.Scatter(X = x,Y = y, Mode = StyleOption.Markers)
33+
|> Options.ITraceInfo(?Name=Name,?Showlegend=Showlegend,?Opacity=Opacity)
34+
|> Options.ILine(Options.Line(?Color=Color,?Dash=Dash,?Width=Width))
35+
|> Options.IMarker(Options.Marker(?Color=Color,?Symbol=MarkerSymbol))
36+
|> Options.ITextLabel(?Text=Labels,?Textposition=TextPosition,?Textfont=TextFont)
37+
GenericChart.Chart (trace,None)
38+
39+
/// Uses points to represent data points
40+
static member Point(xy,?Name,?Showlegend,?MarkerSymbol,?Color,?Opacity,?Labels,?TextPosition,?TextFont,?Dash,?Width) =
41+
let x,y = Seq.unzip xy
42+
Chart.Point(x, y, ?Name=Name,?Showlegend=Showlegend,?MarkerSymbol=MarkerSymbol,?Color=Color,?Opacity=Opacity,?Labels=Labels,?TextPosition=TextPosition,?TextFont=TextFont,?Dash=Dash,?Width=Width)
43+
44+
/// Uses lines to represent data points
45+
static member Line(x, y, ?Name,?ShowMarkers,?Showlegend,?MarkerSymbol,?Color,?Opacity,?Labels,?TextPosition,?TextFont,?Dash,?Width) =
46+
let mode' =
47+
match ShowMarkers with
48+
| Some show -> if show then StyleOption.Lines_Markers else StyleOption.Lines
49+
| None -> StyleOption.Lines_Markers // default
50+
let trace =
51+
TraceObjects.Scatter()
52+
|> Options.Scatter(X = x,Y = y, Mode = mode')
53+
|> Options.ITraceInfo(?Name=Name,?Showlegend=Showlegend,?Opacity=Opacity)
54+
|> Options.ILine(Options.Line(?Color=Color,?Dash=Dash,?Width=Width))
55+
|> Options.IMarker(Options.Marker(?Color=Color,?Symbol=MarkerSymbol))
56+
|> Options.ITextLabel(?Text=Labels,?Textposition=TextPosition,?Textfont=TextFont)
57+
GenericChart.Chart (trace,None)
58+
59+
/// Uses lines to represent data points
60+
static member Line(xy,?Name,?ShowMarkers,?Showlegend,?MarkerSymbol,?Color,?Opacity,?Labels,?TextPosition,?TextFont,?Dash,?Width) =
61+
let x,y = Seq.unzip xy
62+
Chart.Line(x, y, ?Name=Name,?ShowMarkers=ShowMarkers,?Showlegend=Showlegend,?MarkerSymbol=MarkerSymbol,?Color=Color,?Opacity=Opacity,?Labels=Labels,?TextPosition=TextPosition,?TextFont=TextFont,?Dash=Dash,?Width=Width)
63+
2364

24-
// /// Uses points to represent data points.
25-
// static member Point(x, y, ?Name,?Showlegend,?Color,?Opacity,?MarkerSymbol,?Labels) =
26-
// let trace =
27-
// TraceObjects.Scatter()
28-
// |> Options.Scatter(X = x,Y = y, Mode=StyleOption.Markers,
29-
// TraceOptions=Options.Trace(?Name=Name,?Showlegend=Showlegend,?Opacity=Opacity),
30-
// Marker=Options.Marker(?Color=Color,?Symbol=MarkerSymbol),
31-
// ?Fillcolor=Color,?Text=Labels)
32-
// GenericChart.Chart (trace,None)
33-
//
34-
//
35-
// /// Uses points to represent data points.
36-
// static member Point(xy, ?Name,?Showlegend,?Color,?Opacity,?MarkerSymbol,?Labels) =
37-
// let x,y = Seq.unzip xy
38-
// Chart.Point(x,y, ?Name=Name,?Showlegend=Showlegend,?Color=Color,?Opacity=Opacity,?MarkerSymbol=MarkerSymbol,?Labels=Labels)
39-
//
40-
//
4165
// /// Uses a line to connect the data points represented.
4266
// static member Line(x, y,?Name,?ShowMarkers,?Dash,?Showlegend,?Width,?Color,?Opacity,?MarkerSymbol,?Labels) =
4367
// let mode' = match ShowMarkers with

src/FSharp.Plotly/Chart3d.fs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,23 @@
1-
module Chart3d
1+
namespace FSharp.Plotly
2+
3+
open System
4+
open System.IO
5+
open FSharp.Care.Collections
6+
7+
open GenericChart3d
8+
9+
/// Provides a set of static methods for creating charts.
10+
type Chart3d =
11+
12+
/// Uses points, line or both depending on the mode to represent data points
13+
static member Scatter(x, y, z, mode, ?Name,?Showlegend,?MarkerSymbol,?Color,?Opacity,?Labels,?TextPosition,?TextFont,?Dash,?Width) =
14+
let trace =
15+
Trace3dObjects.Scatter3d()
16+
|> Options3d.Scatter3d(X = x,Y = y,Z=z, Mode=mode)
17+
|> Options.ITraceInfo(?Name=Name,?Showlegend=Showlegend,?Opacity=Opacity)
18+
|> Options.ILine(Options.Line(?Color=Color,?Dash=Dash,?Width=Width))
19+
|> Options.IMarker(Options.Marker(?Color=Color,?Symbol=MarkerSymbol))
20+
|> Options.ITextLabel(?Text=Labels,?Textposition=TextPosition,?Textfont=TextFont)
21+
GenericChart3d.Chart (trace,None)
22+
223

src/FSharp.Plotly/Chart3dExtensions.fs

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,32 @@
33
open System
44
open System.IO
55

6-
open GenericChart
6+
open GenericChart3d
77

88
/// Extensions methods for 3d-Charts supporting the fluent pipeline style 'Chart3d.WithXYZ(...)'.
99
[<AutoOpen>]
1010
module Chart3dExtensions =
11+
12+
/// Provides a set of static methods for creating charts.
13+
type Chart3d with
14+
15+
static member withSize(width,heigth) =
16+
(fun (ch:GenericChart3d) ->
17+
let layout = Options.Layout(Width=width,Height=heigth)
18+
GenericChart3d.addLayout layout ch)
1119

12-
let a = 42
20+
// #######################
21+
/// Create a combined chart with the given charts merged
22+
static member Combine(gCharts:seq<GenericChart3d>) =
23+
GenericChart3d.combine gCharts
24+
25+
/// Show chart in browser
26+
static member Show (ch:GenericChart3d) =
27+
let guid = Guid.NewGuid().ToString()
28+
let html = GenericChart3d.toEmbeddedHTML ch
29+
let tempPath = Path.GetTempPath()
30+
let file = sprintf "%s.html" guid
31+
let path = Path.Combine(tempPath, file)
32+
File.WriteAllText(path, html)
33+
System.Diagnostics.Process.Start(path) |> ignore
1334

src/FSharp.Plotly/GenericChart.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ module HTML =
2929
</script>"""
3030

3131

32-
/// Module
32+
/// Module to represent a GenericChart
3333
module GenericChart =
3434
// 'T when 'T :> ITrace
3535
type GenericChart =

0 commit comments

Comments
 (0)