Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 4f037ee

Browse filesBrowse files
committed
Merge pull request plotly#140 from plotly/scattergl-addtrace
Clean data when addTraces is called
2 parents ebdb86e + ca1b363 commit 4f037ee
Copy full SHA for 4f037ee

File tree

2 files changed

+20
-42
lines changed
Filter options

2 files changed

+20
-42
lines changed

‎src/plot_api/plot_api.js

Copy file name to clipboardExpand all lines: src/plot_api/plot_api.js
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1427,6 +1427,7 @@ Plotly.addTraces = function addTraces (gd, traces, newIndices) {
14271427
if (!Array.isArray(traces)) {
14281428
traces = [traces];
14291429
}
1430+
cleanData(traces, gd.data);
14301431

14311432
// add the traces to gd.data (no redrawing yet!)
14321433
for (i = 0; i < traces.length; i += 1) {

‎test/jasmine/tests/plot_api_test.js

Copy file name to clipboardExpand all lines: test/jasmine/tests/plot_api_test.js
+19-42Lines changed: 19 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -133,12 +133,7 @@ describe('Test graph_obj', function () {
133133
var gd;
134134

135135
beforeEach(function () {
136-
gd = {
137-
data: [
138-
{'name': 'a'},
139-
{'name': 'b'}
140-
]
141-
};
136+
gd = { data: [{'name': 'a'}, {'name': 'b'}] };
142137
spyOn(Plotly, 'redraw');
143138
spyOn(Plotly, 'moveTraces');
144139
});
@@ -147,15 +142,15 @@ describe('Test graph_obj', function () {
147142
var expected = JSON.parse(JSON.stringify(gd));
148143
expect(function () {
149144
Plotly.addTraces(gd, 1, 2);
150-
}).toThrow(new Error('all values in traces array must be non-array objects'));
145+
}).toThrowError(Error, 'all values in traces array must be non-array objects');
151146

152147
expect(function () {
153148
Plotly.addTraces(gd, [{}, 4], 2);
154-
}).toThrow(new Error('all values in traces array must be non-array objects'));
149+
}).toThrowError(Error, 'all values in traces array must be non-array objects');
155150

156151
expect(function () {
157152
Plotly.addTraces(gd, [{}, []], 2);
158-
}).toThrow(new Error('all values in traces array must be non-array objects'));
153+
}).toThrowError(Error, 'all values in traces array must be non-array objects');
159154

160155
// make sure we didn't muck with gd.data if things failed!
161156
expect(gd).toEqual(expected);
@@ -166,7 +161,7 @@ describe('Test graph_obj', function () {
166161

167162
expect(function () {
168163
Plotly.addTraces(gd, [{}, {}], 2);
169-
}).toThrow(new Error('if indices is specified, traces.length must equal indices.length'));
164+
}).toThrowError(Error, 'if indices is specified, traces.length must equal indices.length');
170165

171166
});
172167

@@ -182,59 +177,41 @@ describe('Test graph_obj', function () {
182177
});
183178

184179
it('should work when newIndices is undefined', function () {
185-
var expectedData = [
186-
{'name': 'a'},
187-
{'name': 'b'},
188-
{'name': 'c'},
189-
{'name': 'd'}
190-
];
191-
192180
Plotly.addTraces(gd, [{'name': 'c'}, {'name': 'd'}]);
193-
expect(gd.data).toEqual(expectedData);
181+
expect(gd.data[2].name).toBeDefined();
182+
expect(gd.data[2].uid).toBeDefined();
183+
expect(gd.data[3].name).toBeDefined();
184+
expect(gd.data[3].uid).toBeDefined();
194185
expect(Plotly.redraw).toHaveBeenCalled();
195186
expect(Plotly.moveTraces).not.toHaveBeenCalled();
196-
197187
});
198188

199189
it('should work when newIndices is defined', function () {
200-
var expectedData = [
201-
{'name': 'a'},
202-
{'name': 'b'},
203-
{'name': 'c'},
204-
{'name': 'd'}
205-
];
206-
207190
Plotly.addTraces(gd, [{'name': 'c'}, {'name': 'd'}], [1, 3]);
208-
expect(gd.data).toEqual(expectedData);
191+
expect(gd.data[2].name).toBeDefined();
192+
expect(gd.data[2].uid).toBeDefined();
193+
expect(gd.data[3].name).toBeDefined();
194+
expect(gd.data[3].uid).toBeDefined();
209195
expect(Plotly.redraw).not.toHaveBeenCalled();
210196
expect(Plotly.moveTraces).toHaveBeenCalledWith(gd, [-2, -1], [1, 3]);
211197

212198
});
213199

214200
it('should work when newIndices has negative indices', function () {
215-
var expectedData = [
216-
{'name': 'a'},
217-
{'name': 'b'},
218-
{'name': 'c'},
219-
{'name': 'd'}
220-
];
221-
222201
Plotly.addTraces(gd, [{'name': 'c'}, {'name': 'd'}], [-3, -1]);
223-
expect(gd.data).toEqual(expectedData);
202+
expect(gd.data[2].name).toBeDefined();
203+
expect(gd.data[2].uid).toBeDefined();
204+
expect(gd.data[3].name).toBeDefined();
205+
expect(gd.data[3].uid).toBeDefined();
224206
expect(Plotly.redraw).not.toHaveBeenCalled();
225207
expect(Plotly.moveTraces).toHaveBeenCalledWith(gd, [-2, -1], [-3, -1]);
226208

227209
});
228210

229211
it('should work when newIndices is an integer', function () {
230-
var expectedData = [
231-
{'name': 'a'},
232-
{'name': 'b'},
233-
{'name': 'c'}
234-
];
235-
236212
Plotly.addTraces(gd, {'name': 'c'}, 0);
237-
expect(gd.data).toEqual(expectedData);
213+
expect(gd.data[2].name).toBeDefined();
214+
expect(gd.data[2].uid).toBeDefined();
238215
expect(Plotly.redraw).not.toHaveBeenCalled();
239216
expect(Plotly.moveTraces).toHaveBeenCalledWith(gd, [-1], [0]);
240217

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.