Skip to content

Commit 1174a9e

Browse files
committed
Add withTitle extension
1 parent b568677 commit 1174a9e

File tree

2 files changed

+69
-35
lines changed

2 files changed

+69
-35
lines changed

src/FSharp.Plotly/Chart.fs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,25 @@ type Chart =
349349
Chart.Doughnut(values,Labels=labels,?Name=Name,?Showlegend=Showlegend,?Color=Color,?Hole=Hole,?TextPosition=TextPosition,?TextFont=TextFont,?Hoverinfo=Hoverinfo,?Textinfo=Textinfo,?Opacity=Opacity)
350350

351351

352+
// /// Uses points, line or both depending on the mode to represent data points
353+
// static member Scatter(x, y,mode,?Name,?Showlegend,?MarkerSymbol,?Color,?Opacity,?Labels,?TextPosition,?TextFont,?Dash,?Width) =
354+
// Trace.initScatter (
355+
// TraceStyle.Scatter(X = x,Y = y, Mode=mode) )
356+
// |> TraceStyle.TraceInfo(?Name=Name,?Showlegend=Showlegend,?Opacity=Opacity)
357+
// |> TraceStyle.Line(?Color=Color,?Dash=Dash,?Width=Width)
358+
// |> TraceStyle.Marker(?Color=Color,?Symbol=MarkerSymbol)
359+
// |> TraceStyle.TextLabel(?Text=Labels,?Textposition=TextPosition,?Textfont=TextFont)
360+
// |> GenericChart.ofTraceObject
361+
//
362+
//
363+
// /// Uses points, line or both depending on the mode to represent data points
364+
// static member Scatter(xy,mode,?Name,?Showlegend,?MarkerSymbol,?Color,?Opacity,?Labels,?TextPosition,?TextFont,?Dash,?Width) =
365+
// let x,y = Seq.unzip xy
366+
// 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)
367+
368+
369+
370+
352371
// // /// Computes the bi-dimensional histogram of two data samples and auto-determines the bin size.
353372
// // static member Histogram2d(x,y,?Name,?HistNorm,?HistFunc,?Colorscale,?Showscale,?zSmooth,?Colorbar,?zAuto,?zMin,?zMax,?nBinsx,?nBinsy,?Xbins,?Ybins) =
354373
// // let trace =
@@ -401,7 +420,7 @@ type Chart =
401420

402421
/// Uses points, line or both depending on the mode to represent 3d-data points
403422
static member Mesh3d(x, y, z, mode, ?Name,?Showlegend,?MarkerSymbol,?Color,?Opacity,?Labels,?TextPosition,?TextFont,?Dash,?Width) =
404-
Trace3d.initMesh3d (Trace3dStyle.Mesh3d(X = x,Y = y,Z=z,?Color=Color) )
423+
Trace3d.initMesh3d (Trace3dStyle.Mesh3d(X = x,Y = y,Z=z) ) //,?Color=Color) )
405424
|> TraceStyle.TraceInfo(?Name=Name,?Showlegend=Showlegend,?Opacity=Opacity)
406425
|> TraceStyle.TextLabel(?Text=Labels,?Textposition=TextPosition,?Textfont=TextFont)
407426
|> GenericChart.ofTraceObject

src/FSharp.Plotly/ChartExtensions.fs

Lines changed: 49 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,11 @@ module ChartExtensions =
103103

104104

105105

106-
// // Sets x-Axis of 2d and 3d- Charts
107-
// static member withX_AxisStyle(title,?MinMax,?Showgrid) =
108-
// let range = if MinMax.IsSome then Some (StyleOption.RangeValues.MinMax (MinMax.Value)) else None
109-
// let xaxis = Options.Axis(Title=title,?Range=range,?Showgrid=Showgrid)
110-
// Chart.withX_Axis(xaxis)
106+
// Sets x-Axis style with ...
107+
static member withX_AxisStyle(title,?MinMax,?Showgrid) =
108+
let range = if MinMax.IsSome then Some (StyleParam.RangeValues.MinMax (MinMax.Value)) else None
109+
let xaxis = Axis.LinearAxis.init(Axis.LinearAxis.LinearAxis(Title=title,?Range=range,?Showgrid=Showgrid))
110+
Chart.withX_Axis(xaxis)
111111

112112

113113
// Sets y-Axis of 2d and 3d- Charts
@@ -133,39 +133,56 @@ module ChartExtensions =
133133
GenericChart.addLayout layout ch
134134
)
135135

