Skip to content

Commit bb7adb6

Browse files
committed
revised the condition check and added a jasmine test for textpositions
1 parent d4addd0 commit bb7adb6

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

src/plot_api/helpers.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ function cleanTextPosition(textposition) {
440440
var posY = 'middle',
441441
posX = 'center';
442442

443-
if(textposition !== undefined && textposition !== null) {
443+
if(typeof textposition === "string") {
444444
if(textposition.indexOf('top') !== -1) posY = 'top';
445445
else if(textposition.indexOf('bottom') !== -1) posY = 'bottom';
446446

test/jasmine/tests/gl3d_plot_interact_test.js

+26
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,32 @@ describe('Test gl3d plots', function() {
558558
.catch(failTest)
559559
.then(done);
560560
});
561+
562+
it('@gl should only accept texts for textposition otherwise textposition is set to middle center before passing to webgl', function(done) {
563+
Plotly.plot(gd, [{
564+
type: 'scatter3d',
565+
mode: 'markers+text+lines',
566+
x: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16],
567+
y: [-1, -2, -3, -4, -5, -6, -7, -8, -9, -10, -11, -12, -13, -14, -15, -16],
568+
z: [0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1],
569+
text: ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p'],
570+
textposition: ["left top", "right top", "left bottom", "right bottom", null, undefined, , true, false, [], {}, NaN, Infinity, 0]
571+
}])
572+
.then(function() {
573+
var AllTextpositions = gd._fullData[0].textposition
574+
575+
expect(AllTextpositions[0]).toBe("top left", 'is not top left');
576+
expect(AllTextpositions[1]).toBe("top right", 'is not top right');
577+
expect(AllTextpositions[2]).toBe("bottom left", 'is not bottom left');
578+
expect(AllTextpositions[3]).toBe("bottom right", 'is not bottom right');
579+
for(var i = 4; i < AllTextpositions.length; i++) {
580+
expect(AllTextpositions[i]).toBe("middle center", 'is not middle center');
581+
}
582+
})
583+
.catch(failTest)
584+
.then(done);
585+
});
586+
561587
});
562588

563589
describe('Test gl3d modebar handlers', function() {

0 commit comments

Comments
 (0)