@@ -2276,6 +2276,90 @@ describe('Test plot api', function() {
2276
2276
expect ( gd . layout . shapes [ 2 ] . yref ) . toEqual ( 'y' ) ;
2277
2277
2278
2278
} ) ;
2279
+
2280
+ it ( 'removes direction names and showlegend from finance traces' , function ( ) {
2281
+ var data = [ {
2282
+ type : 'ohlc' , open : [ 1 ] , high : [ 3 ] , low : [ 0 ] , close : [ 2 ] ,
2283
+ increasing : {
2284
+ showlegend : true ,
2285
+ name : 'Yeti goes up'
2286
+ } ,
2287
+ decreasing : {
2288
+ showlegend : 'legendonly' ,
2289
+ name : 'Yeti goes down'
2290
+ } ,
2291
+ name : 'Snowman'
2292
+ } , {
2293
+ type : 'candlestick' , open : [ 1 ] , high : [ 3 ] , low : [ 0 ] , close : [ 2 ] ,
2294
+ increasing : {
2295
+ name : 'Bigfoot'
2296
+ } ,
2297
+ decreasing : {
2298
+ showlegend : false ,
2299
+ name : 'Biggerfoot'
2300
+ } ,
2301
+ name : 'Nobody'
2302
+ } , {
2303
+ type : 'ohlc' , open : [ 1 ] , high : [ 3 ] , low : [ 0 ] , close : [ 2 ] ,
2304
+ increasing : {
2305
+ name : 'Batman'
2306
+ } ,
2307
+ decreasing : {
2308
+ showlegend : true
2309
+ } ,
2310
+ name : 'Robin'
2311
+ } , {
2312
+ type : 'candlestick' , open : [ 1 ] , high : [ 3 ] , low : [ 0 ] , close : [ 2 ] ,
2313
+ increasing : {
2314
+ showlegend : false ,
2315
+ } ,
2316
+ decreasing : {
2317
+ name : 'Fred'
2318
+ }
2319
+ } , {
2320
+ type : 'ohlc' , open : [ 1 ] , high : [ 3 ] , low : [ 0 ] , close : [ 2 ] ,
2321
+ increasing : {
2322
+ showlegend : false ,
2323
+ name : 'Gruyere heating up'
2324
+ } ,
2325
+ decreasing : {
2326
+ showlegend : false ,
2327
+ name : 'Gruyere cooling off'
2328
+ } ,
2329
+ name : 'Emmenthaler'
2330
+ } ] ;
2331
+
2332
+ Plotly . plot ( gd , data ) ;
2333
+
2334
+ // Even if both showlegends are false, leave trace.showlegend out
2335
+ // My rationale for this is that legends are sufficiently different
2336
+ // now that it's worthwhile resetting their existence to default
2337
+ gd . data . forEach ( function ( trace ) {
2338
+ expect ( trace . increasing . name ) . toBeUndefined ( ) ;
2339
+ expect ( trace . increasing . showlegend ) . toBeUndefined ( ) ;
2340
+ expect ( trace . decreasing . name ) . toBeUndefined ( ) ;
2341
+ expect ( trace . decreasing . showlegend ) . toBeUndefined ( ) ;
2342
+ } ) ;
2343
+
2344
+ // Both directions have names: ignore trace.name, as it
2345
+ // had no effect on the output previously
2346
+ // Ideally 'Yeti goes' would be smart enough to truncate
2347
+ // at 'Yeti' but I don't see how to do that...
2348
+ expect ( gd . data [ 0 ] . name ) . toBe ( 'Yeti goes' ) ;
2349
+ // One direction has empty or hidden name so use the other
2350
+ // Note that even '' in both names would render trace.name impact-less
2351
+ expect ( gd . data [ 1 ] . name ) . toBe ( 'Bigfoot' ) ;
2352
+
2353
+ // One direction has a name but trace.name is there too:
2354
+ // just use trace.name
2355
+ expect ( gd . data [ 2 ] . name ) . toBe ( 'Robin' ) ;
2356
+
2357
+ // No trace.name, only one direction name: use the direction name
2358
+ expect ( gd . data [ 3 ] . name ) . toBe ( 'Fred' ) ;
2359
+
2360
+ // both names exist but hidden from the legend: still look for common prefix
2361
+ expect ( gd . data [ 4 ] . name ) . toBe ( 'Gruyere' ) ;
2362
+ } ) ;
2279
2363
} ) ;
2280
2364
2281
2365
describe ( 'Plotly.newPlot' , function ( ) {
0 commit comments