Skip to content

Commit

Permalink
[sigma/edge-curve] Adds settings.minEdgeThickness
Browse files Browse the repository at this point in the history
Fixes #1428.

Details:
- Adds new setting minEdgeThickness (default value as 1.7) aiming to
  replace the hardcoded values in each edge renderer
- Replaces the hardcoded value in each edge renderer in sigma
- Replaces the hardcoded value in each edge renderer in
  @sigma/edge-curve
  • Loading branch information
jacomyal committed May 27, 2024
1 parent 6c1cf6d commit 8e52503
Show file tree
Hide file tree
Showing 11 changed files with 29 additions and 11 deletions.
4 changes: 3 additions & 1 deletion packages/edge-curve/src/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export default function createEdgeCurveProgram<
"u_sizeRatio",
"u_dimensions",
"u_pixelRatio",
"u_minEdgeThickness",
...(arrowHead ? ["u_lengthToThicknessRatio", "u_widenessToThicknessRatio"] : []),
] as const;

Expand Down Expand Up @@ -92,12 +93,13 @@ export default function createEdgeCurveProgram<
}

setUniforms(params: RenderParams, { gl, uniformLocations }: ProgramInfo): void {
const { u_matrix, u_pixelRatio, u_sizeRatio, u_dimensions } = uniformLocations;
const { u_matrix, u_pixelRatio, u_sizeRatio, u_dimensions, u_minEdgeThickness } = uniformLocations;

gl.uniformMatrix3fv(u_matrix, false, params.matrix);
gl.uniform1f(u_pixelRatio, params.pixelRatio);
gl.uniform1f(u_sizeRatio, params.sizeRatio);
gl.uniform2f(u_dimensions, params.width * params.pixelRatio, params.height * params.pixelRatio);
gl.uniform1f(u_minEdgeThickness, params.minEdgeThickness);

if (arrowHead) {
const { u_lengthToThicknessRatio, u_widenessToThicknessRatio } = uniformLocations;
Expand Down
4 changes: 3 additions & 1 deletion packages/edge-curve/src/shader-vert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ uniform mat3 u_matrix;
uniform float u_sizeRatio;
uniform float u_pixelRatio;
uniform vec2 u_dimensions;
uniform float u_minEdgeThickness;
varying vec4 v_color;
varying float v_thickness;
Expand All @@ -35,7 +36,6 @@ uniform float u_widenessToThicknessRatio;
const float bias = 255.0 / 254.0;
const float epsilon = 0.7;
const float minThickness = 0.3;
vec2 clipspaceToViewport(vec2 pos, vec2 dimensions) {
return vec2(
Expand All @@ -52,6 +52,8 @@ vec2 viewportToClipspace(vec2 pos, vec2 dimensions) {
}
void main() {
float minThickness = u_minEdgeThickness;
// Selecting the correct position
// Branchless "position = a_source if a_current == 1.0 else a_target"
vec2 position = a_source * max(0.0, a_current) + a_target * max(0.0, 1.0 - a_current);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import VERTEX_SHADER_SOURCE from "./vert.glsl";

const { UNSIGNED_BYTE, FLOAT } = WebGLRenderingContext;

const UNIFORMS = ["u_matrix", "u_sizeRatio", "u_correctionRatio"] as const;
const UNIFORMS = ["u_matrix", "u_sizeRatio", "u_correctionRatio", "u_minEdgeThickness"] as const;

export default class EdgeArrowHeadProgram<
N extends Attributes = Attributes,
Expand Down Expand Up @@ -88,10 +88,11 @@ export default class EdgeArrowHeadProgram<
}

setUniforms(params: RenderParams, { gl, uniformLocations }: ProgramInfo): void {
const { u_matrix, u_sizeRatio, u_correctionRatio } = uniformLocations;
const { u_matrix, u_sizeRatio, u_correctionRatio, u_minEdgeThickness } = uniformLocations;

gl.uniformMatrix3fv(u_matrix, false, params.matrix);
gl.uniform1f(u_sizeRatio, params.sizeRatio);
gl.uniform1f(u_correctionRatio, params.correctionRatio);
gl.uniform1f(u_minEdgeThickness, params.minEdgeThickness);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,17 @@ attribute vec4 a_color;
uniform mat3 u_matrix;
uniform float u_sizeRatio;
uniform float u_correctionRatio;
uniform float u_minEdgeThickness;
varying vec4 v_color;
const float minThickness = 1.7;
const float bias = 255.0 / 254.0;
const float arrowHeadWidthLengthRatio = 0.66;
const float arrowHeadLengthThicknessRatio = 2.5;
void main() {
float minThickness = u_minEdgeThickness;
float normalLength = length(a_normal);
vec2 unitNormal = a_normal / normalLength;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,18 @@ uniform mat3 u_matrix;
uniform float u_zoomRatio;
uniform float u_sizeRatio;
uniform float u_correctionRatio;
uniform float u_minEdgeThickness;
varying vec4 v_color;
varying vec2 v_normal;
varying float v_thickness;
const float minThickness = 1.7;
const float bias = 255.0 / 254.0;
const float arrowHeadLengthThicknessRatio = 2.5;
void main() {
float minThickness = u_minEdgeThickness;
float radius = a_radius * a_radiusCoef;
vec2 normal = a_normal * a_normalCoef;
vec2 position = a_positionStart * (1.0 - a_positionCoef) + a_positionEnd * a_positionCoef;
Expand Down
5 changes: 3 additions & 2 deletions packages/sigma/src/rendering/programs/edge-rectangle/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import VERTEX_SHADER_SOURCE from "./vert.glsl";

const { UNSIGNED_BYTE, FLOAT } = WebGLRenderingContext;

const UNIFORMS = ["u_matrix", "u_zoomRatio", "u_sizeRatio", "u_correctionRatio"] as const;
const UNIFORMS = ["u_matrix", "u_zoomRatio", "u_sizeRatio", "u_correctionRatio", "u_minEdgeThickness"] as const;

export default class EdgeRectangleProgram<
N extends Attributes = Attributes,
Expand Down Expand Up @@ -106,11 +106,12 @@ export default class EdgeRectangleProgram<
}

setUniforms(params: RenderParams, { gl, uniformLocations }: ProgramInfo): void {
const { u_matrix, u_zoomRatio, u_correctionRatio, u_sizeRatio } = uniformLocations;
const { u_matrix, u_zoomRatio, u_correctionRatio, u_sizeRatio, u_minEdgeThickness } = uniformLocations;

gl.uniformMatrix3fv(u_matrix, false, params.matrix);
gl.uniform1f(u_zoomRatio, params.zoomRatio);
gl.uniform1f(u_sizeRatio, params.sizeRatio);
gl.uniform1f(u_correctionRatio, params.correctionRatio);
gl.uniform1f(u_minEdgeThickness, params.minEdgeThickness);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,17 @@ uniform mat3 u_matrix;
uniform float u_sizeRatio;
uniform float u_zoomRatio;
uniform float u_correctionRatio;
uniform float u_minEdgeThickness;
varying vec4 v_color;
varying vec2 v_normal;
varying float v_thickness;
const float minThickness = 1.7;
const float bias = 255.0 / 254.0;
void main() {
float minThickness = u_minEdgeThickness;
vec2 normal = a_normal * a_normalCoef;
vec2 position = a_positionStart * (1.0 - a_positionCoef) + a_positionEnd * a_positionCoef;
Expand Down
5 changes: 3 additions & 2 deletions packages/sigma/src/rendering/programs/edge-triangle/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import VERTEX_SHADER_SOURCE from "./vert.glsl";

const { UNSIGNED_BYTE, FLOAT } = WebGLRenderingContext;

const UNIFORMS = ["u_matrix", "u_sizeRatio", "u_correctionRatio"] as const;
const UNIFORMS = ["u_matrix", "u_sizeRatio", "u_correctionRatio", "u_minEdgeThickness"] as const;

export default class EdgeTriangleProgram<
N extends Attributes = Attributes,
Expand Down Expand Up @@ -94,10 +94,11 @@ export default class EdgeTriangleProgram<
}

setUniforms(params: RenderParams, { gl, uniformLocations }: ProgramInfo): void {
const { u_matrix, u_sizeRatio, u_correctionRatio } = uniformLocations;
const { u_matrix, u_sizeRatio, u_correctionRatio, u_minEdgeThickness } = uniformLocations;

gl.uniformMatrix3fv(u_matrix, false, params.matrix);
gl.uniform1f(u_sizeRatio, params.sizeRatio);
gl.uniform1f(u_correctionRatio, params.correctionRatio);
gl.uniform1f(u_minEdgeThickness, params.minEdgeThickness);
}
}
2 changes: 2 additions & 0 deletions packages/sigma/src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export interface Settings<
defaultDrawEdgeLabel: EdgeLabelDrawingFunction<N, E, G>;
defaultDrawNodeLabel: NodeLabelDrawingFunction<N, E, G>;
defaultDrawNodeHover: NodeHoverDrawingFunction<N, E, G>;
minEdgeThickness: number;

// Labels
labelDensity: number;
Expand Down Expand Up @@ -108,6 +109,7 @@ export const DEFAULT_SETTINGS: Settings<Attributes, Attributes, Attributes> = {
defaultDrawEdgeLabel: drawStraightEdgeLabel,
defaultDrawNodeLabel: drawDiscNodeLabel,
defaultDrawNodeHover: drawDiscNodeHover,
minEdgeThickness: 1.7,

// Labels
labelDensity: 1,
Expand Down
2 changes: 2 additions & 0 deletions packages/sigma/src/sigma.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1105,6 +1105,7 @@ export default class Sigma<
sizeRatio: 1 / this.scaleSize(),
correctionRatio: this.correctionRatio,
downSizingRatio: this.pickingDownSizingRatio,
minEdgeThickness: this.settings.minEdgeThickness,
});
}
}
Expand Down Expand Up @@ -1200,6 +1201,7 @@ export default class Sigma<
sizeRatio: 1 / this.scaleSize(),
correctionRatio: this.correctionRatio,
downSizingRatio: this.pickingDownSizingRatio,
minEdgeThickness: this.settings.minEdgeThickness,
};

// Drawing nodes
Expand Down
1 change: 1 addition & 0 deletions packages/sigma/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ export interface RenderParams {
correctionRatio: number;
matrix: Float32Array;
downSizingRatio: number;
minEdgeThickness: number;
}

/**
Expand Down

0 comments on commit 8e52503

Please sign in to comment.