Skip to content

Pass static argument to scene2d #980

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 12 commits into from
Oct 13, 2016
Merged
Show file tree
Hide file tree
Changes from 8 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
2 changes: 2 additions & 0 deletions src/plots/gl2d/convert.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ function Axes2DOptions(scene) {

this.borderColor = [0, 0, 0, 0];
this.backgroundColor = [0, 0, 0, 0];

this.static = this.scene.staticPlot;
}

var proto = Axes2DOptions.prototype;
Expand Down
45 changes: 29 additions & 16 deletions src/plots/gl2d/scene2d.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,19 +124,17 @@ proto.makeFramework = function() {
}

// position the canvas
var canvas = this.canvas,
pixelRatio = this.pixelRatio,
fullLayout = this.fullLayout;
var canvas = this.canvas;

canvas.width = Math.ceil(pixelRatio * fullLayout.width) |0;
canvas.height = Math.ceil(pixelRatio * fullLayout.height) |0;
canvas.style.width = '100%';
canvas.style.height = '100%';
canvas.style.position = 'absolute';
canvas.style.top = '0px';
canvas.style.left = '0px';
canvas.style['pointer-events'] = 'none';

this.updateSize(canvas);

// disabling user select on the canvas
// sanitizes double-clicks interactions
// ref: https://github.com/plotly/plotly.js/issues/744
Expand Down Expand Up @@ -169,6 +167,9 @@ proto.toImage = function(format) {
this.stopped = true;
if(this.staticPlot) this.container.appendChild(STATIC_CANVAS);

// update canvas size
this.updateSize(this.canvas);

// force redraw
this.glplot.setDirty();
this.glplot.draw();
Expand Down Expand Up @@ -221,6 +222,26 @@ proto.toImage = function(format) {
return dataURL;
};

proto.updateSize = function(canvas) {
if(!canvas) canvas = this.canvas;

var pixelRatio = this.pixelRatio,
fullLayout = this.fullLayout;

var width = fullLayout.width,
height = fullLayout.height,
pixelWidth = Math.ceil(pixelRatio * width) |0,
pixelHeight = Math.ceil(pixelRatio * height) |0;

// check for resize
if(canvas.width !== pixelWidth || canvas.height !== pixelHeight) {
canvas.width = pixelWidth;
canvas.height = pixelHeight;
}

return canvas;
};

proto.computeTickMarks = function() {
this.xaxis._length =
this.glplot.viewBox[2] - this.glplot.viewBox[0];
Expand Down Expand Up @@ -337,24 +358,16 @@ proto.destroy = function() {
};

proto.plot = function(fullData, calcData, fullLayout) {
var glplot = this.glplot,
pixelRatio = this.pixelRatio;
var glplot = this.glplot;

this.fullLayout = fullLayout;
this.updateAxes(fullLayout);
this.updateTraces(fullData, calcData);

var width = fullLayout.width,
height = fullLayout.height,
pixelWidth = Math.ceil(pixelRatio * width) |0,
pixelHeight = Math.ceil(pixelRatio * height) |0;
height = fullLayout.height;

// check for resize
var canvas = this.canvas;
if(canvas.width !== pixelWidth || canvas.height !== pixelHeight) {
canvas.width = pixelWidth;
canvas.height = pixelHeight;
}
this.updateSize(this.canvas);

var options = this.glplotOptions;
options.merge(fullLayout);
Expand Down
2 changes: 1 addition & 1 deletion src/traces/pointcloud/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ module.exports = {
},
blend: {
valType: 'boolean',
dflt: false,
dflt: undefined,
Copy link
Contributor

Choose a reason for hiding this comment

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

we usually use null in situation like this one

role: 'style',
description: [
'Determines if colors are blended together for a translucency effect',
Expand Down
7 changes: 6 additions & 1 deletion src/traces/pointcloud/convert.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,12 @@ proto.updateFast = function(options) {

markerColor[3] *= opacity;
this.pointcloudOptions.color = markerColor;
this.pointcloudOptions.blend = options.marker.blend;

var blend = options.marker.blend;
if (blend == null) {
Copy link
Contributor

Choose a reason for hiding this comment

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

... and (blend === null)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

blend = x.length < 100 || y.length < 100;
}
this.pointcloudOptions.blend = blend;

borderColor[3] *= opacity;
this.pointcloudOptions.borderColor = borderColor;
Expand Down
4 changes: 3 additions & 1 deletion test/image/mocks/gl2d_multiple_subplots.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@
}
],
"layout": {
"width": 700,
"height": 500,
"xaxis": {
"domain": [
0,
Expand Down Expand Up @@ -113,4 +115,4 @@
"anchor": "x4"
}
}
}
}
4 changes: 3 additions & 1 deletion test/image/mocks/gl2d_simple_inset.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
}
],
"layout": {
"width": 700,
"height": 500,
"yaxis2": {
"domain": [
0.6,
Expand All @@ -45,4 +47,4 @@
"anchor": "y2"
}
}
}
}
4 changes: 3 additions & 1 deletion test/image/mocks/gl2d_stacked_coupled_subplots.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
}
],
"layout": {
"width": 700,
"height": 500,
"yaxis": {
"domain": [
0,
Expand All @@ -65,4 +67,4 @@
]
}
}
}
}
4 changes: 3 additions & 1 deletion test/image/mocks/gl2d_stacked_subplots.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@
}
],
"layout": {
"width": 700,
"height": 500,
"yaxis": {
"domain": [
0,
Expand Down Expand Up @@ -73,4 +75,4 @@
]
}
}
}
}