@@ -1112,22 +1112,22 @@ var TEMPLATE_STRING_FORMAT_SEPARATOR = /^[:|\|]/;
11121112 * or fallback to associated labels.
11131113 *
11141114 * Examples:
1115- * Lib.hovertemplateString ({ string 'name: %{trace}', labels: {trace: 'asdf'} }) --> 'name: asdf'
1116- * Lib.hovertemplateString ({ string : 'name: %{trace[0].name}', labels: { trace: [{ name: 'asdf' }] } }) --> 'name: asdf'
1117- * Lib.hovertemplateString ({ string : 'price: %{y:$.2f}', labels: { y: 1 } }) --> 'price: $1.00'
1115+ * Lib.templateFormatString ({ template 'name: %{trace}', labels: {trace: 'asdf'} }) --> 'name: asdf'
1116+ * Lib.templateFormatString ({ template : 'name: %{trace[0].name}', labels: { trace: [{ name: 'asdf' }] } }) --> 'name: asdf'
1117+ * Lib.templateFormatString ({ template : 'price: %{y:$.2f}', labels: { y: 1 } }) --> 'price: $1.00'
11181118 *
11191119 * @param {object } options - Configuration object
1120- * @param {array } options.args - Data objects containing substitution values
1121- * @param {object } options.d3locale - D3 locale for formatting
1120+ * @param {array } options.data - Data objects containing substitution values
11221121 * @param {string } options.fallback - Fallback value when substitution fails
11231122 * @param {object } options.labels - Data object containing fallback text when no formatting is specified, ex.: {yLabel: 'formattedYValue'}
1123+ * @param {object } options.locale - D3 locale for formatting
11241124 * @param {object } options.opts - Additional options
1125- * @param {string } options.string - Input string containing %{...:...} template strings
1125+ * @param {string } options.template - Input string containing %{...:...} template strings
11261126 *
11271127 * @return {string } templated string
11281128 */
1129- function templateFormatString ( { args = [ ] , d3locale , fallback, labels = { } , opts, string } ) {
1130- return string . replace ( lib . TEMPLATE_STRING_REGEX , ( _ , rawKey , format ) => {
1129+ function templateFormatString ( { data = [ ] , locale , fallback, labels = { } , opts, template } ) {
1130+ return template . replace ( lib . TEMPLATE_STRING_REGEX , ( _ , rawKey , format ) => {
11311131 const isOther = [ 'xother' , 'yother' ] . includes ( rawKey ) ;
11321132 const isSpaceOther = [ '_xother' , '_yother' ] . includes ( rawKey ) ;
11331133 const isSpaceOtherSpace = [ '_xother_' , '_yother_' ] . includes ( rawKey ) ;
@@ -1154,7 +1154,7 @@ function templateFormatString({ args = [], d3locale, fallback, labels = {}, opts
11541154 if ( labels [ key ] === undefined ) return '' ;
11551155 value = labels [ key ] ;
11561156 } else {
1157- for ( const obj of args ) {
1157+ for ( const obj of data ) {
11581158 if ( ! obj ) continue ;
11591159 if ( obj . hasOwnProperty ( key ) ) {
11601160 value = obj [ key ] ;
@@ -1184,15 +1184,15 @@ function templateFormatString({ args = [], d3locale, fallback, labels = {}, opts
11841184 if ( format ) {
11851185 var fmt ;
11861186 if ( format [ 0 ] === ':' ) {
1187- fmt = d3locale ? d3locale . numberFormat : lib . numberFormat ;
1187+ fmt = locale ? locale . numberFormat : lib . numberFormat ;
11881188 if ( value !== '' ) {
11891189 // e.g. skip missing data on heatmap
11901190 value = fmt ( format . replace ( TEMPLATE_STRING_FORMAT_SEPARATOR , '' ) ) ( value ) ;
11911191 }
11921192 }
11931193
11941194 if ( format [ 0 ] === '|' ) {
1195- fmt = d3locale ? d3locale . timeFormat : utcFormat ;
1195+ fmt = locale ? locale . timeFormat : utcFormat ;
11961196 var ms = lib . dateTime2ms ( value ) ;
11971197 value = lib . formatDate ( ms , format . replace ( TEMPLATE_STRING_FORMAT_SEPARATOR , '' ) , false , fmt ) ;
11981198 }
0 commit comments