Skip to content

Implement connect gaps for 2d WebGL plots #449

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 4 commits into from
May 5, 2016
Merged
Show file tree
Hide file tree
Changes from 2 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
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"cibuild": "node tasks/cibundle.js",
"watch": "node tasks/watch_plotly.js",
"lint": "eslint . || true",
"lint-fix": "eslint . --fix",
Copy link
Contributor

Choose a reason for hiding this comment

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

nicely done!

"test-jasmine": "karma start test/jasmine/karma.conf.js",
"citest-jasmine": "karma start test/jasmine/karma.ciconf.js",
"test-image": "./tasks/test_image.sh",
Expand Down Expand Up @@ -55,7 +56,7 @@
"gl-error2d": "^1.0.0",
"gl-error3d": "^1.0.0",
"gl-heatmap2d": "^1.0.2",
"gl-line2d": "^1.2.1",
"gl-line2d": "^1.3.0",
"gl-line3d": "^1.1.0",
"gl-mat4": "^1.1.2",
"gl-mesh3d": "^1.0.7",
Expand Down Expand Up @@ -85,7 +86,7 @@
"browserify": "^13.0.0",
"browserify-transform-tools": "^1.5.1",
"ecstatic": "^1.4.0",
"eslint": "^2.1.0",
"eslint": "^2.8.0",
"falafel": "^1.2.0",
"fs-extra": "^0.27.0",
"fuse.js": "^2.2.0",
Expand Down
1 change: 1 addition & 0 deletions src/traces/scattergl/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ module.exports = {
reversescale: scatterMarkerLineAttrs.reversescale
}
},
connectgaps: scatterAttrs.connectgaps,
fill: extendFlat({}, scatterAttrs.fill, {
values: ['none', 'tozeroy', 'tozerox']
}),
Expand Down
24 changes: 21 additions & 3 deletions src/traces/scattergl/convert.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ function LineWithMarkers(scene, uid) {
this.color = 'rgb(0, 0, 0)';
this.name = '';
this.hoverinfo = 'all';
this.connectgaps = true;

this.idToIndex = [];
this.bounds = [0, 0, 0, 0];
Expand Down Expand Up @@ -103,7 +104,10 @@ function LineWithMarkers(scene, uid) {
var proto = LineWithMarkers.prototype;

proto.handlePick = function(pickResult) {
var index = this.idToIndex[pickResult.pointId];
var index = pickResult.pointId;
if(pickResult.object !== this.line || this.connectgaps) {
index = this.idToIndex[pickResult.pointId];
}

return {
trace: this,
Expand Down Expand Up @@ -248,6 +252,7 @@ proto.update = function(options) {
this.name = options.name;
this.hoverinfo = options.hoverinfo;
this.bounds = [Infinity, Infinity, -Infinity, -Infinity];
this.connectgaps = !!options.connectgaps;

if(this.isFancy(options)) {
this.updateFancy(options);
Expand Down Expand Up @@ -460,16 +465,29 @@ proto.updateFancy = function(options) {
};

proto.updateLines = function(options, positions) {
var i;
if(this.hasLines) {
this.lineOptions.positions = positions;
var linePositions = positions;
if(!options.connectgaps) {
var p = 0;
var x = this.xData;
var y = this.yData;
linePositions = new Float32Array(2 * x.length);

for(i=0; i<x.length; ++i) {
linePositions[p++] = x[i];
Copy link
Contributor

Choose a reason for hiding this comment

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

you might have to ♻️ this block.

linePositions[p++] = y[i];
}
}
this.lineOptions.positions = linePositions;

var lineColor = str2RGBArray(options.line.color);
if(this.hasMarkers) lineColor[3] *= options.marker.opacity;

var lineWidth = Math.round(0.5 * this.lineOptions.width),
dashes = (DASHES[options.line.dash] || [1]).slice();

for(var i = 0; i < dashes.length; ++i) dashes[i] *= lineWidth;
for(i = 0; i < dashes.length; ++i) dashes[i] *= lineWidth;

switch(options.fill) {
case 'tozeroy':
Expand Down
1 change: 1 addition & 0 deletions src/traces/scattergl/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
coerce('mode', len < constants.PTS_LINESONLY ? 'lines+markers' : 'lines');

if(subTypes.hasLines(traceOut)) {
coerce('connectgaps');
handleLineDefaults(traceIn, traceOut, defaultColor, coerce);
}

Expand Down
21 changes: 21 additions & 0 deletions test/image/mocks/gl2d_connect_gaps.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"data": [
{
"x": [1, 2, 3, 4, 5],
"y": [1, 1, null, -1, -1],
"connectgaps": false,
"mode": "lines",
"type": "scattergl"
},
{
"x": [1, 2, 3, 4, 5],
"y": [-2, -2, null, 2, 2],
"connectgaps": true,
"mode": "lines",
"type": "scattergl"
}
],
"layout": {
"title": "Connect gaps test"
}
}