@@ -26,6 +26,7 @@ var project = require('./project');
2626var createAxesOptions = require ( './layout/convert' ) ;
2727var createSpikeOptions = require ( './layout/spikes' ) ;
2828var computeTickMarks = require ( './layout/tick_marks' ) ;
29+ var layoutAttributes = require ( './layout/layout_attributes' ) ;
2930
3031var STATIC_CANVAS , STATIC_CONTEXT ;
3132
@@ -396,6 +397,9 @@ proto.plot = function(sceneData, fullLayout, layout) {
396397 // Save scale
397398 this . dataScale = dataScale ;
398399
400+ // after computeTraceBounds where ax._categories are filled in
401+ this . updateAnnotations ( ) ;
402+
399403 // Update traces
400404 for ( i = 0 ; i < sceneData . length ; ++ i ) {
401405 data = sceneData [ i ] ;
@@ -719,16 +723,17 @@ proto.toImage = function(format) {
719723} ;
720724
721725proto . setConvert = function ( ) {
722- var i ;
723-
724- for ( i = 0 ; i < 3 ; i ++ ) {
726+ for ( var i = 0 ; i < 3 ; i ++ ) {
725727 var ax = this . fullSceneLayout [ axisProperties [ i ] ] ;
726728 Axes . setConvert ( ax , this . fullLayout ) ;
727729 ax . setScale = Lib . noop ;
728730 }
731+ } ;
729732
733+ proto . updateAnnotations = function ( ) {
730734 var anns = this . fullSceneLayout . annotations ;
731- for ( i = 0 ; i < anns . length ; i ++ ) {
735+
736+ for ( var i = 0 ; i < anns . length ; i ++ ) {
732737 mockAnnAxes ( anns [ i ] , this ) ;
733738 }
734739
@@ -750,7 +755,9 @@ proto.handleAnnotations = function() {
750755
751756 for ( var j = 0 ; j < 3 ; j ++ ) {
752757 var axLetter = axLetters [ j ] ;
753- var posFraction = fullSceneLayout [ axLetter + 'axis' ] . r2fraction ( ann [ axLetter ] ) ;
758+ var pos = ann [ axLetter ] ;
759+ var ax = fullSceneLayout [ axLetter + 'axis' ] ;
760+ var posFraction = ax . r2fraction ( pos ) ;
754761
755762 if ( posFraction < 0 || posFraction > 1 ) {
756763 annotationIsOffscreen = true ;
@@ -764,9 +771,9 @@ proto.handleAnnotations = function() {
764771 . remove ( ) ;
765772 } else {
766773 ann . pdata = project ( this . glplot . cameraParams , [
767- fullSceneLayout . xaxis . d2l ( ann . x ) * dataScale [ 0 ] ,
768- fullSceneLayout . yaxis . d2l ( ann . y ) * dataScale [ 1 ] ,
769- fullSceneLayout . zaxis . d2l ( ann . z ) * dataScale [ 2 ]
774+ fullSceneLayout . xaxis . r2l ( ann . x ) * dataScale [ 0 ] ,
775+ fullSceneLayout . yaxis . r2l ( ann . y ) * dataScale [ 1 ] ,
776+ fullSceneLayout . zaxis . r2l ( ann . z ) * dataScale [ 2 ]
770777 ] ) ;
771778
772779 drawAnnotation ( this . graphDiv , ann , i , ann . _xa , ann . _ya ) ;
@@ -807,6 +814,27 @@ function mockAnnAxes(ann, scene) {
807814 ann . _ya . l2p = function ( ) {
808815 return 0.5 * ( 1 - ann . pdata [ 1 ] / ann . pdata [ 3 ] ) * size . h * ( domain . y [ 1 ] - domain . y [ 0 ] ) ;
809816 } ;
817+
818+ // or do something more similar to 2d
819+ // where Annotations.supplyLayoutDefaults is called after in Plots.doCalcdata
820+ // if category axes are found.
821+ function coerce ( attr , dflt ) {
822+ return Lib . coerce ( ann , ann , layoutAttributes . annotations , attr , dflt ) ;
823+ }
824+
825+ function coercePosition ( axLetter ) {
826+ var axName = axLetter + 'axis' ;
827+
828+ // mock in such way that getFromId grabs correct 3D axis
829+ var gdMock = { _fullLayout : { } } ;
830+ gdMock . _fullLayout [ axName ] = fullSceneLayout [ axName ] ;
831+
832+ return Axes . coercePosition ( ann , gdMock , coerce , axLetter , axLetter , 0.5 ) ;
833+ }
834+
835+ coercePosition ( 'x' ) ;
836+ coercePosition ( 'y' ) ;
837+ coercePosition ( 'z' ) ;
810838}
811839
812840module . exports = Scene ;
0 commit comments