Skip to content

Commit 27d8c43

Browse files
Don't take log of range for images
Because we would take the log of the range values but not the x, y, sizex, sizey, values, the image would plot, exist and be correct, but it would never be shown because it would usually be off the plot, which was strange.
1 parent e651d57 commit 27d8c43

File tree

2 files changed

+73
-45
lines changed

2 files changed

+73
-45
lines changed

test/jasmine/assets/domain_ref/components.js

Lines changed: 67 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -259,14 +259,15 @@ function annotationTest(gd, layout, x0, y0, ax, ay, xref, yref, axref, ayref,
259259
}
260260

261261
// 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) {
263264
var axname = axisIds.id2name(axid);
264265
if ((axtype === 'log') && (axid !== undefined)) {
265266
var axis = {
266267
...layoutIn[axname]
267268
};
268269
axis.type = 'log';
269-
axis.range = axis.range.map(Math.log10);
270+
axis.range = nologrange ? axis.range : axis.range.map(Math.log10);
270271
layoutOut[axname] = axis;
271272
}
272273
}
@@ -398,11 +399,8 @@ function findImage(id) {
398399
return ret;
399400
}
400401

401-
function checkImage(layout, imageObj, imageBBox) {}
402-
403402
function imageTest(gd, layout, xaxtype, yaxtype, x, y, sizex, sizey, xanchor,
404403
yanchor, xref, yref, xid, yid) {
405-
console.log('running imageTest on ', gd);
406404
var image = {
407405
x: x,
408406
y: y,
@@ -420,18 +418,15 @@ function imageTest(gd, layout, xaxtype, yaxtype, x, y, sizex, sizey, xanchor,
420418
var ret;
421419
// we pass xid, yid because we possibly want to change some axes to log,
422420
// 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);
425423
layout.images = [image];
426424
return Plotly.relayout(gd, layout)
427425
.then(function(gd) {
428426
var imageElem = findImage("#" + gd.id);
429427
var svgImageBBox = getSVGElemScreenBBox(imageElem);
430428
var imageBBox = imageToBBox(gd.layout, image);
431429
ret = compareBBoxes(svgImageBBox, imageBBox);
432-
//if (!ret) {
433-
// throw 'test failed';
434-
//}
435430
return ret;
436431
});
437432
}
@@ -602,7 +597,7 @@ function runComboTests(productItems, testCombo, start_stop, filter, keep_graph_d
602597
var tc = testCombos.map(c => testCombo(c, keep_graph_div)).reduce((a, v) => a.then(v));
603598
}
604599

605-
function testImageCombo(combo, keep_graph_div) {
600+
function describeImageComboTest(combo) {
606601
var axistypex = combo[0];
607602
var axistypey = combo[1];
608603
var axispair = combo[2];
@@ -615,48 +610,47 @@ function testImageCombo(combo, keep_graph_div) {
615610
var yid = axispair[1];
616611
var xref = makeAxRef(xid, aroposx.ref);
617612
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)
627644
.then(function(gd) {
628645
return imageTest(gd, {}, axistypex, axistypey,
629646
aroposx.value[0], aroposy.value[0], aroposx.size,
630647
aroposy.size,
631648
xanchor, yanchor, xref, yref, xid, yid);
632649
}).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);
648651
});
649652
}
650653

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-
660654
function describeAnnotationComboTest(combo) {
661655
var axistypex = combo[0];
662656
var axistypey = combo[1];
@@ -708,7 +702,7 @@ function testAnnotationCombo(combo, assert, gd) {
708702
ayref, axistypex, axistypey, xid, yid);
709703
}).then(function(test_ret) {
710704
assert(test_ret);
711-
})
705+
});
712706
}
713707

714708
// return a list of functions, each returning a promise that executes a
@@ -755,12 +749,40 @@ function annotationTestDescriptions() {
755749
return comboTestDescriptions(testCombos,describeAnnotationComboTest);
756750
}
757751

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+
758776
module.exports = {
759777
// tests
760778
annotations: {
761779
descriptions: annotationTestDescriptions,
762780
tests: annotationTests,
763781
},
782+
images: {
783+
descriptions: imageTestDescriptions,
784+
tests: imageTests,
785+
},
764786
// utilities
765787
findAROByColor: findAROByColor
766788
};

test/jasmine/tests/domain_ref_test.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,9 @@ describe('Test annotations', makeTests(domainRefComponents.annotations,
3838
if (testNumber === undefined) { return true; }
3939
return i == testNumber;
4040
}));
41+
42+
fdescribe('Test images', makeTests(domainRefComponents.images,
43+
function(f, i) {
44+
if (testNumber === undefined) { return true; }
45+
return i == testNumber;
46+
}));

0 commit comments

Comments
 (0)