Skip to content

Upgrade d3 in plotly.js from v3 to v4 #5833

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 55 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
87b6741
replace plotly/d3 v3 with d3 v4
archmoj Jul 17, 2021
37686ec
adjust to d3-drag and d3-zoom
archmoj Jul 17, 2021
ef34849
adjust calls to d3.scale and d3.svg
archmoj Jul 14, 2021
131c785
replace .attr({ and .style({ with .attrs({ and .styles({
archmoj Jul 14, 2021
4ca5e45
plot_api enter and exit adjustment
archmoj Jul 18, 2021
6654f6e
sub plots enter and exit adjustment
archmoj Jul 18, 2021
8fbc9b8
lib enter and exit adjustment
archmoj Jul 18, 2021
cc3c454
annotations enter and exit adjustment
archmoj Jul 18, 2021
a43c348
colorbar enter and exit adjustment
archmoj Jul 18, 2021
71d411d
drawing enter and exit adjustment
archmoj Jul 18, 2021
d20a791
errorbars enter and exit adjustment
archmoj Jul 18, 2021
f6e01df
hover enter and exit adjustment
archmoj Jul 18, 2021
d1755e8
layout images enter and exit adjustment
archmoj Jul 18, 2021
b06db2a
legend enter and exit adjustment
archmoj Jul 18, 2021
a0925b2
rangeselector enter and exit adjustment
archmoj Jul 18, 2021
df709e9
rangeslider enter and exit adjustment
archmoj Jul 18, 2021
9b48dca
shapes enter and exit adjustment
archmoj Jul 18, 2021
0f0711f
sliders enter and exit adjustment
archmoj Jul 18, 2021
86b9499
titles enter and exit adjustment
archmoj Jul 18, 2021
dd9b818
updatemenus enter and exit adjustment
archmoj Jul 18, 2021
0dde732
scatter enter and exit adjustment
archmoj Jul 18, 2021
ccc1b63
bar-like enter and exit adjustment
archmoj Jul 18, 2021
3292318
pie-like enter and exit adjustment
archmoj Jul 18, 2021
5e7093b
sunburst, treemap & icicle enter and exit adjustment
archmoj Jul 18, 2021
a6b93d4
heatmap & contour enter and exit adjustment
archmoj Jul 18, 2021
86a0f8d
carpet & contourcarpet enter and exit adjustment
archmoj Jul 18, 2021
3787fb8
box & violin enter and exit adjustment
archmoj Jul 18, 2021
562db25
parcats enter and exit adjustment
archmoj Jul 18, 2021
20aa8da
parcoords enter and exit adjustment
archmoj Jul 18, 2021
6ff6b04
table enter and exit adjustment
archmoj Jul 18, 2021
5a5c9b6
sankey enter and exit adjustment
archmoj Jul 18, 2021
24747dd
choropleth & scattergeo enter and exit adjustment
archmoj Jul 18, 2021
927fff9
ohlc enter and exit adjustment
archmoj Jul 18, 2021
ead3d14
barpolar enter and exit adjustment
archmoj Jul 18, 2021
b2f5877
image enter and exit adjustment
archmoj Jul 18, 2021
efdb078
indicator enter and exit adjustment
archmoj Jul 18, 2021
fd0dce4
move setting subplots bg color into .each
archmoj Jul 15, 2021
0c51567
more styles and attrs adjustments
archmoj Jul 16, 2021
1553518
adjust d3.ease calls
archmoj Jul 17, 2021
712a4b7
adjust outerTickSize to be tickSizeOuter
archmoj Jul 15, 2021
c10335f
get trace_from_cd instead of looking into cd[0]
archmoj Jul 15, 2021
a7b4d43
disable makeUpdate enter true to show lines
archmoj Jul 16, 2021
81a3a1f
Merge remote-tracking branch 'origin/master' into upgrade-d3-to-v4
archmoj Jul 24, 2021
4fcb937
print number and list of succeeded images
archmoj Jul 24, 2021
01dd5de
pass syntax test
archmoj Jul 24, 2021
18dae68
improve compare test to help maintain certain success rate after each…
archmoj Jul 24, 2021
5f51592
for now throw when success rate is reduced
archmoj Jul 24, 2021
da11d75
Merge remote-tracking branch 'origin/master' into upgrade-d3-to-v4
archmoj Jul 30, 2021
1ccfe8a
Merge remote-tracking branch 'origin/master' into upgrade-d3-to-v4
archmoj Aug 27, 2021
5c621d6
Merge remote-tracking branch 'origin/master' into upgrade-d3-to-v4
archmoj Aug 31, 2021
0ded003
Merge remote-tracking branch 'origin/master' into upgrade-d3-to-v4
archmoj Oct 5, 2021
5ff9d3b
update package-lock now using node16+npm7
archmoj Oct 5, 2021
9bcad16
Merge remote-tracking branch 'origin/master' into upgrade-d3-to-v4
archmoj Oct 19, 2021
fb29753
add some smith mocks to the white list
archmoj Oct 19, 2021
6c3b271
Merge remote-tracking branch 'origin/master' into upgrade-d3-to-v4
archmoj Oct 29, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
582 changes: 555 additions & 27 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@
]
},
"dependencies": {
"@plotly/d3": "3.8.0",
"@plotly/d3-sankey": "0.7.2",
"@plotly/d3-sankey-circular": "0.33.1",
"@turf/area": "^6.4.0",
Expand All @@ -81,6 +80,7 @@
"color-parse": "1.3.8",
"color-rgba": "2.1.1",
"country-regex": "^1.1.0",
"d3": "^4.13.0",
"d3-force": "^1.2.1",
"d3-format": "^1.4.5",
"d3-geo": "^1.12.1",
Expand Down
31 changes: 17 additions & 14 deletions src/components/annotations/draw.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

var d3 = require('@plotly/d3');
var d3 = require('../../lib/d3');

var Registry = require('../../registry');
var Plots = require('../../plots/plots');
Expand Down Expand Up @@ -221,13 +221,16 @@ function drawRaw(gd, options, index, subplotId, xa, ya) {

var annTextClip = fullLayout._topclips
.selectAll('#' + annClipID)
.data(isSizeConstrained ? [0] : []);
.data(isSizeConstrained ? [0] : [])
.enter()
.append('clipPath');

annTextClip.enter().append('clipPath')
annTextClip.exit().remove();

annTextClip
.classed('annclip', true)
.attr('id', annClipID)
.append('rect');
annTextClip.exit().remove();
.append('rect');

var font = options.font;

Expand All @@ -241,7 +244,7 @@ function drawRaw(gd, options, index, subplotId, xa, ya) {

function textLayout(s) {
s.call(Drawing.font, font)
.attr({
.attrs({
'text-anchor': {
left: 'start',
right: 'end'
Expand All @@ -256,11 +259,11 @@ function drawRaw(gd, options, index, subplotId, xa, ya) {
// if the text has *only* a link, make the whole box into a link
var anchor3 = annText.selectAll('a');
if(anchor3.size() === 1 && anchor3.text() === annText.text()) {
var wholeLink = annTextGroupInner.insert('a', ':first-child').attr({
var wholeLink = annTextGroupInner.insert('a', ':first-child').attrs({
'xlink:xlink:href': anchor3.attr('xlink:href'),
'xlink:xlink:show': anchor3.attr('xlink:show')
})
.style({cursor: 'pointer'});
.styles({cursor: 'pointer'});

wholeLink.node().appendChild(annTextBG.node());
}
Expand Down Expand Up @@ -453,7 +456,7 @@ function drawRaw(gd, options, index, subplotId, xa, ya) {
}

if(hasMathjax) {
mathjaxGroup.select('svg').attr({
mathjaxGroup.select('svg').attrs({
x: borderfull + xShift - 1,
y: borderfull + yShift
})
Expand Down Expand Up @@ -482,7 +485,7 @@ function drawRaw(gd, options, index, subplotId, xa, ya) {
* because we needed that for autoranging anyway, so now whether
* we have an arrow or not, we rotate about the text center.
*/
annTextGroup.attr({transform: 'rotate(' + textangle + ',' +
annTextGroup.attrs({transform: 'rotate(' + textangle + ',' +
annPosPx.x.text + ',' + annPosPx.y.text + ')'});

/*
Expand Down Expand Up @@ -550,7 +553,7 @@ function drawRaw(gd, options, index, subplotId, xa, ya) {
var arrowSide = options.arrowside;

var arrowGroup = annGroup.append('g')
.style({opacity: Color.opacity(arrowColor)})
.styles({opacity: Color.opacity(arrowColor)})
.classed('annotation-arrow-g', true);

var arrow = arrowGroup.append('path')
Expand All @@ -574,7 +577,7 @@ function drawRaw(gd, options, index, subplotId, xa, ya) {
.classed('annotation-arrow', true)
.classed('anndrag', true)
.classed('cursor-move', true)
.attr({
.attrs({
d: 'M3,3H-3V-3H3ZM0,0L' + (tailX - arrowDragHeadX) + ',' + (tailY - arrowDragHeadY),
transform: strTranslate(arrowDragHeadX, arrowDragHeadY)
})
Expand Down Expand Up @@ -624,7 +627,7 @@ function drawRaw(gd, options, index, subplotId, xa, ya) {
}

arrowGroup.attr('transform', strTranslate(dx, dy));
annTextGroup.attr({
annTextGroup.attrs({
transform: 'rotate(' + textangle + ',' +
xcenter + ',' + ycenter + ')'
});
Expand Down Expand Up @@ -707,7 +710,7 @@ function drawRaw(gd, options, index, subplotId, xa, ya) {
}
} else return;

annTextGroup.attr({
annTextGroup.attrs({
transform: strTranslate(dx, dy) + baseTextTransform
});

Expand Down
10 changes: 5 additions & 5 deletions src/components/annotations/draw_arrow_head.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

var d3 = require('@plotly/d3');
var d3 = require('../../lib/d3');

var Color = require('../color');

Expand Down Expand Up @@ -70,7 +70,7 @@ module.exports = function drawArrowHead(el3, ends, options) {

end.x += backOffX;
end.y += backOffY;
el3.attr({x2: end.x, y2: end.y});
el3.attrs({x2: end.x, y2: end.y});
}

if(startBackOff) {
Expand All @@ -83,7 +83,7 @@ module.exports = function drawArrowHead(el3, ends, options) {

start.x -= startBackOffX;
start.y -= startbackOffY;
el3.attr({x1: start.x, y1: start.y});
el3.attrs({x1: start.x, y1: start.y});
}
} else if(el.nodeName === 'path') {
var pathlen = el.getTotalLength();
Expand Down Expand Up @@ -126,15 +126,15 @@ module.exports = function drawArrowHead(el3, ends, options) {
if(arrowHeadStyle.noRotate) rot = 0;

d3.select(el.parentNode).append('path')
.attr({
.attrs({
'class': el3.attr('class'),
d: arrowHeadStyle.path,
transform:
strTranslate(p.x, p.y) +
strRotate(rot * 180 / Math.PI) +
strScale(arrowScale)
})
.style({
.styles({
fill: Color.rgb(options.arrowcolor),
'stroke-width': 0
});
Expand Down
4 changes: 2 additions & 2 deletions src/components/color/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,12 @@ color.contrast = function(cstr, lightAmount, darkAmount) {

color.stroke = function(s, c) {
var tc = tinycolor(c);
s.style({'stroke': color.tinyRGB(tc), 'stroke-opacity': tc.getAlpha()});
s.styles({'stroke': color.tinyRGB(tc), 'stroke-opacity': tc.getAlpha()});
};

color.fill = function(s, c) {
var tc = tinycolor(c);
s.style({
s.styles({
'fill': color.tinyRGB(tc),
'fill-opacity': tc.getAlpha()
});
Expand Down
52 changes: 32 additions & 20 deletions src/components/colorbar/draw.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
'use strict';

var d3 = require('@plotly/d3');
var d3 = require('../../lib/d3');
var tinycolor = require('tinycolor2');

var Plots = require('../../plots/plots');
var Registry = require('../../registry');
var Axes = require('../../plots/cartesian/axes');
var dragElement = require('../dragelement');
var Lib = require('../../lib');
var getTraceFromCd = require('../../lib/trace_from_cd');
var strTranslate = Lib.strTranslate;
var extendFlat = require('../../lib/extend').extendFlat;
var setCursor = require('../../lib/setcursor');
Expand All @@ -33,12 +34,20 @@ function draw(gd) {

var colorBars = fullLayout._infolayer
.selectAll('g.' + cn.colorbar)
.data(makeColorBarData(gd), function(opts) { return opts._id; });
.data(makeColorBarData(gd), function(opts) { return opts._id; })
.enter()
.append('g');

colorBars.enter().append('g')
colorBars.exit()
.each(function(opts) { Plots.autoMargin(gd, opts._id); })
.remove();

colorBars
.attr('class', function(opts) { return opts._id; })
.classed(cn.colorbar, true);

colorBars.order();

colorBars.each(function(opts) {
var g = d3.select(this);

Expand All @@ -56,12 +65,6 @@ function draw(gd) {
makeEditable(g, opts, gd);
}
});

colorBars.exit()
.each(function(opts) { Plots.autoMargin(gd, opts._id); })
.remove();

colorBars.order();
}

function makeColorBarData(gd) {
Expand Down Expand Up @@ -116,7 +119,7 @@ function makeColorBarData(gd) {

for(var i = 0; i < calcdata.length; i++) {
var cd = calcdata[i];
trace = cd[0].trace;
trace = getTraceFromCd(cd);
var moduleOpts = trace._module.colorbar;

if(trace.visible === true && moduleOpts) {
Expand Down Expand Up @@ -391,11 +394,15 @@ function drawColorBar(g, opts, gd) {
var fills = g.select('.' + cn.cbfills)
.selectAll('rect.' + cn.cbfill)
.attr('style', '')
.data(fillLevels);
fills.enter().append('rect')
.data(fillLevels)
.enter()
.append('rect');

fills.exit().remove();

fills
.classed(cn.cbfill, true)
.style('stroke', 'none');
fills.exit().remove();

var zBounds = zrange
.map(ax.c2p)
Expand All @@ -417,7 +424,7 @@ function drawColorBar(g, opts, gd) {

// Colorbar cannot currently support opacities so we
// use an opaque fill even when alpha channels present
var fillEl = d3.select(this).attr({
var fillEl = d3.select(this).attrs({
x: xLeft,
width: Math.max(thickPx, 2),
y: d3.min(z),
Expand All @@ -436,10 +443,15 @@ function drawColorBar(g, opts, gd) {

var lines = g.select('.' + cn.cblines)
.selectAll('path.' + cn.cbline)
.data(line.color && line.width ? lineLevels : []);
lines.enter().append('path')
.classed(cn.cbline, true);
.data(line.color && line.width ? lineLevels : [])
.enter()
.append('path');

lines.exit().remove();

lines
.classed(cn.cbline, true);

lines.each(function(d) {
d3.select(this)
.attr('d', 'M' + xLeft + ',' +
Expand Down Expand Up @@ -501,7 +513,7 @@ function drawColorBar(g, opts, gd) {
var outerwidth = 2 * opts.xpad + innerWidth + opts.borderwidth + opts.outlinewidth / 2;
var outerheight = yBottomPx - yTopPx;

g.select('.' + cn.cbbg).attr({
g.select('.' + cn.cbbg).attrs({
x: xLeft - opts.xpad - (opts.borderwidth + opts.outlinewidth) / 2,
y: yTopPx - yExtraPx,
width: Math.max(outerwidth, 2),
Expand All @@ -511,14 +523,14 @@ function drawColorBar(g, opts, gd) {
.call(Color.stroke, opts.bordercolor)
.style('stroke-width', opts.borderwidth);

g.selectAll('.' + cn.cboutline).attr({
g.selectAll('.' + cn.cboutline).attrs({
x: xLeft,
y: yTopPx + opts.ypad + (titleSide === 'top' ? titleHeight : 0),
width: Math.max(thickPx, 2),
height: Math.max(outerheight - 2 * opts.ypad - titleHeight, 2)
})
.call(Color.stroke, opts.outlinecolor)
.style({
.styles({
fill: 'none',
'stroke-width': opts.outlinewidth
});
Expand Down
4 changes: 2 additions & 2 deletions src/components/colorscale/helpers.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

var d3 = require('@plotly/d3');
var d3 = require('../../lib/d3');
var tinycolor = require('tinycolor2');
var isNumeric = require('fast-isnumeric');

Expand Down Expand Up @@ -169,7 +169,7 @@ function makeColorScaleFunc(specs, opts) {
_range[i] = [rgba.r, rgba.g, rgba.b, rgba.a];
}

var _sclFunc = d3.scale.linear()
var _sclFunc = d3.scaleLinear()
.domain(domain)
.range(_range)
.clamp(true);
Expand Down
Loading