@@ -2124,10 +2124,6 @@ describe('Test lib.js:', function() {
2124
2124
expect ( Lib . templateString ( 'foo %{bar}' , { bar : 'baz' } ) ) . toEqual ( 'foo baz' ) ;
2125
2125
} ) ;
2126
2126
2127
- it ( 'evaluates attributes with a dot in their name' , function ( ) {
2128
- expect ( Lib . templateString ( '%{marker.size}' , { 'marker.size' : 12 } , { marker : { size : 14 } } ) ) . toEqual ( '12' ) ;
2129
- } ) ;
2130
-
2131
2127
it ( 'evaluates nested properties' , function ( ) {
2132
2128
expect ( Lib . templateString ( 'foo %{bar.baz}' , { bar : { baz : 'asdf' } } ) ) . toEqual ( 'foo asdf' ) ;
2133
2129
} ) ;
@@ -2147,24 +2143,54 @@ describe('Test lib.js:', function() {
2147
2143
it ( 'replaces empty key with empty string' , function ( ) {
2148
2144
expect ( Lib . templateString ( 'foo %{} %{}' , { } ) ) . toEqual ( 'foo ' ) ;
2149
2145
} ) ;
2146
+ } ) ;
2147
+
2148
+ describe ( 'hovertemplateString' , function ( ) {
2149
+ it ( 'evaluates attributes' , function ( ) {
2150
+ expect ( Lib . hovertemplateString ( 'foo %{bar}' , { } , { bar : 'baz' } ) ) . toEqual ( 'foo baz' ) ;
2151
+ } ) ;
2152
+
2153
+ it ( 'evaluates attributes with a dot in their name' , function ( ) {
2154
+ expect ( Lib . hovertemplateString ( '%{marker.size}' , { } , { 'marker.size' : 12 } , { marker : { size : 14 } } ) ) . toEqual ( '12' ) ;
2155
+ } ) ;
2156
+
2157
+ it ( 'evaluates nested properties' , function ( ) {
2158
+ expect ( Lib . hovertemplateString ( 'foo %{bar.baz}' , { } , { bar : { baz : 'asdf' } } ) ) . toEqual ( 'foo asdf' ) ;
2159
+ } ) ;
2160
+
2161
+ it ( 'evaluates array nested properties' , function ( ) {
2162
+ expect ( Lib . hovertemplateString ( 'foo %{bar[0].baz}' , { } , { bar : [ { baz : 'asdf' } ] } ) ) . toEqual ( 'foo asdf' ) ;
2163
+ } ) ;
2164
+
2165
+ it ( 'subtitutes multiple matches' , function ( ) {
2166
+ expect ( Lib . hovertemplateString ( 'foo %{group} %{trace}' , { } , { group : 'asdf' , trace : 'jkl;' } ) ) . toEqual ( 'foo asdf jkl;' ) ;
2167
+ } ) ;
2168
+
2169
+ it ( 'replaces missing matches with template string' , function ( ) {
2170
+ expect ( Lib . hovertemplateString ( 'foo %{group} %{trace}' , { } , { group : 1 } ) ) . toEqual ( 'foo 1 %{trace}' ) ;
2171
+ } ) ;
2150
2172
2151
2173
it ( 'uses the value from the first object with the specified key' , function ( ) {
2152
2174
var obj1 = { a : 'first' } , obj2 = { a : 'second' , foo : { bar : 'bar' } } ;
2153
2175
2154
2176
// Simple key
2155
- expect ( Lib . templateString ( 'foo %{a}' , obj1 , obj2 ) ) . toEqual ( 'foo first' ) ;
2156
- expect ( Lib . templateString ( 'foo %{a}' , obj2 , obj1 ) ) . toEqual ( 'foo second' ) ;
2177
+ expect ( Lib . hovertemplateString ( 'foo %{a}' , { } , obj1 , obj2 ) ) . toEqual ( 'foo first' ) ;
2178
+ expect ( Lib . hovertemplateString ( 'foo %{a}' , { } , obj2 , obj1 ) ) . toEqual ( 'foo second' ) ;
2157
2179
2158
2180
// Nested Keys
2159
- expect ( Lib . templateString ( 'foo %{foo.bar}' , obj1 , obj2 ) ) . toEqual ( 'foo bar' ) ;
2181
+ expect ( Lib . hovertemplateString ( 'foo %{foo.bar}' , { } , obj1 , obj2 ) ) . toEqual ( 'foo bar' ) ;
2160
2182
2161
2183
// Nested keys with 0
2162
- expect ( Lib . templateString ( 'y: %{y}' , { y : 0 } , { y : 1 } ) ) . toEqual ( 'y: 0' ) ;
2184
+ expect ( Lib . hovertemplateString ( 'y: %{y}' , { } , { y : 0 } , { y : 1 } ) ) . toEqual ( 'y: 0' ) ;
2163
2185
} ) ;
2164
2186
2165
2187
it ( 'formats value using d3 mini-language' , function ( ) {
2166
- expect ( Lib . templateString ( 'a: %{a:.0%}' , { a : 0.123 } ) ) . toEqual ( 'a: 12%' ) ;
2167
- expect ( Lib . templateString ( 'b: %{b:2.2f}' , { b : 43 } ) ) . toEqual ( 'b: 43.00' ) ;
2188
+ expect ( Lib . hovertemplateString ( 'a: %{a:.0%}' , { } , { a : 0.123 } ) ) . toEqual ( 'a: 12%' ) ;
2189
+ expect ( Lib . hovertemplateString ( 'b: %{b:2.2f}' , { } , { b : 43 } ) ) . toEqual ( 'b: 43.00' ) ;
2190
+ } ) ;
2191
+
2192
+ it ( 'looks for default label if no format is provided' , function ( ) {
2193
+ expect ( Lib . hovertemplateString ( 'y: %{y}' , { yLabel : '0.1' } , { y : 0.123 } ) ) . toEqual ( 'y: 0.1' ) ;
2168
2194
} ) ;
2169
2195
} ) ;
2170
2196
0 commit comments