Skip to content

Improve gl2d interactions #855

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Aug 18, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 44 additions & 34 deletions src/plots/gl2d/scene2d.js
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,6 @@ proto.cameraChanged = function() {
};

proto.destroy = function() {

var traces = this.traces;

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

var i, j, trace;
var i;
Copy link
Contributor

@mdtusz mdtusz Aug 18, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor grievance 🐄 - move this closer down to where it's used.


this.fullLayout = fullLayout;
this.updateAxes(fullLayout);
this.updateTraces(fullData, calcData);

var width = fullLayout.width,
height = fullLayout.height,
Expand All @@ -353,34 +353,6 @@ proto.plot = function(fullData, calcData, fullLayout) {
canvas.height = pixelHeight;
}

// update traces
for(i = 0; i < fullData.length; ++i) {
var fullTrace = fullData[i],
calcTrace = calcData[i];
trace = this.traces[fullTrace.uid];

if(trace) trace.update(fullTrace, calcTrace);
else {
trace = fullTrace._module.plot(this, fullTrace, calcTrace);
}

this.traces[fullTrace.uid] = trace;
}

// remove empty traces
var traceIds = Object.keys(this.traces);

trace_id_loop:
for(i = 0; i < traceIds.length; ++i) {
for(j = 0; j < calcData.length; ++j) {
if(calcData[j][0].trace.uid === traceIds[i]) continue trace_id_loop;
}

trace = this.traces[traceIds[i]];
trace.dispose();
delete this.traces[traceIds[i]];
}

var options = this.glplotOptions;
options.merge(fullLayout);
options.screenBox = [0, 0, width, height];
Expand All @@ -406,12 +378,13 @@ proto.plot = function(fullData, calcData, fullLayout) {
bounds[0] = bounds[1] = Infinity;
bounds[2] = bounds[3] = -Infinity;

traceIds = Object.keys(this.traces);
var traceIds = Object.keys(this.traces);
for(i = 0; i < traceIds.length; ++i) {
trace = this.traces[traceIds[i]];
var traceObj = this.traces[traceIds[i]];

for(var k = 0; k < 2; ++k) {
bounds[k] = Math.min(bounds[k], trace.bounds[k]);
bounds[k + 2] = Math.max(bounds[k + 2], trace.bounds[k + 2]);
bounds[k] = Math.min(bounds[k], traceObj.bounds[k]);
bounds[k + 2] = Math.max(bounds[k + 2], traceObj.bounds[k + 2]);
}
}

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

proto.updateTraces = function(fullData, calcData) {
var traceIds = Object.keys(this.traces);
var i, j, fullTrace;

// remove empty traces
trace_id_loop:
for(i = 0; i < traceIds.length; i++) {
var oldUid = traceIds[i],
oldTrace = this.traces[oldUid];

for(j = 0; j < fullData.length; j++) {
fullTrace = fullData[j];

if(fullTrace.uid === oldUid && fullTrace.type === oldTrace.type) {
continue trace_id_loop;
}
}

oldTrace.dispose();
delete this.traces[oldUid];
}

// update / create trace objects
for(i = 0; i < fullData.length; i++) {
fullTrace = fullData[i];

var calcTrace = calcData[i],
traceObj = this.traces[fullTrace.uid];

if(traceObj) traceObj.update(fullTrace, calcTrace);
else {
traceObj = fullTrace._module.plot(this, fullTrace, calcTrace);
this.traces[fullTrace.uid] = traceObj;
}
}
};

proto.draw = function() {
if(this.stopped) return;

Expand Down
1 change: 1 addition & 0 deletions src/traces/contourgl/convert.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ var str2RGBArray = require('../../lib/str2rgbarray');
function Contour(scene, uid) {
this.scene = scene;
this.uid = uid;
this.type = 'contourgl';

this.name = '';
this.hoverinfo = 'all';
Expand Down
1 change: 1 addition & 0 deletions src/traces/heatmapgl/convert.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ var str2RGBArray = require('../../lib/str2rgbarray');
function Heatmap(scene, uid) {
this.scene = scene;
this.uid = uid;
this.type = 'heatmapgl';

this.name = '';
this.hoverinfo = 'all';
Expand Down
1 change: 1 addition & 0 deletions src/traces/scattergl/convert.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ var AXES = ['xaxis', 'yaxis'];
function LineWithMarkers(scene, uid) {
this.scene = scene;
this.uid = uid;
this.type = 'scattergl';

this.pickXData = [];
this.pickYData = [];
Expand Down