Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
---
name: WebGL Heatmaps
plot_url: https://codepen.io/plotly/embed/rrvdXv/?height=500&theme-id=15263&default-tab=result
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bcdunbar can you check if this link is working for you? I got some console errors.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cldougl Same - I get console errors too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was working in windows and linux before I pushed, I'm still puzzled why it wasn't working for you guys. I updated the code under the same link. lmk if its working.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@priyatharsan nice 👌 that works for me now. I think it would be better to just have the plotly output without the image in codepen (you could just add style="display: none") to canvas.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @bcdunbar I removed the image now.

language: plotly_js
suite: heatmap-webgl
order: 1
sitemap: false
arrangement: horizontal
---
function HeatmapGLfromImage() {
var img = new Image();
img.setAttribute(
"src",
processdata(
"https://images.plot.ly/plotly-documentation/images/heatmap-galaxy.jpg")
);
}
function processdata(url) {
var canvas = document.getElementById("canvas");
var img = new Image();
img.crossOrigin = "anonymous";
img.src = url;
var context = canvas.getContext("2d");
context.drawImage(img, 0, 0);
var w = img.width; var h = img.height;
var l = w * h;
var arr = context.getImageData(0, 0, w, h).data;

var zdata = [];
for (var i = 0; i < l; i++) {
// get color of pixel
var r = arr[i * 4]; // Red
var g = arr[i * 4 + 1]; // Green
var b = arr[i * 4 + 2]; // Blue
var a = arr[i * 4 + 3]; // Alpha
zdata.push(r + g + b + a);
}
var createGroupedArray = function(arr, chunkSize) {
var groups = [],
i;
for (i = 0; i < arr.length; i += chunkSize) {
groups.push(arr.slice(i, i + chunkSize));
}
return groups;
};
// Grouping zdata into 500x500
var zdata = createGroupedArray(zdata, 500);

var data = [
{
z: zdata,
type: "heatmapgl",
colorscale: "Picnic"
}
];

Plotly.plot("myDiv", data);
}

HeatmapGLfromImage();
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
title: Javascript Heatmaps WebGL | Plotly
name: WebGL Heatmaps
permalink: javascript/heatmap-webgl/
description: How to make webGL based heatmaps in Javascript with Plotly.
layout: user-guide
has_thumbnail: true
thumbnail: thumbnail/heatmap-webgl.jpg
language: plotly_js
page_type: example_index
display_as: scientific
order: 3
redirect_from: javascript-graphing-library/heatmap-webgl/
---
{% assign examples = site.posts | where:"language","plotly_js" | where:"suite","heatmap-webgl" | sort: "order" %}
{% include auto_examples.html examples=examples %}