Skip to content

Commit 1bf4e3e

Browse files
authored
Merge pull request #980 from dfcreative/scene2d-static
Pass static argument to scene2d
2 parents f2d625c + 1bc8d08 commit 1bf4e3e

File tree

9 files changed

+54
-23
lines changed

9 files changed

+54
-23
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
"gl-line3d": "^1.1.0",
6666
"gl-mat4": "^1.1.2",
6767
"gl-mesh3d": "^1.2.0",
68-
"gl-plot2d": "^1.1.6",
68+
"gl-plot2d": "^1.1.8",
6969
"gl-plot3d": "^1.5.1",
7070
"gl-pointcloud2d": "^1.0.0",
7171
"gl-scatter2d": "^1.0.5",

src/plots/gl2d/convert.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ function Axes2DOptions(scene) {
8989

9090
this.borderColor = [0, 0, 0, 0];
9191
this.backgroundColor = [0, 0, 0, 0];
92+
93+
this.static = this.scene.staticPlot;
9294
}
9395

9496
var proto = Axes2DOptions.prototype;

src/plots/gl2d/scene2d.js

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -129,19 +129,17 @@ proto.makeFramework = function() {
129129
}
130130

131131
// position the canvas
132-
var canvas = this.canvas,
133-
pixelRatio = this.pixelRatio,
134-
fullLayout = this.fullLayout;
132+
var canvas = this.canvas;
135133

136-
canvas.width = Math.ceil(pixelRatio * fullLayout.width) |0;
137-
canvas.height = Math.ceil(pixelRatio * fullLayout.height) |0;
138134
canvas.style.width = '100%';
139135
canvas.style.height = '100%';
140136
canvas.style.position = 'absolute';
141137
canvas.style.top = '0px';
142138
canvas.style.left = '0px';
143139
canvas.style['pointer-events'] = 'none';
144140

141+
this.updateSize(canvas);
142+
145143
// disabling user select on the canvas
146144
// sanitizes double-clicks interactions
147145
// ref: https://github.com/plotly/plotly.js/issues/744
@@ -174,6 +172,9 @@ proto.toImage = function(format) {
174172
this.stopped = true;
175173
if(this.staticPlot) this.container.appendChild(STATIC_CANVAS);
176174

175+
// update canvas size
176+
this.updateSize(this.canvas);
177+
177178
// force redraw
178179
this.glplot.setDirty();
179180
this.glplot.draw();
@@ -226,6 +227,26 @@ proto.toImage = function(format) {
226227
return dataURL;
227228
};
228229

230+
proto.updateSize = function(canvas) {
231+
if(!canvas) canvas = this.canvas;
232+
233+
var pixelRatio = this.pixelRatio,
234+
fullLayout = this.fullLayout;
235+
236+
var width = fullLayout.width,
237+
height = fullLayout.height,
238+
pixelWidth = Math.ceil(pixelRatio * width) |0,
239+
pixelHeight = Math.ceil(pixelRatio * height) |0;
240+
241+
// check for resize
242+
if(canvas.width !== pixelWidth || canvas.height !== pixelHeight) {
243+
canvas.width = pixelWidth;
244+
canvas.height = pixelHeight;
245+
}
246+
247+
return canvas;
248+
};
249+
229250
proto.computeTickMarks = function() {
230251
this.xaxis._length =
231252
this.glplot.viewBox[2] - this.glplot.viewBox[0];
@@ -344,24 +365,16 @@ proto.destroy = function() {
344365
};
345366

346367
proto.plot = function(fullData, calcData, fullLayout) {
347-
var glplot = this.glplot,
348-
pixelRatio = this.pixelRatio;
368+
var glplot = this.glplot;
349369

350370
this.fullLayout = fullLayout;
351371
this.updateAxes(fullLayout);
352372
this.updateTraces(fullData, calcData);
353373

354374
var width = fullLayout.width,
355-
height = fullLayout.height,
356-
pixelWidth = Math.ceil(pixelRatio * width) |0,
357-
pixelHeight = Math.ceil(pixelRatio * height) |0;
375+
height = fullLayout.height;
358376

359-
// check for resize
360-
var canvas = this.canvas;
361-
if(canvas.width !== pixelWidth || canvas.height !== pixelHeight) {
362-
canvas.width = pixelWidth;
363-
canvas.height = pixelHeight;
364-
}
377+
this.updateSize(this.canvas);
365378

366379
var options = this.glplotOptions;
367380
options.merge(fullLayout);

src/traces/pointcloud/attributes.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ module.exports = {
7575
},
7676
blend: {
7777
valType: 'boolean',
78-
dflt: false,
78+
dflt: null,
7979
role: 'style',
8080
description: [
8181
'Determines if colors are blended together for a translucency effect',

src/traces/pointcloud/convert.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,15 @@ proto.updateFast = function(options) {
175175

176176
markerColor[3] *= opacity;
177177
this.pointcloudOptions.color = markerColor;
178-
this.pointcloudOptions.blend = options.marker.blend;
178+
179+
// detect blending from the number of points, if undefined
180+
// because large data with blending hits performance
181+
var blend = options.marker.blend;
182+
if(blend === null) {
183+
var maxPoints = 100;
184+
blend = x.length < maxPoints || y.length < maxPoints;
185+
}
186+
this.pointcloudOptions.blend = blend;
179187

180188
borderColor[3] *= opacity;
181189
this.pointcloudOptions.borderColor = borderColor;

test/image/mocks/gl2d_multiple_subplots.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@
6060
}
6161
],
6262
"layout": {
63+
"width": 700,
64+
"height": 500,
6365
"xaxis": {
6466
"domain": [
6567
0,
@@ -113,4 +115,4 @@
113115
"anchor": "x4"
114116
}
115117
}
116-
}
118+
}

test/image/mocks/gl2d_simple_inset.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
}
3131
],
3232
"layout": {
33+
"width": 700,
34+
"height": 500,
3335
"yaxis2": {
3436
"domain": [
3537
0.6,
@@ -45,4 +47,4 @@
4547
"anchor": "y2"
4648
}
4749
}
48-
}
50+
}

test/image/mocks/gl2d_stacked_coupled_subplots.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@
4343
}
4444
],
4545
"layout": {
46+
"width": 700,
47+
"height": 500,
4648
"yaxis": {
4749
"domain": [
4850
0,
@@ -65,4 +67,4 @@
6567
]
6668
}
6769
}
68-
}
70+
}

test/image/mocks/gl2d_stacked_subplots.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@
4545
}
4646
],
4747
"layout": {
48+
"width": 700,
49+
"height": 500,
4850
"yaxis": {
4951
"domain": [
5052
0,
@@ -73,4 +75,4 @@
7375
]
7476
}
7577
}
76-
}
78+
}

0 commit comments

Comments
 (0)