Skip to content

Commit d940675

Browse files
committed
Add docstring and improve code clarity/consistency
1 parent 296bd55 commit d940675

File tree

3 files changed

+24
-20
lines changed

3 files changed

+24
-20
lines changed

src/components/shapes/calc_autorange.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,14 @@ module.exports = function calcAutorange(gd) {
5252
}
5353
};
5454

55+
/**
56+
* Calculate autorange extremes for shapes that reference multiple axes (array refs).
57+
*
58+
* @param {object} gd - main graph div object
59+
* @param {object} shape - shape object
60+
* @param {string} axLetter - 'x' or 'y' indicating which axis dimension to process
61+
* @returns {object} - mapping of axis IDs to arrays of converted coordinate values
62+
*/
5563
function calcArrayRefAutorange(gd, shape, axLetter) {
5664
var refs = shape[axLetter + 'ref'];
5765
var paramsToUse = axLetter === 'x' ? constants.paramIsX : constants.paramIsY;

src/components/shapes/defaults.js

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ function handleShapeDefaults(shapeIn, shapeOut, fullLayout) {
6868
var ySizeMode = coerce('ysizemode');
6969

7070
// positioning
71+
var dflts = [0.25, 0.75];
72+
var pixelDflts = [0, 10];
73+
7174
['x', 'y'].forEach(axLetter => {
7275
var attrAnchor = axLetter + 'anchor';
7376
var sizeMode = axLetter === 'x' ? xSizeMode : ySizeMode;
@@ -86,8 +89,13 @@ function handleShapeDefaults(shapeIn, shapeOut, fullLayout) {
8689
var expectedLen = helpers.countDefiningCoords(shapeType, path, axLetter);
8790
axRef = Axes.coerceRefArray(shapeIn, shapeOut, gdMock, axLetter, undefined, 'paper', expectedLen);
8891
shapeOut['_' + axLetter + 'refArray'] = true;
92+
} else {
93+
// String/undefined case: use coerceRef
94+
axRef = Axes.coerceRef(shapeIn, shapeOut, gdMock, axLetter, undefined, 'paper');
95+
}
8996

90-
// Need to register the shape with all referenced axes for redrawing purposes
97+
if(Array.isArray(axRef)) {
98+
// Register the shape with all referenced axes for redrawing purposes
9199
axRef.forEach(function(ref) {
92100
if(Axes.getRefType(ref) === 'range') {
93101
ax = Axes.getFromId(gdMock, ref);
@@ -96,16 +104,8 @@ function handleShapeDefaults(shapeIn, shapeOut, fullLayout) {
96104
}
97105
}
98106
});
99-
} else {
100-
// String/undefined case: use coerceRef
101-
axRef = Axes.coerceRef(shapeIn, shapeOut, gdMock, axLetter, undefined, 'paper');
102-
}
103107

104-
if(Array.isArray(axRef)) {
105108
if(noPath) {
106-
var dflts = [0.25, 0.75];
107-
var pixelDflts = [0, 10];
108-
109109
[0, 1].forEach(function(i) {
110110
var ref = axRef[i];
111111
var refType = Axes.getRefType(ref);
@@ -160,9 +160,6 @@ function handleShapeDefaults(shapeIn, shapeOut, fullLayout) {
160160

161161
// Coerce x0, x1, y0, y1
162162
if(noPath) {
163-
var dflt0 = 0.25;
164-
var dflt1 = 0.75;
165-
166163
// hack until V3.0 when log has regular range behavior - make it look like other
167164
// ranges to send to coerce, then put it back after
168165
// this is all to give reasonable default position behavior on log axes, which is
@@ -175,11 +172,11 @@ function handleShapeDefaults(shapeIn, shapeOut, fullLayout) {
175172
shapeIn[attr1] = pos2r(shapeIn[attr1], true);
176173

177174
if(sizeMode === 'pixel') {
178-
coerce(attr0, 0);
179-
coerce(attr1, 10);
175+
coerce(attr0, pixelDflts[0]);
176+
coerce(attr1, pixelDflts[1]);
180177
} else {
181-
Axes.coercePosition(shapeOut, gdMock, coerce, axRef, attr0, dflt0);
182-
Axes.coercePosition(shapeOut, gdMock, coerce, axRef, attr1, dflt1);
178+
Axes.coercePosition(shapeOut, gdMock, coerce, axRef, attr0, dflts[0]);
179+
Axes.coercePosition(shapeOut, gdMock, coerce, axRef, attr1, dflts[1]);
183180
}
184181

185182
// hack part 2

src/components/shapes/draw.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -212,11 +212,10 @@ function setClipPath(shapePath, gd, shapeOptions) {
212212
}).select('rect').attr(rect);
213213

214214
Drawing.setClipUrl(shapePath, clipId, gd);
215-
return;
215+
} else {
216+
var clipAxes = (xref + yref).replace(/paper/g, '').replace(/[xyz][0-9]* *domain/g, '');
217+
Drawing.setClipUrl(shapePath, clipAxes ? 'clip' + gd._fullLayout._uid + clipAxes : null, gd);
216218
}
217-
218-
var clipAxes = (xref + yref).replace(/paper/g, '').replace(/[xyz][0-9]* *domain/g, '');
219-
Drawing.setClipUrl(shapePath, clipAxes ? 'clip' + gd._fullLayout._uid + clipAxes : null, gd);
220219
}
221220

222221
function getMultiAxisClipRect(gd, xref, yref) {

0 commit comments

Comments
 (0)