@@ -1031,25 +1031,26 @@ var maximumNumberOfHoverTemplateWarnings = 10;
10311031 * or fallback to associated labels.
10321032 *
10331033 * Examples:
1034- * Lib.templateString ('name: %{trace}', {trace: 'asdf'}) --> 'name: asdf'
1035- * Lib.templateString ('name: %{trace[0].name}', {trace: [{name: 'asdf'}]}) --> 'name: asdf'
1036- * Lib.templateString ('price: %{y:$.2f}', {y: 1}) --> 'price: $1.00'
1034+ * Lib.hovertemplateString ('name: %{trace}', {trace: 'asdf'}) --> 'name: asdf'
1035+ * Lib.hovertemplateString ('name: %{trace[0].name}', {trace: [{name: 'asdf'}]}) --> 'name: asdf'
1036+ * Lib.hovertemplateString ('price: %{y:$.2f}', {y: 1}) --> 'price: $1.00'
10371037 *
1038+ * @param {obj } d3 locale
10381039 * @param {string } input string containing %{...:...} template strings
10391040 * @param {obj } data object containing fallback text when no formatting is specified, ex.: {yLabel: 'formattedYValue'}
10401041 * @param {obj } data objects containing substitution values
10411042 *
10421043 * @return {string } templated string
10431044 */
1044- lib . hovertemplateString = function ( string , labels ) {
1045+ lib . hovertemplateString = function ( string , labels , d3locale ) {
10451046 var args = arguments ;
10461047 // Not all that useful, but cache nestedProperty instantiation
10471048 // just in case it speeds things up *slightly*:
10481049 var getterCache = { } ;
10491050
10501051 return string . replace ( lib . TEMPLATE_STRING_REGEX , function ( match , key , format ) {
10511052 var obj , value , i ;
1052- for ( i = 2 ; i < args . length ; i ++ ) {
1053+ for ( i = 3 ; i < args . length ; i ++ ) {
10531054 obj = args [ i ] ;
10541055 if ( obj . hasOwnProperty ( key ) ) {
10551056 value = obj [ key ] ;
@@ -1076,7 +1077,13 @@ lib.hovertemplateString = function(string, labels) {
10761077 }
10771078
10781079 if ( format ) {
1079- value = d3 . format ( format . replace ( TEMPLATE_STRING_FORMAT_SEPARATOR , '' ) ) ( value ) ;
1080+ var fmt ;
1081+ if ( d3locale ) {
1082+ fmt = d3locale . numberFormat ;
1083+ } else {
1084+ fmt = d3 . format ;
1085+ }
1086+ value = fmt ( format . replace ( TEMPLATE_STRING_FORMAT_SEPARATOR , '' ) ) ( value ) ;
10801087 } else {
10811088 if ( labels . hasOwnProperty ( key + 'Label' ) ) value = labels [ key + 'Label' ] ;
10821089 }
0 commit comments