sigma
Version:
A JavaScript library dedicated to graph drawing.
1 lines • 1.92 kB
JavaScript
(()=>{"use strict";var n={d:(t,o)=>{for(var e in o)n.o(o,e)&&!n.o(t,e)&&Object.defineProperty(t,e,{enumerable:!0,get:o[e]})},o:(n,t)=>Object.prototype.hasOwnProperty.call(n,t),r:n=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(n,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(n,"__esModule",{value:!0})}},t={};n.r(t),n.d(t,{default:()=>o});const o="attribute vec2 a_position;\nattribute vec2 a_normal;\nattribute float a_thickness;\nattribute vec4 a_color;\nattribute float a_radius;\n\nuniform mat3 u_matrix;\nuniform float u_scale;\nuniform float u_cameraRatio;\nuniform float u_viewportRatio;\nuniform float u_thicknessRatio;\n\nvarying vec4 v_color;\nvarying vec2 v_normal;\nvarying float v_thickness;\n\nconst float arrowHeadLengthThicknessRatio = 2.5;\nconst float minThickness = 0.8;\nconst float bias = 255.0 / 254.0;\n\nvoid main() {\n\n // Computing thickness in screen space:\n float thickness = a_thickness * u_thicknessRatio * u_scale * u_viewportRatio / 2.0;\n thickness = max(thickness, minThickness * u_viewportRatio);\n\n float direction = sign(a_radius);\n float nodeRadius = direction * a_radius * u_thicknessRatio * u_viewportRatio;\n float arrowHeadLength = thickness * 2.0 * arrowHeadLengthThicknessRatio;\n\n vec2 arrowHeadVector = vec2(-direction * a_normal.y, direction * a_normal.x);\n\n // Add normal vector to the position in screen space, but correct thickness first:\n vec2 position = a_position + a_normal * thickness * u_cameraRatio;\n // Add vector that corrects the arrow head length:\n position = position + arrowHeadVector * (arrowHeadLength + nodeRadius) * u_cameraRatio;\n // Apply camera\n position = (u_matrix * vec3(position, 1)).xy;\n\n gl_Position = vec4(position, 0, 1);\n\n v_normal = a_normal;\n v_thickness = thickness;\n\n // Extract the color:\n v_color = a_color;\n v_color.a *= bias;\n}\n";module.exports=t})();