Skip to content

Commit

Permalink
Merge pull request #13 from gl-vis/issue-3258_finalist
Browse files Browse the repository at this point in the history
Plotly issue 3258 - hover locked on first point of the first trace
  • Loading branch information
archmoj committed Dec 7, 2018
2 parents dc793d1 + c252e1c commit 1d5ea92
Showing 1 changed file with 35 additions and 16 deletions.
51 changes: 35 additions & 16 deletions pointcloud.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@ function ScatterPlotPickResult(index, position) {
this.dataCoordinate = this.position = position
}

var MAX_OPACITY = 1

function fixOpacity(a) {
if(a === true) return MAX_OPACITY
if(a > MAX_OPACITY) return MAX_OPACITY
return a
}

function PointCloud(
gl,
shader,
Expand Down Expand Up @@ -77,11 +85,11 @@ function PointCloud(
this.vertexCount = 0
this.lineVertexCount = 0

this.opacity = 1.0
this.opacity = MAX_OPACITY

this.lineWidth = 0
this.projectScale = [2.0/3.0, 2.0/3.0, 2.0/3.0]
this.projectOpacity = [1,1,1]
this.projectOpacity = [MAX_OPACITY, MAX_OPACITY, MAX_OPACITY]

this.pickId = 0
this.pickPerspectiveShader = pickPerspectiveShader
Expand Down Expand Up @@ -118,23 +126,23 @@ proto.setPickBase = function(pickBase) {
}

proto.isTransparent = function() {
if(this.opacity < 1) {
if(this.opacity < MAX_OPACITY) {
return true
}
for(var i=0; i<3; ++i) {
if(this.axesProject[i] && this.projectOpacity[i] < 1) {
if(this.axesProject[i] && this.projectOpacity[i] < MAX_OPACITY) {
return true
}
}
return false
}

proto.isOpaque = function() {
if(this.opacity >= 1) {
if(this.opacity >= MAX_OPACITY) {
return true
}
for(var i=0; i<3; ++i) {
if(this.axesProject[i] && this.projectOpacity[i] >= 1) {
if(this.axesProject[i] && this.projectOpacity[i] >= MAX_OPACITY) {
return true
}
}
Expand Down Expand Up @@ -181,7 +189,7 @@ function getClipBounds(bounds) {
return result
}

function drawProject(shader, points, camera, transparent, forceDraw) {
function drawProject(shader, points, camera) {
var axesProject = points.axesProject

var gl = points.gl
Expand Down Expand Up @@ -216,9 +224,6 @@ function drawProject(shader, points, camera, transparent, forceDraw) {
if(!axesProject[i]) {
continue
}
if((points.projectOpacity[i] < 1) !== transparent) {
continue
}

uniforms.scale = points.projectScale[i]
uniforms.opacity = points.projectOpacity[i]
Expand Down Expand Up @@ -283,6 +288,8 @@ function drawProject(shader, points, camera, transparent, forceDraw) {
uniforms.fragClipBounds[0] = setComponent(SCRATCH_VEC, clipBounds[0], i, -1e8)
uniforms.fragClipBounds[1] = setComponent(SCRATCH_VEC, clipBounds[1], i, 1e8)

points.vao.bind()

//Draw interior
points.vao.draw(gl.TRIANGLES, points.vertexCount)

Expand All @@ -291,6 +298,8 @@ function drawProject(shader, points, camera, transparent, forceDraw) {
gl.lineWidth(points.lineWidth)
points.vao.draw(gl.LINES, points.lineVertexCount, points.vertexCount)
}

points.vao.unbind()
}
}

Expand All @@ -302,9 +311,14 @@ var CLIP_GROUP = [NEG_INFINITY3, POS_INFINITY3]
function drawFull(shader, pshader, points, camera, transparent, forceDraw) {
var gl = points.gl

points.vao.bind()

if(transparent === (points.opacity < 1) || forceDraw) {

if(transparent === (points.projectOpacity < MAX_OPACITY) || forceDraw) {
drawProject(pshader, points, camera)
}

if(transparent === (points.opacity < MAX_OPACITY) || forceDraw) {

shader.bind()
var uniforms = shader.uniforms

Expand All @@ -327,6 +341,8 @@ function drawFull(shader, pshader, points, camera, transparent, forceDraw) {

uniforms.pixelRatio = points.pixelRatio

points.vao.bind()

//Draw interior
points.vao.draw(gl.TRIANGLES, points.vertexCount)

Expand All @@ -335,11 +351,11 @@ function drawFull(shader, pshader, points, camera, transparent, forceDraw) {
gl.lineWidth(points.lineWidth)
points.vao.draw(gl.LINES, points.lineVertexCount, points.vertexCount)
}

points.vao.unbind()
}

drawProject(pshader, points, camera, transparent, forceDraw)

points.vao.unbind()
}

proto.draw = function(camera) {
Expand All @@ -354,7 +370,7 @@ proto.drawTransparent = function(camera) {

proto.drawPick = function(camera) {
var shader = this.useOrtho ? this.pickOrthoShader : this.pickPerspectiveShader
drawFull(shader, this.pickProjectShader, this, camera, false, true)
drawFull(shader, this.pickProjectShader, this, camera, true, true)
}

proto.pick = function(selected) {
Expand Down Expand Up @@ -459,9 +475,12 @@ proto.update = function(options) {
var s = +options.projectOpacity
this.projectOpacity = [s,s,s]
}
for(var i=0; i<3; ++i) {
this.projectOpacity[i] = fixOpacity(this.projectOpacity[i]);
}
}
if('opacity' in options) {
this.opacity = options.opacity
this.opacity = fixOpacity(options.opacity)
}

//Set dirty flag
Expand Down

0 comments on commit 1d5ea92

Please sign in to comment.