@@ -259,14 +259,15 @@ function annotationTest(gd, layout, x0, y0, ax, ay, xref, yref, axref, ayref,
259
259
}
260
260
261
261
// axid is e.g., 'x', 'y2' etc.
262
- function logAxisIfAxType ( layoutIn , layoutOut , axid , axtype ) {
262
+ // if nologrange is true, log of range is not taken
263
+ function logAxisIfAxType ( layoutIn , layoutOut , axid , axtype , nologrange ) {
263
264
var axname = axisIds . id2name ( axid ) ;
264
265
if ( ( axtype === 'log' ) && ( axid !== undefined ) ) {
265
266
var axis = {
266
267
...layoutIn [ axname ]
267
268
} ;
268
269
axis . type = 'log' ;
269
- axis . range = axis . range . map ( Math . log10 ) ;
270
+ axis . range = nologrange ? axis . range : axis . range . map ( Math . log10 ) ;
270
271
layoutOut [ axname ] = axis ;
271
272
}
272
273
}
@@ -398,11 +399,8 @@ function findImage(id) {
398
399
return ret ;
399
400
}
400
401
401
- function checkImage ( layout , imageObj , imageBBox ) { }
402
-
403
402
function imageTest ( gd , layout , xaxtype , yaxtype , x , y , sizex , sizey , xanchor ,
404
403
yanchor , xref , yref , xid , yid ) {
405
- console . log ( 'running imageTest on ' , gd ) ;
406
404
var image = {
407
405
x : x ,
408
406
y : y ,
@@ -420,18 +418,15 @@ function imageTest(gd, layout, xaxtype, yaxtype, x, y, sizex, sizey, xanchor,
420
418
var ret ;
421
419
// we pass xid, yid because we possibly want to change some axes to log,
422
420
// even if we refer to paper in the end
423
- logAxisIfAxType ( gd . layout , layout , xid , xaxtype ) ;
424
- logAxisIfAxType ( gd . layout , layout , yid , yaxtype ) ;
421
+ logAxisIfAxType ( gd . layout , layout , xid , xaxtype , true ) ;
422
+ logAxisIfAxType ( gd . layout , layout , yid , yaxtype , true ) ;
425
423
layout . images = [ image ] ;
426
424
return Plotly . relayout ( gd , layout )
427
425
. then ( function ( gd ) {
428
426
var imageElem = findImage ( "#" + gd . id ) ;
429
427
var svgImageBBox = getSVGElemScreenBBox ( imageElem ) ;
430
428
var imageBBox = imageToBBox ( gd . layout , image ) ;
431
429
ret = compareBBoxes ( svgImageBBox , imageBBox ) ;
432
- //if (!ret) {
433
- // throw 'test failed';
434
- //}
435
430
return ret ;
436
431
} ) ;
437
432
}
@@ -602,7 +597,7 @@ function runComboTests(productItems, testCombo, start_stop, filter, keep_graph_d
602
597
var tc = testCombos . map ( c => testCombo ( c , keep_graph_div ) ) . reduce ( ( a , v ) => a . then ( v ) ) ;
603
598
}
604
599
605
- function testImageCombo ( combo , keep_graph_div ) {
600
+ function describeImageComboTest ( combo ) {
606
601
var axistypex = combo [ 0 ] ;
607
602
var axistypey = combo [ 1 ] ;
608
603
var axispair = combo [ 2 ] ;
@@ -615,48 +610,47 @@ function testImageCombo(combo, keep_graph_div) {
615
610
var yid = axispair [ 1 ] ;
616
611
var xref = makeAxRef ( xid , aroposx . ref ) ;
617
612
var yref = makeAxRef ( yid , aroposy . ref ) ;
618
- if ( DEBUG ) {
619
- console . log ( combo ) ;
620
- }
621
- return new Promise ( function ( resolve ) {
622
- var gd = createGraphDiv ( gd_id ) ;
623
- resolve ( gd ) ;
624
- } ) . then ( function ( gd ) {
625
- return Plotly . newPlot ( gd , testMock ) ;
626
- } )
613
+ // TODO Add image combo test description
614
+ return [
615
+ "layout image with graph ID" ,
616
+ gd_id ,
617
+ "with parameters:" ,
618
+ "x-axis type:" , axistypex , "\n" ,
619
+ "y-axis type:" , axistypey , "\n" ,
620
+ "axis pair:" , axispair , "\n" ,
621
+ "ARO position x:" , aroposx , "\n" ,
622
+ "ARO position y:" , aroposy , "\n" ,
623
+ "xanchor:" , xanchor , "\n" ,
624
+ "yanchor:" , yanchor , "\n" ,
625
+ "xref:" , xref , "\n" ,
626
+ "yref:" , yref , "\n" ,
627
+ ] . join ( ' ' ) ;
628
+ }
629
+
630
+ function testImageCombo ( combo , assert , gd ) {
631
+ var axistypex = combo [ 0 ] ;
632
+ var axistypey = combo [ 1 ] ;
633
+ var axispair = combo [ 2 ] ;
634
+ var aroposx = combo [ 3 ] ;
635
+ var aroposy = combo [ 4 ] ;
636
+ var xanchor = combo [ 5 ] ;
637
+ var yanchor = combo [ 6 ] ;
638
+ var gd_id = combo [ 7 ] ;
639
+ var xid = axispair [ 0 ] ;
640
+ var yid = axispair [ 1 ] ;
641
+ var xref = makeAxRef ( xid , aroposx . ref ) ;
642
+ var yref = makeAxRef ( yid , aroposy . ref ) ;
643
+ return Plotly . newPlot ( gd , testMock )
627
644
. then ( function ( gd ) {
628
645
return imageTest ( gd , { } , axistypex , axistypey ,
629
646
aroposx . value [ 0 ] , aroposy . value [ 0 ] , aroposx . size ,
630
647
aroposy . size ,
631
648
xanchor , yanchor , xref , yref , xid , yid ) ;
632
649
} ) . then ( function ( test_ret ) {
633
- console . log ( [
634
- "Testing layout image with parameters:" ,
635
- "x-axis type:" , axistypex , "\n" ,
636
- "y-axis type:" , axistypey , "\n" ,
637
- "xanchor:" , xanchor , "\n" ,
638
- "yanchor:" , yanchor , "\n" ,
639
- "xref:" , xref , "\n" ,
640
- "yref:" , yref , "\n" ,
641
- ] . join ( ' ' ) , test_ret ) ;
642
- } ) . then ( function ( ) {
643
- if ( ! keep_graph_div ) {
644
- console . log ( 'destroying graph div ' , gd_id ) ;
645
- Plotly . purge ( gd_id ) ;
646
- destroyGraphDiv ( gd_id ) ;
647
- }
650
+ assert ( test_ret ) ;
648
651
} ) ;
649
652
}
650
653
651
- function runImageTests ( start_stop , filter ) {
652
- runComboTests ( [
653
- axisTypes , axisTypes , axisPairs ,
654
- // axis reference types are contained in here
655
- aroPositionsX , aroPositionsY ,
656
- xAnchors , yAnchors
657
- ] , testImageCombo , start_stop , filter ) ;
658
- }
659
-
660
654
function describeAnnotationComboTest ( combo ) {
661
655
var axistypex = combo [ 0 ] ;
662
656
var axistypey = combo [ 1 ] ;
@@ -708,7 +702,7 @@ function testAnnotationCombo(combo, assert, gd) {
708
702
ayref , axistypex , axistypey , xid , yid ) ;
709
703
} ) . then ( function ( test_ret ) {
710
704
assert ( test_ret ) ;
711
- } )
705
+ } ) ;
712
706
}
713
707
714
708
// return a list of functions, each returning a promise that executes a
@@ -755,12 +749,40 @@ function annotationTestDescriptions() {
755
749
return comboTestDescriptions ( testCombos , describeAnnotationComboTest ) ;
756
750
}
757
751
752
+
753
+ function imageTestCombos ( ) {
754
+ var testCombos = [ ...iterable . cartesianProduct (
755
+ [
756
+ axisTypes , axisTypes , axisPairs ,
757
+ // axis reference types are contained in here
758
+ aroPositionsX , aroPositionsY ,
759
+ xAnchors , yAnchors
760
+ ]
761
+ ) ] ;
762
+ testCombos = testCombos . map ( ( c , i ) => c . concat ( [ 'graph-' + i ] ) ) ;
763
+ return testCombos ;
764
+ }
765
+
766
+ function imageTests ( ) {
767
+ var testCombos = imageTestCombos ( ) ;
768
+ return comboTests ( testCombos , testImageCombo ) ;
769
+ }
770
+
771
+ function imageTestDescriptions ( ) {
772
+ var testCombos = imageTestCombos ( ) ;
773
+ return comboTestDescriptions ( testCombos , describeImageComboTest ) ;
774
+ }
775
+
758
776
module . exports = {
759
777
// tests
760
778
annotations : {
761
779
descriptions : annotationTestDescriptions ,
762
780
tests : annotationTests ,
763
781
} ,
782
+ images : {
783
+ descriptions : imageTestDescriptions ,
784
+ tests : imageTests ,
785
+ } ,
764
786
// utilities
765
787
findAROByColor : findAROByColor
766
788
} ;
0 commit comments