Skip to content

Commit b64928d

Browse files
committed
regl-ify scattergl by dfcreative
1 parent 599dff9 commit b64928d

32 files changed

+1423
-1067
lines changed

package.json

+7
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@
5757
"3d-view": "^2.0.0",
5858
"@plotly/d3-sankey": "^0.5.0",
5959
"alpha-shape": "^1.0.0",
60+
"bubleify": "^1.0.0",
61+
"canvas-fit": "^1.5.0",
6062
"color-rgba": "^1.1.1",
6163
"convex-hull": "^1.0.3",
6264
"country-regex": "^1.1.0",
@@ -85,6 +87,7 @@
8587
"gl-spikes2d": "^1.0.1",
8688
"gl-surface3d": "^1.3.1",
8789
"has-hover": "^1.0.1",
90+
"kdgrass": "^1.0.1",
8891
"mapbox-gl": "^0.22.0",
8992
"matrix-camera-controller": "^2.1.3",
9093
"minify-stream": "^1.1.0",
@@ -97,11 +100,15 @@
97100
"ndarray-ops": "^1.2.2",
98101
"polybooljs": "^1.2.0",
99102
"regl": "^1.3.0",
103+
"regl-error2d": "^2.0.3",
104+
"regl-line2d": "^2.1.0",
105+
"regl-scatter2d": "^2.1.6",
100106
"right-now": "^1.0.0",
101107
"robust-orientation": "^1.1.3",
102108
"sane-topojson": "^2.0.0",
103109
"strongly-connected-components": "^1.0.1",
104110
"superscript-text": "^1.0.0",
111+
"svg-path-sdf": "^1.1.1",
105112
"tinycolor2": "^1.3.0",
106113
"topojson-client": "^2.1.0",
107114
"webgl-context": "^2.2.0",

src/components/drawing/index.js

+4
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ drawing.symbolNames = [];
213213
drawing.symbolFuncs = [];
214214
drawing.symbolNeedLines = {};
215215
drawing.symbolNoDot = {};
216+
drawing.symbolNoFill = {};
216217
drawing.symbolList = [];
217218

218219
Object.keys(SYMBOLDEFS).forEach(function(k) {
@@ -231,6 +232,9 @@ Object.keys(SYMBOLDEFS).forEach(function(k) {
231232
drawing.symbolList = drawing.symbolList.concat(
232233
[symDef.n + 200, k + '-dot', symDef.n + 300, k + '-open-dot']);
233234
}
235+
if(symDef.noFill) {
236+
drawing.symbolNoFill[symDef.n] = true;
237+
}
234238
});
235239
var MAXSYMBOL = drawing.symbolNames.length,
236240
// add a dot in the middle of the symbol

src/components/drawing/symbol_defs.js

+24-12
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,8 @@ module.exports = {
355355
return 'M0,' + rc + 'V-' + rc + 'M' + rc + ',0H-' + rc;
356356
},
357357
needLine: true,
358-
noDot: true
358+
noDot: true,
359+
noFill: true
359360
},
360361
'x-thin': {
361362
n: 34,
@@ -365,7 +366,8 @@ module.exports = {
365366
'M' + rx + ',-' + rx + 'L-' + rx + ',' + rx;
366367
},
367368
needLine: true,
368-
noDot: true
369+
noDot: true,
370+
noFill: true
369371
},
370372
asterisk: {
371373
n: 35,
@@ -377,7 +379,8 @@ module.exports = {
377379
'M' + rs + ',-' + rs + 'L-' + rs + ',' + rs;
378380
},
379381
needLine: true,
380-
noDot: true
382+
noDot: true,
383+
noFill: true
381384
},
382385
hash: {
383386
n: 36,
@@ -389,7 +392,8 @@ module.exports = {
389392
'M' + r2 + ',' + r1 + 'H-' + r2 +
390393
'm0,-' + r2 + 'H' + r2;
391394
},
392-
needLine: true
395+
needLine: true,
396+
noFill: true
393397
},
394398
'y-up': {
395399
n: 37,
@@ -400,7 +404,8 @@ module.exports = {
400404
return 'M-' + x + ',' + y1 + 'L0,0M' + x + ',' + y1 + 'L0,0M0,-' + y0 + 'L0,0';
401405
},
402406
needLine: true,
403-
noDot: true
407+
noDot: true,
408+
noFill: true
404409
},
405410
'y-down': {
406411
n: 38,
@@ -411,7 +416,8 @@ module.exports = {
411416
return 'M-' + x + ',-' + y1 + 'L0,0M' + x + ',-' + y1 + 'L0,0M0,' + y0 + 'L0,0';
412417
},
413418
needLine: true,
414-
noDot: true
419+
noDot: true,
420+
noFill: true
415421
},
416422
'y-left': {
417423
n: 39,
@@ -422,7 +428,8 @@ module.exports = {
422428
return 'M' + x1 + ',' + y + 'L0,0M' + x1 + ',-' + y + 'L0,0M-' + x0 + ',0L0,0';
423429
},
424430
needLine: true,
425-
noDot: true
431+
noDot: true,
432+
noFill: true
426433
},
427434
'y-right': {
428435
n: 40,
@@ -433,7 +440,8 @@ module.exports = {
433440
return 'M-' + x1 + ',' + y + 'L0,0M-' + x1 + ',-' + y + 'L0,0M' + x0 + ',0L0,0';
434441
},
435442
needLine: true,
436-
noDot: true
443+
noDot: true,
444+
noFill: true
437445
},
438446
'line-ew': {
439447
n: 41,
@@ -442,7 +450,8 @@ module.exports = {
442450
return 'M' + rc + ',0H-' + rc;
443451
},
444452
needLine: true,
445-
noDot: true
453+
noDot: true,
454+
noFill: true
446455
},
447456
'line-ns': {
448457
n: 42,
@@ -451,7 +460,8 @@ module.exports = {
451460
return 'M0,' + rc + 'V-' + rc;
452461
},
453462
needLine: true,
454-
noDot: true
463+
noDot: true,
464+
noFill: true
455465
},
456466
'line-ne': {
457467
n: 43,
@@ -460,7 +470,8 @@ module.exports = {
460470
return 'M' + rx + ',-' + rx + 'L-' + rx + ',' + rx;
461471
},
462472
needLine: true,
463-
noDot: true
473+
noDot: true,
474+
noFill: true
464475
},
465476
'line-nw': {
466477
n: 44,
@@ -469,6 +480,7 @@ module.exports = {
469480
return 'M' + rx + ',' + rx + 'L-' + rx + ',-' + rx;
470481
},
471482
needLine: true,
472-
noDot: true
483+
noDot: true,
484+
noFill: true
473485
}
474486
};

src/components/fx/hover.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ function createHoverText(hoverData, opts, gd) {
519519
var i, traceHoverinfo;
520520
for(i = 0; i < hoverData.length; i++) {
521521
traceHoverinfo = hoverData[i].hoverinfo || hoverData[i].trace.hoverinfo;
522-
var parts = traceHoverinfo.split('+');
522+
var parts = Array.isArray(traceHoverinfo) ? traceHoverinfo : traceHoverinfo.split('+');
523523
if(parts.indexOf('all') === -1 &&
524524
parts.indexOf(hovermode) === -1) {
525525
showCommonLabel = false;
@@ -1077,8 +1077,9 @@ function cleanPoint(d, hovermode) {
10771077
}
10781078

10791079
var infomode = d.hoverinfo || d.trace.hoverinfo;
1080+
10801081
if(infomode !== 'all') {
1081-
infomode = infomode.split('+');
1082+
infomode = Array.isArray(infomode) ? infomode : infomode.split('+');
10821083
if(infomode.indexOf('x') === -1) d.xLabel = undefined;
10831084
if(infomode.indexOf('y') === -1) d.yLabel = undefined;
10841085
if(infomode.indexOf('z') === -1) d.zLabel = undefined;

src/fonts/ploticon/config.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@
8787
"width": 1500
8888
},
8989
"search": [
90-
"tooltip_basic"
90+
"tooltip_basic"
9191
]
9292
},
9393
{

src/lib/gl_format_color.js

+1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ function formatColor(containerIn, opacityIn, len) {
5959

6060
if(isArrayColorIn) {
6161
getColor = function(c, i) {
62+
// FIXME: there is double work, considering that sclFunc does the opposite
6263
return c[i] === undefined ? colorDfltRgba : rgba(sclFunc(c[i]));
6364
};
6465
}

src/plot_api/plot_api.js

+3-7
Original file line numberDiff line numberDiff line change
@@ -220,16 +220,11 @@ Plotly.plot = function(gd, data, layout, config) {
220220
'left': 0,
221221
'width': '100%',
222222
'height': '100%',
223-
'overflow': 'visible'
223+
'overflow': 'visible',
224+
'pointer-events': 'none'
224225
})
225226
.attr('width', fullLayout.width)
226227
.attr('height', fullLayout.height);
227-
228-
fullLayout._glcanvas.filter(function(d) {
229-
return !d.pick;
230-
}).style({
231-
'pointer-events': 'none'
232-
});
233228
}
234229

235230
return Lib.syncOrAsync([
@@ -2804,6 +2799,7 @@ function makePlotFramework(gd) {
28042799
// FIXME: parcoords reuses this object, not the best pattern
28052800
fullLayout._glcontainer = fullLayout._paperdiv.selectAll('.gl-container')
28062801
.data([{}]);
2802+
28072803
fullLayout._glcontainer.enter().append('div')
28082804
.classed('gl-container', true);
28092805

src/plot_api/subroutines.js

-1
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,6 @@ exports.doModeBar = function(gd) {
498498
if(updateFx) updateFx(fullLayout);
499499
}
500500

501-
502501
return Plots.previousPromises(gd);
503502
};
504503

src/plots/cartesian/dragbox.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -759,7 +759,9 @@ module.exports = function dragBox(gd, plotinfo, x, y, w, h, ns, ew) {
759759
}
760760

761761
// don't scale at all if neither axis is scalable here
762-
if(!xScaleFactor2 && !yScaleFactor2) continue;
762+
if(!xScaleFactor2 && !yScaleFactor2) {
763+
continue;
764+
}
763765

764766
// but if only one is, reset the other axis scaling
765767
if(!xScaleFactor2) xScaleFactor2 = 1;

src/plots/cartesian/index.js

+34-7
Original file line numberDiff line numberDiff line change
@@ -137,21 +137,22 @@ function plotOne(gd, plotinfo, cdSubplot, transitionOpts, makeOnCompleteCallback
137137
}
138138
}
139139

140-
_module.plot(gd, plotinfo, cdModule, transitionOpts, makeOnCompleteCallback);
140+
if(_module.plot) _module.plot(gd, plotinfo, cdModule, transitionOpts, makeOnCompleteCallback);
141141
}
142142
}
143143

144144
exports.clean = function(newFullData, newFullLayout, oldFullData, oldFullLayout) {
145145
var oldModules = oldFullLayout._modules || [],
146146
newModules = newFullLayout._modules || [];
147147

148-
var hadScatter, hasScatter, i;
148+
var hadScatter, hasScatter, hadGl, hasGl, i, oldPlots, ids, subplotInfo;
149+
149150

150151
for(i = 0; i < oldModules.length; i++) {
151152
if(oldModules[i].name === 'scatter') {
152153
hadScatter = true;
153-
break;
154154
}
155+
break;
155156
}
156157

157158
for(i = 0; i < newModules.length; i++) {
@@ -161,12 +162,26 @@ exports.clean = function(newFullData, newFullLayout, oldFullData, oldFullLayout)
161162
}
162163
}
163164

165+
for(i = 0; i < oldModules.length; i++) {
166+
if(oldModules[i].name === 'scattergl') {
167+
hadGl = true;
168+
}
169+
break;
170+
}
171+
172+
for(i = 0; i < newModules.length; i++) {
173+
if(newModules[i].name === 'scattergl') {
174+
hasGl = true;
175+
break;
176+
}
177+
}
178+
164179
if(hadScatter && !hasScatter) {
165-
var oldPlots = oldFullLayout._plots,
166-
ids = Object.keys(oldPlots || {});
180+
oldPlots = oldFullLayout._plots;
181+
ids = Object.keys(oldPlots || {});
167182

168183
for(i = 0; i < ids.length; i++) {
169-
var subplotInfo = oldPlots[ids[i]];
184+
subplotInfo = oldPlots[ids[i]];
170185

171186
if(subplotInfo.plot) {
172187
subplotInfo.plot.select('g.scatterlayer')
@@ -181,6 +196,19 @@ exports.clean = function(newFullData, newFullLayout, oldFullData, oldFullLayout)
181196
.remove();
182197
}
183198

199+
if(hadGl && !hasGl) {
200+
oldPlots = oldFullLayout._plots;
201+
ids = Object.keys(oldPlots || {});
202+
203+
for(i = 0; i < ids.length; i++) {
204+
subplotInfo = oldPlots[ids[i]];
205+
206+
if(subplotInfo._scene) {
207+
subplotInfo._scene.destroy();
208+
}
209+
}
210+
}
211+
184212
var hadCartesian = (oldFullLayout._has && oldFullLayout._has('cartesian'));
185213
var hasCartesian = (newFullLayout._has && newFullLayout._has('cartesian'));
186214

@@ -222,7 +250,6 @@ exports.drawFramework = function(gd) {
222250
plotinfo.overlays = [];
223251

224252
makeSubplotLayer(plotinfo);
225-
226253
// fill in list of overlay subplots
227254
if(plotinfo.mainplot) {
228255
var mainplot = fullLayout._plots[plotinfo.mainplot];

0 commit comments

Comments
 (0)