@@ -17,15 +17,46 @@ var destroyGraphDiv = require('../../assets/destroy_graph_div');
17
17
var pixelCalc = require ( '../../assets/pixel_calc' ) ;
18
18
var getSVGElemScreenBBox = require (
19
19
'../../assets/get_svg_elem_screen_bbox' ) ;
20
+ var SVGTools = require (
21
+ '../../assets/svg_tools' ) ;
20
22
var Lib = require ( '../../../../src/lib' ) ;
21
23
var Axes = require ( '../../../../src/plots/cartesian/axes' ) ;
22
24
var axisIds = require ( '../../../../src/plots/cartesian/axis_ids' ) ;
23
25
var testImage = 'https://images.plot.ly/language-icons/api-home/js-logo.png' ;
24
26
var iterable = require ( 'extra-iterable' ) ;
25
27
var delay = require ( '../../assets/delay' ) ;
26
28
27
- var testMock = Lib . extendDeep ( { } ,
28
- require ( '../../../image/mocks/domain_ref_base.json' ) ) ;
29
+ var testMock = require ( '../../../image/mocks/domain_ref_base.json' ) ;
30
+
31
+ var defaultLayout = {
32
+ "xaxis" : {
33
+ "domain" : [ 0 , 0.75 ] ,
34
+ "range" : [ 1 , 3 ]
35
+ } ,
36
+ "yaxis" : {
37
+ "domain" : [ 0 , 0.4 ] ,
38
+ "range" : [ 1 , 4 ]
39
+ } ,
40
+ "xaxis2" : {
41
+ "domain" : [ 0.75 , 1 ] ,
42
+ "range" : [ 1 , 4 ] ,
43
+ "anchor" : "y2"
44
+ } ,
45
+ "yaxis2" : {
46
+ "domain" : [ 0.4 , 1 ] ,
47
+ "range" : [ 1 , 3 ] ,
48
+ "anchor" : "x2"
49
+ } ,
50
+ "margin" : {
51
+ "l" : 100 ,
52
+ "r" : 100 ,
53
+ "t" : 100 ,
54
+ "b" : 100 ,
55
+ "autoexpand" : false
56
+ } ,
57
+ "width" : 400 ,
58
+ "height" : 400
59
+ } ;
29
60
30
61
// NOTE: this tolerance is in pixels
31
62
var EQUALITY_TOLERANCE = 1e-2 ;
@@ -373,7 +404,10 @@ function imageToBBox(layout, img) {
373
404
374
405
375
406
function coordsEq ( a , b ) {
376
- return Math . abs ( a - b ) < EQUALITY_TOLERANCE ;
407
+ if ( a && b ) {
408
+ return Math . abs ( a - b ) < EQUALITY_TOLERANCE ;
409
+ }
410
+ return false ;
377
411
}
378
412
379
413
function compareBBoxes ( a , b ) {
@@ -438,6 +472,8 @@ function checkAROPosition(gd, aro) {
438
472
var aroPathBBox = getSVGElemScreenBBox ( aroPath ) ;
439
473
var aroBBox = shapeToBBox ( gd . layout , aro ) ;
440
474
var ret = compareBBoxes ( aroBBox , aroPathBBox ) ;
475
+ console . log ( "aroBBox: " + JSON . stringify ( aroBBox ) )
476
+ console . log ( "aroPathBBox: " + JSON . stringify ( SVGTools . SVGRectToObj ( aroPathBBox ) ) )
441
477
return ret ;
442
478
}
443
479
@@ -535,6 +571,7 @@ function testShape(
535
571
yaroPos ,
536
572
aroType
537
573
) {
574
+ console . log ( 'gd.layout: ' , JSON . stringify ( gd . layout ) ) ;
538
575
var aro = {
539
576
type : aroType ,
540
577
line : {
@@ -549,6 +586,7 @@ function testShape(
549
586
// change to log axes if need be
550
587
logAxisIfAxType ( gd . layout , layout , 'x' + xAxNum , xaxisType ) ;
551
588
logAxisIfAxType ( gd . layout , layout , 'y' + yAxNum , yaxisType ) ;
589
+ console . log ( 'layout: ' , JSON . stringify ( layout ) ) ;
552
590
return Plotly . relayout ( gd , layout )
553
591
. then ( function ( gd ) {
554
592
return checkAROPosition ( gd , aro ) ;
@@ -562,15 +600,16 @@ function describeShapeComboTest(combo) {
562
600
var xaroPos = combo [ 3 ] ;
563
601
var yaroPos = combo [ 4 ] ;
564
602
var gd_id = combo [ 5 ] ;
603
+ var xid = axispair [ 0 ] ;
604
+ var yid = axispair [ 1 ] ;
565
605
return [
566
- "should create a plot with graph ID" ,
567
- gd_id ,
568
- " with parameters:" , "\n" ,
606
+ "#" , gd_id ,
607
+ "should create a plot with parameters:" , "\n" ,
569
608
"x-axis type:" , xaxisType , "\n" ,
570
609
"y-axis type:" , yaxisType , "\n" ,
571
- "axis pair:" , axispair , "\n" ,
572
- "ARO position x:" , xaroPos , "\n" ,
573
- "ARO position y:" , yaroPos , "\n" ,
610
+ "axis pair:" , xid , yid , "\n" ,
611
+ "ARO position x:" , JSON . stringify ( xaroPos ) , "\n" ,
612
+ "ARO position y:" , JSON . stringify ( yaroPos ) , "\n" ,
574
613
] . join ( ' ' ) ;
575
614
}
576
615
@@ -582,70 +621,14 @@ function testShapeCombo(combo, assert, gd) {
582
621
var yaroPos = combo [ 4 ] ;
583
622
var xAxNum = axispair [ 0 ] . substr ( 1 ) ;
584
623
var yAxNum = axispair [ 1 ] . substr ( 1 ) ;
585
- return Plotly . newPlot ( gd , testMock )
624
+ return Plotly . newPlot ( gd , Lib . extendDeep ( { } , testMock ) )
586
625
. then ( function ( gd ) {
587
- return testShape ( gd , xAxNum , xaxisType , xaroPos , yAxNum , yaxisType , yaroPos , 'shape' ) ;
626
+ return testShape ( gd , xAxNum , xaxisType , xaroPos , yAxNum , yaxisType , yaroPos , 'shape' ) ;
588
627
} ) . then ( function ( test_ret ) {
589
628
assert ( test_ret ) ;
590
629
} ) ;
591
630
}
592
631
593
- var testDomRefAROCombo = function ( combo ) {
594
- var xAxNum = combo [ 0 ] ;
595
- var xaxisType = combo [ 1 ] ;
596
- var xaroPos = combo [ 2 ] ;
597
- var yAxNum = combo [ 3 ] ;
598
- var yaxisType = combo [ 4 ] ;
599
- var yaroPos = combo [ 5 ] ;
600
- var aroType = combo [ 6 ] ;
601
- it ( 'should draw a ' + aroType +
602
- ' for x' + xAxNum + ' of type ' +
603
- xaxisType +
604
- ' with a value referencing ' +
605
- xaroPos . ref +
606
- ' and for y' + yAxNum + ' of type ' +
607
- yaxisType +
608
- ' with a value referencing ' +
609
- yaroPos . ref ,
610
- function ( done ) {
611
- var gd = createGraphDiv ( ) ;
612
- var mock = testMock ;
613
- if ( DEBUG ) {
614
- console . log ( combo ) ;
615
- }
616
- Plotly . newPlot ( gd , mock )
617
- var aro = {
618
- type : aroType ,
619
- line : {
620
- color : aroColor
621
- }
622
- } ;
623
- aroFromAROPos ( aro , 'x' , xAxNum , xaroPos ) ;
624
- aroFromAROPos ( aro , 'y' , yAxNum , yaroPos ) ;
625
- var layout = {
626
- shapes : [ aro ]
627
- } ;
628
- // change to log axes if need be
629
- logAxisIfAxType ( gd . layout , layout , 'x' + xAxNum , xaxisType ) ;
630
- logAxisIfAxType ( gd . layout , layout , 'y' + yAxNum , yaxisType ) ;
631
- Plotly . relayout ( gd , layout ) ;
632
- console . log ( checkAROPosition ( gd , aro ) ) ;
633
- destroyGraphDiv ( ) ;
634
- } ) ;
635
- }
636
-
637
- // Test correct aro positions
638
- function test_correct_aro_positions ( ) {
639
- // for both x and y axes
640
- var testCombos = [ ...iterable . cartesianProduct ( [
641
- axNum , axisTypes , aroPositionsX , axNum , axisTypes ,
642
- aroPositionsY , aroType
643
- ] ) ] ;
644
- // map all the combinations to a aro definition and check this aro is
645
- // placed properly
646
- testCombos . forEach ( testDomRefAROCombo ) ;
647
- }
648
-
649
632
function describeImageComboTest ( combo ) {
650
633
var axistypex = combo [ 0 ] ;
651
634
var axistypey = combo [ 1 ] ;
@@ -661,14 +644,13 @@ function describeImageComboTest(combo) {
661
644
var yref = makeAxRef ( yid , aroposy . ref ) ;
662
645
// TODO Add image combo test description
663
646
return [
664
- "layout image with graph ID" ,
665
- gd_id ,
666
- "with parameters:" ,
647
+ "#" , gd_id ,
648
+ "should create a plot with parameters:" , "\n" ,
667
649
"x-axis type:" , axistypex , "\n" ,
668
650
"y-axis type:" , axistypey , "\n" ,
669
- "axis pair:" , axispair , "\n" ,
670
- "ARO position x:" , aroposx , "\n" ,
671
- "ARO position y:" , aroposy , "\n" ,
651
+ "axis pair:" , xid , yid , "\n" ,
652
+ "ARO position x:" , JSON . stringify ( aroposx ) , "\n" ,
653
+ "ARO position y:" , JSON . stringify ( aroposy ) , "\n" ,
672
654
"xanchor:" , xanchor , "\n" ,
673
655
"yanchor:" , yanchor , "\n" ,
674
656
"xref:" , xref , "\n" ,
@@ -689,7 +671,7 @@ function testImageCombo(combo, assert, gd) {
689
671
var yid = axispair [ 1 ] ;
690
672
var xref = makeAxRef ( xid , aroposx . ref ) ;
691
673
var yref = makeAxRef ( yid , aroposy . ref ) ;
692
- return Plotly . newPlot ( gd , testMock )
674
+ return Plotly . newPlot ( gd , Lib . extendDeep ( { } , testMock ) )
693
675
. then ( function ( gd ) {
694
676
return imageTest ( gd , { } , axistypex , axistypey ,
695
677
aroposx . value [ 0 ] , aroposy . value [ 0 ] , aroposx . size ,
@@ -713,14 +695,13 @@ function describeAnnotationComboTest(combo) {
713
695
var xref = makeAxRef ( xid , aroposx . ref ) ;
714
696
var yref = makeAxRef ( yid , aroposy . ref ) ;
715
697
return [
716
- "should create a plot with graph ID" ,
717
- gd_id ,
718
- " with parameters:" , "\n" ,
698
+ "#" , gd_id ,
699
+ "should create a plot with parameters:" , "\n" ,
719
700
"x-axis type:" , axistypex , "\n" ,
720
701
"y-axis type:" , axistypey , "\n" ,
721
- "axis pair:" , axispair , "\n" ,
722
- "ARO position x:" , aroposx , "\n" ,
723
- "ARO position y:" , aroposy , "\n" ,
702
+ "axis pair:" , xid , yid , "\n" ,
703
+ "ARO position x:" , JSON . stringify ( aroposx ) , "\n" ,
704
+ "ARO position y:" , JSON . stringify ( aroposy ) , "\n" ,
724
705
"arrow axis pair:" , arrowaxispair , "\n" ,
725
706
"xref:" , xref , "\n" ,
726
707
"yref:" , yref , "\n" ,
@@ -745,7 +726,7 @@ function testAnnotationCombo(combo, assert, gd) {
745
726
var y0 = aroposy . value [ 0 ] ;
746
727
var ax = axref === 'pixel' ? aroposx . pixel : aroposx . value [ 1 ] ;
747
728
var ay = ayref === 'pixel' ? aroposy . pixel : aroposy . value [ 1 ] ;
748
- return Plotly . newPlot ( gd , testMock )
729
+ return Plotly . newPlot ( gd , Lib . extendDeep ( { } , testMock ) )
749
730
. then ( function ( gd ) {
750
731
return annotationTest ( gd , { } , x0 , y0 , ax , ay , xref , yref , axref ,
751
732
ayref , axistypex , axistypey , xid , yid ) ;
@@ -859,4 +840,4 @@ module.exports = {
859
840
} ,
860
841
// utilities
861
842
findAROByColor : findAROByColor
862
- } ;
843
+ } ;
0 commit comments