Skip to content

Commit f0af183

Browse files
committed
more wip heatmap gl
1 parent d091f13 commit f0af183

File tree

4 files changed

+20
-46
lines changed

4 files changed

+20
-46
lines changed

lib/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ Core.register([
3030
require('./scattergeo'),
3131
require('./choropleth'),
3232
require('./scattergl'),
33-
require('./scatterternary')
33+
require('./scatterternary'),
34+
require('../src/traces/heatmapgl')
3435
]);
3536

3637
module.exports = Core;

src/plots/gl2d/scene2d.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -447,12 +447,9 @@ proto.draw = function() {
447447
(y / glplot.pixelRatio) - (size.t + (1-domainY[1]) * size.h)
448448
);
449449

450-
451450
if(result && fullLayout.hovermode) {
452451
var nextSelection = result.object._trace.handlePick(result);
453452

454-
console.log(result.dataCoord, result.pointId)
455-
456453
if(nextSelection && (
457454
!this.lastPickResult ||
458455
this.lastPickResult.trace !== nextSelection.trace ||
@@ -478,6 +475,7 @@ proto.draw = function() {
478475
var parts = hoverinfo.split('+');
479476
if(parts.indexOf('x') === -1) selection.traceCoord[0] = undefined;
480477
if(parts.indexOf('y') === -1) selection.traceCoord[1] = undefined;
478+
if(parts.indexOf('z') === -1) selection.traceCoord[2] = undefined;
481479
if(parts.indexOf('text') === -1) selection.textLabel = undefined;
482480
if(parts.indexOf('name') === -1) selection.name = undefined;
483481
}
@@ -487,6 +485,7 @@ proto.draw = function() {
487485
y: selection.screenCoord[1],
488486
xLabel: this.hoverFormatter('xaxis', selection.traceCoord[0]),
489487
yLabel: this.hoverFormatter('yaxis', selection.traceCoord[1]),
488+
zLabel: selection.traceCoord[2],
490489
text: selection.textLabel,
491490
name: selection.name,
492491
color: selection.color

src/traces/heatmap/calc.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ function makeBoundArray(trace, arrayIn, v0In, dvIn, numbricks, ax) {
175175
v0,
176176
dv,
177177
i;
178+
178179
if(Array.isArray(arrayIn) && !isHist && (ax.type!=='category')) {
179180
arrayIn = arrayIn.map(ax.d2c);
180181
var len = arrayIn.length;
@@ -184,7 +185,7 @@ function makeBoundArray(trace, arrayIn, v0In, dvIn, numbricks, ax) {
184185
// and extend it linearly based on the last two points
185186
if(len <= numbricks) {
186187
// contour plots only want the centers
187-
if(isContour) arrayOut = arrayIn.slice(0, numbricks);
188+
if(isContour || isGL2D) arrayOut = arrayIn.slice(0, numbricks);
188189
else if(numbricks === 1) arrayOut = [arrayIn[0]-0.5,arrayIn[0]+0.5];
189190
else {
190191
arrayOut = [1.5*arrayIn[0]-0.5*arrayIn[1]];
@@ -217,7 +218,9 @@ function makeBoundArray(trace, arrayIn, v0In, dvIn, numbricks, ax) {
217218
else if(isHist || ax.type==='category') v0 = v0In;
218219
else v0 = ax.d2c(v0In);
219220

220-
for(i = isContour ? 0 : -0.5; i < numbricks; i++) arrayOut.push(v0 + dv * i);
221+
for(i = (isContour || isGL2D) ? 0 : -0.5; i < numbricks; i++) {
222+
arrayOut.push(v0 + dv * i);
223+
}
221224
}
222225
return arrayOut;
223226
}

src/traces/heatmapgl/convert.js

Lines changed: 11 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,8 @@
1111

1212
var createHeatmap2D = require('gl-heatmap2d');
1313

14-
var maxRowLength = require('../heatmap/max_row_length');
1514
var str2RGBArray = require('../../lib/str2rgbarray');
1615

17-
var AXES = ['xaxis', 'yaxis'];
18-
1916

2017
function Heatmap(scene, uid) {
2118
this.scene = scene;
@@ -48,23 +45,18 @@ function Heatmap(scene, uid) {
4845
var proto = Heatmap.prototype;
4946

5047
proto.handlePick = function(pickResult) {
51-
var index = this.idToIndex[pickResult.pointId];
52-
53-
// console.log(pickResult.pointId)
48+
var index = pickResult.pointId,
49+
shape = this.options.shape;
5450

5551
return {
5652
trace: this,
5753
dataCoord: pickResult.dataCoord,
5854
traceCoord: [
59-
this.xData[index],
60-
this.yData[index]
55+
this.options.x[index % shape[0]],
56+
this.options.y[Math.floor(index / shape[0])],
57+
this.options.z[index]
6158
],
62-
textLabel: Array.isArray(this.textLabels) ?
63-
this.textLabels[index] :
64-
this.textLabels,
65-
color: Array.isArray(this.color) ?
66-
this.color[index] :
67-
this.color,
59+
textLabel: this.textLabels[index],
6860
name: this.name,
6961
hoverinfo: this.hoverinfo
7062
};
@@ -73,7 +65,6 @@ proto.handlePick = function(pickResult) {
7365
proto.update = function(fullTrace, calcTrace) {
7466
var calcPt = calcTrace[0];
7567

76-
this.textLabels = fullTrace.text;
7768
this.name = fullTrace.name;
7869
this.hoverinfo = fullTrace.hoverinfo;
7970

@@ -85,36 +76,16 @@ proto.update = function(fullTrace, calcTrace) {
8576
colLen = z.length;
8677
this.options.shape = [rowLen, colLen];
8778

88-
// don't use calc'ed bricks
89-
// maybe use xa.makeCalcdata() ???
90-
var x = fullTrace.x;
91-
if(x) {
92-
this.options.x = x;
93-
this.bounds[0] = x[0];
94-
this.bounds[2] = x[rowLen - 1];
95-
}
96-
else {
97-
this.options.x = null;
98-
this.bounds[0] = 0;
99-
this.bounds[2] = rowLen
100-
}
101-
102-
var y = fullTrace.y;
103-
if(y) {
104-
this.options.y = y;
105-
this.bounds[1] = y[0];
106-
this.bounds[3] = y[colLen - 1];
107-
}
108-
else {
109-
this.options.y = null;
110-
this.bounds[1] = 0;
111-
this.bounds[3] = colLen
112-
}
79+
this.options.x = calcPt.x;
80+
this.options.y = calcPt.y;
11381

11482
var colorOptions = convertColorscale(fullTrace);
11583
this.options.colorLevels = colorOptions.colorLevels;
11684
this.options.colorValues = colorOptions.colorValues;
11785

86+
// convert text from 2D -> 1D
87+
this.textLabels = [].concat.apply([], fullTrace.text);
88+
11889
this.heatmap.update(this.options);
11990
};
12091

0 commit comments

Comments
 (0)