@@ -46,61 +46,7 @@ function convertStyle(gd, trace) {
4646 if ( trace . visible !== true ) return opts ;
4747
4848 if ( subTypes . hasText ( trace ) ) {
49- opts . text = [ ] ;
50-
51- for ( i = 0 ; i < trace . text . length ; i ++ ) {
52- var textOptions = opts . text [ i ] = { } ;
53-
54- var textfont = unarr ( trace . textfont , i ) ;
55- var fontSize = unarr ( textfont . size , i ) ;
56- if ( ! isNumeric ( fontSize ) ) continue ;
57-
58- textOptions . color = unarr ( textfont . color , i ) ;
59-
60- textOptions . font = {
61- family : unarr ( textfont . family , i ) ,
62- size : fontSize
63- } ;
64-
65-
66- var textpos = unarr ( trace . textposition , i ) ;
67- textpos = textpos . split ( / \s + / ) ;
68- switch ( textpos [ 1 ] ) {
69- case 'left' :
70- textOptions . align = 'right' ;
71- break ;
72- case 'right' :
73- textOptions . align = 'left' ;
74- break ;
75- default :
76- textOptions . align = textpos [ 1 ] ;
77- }
78-
79- switch ( textpos [ 0 ] ) {
80- case 'top' :
81- textOptions . baseline = 'bottom' ;
82- break ;
83- case 'bottom' :
84- textOptions . baseline = 'top' ;
85- break ;
86- default :
87- textOptions . baseline = textpos [ 0 ] ;
88- }
89-
90- // corresponds to textPointPosition from component.drawing
91- if ( trace . marker ) {
92- var hSign = TEXTOFFSETSIGN [ textOptions . align ] ;
93- var markerRadius = unarr ( unarr ( trace . marker , i ) . size , i ) / 2 ;
94- var xPad = markerRadius ? markerRadius / 0.8 + 1 : 0 ;
95- var vSign = TEXTOFFSETSIGN [ textOptions . baseline ] ;
96- var yPad = - vSign * xPad - vSign * 0.5 ;
97- textOptions . offset = [ hSign * xPad / fontSize , yPad / fontSize ] ;
98- }
99-
100- textOptions . position = [ unarr ( trace . x , i ) , unarr ( trace . y , i ) ] ;
101-
102- textOptions . text = unarr ( trace . text , i ) ;
103- }
49+ opts . text = convertTextfont ( trace , trace . textfont ) ;
10450 }
10551
10652 if ( subTypes . hasMarkers ( trace ) ) {
@@ -151,6 +97,69 @@ function convertStyle(gd, trace) {
15197 return opts ;
15298}
15399
100+ function convertTextfont ( trace , textfont ) {
101+ var opts = [ ] , i ;
102+
103+ for ( i = 0 ; i < trace . text . length ; i ++ ) {
104+ var textOptions = opts [ i ] = { } ;
105+
106+ textOptions . color = unarr ( textfont . color , i ) ;
107+
108+ var textpos = unarr ( trace . textposition , i ) ;
109+ textpos = textpos . split ( / \s + / ) ;
110+ switch ( textpos [ 1 ] ) {
111+ case 'left' :
112+ textOptions . align = 'right' ;
113+ break ;
114+ case 'right' :
115+ textOptions . align = 'left' ;
116+ break ;
117+ default :
118+ textOptions . align = textpos [ 1 ] ;
119+ }
120+
121+ switch ( textpos [ 0 ] ) {
122+ case 'top' :
123+ textOptions . baseline = 'bottom' ;
124+ break ;
125+ case 'bottom' :
126+ textOptions . baseline = 'top' ;
127+ break ;
128+ default :
129+ textOptions . baseline = textpos [ 0 ] ;
130+ }
131+
132+ textfont = unarr ( textfont , i ) ;
133+
134+ var fontSize = unarr ( textfont . size , i ) ;
135+
136+ if ( ! isNumeric ( fontSize ) ) {
137+ continue ;
138+ }
139+
140+ textOptions . font = {
141+ family : unarr ( textfont . family , i ) ,
142+ size : fontSize
143+ } ;
144+
145+ // corresponds to textPointPosition from component.drawing
146+ if ( trace . marker ) {
147+ var hSign = TEXTOFFSETSIGN [ textOptions . align ] ;
148+ var markerRadius = unarr ( unarr ( trace . marker , i ) . size , i ) / 2 ;
149+ var xPad = markerRadius ? markerRadius / 0.8 + 1 : 0 ;
150+ var vSign = TEXTOFFSETSIGN [ textOptions . baseline ] ;
151+ var yPad = - vSign * xPad - vSign * 0.5 ;
152+ textOptions . offset = [ hSign * xPad / fontSize , yPad / fontSize ] ;
153+ }
154+
155+ textOptions . position = [ unarr ( trace . x , i ) , unarr ( trace . y , i ) ] ;
156+
157+ textOptions . text = unarr ( trace . text , i ) ;
158+
159+ }
160+
161+ return opts ;
162+ }
154163
155164// FIXME: find proper util method for this
156165function unarr ( obj , i ) {
@@ -294,6 +303,10 @@ function convertMarkerSelection(trace, target) {
294303 if ( target . marker . opacity !== undefined ) optsOut . opacity = target . marker . opacity ;
295304 }
296305
306+ if ( target . textfont ) {
307+ optsOut . textfont = convertTextfont ( trace , target . textfont ) ;
308+ }
309+
297310 return optsOut ;
298311}
299312
0 commit comments