@@ -39,69 +39,56 @@ module.exports = function handleAnnotationDefaults(annIn, fullLayout) {
39
39
var borderWidth = coerce ( 'borderwidth' ) ;
40
40
var showArrow = coerce ( 'showarrow' ) ;
41
41
42
- if ( showArrow ) {
43
- coerce ( 'arrowcolor' , borderOpacity ? annOut . bordercolor : Color . defaultLine ) ;
44
- coerce ( 'arrowhead' ) ;
45
- coerce ( 'arrowsize' ) ;
46
- coerce ( 'arrowwidth' , ( ( borderOpacity && borderWidth ) || 1 ) * 2 ) ;
47
- coerce ( 'ax' ) ;
48
- coerce ( 'ay' ) ;
49
- coerce ( 'axref' ) ;
50
- coerce ( 'ayref' ) ;
51
-
52
- // if you have one part of arrow length you should have both
53
- Lib . noneOrAll ( annIn , annOut , [ 'ax' , 'ay' ] ) ;
54
- }
55
-
56
42
coerce ( 'text' , showArrow ? ' ' : 'new text' ) ;
57
43
coerce ( 'textangle' ) ;
58
44
Lib . coerceFont ( coerce , 'font' , fullLayout . font ) ;
59
45
60
46
// positioning
61
- var axLetters = [ 'x' , 'y' ] ;
47
+ var axLetters = [ 'x' , 'y' ] ,
48
+ arrowPosDflt = [ - 10 , - 30 ] ,
49
+ gdMock = { _fullLayout : fullLayout } ;
62
50
for ( var i = 0 ; i < 2 ; i ++ ) {
63
- var axLetter = axLetters [ i ] ,
64
- tdMock = { _fullLayout : fullLayout } ;
51
+ var axLetter = axLetters [ i ] ;
65
52
66
53
// xref, yref
67
- var axRef = Axes . coerceRef ( annIn , annOut , tdMock , axLetter ) ;
68
-
69
- // TODO: should be refactored in conjunction with Axes axref, ayref
70
- var aaxRef = Axes . coerceARef ( annIn , annOut , tdMock , axLetter ) ;
54
+ var axRef = Axes . coerceRef ( annIn , annOut , gdMock , axLetter , '' , 'paper' ) ;
71
55
72
56
// x, y
73
- var defaultPosition = 0.5 ;
74
- if ( axRef !== 'paper' ) {
75
- var ax = Axes . getFromId ( tdMock , axRef ) ;
76
- defaultPosition = ax . range [ 0 ] + defaultPosition * ( ax . range [ 1 ] - ax . range [ 0 ] ) ;
77
-
78
- // convert date or category strings to numbers
79
- if ( [ 'date' , 'category' ] . indexOf ( ax . type ) !== - 1 &&
80
- typeof annIn [ axLetter ] === 'string' ) {
81
- var newval ;
82
- if ( ax . type === 'date' ) {
83
- newval = Lib . dateTime2ms ( annIn [ axLetter ] ) ;
84
- if ( newval !== false ) annIn [ axLetter ] = newval ;
85
-
86
- if ( aaxRef === axRef ) {
87
- var newvalB = Lib . dateTime2ms ( annIn [ 'a' + axLetter ] ) ;
88
- if ( newvalB !== false ) annIn [ 'a' + axLetter ] = newvalB ;
89
- }
90
- }
91
- else if ( ( ax . _categories || [ ] ) . length ) {
92
- newval = ax . _categories . indexOf ( annIn [ axLetter ] ) ;
93
- if ( newval !== - 1 ) annIn [ axLetter ] = newval ;
94
- }
57
+ Axes . coercePosition ( annOut , gdMock , coerce , axRef , axLetter , 0.5 ) ;
58
+
59
+ if ( showArrow ) {
60
+ var arrowPosAttr = 'a' + axLetter ,
61
+ // axref, ayref
62
+ aaxRef = Axes . coerceRef ( annIn , annOut , gdMock , arrowPosAttr , 'pixel' ) ;
63
+
64
+ // for now the arrow can only be on the same axis or specified as pixels
65
+ // TODO: sometime it might be interesting to allow it to be on *any* axis
66
+ // but that would require updates to drawing & autorange code and maybe more
67
+ if ( aaxRef !== 'pixel' && aaxRef !== axRef ) {
68
+ aaxRef = annOut [ arrowPosAttr ] = 'pixel' ;
95
69
}
70
+
71
+ // ax, ay
72
+ var aDflt = ( aaxRef === 'pixel' ) ? arrowPosDflt [ i ] : 0.4 ;
73
+ Axes . coercePosition ( annOut , gdMock , coerce , aaxRef , arrowPosAttr , aDflt ) ;
96
74
}
97
- coerce ( axLetter , defaultPosition ) ;
98
75
99
76
// xanchor, yanchor
100
- if ( ! showArrow ) coerce ( axLetter + 'anchor' ) ;
77
+ else coerce ( axLetter + 'anchor' ) ;
101
78
}
102
79
103
80
// if you have one coordinate you should have both
104
81
Lib . noneOrAll ( annIn , annOut , [ 'x' , 'y' ] ) ;
105
82
83
+ if ( showArrow ) {
84
+ coerce ( 'arrowcolor' , borderOpacity ? annOut . bordercolor : Color . defaultLine ) ;
85
+ coerce ( 'arrowhead' ) ;
86
+ coerce ( 'arrowsize' ) ;
87
+ coerce ( 'arrowwidth' , ( ( borderOpacity && borderWidth ) || 1 ) * 2 ) ;
88
+
89
+ // if you have one part of arrow length you should have both
90
+ Lib . noneOrAll ( annIn , annOut , [ 'ax' , 'ay' ] ) ;
91
+ }
92
+
106
93
return annOut ;
107
94
} ;
0 commit comments