Skip to content

Commit

Permalink
Merge branch 'main' into curvedpath-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Manfred Cheung committed Aug 22, 2023
2 parents cf208c2 + f4d858a commit 1ca8c22
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
3 changes: 2 additions & 1 deletion docs/api/grafer-edges-data.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,5 @@ An object containing configuration options for the edges.
| brightness | number | Takes a range between -1 to 1. Defaults to 0. |
| nearDepth | number | Takes a range between 0 to 1. Defaults to 0. Controls camera near depth. |
| farDepth | number | Takes a range between 0 to 1. Defaults to 1. Controls camera far depth. |
| lineWidth | number | Sets the line width of the edges in the layer |
| lineWidth | number | Sets the line width of the edges in the layer. Defaults to 1.5. |
| pickingWidth | number | Sets the width of the edge picking area in the layer where applicable, as a multiplier of the `lineWidth`. Defaults to 8. |
8 changes: 8 additions & 0 deletions src/graph/edges/Edges.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,19 @@ export abstract class Edges<T_SRC extends BasicEdgeData, T_TGT> extends LayerRen
this.localUniforms.uLineWidth = value;
}

public get pickingWidth(): number {
return this.localUniforms.uPickingWidth as number;
}
public set pickingWidth(value: number) {
this.localUniforms.uPickingWidth = value;
}

protected initialize(...args: any[]): void {
super.initialize(...args);
this.localUniforms = Object.assign({}, this.localUniforms, {
uGraphPoints: this.dataTexture,
uLineWidth: 1.5,
uPickingWidth: 8,
});
}

Expand Down
3 changes: 2 additions & 1 deletion src/graph/edges/path/CurvedPath.vs.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ uniform mat4 uSceneMatrix;
uniform mat4 uProjectionMatrix;
uniform vec2 uViewportSize;
uniform float uPixelRatio;
uniform float uPickingWidth;
uniform sampler2D uColorPalette;

uniform float uLineWidth;
Expand Down Expand Up @@ -63,7 +64,7 @@ void main() {
vec2 normal = vec2(-direction.y, direction.x);

// calculate the pixel offset
fLineWidth = (uPicking ? uLineWidth * 8. : uLineWidth) * uPixelRatio;
fLineWidth = (uPicking ? uLineWidth * uPickingWidth : uLineWidth) * uPixelRatio;
float offsetWidth = fLineWidth + 0.5;
vec4 offset = vec4(((aVertex.x * normal * offsetWidth) / uViewportSize) * b0Projected.w, 0.0, 0.0);

Expand Down
3 changes: 2 additions & 1 deletion src/graph/edges/straight/Straight.vs.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ uniform mat4 uSceneMatrix;
uniform mat4 uProjectionMatrix;
uniform vec2 uViewportSize;
uniform float uPixelRatio;
uniform float uPickingWidth;
uniform sampler2D uGraphPoints;
uniform sampler2D uColorPalette;

Expand Down Expand Up @@ -57,7 +58,7 @@ void main() {
vec2 screenDirection = normalize(bScreen - aScreen);
vec2 perp = vec2(-screenDirection.y, screenDirection.x);

fLineWidth = (uPicking ? uLineWidth * 8. : uLineWidth) * uPixelRatio;
fLineWidth = (uPicking ? uLineWidth * uPickingWidth : uLineWidth) * uPixelRatio;
float offsetWidth = fLineWidth + 0.5;
vec4 position = aProjected * multA + bProjected * multB;
vec4 offset = vec4(((aVertex.x * perp * offsetWidth) / uViewportSize) * position.w, 0.0, 0.0);
Expand Down

0 comments on commit 1ca8c22

Please sign in to comment.