Skip to content

Commit edcb1a4

Browse files
authored
Merge pull request #4953 from plotly/fix4924-discrete-heatmap2d
Discrete heatmapgl
2 parents 9a8089c + 6f3c415 commit edcb1a4

File tree

8 files changed

+164
-7
lines changed

8 files changed

+164
-7
lines changed

package-lock.json

+4-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@
7777
"gl-cone3d": "^1.5.2",
7878
"gl-contour2d": "^1.1.7",
7979
"gl-error3d": "^1.0.16",
80-
"gl-heatmap2d": "^1.0.6",
80+
"gl-heatmap2d": "^1.1.0",
8181
"gl-line3d": "1.2.1",
8282
"gl-mat4": "^1.2.0",
8383
"gl-mesh3d": "^2.3.1",

src/traces/heatmapgl/attributes.js

+9
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,15 @@ for(var i = 0; i < commonList.length; i++) {
2929
attrs[k] = heatmapAttrs[k];
3030
}
3131

32+
attrs.zsmooth = {
33+
valType: 'enumerated',
34+
values: ['fast', false],
35+
dflt: 'fast',
36+
role: 'style',
37+
editType: 'calc',
38+
description: 'Picks a smoothing algorithm use to smooth `z` data.'
39+
};
40+
3241
extendFlat(
3342
attrs,
3443
colorScaleAttrs('', {cLetter: 'z', autoColorDflt: false})

src/traces/heatmapgl/convert.js

+12-2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ function Heatmap(scene, uid) {
3131
this.bounds = [0, 0, 0, 0];
3232

3333
this.options = {
34+
zsmooth: 'fast',
3435
z: [],
3536
x: [],
3637
y: [],
@@ -85,6 +86,7 @@ proto.update = function(fullTrace, calcTrace) {
8586

8687
this.options.x = calcPt.x;
8788
this.options.y = calcPt.y;
89+
this.options.zsmooth = fullTrace.zsmooth;
8890

8991
var colorOptions = convertColorscale(fullTrace);
9092
this.options.colorLevels = colorOptions.colorLevels;
@@ -97,8 +99,16 @@ proto.update = function(fullTrace, calcTrace) {
9799

98100
var xa = this.scene.xaxis;
99101
var ya = this.scene.yaxis;
100-
fullTrace._extremes[xa._id] = Axes.findExtremes(xa, calcPt.x);
101-
fullTrace._extremes[ya._id] = Axes.findExtremes(ya, calcPt.y);
102+
103+
var xOpts, yOpts;
104+
if(fullTrace.zsmooth === false) {
105+
// increase padding for discretised heatmap as suggested by Louise Ord
106+
xOpts = { ppad: calcPt.x[1] - calcPt.x[0] };
107+
yOpts = { ppad: calcPt.y[1] - calcPt.y[0] };
108+
}
109+
110+
fullTrace._extremes[xa._id] = Axes.findExtremes(xa, calcPt.x, xOpts);
111+
fullTrace._extremes[ya._id] = Axes.findExtremes(ya, calcPt.y, yOpts);
102112
};
103113

104114
proto.dispose = function() {

src/traces/heatmapgl/defaults.js

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
2828
}
2929

3030
coerce('text');
31+
coerce('zsmooth');
3132

3233
colorscaleDefaults(traceIn, traceOut, layout, coerce, {prefix: '', cLetter: 'z'});
3334
};
17.7 KB
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
{
2+
"data": [
3+
{
4+
"type": "heatmapgl",
5+
"zsmooth": false,
6+
"z": [
7+
[
8+
125,
9+
106,
10+
89,
11+
74,
12+
61,
13+
50,
14+
41,
15+
34,
16+
29,
17+
26
18+
],
19+
[
20+
116,
21+
97,
22+
80,
23+
65,
24+
52,
25+
41,
26+
32,
27+
25,
28+
20,
29+
17
30+
],
31+
[
32+
109,
33+
90,
34+
73,
35+
58,
36+
45,
37+
34,
38+
25,
39+
18,
40+
13,
41+
10
42+
],
43+
[
44+
104,
45+
85,
46+
68,
47+
53,
48+
40,
49+
29,
50+
20,
51+
13,
52+
8,
53+
5
54+
],
55+
[
56+
101,
57+
82,
58+
65,
59+
50,
60+
37,
61+
26,
62+
17,
63+
10,
64+
5,
65+
2
66+
],
67+
[
68+
100,
69+
81,
70+
64,
71+
49,
72+
36,
73+
25,
74+
16,
75+
9,
76+
4,
77+
1
78+
],
79+
[
80+
101,
81+
82,
82+
65,
83+
50,
84+
37,
85+
26,
86+
17,
87+
10,
88+
5,
89+
2
90+
],
91+
[
92+
104,
93+
85,
94+
68,
95+
53,
96+
40,
97+
29,
98+
20,
99+
13,
100+
8,
101+
5
102+
],
103+
[
104+
109,
105+
90,
106+
73,
107+
58,
108+
45,
109+
34,
110+
25,
111+
18,
112+
13,
113+
10
114+
],
115+
[
116+
116,
117+
97,
118+
80,
119+
65,
120+
52,
121+
41,
122+
32,
123+
25,
124+
20,
125+
17
126+
]
127+
],
128+
"colorscale": "Viridis"
129+
}
130+
],
131+
"layout": {
132+
"height": 450,
133+
"width": 550
134+
}
135+
}

test/jasmine/tests/mock_test.js

+2
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,7 @@ var list = [
376376
'gl2d_fill-ordering',
377377
'gl2d_fonts',
378378
'gl2d_heatmapgl',
379+
'gl2d_heatmapgl_discrete',
379380
'gl2d_horiz-lines',
380381
'gl2d_layout_image',
381382
'gl2d_line_aligned',
@@ -1420,6 +1421,7 @@ figs['gl2d_error_bars_log'] = require('@mocks/gl2d_error_bars_log');
14201421
figs['gl2d_fill-ordering'] = require('@mocks/gl2d_fill-ordering');
14211422
// figs['gl2d_fonts'] = require('@mocks/gl2d_fonts');
14221423
figs['gl2d_heatmapgl'] = require('@mocks/gl2d_heatmapgl');
1424+
figs['gl2d_heatmapgl_discrete'] = require('@mocks/gl2d_heatmapgl_discrete');
14231425
figs['gl2d_horiz-lines'] = require('@mocks/gl2d_horiz-lines');
14241426
// figs['gl2d_layout_image'] = require('@mocks/gl2d_layout_image');
14251427
figs['gl2d_line_aligned'] = require('@mocks/gl2d_line_aligned');

0 commit comments

Comments
 (0)