Skip to content

Commit 64488c9

Browse files
committed
implement connect gaps for 2d webgl plots
1 parent 894bbad commit 64488c9

File tree

5 files changed

+43
-3
lines changed

5 files changed

+43
-3
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
"gl-error2d": "^1.0.0",
5656
"gl-error3d": "^1.0.0",
5757
"gl-heatmap2d": "^1.0.2",
58-
"gl-line2d": "^1.2.1",
58+
"gl-line2d": "^1.3.0",
5959
"gl-line3d": "^1.1.0",
6060
"gl-mat4": "^1.1.2",
6161
"gl-mesh3d": "^1.0.7",

src/traces/scattergl/attributes.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ module.exports = {
8686
reversescale: scatterMarkerLineAttrs.reversescale
8787
}
8888
},
89+
connectgaps: scatterAttrs.connectgaps,
8990
fill: extendFlat({}, scatterAttrs.fill, {
9091
values: ['none', 'tozeroy', 'tozerox']
9192
}),

src/traces/scattergl/convert.js

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ function LineWithMarkers(scene, uid) {
3939
this.color = 'rgb(0, 0, 0)';
4040
this.name = '';
4141
this.hoverinfo = 'all';
42+
this.connectgaps = true;
4243

4344
this.idToIndex = [];
4445
this.bounds = [0, 0, 0, 0];
@@ -103,7 +104,10 @@ function LineWithMarkers(scene, uid) {
103104
var proto = LineWithMarkers.prototype;
104105

105106
proto.handlePick = function(pickResult) {
106-
var index = this.idToIndex[pickResult.pointId];
107+
var index = pickResult.pointId
108+
if (pickResult.object !== this.line || this.connectgaps) {
109+
index = this.idToIndex[pickResult.pointId];
110+
}
107111

108112
return {
109113
trace: this,
@@ -248,6 +252,7 @@ proto.update = function(options) {
248252
this.name = options.name;
249253
this.hoverinfo = options.hoverinfo;
250254
this.bounds = [Infinity, Infinity, -Infinity, -Infinity];
255+
this.connectgaps = !!options.connectgaps
251256

252257
if(this.isFancy(options)) {
253258
this.updateFancy(options);
@@ -461,7 +466,19 @@ proto.updateFancy = function(options) {
461466

462467
proto.updateLines = function(options, positions) {
463468
if(this.hasLines) {
464-
this.lineOptions.positions = positions;
469+
var linePositions = positions
470+
if (!options.connectgaps) {
471+
var p = 0;
472+
var x = this.xData;
473+
var y = this.yData;
474+
linePositions = new Float32Array(2 * x.length)
475+
476+
for(var i=0; i<x.length; ++i) {
477+
linePositions[p++] = x[i]
478+
linePositions[p++] = y[i]
479+
}
480+
}
481+
this.lineOptions.positions = linePositions
465482

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

src/traces/scattergl/defaults.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
3737
coerce('mode', len < constants.PTS_LINESONLY ? 'lines+markers' : 'lines');
3838

3939
if(subTypes.hasLines(traceOut)) {
40+
coerce('connectgaps');
4041
handleLineDefaults(traceIn, traceOut, defaultColor, coerce);
4142
}
4243

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"data": [
3+
{
4+
"x": [1, 2, 3, 4, 5],
5+
"y": [1, 1, null, -1, -1],
6+
"connectgaps": false,
7+
"mode": "lines",
8+
"type": "scattergl"
9+
},
10+
{
11+
"x": [1, 2, 3, 4, 5],
12+
"y": [-2, -2, null, 2, 2],
13+
"connectgaps": true,
14+
"mode": "lines",
15+
"type": "scattergl"
16+
}
17+
],
18+
"layout": {
19+
"title": "Connect gaps test"
20+
}
21+
}

0 commit comments

Comments
 (0)