@@ -23,18 +23,21 @@ function templateFormatStringDescription(opts) {
23
23
] . join ( ' ' ) ;
24
24
}
25
25
26
- function templateFormatStringDescriptionForShapes ( ) {
26
+ function shapeTemplateFormatStringDescription ( ) {
27
27
return [
28
28
'Variables are inserted using %{variable},' ,
29
29
'for example "x0: %{x0}".' ,
30
30
'Numbers are formatted using d3-format\'s syntax %{variable:d3-format}, for example "Price: %{x0:$.2f}".' ,
31
31
FORMAT_LINK ,
32
32
'for details on the formatting syntax.' ,
33
- 'A single multiplication or division operation may be applied to the variable, and combined with' ,
34
- 'd3 number formatting, for example "Length in cm: %{x0*2.54}", "%{slope*60:.1f} meters per second."'
33
+ 'Dates are formatted using d3-time-format\'s syntax %{variable|d3-time-format}, for example "Day: %{2019-01-01|%A}".' ,
34
+ DATE_FORMAT_LINK ,
35
+ 'A single multiplication or division operation may be applied to numeric variables, and combined with' ,
36
+ 'd3 number formatting, for example "Length in cm: %{x0*2.54}", "%{slope*60:.1f} meters per second."' ,
37
+ 'For log axes, variable values are given in log units.' ,
38
+ 'For date axes, x/y coordinate variables and center variables use datetimes, while all other variable values use values in ms.' ,
35
39
] . join ( ' ' ) ;
36
40
}
37
- exports . templateFormatStringDescriptionForShapes = templateFormatStringDescriptionForShapes ;
38
41
39
42
function describeVariables ( extra ) {
40
43
var descPart = extra . description ? ' ' + extra . description : '' ;
@@ -46,14 +49,13 @@ function describeVariables(extra) {
46
49
}
47
50
descPart = descPart + 'Finally, the template string has access to ' ;
48
51
if ( keys . length === 1 ) {
49
- descPart = 'variable ' + quotedKeys [ 0 ] ;
52
+ descPart = descPart + 'variable ' + quotedKeys [ 0 ] ;
50
53
} else {
51
- descPart = 'variables ' + quotedKeys . slice ( 0 , - 1 ) . join ( ', ' ) + ' and ' + quotedKeys . slice ( - 1 ) + '.' ;
54
+ descPart = descPart + 'variables ' + quotedKeys . slice ( 0 , - 1 ) . join ( ', ' ) + ' and ' + quotedKeys . slice ( - 1 ) + '.' ;
52
55
}
53
56
}
54
57
return descPart ;
55
58
}
56
- exports . describeVariables = describeVariables ;
57
59
58
60
exports . hovertemplateAttrs = function ( opts , extra ) {
59
61
opts = opts || { } ;
@@ -108,3 +110,30 @@ exports.texttemplateAttrs = function(opts, extra) {
108
110
}
109
111
return texttemplate ;
110
112
} ;
113
+
114
+
115
+ exports . shapeTexttemplateAttrs = function ( opts , extra ) {
116
+ opts = opts || { } ;
117
+ extra = extra || { } ;
118
+
119
+ var newStr = opts . newshape ? 'new ' : '' ;
120
+
121
+ var descPart = describeVariables ( extra ) ;
122
+
123
+ var texttemplate = {
124
+ valType : 'string' ,
125
+ dflt : '' ,
126
+ editType : opts . editType || 'arraydraw' ,
127
+ description : [
128
+ 'Template string used for rendering the ' + newStr + 'shape\'s label.' ,
129
+ 'Note that this will override `text`.' ,
130
+ shapeTemplateFormatStringDescription ( ) ,
131
+ descPart ,
132
+ ] . join ( ' ' )
133
+ } ;
134
+
135
+ if ( opts . arrayOk !== false ) {
136
+ texttemplate . arrayOk = true ;
137
+ }
138
+ return texttemplate ;
139
+ } ;
0 commit comments