136-
// // Sets y-Axis of 3d- Charts
137-
// static member withY_AxisStyle(title,?MinMax,?Showgrid) =
138-
// let range = if MinMax.IsSome then Some (StyleOption.RangeValues.MinMax (MinMax.Value)) else None
139-
// let yaxis = Options.Axis(Title=title,?Range=range,?Showgrid=Showgrid)
140-
// Chart.withY_Axis(yaxis)
136+
// Sets y-Axis style with ...
137+
static member withY_AxisStyle(title,?MinMax,?Showgrid) =
138+
let range = if MinMax.IsSome then Some (StyleParam.RangeValues.MinMax (MinMax.Value)) else None
139+
let yaxis = Axis.LinearAxis.init(Axis.LinearAxis.LinearAxis(Title=title,?Range=range,?Showgrid=Showgrid))
140+
Chart.withY_Axis(yaxis)
141141

142142

143143

144-
// // Sets z-Axis of 3d- Charts
145-
// static member withZ_Axis(zAxis:AxisOptions) =
146-
// (fun (ch:GenericChart) ->
147-
// let layout =
148-
// Options.Layout(Scene=Options.Scene(zAxis=zAxis))
149-
// GenericChart.addLayout layout ch
150-
// )
144+
// Sets z-Axis of 3d- Charts
145+
static member withZ_Axis(zAxis:Axis.LinearAxis) =
146+
(fun (ch:GenericChart) ->
147+
let layout =
148+
Layout()
149+
|> Layout.style(Scene=Scene.init(Scene.style (zAxis=zAxis) ))
150+
GenericChart.addLayout layout ch
151+
)
151152

152-
// // Sets z-Axis of 3d- Charts
153-
// static member withZ_AxisStyle(title,?MinMax) =
154-
// let range = if MinMax.IsSome then Some (StyleOption.RangeValues.MinMax (MinMax.Value)) else None
155-
// let zaxis = Options.Axis(Title=title,?Range=range)
156-
// Chart.withZ_Axis(zaxis)
153+
// Sets z-Axis style with ...
154+
static member withZ_AxisStyle(title,?MinMax,?Showgrid) =
155+
let range = if MinMax.IsSome then Some (StyleParam.RangeValues.MinMax (MinMax.Value)) else None
156+
let zaxis = Axis.LinearAxis.init(Axis.LinearAxis.LinearAxis(Title=title,?Range=range,?Showgrid=Showgrid))
157+
Chart.withZ_Axis(zaxis)
157158

158159

159160

161+
// Set the Layout options of a Chart
162+
static member withLayout(layout:Layout) =
163+
(fun (ch:GenericChart) ->
164+
GenericChart.addLayout layout ch)
160165

161166

167+
// Set the title of a Chart
168+
static member withTitle(title,?Titlefont) =
169+
(fun (ch:GenericChart) ->
170+
let layout =
171+
Layout()
172+
|> Layout.style(Title=title,?Titlefont=Titlefont)
173+
GenericChart.addLayout layout ch
174+
)
162175

163176

177+
// Set showLegend of a Chart
178+
static member withLegend(showlegend) =
179+
(fun (ch:GenericChart) ->
180+
let layout =
181+
Layout()
182+
|> Layout.style(Showlegend=showlegend)
183+
GenericChart.addLayout layout ch
184+
)
164185

165-
// Set the Layout options of a Chart
166-
static member withLayout(layout:Layout) =
167-
(fun (ch:GenericChart) ->
168-
GenericChart.addLayout layout ch)
169186

170187
// Set the size of a Chart
171188
static member withSize(width,heigth) =
@@ -218,14 +235,12 @@ module ChartExtensions =
218235
static member Combine(gCharts:seq<GenericChart>) =
219236
GenericChart.combine gCharts
220237

221-
// /// Save chart as html single page
222-
// static member SaveHtmlAs pathName (ch:GenericChart) =
223-
// let html = GenericChart.toEmbeddedHTML ch
224-
// let tempPath = Path.GetTempPath()
225-
// let file = sprintf "%s.html" guid
226-
// let path = Path.Combine(tempPath, file)
227-
// File.WriteAllText(path, html)
228-
// System.Diagnostics.Process.Start(path) |> ignore
238+
/// Save chart as html single page
239+
static member SaveHtmlAs pathName (ch:GenericChart) =
240+
let html = GenericChart.toEmbeddedHTML ch
241+
let file = sprintf "%s.html" pathName // remove file extension
242+
File.WriteAllText(file, html)
243+
System.Diagnostics.Process.Start(file) |> ignore
229244

230245

231246
/// Show chart in browser

0 commit comments

Comments
 (0)