Skip to content

Commit 0f1eae6

Browse files
Shapes tests now run as Jasmine tests
Will test them individually to see what's going on.
1 parent 27d8c43 commit 0f1eae6

File tree

2 files changed

+152
-72
lines changed

2 files changed

+152
-72
lines changed

test/jasmine/assets/domain_ref/components.js

Lines changed: 145 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -213,49 +213,49 @@ function annotationTest(gd, layout, x0, y0, ax, ay, xref, yref, axref, ayref,
213213
layout.annotations = [anno0, anno1];
214214
return Plotly.relayout(gd, layout)
215215
.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+
});
259259
}
260260

261261
// axid is e.g., 'x', 'y2' etc.
@@ -438,10 +438,6 @@ function checkAROPosition(gd, aro) {
438438
var aroPathBBox = getSVGElemScreenBBox(aroPath);
439439
var aroBBox = shapeToBBox(gd.layout, aro);
440440
var ret = compareBBoxes(aroBBox, aroPathBBox);
441-
if (DEBUG) {
442-
console.log('SVG BBox', aroPathBBox);
443-
console.log('aro BBox', aroBBox);
444-
}
445441
return ret;
446442
}
447443

@@ -528,6 +524,72 @@ var yAnchors = ['top', 'middle', 'bottom'];
528524
// NOTE: for images color cannot be set but it will be the only image in the
529525
// plot so you can use d3.select('g image').node()
530526
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+
531593
var testDomRefAROCombo = function(combo) {
532594
var xAxNum = combo[0];
533595
var xaxisType = combo[1];
@@ -584,19 +646,6 @@ function test_correct_aro_positions() {
584646
testCombos.forEach(testDomRefAROCombo);
585647
}
586648

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-
600649
function describeImageComboTest(combo) {
601650
var axistypex = combo[0];
602651
var axistypey = combo[1];
@@ -713,9 +762,9 @@ function testAnnotationCombo(combo, assert, gd) {
713762
// {testCombos} is a list of combinations each of which will be passed to the
714763
// test function
715764
// {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) {
719768
return test(combo, assert, gd);
720769
}
721770
});
@@ -725,28 +774,27 @@ function comboTests(testCombos,test) {
725774
// return a list of strings, each describing a corresponding test
726775
// describe is a function taking a combination and returning a description of
727776
// the test
728-
function comboTestDescriptions(testCombos,desribe) {
777+
function comboTestDescriptions(testCombos, desribe) {
729778
var ret = testCombos.map(desribe);
730779
return ret;
731780
}
732781

733782
function annotationTestCombos() {
734783
var testCombos = [...iterable.cartesianProduct([
735-
axisTypes, axisTypes, axisPairs, aroPositionsX, aroPositionsY, arrowAxis
736-
]
737-
)];
784+
axisTypes, axisTypes, axisPairs, aroPositionsX, aroPositionsY, arrowAxis
785+
])];
738786
testCombos = testCombos.map((c, i) => c.concat(['graph-' + i]));
739787
return testCombos;
740788
}
741789

742790
function annotationTests() {
743791
var testCombos = annotationTestCombos();
744-
return comboTests(testCombos,testAnnotationCombo);
792+
return comboTests(testCombos, testAnnotationCombo);
745793
}
746794

747795
function annotationTestDescriptions() {
748796
var testCombos = annotationTestCombos();
749-
return comboTestDescriptions(testCombos,describeAnnotationComboTest);
797+
return comboTestDescriptions(testCombos, describeAnnotationComboTest);
750798
}
751799

752800

@@ -765,12 +813,34 @@ function imageTestCombos() {
765813

766814
function imageTests() {
767815
var testCombos = imageTestCombos();
768-
return comboTests(testCombos,testImageCombo);
816+
return comboTests(testCombos, testImageCombo);
769817
}
770818

771819
function imageTestDescriptions() {
772820
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);
774844
}
775845

776846
module.exports = {
@@ -783,6 +853,10 @@ module.exports = {
783853
descriptions: imageTestDescriptions,
784854
tests: imageTests,
785855
},
856+
shapes: {
857+
descriptions: shapeTestDescriptions,
858+
tests: shapeTests
859+
},
786860
// utilities
787861
findAROByColor: findAROByColor
788862
};

test/jasmine/tests/domain_ref_test.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,13 @@ describe('Test annotations', makeTests(domainRefComponents.annotations,
3939
return i == testNumber;
4040
}));
4141

42-
fdescribe('Test images', makeTests(domainRefComponents.images,
42+
describe('Test images', makeTests(domainRefComponents.images,
43+
function(f, i) {
44+
if (testNumber === undefined) { return true; }
45+
return i == testNumber;
46+
}));
47+
48+
fdescribe('Test shapes', makeTests(domainRefComponents.shapes,
4349
function(f, i) {
4450
if (testNumber === undefined) { return true; }
4551
return i == testNumber;

0 commit comments

Comments
 (0)