Skip to content

Commit 736ab69

Browse files
committed
replace Axex.expand -> findExtremes in annotations and shapes
1 parent 769c160 commit 736ab69

File tree

2 files changed

+53
-58
lines changed

2 files changed

+53
-58
lines changed

src/components/annotations/calc_autorange.js

Lines changed: 46 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -34,63 +34,54 @@ function annAutorange(gd) {
3434
Lib.filterVisible(fullLayout.annotations).forEach(function(ann) {
3535
var xa = Axes.getFromId(gd, ann.xref);
3636
var ya = Axes.getFromId(gd, ann.yref);
37-
var headSize = 3 * ann.arrowsize * ann.arrowwidth || 0;
38-
var startHeadSize = 3 * ann.startarrowsize * ann.arrowwidth || 0;
3937

40-
var headPlus, headMinus, startHeadPlus, startHeadMinus;
41-
42-
if(xa) {
43-
headPlus = headSize + ann.xshift;
44-
headMinus = headSize - ann.xshift;
45-
startHeadPlus = startHeadSize + ann.xshift;
46-
startHeadMinus = startHeadSize - ann.xshift;
38+
ann._extremes = {};
39+
if(xa) calcAxisExpansion(ann, xa);
40+
if(ya) calcAxisExpansion(ann, ya);
41+
});
42+
}
4743

48-
if(ann.axref === ann.xref) {
49-
// expand for the arrowhead (padded by arrowhead)
50-
Axes.expand(xa, [xa.r2c(ann.x)], {
51-
ppadplus: headPlus,
52-
ppadminus: headMinus
53-
});
54-
// again for the textbox (padded by textbox)
55-
Axes.expand(xa, [xa.r2c(ann.ax)], {
56-
ppadplus: Math.max(ann._xpadplus, startHeadPlus),
57-
ppadminus: Math.max(ann._xpadminus, startHeadMinus)
58-
});
59-
}
60-
else {
61-
startHeadPlus = ann.ax ? startHeadPlus + ann.ax : startHeadPlus;
62-
startHeadMinus = ann.ax ? startHeadMinus - ann.ax : startHeadMinus;
63-
Axes.expand(xa, [xa.r2c(ann.x)], {
64-
ppadplus: Math.max(ann._xpadplus, headPlus, startHeadPlus),
65-
ppadminus: Math.max(ann._xpadminus, headMinus, startHeadMinus)
66-
});
67-
}
68-
}
44+
function calcAxisExpansion(ann, ax) {
45+
var axId = ax._id;
46+
var letter = axId.charAt(0);
47+
var pos = ann[letter];
48+
var apos = ann['a' + letter];
49+
var ref = ann[letter + 'ref'];
50+
var aref = ann['a' + letter + 'ref'];
51+
var padplus = ann['_' + letter + 'padplus'];
52+
var padminus = ann['_' + letter + 'padminus'];
53+
var shift = {x: 1, y: -1}[letter] * ann[letter + 'shift'];
54+
var headSize = 3 * ann.arrowsize * ann.arrowwidth || 0;
55+
var headPlus = headSize + shift;
56+
var headMinus = headSize - shift;
57+
var startHeadSize = 3 * ann.startarrowsize * ann.arrowwidth || 0;
58+
var startHeadPlus = startHeadSize + shift;
59+
var startHeadMinus = startHeadSize - shift;
60+
var extremes;
6961

70-
if(ya) {
71-
headPlus = headSize - ann.yshift;
72-
headMinus = headSize + ann.yshift;
73-
startHeadPlus = startHeadSize - ann.yshift;
74-
startHeadMinus = startHeadSize + ann.yshift;
62+
if(aref === ref) {
63+
// expand for the arrowhead (padded by arrowhead)
64+
var extremeArrowHead = Axes.findExtremes(ax, [ax.r2c(pos)], {
65+
ppadplus: headPlus,
66+
ppadminus: headMinus
67+
});
68+
// again for the textbox (padded by textbox)
69+
var extremeText = Axes.findExtremes(ax, [ax.r2c(apos)], {
70+
ppadplus: Math.max(padplus, startHeadPlus),
71+
ppadminus: Math.max(padminus, startHeadMinus)
72+
});
73+
extremes = {
74+
min: [extremeArrowHead.min[0], extremeText.min[0]],
75+
max: [extremeArrowHead.max[0], extremeText.max[0]]
76+
};
77+
} else {
78+
startHeadPlus = apos ? startHeadPlus + apos : startHeadPlus;
79+
startHeadMinus = apos ? startHeadMinus - apos : startHeadMinus;
80+
extremes = Axes.findExtremes(ax, [ax.r2c(pos)], {
81+
ppadplus: Math.max(padplus, headPlus, startHeadPlus),
82+
ppadminus: Math.max(padminus, headMinus, startHeadMinus)
83+
});
84+
}
7585

76-
if(ann.ayref === ann.yref) {
77-
Axes.expand(ya, [ya.r2c(ann.y)], {
78-
ppadplus: headPlus,
79-
ppadminus: headMinus
80-
});
81-
Axes.expand(ya, [ya.r2c(ann.ay)], {
82-
ppadplus: Math.max(ann._ypadplus, startHeadPlus),
83-
ppadminus: Math.max(ann._ypadminus, startHeadMinus)
84-
});
85-
}
86-
else {
87-
startHeadPlus = ann.ay ? startHeadPlus + ann.ay : startHeadPlus;
88-
startHeadMinus = ann.ay ? startHeadMinus - ann.ay : startHeadMinus;
89-
Axes.expand(ya, [ya.r2c(ann.y)], {
90-
ppadplus: Math.max(ann._ypadplus, headPlus, startHeadPlus),
91-
ppadminus: Math.max(ann._ypadminus, headMinus, startHeadMinus)
92-
});
93-
}
94-
}
95-
});
86+
ann._extremes[axId] = extremes;
9687
}

src/components/shapes/calc_autorange.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ module.exports = function calcAutorange(gd) {
2424

2525
for(var i = 0; i < shapeList.length; i++) {
2626
var shape = shapeList[i];
27+
shape._extremes = {};
2728

2829
var ax, bounds;
2930

@@ -33,8 +34,9 @@ module.exports = function calcAutorange(gd) {
3334
ax = Axes.getFromId(gd, shape.xref);
3435

3536
bounds = shapeBounds(ax, vx0, vx1, shape.path, constants.paramIsX);
36-
37-
if(bounds) Axes.expand(ax, bounds, calcXPaddingOptions(shape));
37+
if(bounds) {
38+
shape._extremes[ax._id] = Axes.findExtremes(ax, bounds, calcXPaddingOptions(shape));
39+
}
3840
}
3941

4042
if(shape.yref !== 'paper') {
@@ -43,7 +45,9 @@ module.exports = function calcAutorange(gd) {
4345
ax = Axes.getFromId(gd, shape.yref);
4446

4547
bounds = shapeBounds(ax, vy0, vy1, shape.path, constants.paramIsY);
46-
if(bounds) Axes.expand(ax, bounds, calcYPaddingOptions(shape));
48+
if(bounds) {
49+
shape._extremes[ax._id] = Axes.findExtremes(ax, bounds, calcYPaddingOptions(shape));
50+
}
4751
}
4852
}
4953
};

0 commit comments

Comments
 (0)