Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
purescript-gargantext
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
143
Issues
143
List
Board
Labels
Milestones
Merge Requests
8
Merge Requests
8
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
gargantext
purescript-gargantext
Commits
38e9b3a8
Commit
38e9b3a8
authored
Feb 21, 2025
by
Karen Konou
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Sigma] Update circle-with-contour to use the new program API
parent
75a49825
Pipeline
#7335
passed with stages
in 21 minutes and 16 seconds
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
118 additions
and
57 deletions
+118
-57
sigmajs-circle-with-contour.js
src/external-deps/sigmajs-circle-with-contour.js
+118
-57
No files found.
src/external-deps/sigmajs-circle-with-contour.js
View file @
38e9b3a8
// Based on
sigma.js/src/rendering/webgl/programs/node.fast
.ts
// Based on
https://github.com/jacomyal/sigma.js/blob/main/packages/sigma/src/rendering/programs/node-point/index
.ts
import
{
floatColor
}
from
"sigma/utils"
;
import
{
NodePointProgram
}
from
'sigma/rendering'
;
import
{
NodeProgram
}
from
'sigma/rendering'
;
// From https://github.com/jacomyal/sigma.js/blob/main/packages/sigma/src/rendering/programs/node-point/frag.glsl.ts
const
FRAGMENT_SHADER_SOURCE
=
/*glsl*/
`
precision mediump float;
varying vec4 v_color;
varying float v_border;
const float radius = 0.5;
const vec4 transparent = vec4(0.0, 0.0, 0.0, 0.0);
void main(void) {
vec2 m = gl_PointCoord - vec2(0.5, 0.5);
float dist = radius - length(m);
// No antialiasing for picking mode:
#ifdef PICKING_MODE
if (dist > v_border)
gl_FragColor = v_color;
else
gl_FragColor = transparent;
#else
float t = 0.0;
if (dist > v_border)
t = 1.0;
else if (dist > 0.0)
t = dist / v_border;
gl_FragColor = mix(transparent, v_color, t);
#endif
}
`
;
// From https://github.com/jacomyal/sigma.js/blob/main/packages/sigma/src/rendering/programs/node-point/vert.glsl.ts
const
VERTEX_SHADER_SOURCE
=
/*glsl*/
`
attribute vec4 a_id;
attribute vec4 a_color;
attribute vec2 a_position;
attribute float a_size;
uniform float u_sizeRatio;
uniform float u_pixelRatio;
uniform mat3 u_matrix;
varying vec4 v_color;
varying float v_border;
const float bias = 255.0 / 254.0;
void main() {
gl_Position = vec4(
(u_matrix * vec3(a_position, 1)).xy,
0,
1
);
// Multiply the point size twice:
// - x SCALING_RATIO to correct the canvas scaling
// - x 2 to correct the formulae
gl_PointSize = a_size / u_sizeRatio * u_pixelRatio * 2.0;
v_border = (0.5 / a_size) * u_sizeRatio;
#ifdef PICKING_MODE
// For picking mode, we use the ID as the color:
v_color = a_id;
#else
// For normal mode, we use the color:
v_color = a_color;
#endif
v_color.a *= bias;
}
`
;
const
POINTS
=
2
;
const
{
UNSIGNED_BYTE
,
FLOAT
}
=
WebGLRenderingContext
;
const
UNIFORMS
=
[
"u_sizeRatio"
,
"u_pixelRatio"
,
"u_matrix"
]
/*
export default class NodeContourFastProgram extends AbstractNodeProgram {
//constructor(gl : WebGLRenderingContext) {
constructor(gl) {
super(gl, vertexShaderSource, fragmentShaderSource, POINTS, ATTRIBUTES);
this.bind();
}
export default class NodePointProgram<
N extends Attributes = Attributes,
E extends Attributes = Attributes,
G extends Attributes = Attributes,
> extends NodeProgram<(typeof UNIFORMS)[number], N, E, G> {
*/
export
default
class
NodeContourFastProgram
extends
NodePointProgram
{
constructor
(
gl
)
{
super
(
gl
);
// NOTE super method above will set POINTS = 1 from CircleNodeProgram
// We need to overwrite this
// https://gitlab.iscpif.fr/gargantext/purescript-gargantext/issues/471
this
.
points
=
POINTS
;
export
default
class
NodeContourFastProgram
extends
NodeProgram
{
getDefinition
()
{
return
{
VERTICES
:
2
,
VERTEX_SHADER_SOURCE
,
FRAGMENT_SHADER_SOURCE
,
METHOD
:
WebGLRenderingContext
.
POINTS
,
UNIFORMS
,
ATTRIBUTES
:
[
{
name
:
"a_position"
,
size
:
2
,
type
:
FLOAT
},
{
name
:
"a_size"
,
size
:
1
,
type
:
FLOAT
},
{
name
:
"a_color"
,
size
:
4
,
type
:
UNSIGNED_BYTE
,
normalized
:
true
},
{
name
:
"a_id"
,
size
:
4
,
type
:
UNSIGNED_BYTE
,
normalized
:
true
},
],
};
}
//
process(data: NodeDisplayData, hidden: boolean, offset: number): void
{
process
(
data
,
hidden
,
offset
)
{
//
processVisibleItem(nodeIndex: number, startIndex: number, data: NodeDisplayData)
{
process
VisibleItem
(
nodeIndex
,
startIndex
,
data
)
{
const
array
=
this
.
array
;
let
i
=
offset
*
POINTS
*
ATTRIBUTES
;
if
(
hidden
)
{
// contour
array
[
i
++
]
=
0
;
array
[
i
++
]
=
0
;
array
[
i
++
]
=
0
;
array
[
i
++
]
=
0
;
// circle
array
[
i
++
]
=
0
;
array
[
i
++
]
=
0
;
array
[
i
++
]
=
0
;
array
[
i
++
]
=
0
;
return
;
}
const
color
=
floatColor
(
data
.
color
);
//const black = floatColor('black');
const
gray
=
floatColor
(
'#aaa'
)
// contour
array
[
i
++
]
=
data
.
x
;
array
[
i
++
]
=
data
.
y
;
array
[
i
++
]
=
data
.
size
+
1
;
array
[
startIndex
++
]
=
data
.
x
;
array
[
startIndex
++
]
=
data
.
y
;
array
[
startIndex
++
]
=
data
.
size
+
1
;
//array[i++] = black;
array
[
i
++
]
=
gray
;
array
[
startIndex
++
]
=
gray
;
array
[
startIndex
++
]
=
nodeIndex
;
// circle
array
[
i
++
]
=
data
.
x
;
array
[
i
++
]
=
data
.
y
;
array
[
i
++
]
=
data
.
size
;
array
[
i
]
=
color
;
array
[
startIndex
++
]
=
data
.
x
;
array
[
startIndex
++
]
=
data
.
y
;
array
[
startIndex
++
]
=
data
.
size
;
array
[
startIndex
++
]
=
color
;
array
[
startIndex
++
]
=
nodeIndex
;
}
//render(params: RenderParams): void {
render
(
params
)
{
if
(
this
.
hasNothingToRender
())
return
;
const
gl
=
this
.
gl
;
const
program
=
this
.
program
;
gl
.
useProgram
(
program
);
gl
.
uniform1f
(
this
.
ratioLocation
,
1
/
Math
.
sqrt
(
params
.
ratio
));
gl
.
uniform1f
(
this
.
scaleLocation
,
params
.
scalingRatio
);
gl
.
uniformMatrix3fv
(
this
.
matrixLocation
,
false
,
params
.
matrix
);
//setUniforms({ sizeRatio, pixelRatio, matrix }: RenderParams, { gl, uniformLocations }: ProgramInfo): void {
setUniforms
({
sizeRatio
,
pixelRatio
,
matrix
},
{
gl
,
uniformLocations
})
{
const
{
u_sizeRatio
,
u_pixelRatio
,
u_matrix
}
=
uniformLocations
;
gl
.
drawArrays
(
gl
.
POINTS
,
0
,
this
.
array
.
length
/
ATTRIBUTES
);
gl
.
uniform1f
(
u_pixelRatio
,
pixelRatio
);
gl
.
uniform1f
(
u_sizeRatio
,
sizeRatio
);
gl
.
uniformMatrix3fv
(
u_matrix
,
false
,
matrix
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment