Skip to content

Commit 658c529

Browse files
committed
split prepareRegl and clearGlCanvases into two modules
- so that plot_api.js can require clearGlCanvases w/o requiring all of regl. - this also makes the ie9_test.js pass again !
1 parent e7b02c0 commit 658c529

File tree

7 files changed

+41
-30
lines changed

7 files changed

+41
-30
lines changed

src/lib/clear_gl_canvases.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
* Copyright 2012-2018, Plotly, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
'use strict';
10+
11+
/**
12+
* Clear gl frame (if any). This is a common pattern as
13+
* we usually set `preserveDrawingBuffer: true` during
14+
* gl context creation (e.g. via `reglUtils.prepare`).
15+
*
16+
* @param {DOM node or object} gd : graph div object
17+
*/
18+
module.exports = function clearGlCanvases(gd) {
19+
var fullLayout = gd._fullLayout;
20+
21+
if(fullLayout._glcanvas && fullLayout._glcanvas.size()) {
22+
fullLayout._glcanvas.each(function(d) {
23+
if(d.regl) d.regl.clear({color: true});
24+
});
25+
}
26+
};

src/lib/regl_utils.js renamed to src/lib/prepare_regl.js

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88

99
'use strict';
1010

11+
// Note that this module should be ONLY required into
12+
// files corresponding to regl trace modules
13+
// so that bundles with non-regl only don't include
14+
// regl and all its bytes.
1115
var createRegl = require('regl');
1216

1317
/**
@@ -18,7 +22,7 @@ var createRegl = require('regl');
1822
* @param {DOM node or object} gd : graph div object
1923
* @param {array} extensions : list of extension to pass to createRegl
2024
*/
21-
exports.prepare = function prepare(gd, extensions) {
25+
module.exports = function prepareRegl(gd, extensions) {
2226
gd._fullLayout._glcanvas.each(function(d) {
2327
if(d.regl) return;
2428

@@ -33,20 +37,3 @@ exports.prepare = function prepare(gd, extensions) {
3337
});
3438
});
3539
};
36-
37-
/**
38-
* Clear gl frame (if any). This is a common pattern as
39-
* we usually set `preserveDrawingBuffer: true` during
40-
* gl context creation (e.g. via `reglUtils.prepare`).
41-
*
42-
* @param {DOM node or object} gd : graph div object
43-
*/
44-
exports.clear = function clear(gd) {
45-
var fullLayout = gd._fullLayout;
46-
47-
if(fullLayout._glcanvas && fullLayout._glcanvas.size()) {
48-
fullLayout._glcanvas.each(function(d) {
49-
if(d.regl) d.regl.clear({color: true});
50-
});
51-
}
52-
};

src/plot_api/plot_api.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ var Drawing = require('../components/drawing');
2929
var Color = require('../components/color');
3030
var xmlnsNamespaces = require('../constants/xmlns_namespaces');
3131
var svgTextUtils = require('../lib/svg_text_utils');
32-
var reglUtils = require('../lib/regl_utils');
32+
var clearGlCanvases = require('../lib/clear_gl_canvases');
3333

3434
var defaultConfig = require('./plot_config');
3535
var manageArrays = require('./manage_arrays');
@@ -386,9 +386,7 @@ exports.plot = function(gd, data, layout, config) {
386386
}
387387

388388
// TODO does this break or slow down parcoords??
389-
if(fullLayout._glcanvas) {
390-
reglUtils.clear(gd);
391-
}
389+
clearGlCanvases(gd);
392390

393391
// loop over the base plot modules present on graph
394392
var basePlotModules = fullLayout._basePlotModules;

src/plots/cartesian/dragbox.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ var supportsPassive = require('has-passive-events');
1616
var Registry = require('../../registry');
1717
var Lib = require('../../lib');
1818
var svgTextUtils = require('../../lib/svg_text_utils');
19-
var reglUtils = require('../../lib/regl_utils');
19+
var clearGlCanvases = require('../../lib/clear_gl_canvases');
2020
var Color = require('../../components/color');
2121
var Drawing = require('../../components/drawing');
2222
var Fx = require('../../components/fx');
@@ -714,7 +714,7 @@ function makeDragBox(gd, plotinfo, x, y, w, h, ns, ew) {
714714
return ax._length * (1 - scaleFactor) * FROM_TL[ax.constraintoward || 'middle'];
715715
}
716716

717-
reglUtils.clear(gd);
717+
clearGlCanvases(gd);
718718

719719
for(i = 0; i < subplots.length; i++) {
720720
var subplot = plotinfos[subplots[i]],

src/traces/parcoords/plot.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@
99
'use strict';
1010

1111
var parcoords = require('./parcoords');
12-
var reglUtils = require('../../lib/regl_utils');
12+
var prepareRegl = require('../../lib/prepare_regl');
1313

1414
module.exports = function plot(gd, cdparcoords) {
1515
var fullLayout = gd._fullLayout;
1616
var svg = fullLayout._toppaper;
1717
var root = fullLayout._paperdiv;
1818
var container = fullLayout._glcontainer;
1919

20-
reglUtils.prepare(gd);
20+
prepareRegl(gd);
2121

2222
var gdDimensions = {};
2323
var gdDimensionsOriginalOrder = {};

src/traces/scattergl/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ var arrayRange = require('array-range');
1616

1717
var Registry = require('../../registry');
1818
var Lib = require('../../lib');
19-
var reglUtils = require('../../lib/regl_utils');
19+
var prepareRegl = require('../../lib/prepare_regl');
2020
var AxisIDs = require('../../plots/cartesian/axis_ids');
2121

2222
var subTypes = require('../scatter/subtypes');
@@ -336,7 +336,7 @@ function plot(gd, subplot, cdata) {
336336
var width = fullLayout.width;
337337
var height = fullLayout.height;
338338

339-
reglUtils.prepare(gd, ['ANGLE_instanced_arrays', 'OES_element_index_uint']);
339+
prepareRegl(gd, ['ANGLE_instanced_arrays', 'OES_element_index_uint']);
340340
var regl = fullLayout._glcanvas.data()[0].regl;
341341

342342
// that is needed for fills

src/traces/splom/base_plot.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ var createLine = require('regl-line2d');
1212

1313
var Registry = require('../../registry');
1414
var Lib = require('../../lib');
15-
var reglUtils = require('../../lib/regl_utils');
15+
var prepareRegl = require('../../lib/prepare_regl');
1616
var getModuleCalcData = require('../../plots/get_data').getModuleCalcData;
1717
var Cartesian = require('../../plots/cartesian');
1818
var AxisIDs = require('../../plots/cartesian/axis_ids');
@@ -24,7 +24,7 @@ function plot(gd) {
2424
var _module = Registry.getModule(SPLOM);
2525
var splomCalcData = getModuleCalcData(gd.calcdata, _module);
2626

27-
reglUtils.prepare(gd, ['ANGLE_instanced_arrays', 'OES_element_index_uint']);
27+
prepareRegl(gd, ['ANGLE_instanced_arrays', 'OES_element_index_uint']);
2828

2929
if(fullLayout._hasOnlyLargeSploms) {
3030
drawGrid(gd);

0 commit comments

Comments
 (0)