Skip to content

Commit af9d440

Browse files
authored
Merge pull request #5400 from plotly/make-d3-v3-internal
Make d3 internal and stop exporting d3-v3 to the API
2 parents 4865393 + 1496d3a commit af9d440

File tree

101 files changed

+949
-894
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

101 files changed

+949
-894
lines changed

devtools/image_viewer/viewer.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
var fs = require('fs');
22
var path = require('path');
33

4-
var d3 = require('@plotly/d3');
4+
var d3Json = require('../../test/strict_d3').json;
55

66
var $plotlist = document.getElementById('plot-list');
77
var $toggles = document.getElementById('plot-toggles');
@@ -55,7 +55,7 @@ function createButton(imageName) {
5555
button.style.cursor = 'pointer';
5656

5757
button.addEventListener('click', function() {
58-
d3.json(dirMocks + imageName + '.json', function(err, mock) {
58+
d3Json(dirMocks + imageName + '.json', function(err, mock) {
5959
$toggles.style.display = 'block';
6060

6161
$images.style.display = 'block';

devtools/test_dashboard/devtools.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ var Fuse = require('fuse.js/dist/fuse.common.js');
66
var mocks = require('../../build/test_dashboard_mocks.json');
77
var credentials = require('../../build/credentials.json');
88
var Lib = require('@src/lib');
9-
var d3 = Plotly.d3;
9+
var d3 = require('../../test/strict_d3');
10+
var d3Json = d3.json;
1011

1112
require('./perf');
1213

@@ -59,7 +60,7 @@ var Tabs = {
5960
plotMock: function(mockName, id) {
6061
var mockURL = '/test/image/mocks/' + mockName + '.json';
6162

62-
d3.json(mockURL, function(err, fig) {
63+
d3Json(mockURL, function(err, fig) {
6364
Plotly.newPlot(Tabs.fresh(id), fig);
6465

6566
console.warn('Plotting:', mockURL);
@@ -69,7 +70,7 @@ var Tabs = {
6970
getMock: function(mockName, callback) {
7071
var mockURL = '/test/image/mocks/' + mockName + '.json';
7172

72-
d3.json(mockURL, function(err, fig) {
73+
d3Json(mockURL, function(err, fig) {
7374
if(typeof callback !== 'function') {
7475
window.mock = fig;
7576
} else {

src/core.js

-3
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,3 @@ exports.Fx = require('./components/fx');
7979
exports.Snapshot = require('./snapshot');
8080
exports.PlotSchema = require('./plot_api/plot_schema');
8181
exports.Queue = require('./lib/queue');
82-
83-
// export d3 used in the bundle
84-
exports.d3 = require('@plotly/d3');

tasks/util/constants.js

+3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ var pathToRoot = path.join(__dirname, '../../');
55
var pathToSrc = path.join(pathToRoot, 'src/');
66
var pathToLib = path.join(pathToRoot, 'lib/');
77
var pathToImageTest = path.join(pathToRoot, 'test/image');
8+
var pathToStrictD3Module = path.join(pathToRoot, 'test/strict-d3.js');
89
var pathToDist = path.join(pathToRoot, 'dist/');
910
var pathToBuild = path.join(pathToRoot, 'build/');
1011

@@ -77,6 +78,8 @@ module.exports = {
7778
pathToTestImagesDiff: path.join(pathToBuild, 'test_images_diff/'),
7879
pathToTestImagesDiffList: path.join(pathToBuild, 'list_of_incorrect_images.txt'),
7980

81+
pathToStrictD3Module: pathToStrictD3Module,
82+
8083
pathToJasmineTests: path.join(pathToRoot, 'test/jasmine/tests'),
8184
pathToJasmineBundleTests: path.join(pathToRoot, 'test/jasmine/bundle_tests'),
8285
pathToRequireJS: path.join(pathToRoot, 'node_modules', 'requirejs', 'require.js'),

tasks/util/strict_d3.js

+1-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
1-
var path = require('path');
21
var transformTools = require('browserify-transform-tools');
3-
var constants = require('./constants');
2+
var pathToStrictD3Module = require('./constants').pathToStrictD3Module;
43

5-
var pathToStrictD3Module = path.join(
6-
constants.pathToImageTest,
7-
'strict-d3.js'
8-
);
94
/**
105
* Transform `require('@plotly/d3')` expressions to `require(/path/to/strict-d3.js)`
116
*/

tasks/util/watchified_bundle.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ var prettySize = require('prettysize');
66

77
var constants = require('./constants');
88
var common = require('./common');
9-
var strictD3 = require('./strict_d3');
109

1110
/**
1211
* Make a plotly.js browserify bundle function watched by watchify.
@@ -22,7 +21,7 @@ module.exports = function makeWatchifiedBundle(onFirstBundleCallback) {
2221
var b = browserify(constants.pathToPlotlyIndex, {
2322
debug: true,
2423
standalone: 'Plotly',
25-
transform: [strictD3],
24+
transform: [],
2625
cache: {},
2726
packageCache: {},
2827
plugin: [watchify]

test/jasmine/assets/check_component.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
var d3 = require('@plotly/d3');
1+
var d3SelectAll = require('../../strict-d3').selectAll;
22

33
var createGraphDiv = require('../assets/create_graph_div');
44
var destroyGraphDiv = require('../assets/destroy_graph_div');
@@ -44,7 +44,7 @@ module.exports = function checkComponent(Plotly) {
4444
afterEach(destroyGraphDiv);
4545

4646
it('should graph scatter traces with calendar attributes', function() {
47-
var nodes = d3.selectAll('g.trace.scatter');
47+
var nodes = d3SelectAll('g.trace.scatter');
4848

4949
expect(nodes.size()).toEqual(1);
5050

@@ -55,7 +55,7 @@ module.exports = function checkComponent(Plotly) {
5555
});
5656

5757
it('should graph bar traces with calendar attributes', function() {
58-
var nodes = d3.selectAll('g.trace.bars');
58+
var nodes = d3SelectAll('g.trace.bars');
5959

6060
expect(nodes.size()).toEqual(1);
6161
expect(gd._fullData[1].xcalendar).toBe('gregorian');

test/jasmine/assets/check_texttemplate.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ var Plotly = require('@lib/index');
44
var Registry = require('@src/registry');
55

66
var Lib = require('@src/lib');
7+
var d3Select = require('../../strict-d3').select;
8+
var d3SelectAll = require('../../strict-d3').selectAll;
79
var failTest = require('../assets/fail_test');
810
var createGraphDiv = require('../assets/create_graph_div');
911
var destroyGraphDiv = require('../assets/destroy_graph_div');
@@ -127,10 +129,10 @@ module.exports = function checkTextTemplate(mock, selector, tests, skipExtra) {
127129
dataCopy[0].texttemplate = test[0];
128130
Plotly.newPlot(gd, dataCopy, Lib.extendDeep({}, layout))
129131
.then(function() {
130-
var pts = Plotly.d3.selectAll(selector);
132+
var pts = d3SelectAll(selector);
131133
expect(pts.size()).toBe(test[1].length);
132134
pts.each(function() {
133-
expect(test[1]).toContain(Plotly.d3.select(this).text());
135+
expect(test[1]).toContain(d3Select(this).text());
134136
});
135137
})
136138
.catch(failTest)

test/jasmine/assets/check_transitions.js

+7-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
var Plotly = require('@lib/index');
44
var Lib = require('@src/lib');
5-
var d3 = require('@plotly/d3');
5+
var d3Timer = require('../../strict-d3').timer;
6+
var d3Select = require('../../strict-d3').select;
7+
var d3SelectAll = require('../../strict-d3').selectAll;
68
var delay = require('./delay.js');
79

810
var reNumbers = /([\d\.]+)/gm;
@@ -19,7 +21,7 @@ function clockTick(currentNow, milliseconds) {
1921
Date.now = function() {
2022
return currentNow + milliseconds;
2123
};
22-
d3.timer.flush();
24+
d3Timer.flush();
2325
}
2426

2527
// Using the methodology from http://eng.wealthfront.com/2017/10/26/testing-d3-transitions/
@@ -87,11 +89,11 @@ module.exports = function checkTransition(gd, mock, animateOpts, transitionOpts,
8789
function assert(test) {
8890
var msg = 'at ' + test[0] + 'ms, selection ' + test[1] + ' has ' + test[3];
8991
var cur = [];
90-
d3.selectAll(test[1]).each(function(d, i) {
92+
d3SelectAll(test[1]).each(function(d, i) {
9193
if(test[2] === 'style') cur[i] = this.style[test[3]];
92-
else if(test[2] === 'attr') cur[i] = d3.select(this).attr(test[3]);
94+
else if(test[2] === 'attr') cur[i] = d3Select(this).attr(test[3]);
9395
else if(test[2] === 'datum') {
94-
cur[i] = d3.select(this).datum()[test[3]];
96+
cur[i] = d3Select(this).datum()[test[3]];
9597
}
9698
});
9799
switch(test[3]) {

test/jasmine/assets/custom_assertions.js

+18-17
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
'use strict';
22

3-
var d3 = require('@plotly/d3');
3+
var d3Select = require('../../strict-d3').select;
4+
var d3SelectAll = require('../../strict-d3').selectAll;
45
var negateIf = require('./negate_if');
56

67
exports.assertDims = function(dims) {
7-
var traces = d3.selectAll('.trace');
8+
var traces = d3SelectAll('.trace');
89

910
expect(traces.size())
1011
.toEqual(dims.length, 'to have correct number of traces');
1112

1213
traces.each(function(_, i) {
13-
var trace = d3.select(this);
14+
var trace = d3Select(this);
1415
var points = trace.selectAll('.point');
1516

1617
expect(points.size())
@@ -23,15 +24,15 @@ exports.assertStyle = function(dims, color, opacity) {
2324
return a + b;
2425
});
2526

26-
var traces = d3.selectAll('.trace');
27+
var traces = d3SelectAll('.trace');
2728
expect(traces.size())
2829
.toEqual(dims.length, 'to have correct number of traces');
2930

30-
expect(d3.selectAll('.point').size())
31+
expect(d3SelectAll('.point').size())
3132
.toEqual(N, 'to have correct total number of points');
3233

3334
traces.each(function(_, i) {
34-
var trace = d3.select(this);
35+
var trace = d3Select(this);
3536
var points = trace.selectAll('.point');
3637

3738
expect(points.size())
@@ -72,7 +73,7 @@ function getLabelContent(label) {
7273
}
7374

7475
if(lines.size()) {
75-
lines.each(function() { fill(d3.select(this)); });
76+
lines.each(function() { fill(d3Select(this)); });
7677
} else {
7778
fill(label);
7879
}
@@ -88,7 +89,7 @@ function assertLabelContent(label, expectation, msg) {
8889
}
8990

9091
function count(selector) {
91-
return d3.selectAll(selector).size();
92+
return d3SelectAll(selector).size();
9293
}
9394

9495
/**
@@ -115,7 +116,7 @@ exports.assertHoverLabelContent = function(expectation, msg) {
115116
var reRotate = /(\brotate\(.*?\);?)/;
116117

117118
if(ptCnt === 1) {
118-
var g = d3.select(ptSelector);
119+
var g = d3Select(ptSelector);
119120
var numsSel = g.select('text.nums');
120121
var nameSel = g.select('text.name');
121122

@@ -142,8 +143,8 @@ exports.assertHoverLabelContent = function(expectation, msg) {
142143
order: (expectation.hOrder || expectation.vOrder || []).indexOf(i)
143144
};
144145
});
145-
d3.selectAll(ptSelector).each(function(_, i) {
146-
var g = d3.select(this);
146+
d3SelectAll(ptSelector).each(function(_, i) {
147+
var g = d3Select(this);
147148
var numsSel = g.select('text.nums');
148149
var nameSel = g.select('text.name');
149150

@@ -201,7 +202,7 @@ exports.assertHoverLabelContent = function(expectation, msg) {
201202

202203
if(axCnt) {
203204
assertLabelContent(
204-
d3.select(axSelector + '> text'),
205+
d3Select(axSelector + '> text'),
205206
expectation.axis,
206207
axMsg
207208
);
@@ -222,7 +223,7 @@ exports.assertClip = function(sel, isClipped, size, msg) {
222223
expect(sel.size()).toBe(size, msg + ' clip path (selection size)');
223224

224225
sel.each(function(d, i) {
225-
var clipPath = d3.select(this).attr('clip-path');
226+
var clipPath = d3Select(this).attr('clip-path');
226227

227228
if(isClipped) {
228229
expect(String(clipPath).substr(0, 5))
@@ -239,16 +240,16 @@ exports.assertNodeDisplay = function(sel, expectation, msg) {
239240
.toBe(expectation.length, msg + ' display (selection size)');
240241

241242
sel.each(function(d, i) {
242-
expect(d3.select(this).attr('display'))
243+
expect(d3Select(this).attr('display'))
243244
.toBe(expectation[i], msg + ' display ' + '(item ' + i + ')');
244245
});
245246
};
246247

247248
exports.checkTicks = function(axLetter, vals, msg) {
248-
var selection = d3.selectAll('.' + axLetter + 'tick text');
249+
var selection = d3SelectAll('.' + axLetter + 'tick text');
249250
expect(selection.size()).toBe(vals.length);
250251
selection.each(function(d, i) {
251-
expect(d3.select(this).text()).toBe(vals[i], msg + ': ' + i);
252+
expect(d3Select(this).text()).toBe(vals[i], msg + ': ' + i);
252253
});
253254
};
254255

@@ -294,7 +295,7 @@ exports.assertPlotSize = function(opts, msg) {
294295
var widthLessThan = opts.widthLessThan;
295296
var heightLessThan = opts.heightLessThan;
296297

297-
var plotBB = d3.select('.plotclip > rect').node().getBoundingClientRect();
298+
var plotBB = d3Select('.plotclip > rect').node().getBoundingClientRect();
298299
var actualWidth = plotBB.width;
299300
var actualHeight = plotBB.height;
300301

test/jasmine/assets/domain_ref/components.js renamed to test/jasmine/assets/domain_ref_components.js

+13-12
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,19 @@
1010
// promise is followed by .then(done, done.fail)
1111
'use strict';
1212

13-
var Plotly = require('../../../../lib/index');
14-
var d3 = require('@plotly/d3');
15-
var pixelCalc = require('../../assets/pixel_calc');
16-
var getSVGElemScreenBBox = require('../../assets/get_svg_elem_screen_bbox');
17-
// var SVGTools = require('../../assets/svg_tools');
18-
var Lib = require('../../../../src/lib');
19-
var Axes = require('../../../../src/plots/cartesian/axes');
20-
var axisIds = require('../../../../src/plots/cartesian/axis_ids');
13+
var Plotly = require('@lib/index');
14+
var d3Select = require('../../strict-d3').select;
15+
var d3SelectAll = require('../../strict-d3').selectAll;
16+
var pixelCalc = require('../assets/pixel_calc');
17+
var getSVGElemScreenBBox = require('../assets/get_svg_elem_screen_bbox');
18+
// var SVGTools = require('../assets/svg_tools');
19+
var Lib = require('@src/lib');
20+
var Axes = require('@src/plots/cartesian/axes');
21+
var axisIds = require('@src/plots/cartesian/axis_ids');
2122
var testImage = 'https://images.plot.ly/language-icons/api-home/js-logo.png';
2223
var iterable = require('extra-iterable');
2324

24-
var testMock = require('./domain_ref_base.json');
25+
var testMock = require('../assets/domain_ref_base.json');
2526

2627
// NOTE: this tolerance is in pixels
2728
var EQUALITY_TOLERANCE = 1e-2;
@@ -116,7 +117,7 @@ var xAnchors = ['left', 'center', 'right'];
116117
var yAnchors = ['top', 'middle', 'bottom'];
117118
// this color chosen so it can easily be found with d3
118119
// NOTE: for images color cannot be set but it will be the only image in the
119-
// plot so you can use d3.select('g image').node()
120+
// plot so you can use d3Select('g image').node()
120121
var aroColor = 'rgb(50, 100, 150)';
121122

122123
// acts on an Object representing a aro which could be a line or a rect
@@ -461,7 +462,7 @@ function findAROByColor(color, id, type, colorAttribute) {
461462
type = (type === undefined) ? 'path' : type;
462463
colorAttribute = (colorAttribute === undefined) ? 'stroke' : colorAttribute;
463464
var selector = id + type;
464-
var ret = d3.selectAll(selector).filter(function() {
465+
var ret = d3SelectAll(selector).filter(function() {
465466
return this.style[colorAttribute] === color;
466467
}).node();
467468
return ret;
@@ -470,7 +471,7 @@ function findAROByColor(color, id, type, colorAttribute) {
470471
function findImage(id) {
471472
id = (id === undefined) ? '' : id + ' ';
472473
var selector = id + 'g image';
473-
var ret = d3.select(selector).node();
474+
var ret = d3Select(selector).node();
474475
return ret;
475476
}
476477

test/jasmine/assets/get_bbox.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22

3-
var d3 = require('@plotly/d3');
3+
var d3Select = require('../../strict-d3').select;
44

55
var ATTRS = ['x', 'y', 'width', 'height'];
66

@@ -9,7 +9,7 @@ var ATTRS = ['x', 'y', 'width', 'height'];
99
module.exports = function getBBox(element) {
1010
var elementBBox = element.getBBox();
1111

12-
var s = d3.select(element);
12+
var s = d3Select(element);
1313
var clipPathAttr = s.attr('clip-path');
1414

1515
if(!clipPathAttr) return elementBBox;
@@ -22,15 +22,15 @@ module.exports = function getBBox(element) {
2222
};
2323

2424
function getClipBBox(clipPathId) {
25-
var clipPath = d3.select('#' + clipPathId);
25+
var clipPath = d3Select('#' + clipPathId);
2626
var clipBBox;
2727

2828
try {
2929
// this line throws an error in FF (38 and 45 at least)
3030
clipBBox = clipPath.node().getBBox();
3131
} catch(e) {
3232
// use DOM attributes as fallback
33-
var path = d3.select(clipPath.node().firstChild);
33+
var path = d3Select(clipPath.node().firstChild);
3434

3535
clipBBox = {};
3636

0 commit comments

Comments
 (0)