Skip to content

Add HeatMapGL #81

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 31, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions src/Plotly.NET/Chart.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1082,6 +1082,13 @@ type Chart =
?Scalegroup=Scalegroup,?Scalemode=Scalemode,?Side=Side,?Span=Span,?SpanMode=SpanMode,?Uirevision=Uirevision
)

static member private renderHeatmapTrace (useWebGL:bool) (style: Trace -> Trace) =
if useWebGL then
Trace.initHeatmapGL style
|> GenericChart.ofTraceObject
else
Trace.initHeatmap style
|> GenericChart.ofTraceObject

/// Shows a graphical representation of a 3-dimensional surface by plotting constant z slices, called contours, on a 2-dimensional format.
/// That is, given a value for z, lines are drawn for connecting the (x,y) coordinates where that z value occurs.
Expand All @@ -1096,11 +1103,17 @@ type Chart =
[<Optional;DefaultParameterValue(null)>] ?Xgap,
[<Optional;DefaultParameterValue(null)>] ?Ygap,
[<Optional;DefaultParameterValue(null)>] ?zSmooth,
[<Optional;DefaultParameterValue(null)>] ?Colorbar) =
Trace.initHeatmap (TraceStyle.Heatmap(Z=data,?X=ColNames, ?Y=RowNames,
?Xgap=Xgap,?Ygap=Ygap,?Colorscale=Colorscale,?Showscale=Showscale,?zSmooth=zSmooth,?Colorbar=Colorbar) )
|> TraceStyle.TraceInfo(?Name=Name,?Showlegend=Showlegend,?Opacity=Opacity)
|> GenericChart.ofTraceObject
[<Optional;DefaultParameterValue(null)>] ?Colorbar,
[<Optional;DefaultParameterValue(false)>]?UseWebGL : bool)
=
let style =
TraceStyle.Heatmap(Z=data,?X=ColNames, ?Y=RowNames,
?Xgap=Xgap,?Ygap=Ygap,?Colorscale=Colorscale,?Showscale=Showscale,?zSmooth=zSmooth,?Colorbar=Colorbar)
>> TraceStyle.TraceInfo(?Name=Name,?Showlegend=Showlegend,?Opacity=Opacity)

let useWebGL = defaultArg UseWebGL false

Chart.renderHeatmapTrace useWebGL style


/// Shows a graphical representation of data where the individual values contained in a matrix are represented as colors.
Expand Down
21 changes: 21 additions & 0 deletions src/Plotly.NET/Playground.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,27 @@ generateDomainRanges 8 1
)
|> Chart.Show

// Heatmap example from Plotly docs: https://plotly.net/2_7_heatmaps.html
let matrix =
[[1.;1.5;0.7;2.7];
[2.;0.5;1.2;1.4];
[0.1;2.6;2.4;3.0];]

let rownames = ["p3";"p2";"p1"]
let colnames = ["Tp0";"Tp30";"Tp60";"Tp160"]
let colorscaleValue = StyleParam.Colorscale.Custom [(0.0,"#3D9970");(1.0,"#001f3f")]

let heat1 =
Chart.Heatmap(
matrix,colnames,rownames,
Colorscale=colorscaleValue,
Showscale=true,
UseWebGL=true
)
|> Chart.withSize(700.,500.)
|> Chart.withMarginSize(Left=200.)
|> Chart.Show

let values,labels =
[
1,"v1"
Expand Down
4 changes: 4 additions & 0 deletions src/Plotly.NET/Trace.fs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ module Trace =
let initHeatmap (applyStyle:Trace->Trace) =
Trace("heatmap") |> applyStyle

///initializes a trace of type "heatmapgl" applying the given trace styling function
let initHeatmapGL (applyStyle:Trace->Trace) =
Trace("heatmapgl") |> applyStyle

///initializes a trace of type "image" applying the given trace styling function
let initImage (applyStyle:Trace->Trace) =
Trace("image") |> applyStyle
Expand Down