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