Skip to content

Commit 95ebc76

Browse files
authored
Merge pull request #81 from Joott/HeatmapWebGL
Add HeatMapGL
2 parents 3c03a1d + b39f470 commit 95ebc76

File tree

3 files changed

+43
-5
lines changed

3 files changed

+43
-5
lines changed

src/Plotly.NET/Chart.fs

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1082,6 +1082,13 @@ type Chart =
10821082
?Scalegroup=Scalegroup,?Scalemode=Scalemode,?Side=Side,?Span=Span,?SpanMode=SpanMode,?Uirevision=Uirevision
10831083
)
10841084

1085+
static member private renderHeatmapTrace (useWebGL:bool) (style: Trace -> Trace) =
1086+
if useWebGL then
1087+
Trace.initHeatmapGL style
1088+
|> GenericChart.ofTraceObject
1089+
else
1090+
Trace.initHeatmap style
1091+
|> GenericChart.ofTraceObject
10851092

10861093
/// Shows a graphical representation of a 3-dimensional surface by plotting constant z slices, called contours, on a 2-dimensional format.
10871094
/// That is, given a value for z, lines are drawn for connecting the (x,y) coordinates where that z value occurs.
@@ -1096,11 +1103,17 @@ type Chart =
10961103
[<Optional;DefaultParameterValue(null)>] ?Xgap,
10971104
[<Optional;DefaultParameterValue(null)>] ?Ygap,
10981105
[<Optional;DefaultParameterValue(null)>] ?zSmooth,
1099-
[<Optional;DefaultParameterValue(null)>] ?Colorbar) =
1100-
Trace.initHeatmap (TraceStyle.Heatmap(Z=data,?X=ColNames, ?Y=RowNames,
1101-
?Xgap=Xgap,?Ygap=Ygap,?Colorscale=Colorscale,?Showscale=Showscale,?zSmooth=zSmooth,?Colorbar=Colorbar) )
1102-
|> TraceStyle.TraceInfo(?Name=Name,?Showlegend=Showlegend,?Opacity=Opacity)
1103-
|> GenericChart.ofTraceObject
1106+
[<Optional;DefaultParameterValue(null)>] ?Colorbar,
1107+
[<Optional;DefaultParameterValue(false)>]?UseWebGL : bool)
1108+
=
1109+
let style =
1110+
TraceStyle.Heatmap(Z=data,?X=ColNames, ?Y=RowNames,
1111+
?Xgap=Xgap,?Ygap=Ygap,?Colorscale=Colorscale,?Showscale=Showscale,?zSmooth=zSmooth,?Colorbar=Colorbar)
1112+
>> TraceStyle.TraceInfo(?Name=Name,?Showlegend=Showlegend,?Opacity=Opacity)
1113+
1114+
let useWebGL = defaultArg UseWebGL false
1115+
1116+
Chart.renderHeatmapTrace useWebGL style
11041117

11051118

11061119
/// Shows a graphical representation of data where the individual values contained in a matrix are represented as colors.

src/Plotly.NET/Playground.fsx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -532,6 +532,27 @@ generateDomainRanges 8 1
532532
)
533533
|> Chart.Show
534534

535+
// Heatmap example from Plotly docs: https://plotly.net/2_7_heatmaps.html
536+
let matrix =
537+
[[1.;1.5;0.7;2.7];
538+
[2.;0.5;1.2;1.4];
539+
[0.1;2.6;2.4;3.0];]
540+
541+
let rownames = ["p3";"p2";"p1"]
542+
let colnames = ["Tp0";"Tp30";"Tp60";"Tp160"]
543+
let colorscaleValue = StyleParam.Colorscale.Custom [(0.0,"#3D9970");(1.0,"#001f3f")]
544+
545+
let heat1 =
546+
Chart.Heatmap(
547+
matrix,colnames,rownames,
548+
Colorscale=colorscaleValue,
549+
Showscale=true,
550+
UseWebGL=true
551+
)
552+
|> Chart.withSize(700.,500.)
553+
|> Chart.withMarginSize(Left=200.)
554+
|> Chart.Show
555+
535556
let values,labels =
536557
[
537558
1,"v1"

src/Plotly.NET/Trace.fs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ module Trace =
4040
let initHeatmap (applyStyle:Trace->Trace) =
4141
Trace("heatmap") |> applyStyle
4242

43+
///initializes a trace of type "heatmapgl" applying the given trace styling function
44+
let initHeatmapGL (applyStyle:Trace->Trace) =
45+
Trace("heatmapgl") |> applyStyle
46+
4347
///initializes a trace of type "image" applying the given trace styling function
4448
let initImage (applyStyle:Trace->Trace) =
4549
Trace("image") |> applyStyle

0 commit comments

Comments
 (0)