Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5734107

Browse files
committed
gl2d: clean up update trace step
1 parent f65dded commit 5734107

File tree

4 files changed

+47
-34
lines changed

4 files changed

+47
-34
lines changed

src/plots/gl2d/scene2d.js

Lines changed: 44 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,6 @@ proto.cameraChanged = function() {
312312
};
313313

314314
proto.destroy = function() {
315-
316315
var traces = this.traces;
317316

318317
if(traces) {
@@ -336,10 +335,11 @@ proto.plot = function(fullData, calcData, fullLayout) {
336335
var glplot = this.glplot,
337336
pixelRatio = this.pixelRatio;
338337

339-
var i, j, trace;
338+
var i;
340339

341340
this.fullLayout = fullLayout;
342341
this.updateAxes(fullLayout);
342+
this.updateTraces(fullData, calcData);
343343

344344
var width = fullLayout.width,
345345
height = fullLayout.height,
@@ -353,34 +353,6 @@ proto.plot = function(fullData, calcData, fullLayout) {
353353
canvas.height = pixelHeight;
354354
}
355355

356-
// update traces
357-
for(i = 0; i < fullData.length; ++i) {
358-
var fullTrace = fullData[i],
359-
calcTrace = calcData[i];
360-
trace = this.traces[fullTrace.uid];
361-
362-
if(trace) trace.update(fullTrace, calcTrace);
363-
else {
364-
trace = fullTrace._module.plot(this, fullTrace, calcTrace);
365-
}
366-
367-
this.traces[fullTrace.uid] = trace;
368-
}
369-
370-
// remove empty traces
371-
var traceIds = Object.keys(this.traces);
372-
373-
trace_id_loop:
374-
for(i = 0; i < traceIds.length; ++i) {
375-
for(j = 0; j < calcData.length; ++j) {
376-
if(calcData[j][0].trace.uid === traceIds[i]) continue trace_id_loop;
377-
}
378-
379-
trace = this.traces[traceIds[i]];
380-
trace.dispose();
381-
delete this.traces[traceIds[i]];
382-
}
383-
384356
var options = this.glplotOptions;
385357
options.merge(fullLayout);
386358
options.screenBox = [0, 0, width, height];
@@ -406,12 +378,13 @@ proto.plot = function(fullData, calcData, fullLayout) {
406378
bounds[0] = bounds[1] = Infinity;
407379
bounds[2] = bounds[3] = -Infinity;
408380

409-
traceIds = Object.keys(this.traces);
381+
var traceIds = Object.keys(this.traces);
410382
for(i = 0; i < traceIds.length; ++i) {
411-
trace = this.traces[traceIds[i]];
383+
var traceObj = this.traces[traceIds[i]];
384+
412385
for(var k = 0; k < 2; ++k) {
413-
bounds[k] = Math.min(bounds[k], trace.bounds[k]);
414-
bounds[k + 2] = Math.max(bounds[k + 2], trace.bounds[k + 2]);
386+
bounds[k] = Math.min(bounds[k], traceObj.bounds[k]);
387+
bounds[k + 2] = Math.max(bounds[k + 2], traceObj.bounds[k + 2]);
415388
}
416389
}
417390

@@ -441,6 +414,43 @@ proto.plot = function(fullData, calcData, fullLayout) {
441414
this.glplot.draw();
442415
};
443416

417+
proto.updateTraces = function(fullData, calcData) {
418+
var traceIds = Object.keys(this.traces);
419+
var i, j, fullTrace;
420+
421+
// remove empty traces
422+
trace_id_loop:
423+
for(i = 0; i < traceIds.length; i++) {
424+
var oldUid = traceIds[i],
425+
oldTrace = this.traces[oldUid];
426+
427+
for(j = 0; j < fullData.length; j++) {
428+
fullTrace = fullData[j];
429+
430+
if(fullTrace.uid === oldUid && fullTrace.type === oldTrace.type) {
431+
continue trace_id_loop;
432+
}
433+
}
434+
435+
oldTrace.dispose();
436+
delete this.traces[oldUid];
437+
}
438+
439+
// update / create trace objects
440+
for(i = 0; i < fullData.length; i++) {
441+
fullTrace = fullData[i];
442+
443+
var calcTrace = calcData[i],
444+
traceObj = this.traces[fullTrace.uid];
445+
446+
if(traceObj) traceObj.update(fullTrace, calcTrace);
447+
else {
448+
traceObj = fullTrace._module.plot(this, fullTrace, calcTrace);
449+
this.traces[fullTrace.uid] = traceObj;
450+
}
451+
}
452+
};
453+
444454
proto.draw = function() {
445455
if(this.stopped) return;
446456

src/traces/contourgl/convert.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ var str2RGBArray = require('../../lib/str2rgbarray');
2020
function Contour(scene, uid) {
2121
this.scene = scene;
2222
this.uid = uid;
23+
this.type = 'contourgl';
2324

2425
this.name = '';
2526
this.hoverinfo = 'all';

src/traces/heatmapgl/convert.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ var str2RGBArray = require('../../lib/str2rgbarray');
1717
function Heatmap(scene, uid) {
1818
this.scene = scene;
1919
this.uid = uid;
20+
this.type = 'heatmapgl';
2021

2122
this.name = '';
2223
this.hoverinfo = 'all';

src/traces/scattergl/convert.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ var AXES = ['xaxis', 'yaxis'];
3232
function LineWithMarkers(scene, uid) {
3333
this.scene = scene;
3434
this.uid = uid;
35+
this.type = 'scattergl';
3536

3637
this.pickXData = [];
3738
this.pickYData = [];

0 commit comments

Comments
 (0)