Skip to content

Commit cdd7653

Browse files
muehlmuehl
authored andcommitted
Add BIns as DynamicObj
1 parent 3e6da06 commit cdd7653

File tree

5 files changed

+186
-29
lines changed

5 files changed

+186
-29
lines changed

docs/content/heatmaps.fsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ let colnames = ["Tp0";"Tp30";"Tp60";"Tp160"]
2525

2626

2727
let colorscaleValue =
28-
//StyleOption.ColorScale.Electric
29-
StyleOption.ColorScale.Custom [(0.0,"#3D9970");(1.0,"#001f3f")]
28+
//StyleParam.ColorScale.Electric
29+
StyleParam.ColorScale.Custom [(0.0,"#3D9970");(1.0,"#001f3f")]
3030
// Generating the Heatmap
3131
(*** define-output:heat1 ***)
3232
Chart.Heatmap(matrix,colnames,rownames,Colorscale=colorscaleValue,Showscale=true)

src/FSharp.Plotly/Bins.fs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
namespace FSharp.Plotly
2+
3+
/// Module containing plotly Bins
4+
module Bins =
5+
6+
/// Bin type inherits from dynamic object
7+
type Bins () =
8+
inherit DynamicObj ()
9+
10+
type BinsStyle =
11+
12+
// Applies the styles to Bins()
13+
static member BinsStyle
14+
(
15+
?StartBins:float,
16+
?EndBins:float,
17+
?Size
18+
) =
19+
20+
(fun (bins:('T :> Bins)) ->
21+
StartBins |> DynObj.setValueOpt bins "start"
22+
EndBins |> DynObj.setValueOpt bins "end"
23+
Size |> DynObj.setValueOpt bins "size"
24+
25+
bins
26+
)

src/FSharp.Plotly/Chart.fs

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -288,8 +288,8 @@ type Chart =
288288
/// Displays the distribution of data based on the five number summary: minimum, first quartile, median, third quartile, and maximum.
289289
static member BoxPlot(?x,?y,?Name,?Showlegend,?Color,?Opacity,?Whiskerwidth,?Boxpoints,?Boxmean,?Jitter,?Pointpos,?Orientation) =
290290
Trace.initBoxPlot (TraceStyle.BoxPlot(?X=x, ?Y = y,
291-
?Whiskerwidth=Whiskerwidth,?Boxpoints=Boxpoints,
292-
?Boxmean=Boxmean,?Jitter=Jitter,?Pointpos=Pointpos,?Orientation=Orientation,?Fillcolor=Color) )
291+
?Whiskerwidth=Whiskerwidth,?Boxpoints=Boxpoints,
292+
?Boxmean=Boxmean,?Jitter=Jitter,?Pointpos=Pointpos,?Orientation=Orientation,?Fillcolor=Color) )
293293
|> TraceStyle.TraceInfo(?Name=Name,?Showlegend=Showlegend,?Opacity=Opacity)
294294
|> GenericChart.ofTraceObject
295295

@@ -300,27 +300,21 @@ type Chart =
300300
Chart.BoxPlot(x, y, ?Name=Name,?Showlegend=Showlegend,?Color=Color,?Opacity=Opacity,?Whiskerwidth=Whiskerwidth,?Boxpoints=Boxpoints,?Boxmean=Boxmean,?Jitter=Jitter,?Pointpos=Pointpos,?Orientation=Orientation)
301301

302302

