Skip to content
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

[Experimental] Investigate d3 v4 upgrade #838

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"arraytools": "^1.0.0",
"convex-hull": "^1.0.3",
"country-regex": "^1.0.0",
"d3": "^3.5.12",
"d3": "^4.2.1",
"delaunay-triangulate": "^1.1.6",
"es6-promise": "^3.0.2",
"fast-isnumeric": "^1.1.1",
Expand Down
30 changes: 15 additions & 15 deletions src/components/annotations/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ annotations.draw = function(gd, index, opt, value) {

function textLayout(s) {
s.call(Drawing.font, font)
.attr({
.attrs({
'text-anchor': {
left: 'start',
right: 'end'
Expand All @@ -396,7 +396,7 @@ annotations.draw = function(gd, index, opt, value) {

// make sure lines are aligned the way they will be
// at the end, even if their position changes
anntext.selectAll('tspan.line').attr({y: 0, x: 0});
anntext.selectAll('tspan.line').attrs({y: 0, x: 0});

var mathjaxGroup = ann.select('.annotation-math-group'),
hasMathjax = !mathjaxGroup.empty(),
Expand Down Expand Up @@ -522,11 +522,11 @@ annotations.draw = function(gd, index, opt, value) {
textx = borderfull - anntextBB.left;

if(hasMathjax) {
mathjaxGroup.select('svg').attr({x: borderfull - 1, y: borderfull});
mathjaxGroup.select('svg').attrs({x: borderfull - 1, y: borderfull});
}
else {
anntext.attr({x: textx, y: texty});
anntext.selectAll('tspan.line').attr({y: texty, x: textx});
anntext.attrs({x: textx, y: texty});
anntext.selectAll('tspan.line').attrs({y: texty, x: textx});
}

annbg.call(Drawing.setRect, borderwidth / 2, borderwidth / 2,
Expand Down Expand Up @@ -618,7 +618,7 @@ annotations.draw = function(gd, index, opt, value) {
arrowColor = options.arrowcolor;

var arrowgroup = anngroup.append('g')
.style({opacity: Color.opacity(arrowColor)})
.styles({opacity: Color.opacity(arrowColor)})
.classed('annotation-arrow-g', true)
.attr('data-index', String(index));

Expand All @@ -632,7 +632,7 @@ annotations.draw = function(gd, index, opt, value) {
var arrowdrag = arrowgroup.append('path')
.classed('annotation', true)
.classed('anndrag', true)
.attr({
.attrs({
'data-index': String(index),
d: 'M3,3H-3V-3H3ZM0,0L' + (arrowX0 - arrowX) + ',' + (arrowY0 - arrowY),
transform: 'translate(' + arrowX + ',' + arrowY + ')'
Expand Down Expand Up @@ -688,7 +688,7 @@ annotations.draw = function(gd, index, opt, value) {
(1 - ((arrowY + dy - gs.t) / gs.h));
}

anng.attr({
anng.attrs({
transform: 'rotate(' + textangle + ',' +
xcenter + ',' + ycenter + ')'
});
Expand Down Expand Up @@ -777,7 +777,7 @@ annotations.draw = function(gd, index, opt, value) {

ann.call(Lib.setTranslate, x0 + dx, y0 + dy);

anng.attr({
anng.attrs({
transform: 'rotate(' + textangle + ',' +
x1 + ',' + y1 + ')'
});
Expand All @@ -801,7 +801,7 @@ annotations.draw = function(gd, index, opt, value) {
.call(textLayout)
.on('edit', function(_text) {
options.text = _text;
this.attr({'data-unformatted': options.text});
this.attrs({'data-unformatted': options.text});
this.call(textLayout);
var update = {};
update['annotations[' + index + '].text'] = options.text;
Expand All @@ -817,7 +817,7 @@ annotations.draw = function(gd, index, opt, value) {
else anntext.call(textLayout);

// rotate and position text and background
anng.attr({transform: 'rotate(' + textangle + ',' +
anng.attrs({transform: 'rotate(' + textangle + ',' +
annPosPx.x + ',' + annPosPx.y + ')'})
.call(Drawing.setPosition, annPosPx.x, annPosPx.y);
};
Expand Down Expand Up @@ -857,12 +857,12 @@ annotations.arrowhead = function(el3, style, ends, mag) {
if(doStart) {
start.x -= backOffX;
start.y -= backOffY;
el3.attr({x1: start.x, y1: start.y});
el3.attrs({x1: start.x, y1: start.y});
}
if(doEnd) {
end.x += backOffX;
end.y += backOffY;
el3.attr({x2: end.x, y2: end.y});
el3.attrs({x2: end.x, y2: end.y});
}
}
}
Expand Down Expand Up @@ -901,15 +901,15 @@ annotations.arrowhead = function(el3, style, ends, mag) {
var drawhead = function(p, rot) {
if(style > 5) rot = 0; // don't rotate square or circle
d3.select(el.parentElement).append('path')
.attr({
.attrs({
'class': el3.attr('class'),
d: headStyle.path,
transform:
'translate(' + p.x + ',' + p.y + ')' +
'rotate(' + (rot * 180 / Math.PI) + ')' +
'scale(' + scale + ')'
})
.style({
.styles({
fill: stroke,
opacity: opacity,
'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 @@ -69,12 +69,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({'fill': color.tinyRGB(tc), 'fill-opacity': tc.getAlpha()});
s.styles({'fill': color.tinyRGB(tc), 'fill-opacity': tc.getAlpha()});
};

// search container for colors with the deprecated rgb(fractions) format
Expand Down
10 changes: 5 additions & 5 deletions src/components/colorbar/draw.js
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ module.exports = function draw(gd, id) {

// Colorbar cannot currently support opacities so we
// use an opaque fill even when alpha channels present
d3.select(this).attr({
d3.select(this).attrs({
x: xLeft,
width: Math.max(thickPx, 2),
y: d3.min(z),
Expand Down Expand Up @@ -495,7 +495,7 @@ module.exports = function draw(gd, id) {
opts.borderwidth + opts.outlinewidth / 2,
outerheight = yBottomPx - yTopPx;

container.select('.cbbg').attr({
container.select('.cbbg').attrs({
x: xLeft - opts.xpad -
(opts.borderwidth + opts.outlinewidth) / 2,
y: yTopPx - yExtraPx,
Expand All @@ -504,17 +504,17 @@ module.exports = function draw(gd, id) {
})
.call(Color.fill, opts.bgcolor)
.call(Color.stroke, opts.bordercolor)
.style({'stroke-width': opts.borderwidth});
.styles({'stroke-width': opts.borderwidth});

container.selectAll('.cboutline').attr({
container.selectAll('.cboutline').attrs({
x: xLeft,
y: yTopPx + opts.ypad +
(opts.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
22 changes: 12 additions & 10 deletions src/components/drawing/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ drawing.dashLine = function(s, dash, lineWidth) {
}
// otherwise user wrote the dasharray themselves - leave it be

s.style({
s.styles({
'stroke-dasharray': dash,
'stroke-width': lineWidth + 'px'
});
Expand Down Expand Up @@ -248,7 +248,7 @@ drawing.pointStyle = function(s, trace) {
// open markers can't have zero linewidth, default to 1px,
// and use fill color as stroke color
p.call(Color.stroke, fillColor)
.style({
.styles({
'stroke-width': (lineWidth || 1) + 'px',
fill: 'none'
});
Expand Down Expand Up @@ -346,7 +346,7 @@ drawing.textPointStyle = function(s, trace) {

// then fix multiline text
if(numLines > 1) {
tspans.attr({ x: p.attr('x'), y: p.attr('y') });
tspans.attrs({ x: p.attr('x'), y: p.attr('y') });
}
});
};
Expand Down Expand Up @@ -456,15 +456,16 @@ drawing.makeTester = function(gd) {

tester.enter().append('svg')
.attr('id', 'js-plotly-tester')
.attr(xmlnsNamespaces.svgAttrs)
.style({
.attrs(xmlnsNamespaces.svgAttrs)
.styles({
position: 'absolute',
left: '-10000px',
top: '-10000px',
width: '9000px',
height: '9000px',
'z-index': '1'
});
tester = d3.select('body').select('#js-plotly-tester');

// browsers differ on how they describe the bounding rect of
// the svg if its contents spill over... so make a 1x1px
Expand All @@ -473,14 +474,15 @@ drawing.makeTester = function(gd) {
testref.enter().append('path')
.classed('js-reference-point', true)
.attr('d', 'M0,0H1V1H0Z')
.style({
.styles({
'stroke-width': 0,
fill: 'black'
});
testref = tester.select('.js-reference-point');

if(!tester.node()._cache) {
tester.node()._cache = {};
}
//if(!tester.node()._cache) {
//tester.node()._cache = {};
//}

gd._tester = tester;
gd._testref = testref;
Expand All @@ -507,7 +509,7 @@ drawing.bBox = function(node) {
var testNode = node.cloneNode(true);
tester.appendChild(testNode);
// standardize its position... do we really want to do this?
d3.select(testNode).attr({
d3.select(testNode).attrs({
x: 0,
y: 0,
transform: ''
Expand Down
2 changes: 1 addition & 1 deletion src/components/images/draw.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ module.exports = function draw(gd) {
break;
}

thisImage.attr({
thisImage.attrs({
x: xPos,
y: yPos,
width: width,
Expand Down
Loading