@@ -12,6 +12,7 @@ var failTest = require('../assets/fail_test');
12
12
var customAssertions = require ( '../assets/custom_assertions' ) ;
13
13
var assertHoverLabelContent = customAssertions . assertHoverLabelContent ;
14
14
var Fx = require ( '@src/components/fx' ) ;
15
+ var mouseEvent = require ( '../assets/mouse_event' ) ;
15
16
16
17
describe ( 'image supplyDefaults' , function ( ) {
17
18
'use strict' ;
@@ -55,6 +56,28 @@ describe('image supplyDefaults', function() {
55
56
traceOut = Plots . supplyTraceDefaults ( traceIn , { type : 'image' } , 0 , layout ) ;
56
57
expect ( traceOut . visible ) . toBe ( true ) ;
57
58
} ) ;
59
+
60
+ it ( 'should set proper zmin/zmax depending on colormodel' , function ( ) {
61
+ var tests = [
62
+ [ 'rgb' , [ 0 , 0 , 0 ] , [ 255 , 255 , 255 ] ] ,
63
+ [ 'rgba' , [ 0 , 0 , 0 , 0 ] , [ 255 , 255 , 255 , 1 ] ] ,
64
+ [ 'hsl' , [ 0 , 0 , 0 ] , [ 360 , 100 , 100 ] ] ,
65
+ [ 'hsla' , [ 0 , 0 , 0 , 0 ] , [ 360 , 100 , 100 , 1 ] ]
66
+ ] ;
67
+
68
+ expect ( tests . map ( function ( t ) { return t [ 0 ] ; } ) ) . toEqual ( Image . attributes . colormodel . values , 'zmin/zmax test coverage' ) ;
69
+
70
+ tests . forEach ( function ( test ) {
71
+ traceIn = {
72
+ z : [ [ [ 1 , 1 , 1 , 1 ] ] ] ,
73
+ colormodel : test [ 0 ]
74
+ } ;
75
+ supplyDefaults ( traceIn , traceOut ) ;
76
+ expect ( traceOut . zmin ) . toEqual ( test [ 1 ] , 'default zmin for ' + test [ 0 ] ) ;
77
+ expect ( traceOut . zmax ) . toEqual ( test [ 2 ] , 'default zmax for ' + test [ 0 ] ) ;
78
+ supplyDefaults ( traceIn , traceOut ) ;
79
+ } ) ;
80
+ } ) ;
58
81
} ) ;
59
82
//
60
83
// describe('image calc', function() {
@@ -218,7 +241,7 @@ describe('image plot', function() {
218
241
} ) ;
219
242
} ) ;
220
243
221
- describe ( 'image hover' , function ( ) {
244
+ describe ( 'image hover: ' , function ( ) {
222
245
'use strict' ;
223
246
224
247
var gd ;
@@ -302,7 +325,37 @@ describe('image hover', function() {
302
325
. then ( function ( ) { _hover ( 255 , 295 ) ; } )
303
326
. then ( function ( ) {
304
327
assertHoverLabelContent ( {
305
- nums : 'z: [128, 77, 54, 254]\n<tspan style="text-transform:uppercase">rgba</tspan>: [128, 77, 54, 254]' ,
328
+ nums : 'z: [128, 77, 54, 254]\n<tspan style="text-transform:uppercase">rgba</tspan>: [128, 77, 54, 1]' ,
329
+ name : 'trace 0'
330
+ } ) ;
331
+ } )
332
+ . catch ( failTest )
333
+ . then ( done ) ;
334
+ } ) ;
335
+
336
+ it ( 'should display HSL channel values' , function ( done ) {
337
+ var mockCopy = Lib . extendDeep ( { } , mock ) ;
338
+ mockCopy . data [ 0 ] . colormodel = 'hsl' ;
339
+ Plotly . newPlot ( gd , mockCopy )
340
+ . then ( function ( ) { _hover ( 255 , 295 ) ; } )
341
+ . then ( function ( ) {
342
+ assertHoverLabelContent ( {
343
+ nums : 'z: [128, 77, 54]\n<tspan style="text-transform:uppercase">hsl</tspan>: [128°, 77%, 54%]' ,
344
+ name : 'trace 0'
345
+ } ) ;
346
+ } )
347
+ . catch ( failTest )
348
+ . then ( done ) ;
349
+ } ) ;
350
+
351
+ it ( 'should display HSLA channel values' , function ( done ) {
352
+ var mockCopy = Lib . extendDeep ( { } , mock ) ;
353
+ mockCopy . data [ 0 ] . colormodel = 'hsla' ;
354
+ Plotly . newPlot ( gd , mockCopy )
355
+ . then ( function ( ) { _hover ( 255 , 295 ) ; } )
356
+ . then ( function ( ) {
357
+ assertHoverLabelContent ( {
358
+ nums : 'z: [128, 77, 54, 254]\n<tspan style="text-transform:uppercase">hsla</tspan>: [128°, 77%, 54%, 1]' ,
306
359
name : 'trace 0'
307
360
} ) ;
308
361
} )
@@ -311,3 +364,136 @@ describe('image hover', function() {
311
364
} ) ;
312
365
} ) ;
313
366
} ) ;
367
+
368
+ // describe('image hover/click event data:', function() {
369
+ // var gd;
370
+ // var mock = require('@mocks/image_adventurer.json');
371
+ //
372
+ // beforeEach(function() {
373
+ // gd = createGraphDiv();
374
+ // });
375
+ //
376
+ // afterEach(destroyGraphDiv);
377
+ //
378
+ // function _makeWrapper(eventType, mouseFn) {
379
+ // var posByElementType = {
380
+ // node: [404, 302],
381
+ // link: [450, 300]
382
+ // };
383
+ //
384
+ // return function(elType) {
385
+ // return new Promise(function(resolve, reject) {
386
+ // gd.once(eventType, function(d) {
387
+ // Lib.clearThrottle();
388
+ // resolve(d);
389
+ // });
390
+ //
391
+ // mouseFn(posByElementType[elType]);
392
+ // setTimeout(function() {
393
+ // reject(eventType + ' did not get called!');
394
+ // }, 100);
395
+ // });
396
+ // };
397
+ // }
398
+ //
399
+ // var _hover = _makeWrapper('plotly_hover', function(pos) {
400
+ // mouseEvent('mouseover', pos[0], pos[1]);
401
+ // });
402
+ //
403
+ // var _click = _makeWrapper('plotly_click', function(pos) {
404
+ // mouseEvent('click', pos[0], pos[1]);
405
+ // });
406
+ //
407
+ // var _unhover = _makeWrapper('plotly_unhover', function(pos) {
408
+ // mouseEvent('mouseover', pos[0], pos[1]);
409
+ // mouseEvent('mouseout', pos[0], pos[1]);
410
+ // });
411
+ //
412
+ // function _assert(d, expectedPtData) {
413
+ // expect(d.event).toBeDefined('original event reference');
414
+ //
415
+ // var ptData = d.points[0];
416
+ // Object.keys(expectedPtData).forEach(function(k) {
417
+ // expect(ptData[k]).toBe(expectedPtData[k], 'point data for ' + k);
418
+ // });
419
+ // }
420
+ //
421
+ // it('should output correct click event data', function(done) {
422
+ // var fig = Lib.extendDeep({}, mock);
423
+ //
424
+ // Plotly.plot(gd, fig)
425
+ // .then(function() { return _click('node'); })
426
+ // .then(function(d) {
427
+ // _assert(d, {
428
+ // curveNumber: 0,
429
+ // pointNumber: 4,
430
+ // label: 'Solid'
431
+ // });
432
+ // })
433
+ // .catch(failTest)
434
+ // .then(done);
435
+ // });
436
+ //
437
+ // it('should output correct hover/unhover event data', function(done) {
438
+ // var fig = Lib.extendDeep({}, mock);
439
+ //
440
+ // Plotly.plot(gd, fig)
441
+ // .then(function() { return Plotly.restyle(gd, 'hoverinfo', 'none'); })
442
+ // .then(function() { return _hover('node'); })
443
+ // .then(function(d) {
444
+ // _assert(d, {
445
+ // curveNumber: 0,
446
+ // pointNumber: 4,
447
+ // label: 'Solid',
448
+ // value: 447.48
449
+ // });
450
+ // var pt = d.points[0];
451
+ // expect(pt.sourceLinks.length).toBe(3);
452
+ // expect(pt.targetLinks.length).toBe(4);
453
+ // })
454
+ // .then(function() { return _unhover('node'); })
455
+ // .then(function(d) {
456
+ // _assert(d, {
457
+ // curveNumber: 0,
458
+ // pointNumber: 4,
459
+ // label: 'Solid'
460
+ // });
461
+ // })
462
+ // .catch(failTest)
463
+ // .then(done);
464
+ // });
465
+ //
466
+ // function assertNoHoverEvents(type) {
467
+ // return function() {
468
+ // return Promise.resolve()
469
+ // .then(function() { return _hover(type); })
470
+ // .then(failTest).catch(function(err) {
471
+ // expect(err).toBe('plotly_hover did not get called!');
472
+ // })
473
+ // .then(function() { return _unhover(type); })
474
+ // .then(failTest).catch(function(err) {
475
+ // expect(err).toBe('plotly_unhover did not get called!');
476
+ // });
477
+ // };
478
+ // }
479
+ //
480
+ // it('should not output hover/unhover event data when hovermode is false', function(done) {
481
+ // var fig = Lib.extendDeep({}, mock);
482
+ //
483
+ // Plotly.plot(gd, fig)
484
+ // .then(function() { return Plotly.relayout(gd, 'hovermode', false); })
485
+ // .then(assertNoHoverEvents('node'))
486
+ // .catch(failTest)
487
+ // .then(done);
488
+ // });
489
+ //
490
+ // it('should not output hover/unhover event data when trace hoverinfo is skip', function(done) {
491
+ // var fig = Lib.extendDeep({}, mock);
492
+ //
493
+ // Plotly.plot(gd, fig)
494
+ // .then(function() { return Plotly.restyle(gd, 'hoverinfo', 'skip'); })
495
+ // .then(assertNoHoverEvents('node'))
496
+ // .catch(failTest)
497
+ // .then(done);
498
+ // });
499
+ // });
0 commit comments