@@ -23,18 +23,21 @@ function templateFormatStringDescription(opts) {
2323 ] . join ( ' ' ) ;
2424}
2525
26- function templateFormatStringDescriptionForShapes ( ) {
26+ function shapeTemplateFormatStringDescription ( ) {
2727 return [
2828 'Variables are inserted using %{variable},' ,
2929 'for example "x0: %{x0}".' ,
3030 'Numbers are formatted using d3-format\'s syntax %{variable:d3-format}, for example "Price: %{x0:$.2f}".' ,
3131 FORMAT_LINK ,
3232 '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.' ,
3539 ] . join ( ' ' ) ;
3640}
37- exports . templateFormatStringDescriptionForShapes = templateFormatStringDescriptionForShapes ;
3841
3942function describeVariables ( extra ) {
4043 var descPart = extra . description ? ' ' + extra . description : '' ;
@@ -46,14 +49,13 @@ function describeVariables(extra) {
4649 }
4750 descPart = descPart + 'Finally, the template string has access to ' ;
4851 if ( keys . length === 1 ) {
49- descPart = 'variable ' + quotedKeys [ 0 ] ;
52+ descPart = descPart + 'variable ' + quotedKeys [ 0 ] ;
5053 } 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 ) + '.' ;
5255 }
5356 }
5457 return descPart ;
5558}
56- exports . describeVariables = describeVariables ;
5759
5860exports . hovertemplateAttrs = function ( opts , extra ) {
5961 opts = opts || { } ;
@@ -108,3 +110,30 @@ exports.texttemplateAttrs = function(opts, extra) {
108110 }
109111 return texttemplate ;
110112} ;
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