New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@sigma/edge-curve

Package Overview
Dependencies
Maintainers
0
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@sigma/edge-curve - npm Package Compare versions

Comparing version 3.0.0 to 3.1.0

1

dist/declarations/src/index.d.ts

@@ -9,1 +9,2 @@ import { EdgeProgramType } from "sigma/rendering";

export declare const EdgeCurvedArrowProgram: EdgeProgramType;
export declare const EdgeCurvedDoubleArrowProgram: EdgeProgramType;

@@ -9,2 +9,3 @@ import Graph from "graphology";

arrowHead: null | {
extremity: "target" | "source" | "both";
lengthToThicknessRatio: number;

@@ -11,0 +12,0 @@ widenessToThicknessRatio: number;

97

dist/sigma-edge-curve.cjs.dev.js

@@ -8,6 +8,2 @@ 'use strict';

function _classCallCheck(a, n) {
if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function");
}
function _toPrimitive(t, r) {

@@ -29,2 +25,37 @@ if ("object" != typeof t || !t) return t;

function _defineProperty(e, r, t) {
return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
value: t,
enumerable: !0,
configurable: !0,
writable: !0
}) : e[r] = t, e;
}
function ownKeys(e, r) {
var t = Object.keys(e);
if (Object.getOwnPropertySymbols) {
var o = Object.getOwnPropertySymbols(e);
r && (o = o.filter(function (r) {
return Object.getOwnPropertyDescriptor(e, r).enumerable;
})), t.push.apply(t, o);
}
return t;
}
function _objectSpread2(e) {
for (var r = 1; r < arguments.length; r++) {
var t = null != arguments[r] ? arguments[r] : {};
r % 2 ? ownKeys(Object(t), !0).forEach(function (r) {
_defineProperty(e, r, t[r]);
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) {
Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
});
}
return e;
}
function _classCallCheck(a, n) {
if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function");
}
function _defineProperties(e, r) {

@@ -91,11 +122,2 @@ for (var t = 0; t < r.length; t++) {

function _defineProperty(e, r, t) {
return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
value: t,
enumerable: !0,
configurable: !0,
writable: !0
}) : e[r] = t, e;
}
function _arrayLikeToArray(r, a) {

@@ -131,24 +153,2 @@ (null == a || a > r.length) && (a = r.length);

function ownKeys(e, r) {
var t = Object.keys(e);
if (Object.getOwnPropertySymbols) {
var o = Object.getOwnPropertySymbols(e);
r && (o = o.filter(function (r) {
return Object.getOwnPropertyDescriptor(e, r).enumerable;
})), t.push.apply(t, o);
}
return t;
}
function _objectSpread2(e) {
for (var r = 1; r < arguments.length; r++) {
var t = null != arguments[r] ? arguments[r] : {};
r % 2 ? ownKeys(Object(t), !0).forEach(function (r) {
_defineProperty(e, r, t[r]);
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) {
Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
});
}
return e;
}
function getCurvePoint(t, p0, p1, p2) {

@@ -286,4 +286,7 @@ var x = Math.pow(1 - t, 2) * p0.x + 2 * (1 - t) * t * p1.x + Math.pow(t, 2) * p2.x;

var arrowHead = _ref.arrowHead;
var hasTargetArrowHead = (arrowHead === null || arrowHead === void 0 ? void 0 : arrowHead.extremity) === "target" || (arrowHead === null || arrowHead === void 0 ? void 0 : arrowHead.extremity) === "both";
var hasSourceArrowHead = (arrowHead === null || arrowHead === void 0 ? void 0 : arrowHead.extremity) === "source" || (arrowHead === null || arrowHead === void 0 ? void 0 : arrowHead.extremity) === "both";
// language=GLSL
var SHADER = /*glsl*/"\nprecision highp float;\n\nvarying vec4 v_color;\nvarying float v_thickness;\nvarying float v_feather;\nvarying vec2 v_cpA;\nvarying vec2 v_cpB;\nvarying vec2 v_cpC;\n".concat(arrowHead ? "\nvarying float v_targetSize;\nvarying vec2 v_targetPoint;\n\nuniform float u_lengthToThicknessRatio;\nuniform float u_widenessToThicknessRatio;" : "", "\n\nfloat det(vec2 a, vec2 b) {\n return a.x * b.y - b.x * a.y;\n}\n\nvec2 getDistanceVector(vec2 b0, vec2 b1, vec2 b2) {\n float a = det(b0, b2), b = 2.0 * det(b1, b0), d = 2.0 * det(b2, b1);\n float f = b * d - a * a;\n vec2 d21 = b2 - b1, d10 = b1 - b0, d20 = b2 - b0;\n vec2 gf = 2.0 * (b * d21 + d * d10 + a * d20);\n gf = vec2(gf.y, -gf.x);\n vec2 pp = -f * gf / dot(gf, gf);\n vec2 d0p = b0 - pp;\n float ap = det(d0p, d20), bp = 2.0 * det(d10, d0p);\n float t = clamp((ap + bp) / (2.0 * a + b + d), 0.0, 1.0);\n return mix(mix(b0, b1, t), mix(b1, b2, t), t);\n}\n\nfloat distToQuadraticBezierCurve(vec2 p, vec2 b0, vec2 b1, vec2 b2) {\n return length(getDistanceVector(b0 - p, b1 - p, b2 - p));\n}\n\nconst vec4 transparent = vec4(0.0, 0.0, 0.0, 0.0);\n\nvoid main(void) {\n float dist = distToQuadraticBezierCurve(gl_FragCoord.xy, v_cpA, v_cpB, v_cpC);\n float thickness = v_thickness;\n").concat(arrowHead ? "\n float distToTarget = length(gl_FragCoord.xy - v_targetPoint);\n float arrowLength = v_targetSize + thickness * u_lengthToThicknessRatio;\n if (distToTarget < arrowLength) {\n thickness = (distToTarget - v_targetSize) / (arrowLength - v_targetSize) * u_widenessToThicknessRatio * thickness;\n }" : "", "\n\n float halfThickness = thickness / 2.0;\n if (dist < halfThickness) {\n #ifdef PICKING_MODE\n gl_FragColor = v_color;\n #else\n float t = smoothstep(\n halfThickness - v_feather,\n halfThickness,\n dist\n );\n\n gl_FragColor = mix(v_color, transparent, t);\n #endif\n } else {\n gl_FragColor = transparent;\n }\n}\n");
var SHADER = /*glsl*/"\nprecision highp float;\n\nvarying vec4 v_color;\nvarying float v_thickness;\nvarying float v_feather;\nvarying vec2 v_cpA;\nvarying vec2 v_cpB;\nvarying vec2 v_cpC;\n".concat(hasTargetArrowHead ? "\nvarying float v_targetSize;\nvarying vec2 v_targetPoint;" : "", "\n").concat(hasSourceArrowHead ? "\nvarying float v_sourceSize;\nvarying vec2 v_sourcePoint;" : "", "\n").concat(arrowHead ? "\nuniform float u_lengthToThicknessRatio;\nuniform float u_widenessToThicknessRatio;" : "", "\n\nfloat det(vec2 a, vec2 b) {\n return a.x * b.y - b.x * a.y;\n}\n\nvec2 getDistanceVector(vec2 b0, vec2 b1, vec2 b2) {\n float a = det(b0, b2), b = 2.0 * det(b1, b0), d = 2.0 * det(b2, b1);\n float f = b * d - a * a;\n vec2 d21 = b2 - b1, d10 = b1 - b0, d20 = b2 - b0;\n vec2 gf = 2.0 * (b * d21 + d * d10 + a * d20);\n gf = vec2(gf.y, -gf.x);\n vec2 pp = -f * gf / dot(gf, gf);\n vec2 d0p = b0 - pp;\n float ap = det(d0p, d20), bp = 2.0 * det(d10, d0p);\n float t = clamp((ap + bp) / (2.0 * a + b + d), 0.0, 1.0);\n return mix(mix(b0, b1, t), mix(b1, b2, t), t);\n}\n\nfloat distToQuadraticBezierCurve(vec2 p, vec2 b0, vec2 b1, vec2 b2) {\n return length(getDistanceVector(b0 - p, b1 - p, b2 - p));\n}\n\nconst vec4 transparent = vec4(0.0, 0.0, 0.0, 0.0);\n\nvoid main(void) {\n float dist = distToQuadraticBezierCurve(gl_FragCoord.xy, v_cpA, v_cpB, v_cpC);\n float thickness = v_thickness;\n").concat(hasTargetArrowHead ? "\n float distToTarget = length(gl_FragCoord.xy - v_targetPoint);\n float targetArrowLength = v_targetSize + thickness * u_lengthToThicknessRatio;\n if (distToTarget < targetArrowLength) {\n thickness = (distToTarget - v_targetSize) / (targetArrowLength - v_targetSize) * u_widenessToThicknessRatio * thickness;\n }" : "", "\n").concat(hasSourceArrowHead ? "\n float distToSource = length(gl_FragCoord.xy - v_sourcePoint);\n float sourceArrowLength = v_sourceSize + thickness * u_lengthToThicknessRatio;\n if (distToSource < sourceArrowLength) {\n thickness = (distToSource - v_sourceSize) / (sourceArrowLength - v_sourceSize) * u_widenessToThicknessRatio * thickness;\n }" : "", "\n\n float halfThickness = thickness / 2.0;\n if (dist < halfThickness) {\n #ifdef PICKING_MODE\n gl_FragColor = v_color;\n #else\n float t = smoothstep(\n halfThickness - v_feather,\n halfThickness,\n dist\n );\n\n gl_FragColor = mix(v_color, transparent, t);\n #endif\n } else {\n gl_FragColor = transparent;\n }\n}\n");
return SHADER;

@@ -294,4 +297,7 @@ }

var arrowHead = _ref.arrowHead;
var hasTargetArrowHead = (arrowHead === null || arrowHead === void 0 ? void 0 : arrowHead.extremity) === "target" || (arrowHead === null || arrowHead === void 0 ? void 0 : arrowHead.extremity) === "both";
var hasSourceArrowHead = (arrowHead === null || arrowHead === void 0 ? void 0 : arrowHead.extremity) === "source" || (arrowHead === null || arrowHead === void 0 ? void 0 : arrowHead.extremity) === "both";
// language=GLSL
var SHADER = /*glsl*/"\nattribute vec4 a_id;\nattribute vec4 a_color;\nattribute float a_direction;\nattribute float a_thickness;\nattribute vec2 a_source;\nattribute vec2 a_target;\nattribute float a_current;\nattribute float a_curvature;\n".concat(arrowHead ? "attribute float a_targetSize;\n" : "", "\n\nuniform mat3 u_matrix;\nuniform float u_sizeRatio;\nuniform float u_pixelRatio;\nuniform vec2 u_dimensions;\nuniform float u_minEdgeThickness;\nuniform float u_feather;\n\nvarying vec4 v_color;\nvarying float v_thickness;\nvarying float v_feather;\nvarying vec2 v_cpA;\nvarying vec2 v_cpB;\nvarying vec2 v_cpC;\n").concat(arrowHead ? "\nvarying float v_targetSize;\nvarying vec2 v_targetPoint;\nuniform float u_widenessToThicknessRatio;\n" : "", "\n\nconst float bias = 255.0 / 254.0;\nconst float epsilon = 0.7;\n\nvec2 clipspaceToViewport(vec2 pos, vec2 dimensions) {\n return vec2(\n (pos.x + 1.0) * dimensions.x / 2.0,\n (pos.y + 1.0) * dimensions.y / 2.0\n );\n}\n\nvec2 viewportToClipspace(vec2 pos, vec2 dimensions) {\n return vec2(\n pos.x / dimensions.x * 2.0 - 1.0,\n pos.y / dimensions.y * 2.0 - 1.0\n );\n}\n\nvoid main() {\n float minThickness = u_minEdgeThickness;\n\n // Selecting the correct position\n // Branchless \"position = a_source if a_current == 1.0 else a_target\"\n vec2 position = a_source * max(0.0, a_current) + a_target * max(0.0, 1.0 - a_current);\n position = (u_matrix * vec3(position, 1)).xy;\n\n vec2 source = (u_matrix * vec3(a_source, 1)).xy;\n vec2 target = (u_matrix * vec3(a_target, 1)).xy;\n\n vec2 viewportPosition = clipspaceToViewport(position, u_dimensions);\n vec2 viewportSource = clipspaceToViewport(source, u_dimensions);\n vec2 viewportTarget = clipspaceToViewport(target, u_dimensions);\n\n vec2 delta = viewportTarget.xy - viewportSource.xy;\n float len = length(delta);\n vec2 normal = vec2(-delta.y, delta.x) * a_direction;\n vec2 unitNormal = normal / len;\n float boundingBoxThickness = len * a_curvature;\n\n float curveThickness = max(minThickness, a_thickness / u_sizeRatio);\n v_thickness = curveThickness * u_pixelRatio;\n v_feather = u_feather;\n\n v_cpA = viewportSource;\n v_cpB = 0.5 * (viewportSource + viewportTarget) + unitNormal * a_direction * boundingBoxThickness;\n v_cpC = viewportTarget;\n\n vec2 viewportOffsetPosition = (\n viewportPosition +\n unitNormal * (boundingBoxThickness / 2.0 + sign(boundingBoxThickness) * (").concat(arrowHead ? "curveThickness * u_widenessToThicknessRatio" : "curveThickness", " + epsilon)) *\n max(0.0, a_direction) // NOTE: cutting the bounding box in half to avoid overdraw\n );\n\n position = viewportToClipspace(viewportOffsetPosition, u_dimensions);\n gl_Position = vec4(position, 0, 1);\n \n").concat(arrowHead ? "\n v_targetSize = a_targetSize * u_pixelRatio / u_sizeRatio;\n v_targetPoint = viewportTarget;\n" : "", "\n\n #ifdef PICKING_MODE\n // For picking mode, we use the ID as the color:\n v_color = a_id;\n #else\n // For normal mode, we use the color:\n v_color = a_color;\n #endif\n\n v_color.a *= bias;\n}\n");
var SHADER = /*glsl*/"\nattribute vec4 a_id;\nattribute vec4 a_color;\nattribute float a_direction;\nattribute float a_thickness;\nattribute vec2 a_source;\nattribute vec2 a_target;\nattribute float a_current;\nattribute float a_curvature;\n".concat(hasTargetArrowHead ? "attribute float a_targetSize;\n" : "", "\n").concat(hasSourceArrowHead ? "attribute float a_sourceSize;\n" : "", "\n\nuniform mat3 u_matrix;\nuniform float u_sizeRatio;\nuniform float u_pixelRatio;\nuniform vec2 u_dimensions;\nuniform float u_minEdgeThickness;\nuniform float u_feather;\n\nvarying vec4 v_color;\nvarying float v_thickness;\nvarying float v_feather;\nvarying vec2 v_cpA;\nvarying vec2 v_cpB;\nvarying vec2 v_cpC;\n").concat(hasTargetArrowHead ? "\nvarying float v_targetSize;\nvarying vec2 v_targetPoint;" : "", "\n").concat(hasSourceArrowHead ? "\nvarying float v_sourceSize;\nvarying vec2 v_sourcePoint;" : "", "\n").concat(arrowHead ? "\nuniform float u_widenessToThicknessRatio;" : "", "\n\nconst float bias = 255.0 / 254.0;\nconst float epsilon = 0.7;\n\nvec2 clipspaceToViewport(vec2 pos, vec2 dimensions) {\n return vec2(\n (pos.x + 1.0) * dimensions.x / 2.0,\n (pos.y + 1.0) * dimensions.y / 2.0\n );\n}\n\nvec2 viewportToClipspace(vec2 pos, vec2 dimensions) {\n return vec2(\n pos.x / dimensions.x * 2.0 - 1.0,\n pos.y / dimensions.y * 2.0 - 1.0\n );\n}\n\nvoid main() {\n float minThickness = u_minEdgeThickness;\n\n // Selecting the correct position\n // Branchless \"position = a_source if a_current == 1.0 else a_target\"\n vec2 position = a_source * max(0.0, a_current) + a_target * max(0.0, 1.0 - a_current);\n position = (u_matrix * vec3(position, 1)).xy;\n\n vec2 source = (u_matrix * vec3(a_source, 1)).xy;\n vec2 target = (u_matrix * vec3(a_target, 1)).xy;\n\n vec2 viewportPosition = clipspaceToViewport(position, u_dimensions);\n vec2 viewportSource = clipspaceToViewport(source, u_dimensions);\n vec2 viewportTarget = clipspaceToViewport(target, u_dimensions);\n\n vec2 delta = viewportTarget.xy - viewportSource.xy;\n float len = length(delta);\n vec2 normal = vec2(-delta.y, delta.x) * a_direction;\n vec2 unitNormal = normal / len;\n float boundingBoxThickness = len * a_curvature;\n\n float curveThickness = max(minThickness, a_thickness / u_sizeRatio);\n v_thickness = curveThickness * u_pixelRatio;\n v_feather = u_feather;\n\n v_cpA = viewportSource;\n v_cpB = 0.5 * (viewportSource + viewportTarget) + unitNormal * a_direction * boundingBoxThickness;\n v_cpC = viewportTarget;\n\n vec2 viewportOffsetPosition = (\n viewportPosition +\n unitNormal * (boundingBoxThickness / 2.0 + sign(boundingBoxThickness) * (").concat(arrowHead ? "curveThickness * u_widenessToThicknessRatio" : "curveThickness", " + epsilon)) *\n max(0.0, a_direction) // NOTE: cutting the bounding box in half to avoid overdraw\n );\n\n position = viewportToClipspace(viewportOffsetPosition, u_dimensions);\n gl_Position = vec4(position, 0, 1);\n \n").concat(hasTargetArrowHead ? "\n v_targetSize = a_targetSize * u_pixelRatio / u_sizeRatio;\n v_targetPoint = viewportTarget;\n" : "", "\n").concat(hasSourceArrowHead ? "\n v_sourceSize = a_sourceSize * u_pixelRatio / u_sizeRatio;\n v_sourcePoint = viewportSource;\n" : "", "\n\n #ifdef PICKING_MODE\n // For picking mode, we use the ID as the color:\n v_color = a_id;\n #else\n // For normal mode, we use the color:\n v_color = a_color;\n #endif\n\n v_color.a *= bias;\n}\n");
return SHADER;

@@ -399,2 +405,4 @@ }

