@@ -213,49 +213,49 @@ function annotationTest(gd, layout, x0, y0, ax, ay, xref, yref, axref, ayref,
213
213
layout . annotations = [ anno0 , anno1 ] ;
214
214
return Plotly . relayout ( gd , layout )
215
215
. then ( function ( gd ) {
216
- // the choice of anno1 or anno0 is arbitrary
217
- var xabspixels = mapAROCoordToPixel ( gd . layout , 'xref' , anno1 , 'x' , 0 , true ) ;
218
- var yabspixels = mapAROCoordToPixel ( gd . layout , 'yref' , anno1 , 'y' , 0 , true ) ;
219
- if ( axpixels ) {
220
- // no need to map the specified values to pixels (because that's what
221
- // they are already)
222
- xpixels = ax ;
223
- } else {
224
- xpixels = mapAROCoordToPixel ( gd . layout , 'xref' , anno0 , 'ax' , 0 , true ) -
225
- xabspixels ;
226
- }
227
- if ( aypixels ) {
228
- // no need to map the specified values to pixels (because that's what
229
- // they are already)
230
- ypixels = ay ;
231
- } else {
232
- ypixels = mapAROCoordToPixel ( gd . layout , 'yref' , anno0 , 'ay' , 0 , true ) -
233
- yabspixels ;
234
- }
235
- var annobbox0 = getSVGElemScreenBBox ( findAROByColor ( color0 ) ) ;
236
- var annobbox1 = getSVGElemScreenBBox ( findAROByColor ( color1 ) ) ;
237
- // solve for the arrow length's x coordinate
238
- var arrowLenX = ( ( annobbox1 . x + annobbox1 . width ) - ( annobbox0 . x + annobbox0
239
- . width ) ) ;
240
- var arrowLenY ;
241
- var yabspixelscmp ;
242
- if ( aypixels ) {
243
- // for annotations whose arrows are specified in relative pixels,
244
- // positive pixel values on the y axis mean moving down the page like
245
- // SVG coordinates, so we have to add height
246
- var arrowLenY = ( annobbox1 . y + annobbox1 . height ) -
247
- ( annobbox0 . y + annobbox0 . height ) ;
248
- yabspixelscmp = annobbox0 . y ;
249
- } else {
250
- var arrowLenY = annobbox1 . y - annobbox0 . y ;
251
- yabspixelscmp = annobbox0 . y + annobbox0 . height ;
252
- }
253
- var ret = coordsEq ( arrowLenX , xpixels ) &&
254
- coordsEq ( arrowLenY , ypixels ) &&
255
- coordsEq ( xabspixels , annobbox0 . x ) &&
256
- coordsEq ( yabspixels , yabspixelscmp ) ;
257
- return ret ;
258
- } ) ;
216
+ // the choice of anno1 or anno0 is arbitrary
217
+ var xabspixels = mapAROCoordToPixel ( gd . layout , 'xref' , anno1 , 'x' , 0 , true ) ;
218
+ var yabspixels = mapAROCoordToPixel ( gd . layout , 'yref' , anno1 , 'y' , 0 , true ) ;
219
+ if ( axpixels ) {
220
+ // no need to map the specified values to pixels (because that's what
221
+ // they are already)
222
+ xpixels = ax ;
223
+ } else {
224
+ xpixels = mapAROCoordToPixel ( gd . layout , 'xref' , anno0 , 'ax' , 0 , true ) -
225
+ xabspixels ;
226
+ }
227
+ if ( aypixels ) {
228
+ // no need to map the specified values to pixels (because that's what
229
+ // they are already)
230
+ ypixels = ay ;
231
+ } else {
232
+ ypixels = mapAROCoordToPixel ( gd . layout , 'yref' , anno0 , 'ay' , 0 , true ) -
233
+ yabspixels ;
234
+ }
235
+ var annobbox0 = getSVGElemScreenBBox ( findAROByColor ( color0 ) ) ;
236
+ var annobbox1 = getSVGElemScreenBBox ( findAROByColor ( color1 ) ) ;
237
+ // solve for the arrow length's x coordinate
238
+ var arrowLenX = ( ( annobbox1 . x + annobbox1 . width ) - ( annobbox0 . x + annobbox0
239
+ . width ) ) ;
240
+ var arrowLenY ;
241
+ var yabspixelscmp ;
242
+ if ( aypixels ) {
243
+ // for annotations whose arrows are specified in relative pixels,
244
+ // positive pixel values on the y axis mean moving down the page like
245
+ // SVG coordinates, so we have to add height
246
+ var arrowLenY = ( annobbox1 . y + annobbox1 . height ) -
247
+ ( annobbox0 . y + annobbox0 . height ) ;
248
+ yabspixelscmp = annobbox0 . y ;
249
+ } else {
250
+ var arrowLenY = annobbox1 . y - annobbox0 . y ;
251
+ yabspixelscmp = annobbox0 . y + annobbox0 . height ;
252
+ }
253
+ var ret = coordsEq ( arrowLenX , xpixels ) &&
254
+ coordsEq ( arrowLenY , ypixels ) &&
255
+ coordsEq ( xabspixels , annobbox0 . x ) &&
256
+ coordsEq ( yabspixels , yabspixelscmp ) ;
257
+ return ret ;
258
+ } ) ;
259
259
}
260
260
261
261
// axid is e.g., 'x', 'y2' etc.
@@ -438,10 +438,6 @@ function checkAROPosition(gd, aro) {
438
438
var aroPathBBox = getSVGElemScreenBBox ( aroPath ) ;
439
439
var aroBBox = shapeToBBox ( gd . layout , aro ) ;
440
440
var ret = compareBBoxes ( aroBBox , aroPathBBox ) ;
441
- if ( DEBUG ) {
442
- console . log ( 'SVG BBox' , aroPathBBox ) ;
443
- console . log ( 'aro BBox' , aroBBox ) ;
444
- }
445
441
return ret ;
446
442
}
447
443
@@ -528,6 +524,72 @@ var yAnchors = ['top', 'middle', 'bottom'];
528
524
// NOTE: for images color cannot be set but it will be the only image in the
529
525
// plot so you can use d3.select('g image').node()
530
526
var aroColor = 'rgb(50, 100, 150)' ;
527
+
528
+ function testShape (
529
+ gd ,
530
+ xAxNum ,
531
+ xaxisType ,
532
+ xaroPos ,
533
+ yAxNum ,
534
+ yaxisType ,
535
+ yaroPos ,
536
+ aroType
537
+ ) {
538
+ var aro = {
539
+ type : aroType ,
540
+ line : {
541
+ color : aroColor
542
+ }
543
+ } ;
544
+ aroFromAROPos ( aro , 'x' , xAxNum , xaroPos ) ;
545
+ aroFromAROPos ( aro , 'y' , yAxNum , yaroPos ) ;
546
+ var layout = {
547
+ shapes : [ aro ]
548
+ } ;
549
+ // change to log axes if need be
550
+ logAxisIfAxType ( gd . layout , layout , 'x' + xAxNum , xaxisType ) ;
551
+ logAxisIfAxType ( gd . layout , layout , 'y' + yAxNum , yaxisType ) ;
552
+ return Plotly . relayout ( gd , layout )
553
+ . then ( function ( gd ) {
554
+ return checkAROPosition ( gd , aro ) ;
555
+ } ) ;
556
+ }
557
+
558
+ function describeShapeComboTest ( combo ) {
559
+ var xaxisType = combo [ 0 ] ;
560
+ var yaxisType = combo [ 1 ] ;
561
+ var axispair = combo [ 2 ] ;
562
+ var xaroPos = combo [ 3 ] ;
563
+ var yaroPos = combo [ 4 ] ;
564
+ var gd_id = combo [ 5 ] ;
565
+ return [
566
+ "should create a plot with graph ID" ,
567
+ gd_id ,
568
+ " with parameters:" , "\n" ,
569
+ "x-axis type:" , xaxisType , "\n" ,
570
+ "y-axis type:" , yaxisType , "\n" ,
571
+ "axis pair:" , axispair , "\n" ,
572
+ "ARO position x:" , xaroPos , "\n" ,
573
+ "ARO position y:" , yaroPos , "\n" ,
574
+ ] . join ( ' ' ) ;
575
+ }
576
+
577
+ function testShapeCombo ( combo , assert , gd ) {
578
+ var xaxisType = combo [ 0 ] ;
579
+ var yaxisType = combo [ 1 ] ;
580
+ var axispair = combo [ 2 ] ;
581
+ var xaroPos = combo [ 3 ] ;
582
+ var yaroPos = combo [ 4 ] ;
583
+ var xAxNum = axispair [ 0 ] . substr ( 1 ) ;
584
+ var yAxNum = axispair [ 1 ] . substr ( 1 ) ;
585
+ return Plotly . newPlot ( gd , testMock )
586
+ . then ( function ( gd ) {
587
+ return testShape ( gd , xAxNum , xaxisType , xaroPos , yAxNum , yaxisType , yaroPos , 'shape' ) ;
588
+ } ) . then ( function ( test_ret ) {
589
+ assert ( test_ret ) ;
590
+ } ) ;
591
+ }
592
+
531
593
var testDomRefAROCombo = function ( combo ) {
532
594
var xAxNum = combo [ 0 ] ;
533
595
var xaxisType = combo [ 1 ] ;
@@ -584,19 +646,6 @@ function test_correct_aro_positions() {
584
646
testCombos . forEach ( testDomRefAROCombo ) ;
585
647
}
586
648
587
- function runComboTests ( productItems , testCombo , start_stop , filter , keep_graph_div ) {
588
- var testCombos = [ ...iterable . cartesianProduct ( productItems ) ] ;
589
- testCombos = testCombos . map ( ( c , i ) => c . concat ( [ 'graph-' + i ] ) ) ;
590
- if ( filter ) {
591
- testCombos = testCombos . filter ( filter ) ;
592
- }
593
- if ( start_stop ) {
594
- testCombos = testCombos . slice ( start_stop . start , start_stop . stop ) ;
595
- }
596
- console . log ( "Executing " + testCombos . length + " tests" ) ;
597
- var tc = testCombos . map ( c => testCombo ( c , keep_graph_div ) ) . reduce ( ( a , v ) => a . then ( v ) ) ;
598
- }
599
-
600
649
function describeImageComboTest ( combo ) {
601
650
var axistypex = combo [ 0 ] ;
602
651
var axistypey = combo [ 1 ] ;
@@ -713,9 +762,9 @@ function testAnnotationCombo(combo, assert, gd) {
713
762
// {testCombos} is a list of combinations each of which will be passed to the
714
763
// test function
715
764
// {test} is the function returning a Promise that executes this test
716
- function comboTests ( testCombos , test ) {
717
- var ret = testCombos . map ( function ( combo ) {
718
- return function ( assert , gd ) {
765
+ function comboTests ( testCombos , test ) {
766
+ var ret = testCombos . map ( function ( combo ) {
767
+ return function ( assert , gd ) {
719
768
return test ( combo , assert , gd ) ;
720
769
}
721
770
} ) ;
@@ -725,28 +774,27 @@ function comboTests(testCombos,test) {
725
774
// return a list of strings, each describing a corresponding test
726
775
// describe is a function taking a combination and returning a description of
727
776
// the test
728
- function comboTestDescriptions ( testCombos , desribe ) {
777
+ function comboTestDescriptions ( testCombos , desribe ) {
729
778
var ret = testCombos . map ( desribe ) ;
730
779
return ret ;
731
780
}
732
781
733
782
function annotationTestCombos ( ) {
734
783
var testCombos = [ ...iterable . cartesianProduct ( [
735
- axisTypes , axisTypes , axisPairs , aroPositionsX , aroPositionsY , arrowAxis
736
- ]
737
- ) ] ;
784
+ axisTypes , axisTypes , axisPairs , aroPositionsX , aroPositionsY , arrowAxis
785
+ ] ) ] ;
738
786
testCombos = testCombos . map ( ( c , i ) => c . concat ( [ 'graph-' + i ] ) ) ;
739
787
return testCombos ;
740
788
}
741
789
742
790
function annotationTests ( ) {
743
791
var testCombos = annotationTestCombos ( ) ;
744
- return comboTests ( testCombos , testAnnotationCombo ) ;
792
+ return comboTests ( testCombos , testAnnotationCombo ) ;
745
793
}
746
794
747
795
function annotationTestDescriptions ( ) {
748
796
var testCombos = annotationTestCombos ( ) ;
749
- return comboTestDescriptions ( testCombos , describeAnnotationComboTest ) ;
797
+ return comboTestDescriptions ( testCombos , describeAnnotationComboTest ) ;
750
798
}
751
799
752
800
@@ -765,12 +813,34 @@ function imageTestCombos() {
765
813
766
814
function imageTests ( ) {
767
815
var testCombos = imageTestCombos ( ) ;
768
- return comboTests ( testCombos , testImageCombo ) ;
816
+ return comboTests ( testCombos , testImageCombo ) ;
769
817
}
770
818
771
819
function imageTestDescriptions ( ) {
772
820
var testCombos = imageTestCombos ( ) ;
773
- return comboTestDescriptions ( testCombos , describeImageComboTest ) ;
821
+ return comboTestDescriptions ( testCombos , describeImageComboTest ) ;
822
+ }
823
+
824
+ function shapeTestCombos ( ) {
825
+ var testCombos = [ ...iterable . cartesianProduct (
826
+ [
827
+ axisTypes , axisTypes , axisPairs ,
828
+ // axis reference types are contained in here
829
+ aroPositionsX , aroPositionsY ,
830
+ ]
831
+ ) ] ;
832
+ testCombos = testCombos . map ( ( c , i ) => c . concat ( [ 'graph-' + i ] ) ) ;
833
+ return testCombos ;
834
+ }
835
+
836
+ function shapeTests ( ) {
837
+ var testCombos = shapeTestCombos ( ) ;
838
+ return comboTests ( testCombos , testShapeCombo ) ;
839
+ }
840
+
841
+ function shapeTestDescriptions ( ) {
842
+ var testCombos = shapeTestCombos ( ) ;
843
+ return comboTestDescriptions ( testCombos , describeShapeComboTest ) ;
774
844
}
775
845
776
846
module . exports = {
@@ -783,6 +853,10 @@ module.exports = {
783
853
descriptions : imageTestDescriptions ,
784
854
tests : imageTests ,
785
855
} ,
856
+ shapes : {
857
+ descriptions : shapeTestDescriptions ,
858
+ tests : shapeTests
859
+ } ,
786
860
// utilities
787
861
findAROByColor : findAROByColor
788
862
} ;
0 commit comments