Skip to content

Commit d9d92db

Browse files
authored
Merge pull request #3536 from 3dcl/master
Fix bug in scattergl text update
2 parents 26d6384 + d72fc6b commit d9d92db

File tree

2 files changed

+110
-0
lines changed

2 files changed

+110
-0
lines changed

src/traces/scattergl/index.js

+13
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,19 @@ function plot(gd, subplot, cdata) {
390390

391391
// update main marker options
392392
if(scene.glText) {
393+
if(scene.count > scene.glText.length) {
394+
// add gl text marker
395+
var textsToAdd = scene.count - scene.glText.length;
396+
for(i = 0; i < textsToAdd; i++) {
397+
scene.glText.push(new Text(regl));
398+
}
399+
} else if(scene.count < scene.glText.length) {
400+
// remove gl text marker
401+
var textsToRemove = scene.glText.length - scene.count;
402+
var removedTexts = scene.glText.splice(scene.count, textsToRemove);
403+
removedTexts.forEach(function(text) { text.destroy(); });
404+
}
405+
393406
for(i = 0; i < scene.count; i++) {
394407
scene.glText[i].update(scene.textOptions[i]);
395408
}

test/jasmine/tests/scattergl_test.js

+97
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
var Plotly = require('@lib/index');
2+
var createGraphDiv = require('../assets/create_graph_div');
3+
var destroyGraphDiv = require('../assets/destroy_graph_div');
4+
var failTest = require('../assets/fail_test');
5+
6+
describe('end-to-end scattergl tests', function() {
7+
var gd;
8+
9+
beforeEach(function() {
10+
gd = createGraphDiv();
11+
});
12+
13+
afterEach(destroyGraphDiv);
14+
15+
it('should create a plot with text labels', function(done) {
16+
Plotly.react(gd, [{
17+
type: 'scattergl',
18+
mode: 'text+lines',
19+
x: [1, 2, 3, 4, 5, 6, 7],
20+
y: [2, 3, 4, 5, 6, 7, 8],
21+
text: 'Test'
22+
}]).then(function() {
23+
var fullLayout = gd._fullLayout;
24+
var subplot = fullLayout._plots.xy;
25+
var scene = subplot._scene;
26+
expect(scene.glText.length).toEqual(1);
27+
}).catch(failTest).then(done);
28+
});
29+
30+
it('should update a plot with text labels', function(done) {
31+
Plotly.react(gd, [{
32+
type: 'scattergl',
33+
mode: 'text+lines',
34+
x: [1, 2, 3, 4, 5, 6, 7],
35+
y: [2, 3, 4, 5, 6, 7, 8],
36+
text: 'Test'
37+
}]).then(function() {
38+
var fullLayout = gd._fullLayout;
39+
var subplot = fullLayout._plots.xy;
40+
var scene = subplot._scene;
41+
expect(scene.glText.length).toEqual(1);
42+
43+
// add plots
44+
return Plotly.react(gd, [
45+
{
46+
type: 'scattergl',
47+
mode: 'text+lines',
48+
x: [1, 2, 3, 4, 5, 6, 7],
49+
y: [2, 3, 4, 5, 6, 7, 8],
50+
text: 'Test'
51+
},
52+
{
53+
type: 'scattergl',
54+
mode: 'text+lines',
55+
x: [1, 2, 3, 4, 5, 6, 7],
56+
y: [3, 4, 5, 6, 7, 8, 9],
57+
text: 'Test 2'
58+
},
59+
{
60+
type: 'scattergl',
61+
mode: 'text+lines',
62+
x: [1, 2, 3, 4, 5, 6, 7],
63+
y: [4, 5, 6, 7, 8, 9, 10],
64+
text: 'Test 3'
65+
}
66+
]);
67+
}).then(function() {
68+
var fullLayout = gd._fullLayout;
69+
var subplot = fullLayout._plots.xy;
70+
var scene = subplot._scene;
71+
expect(scene.glText.length).toEqual(3);
72+
73+
// remove plots
74+
return Plotly.react(gd, [
75+
{
76+
type: 'scattergl',
77+
mode: 'text+lines',
78+
x: [1, 2, 3, 4, 5, 6, 7],
79+
y: [2, 3, 4, 5, 6, 7, 8],
80+
text: 'Test'
81+
},
82+
{
83+
type: 'scattergl',
84+
mode: 'text+lines',
85+
x: [1, 2, 3, 4, 5, 6, 7],
86+
y: [3, 4, 5, 6, 7, 8, 9],
87+
text: 'Test 2'
88+
}
89+
]);
90+
}).then(function() {
91+
var fullLayout = gd._fullLayout;
92+
var subplot = fullLayout._plots.xy;
93+
var scene = subplot._scene;
94+
expect(scene.glText.length).toEqual(2);
95+
}).catch(failTest).then(done);
96+
});
97+
});

0 commit comments

Comments
 (0)