Skip to content

Commit 8b8a088

Browse files
committed
pass subplotId as arg to Annotations.drawRaw
- instead of expecting it on options._subplotId
1 parent 0b4214f commit 8b8a088

File tree

3 files changed

+27
-26
lines changed

3 files changed

+27
-26
lines changed

src/components/annotations/draw.js

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ function draw(gd) {
5858
}
5959

6060
/*
61-
* drawOne: draw a single annotation, potentially with modifications
61+
* drawOne: draw a single cartesian or paper-ref annotation, potentially with modifications
6262
*
6363
* index (int): the annotation to draw
6464
*/
@@ -68,28 +68,33 @@ function drawOne(gd, index) {
6868
var xa = Axes.getFromId(gd, options.xref);
6969
var ya = Axes.getFromId(gd, options.yref);
7070

71-
drawRaw(gd, options, index, xa, ya);
71+
drawRaw(gd, options, index, false, xa, ya);
7272
}
7373

74-
/*
74+
/**
7575
* drawRaw: draw a single annotation, potentially with modifications
7676
*
77-
* options (object): this annotation's options
78-
* index (int): the annotation to draw
79-
* xa (object | undefined): full x-axis object to compute subplot pos-to-px
80-
* ya (object | undefined): ... y-axis
77+
* @param {DOM element} gd
78+
* @param {object} options : this annotation's fullLayout options
79+
* @param {integer} index : index in 'annotations' container of the annotation to draw
80+
* @param {string} subplotId : id of the annotation's subplot
81+
* - use false for 2d (i.e. cartesian or paper-ref) annotations
82+
* @param {object | undefined} xa : full x-axis object to compute subplot pos-to-px
83+
* @param {object | undefined} ya : ... y-axis
8184
*/
82-
function drawRaw(gd, options, index, xa, ya) {
85+
function drawRaw(gd, options, index, subplotId, xa, ya) {
8386
var fullLayout = gd._fullLayout;
8487
var gs = gd._fullLayout._size;
85-
86-
var className = options._sceneId ?
87-
'annotation-' + options._sceneId :
88-
'annotation';
89-
90-
var annbase = options._sceneId ?
91-
options._sceneId + '.annotations[' + index + ']' :
92-
'annotations[' + index + ']';
88+
var className;
89+
var annbase;
90+
91+
if(subplotId) {
92+
className = 'annotation-' + subplotId;
93+
annbase = subplotId + '.annotations[' + index + ']';
94+
} else {
95+
className = 'annotation';
96+
annbase = 'annotations[' + index + ']';
97+
}
9398

9499
// remove the existing annotation if there is one
95100
fullLayout._infolayer
@@ -515,7 +520,7 @@ function drawRaw(gd, options, index, xa, ya) {
515520

516521
// the arrow dragger is a small square right at the head, then a line to the tail,
517522
// all expanded by a stroke width of 6px plus the arrow line width
518-
if(gd._context.editable && arrow.node().parentNode && !options._sceneId) {
523+
if(gd._context.editable && arrow.node().parentNode && !subplotId) {
519524
var arrowDragHeadX = headX;
520525
var arrowDragHeadY = headY;
521526
if(options.standoff) {
@@ -625,7 +630,7 @@ function drawRaw(gd, options, index, xa, ya) {
625630

626631
drawArrow(dx, dy);
627632
}
628-
else if(!options._sceneId) {
633+
else if(!subplotId) {
629634
if(xa) update[annbase + '.x'] = options.x + dx / xa._m;
630635
else {
631636
var widthFraction = options._xsize / gs.w,

src/components/annotations3d/defaults.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ module.exports = function handleDefaults(sceneLayoutIn, sceneLayoutOut, opts) {
1717
handleArrayContainerDefaults(sceneLayoutIn, sceneLayoutOut, {
1818
name: 'annotations',
1919
handleItemDefaults: handleAnnotationDefaults,
20-
fullLayout: opts.fullLayout,
21-
sceneId: opts.id
20+
fullLayout: opts.fullLayout
2221
});
2322
};
2423

@@ -32,9 +31,8 @@ function handleAnnotationDefaults(annIn, annOut, sceneLayout, opts, itemOpts) {
3231

3332
handleAnnotationCommonDefaults(annIn, annOut, opts.fullLayout, coerce);
3433

35-
// Do not use Axes.coercePosition here
36-
// as ax._categories aren't filled in at this stage,
37-
// Axes.coercePosition is called during scene.setConvert instead
34+
// do not use Axes.coercePosition here
35+
// as ax._categories aren't filled in at this stage
3836
coerce('x');
3937
coerce('y');
4038
coerce('z');
@@ -64,7 +62,5 @@ function handleAnnotationDefaults(annIn, annOut, sceneLayout, opts, itemOpts) {
6462
Lib.noneOrAll(annIn, annOut, ['ax', 'ay']);
6563
}
6664

67-
annOut._sceneId = opts.sceneId;
68-
6965
return annOut;
7066
}

src/components/annotations3d/draw.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ module.exports = function draw(scene) {
4444
fullSceneLayout.zaxis.r2l(ann.z) * dataScale[2]
4545
]);
4646

47-
drawRaw(scene.graphDiv, ann, i, ann._xa, ann._ya);
47+
drawRaw(scene.graphDiv, ann, i, scene.id, ann._xa, ann._ya);
4848
}
4949
}
5050
};

0 commit comments

Comments
 (0)