drawLabel = _ref.drawLabel;
var hasTargetArrowHead = (arrowHead === null || arrowHead === void 0 ? void 0 : arrowHead.extremity) === "target" || (arrowHead === null || arrowHead === void 0 ? void 0 : arrowHead.extremity) === "both";
var hasSourceArrowHead = (arrowHead === null || arrowHead === void 0 ? void 0 : arrowHead.extremity) === "source" || (arrowHead === null || arrowHead === void 0 ? void 0 : arrowHead.extremity) === "both";
var UNIFORMS = ["u_matrix", "u_sizeRatio", "u_dimensions", "u_pixelRatio", "u_feather", "u_minEdgeThickness"].concat(_toConsumableArray(arrowHead ? ["u_lengthToThicknessRatio", "u_widenessToThicknessRatio"] : []));

@@ -430,6 +438,10 @@ return /*#__PURE__*/function (_EdgeProgram) {

type: FLOAT
}].concat(_toConsumableArray(arrowHead ? [{
}].concat(_toConsumableArray(hasTargetArrowHead ? [{
name: "a_targetSize",
size: 1,
type: FLOAT
}] : []), _toConsumableArray(hasSourceArrowHead ? [{
name: "a_sourceSize",
size: 1,
type: FLOAT
}] : []), [{

@@ -487,3 +499,4 @@ name: "a_thickness",

array[startIndex++] = y2;
if (arrowHead) array[startIndex++] = targetData.size;
if (hasTargetArrowHead) array[startIndex++] = targetData.size;
if (hasSourceArrowHead) array[startIndex++] = sourceData.size;
array[startIndex++] = thickness;

@@ -527,2 +540,7 @@ array[startIndex++] = curvature;

});
var EdgeCurvedDoubleArrowProgram = createEdgeCurveProgram({
arrowHead: _objectSpread2(_objectSpread2({}, rendering.DEFAULT_EDGE_ARROW_HEAD_PROGRAM_OPTIONS), {}, {
extremity: "both"
})
});

@@ -533,2 +551,3 @@ exports.DEFAULT_EDGE_CURVATURE = DEFAULT_EDGE_CURVATURE;

exports.EdgeCurvedArrowProgram = EdgeCurvedArrowProgram;
exports.EdgeCurvedDoubleArrowProgram = EdgeCurvedDoubleArrowProgram;
exports.createDrawCurvedEdgeLabel = createDrawCurvedEdgeLabel;

@@ -535,0 +554,0 @@ exports.createEdgeCurveProgram = createEdgeCurveProgram;

@@ -8,6 +8,2 @@ 'use strict';

function _classCallCheck(a, n) {
if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function");
}
function _toPrimitive(t, r) {

@@ -29,2 +25,37 @@ if ("object" != typeof t || !t) return t;

function _defineProperty(e, r, t) {
return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
value: t,
enumerable: !0,
configurable: !0,
writable: !0
}) : e[r] = t, e;
}
function ownKeys(e, r) {
var t = Object.keys(e);
if (Object.getOwnPropertySymbols) {
var o = Object.getOwnPropertySymbols(e);
r && (o = o.filter(function (r) {
return Object.getOwnPropertyDescriptor(e, r).enumerable;
})), t.push.apply(t, o);
}
return t;
}
function _objectSpread2(e) {
for (var r = 1; r < arguments.length; r++) {
var t = null != arguments[r] ? arguments[r] : {};
r % 2 ? ownKeys(Object(t), !0).forEach(function (r) {
_defineProperty(e, r, t[r]);
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) {
Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
});
}
return e;
}
function _classCallCheck(a, n) {
if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function");
}
function _defineProperties(e, r) {

@@ -91,11 +122,2 @@ for (var t = 0; t < r.length; t++) {

function _defineProperty(e, r, t) {
return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
value: t,
enumerable: !0,
configurable: !0,
writable: !0
}) : e[r] = t, e;
}
function _arrayLikeToArray(r, a) {

@@ -131,24 +153,2 @@ (null == a || a > r.length) && (a = r.length);

function ownKeys(e, r) {
var t = Object.keys(e);
if (Object.getOwnPropertySymbols) {
var o = Object.getOwnPropertySymbols(e);
r && (o = o.filter(function (r) {
return Object.getOwnPropertyDescriptor(e, r).enumerable;
})), t.push.apply(t, o);
}
return t;
}
function _objectSpread2(e) {
for (var r = 1; r < arguments.length; r++) {
var t = null != arguments[r] ? arguments[r] : {};
r % 2 ? ownKeys(Object(t), !0).forEach(function (r) {
_defineProperty(e, r, t[r]);
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) {
Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
});
}
return e;
}
function getCurvePoint(t, p0, p1, p2) {

@@ -286,4 +286,7 @@ var x = Math.pow(1 - t, 2) * p0.x + 2 * (1 - t) * t * p1.x + Math.pow(t, 2) * p2.x;

var arrowHead = _ref.arrowHead;
var hasTargetArrowHead = (arrowHead === null || arrowHead === void 0 ? void 0 : arrowHead.extremity) === "target" || (arrowHead === null || arrowHead === void 0 ? void 0 : arrowHead.extremity) === "both";
var hasSourceArrowHead = (arrowHead === null || arrowHead === void 0 ? void 0 : arrowHead.extremity) === "source" || (arrowHead === null || arrowHead === void 0 ? void 0 : arrowHead.extremity) === "both";
// language=GLSL
var SHADER = /*glsl*/"\nprecision highp float;\n\nvarying vec4 v_color;\nvarying float v_thickness;\nvarying float v_feather;\nvarying vec2 v_cpA;\nvarying vec2 v_cpB;\nvarying vec2 v_cpC;\n".concat(arrowHead ? "\nvarying float v_targetSize;\nvarying vec2 v_targetPoint;\n\nuniform float u_lengthToThicknessRatio;\nuniform float u_widenessToThicknessRatio;" : "", "\n\nfloat det(vec2 a, vec2 b) {\n return a.x * b.y - b.x * a.y;\n}\n\nvec2 getDistanceVector(vec2 b0, vec2 b1, vec2 b2) {\n float a = det(b0, b2), b = 2.0 * det(b1, b0), d = 2.0 * det(b2, b1);\n float f = b * d - a * a;\n vec2 d21 = b2 - b1, d10 = b1 - b0, d20 = b2 - b0;\n vec2 gf = 2.0 * (b * d21 + d * d10 + a * d20);\n gf = vec2(gf.y, -gf.x);\n vec2 pp = -f * gf / dot(gf, gf);\n vec2 d0p = b0 - pp;\n float ap = det(d0p, d20), bp = 2.0 * det(d10, d0p);\n float t = clamp((ap + bp) / (2.0 * a + b + d), 0.0, 1.0);\n return mix(mix(b0, b1, t), mix(b1, b2, t), t);\n}\n\nfloat distToQuadraticBezierCurve(vec2 p, vec2 b0, vec2 b1, vec2 b2) {\n return length(getDistanceVector(b0 - p, b1 - p, b2 - p));\n}\n\nconst vec4 transparent = vec4(0.0, 0.0, 0.0, 0.0);\n\nvoid main(void) {\n float dist = distToQuadraticBezierCurve(gl_FragCoord.xy, v_cpA, v_cpB, v_cpC);\n float thickness = v_thickness;\n").concat(arrowHead ? "\n float distToTarget = length(gl_FragCoord.xy - v_targetPoint);\n float arrowLength = v_targetSize + thickness * u_lengthToThicknessRatio;\n if (distToTarget < arrowLength) {\n thickness = (distToTarget - v_targetSize) / (arrowLength - v_targetSize) * u_widenessToThicknessRatio * thickness;\n }" : "", "\n\n float halfThickness = thickness / 2.0;\n if (dist < halfThickness) {\n #ifdef PICKING_MODE\n gl_FragColor = v_color;\n #else\n float t = smoothstep(\n halfThickness - v_feather,\n halfThickness,\n dist\n );\n\n gl_FragColor = mix(v_color, transparent, t);\n #endif\n } else {\n gl_FragColor = transparent;\n }\n}\n");
var SHADER = /*glsl*/"\nprecision highp float;\n\nvarying vec4 v_color;\nvarying float v_thickness;\nvarying float v_feather;\nvarying vec2 v_cpA;\nvarying vec2 v_cpB;\nvarying vec2 v_cpC;\n".concat(hasTargetArrowHead ? "\nvarying float v_targetSize;\nvarying vec2 v_targetPoint;" : "", "\n").concat(hasSourceArrowHead ? "\nvarying float v_sourceSize;\nvarying vec2 v_sourcePoint;" : "", "\n").concat(arrowHead ? "\nuniform float u_lengthToThicknessRatio;\nuniform float u_widenessToThicknessRatio;" : "", "\n\nfloat det(vec2 a, vec2 b) {\n return a.x * b.y - b.x * a.y;\n}\n\nvec2 getDistanceVector(vec2 b0, vec2 b1, vec2 b2) {\n float a = det(b0, b2), b = 2.0 * det(b1, b0), d = 2.0 * det(b2, b1);\n float f = b * d - a * a;\n vec2 d21 = b2 - b1, d10 = b1 - b0, d20 = b2 - b0;\n vec2 gf = 2.0 * (b * d21 + d * d10 + a * d20);\n gf = vec2(gf.y, -gf.x);\n vec2 pp = -f * gf / dot(gf, gf);\n vec2 d0p = b0 - pp;\n float ap = det(d0p, d20), bp = 2.0 * det(d10, d0p);\n float t = clamp((ap + bp) / (2.0 * a + b + d), 0.0, 1.0);\n return mix(mix(b0, b1, t), mix(b1, b2, t), t);\n}\n\nfloat distToQuadraticBezierCurve(vec2 p, vec2 b0, vec2 b1, vec2 b2) {\n return length(getDistanceVector(b0 - p, b1 - p, b2 - p));\n}\n\nconst vec4 transparent = vec4(0.0, 0.0, 0.0, 0.0);\n\nvoid main(void) {\n float dist = distToQuadraticBezierCurve(gl_FragCoord.xy, v_cpA, v_cpB, v_cpC);\n float thickness = v_thickness;\n").concat(hasTargetArrowHead ? "\n float distToTarget = length(gl_FragCoord.xy - v_targetPoint);\n float targetArrowLength = v_targetSize + thickness * u_lengthToThicknessRatio;\n if (distToTarget < targetArrowLength) {\n thickness = (distToTarget - v_targetSize) / (targetArrowLength - v_targetSize) * u_widenessToThicknessRatio * thickness;\n }" : "", "\n").concat(hasSourceArrowHead ? "\n float distToSource = length(gl_FragCoord.xy - v_sourcePoint);\n float sourceArrowLength = v_sourceSize + thickness * u_lengthToThicknessRatio;\n if (distToSource < sourceArrowLength) {\n thickness = (distToSource - v_sourceSize) / (sourceArrowLength - v_sourceSize) * u_widenessToThicknessRatio * thickness;\n }" : "", "\n\n float halfThickness = thickness / 2.0;\n if (dist < halfThickness) {\n #ifdef PICKING_MODE\n gl_FragColor = v_color;\n #else\n float t = smoothstep(\n halfThickness - v_feather,\n halfThickness,\n dist\n );\n\n gl_FragColor = mix(v_color, transparent, t);\n #endif\n } else {\n gl_FragColor = transparent;\n }\n}\n");
return SHADER;

@@ -294,4 +297,7 @@ }

var arrowHead = _ref.arrowHead;
var hasTargetArrowHead = (arrowHead === null || arrowHead === void 0 ? void 0 : arrowHead.extremity) === "target" || (arrowHead === null || arrowHead === void 0 ? void 0 : arrowHead.extremity) === "both";
var hasSourceArrowHead = (arrowHead === null || arrowHead === void 0 ? void 0 : arrowHead.extremity) === "source" || (arrowHead === null || arrowHead === void 0 ? void 0 : arrowHead.extremity) === "both";
// language=GLSL
var SHADER = /*glsl*/"\nattribute vec4 a_id;\nattribute vec4 a_color;\nattribute float a_direction;\nattribute float a_thickness;\nattribute vec2 a_source;\nattribute vec2 a_target;\nattribute float a_current;\nattribute float a_curvature;\n".concat(arrowHead ? "attribute float a_targetSize;\n" : "", "\n\nuniform mat3 u_matrix;\nuniform float u_sizeRatio;\nuniform float u_pixelRatio;\nuniform vec2 u_dimensions;\nuniform float u_minEdgeThickness;\nuniform float u_feather;\n\nvarying vec4 v_color;\nvarying float v_thickness;\nvarying float v_feather;\nvarying vec2 v_cpA;\nvarying vec2 v_cpB;\nvarying vec2 v_cpC;\n").concat(arrowHead ? "\nvarying float v_targetSize;\nvarying vec2 v_targetPoint;\nuniform float u_widenessToThicknessRatio;\n" : "", "\n\nconst float bias = 255.0 / 254.0;\nconst float epsilon = 0.7;\n\nvec2 clipspaceToViewport(vec2 pos, vec2 dimensions) {\n return vec2(\n (pos.x + 1.0) * dimensions.x / 2.0,\n (pos.y + 1.0) * dimensions.y / 2.0\n );\n}\n\nvec2 viewportToClipspace(vec2 pos, vec2 dimensions) {\n return vec2(\n pos.x / dimensions.x * 2.0 - 1.0,\n pos.y / dimensions.y * 2.0 - 1.0\n );\n}\n\nvoid main() {\n float minThickness = u_minEdgeThickness;\n\n // Selecting the correct position\n // Branchless \"position = a_source if a_current == 1.0 else a_target\"\n vec2 position = a_source * max(0.0, a_current) + a_target * max(0.0, 1.0 - a_current);\n position = (u_matrix * vec3(position, 1)).xy;\n\n vec2 source = (u_matrix * vec3(a_source, 1)).xy;\n vec2 target = (u_matrix * vec3(a_target, 1)).xy;\n\n vec2 viewportPosition = clipspaceToViewport(position, u_dimensions);\n vec2 viewportSource = clipspaceToViewport(source, u_dimensions);\n vec2 viewportTarget = clipspaceToViewport(target, u_dimensions);\n\n vec2 delta = viewportTarget.xy - viewportSource.xy;\n float len = length(delta);\n vec2 normal = vec2(-delta.y, delta.x) * a_direction;\n vec2 unitNormal = normal / len;\n float boundingBoxThickness = len * a_curvature;\n\n float curveThickness = max(minThickness, a_thickness / u_sizeRatio);\n v_thickness = curveThickness * u_pixelRatio;\n v_feather = u_feather;\n\n v_cpA = viewportSource;\n v_cpB = 0.5 * (viewportSource + viewportTarget) + unitNormal * a_direction * boundingBoxThickness;\n v_cpC = viewportTarget;\n\n vec2 viewportOffsetPosition = (\n viewportPosition +\n unitNormal * (boundingBoxThickness / 2.0 + sign(boundingBoxThickness) * (").concat(arrowHead ? "curveThickness * u_widenessToThicknessRatio" : "curveThickness", " + epsilon)) *\n max(0.0, a_direction) // NOTE: cutting the bounding box in half to avoid overdraw\n );\n\n position = viewportToClipspace(viewportOffsetPosition, u_dimensions);\n gl_Position = vec4(position, 0, 1);\n \n").concat(arrowHead ? "\n v_targetSize = a_targetSize * u_pixelRatio / u_sizeRatio;\n v_targetPoint = viewportTarget;\n" : "", "\n\n #ifdef PICKING_MODE\n // For picking mode, we use the ID as the color:\n v_color = a_id;\n #else\n // For normal mode, we use the color:\n v_color = a_color;\n #endif\n\n v_color.a *= bias;\n}\n");
var SHADER = /*glsl*/"\nattribute vec4 a_id;\nattribute vec4 a_color;\nattribute float a_direction;\nattribute float a_thickness;\nattribute vec2 a_source;\nattribute vec2 a_target;\nattribute float a_current;\nattribute float a_curvature;\n".concat(hasTargetArrowHead ? "attribute float a_targetSize;\n" : "", "\n").concat(hasSourceArrowHead ? "attribute float a_sourceSize;\n" : "", "\n\nuniform mat3 u_matrix;\nuniform float u_sizeRatio;\nuniform float u_pixelRatio;\nuniform vec2 u_dimensions;\nuniform float u_minEdgeThickness;\nuniform float u_feather;\n\nvarying vec4 v_color;\nvarying float v_thickness;\nvarying float v_feather;\nvarying vec2 v_cpA;\nvarying vec2 v_cpB;\nvarying vec2 v_cpC;\n").concat(hasTargetArrowHead ? "\nvarying float v_targetSize;\nvarying vec2 v_targetPoint;" : "", "\n").concat(hasSourceArrowHead ? "\nvarying float v_sourceSize;\nvarying vec2 v_sourcePoint;" : "", "\n").concat(arrowHead ? "\nuniform float u_widenessToThicknessRatio;" : "", "\n\nconst float bias = 255.0 / 254.0;\nconst float epsilon = 0.7;\n\nvec2 clipspaceToViewport(vec2 pos, vec2 dimensions) {\n return vec2(\n (pos.x + 1.0) * dimensions.x / 2.0,\n (pos.y + 1.0) * dimensions.y / 2.0\n );\n}\n\nvec2 viewportToClipspace(vec2 pos, vec2 dimensions) {\n return vec2(\n pos.x / dimensions.x * 2.0 - 1.0,\n pos.y / dimensions.y * 2.0 - 1.0\n );\n}\n\nvoid main() {\n float minThickness = u_minEdgeThickness;\n\n // Selecting the correct position\n // Branchless \"position = a_source if a_current == 1.0 else a_target\"\n vec2 position = a_source * max(0.0, a_current) + a_target * max(0.0, 1.0 - a_current);\n position = (u_matrix * vec3(position, 1)).xy;\n\n vec2 source = (u_matrix * vec3(a_source, 1)).xy;\n vec2 target = (u_matrix * vec3(a_target, 1)).xy;\n\n vec2 viewportPosition = clipspaceToViewport(position, u_dimensions);\n vec2 viewportSource = clipspaceToViewport(source, u_dimensions);\n vec2 viewportTarget = clipspaceToViewport(target, u_dimensions);\n\n vec2 delta = viewportTarget.xy - viewportSource.xy;\n float len = length(delta);\n vec2 normal = vec2(-delta.y, delta.x) * a_direction;\n vec2 unitNormal = normal / len;\n float boundingBoxThickness = len * a_curvature;\n\n float curveThickness = max(minThickness, a_thickness / u_sizeRatio);\n v_thickness = curveThickness * u_pixelRatio;\n v_feather = u_feather;\n\n v_cpA = viewportSource;\n v_cpB = 0.5 * (viewportSource + viewportTarget) + unitNormal * a_direction * boundingBoxThickness;\n v_cpC = viewportTarget;\n\n vec2 viewportOffsetPosition = (\n viewportPosition +\n unitNormal * (boundingBoxThickness / 2.0 + sign(boundingBoxThickness) * (").concat(arrowHead ? "curveThickness * u_widenessToThicknessRatio" : "curveThickness", " + epsilon)) *\n max(0.0, a_direction) // NOTE: cutting the bounding box in half to avoid overdraw\n );\n\n position = viewportToClipspace(viewportOffsetPosition, u_dimensions);\n gl_Position = vec4(position, 0, 1);\n \n").concat(hasTargetArrowHead ? "\n v_targetSize = a_targetSize * u_pixelRatio / u_sizeRatio;\n v_targetPoint = viewportTarget;\n" : "", "\n").concat(hasSourceArrowHead ? "\n v_sourceSize = a_sourceSize * u_pixelRatio / u_sizeRatio;\n v_sourcePoint = viewportSource;\n" : "", "\n\n #ifdef PICKING_MODE\n // For picking mode, we use the ID as the color:\n v_color = a_id;\n #else\n // For normal mode, we use the color:\n v_color = a_color;\n #endif\n\n v_color.a *= bias;\n}\n");
return SHADER;

@@ -399,2 +405,4 @@ }

drawLabel = _ref.drawLabel;
var hasTargetArrowHead = (arrowHead === null || arrowHead === void 0 ? void 0 : arrowHead.extremity) === "target" || (arrowHead === null || arrowHead === void 0 ? void 0 : arrowHead.extremity) === "both";
var hasSourceArrowHead = (arrowHead === null || arrowHead === void 0 ? void 0 : arrowHead.extremity) === "source" || (arrowHead === null || arrowHead === void 0 ? void 0 : arrowHead.extremity) === "both";
var UNIFORMS = ["u_matrix", "u_sizeRatio", "u_dimensions", "u_pixelRatio", "u_feather", "u_minEdgeThickness"].concat(_toConsumableArray(arrowHead ? ["u_lengthToThicknessRatio", "u_widenessToThicknessRatio"] : []));

@@ -430,6 +438,10 @@ return /*#__PURE__*/function (_EdgeProgram) {

type: FLOAT
}].concat(_toConsumableArray(arrowHead ? [{
}].concat(_toConsumableArray(hasTargetArrowHead ? [{
name: "a_targetSize",
size: 1,
type: FLOAT
}] : []), _toConsumableArray(hasSourceArrowHead ? [{
name: "a_sourceSize",
size: 1,
type: FLOAT
}] : []), [{

@@ -487,3 +499,4 @@ name: "a_thickness",

array[startIndex++] = y2;
if (arrowHead) array[startIndex++] = targetData.size;
if (hasTargetArrowHead) array[startIndex++] = targetData.size;
if (hasSourceArrowHead) array[startIndex++] = sourceData.size;
array[startIndex++] = thickness;

@@ -527,2 +540,7 @@ array[startIndex++] = curvature;

});
var EdgeCurvedDoubleArrowProgram = createEdgeCurveProgram({
arrowHead: _objectSpread2(_objectSpread2({}, rendering.DEFAULT_EDGE_ARROW_HEAD_PROGRAM_OPTIONS), {}, {
extremity: "both"
})
});

@@ -533,2 +551,3 @@ exports.DEFAULT_EDGE_CURVATURE = DEFAULT_EDGE_CURVATURE;

exports.EdgeCurvedArrowProgram = EdgeCurvedArrowProgram;
exports.EdgeCurvedDoubleArrowProgram = EdgeCurvedDoubleArrowProgram;
exports.createDrawCurvedEdgeLabel = createDrawCurvedEdgeLabel;

@@ -535,0 +554,0 @@ exports.createEdgeCurveProgram = createEdgeCurveProgram;

import { EdgeProgram, DEFAULT_EDGE_ARROW_HEAD_PROGRAM_OPTIONS } from 'sigma/rendering';
import { floatColor } from 'sigma/utils';
function _classCallCheck(a, n) {
if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function");
}
function _toPrimitive(t, r) {

@@ -24,2 +20,37 @@ if ("object" != typeof t || !t) return t;

function _defineProperty(e, r, t) {
return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
value: t,
enumerable: !0,
configurable: !0,
writable: !0
}) : e[r] = t, e;
}
function ownKeys(e, r) {
var t = Object.keys(e);
if (Object.getOwnPropertySymbols) {
var o = Object.getOwnPropertySymbols(e);
r && (o = o.filter(function (r) {
return Object.getOwnPropertyDescriptor(e, r).enumerable;
})), t.push.apply(t, o);
}
return t;
}
function _objectSpread2(e) {
for (var r = 1; r < arguments.length; r++) {
var t = null != arguments[r] ? arguments[r] : {};
r % 2 ? ownKeys(Object(t), !0).forEach(function (r) {
_defineProperty(e, r, t[r]);
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) {
Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
});
}
return e;
}
function _classCallCheck(a, n) {
if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function");
}
function _defineProperties(e, r) {

@@ -86,11 +117,2 @@ for (var t = 0; t < r.length; t++) {

function _defineProperty(e, r, t) {
return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
value: t,
enumerable: !0,
configurable: !0,
writable: !0
}) : e[r] = t, e;
}
function _arrayLikeToArray(r, a) {

@@ -126,24 +148,2 @@ (null == a || a > r.length) && (a = r.length);

function ownKeys(e, r) {
var t = Object.keys(e);
if (Object.getOwnPropertySymbols) {
var o = Object.getOwnPropertySymbols(e);
r && (o = o.filter(function (r) {
return Object.getOwnPropertyDescriptor(e, r).enumerable;
})), t.push.apply(t, o);
}
return t;
}
function _objectSpread2(e) {
for (var r = 1; r < arguments.length; r++) {
var t = null != arguments[r] ? arguments[r] : {};
r % 2 ? ownKeys(Object(t), !0).forEach(function (r) {
_defineProperty(e, r, t[r]);
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) {
Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
});
}
return e;
}
function getCurvePoint(t, p0, p1, p2) {

@@ -281,4 +281,7 @@ var x = Math.pow(1 - t, 2) * p0.x + 2 * (1 - t) * t * p1.x + Math.pow(t, 2) * p2.x;

var arrowHead = _ref.arrowHead;
var hasTargetArrowHead = (arrowHead === null || arrowHead === void 0 ? void 0 : arrowHead.extremity) === "target" || (arrowHead === null || arrowHead === void 0 ? void 0 : arrowHead.extremity) === "both";
var hasSourceArrowHead = (arrowHead === null || arrowHead === void 0 ? void 0 : arrowHead.extremity) === "source" || (arrowHead === null || arrowHead === void 0 ? void 0 : arrowHead.extremity) === "both";
// language=GLSL
var SHADER = /*glsl*/"\nprecision highp float;\n\nvarying vec4 v_color;\nvarying float v_thickness;\nvarying float v_feather;\nvarying vec2 v_cpA;\nvarying vec2 v_cpB;\nvarying vec2 v_cpC;\n".concat(arrowHead ? "\nvarying float v_targetSize;\nvarying vec2 v_targetPoint;\n\nuniform float u_lengthToThicknessRatio;\nuniform float u_widenessToThicknessRatio;" : "", "\n\nfloat det(vec2 a, vec2 b) {\n return a.x * b.y - b.x * a.y;\n}\n\nvec2 getDistanceVector(vec2 b0, vec2 b1, vec2 b2) {\n float a = det(b0, b2), b = 2.0 * det(b1, b0), d = 2.0 * det(b2, b1);\n float f = b * d - a * a;\n vec2 d21 = b2 - b1, d10 = b1 - b0, d20 = b2 - b0;\n vec2 gf = 2.0 * (b * d21 + d * d10 + a * d20);\n gf = vec2(gf.y, -gf.x);\n vec2 pp = -f * gf / dot(gf, gf);\n vec2 d0p = b0 - pp;\n float ap = det(d0p, d20), bp = 2.0 * det(d10, d0p);\n float t = clamp((ap + bp) / (2.0 * a + b + d), 0.0, 1.0);\n return mix(mix(b0, b1, t), mix(b1, b2, t), t);\n}\n\nfloat distToQuadraticBezierCurve(vec2 p, vec2 b0, vec2 b1, vec2 b2) {\n return length(getDistanceVector(b0 - p, b1 - p, b2 - p));\n}\n\nconst vec4 transparent = vec4(0.0, 0.0, 0.0, 0.0);\n\nvoid main(void) {\n float dist = distToQuadraticBezierCurve(gl_FragCoord.xy, v_cpA, v_cpB, v_cpC);\n float thickness = v_thickness;\n").concat(arrowHead ? "\n float distToTarget = length(gl_FragCoord.xy - v_targetPoint);\n float arrowLength = v_targetSize + thickness * u_lengthToThicknessRatio;\n if (distToTarget < arrowLength) {\n thickness = (distToTarget - v_targetSize) / (arrowLength - v_targetSize) * u_widenessToThicknessRatio * thickness;\n }" : "", "\n\n float halfThickness = thickness / 2.0;\n if (dist < halfThickness) {\n #ifdef PICKING_MODE\n gl_FragColor = v_color;\n #else\n float t = smoothstep(\n halfThickness - v_feather,\n halfThickness,\n dist\n );\n\n gl_FragColor = mix(v_color, transparent, t);\n #endif\n } else {\n gl_FragColor = transparent;\n }\n}\n");
var SHADER = /*glsl*/"\nprecision highp float;\n\nvarying vec4 v_color;\nvarying float v_thickness;\nvarying float v_feather;\nvarying vec2 v_cpA;\nvarying vec2 v_cpB;\nvarying vec2 v_cpC;\n".concat(hasTargetArrowHead ? "\nvarying float v_targetSize;\nvarying vec2 v_targetPoint;" : "", "\n").concat(hasSourceArrowHead ? "\nvarying float v_sourceSize;\nvarying vec2 v_sourcePoint;" : "", "\n").concat(arrowHead ? "\nuniform float u_lengthToThicknessRatio;\nuniform float u_widenessToThicknessRatio;" : "", "\n\nfloat det(vec2 a, vec2 b) {\n return a.x * b.y - b.x * a.y;\n}\n\nvec2 getDistanceVector(vec2 b0, vec2 b1, vec2 b2) {\n float a = det(b0, b2), b = 2.0 * det(b1, b0), d = 2.0 * det(b2, b1);\n float f = b * d - a * a;\n vec2 d21 = b2 - b1, d10 = b1 - b0, d20 = b2 - b0;\n vec2 gf = 2.0 * (b * d21 + d * d10 + a * d20);\n gf = vec2(gf.y, -gf.x);\n vec2 pp = -f * gf / dot(gf, gf);\n vec2 d0p = b0 - pp;\n float ap = det(d0p, d20), bp = 2.0 * det(d10, d0p);\n float t = clamp((ap + bp) / (2.0 * a + b + d), 0.0, 1.0);\n return mix(mix(b0, b1, t), mix(b1, b2, t), t);\n}\n\nfloat distToQuadraticBezierCurve(vec2 p, vec2 b0, vec2 b1, vec2 b2) {\n return length(getDistanceVector(b0 - p, b1 - p, b2 - p));\n}\n\nconst vec4 transparent = vec4(0.0, 0.0, 0.0, 0.0);\n\nvoid main(void) {\n float dist = distToQuadraticBezierCurve(gl_FragCoord.xy, v_cpA, v_cpB, v_cpC);\n float thickness = v_thickness;\n").concat(hasTargetArrowHead ? "\n float distToTarget = length(gl_FragCoord.xy - v_targetPoint);\n float targetArrowLength = v_targetSize + thickness * u_lengthToThicknessRatio;\n if (distToTarget < targetArrowLength) {\n thickness = (distToTarget - v_targetSize) / (targetArrowLength - v_targetSize) * u_widenessToThicknessRatio * thickness;\n }" : "", "\n").concat(hasSourceArrowHead ? "\n float distToSource = length(gl_FragCoord.xy - v_sourcePoint);\n float sourceArrowLength = v_sourceSize + thickness * u_lengthToThicknessRatio;\n if (distToSource < sourceArrowLength) {\n thickness = (distToSource - v_sourceSize) / (sourceArrowLength - v_sourceSize) * u_widenessToThicknessRatio * thickness;\n }" : "", "\n\n float halfThickness = thickness / 2.0;\n if (dist < halfThickness) {\n #ifdef PICKING_MODE\n gl_FragColor = v_color;\n #else\n float t = smoothstep(\n halfThickness - v_feather,\n halfThickness,\n dist\n );\n\n gl_FragColor = mix(v_color, transparent, t);\n #endif\n } else {\n gl_FragColor = transparent;\n }\n}\n");
return SHADER;

@@ -289,4 +292,7 @@ }

var arrowHead = _ref.arrowHead;
var hasTargetArrowHead = (arrowHead === null || arrowHead === void 0 ? void 0 : arrowHead.extremity) === "target" || (arrowHead === null || arrowHead === void 0 ? void 0 : arrowHead.extremity) === "both";
var hasSourceArrowHead = (arrowHead === null || arrowHead === void 0 ? void 0 : arrowHead.extremity) === "source" || (arrowHead === null || arrowHead === void 0 ? void 0 : arrowHead.extremity) === "both";
// language=GLSL
var SHADER = /*glsl*/"\nattribute vec4 a_id;\nattribute vec4 a_color;\nattribute float a_direction;\nattribute float a_thickness;\nattribute vec2 a_source;\nattribute vec2 a_target;\nattribute float a_current;\nattribute float a_curvature;\n".concat(arrowHead ? "attribute float a_targetSize;\n" : "", "\n\nuniform mat3 u_matrix;\nuniform float u_sizeRatio;\nuniform float u_pixelRatio;\nuniform vec2 u_dimensions;\nuniform float u_minEdgeThickness;\nuniform float u_feather;\n\nvarying vec4 v_color;\nvarying float v_thickness;\nvarying float v_feather;\nvarying vec2 v_cpA;\nvarying vec2 v_cpB;\nvarying vec2 v_cpC;\n").concat(arrowHead ? "\nvarying float v_targetSize;\nvarying vec2 v_targetPoint;\nuniform float u_widenessToThicknessRatio;\n" : "", "\n\nconst float bias = 255.0 / 254.0;\nconst float epsilon = 0.7;\n\nvec2 clipspaceToViewport(vec2 pos, vec2 dimensions) {\n return vec2(\n (pos.x + 1.0) * dimensions.x / 2.0,\n (pos.y + 1.0) * dimensions.y / 2.0\n );\n}\n\nvec2 viewportToClipspace(vec2 pos, vec2 dimensions) {\n return vec2(\n pos.x / dimensions.x * 2.0 - 1.0,\n pos.y / dimensions.y * 2.0 - 1.0\n );\n}\n\nvoid main() {\n float minThickness = u_minEdgeThickness;\n\n // Selecting the correct position\n // Branchless \"position = a_source if a_current == 1.0 else a_target\"\n vec2 position = a_source * max(0.0, a_current) + a_target * max(0.0, 1.0 - a_current);\n position = (u_matrix * vec3(position, 1)).xy;\n\n vec2 source = (u_matrix * vec3(a_source, 1)).xy;\n vec2 target = (u_matrix * vec3(a_target, 1)).xy;\n\n vec2 viewportPosition = clipspaceToViewport(position, u_dimensions);\n vec2 viewportSource = clipspaceToViewport(source, u_dimensions);\n vec2 viewportTarget = clipspaceToViewport(target, u_dimensions);\n\n vec2 delta = viewportTarget.xy - viewportSource.xy;\n float len = length(delta);\n vec2 normal = vec2(-delta.y, delta.x) * a_direction;\n vec2 unitNormal = normal / len;\n float boundingBoxThickness = len * a_curvature;\n\n float curveThickness = max(minThickness, a_thickness / u_sizeRatio);\n v_thickness = curveThickness * u_pixelRatio;\n v_feather = u_feather;\n\n v_cpA = viewportSource;\n v_cpB = 0.5 * (viewportSource + viewportTarget) + unitNormal * a_direction * boundingBoxThickness;\n v_cpC = viewportTarget;\n\n vec2 viewportOffsetPosition = (\n viewportPosition +\n unitNormal * (boundingBoxThickness / 2.0 + sign(boundingBoxThickness) * (").concat(arrowHead ? "curveThickness * u_widenessToThicknessRatio" : "curveThickness", " + epsilon)) *\n max(0.0, a_direction) // NOTE: cutting the bounding box in half to avoid overdraw\n );\n\n position = viewportToClipspace(viewportOffsetPosition, u_dimensions);\n gl_Position = vec4(position, 0, 1);\n \n").concat(arrowHead ? "\n v_targetSize = a_targetSize * u_pixelRatio / u_sizeRatio;\n v_targetPoint = viewportTarget;\n" : "", "\n\n #ifdef PICKING_MODE\n // For picking mode, we use the ID as the color:\n v_color = a_id;\n #else\n // For normal mode, we use the color:\n v_color = a_color;\n #endif\n\n v_color.a *= bias;\n}\n");
var SHADER = /*glsl*/"\nattribute vec4 a_id;\nattribute vec4 a_color;\nattribute float a_direction;\nattribute float a_thickness;\nattribute vec2 a_source;\nattribute vec2 a_target;\nattribute float a_current;\nattribute float a_curvature;\n".concat(hasTargetArrowHead ? "attribute float a_targetSize;\n" : "", "\n").concat(hasSourceArrowHead ? "attribute float a_sourceSize;\n" : "", "\n\nuniform mat3 u_matrix;\nuniform float u_sizeRatio;\nuniform float u_pixelRatio;\nuniform vec2 u_dimensions;\nuniform float u_minEdgeThickness;\nuniform float u_feather;\n\nvarying vec4 v_color;\nvarying float v_thickness;\nvarying float v_feather;\nvarying vec2 v_cpA;\nvarying vec2 v_cpB;\nvarying vec2 v_cpC;\n").concat(hasTargetArrowHead ? "\nvarying float v_targetSize;\nvarying vec2 v_targetPoint;" : "", "\n").concat(hasSourceArrowHead ? "\nvarying float v_sourceSize;\nvarying vec2 v_sourcePoint;" : "", "\n").concat(arrowHead ? "\nuniform float u_widenessToThicknessRatio;" : "", "\n\nconst float bias = 255.0 / 254.0;\nconst float epsilon = 0.7;\n\nvec2 clipspaceToViewport(vec2 pos, vec2 dimensions) {\n return vec2(\n (pos.x + 1.0) * dimensions.x / 2.0,\n (pos.y + 1.0) * dimensions.y / 2.0\n );\n}\n\nvec2 viewportToClipspace(vec2 pos, vec2 dimensions) {\n return vec2(\n pos.x / dimensions.x * 2.0 - 1.0,\n pos.y / dimensions.y * 2.0 - 1.0\n );\n}\n\nvoid main() {\n float minThickness = u_minEdgeThickness;\n\n // Selecting the correct position\n // Branchless \"position = a_source if a_current == 1.0 else a_target\"\n vec2 position = a_source * max(0.0, a_current) + a_target * max(0.0, 1.0 - a_current);\n position = (u_matrix * vec3(position, 1)).xy;\n\n vec2 source = (u_matrix * vec3(a_source, 1)).xy;\n vec2 target = (u_matrix * vec3(a_target, 1)).xy;\n\n vec2 viewportPosition = clipspaceToViewport(position, u_dimensions);\n vec2 viewportSource = clipspaceToViewport(source, u_dimensions);\n vec2 viewportTarget = clipspaceToViewport(target, u_dimensions);\n\n vec2 delta = viewportTarget.xy - viewportSource.xy;\n float len = length(delta);\n vec2 normal = vec2(-delta.y, delta.x) * a_direction;\n vec2 unitNormal = normal / len;\n float boundingBoxThickness = len * a_curvature;\n\n float curveThickness = max(minThickness, a_thickness / u_sizeRatio);\n v_thickness = curveThickness * u_pixelRatio;\n v_feather = u_feather;\n\n v_cpA = viewportSource;\n v_cpB = 0.5 * (viewportSource + viewportTarget) + unitNormal * a_direction * boundingBoxThickness;\n v_cpC = viewportTarget;\n\n vec2 viewportOffsetPosition = (\n viewportPosition +\n unitNormal * (boundingBoxThickness / 2.0 + sign(boundingBoxThickness) * (").concat(arrowHead ? "curveThickness * u_widenessToThicknessRatio" : "curveThickness", " + epsilon)) *\n max(0.0, a_direction) // NOTE: cutting the bounding box in half to avoid overdraw\n );\n\n position = viewportToClipspace(viewportOffsetPosition, u_dimensions);\n gl_Position = vec4(position, 0, 1);\n \n").concat(hasTargetArrowHead ? "\n v_targetSize = a_targetSize * u_pixelRatio / u_sizeRatio;\n v_targetPoint = viewportTarget;\n" : "", "\n").concat(hasSourceArrowHead ? "\n v_sourceSize = a_sourceSize * u_pixelRatio / u_sizeRatio;\n v_sourcePoint = viewportSource;\n" : "", "\n\n #ifdef PICKING_MODE\n // For picking mode, we use the ID as the color:\n v_color = a_id;\n #else\n // For normal mode, we use the color:\n v_color = a_color;\n #endif\n\n v_color.a *= bias;\n}\n");
return SHADER;

@@ -394,2 +400,4 @@ }

drawLabel = _ref.drawLabel;
var hasTargetArrowHead = (arrowHead === null || arrowHead === void 0 ? void 0 : arrowHead.extremity) === "target" || (arrowHead === null || arrowHead === void 0 ? void 0 : arrowHead.extremity) === "both";
var hasSourceArrowHead = (arrowHead === null || arrowHead === void 0 ? void 0 : arrowHead.extremity) === "source" || (arrowHead === null || arrowHead === void 0 ? void 0 : arrowHead.extremity) === "both";
var UNIFORMS = ["u_matrix", "u_sizeRatio", "u_dimensions", "u_pixelRatio", "u_feather", "u_minEdgeThickness"].concat(_toConsumableArray(arrowHead ? ["u_lengthToThicknessRatio", "u_widenessToThicknessRatio"] : []));

@@ -425,6 +433,10 @@ return /*#__PURE__*/function (_EdgeProgram) {

type: FLOAT
}].concat(_toConsumableArray(arrowHead ? [{
}].concat(_toConsumableArray(hasTargetArrowHead ? [{
name: "a_targetSize",
size: 1,
type: FLOAT
}] : []), _toConsumableArray(hasSourceArrowHead ? [{
name: "a_sourceSize",
size: 1,
type: FLOAT
}] : []), [{

@@ -482,3 +494,4 @@ name: "a_thickness",

array[startIndex++] = y2;
if (arrowHead) array[startIndex++] = targetData.size;
if (hasTargetArrowHead) array[startIndex++] = targetData.size;
if (hasSourceArrowHead) array[startIndex++] = sourceData.size;
array[startIndex++] = thickness;

@@ -522,3 +535,8 @@ array[startIndex++] = curvature;

});
var EdgeCurvedDoubleArrowProgram = createEdgeCurveProgram({
arrowHead: _objectSpread2(_objectSpread2({}, DEFAULT_EDGE_ARROW_HEAD_PROGRAM_OPTIONS), {}, {
extremity: "both"
})
});
export { DEFAULT_EDGE_CURVATURE, DEFAULT_EDGE_CURVE_PROGRAM_OPTIONS, DEFAULT_INDEX_PARALLEL_EDGES_OPTIONS, EdgeCurvedArrowProgram, createDrawCurvedEdgeLabel, createEdgeCurveProgram, EdgeCurveProgram as default, indexParallelEdgesIndex };
export { DEFAULT_EDGE_CURVATURE, DEFAULT_EDGE_CURVE_PROGRAM_OPTIONS, DEFAULT_INDEX_PARALLEL_EDGES_OPTIONS, EdgeCurvedArrowProgram, EdgeCurvedDoubleArrowProgram, createDrawCurvedEdgeLabel, createEdgeCurveProgram, EdgeCurveProgram as default, indexParallelEdgesIndex };
{
"name": "@sigma/edge-curve",
"version": "3.0.0",
"version": "3.1.0",
"description": "An edge program that renders edges as curves for sigma.js",

@@ -51,3 +51,3 @@ "main": "dist/sigma-edge-curve.cjs.js",

},
"gitHead": "f0187cb13da41310bf375caf7105db2f18bc89d2"
"gitHead": "e1aa032da3a2755b45cec0a4b01b69410e873877"
}

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc