@@ -20,6 +20,7 @@ var Color = require('../color');
20
20
var svgTextUtils = require ( '../../lib/svg_text_utils' ) ;
21
21
var interactConstants = require ( '../../constants/interactions' ) ;
22
22
23
+ var PLACEHOLDER_RE = / C l i c k t o e n t e r .+ t i t l e / ;
23
24
24
25
var Titles = module . exports = { } ;
25
26
@@ -52,29 +53,34 @@ var Titles = module.exports = {};
52
53
* title, include here. Otherwise it will go in fullLayout._infolayer
53
54
*/
54
55
Titles . draw = function ( gd , titleClass , options ) {
55
- var cont = options . propContainer ,
56
- prop = options . propName ,
57
- traceIndex = options . traceIndex ,
58
- name = options . dfltName ,
59
- avoid = options . avoid || { } ,
60
- attributes = options . attributes ,
61
- transform = options . transform ,
62
- group = options . containerGroup ,
63
-
64
- fullLayout = gd . _fullLayout ,
65
- font = cont . titlefont . family ,
66
- fontSize = cont . titlefont . size ,
67
- fontColor = cont . titlefont . color ,
68
-
69
- opacity = 1 ,
70
- isplaceholder = false ,
71
- txt = cont . title . trim ( ) ;
56
+ var cont = options . propContainer ;
57
+ var prop = options . propName ;
58
+ var traceIndex = options . traceIndex ;
59
+ var name = options . dfltName ;
60
+ var avoid = options . avoid || { } ;
61
+ var attributes = options . attributes ;
62
+ var transform = options . transform ;
63
+ var group = options . containerGroup ;
64
+
65
+ var fullLayout = gd . _fullLayout ;
66
+ var font = cont . titlefont . family ;
67
+ var fontSize = cont . titlefont . size ;
68
+ var fontColor = cont . titlefont . color ;
69
+
70
+ var opacity = 1 ;
71
+ var isplaceholder = false ;
72
+ var txt = cont . title . trim ( ) ;
73
+ var editable = gd . _context . editable ;
74
+
72
75
if ( txt === '' ) opacity = 0 ;
73
- if ( txt . match ( / C l i c k t o e n t e r . + t i t l e / ) ) {
76
+ if ( txt . match ( PLACEHOLDER_RE ) ) {
74
77
opacity = 0.2 ;
75
78
isplaceholder = true ;
79
+ if ( ! editable ) txt = '' ;
76
80
}
77
81
82
+ var elShouldExist = txt || editable ;
83
+
78
84
if ( ! group ) {
79
85
group = fullLayout . _infolayer . selectAll ( '.g-' + titleClass )
80
86
. data ( [ 0 ] ) ;
@@ -83,7 +89,7 @@ Titles.draw = function(gd, titleClass, options) {
83
89
}
84
90
85
91
var el = group . selectAll ( 'text' )
86
- . data ( [ 0 ] ) ;
92
+ . data ( elShouldExist ? [ 0 ] : [ ] ) ;
87
93
el . enter ( ) . append ( 'text' ) ;
88
94
el . text ( txt )
89
95
// this is hacky, but convertToTspans uses the class
@@ -92,6 +98,9 @@ Titles.draw = function(gd, titleClass, options) {
92
98
// correct one (only relevant for colorbars, at least
93
99
// for now) - ie don't use .classed
94
100
. attr ( 'class' , titleClass ) ;
101
+ el . exit ( ) . remove ( ) ;
102
+
103
+ if ( ! elShouldExist ) return ;
95
104
96
105
function titleLayout ( titleEl ) {
97
106
Lib . syncOrAsync ( [ drawTitle , scootTitle ] , titleEl ) ;
@@ -205,7 +214,7 @@ Titles.draw = function(gd, titleClass, options) {
205
214
} ) ;
206
215
}
207
216
208
- if ( gd . _context . editable ) {
217
+ if ( editable ) {
209
218
if ( ! txt ) setPlaceholder ( ) ;
210
219
else el . on ( '.opacity' , null ) ;
211
220
@@ -224,8 +233,5 @@ Titles.draw = function(gd, titleClass, options) {
224
233
. attr ( attributes ) ;
225
234
} ) ;
226
235
}
227
- else if ( ! txt || txt . match ( / C l i c k t o e n t e r .+ t i t l e / ) ) {
228
- el . remove ( ) ;
229
- }
230
236
el . classed ( 'js-placeholder' , isplaceholder ) ;
231
237
} ;
0 commit comments