Skip to content

Commit 0ad202c

Browse files
committed
Fix - correctly use preloaded d3.js in notebooks/require.js environment
1 parent d5c831d commit 0ad202c

File tree

3 files changed

+25
-18
lines changed

3 files changed

+25
-18
lines changed

changes.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# JSROOT changelog
22

3+
## Changes in 5.3.5
4+
1. Fix - correctly use preloaded d3.js in notebooks/require.js environment
5+
6+
37
## Changes in 5.3.4
48
1. Fix - several problem in TLatex preprocessing for MathJax.js
59
2. Fix - use "E" draw options for THStack only when no any other specified

scripts/JSRootCore.js

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -967,6 +967,7 @@
967967

968968
var ext = jsroot.source_min ? ".min" : "",
969969
need_jquery = false,
970+
use_require = (typeof define === "function") && define.amd,
970971
use_bower = jsroot.bower_dir!==null,
971972
mainfiles = "",
972973
extrafiles = "", // scripts for direct loading
@@ -993,23 +994,9 @@
993994
}
994995

995996
if ((kind.indexOf('2d;')>=0) || (kind.indexOf("3d;")>=0) || (kind.indexOf("geom;")>=0) || (kind.indexOf("openui5;")>=0)) {
996-
if (jsroot._test_d3_ === undefined) {
997-
if ((typeof d3 == 'object') && d3.version && (d3.version[0]==="4")) {
998-
jsroot.console('Reuse existing d3.js ' + d3.version + ", expected 4.4.4", debugout);
999-
jsroot._test_d3_ = 4;
1000-
} else
1001-
if ((typeof d3 == 'object') && d3.version && (d3.version[0]==="3")) {
1002-
jsroot.console("d3 version is " + d3.version + ", try to adjust");
1003-
d3.timeFormat = d3.time.format;
1004-
d3.scaleTime = d3.time.scale;
1005-
d3.scaleLog = d3.scale.log;
1006-
d3.scaleLinear = d3.scale.linear;
1007-
1008-
jsroot._test_d3_ = 3;
1009-
} else {
1010-
mainfiles += use_bower ? '###d3/d3.min.js;' : '&&&scripts/d3.min.js;';
1011-
jsroot._test_d3_ = 4;
1012-
}
997+
if (!use_require && (typeof d3 != 'object') && (jsroot._test_d3_ === undefined)) {
998+
mainfiles += use_bower ? '###d3/d3.min.js;' : '&&&scripts/d3.min.js;';
999+
jsroot._test_d3_ = null;
10131000
}
10141001
if (jsroot.sources.indexOf("2d") < 0) {
10151002
modules.push('JSRootPainter');

scripts/JSRootPainter.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,24 @@
3232
if ( typeof define === "function" && define.amd )
3333
JSROOT.loadScript('$$$style/JSRootPainter.css');
3434

35+
if (!JSROOT._test_d3_) {
36+
if ((typeof d3 == 'object') && d3.version && (d3.version[0]==="4")) {
37+
if (d3.version !== '4.4.4')
38+
console.log('Reuse existing d3.js ' + d3.version + ", expected 4.4.4");
39+
JSROOT._test_d3_ = 4;
40+
} else if ((typeof d3 == 'object') && d3.version && (d3.version[0]==="3")) {
41+
console.log("Older d3.js version " + d3.version + " found, try to adjust");
42+
d3.timeFormat = d3.time.format;
43+
d3.scaleTime = d3.time.scale;
44+
d3.scaleLog = d3.scale.log;
45+
d3.scaleLinear = d3.scale.linear;
46+
JSROOT._test_d3_ = 3;
47+
} else {
48+
console.error('Fail to identify d3.js version ' + (d3 ? d3.version : "???"));
49+
}
50+
}
3551
// list of user painters, called with arguments func(vis, obj, opt)
36-
JSROOT.DrawFuncs = {lst:[], cache:{}};
52+
JSROOT.DrawFuncs = { lst:[], cache:{} };
3753

3854
// add draw function for the class
3955
// List of supported draw options could be provided, separated with ';'

0 commit comments

Comments
 (0)