-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Implement connect gaps for 2d WebGL plots #449
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
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
64488c9
implement connect gaps for 2d webgl plots
mikolalysenko 0718103
fix linter errors
mikolalysenko 7cdd644
fix calculation of xdata/ydata for fancy scattergl
mikolalysenko 4aa202a
use separate xdata/ydata for picking in scatter plots
mikolalysenko File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,12 +33,15 @@ function LineWithMarkers(scene, uid) { | |
this.scene = scene; | ||
this.uid = uid; | ||
|
||
this.pickXData = []; | ||
this.pickYData = []; | ||
this.xData = []; | ||
this.yData = []; | ||
this.textLabels = []; | ||
this.color = 'rgb(0, 0, 0)'; | ||
this.name = ''; | ||
this.hoverinfo = 'all'; | ||
this.connectgaps = true; | ||
|
||
this.idToIndex = []; | ||
this.bounds = [0, 0, 0, 0]; | ||
|
@@ -103,14 +106,17 @@ function LineWithMarkers(scene, uid) { | |
var proto = LineWithMarkers.prototype; | ||
|
||
proto.handlePick = function(pickResult) { | ||
var index = this.idToIndex[pickResult.pointId]; | ||
var index = pickResult.pointId; | ||
if(pickResult.object !== this.line || this.connectgaps) { | ||
index = this.idToIndex[pickResult.pointId]; | ||
} | ||
|
||
return { | ||
trace: this, | ||
dataCoord: pickResult.dataCoord, | ||
traceCoord: [ | ||
this.xData[index], | ||
this.yData[index] | ||
this.pickXData[index], | ||
this.pickYData[index] | ||
], | ||
textLabel: Array.isArray(this.textLabels) ? | ||
this.textLabels[index] : | ||
|
@@ -248,6 +254,7 @@ proto.update = function(options) { | |
this.name = options.name; | ||
this.hoverinfo = options.hoverinfo; | ||
this.bounds = [Infinity, Infinity, -Infinity, -Infinity]; | ||
this.connectgaps = !!options.connectgaps; | ||
|
||
if(this.isFancy(options)) { | ||
this.updateFancy(options); | ||
|
@@ -262,8 +269,8 @@ proto.update = function(options) { | |
}; | ||
|
||
proto.updateFast = function(options) { | ||
var x = this.xData = options.x; | ||
var y = this.yData = options.y; | ||
var x = this.xData = this.pickXData = options.x; | ||
var y = this.yData = this.pickYData = options.y; | ||
|
||
var len = x.length, | ||
idToIndex = new Array(len), | ||
|
@@ -344,8 +351,11 @@ proto.updateFancy = function(options) { | |
bounds = this.bounds; | ||
|
||
// makeCalcdata runs d2c (data-to-coordinate) on every point | ||
var x = this.xData = xaxis.makeCalcdata(options, 'x'); | ||
var y = this.yData = yaxis.makeCalcdata(options, 'y'); | ||
var x = this.pickXData = xaxis.makeCalcdata(options, 'x').slice(); | ||
var y = this.pickYData = yaxis.makeCalcdata(options, 'y').slice(); | ||
|
||
this.xData = x.slice(); | ||
this.yData = y.slice(); | ||
|
||
// get error values | ||
var errorVals = ErrorBars.calcFromTrace(options, scene.fullLayout); | ||
|
@@ -370,8 +380,8 @@ proto.updateFancy = function(options) { | |
var i, j, xx, yy, ex0, ex1, ey0, ey1; | ||
|
||
for(i = 0; i < len; ++i) { | ||
xx = getX(x[i]); | ||
yy = getY(y[i]); | ||
this.xData[i] = xx = getX(x[i]); | ||
this.yData[i] = yy = getY(y[i]); | ||
|
||
if(isNaN(xx) || isNaN(yy)) continue; | ||
|
||
|
@@ -460,16 +470,29 @@ proto.updateFancy = function(options) { | |
}; | ||
|
||
proto.updateLines = function(options, positions) { | ||
var i; | ||
if(this.hasLines) { | ||
this.lineOptions.positions = positions; | ||
var linePositions = positions; | ||
if(!options.connectgaps) { | ||
var p = 0; | ||
var x = this.xData; | ||
var y = this.yData; | ||
linePositions = new Float32Array(2 * x.length); | ||
|
||
for(i=0; i<x.length; ++i) { | ||
linePositions[p++] = x[i]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you might have to ♻️ this block. |
||
linePositions[p++] = y[i]; | ||
} | ||
} | ||
this.lineOptions.positions = linePositions; | ||
|
||
var lineColor = str2RGBArray(options.line.color); | ||
if(this.hasMarkers) lineColor[3] *= options.marker.opacity; | ||
|
||
var lineWidth = Math.round(0.5 * this.lineOptions.width), | ||
dashes = (DASHES[options.line.dash] || [1]).slice(); | ||
|
||
for(var i = 0; i < dashes.length; ++i) dashes[i] *= lineWidth; | ||
for(i = 0; i < dashes.length; ++i) dashes[i] *= lineWidth; | ||
|
||
switch(options.fill) { | ||
case 'tozeroy': | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"data": [ | ||
{ | ||
"x": [1, 2, 3, 4, 5], | ||
"y": [1, 1, null, -1, -1], | ||
"connectgaps": false, | ||
"mode": "lines", | ||
"type": "scattergl" | ||
}, | ||
{ | ||
"x": [1, 2, 3, 4, 5], | ||
"y": [-2, -2, null, 2, 2], | ||
"connectgaps": true, | ||
"mode": "lines", | ||
"type": "scattergl" | ||
} | ||
], | ||
"layout": { | ||
"title": "Connect gaps test" | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nicely done!