303-
// /// Shows a graphical representation of a 3-dimensional surface by plotting constant z slices, called contours, on a 2-dimensional format.
304-
// /// That is, given a value for z, lines are drawn for connecting the (x,y) coordinates where that z value occurs.
305-
// static member Heatmap(data:seq<#seq<#IConvertible>>,?ColNames,?RowNames,?Name,?Showlegend,?Opacity,?Colorscale,?Showscale,?zSmooth,?Colorbar) =
306-
// let trace =
307-
// Heatmap()
308-
// |> Options.IMapZ(Z=data,?X=ColNames, ?Y=RowNames)
309-
// |> Options.IColormap(?Colorscale=Colorscale,?Showscale=Showscale,?zSmooth=zSmooth,?Colorbar=Colorbar)
310-
// |> Options.ITraceInfo(?Name=Name,?Showlegend=Showlegend,?Opacity=Opacity)
311-
// //|> Options.ITextLabel(?Text=Labels,?Textposition=TextPosition,?Textfont=TextFont)
312-
// GenericChart.Chart (trace,None)
303+
/// Shows a graphical representation of a 3-dimensional surface by plotting constant z slices, called contours, on a 2-dimensional format.
304+
/// That is, given a value for z, lines are drawn for connecting the (x,y) coordinates where that z value occurs.
305+
static member Heatmap(data:seq<#seq<#IConvertible>>,?ColNames,?RowNames,?Name,?Showlegend,?Opacity,?Colorscale,?Showscale,?Xgap,?Ygap,?zSmooth,?Colorbar) =
306+
Trace.initHeatmap (TraceStyle.Heatmap(Z=data,?X=ColNames, ?Y=RowNames,
307+
?Xgap=Xgap,?Ygap=Ygap,?Colorscale=Colorscale,?Showscale=Showscale,?zSmooth=zSmooth,?Colorbar=Colorbar) )
308+
|> TraceStyle.TraceInfo(?Name=Name,?Showlegend=Showlegend,?Opacity=Opacity)
309+
|> GenericChart.ofTraceObject
313310

314311

315-
// /// Shows a graphical representation of data where the individual values contained in a matrix are represented as colors.
316-
// static member Contour(data:seq<#seq<#IConvertible>>,?X,?Y,?Name,?Showlegend,?Opacity,?Colorscale,?Showscale,?zSmooth,?Colorbar) =
317-
// let trace =
318-
// Contour()
319-
// |> Options.IMapZ(Z=data,?X=X, ?Y=Y)
320-
// |> Options.IColormap(?Colorscale=Colorscale,?Showscale=Showscale,?zSmooth=zSmooth,?Colorbar=Colorbar)
321-
// |> Options.ITraceInfo(?Name=Name,?Showlegend=Showlegend,?Opacity=Opacity)
322-
// //|> Options.ITextLabel(?Text=Labels,?Textposition=TextPosition,?Textfont=TextFont)
323-
// GenericChart.Chart (trace,None)
312+
/// Shows a graphical representation of data where the individual values contained in a matrix are represented as colors.
313+
static member Contour(data:seq<#seq<#IConvertible>>,?X,?Y,?Name,?Showlegend,?Opacity,?Colorscale,?Showscale,?zSmooth,?Colorbar) =
314+
Trace.initContour (TraceStyle.Contour(Z=data,?X=X, ?Y=Y,
315+
?Colorscale=Colorscale,?Showscale=Showscale,?zSmooth=zSmooth,?Colorbar=Colorbar) )
316+
|> TraceStyle.TraceInfo(?Name=Name,?Showlegend=Showlegend,?Opacity=Opacity)
317+
|> GenericChart.ofTraceObject
324318

325319

326320
/// Shows how proportions of data, shown as pie-shaped pieces, contribute to the data.

src/FSharp.Plotly/FSharp.Plotly.fsproj

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,18 +66,16 @@
6666
<Compile Include="Marker.fs" />
6767
<Compile Include="Font.fs" />
6868
<Compile Include="Axis.fs" />
69+
<Compile Include="Bins.fs" />
6970
<Compile Include="Scene3d.fs" />
7071
<Compile Include="Shape.fs" />
7172
<Compile Include="Error.fs" />
72-
7373
<Compile Include="Trace.fs" />
7474
<Compile Include="Trace3d.fs" />
7575
<Compile Include="Layout.fs" />
76-
7776
<Compile Include="GenericChart.fs" />
7877
<Compile Include="Chart.fs" />
7978
<Compile Include="ChartExtensions.fs" />
80-
8179
<None Include="Script.fsx" />
8280
<None Include="Script.fsx" />
8381
<None Include="paket.references" />

src/FSharp.Plotly/Trace.fs

Lines changed: 142 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,15 @@ module Trace =
3030
let initPie (applyStyle:Trace->Trace) =
3131
Trace("pie") |> applyStyle
3232

33+
/// Init trace for Heatmap
34+
let initHeatmap (applyStyle:Trace->Trace) =
35+
Trace("heatmap") |> applyStyle
36+
37+
/// Init trace for Contour
38+
let initContour (applyStyle:Trace->Trace) =
39+
Trace("contour") |> applyStyle
40+
41+
3342
/// Functions provide the styling of the Chart objects
3443
type TraceStyle() =
3544

@@ -254,7 +263,7 @@ module Trace =
254263
)
255264

256265

257-
// Applies the styles to Bar()
266+
// Applies the styles of bar plot to TraceObjects
258267
static member Bar
259268
(
260269
?X : seq<#IConvertible>,
@@ -283,7 +292,7 @@ module Trace =
283292

284293
)
285294

286-
// Applies the styles to Pie()
295+
// Applies the styles of pie plot to TraceObjects
287296
static member Pie
288297
(
289298
?Values,
@@ -336,7 +345,7 @@ module Trace =
336345
)
337346

338347

339-
// Applies the styles to |> DynObj.setValueOpt pie "
348+
// Applies the styles of box plot plot to TraceObjects
340349
static member BoxPlot
341350
(
342351
?Y,
@@ -381,6 +390,136 @@ module Trace =
381390

382391

383392

393+
// Applies the styles of heatmap to TraceObjects
394+
static member Heatmap
395+
(
396+
?Z : seq<#seq<#IConvertible>>,
397+
?X : seq<#IConvertible>,
398+
?Y : seq<#IConvertible>,
399+
?X0 ,
400+
?dX ,
401+
?Y0 ,
402+
?dY ,
403+
?xType ,
404+
?yType ,
405+
?xAxis ,
406+
?yAxis ,
407+
?Zsrc ,
408+
?Xsrc ,
409+
?Ysrc ,
410+
411+
?Xgap ,
412+
?Ygap ,
413+
?Transpose ,
414+
?zAuto ,
415+
?zMin ,
416+
?zMax ,
417+
?Colorscale ,
418+
?Autocolorscale ,
419+
?Reversescale ,
420+
?Showscale ,
421+
?zSmooth ,
422+
?Colorbar
423+
) =
424+
(fun (heatmap:('T :> Trace)) ->
425+
426+
Z |> DynObj.setValueOpt heatmap "z"
427+
X |> DynObj.setValueOpt heatmap "x"
428+
Y |> DynObj.setValueOpt heatmap "y"
429+
X0 |> DynObj.setValueOpt heatmap "x0"
430+
dX |> DynObj.setValueOpt heatmap "dx"
431+
Y0 |> DynObj.setValueOpt heatmap "y0"
432+
dY |> DynObj.setValueOpt heatmap "dy"
433+
xType |> DynObj.setValueOpt heatmap "xtype"
434+
yType |> DynObj.setValueOpt heatmap "ytype"
435+
xAxis |> DynObj.setValueOpt heatmap "xaxis"
436+
yAxis |> DynObj.setValueOpt heatmap "yaxis"
437+
Zsrc |> DynObj.setValueOpt heatmap "zsrc"
438+
Xsrc |> DynObj.setValueOpt heatmap "xsrc"
439+
Ysrc |> DynObj.setValueOpt heatmap "ysrc"
440+
441+
Xgap |> DynObj.setValueOpt heatmap "xgap"
442+
Ygap |> DynObj.setValueOpt heatmap "ygap"
443+
Transpose |> DynObj.setValueOpt heatmap "transpose"
444+
zAuto |> DynObj.setValueOpt heatmap "zauto"
445+
zMin |> DynObj.setValueOpt heatmap "zmin"
446+
zMax |> DynObj.setValueOpt heatmap "zmax"
447+
Colorscale |> DynObj.setValueOptBy heatmap "colorscale" StyleParam.ColorScale.convert
448+
Autocolorscale |> DynObj.setValueOpt heatmap "autocolorscale"
449+
Reversescale |> DynObj.setValueOpt heatmap "reversescale"
450+
Showscale |> DynObj.setValueOpt heatmap "showscale"
451+
zSmooth |> DynObj.setValueOptBy heatmap "zsmooth" StyleParam.SmoothAlg.convert
452+
Colorbar |> DynObj.setValueOpt heatmap "colorbar"
453+
454+
// out ->
455+
heatmap
456+
)
457+
458+
// TODO include additional attributes: https://plot.ly/javascript/reference/#contour
459+
/// Applies the styles of contour to TraceObjects
460+
static member Contour
461+
(
462+
?Z : seq<#seq<#IConvertible>>,
463+
?X : seq<#IConvertible>,
464+
?Y : seq<#IConvertible>,
465+
?X0 ,
466+
?dX ,
467+
?Y0 ,
468+
?dY ,
469+
?xType ,
470+
?yType ,
471+
?xAxis ,
472+
?yAxis ,
473+
?Zsrc ,
474+
?Xsrc ,
475+
?Ysrc ,
476+
477+
?Xgap ,
478+
?Ygap ,
479+
?Transpose ,
480+
?zAuto ,
481+
?zMin ,
482+
?zMax ,
483+
?Colorscale ,
484+
?Autocolorscale ,
485+
?Reversescale ,
486+
?Showscale ,
487+
?zSmooth ,
488+
?Colorbar
489+
) =
490+
(fun (contour:('T :> Trace)) ->
491+
492+
Z |> DynObj.setValueOpt contour "z"
493+
X |> DynObj.setValueOpt contour "x"
494+
Y |> DynObj.setValueOpt contour "y"
495+
X0 |> DynObj.setValueOpt contour "x0"
496+
dX |> DynObj.setValueOpt contour "dx"
497+
Y0 |> DynObj.setValueOpt contour "y0"
498+
dY |> DynObj.setValueOpt contour "dy"
499+
xType |> DynObj.setValueOpt contour "xtype"
500+
yType |> DynObj.setValueOpt contour "ytype"
501+
xAxis |> DynObj.setValueOpt contour "xaxis"
502+
yAxis |> DynObj.setValueOpt contour "yaxis"
503+
Zsrc |> DynObj.setValueOpt contour "zsrc"
504+
Xsrc |> DynObj.setValueOpt contour "xsrc"
505+
Ysrc |> DynObj.setValueOpt contour "ysrc"
506+
507+
Xgap |> DynObj.setValueOpt contour "xgap"
508+
Ygap |> DynObj.setValueOpt contour "ygap"
509+
Transpose |> DynObj.setValueOpt contour "transpose"
510+
zAuto |> DynObj.setValueOpt contour "zauto"
511+
zMin |> DynObj.setValueOpt contour "zmin"
512+
zMax |> DynObj.setValueOpt contour "zmax"
513+
Colorscale |> DynObj.setValueOptBy contour "colorscale" StyleParam.ColorScale.convert
514+
Autocolorscale |> DynObj.setValueOpt contour "autocolorscale"
515+
Reversescale |> DynObj.setValueOpt contour "reversescale"
516+
Showscale |> DynObj.setValueOpt contour "showscale"
517+
zSmooth |> DynObj.setValueOptBy contour "zsmooth" StyleParam.SmoothAlg.convert
518+
Colorbar |> DynObj.setValueOpt contour "colorbar"
519+
520+
// out ->
521+
contour
522+
)
384523

385524

386525

0 commit comments

Comments
 (0)