Skip to content

Commit 1bbabad

Browse files
committed
implement autorange logic for annotations
- N.B. does not take into consideration the arrowhead (debatable)
1 parent 8f9e370 commit 1bbabad

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed

src/components/annotations/draw.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -684,7 +684,6 @@ function drawRaw(gd, options, index, xa, ya) {
684684
var update = {};
685685
update[annbase + '.text'] = options.text;
686686

687-
// TODO
688687
if(xa && xa.autorange) {
689688
update[xa._name + '.autorange'] = true;
690689
}

src/plots/gl3d/scene.js

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -459,13 +459,28 @@ proto.plot = function(sceneData, fullLayout, layout) {
459459
if(axis.autorange) {
460460
sceneBounds[0][i] = Infinity;
461461
sceneBounds[1][i] = -Infinity;
462-
for(j = 0; j < this.glplot.objects.length; ++j) {
463-
var objBounds = this.glplot.objects[j].bounds;
464-
sceneBounds[0][i] = Math.min(sceneBounds[0][i],
465-
objBounds[0][i] / dataScale[i]);
466-
sceneBounds[1][i] = Math.max(sceneBounds[1][i],
467-
objBounds[1][i] / dataScale[i]);
462+
463+
var objects = this.glplot.objects;
464+
var annotations = this.fullSceneLayout.annotations || [];
465+
var axLetter = axis._name.charAt(0);
466+
467+
for(j = 0; j < objects.length; j++) {
468+
var objBounds = objects[j].bounds;
469+
sceneBounds[0][i] = Math.min(sceneBounds[0][i], objBounds[0][i] / dataScale[i]);
470+
sceneBounds[1][i] = Math.max(sceneBounds[1][i], objBounds[1][i] / dataScale[i]);
471+
}
472+
473+
for(j = 0; j < annotations.length; j++) {
474+
var ann = annotations[j];
475+
476+
// N.B. not taking into consideration the arrowhead
477+
if(ann.visible) {
478+
var pos = axis.r2l(ann[axLetter]);
479+
sceneBounds[0][i] = Math.min(sceneBounds[0][i], pos);
480+
sceneBounds[1][i] = Math.max(sceneBounds[1][i], pos);
481+
}
468482
}
483+
469484
if('rangemode' in axis && axis.rangemode === 'tozero') {
470485
sceneBounds[0][i] = Math.min(sceneBounds[0][i], 0);
471486
sceneBounds[1][i] = Math.max(sceneBounds[1][i], 0);
@@ -793,6 +808,9 @@ function mockAnnAxes(ann, scene) {
793808
// to get setConvert to not execute cleanly
794809
type: 'linear',
795810

811+
// don't try to update them on `editable: true`
812+
autorange: false,
813+
796814
// set infinite range so that annotation draw routine
797815
// does not try to remove 'outside-range' annotations,
798816
// this case is handled in the render loop

0 commit comments

Comments
 (0)