@react-fabric/graph 1.0.0-beta.58
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +10 -0
- package/css/styles.css +56 -0
- package/dist/cjs/_virtual/_commonjs-dynamic-modules.js +7 -0
- package/dist/cjs/_virtual/_commonjsHelpers.js +7 -0
- package/dist/cjs/_virtual/_rollup-plugin-web-worker-loader__helper__auto__createBase64WorkerFactory.js +14 -0
- package/dist/cjs/_virtual/_rollup-plugin-web-worker-loader__helper__auto__isNodeJS.js +9 -0
- package/dist/cjs/_virtual/_rollup-plugin-web-worker-loader__helper__browser__createBase64WorkerFactory.js +35 -0
- package/dist/cjs/_virtual/_rollup-plugin-web-worker-loader__helper__node__WorkerClass.js +11 -0
- package/dist/cjs/_virtual/_rollup-plugin-web-worker-loader__helper__node__createBase64WorkerFactory.js +20 -0
- package/dist/cjs/_virtual/elk-worker.js +8 -0
- package/dist/cjs/_virtual/elk.bundled.js +5 -0
- package/dist/cjs/node_modules/elkjs/lib/elk.bundled.js +6667 -0
- package/dist/cjs/packages/graph/src/components/Context.js +108 -0
- package/dist/cjs/packages/graph/src/components/ContextMenu.js +134 -0
- package/dist/cjs/packages/graph/src/components/Tools.js +127 -0
- package/dist/cjs/packages/graph/src/components/Viewer.js +57 -0
- package/dist/cjs/packages/graph/src/constants/index.js +16 -0
- package/dist/cjs/packages/graph/src/graph/index.js +425 -0
- package/dist/cjs/packages/graph/src/hooks/sigmaDragSelect.js +169 -0
- package/dist/cjs/packages/graph/src/hooks/sigmaHilighter.js +83 -0
- package/dist/cjs/packages/graph/src/hooks/sigmaMouseActions.js +145 -0
- package/dist/cjs/packages/graph/src/hooks/useGraphology.js +41 -0
- package/dist/cjs/packages/graph/src/hooks/useSigma.js +112 -0
- package/dist/cjs/packages/graph/src/index.js +33 -0
- package/dist/cjs/packages/graph/src/programs/arrow-head/frag.glsl.js +8 -0
- package/dist/cjs/packages/graph/src/programs/arrow-head/index.js +142 -0
- package/dist/cjs/packages/graph/src/programs/arrow-head/vert.glsl.js +8 -0
- package/dist/cjs/packages/graph/src/programs/edge-curve/drawLabel.js +136 -0
- package/dist/cjs/packages/graph/src/programs/edge-curve/frag.glsl.js +8 -0
- package/dist/cjs/packages/graph/src/programs/edge-curve/index.js +157 -0
- package/dist/cjs/packages/graph/src/programs/edge-curve/vert.glsl.js +8 -0
- package/dist/cjs/packages/graph/src/programs/edge-line/drawLabel.js +70 -0
- package/dist/cjs/packages/graph/src/programs/edge-line/frag.glsl.js +8 -0
- package/dist/cjs/packages/graph/src/programs/edge-line/index.js +166 -0
- package/dist/cjs/packages/graph/src/programs/edge-line/vert.glsl.js +8 -0
- package/dist/cjs/packages/graph/src/programs/node-badge/factory.js +249 -0
- package/dist/cjs/packages/graph/src/programs/node-badge/frag.glsl.js +8 -0
- package/dist/cjs/packages/graph/src/programs/node-badge/index.js +33 -0
- package/dist/cjs/packages/graph/src/programs/node-badge/texture.js +455 -0
- package/dist/cjs/packages/graph/src/programs/node-badge/vert.glsl.js +19 -0
- package/dist/cjs/packages/graph/src/programs/node-circle/base/drawHover.js +70 -0
- package/dist/cjs/packages/graph/src/programs/node-circle/base/drawLabel.js +112 -0
- package/dist/cjs/packages/graph/src/programs/node-circle/base/frag.glsl.js +8 -0
- package/dist/cjs/packages/graph/src/programs/node-circle/base/index.js +136 -0
- package/dist/cjs/packages/graph/src/programs/node-circle/base/vert.glsl.js +8 -0
- package/dist/cjs/packages/graph/src/programs/node-circle/index.js +15 -0
- package/dist/cjs/packages/graph/src/programs/node-image/factory.js +223 -0
- package/dist/cjs/packages/graph/src/programs/node-image/frag.glsl.js +8 -0
- package/dist/cjs/packages/graph/src/programs/node-image/index.js +14 -0
- package/dist/cjs/packages/graph/src/programs/node-image/texture.js +472 -0
- package/dist/cjs/packages/graph/src/programs/node-image/vert.glsl.js +8 -0
- package/dist/cjs/packages/graph/src/programs/node-rect/base/drawHover.js +67 -0
- package/dist/cjs/packages/graph/src/programs/node-rect/base/drawLabel.js +106 -0
- package/dist/cjs/packages/graph/src/programs/node-rect/base/frag.glsl.js +8 -0
- package/dist/cjs/packages/graph/src/programs/node-rect/base/index.js +135 -0
- package/dist/cjs/packages/graph/src/programs/node-rect/base/vert.glsl.js +8 -0
- package/dist/cjs/packages/graph/src/programs/node-rect/index.js +15 -0
- package/dist/esm/_virtual/_commonjs-dynamic-modules.js +7 -0
- package/dist/esm/_virtual/_commonjsHelpers.js +7 -0
- package/dist/esm/_virtual/_rollup-plugin-web-worker-loader__helper__auto__createBase64WorkerFactory.js +14 -0
- package/dist/esm/_virtual/_rollup-plugin-web-worker-loader__helper__auto__isNodeJS.js +9 -0
- package/dist/esm/_virtual/_rollup-plugin-web-worker-loader__helper__browser__createBase64WorkerFactory.js +34 -0
- package/dist/esm/_virtual/_rollup-plugin-web-worker-loader__helper__node__WorkerClass.js +13 -0
- package/dist/esm/_virtual/_rollup-plugin-web-worker-loader__helper__node__createBase64WorkerFactory.js +20 -0
- package/dist/esm/_virtual/elk-worker.js +8 -0
- package/dist/esm/_virtual/elk.bundled.js +5 -0
- package/dist/esm/node_modules/elkjs/lib/elk.bundled.js +6667 -0
- package/dist/esm/packages/graph/src/components/Context.js +107 -0
- package/dist/esm/packages/graph/src/components/ContextMenu.js +134 -0
- package/dist/esm/packages/graph/src/components/Tools.js +127 -0
- package/dist/esm/packages/graph/src/components/Viewer.js +57 -0
- package/dist/esm/packages/graph/src/constants/index.js +16 -0
- package/dist/esm/packages/graph/src/graph/index.js +425 -0
- package/dist/esm/packages/graph/src/hooks/sigmaDragSelect.js +169 -0
- package/dist/esm/packages/graph/src/hooks/sigmaHilighter.js +83 -0
- package/dist/esm/packages/graph/src/hooks/sigmaMouseActions.js +145 -0
- package/dist/esm/packages/graph/src/hooks/useGraphology.js +41 -0
- package/dist/esm/packages/graph/src/hooks/useSigma.js +112 -0
- package/dist/esm/packages/graph/src/index.js +30 -0
- package/dist/esm/packages/graph/src/programs/arrow-head/frag.glsl.js +8 -0
- package/dist/esm/packages/graph/src/programs/arrow-head/index.js +141 -0
- package/dist/esm/packages/graph/src/programs/arrow-head/vert.glsl.js +8 -0
- package/dist/esm/packages/graph/src/programs/edge-curve/drawLabel.js +136 -0
- package/dist/esm/packages/graph/src/programs/edge-curve/frag.glsl.js +8 -0
- package/dist/esm/packages/graph/src/programs/edge-curve/index.js +156 -0
- package/dist/esm/packages/graph/src/programs/edge-curve/vert.glsl.js +8 -0
- package/dist/esm/packages/graph/src/programs/edge-line/drawLabel.js +70 -0
- package/dist/esm/packages/graph/src/programs/edge-line/frag.glsl.js +8 -0
- package/dist/esm/packages/graph/src/programs/edge-line/index.js +166 -0
- package/dist/esm/packages/graph/src/programs/edge-line/vert.glsl.js +8 -0
- package/dist/esm/packages/graph/src/programs/node-badge/factory.js +249 -0
- package/dist/esm/packages/graph/src/programs/node-badge/frag.glsl.js +8 -0
- package/dist/esm/packages/graph/src/programs/node-badge/index.js +32 -0
- package/dist/esm/packages/graph/src/programs/node-badge/texture.js +445 -0
- package/dist/esm/packages/graph/src/programs/node-badge/vert.glsl.js +19 -0
- package/dist/esm/packages/graph/src/programs/node-circle/base/drawHover.js +70 -0
- package/dist/esm/packages/graph/src/programs/node-circle/base/drawLabel.js +112 -0
- package/dist/esm/packages/graph/src/programs/node-circle/base/frag.glsl.js +8 -0
- package/dist/esm/packages/graph/src/programs/node-circle/base/index.js +136 -0
- package/dist/esm/packages/graph/src/programs/node-circle/base/vert.glsl.js +8 -0
- package/dist/esm/packages/graph/src/programs/node-circle/index.js +15 -0
- package/dist/esm/packages/graph/src/programs/node-image/factory.js +223 -0
- package/dist/esm/packages/graph/src/programs/node-image/frag.glsl.js +8 -0
- package/dist/esm/packages/graph/src/programs/node-image/index.js +13 -0
- package/dist/esm/packages/graph/src/programs/node-image/texture.js +462 -0
- package/dist/esm/packages/graph/src/programs/node-image/vert.glsl.js +8 -0
- package/dist/esm/packages/graph/src/programs/node-rect/base/drawHover.js +67 -0
- package/dist/esm/packages/graph/src/programs/node-rect/base/drawLabel.js +106 -0
- package/dist/esm/packages/graph/src/programs/node-rect/base/frag.glsl.js +8 -0
- package/dist/esm/packages/graph/src/programs/node-rect/base/index.js +135 -0
- package/dist/esm/packages/graph/src/programs/node-rect/base/vert.glsl.js +8 -0
- package/dist/esm/packages/graph/src/programs/node-rect/index.js +15 -0
- package/dist/types/components/Context.d.ts +18 -0
- package/dist/types/components/ContextMenu.d.ts +1 -0
- package/dist/types/components/Tools.d.ts +1 -0
- package/dist/types/components/Viewer.d.ts +2 -0
- package/dist/types/constants/index.d.ts +12 -0
- package/dist/types/graph/index.d.ts +30 -0
- package/dist/types/graph/layout.worker.d.ts +1 -0
- package/dist/types/hooks/sigmaDragSelect.d.ts +8 -0
- package/dist/types/hooks/sigmaHilighter.d.ts +3 -0
- package/dist/types/hooks/sigmaMouseActions.d.ts +3 -0
- package/dist/types/hooks/useGraphology.d.ts +6 -0
- package/dist/types/hooks/useSigma.d.ts +8 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/programs/arrow-head/frag.glsl.d.ts +2 -0
- package/dist/types/programs/arrow-head/index.d.ts +9 -0
- package/dist/types/programs/arrow-head/vert.glsl.d.ts +2 -0
- package/dist/types/programs/edge-curve/drawLabel.d.ts +6 -0
- package/dist/types/programs/edge-curve/frag.glsl.d.ts +2 -0
- package/dist/types/programs/edge-curve/index.d.ts +43 -0
- package/dist/types/programs/edge-curve/vert.glsl.d.ts +2 -0
- package/dist/types/programs/edge-line/drawLabel.d.ts +5 -0
- package/dist/types/programs/edge-line/frag.glsl.d.ts +2 -0
- package/dist/types/programs/edge-line/index.d.ts +11 -0
- package/dist/types/programs/edge-line/vert.glsl.d.ts +2 -0
- package/dist/types/programs/node-badge/factory.d.ts +27 -0
- package/dist/types/programs/node-badge/frag.glsl.d.ts +2 -0
- package/dist/types/programs/node-badge/index.d.ts +5 -0
- package/dist/types/programs/node-badge/texture.d.ts +102 -0
- package/dist/types/programs/node-badge/vert.glsl.d.ts +2 -0
- package/dist/types/programs/node-circle/base/drawHover.d.ts +8 -0
- package/dist/types/programs/node-circle/base/drawLabel.d.ts +8 -0
- package/dist/types/programs/node-circle/base/frag.glsl.d.ts +2 -0
- package/dist/types/programs/node-circle/base/index.d.ts +37 -0
- package/dist/types/programs/node-circle/base/vert.glsl.d.ts +2 -0
- package/dist/types/programs/node-circle/index.d.ts +11 -0
- package/dist/types/programs/node-image/factory.d.ts +25 -0
- package/dist/types/programs/node-image/frag.glsl.d.ts +2 -0
- package/dist/types/programs/node-image/index.d.ts +5 -0
- package/dist/types/programs/node-image/texture.d.ts +102 -0
- package/dist/types/programs/node-image/vert.glsl.d.ts +2 -0
- package/dist/types/programs/node-rect/base/drawHover.d.ts +8 -0
- package/dist/types/programs/node-rect/base/drawLabel.d.ts +8 -0
- package/dist/types/programs/node-rect/base/frag.glsl.d.ts +2 -0
- package/dist/types/programs/node-rect/base/index.d.ts +34 -0
- package/dist/types/programs/node-rect/base/vert.glsl.d.ts +2 -0
- package/dist/types/programs/node-rect/index.d.ts +11 -0
- package/dist/types/types/index.d.ts +189 -0
- package/package.json +69 -0
- package/src/components/Context.tsx +135 -0
- package/src/components/ContextMenu.tsx +156 -0
- package/src/components/Tools.tsx +107 -0
- package/src/components/Viewer.tsx +75 -0
- package/src/constants/index.ts +22 -0
- package/src/graph/index.ts +428 -0
- package/src/graph/layout.worker.ts +42 -0
- package/src/hooks/sigmaDragSelect.ts +219 -0
- package/src/hooks/sigmaHilighter.ts +107 -0
- package/src/hooks/sigmaMouseActions.ts +153 -0
- package/src/hooks/useGraphology.ts +31 -0
- package/src/hooks/useSigma.ts +118 -0
- package/src/index.ts +34 -0
- package/src/programs/arrow-head/frag.glsl.ts +18 -0
- package/src/programs/arrow-head/index.ts +148 -0
- package/src/programs/arrow-head/vert.glsl.ts +75 -0
- package/src/programs/edge-curve/drawLabel.ts +166 -0
- package/src/programs/edge-curve/frag.glsl.ts +86 -0
- package/src/programs/edge-curve/index.ts +158 -0
- package/src/programs/edge-curve/vert.glsl.ts +110 -0
- package/src/programs/edge-line/drawLabel.ts +113 -0
- package/src/programs/edge-line/frag.glsl.ts +34 -0
- package/src/programs/edge-line/index.ts +165 -0
- package/src/programs/edge-line/vert.glsl.ts +104 -0
- package/src/programs/node-badge/factory.ts +327 -0
- package/src/programs/node-badge/frag.glsl.ts +79 -0
- package/src/programs/node-badge/index.ts +35 -0
- package/src/programs/node-badge/texture.ts +425 -0
- package/src/programs/node-badge/vert.glsl.ts +99 -0
- package/src/programs/node-circle/base/drawHover.ts +80 -0
- package/src/programs/node-circle/base/drawLabel.ts +145 -0
- package/src/programs/node-circle/base/frag.glsl.ts +72 -0
- package/src/programs/node-circle/base/index.ts +102 -0
- package/src/programs/node-circle/base/vert.glsl.ts +83 -0
- package/src/programs/node-circle/index.ts +19 -0
- package/src/programs/node-image/factory.ts +301 -0
- package/src/programs/node-image/frag.glsl.ts +97 -0
- package/src/programs/node-image/index.ts +7 -0
- package/src/programs/node-image/texture.ts +435 -0
- package/src/programs/node-image/vert.glsl.ts +60 -0
- package/src/programs/node-rect/base/drawHover.ts +77 -0
- package/src/programs/node-rect/base/drawLabel.ts +149 -0
- package/src/programs/node-rect/base/frag.glsl.ts +67 -0
- package/src/programs/node-rect/base/index.ts +109 -0
- package/src/programs/node-rect/base/vert.glsl.ts +87 -0
- package/src/programs/node-rect/index.ts +19 -0
- package/src/types/index.ts +210 -0
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
|
|
4
|
+
import _classCallCheck from '@babel/runtime/helpers/classCallCheck';
|
|
5
|
+
import _createClass from '@babel/runtime/helpers/createClass';
|
|
6
|
+
import _possibleConstructorReturn from '@babel/runtime/helpers/possibleConstructorReturn';
|
|
7
|
+
import _getPrototypeOf from '@babel/runtime/helpers/getPrototypeOf';
|
|
8
|
+
import _inherits from '@babel/runtime/helpers/inherits';
|
|
9
|
+
import { NodeProgram } from 'sigma/rendering';
|
|
10
|
+
import { floatColor } from 'sigma/utils';
|
|
11
|
+
import SHADER_SOURCE$1 from './frag.glsl.js';
|
|
12
|
+
import SHADER_SOURCE from './vert.glsl.js';
|
|
13
|
+
|
|
14
|
+
function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
|
|
15
|
+
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
16
|
+
|
|
17
|
+
/* istanbul ignore file */
|
|
18
|
+
|
|
19
|
+
var _WebGLRenderingContex = WebGLRenderingContext,
|
|
20
|
+
UNSIGNED_BYTE = _WebGLRenderingContex.UNSIGNED_BYTE,
|
|
21
|
+
FLOAT = _WebGLRenderingContex.FLOAT;
|
|
22
|
+
var UNIFORMS = ["u_sizeRatio", "u_correctionRatio", "u_cameraAngle", "u_matrix"];
|
|
23
|
+
var PI = Math.PI;
|
|
24
|
+
var NodeRectBase = /*#__PURE__*/function (_NodeProgram) {
|
|
25
|
+
function NodeRectBase() {
|
|
26
|
+
_classCallCheck(this, NodeRectBase);
|
|
27
|
+
return _callSuper(this, NodeRectBase, arguments);
|
|
28
|
+
}
|
|
29
|
+
_inherits(NodeRectBase, _NodeProgram);
|
|
30
|
+
return _createClass(NodeRectBase, [{
|
|
31
|
+
key: "getDefinition",
|
|
32
|
+
value: function getDefinition() {
|
|
33
|
+
return {
|
|
34
|
+
VERTICES: 6,
|
|
35
|
+
VERTEX_SHADER_SOURCE: SHADER_SOURCE,
|
|
36
|
+
FRAGMENT_SHADER_SOURCE: SHADER_SOURCE$1,
|
|
37
|
+
METHOD: WebGLRenderingContext.TRIANGLES,
|
|
38
|
+
UNIFORMS: UNIFORMS,
|
|
39
|
+
ATTRIBUTES: [{
|
|
40
|
+
name: "a_position",
|
|
41
|
+
size: 2,
|
|
42
|
+
type: FLOAT
|
|
43
|
+
}, {
|
|
44
|
+
name: "a_size",
|
|
45
|
+
size: 1,
|
|
46
|
+
type: FLOAT
|
|
47
|
+
}, {
|
|
48
|
+
name: "a_border",
|
|
49
|
+
size: 1,
|
|
50
|
+
type: FLOAT
|
|
51
|
+
}, {
|
|
52
|
+
name: "a_opacity",
|
|
53
|
+
size: 1,
|
|
54
|
+
type: FLOAT
|
|
55
|
+
}, {
|
|
56
|
+
name: "a_base",
|
|
57
|
+
size: 4,
|
|
58
|
+
type: UNSIGNED_BYTE,
|
|
59
|
+
normalized: true
|
|
60
|
+
}, {
|
|
61
|
+
name: "a_color",
|
|
62
|
+
size: 4,
|
|
63
|
+
type: UNSIGNED_BYTE,
|
|
64
|
+
normalized: true
|
|
65
|
+
}, {
|
|
66
|
+
name: "a_stroke",
|
|
67
|
+
size: 4,
|
|
68
|
+
type: UNSIGNED_BYTE,
|
|
69
|
+
normalized: true
|
|
70
|
+
}, {
|
|
71
|
+
name: "a_segments",
|
|
72
|
+
size: 1,
|
|
73
|
+
type: FLOAT
|
|
74
|
+
}].concat(_toConsumableArray(Array(7).fill(0).map(function (_, idx) {
|
|
75
|
+
return {
|
|
76
|
+
name: "a_colors_" + idx,
|
|
77
|
+
size: 4,
|
|
78
|
+
type: UNSIGNED_BYTE,
|
|
79
|
+
normalized: true
|
|
80
|
+
};
|
|
81
|
+
})), [{
|
|
82
|
+
name: "a_id",
|
|
83
|
+
size: 4,
|
|
84
|
+
type: UNSIGNED_BYTE,
|
|
85
|
+
normalized: true
|
|
86
|
+
}]),
|
|
87
|
+
CONSTANT_ATTRIBUTES: [{
|
|
88
|
+
name: "a_angle",
|
|
89
|
+
size: 1,
|
|
90
|
+
type: FLOAT
|
|
91
|
+
}],
|
|
92
|
+
CONSTANT_DATA: [[PI / 4], [3 * PI / 4], [-PI / 4], [3 * PI / 4], [-PI / 4], [-3 * PI / 4]]
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
}, {
|
|
96
|
+
key: "processVisibleItem",
|
|
97
|
+
value: function processVisibleItem(nodeIndex, startIndex, data) {
|
|
98
|
+
var _data$color, _data$borderColor, _data$border, _data$opacity, _data$pie$length, _data$pie;
|
|
99
|
+
var array = this.array;
|
|
100
|
+
var base = floatColor(this.renderer.getSetting("defaultNodeColor"));
|
|
101
|
+
var color = floatColor((_data$color = data.color) !== null && _data$color !== void 0 ? _data$color : this.renderer.getSetting("defaultNodeColor"));
|
|
102
|
+
var stroke = floatColor((_data$borderColor = data.borderColor) !== null && _data$borderColor !== void 0 ? _data$borderColor : this.renderer.getSetting("defaultEdgeColor"));
|
|
103
|
+
array[startIndex++] = data.x;
|
|
104
|
+
array[startIndex++] = data.y;
|
|
105
|
+
array[startIndex++] = data.size;
|
|
106
|
+
array[startIndex++] = Math.min((_data$border = data.border) !== null && _data$border !== void 0 ? _data$border : 0, 4);
|
|
107
|
+
array[startIndex++] = (_data$opacity = data.opacity) !== null && _data$opacity !== void 0 ? _data$opacity : 1;
|
|
108
|
+
array[startIndex++] = base;
|
|
109
|
+
array[startIndex++] = color;
|
|
110
|
+
array[startIndex++] = stroke;
|
|
111
|
+
array[startIndex++] = Math.min(7, (_data$pie$length = (_data$pie = data.pie) === null || _data$pie === void 0 ? void 0 : _data$pie.length) !== null && _data$pie$length !== void 0 ? _data$pie$length : 0);
|
|
112
|
+
Array(7).fill(0).forEach(function (_, idx) {
|
|
113
|
+
var _data$pie$idx, _data$pie2;
|
|
114
|
+
array[startIndex++] = floatColor((_data$pie$idx = (_data$pie2 = data.pie) === null || _data$pie2 === void 0 ? void 0 : _data$pie2[idx]) !== null && _data$pie$idx !== void 0 ? _data$pie$idx : "#0000");
|
|
115
|
+
});
|
|
116
|
+
array[startIndex++] = nodeIndex;
|
|
117
|
+
}
|
|
118
|
+
}, {
|
|
119
|
+
key: "setUniforms",
|
|
120
|
+
value: function setUniforms(params, _ref) {
|
|
121
|
+
var gl = _ref.gl,
|
|
122
|
+
uniformLocations = _ref.uniformLocations;
|
|
123
|
+
var u_sizeRatio = uniformLocations.u_sizeRatio,
|
|
124
|
+
u_correctionRatio = uniformLocations.u_correctionRatio,
|
|
125
|
+
u_cameraAngle = uniformLocations.u_cameraAngle,
|
|
126
|
+
u_matrix = uniformLocations.u_matrix;
|
|
127
|
+
gl.uniform1f(u_sizeRatio, params.sizeRatio);
|
|
128
|
+
gl.uniform1f(u_cameraAngle, params.cameraAngle);
|
|
129
|
+
gl.uniform1f(u_correctionRatio, params.correctionRatio);
|
|
130
|
+
gl.uniformMatrix3fv(u_matrix, false, params.matrix);
|
|
131
|
+
}
|
|
132
|
+
}]);
|
|
133
|
+
}(NodeProgram);
|
|
134
|
+
|
|
135
|
+
export { NodeRectBase };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
/* istanbul ignore file */
|
|
4
|
+
|
|
5
|
+
// language=GLSL
|
|
6
|
+
var SHADER_SOURCE = /* glsl */"\nattribute vec4 a_id;\nattribute vec4 a_base;\nattribute vec4 a_color;\nattribute vec4 a_stroke;\nattribute vec2 a_position;\nattribute float a_size;\nattribute float a_border;\nattribute float a_angle;\nattribute float a_opacity;\nattribute float a_segments;\nattribute vec4 a_colors_0;\nattribute vec4 a_colors_1;\nattribute vec4 a_colors_2;\nattribute vec4 a_colors_3;\nattribute vec4 a_colors_4;\nattribute vec4 a_colors_5;\nattribute vec4 a_colors_6;\n\nuniform mat3 u_matrix;\nuniform float u_sizeRatio;\nuniform float u_cameraAngle;\nuniform float u_correctionRatio;\n\nvarying vec4 v_color;\nvarying vec4 v_stroke;\nvarying float v_border;\nvarying vec2 v_diffVector;\nvarying float v_segmentAngle;\nvarying vec4 v_colors_0;\nvarying vec4 v_colors_1;\nvarying vec4 v_colors_2;\nvarying vec4 v_colors_3;\nvarying vec4 v_colors_4;\nvarying vec4 v_colors_5;\nvarying vec4 v_colors_6;\n\nconst float bias = 255.0 / 254.0;\nconst float sqrt_8 = sqrt(8.0);\n\nvoid main() {\n float angle = a_angle + u_cameraAngle; \n\n float size = a_size * u_correctionRatio / u_sizeRatio * sqrt_8;\n vec2 diffVector = size * vec2(cos(angle), sin(angle));\n vec2 position = a_position + diffVector;\n\n float borderLessSize = (a_size - a_border) * u_correctionRatio / u_sizeRatio * sqrt_8;\n\n gl_Position = vec4(\n (u_matrix * vec3(position, 1)).xy,\n 0,\n 1\n );\n\n v_diffVector = diffVector;\n v_border = a_border * u_correctionRatio / u_sizeRatio * sqrt_8;\n v_border = borderLessSize / ".concat(Math.PI / 2.2, ";\n\n #ifdef PICKING_MODE\n v_color = a_id;\n #else\n v_color = mix(a_base, a_color, a_opacity * bias);\n v_stroke = mix(a_base, a_stroke, a_opacity * bias);\n\n // pie colors\n v_segmentAngle = 0.0;\n if(a_segments > 0.0) {\n v_segmentAngle = ").concat(Math.PI * 2, " / a_segments;\n v_colors_0 = mix(a_base, a_colors_0, a_opacity * bias);\n v_colors_1 = mix(a_base, a_colors_1, a_opacity * bias);\n v_colors_2 = mix(a_base, a_colors_2, a_opacity * bias);\n v_colors_3 = mix(a_base, a_colors_3, a_opacity * bias);\n v_colors_4 = mix(a_base, a_colors_4, a_opacity * bias);\n v_colors_5 = mix(a_base, a_colors_5, a_opacity * bias);\n v_colors_6 = mix(a_base, a_colors_6, a_opacity * bias);\n }\n #endif\n\n v_color.a *= bias;\n}\n");
|
|
7
|
+
|
|
8
|
+
export { SHADER_SOURCE as default };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
|
|
4
|
+
import { createNodeCompoundProgram } from 'sigma/rendering';
|
|
5
|
+
import { NodeBadgeProgram } from '../node-badge/index.js';
|
|
6
|
+
import { NodeImageProgram } from '../node-image/index.js';
|
|
7
|
+
import { NodeRectBase } from './base/index.js';
|
|
8
|
+
import { drawNodeHover } from './base/drawHover.js';
|
|
9
|
+
import { drawNodeLabel } from './base/drawLabel.js';
|
|
10
|
+
|
|
11
|
+
/* istanbul ignore file */
|
|
12
|
+
|
|
13
|
+
var NodeRectProgram = createNodeCompoundProgram([NodeRectBase, NodeImageProgram(false)].concat(_toConsumableArray(NodeBadgeProgram(false))), drawNodeLabel, drawNodeHover);
|
|
14
|
+
|
|
15
|
+
export { NodeRectProgram };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { PropsWithChildren } from "react";
|
|
2
|
+
import { Graph } from "../graph";
|
|
3
|
+
import { useDragSelection } from "../hooks/sigmaDragSelect";
|
|
4
|
+
import { useSigma } from "../hooks/useSigma";
|
|
5
|
+
import { EdgeAttributes, GraphProps, NodeAttributes } from "../types";
|
|
6
|
+
interface Context<N = KeyValue, E = KeyValue> {
|
|
7
|
+
sigma: ReturnType<typeof useSigma>;
|
|
8
|
+
graph: Graph<NodeAttributes<N>, EdgeAttributes<E>>;
|
|
9
|
+
selected: string[];
|
|
10
|
+
layoutRunning: boolean;
|
|
11
|
+
dragSelector: ReturnType<typeof useDragSelection>;
|
|
12
|
+
resetViewport: () => void;
|
|
13
|
+
zoomIn: () => void;
|
|
14
|
+
zoomOut: () => void;
|
|
15
|
+
}
|
|
16
|
+
export declare const useGraph: <N = KeyValue, E = KeyValue>() => Context<N, E>;
|
|
17
|
+
export declare const GraphProvider: <N = KeyValue, E = KeyValue>({ ref, data, children, nodeReducer, edgeReducer, onSelectChange, onNodeDoubleClick, onContextMenu, }: PropsWithChildren<GraphProps<N, E>>) => import("react/jsx-runtime").JSX.Element;
|
|
18
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const GraphContextMenu: () => false | import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const Tools: () => import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import Graphology from "graphology";
|
|
2
|
+
import { GraphEvents, GraphOptions } from "graphology-types";
|
|
3
|
+
import { EdgeAttributes, InternalNodeAttributes, NodeAttributes, RawGraph } from "../types";
|
|
4
|
+
interface ExtendedEvents extends GraphEvents {
|
|
5
|
+
nodesLoaded: (nodes: string[]) => void;
|
|
6
|
+
nodesDropped: (nodes: string[]) => void;
|
|
7
|
+
nodesSelected: (nodes: string[]) => void;
|
|
8
|
+
layoutRunning: (isRunning: boolean) => void;
|
|
9
|
+
layoutDone: () => void;
|
|
10
|
+
}
|
|
11
|
+
export declare class Graph<N = KeyValue, E = KeyValue> extends Graphology<InternalNodeAttributes<N>, EdgeAttributes<E>, KeyValue> {
|
|
12
|
+
constructor(options?: GraphOptions);
|
|
13
|
+
on<Event extends keyof ExtendedEvents>(type: Event, listener: ExtendedEvents[Event]): this;
|
|
14
|
+
off<Event extends keyof ExtendedEvents>(type: Event, listener: ExtendedEvents[Event]): this;
|
|
15
|
+
emit<Event extends keyof ExtendedEvents>(type: Event, ...args: Parameters<ExtendedEvents[Event]>): boolean;
|
|
16
|
+
mergeNodes(key: string, nodes: string[], attributesOrNodeReducer?: NodeAttributes<N> | ((attributes: NodeAttributes<N>[]) => NodeAttributes<N>), edgeReducer?: (edges: RawGraph<N, E>["edges"]) => RawGraph<N, E>["edges"]): this | undefined;
|
|
17
|
+
groupNodes(key: string, nodes: string[], attributesOrNodeReducer?: NodeAttributes<N> | ((attributes: NodeAttributes<N>[]) => NodeAttributes<N>), edgeReducer?: (edges: RawGraph<N, E>["edges"]) => RawGraph<N, E>["edges"]): this | undefined;
|
|
18
|
+
ungroupNode(node: string): this | undefined;
|
|
19
|
+
toggleExpanded(node: string, force?: boolean): this;
|
|
20
|
+
import(data: RawGraph<N, E> | Graph<N, E>, merge?: boolean): this;
|
|
21
|
+
private elk;
|
|
22
|
+
elkLayout(type: string): Promise<void>;
|
|
23
|
+
dropNodes(nodes: string[]): void;
|
|
24
|
+
/**
|
|
25
|
+
* parallel edge check to be called after adding edges
|
|
26
|
+
*/
|
|
27
|
+
private getCurvature;
|
|
28
|
+
private checkParallelEdges;
|
|
29
|
+
}
|
|
30
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type Sigma from "sigma";
|
|
2
|
+
import { type EdgeAttributes, type NodeAttributes } from "../types";
|
|
3
|
+
export declare const useDragSelection: (renderer?: Sigma<NodeAttributes<any>, EdgeAttributes<any>>) => {
|
|
4
|
+
selectionMode: false | "rectangle" | "lasso";
|
|
5
|
+
startRectangleSelection: () => void;
|
|
6
|
+
startLassoSelection: () => void;
|
|
7
|
+
cancelSelection: () => void;
|
|
8
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import Sigma from "sigma";
|
|
2
|
+
import { Graph } from "../graph";
|
|
3
|
+
import { EdgeAttributes, NodeAttributes } from "../types";
|
|
4
|
+
export declare const useSigma: <N, E>(graph: Graph<N, E>, nodeReducer?: (node: NodeAttributes<N>) => NodeAttributes<N>, edgeReducer?: (edge: EdgeAttributes<E>) => EdgeAttributes<E>) => {
|
|
5
|
+
instance: Sigma<NodeAttributes<N>, EdgeAttributes<E>, import("graphology-types").Attributes> | undefined;
|
|
6
|
+
containerRef: import("react").Dispatch<import("react").SetStateAction<HTMLDivElement | null>>;
|
|
7
|
+
componentsRef: import("react").Dispatch<import("react").SetStateAction<HTMLDivElement | null>>;
|
|
8
|
+
};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
declare const SHADER_SOURCE = "\nprecision mediump float;\n\nvarying vec4 v_color;\nvarying float v_opacity;\n\nconst vec4 transparent = vec4(0.0, 0.0, 0.0, 0.0);\n\nvoid main(void) {\n gl_FragColor = v_color;\n gl_FragColor = mix(transparent, gl_FragColor, v_opacity);\n}\n";
|
|
2
|
+
export default SHADER_SOURCE;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Attributes } from "graphology-types";
|
|
2
|
+
import { EdgeProgramType } from "sigma/rendering";
|
|
3
|
+
export type CreateEdgeArrowHeadProgramOptions = {
|
|
4
|
+
extremity: "source" | "target";
|
|
5
|
+
lengthToThicknessRatio: number;
|
|
6
|
+
widenessToThicknessRatio: number;
|
|
7
|
+
};
|
|
8
|
+
export declare const DEFAULT_EDGE_ARROW_HEAD_PROGRAM_OPTIONS: CreateEdgeArrowHeadProgramOptions;
|
|
9
|
+
export declare function createEdgeArrowHeadProgram<N extends Attributes = Attributes, E extends Attributes = Attributes, G extends Attributes = Attributes>(inputOptions?: Partial<CreateEdgeArrowHeadProgramOptions>): EdgeProgramType<N, E, G>;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
declare const SHADER_SOURCE = "\nattribute vec2 a_position;\nattribute vec2 a_normal;\nattribute float a_radius;\nattribute vec3 a_barycentric;\nattribute float a_opacity;\n\n#ifdef PICKING_MODE\nattribute vec4 a_id;\n#else\nattribute vec4 a_color;\n#endif\n\nuniform mat3 u_matrix;\nuniform float u_sizeRatio;\nuniform float u_correctionRatio;\nuniform float u_minEdgeThickness;\nuniform float u_lengthToThicknessRatio;\nuniform float u_widenessToThicknessRatio;\n\nvarying vec4 v_color;\nvarying float v_opacity;\n\nconst float bias = 255.0 / 254.0;\n\nvoid main() {\n float minThickness = u_minEdgeThickness;\n\n float normalLength = length(a_normal);\n vec2 unitNormal = a_normal / normalLength;\n\n // These first computations are taken from edge.vert.glsl and\n // edge.clamped.vert.glsl. Please read it to get better comments on what's\n // happening:\n float pixelsThickness = max(normalLength / u_sizeRatio, minThickness);\n float webGLThickness = pixelsThickness * u_correctionRatio;\n float webGLNodeRadius = a_radius * 2.0 * u_correctionRatio / u_sizeRatio;\n float webGLArrowHeadLength = webGLThickness * u_lengthToThicknessRatio * 2.0;\n float webGLArrowHeadThickness = webGLThickness * u_widenessToThicknessRatio;\n\n float da = a_barycentric.x;\n float db = a_barycentric.y;\n float dc = a_barycentric.z;\n\n vec2 delta = vec2(\n da * (webGLNodeRadius * unitNormal.y)\n + db * ((webGLNodeRadius + webGLArrowHeadLength) * unitNormal.y + webGLArrowHeadThickness * unitNormal.x)\n + dc * ((webGLNodeRadius + webGLArrowHeadLength) * unitNormal.y - webGLArrowHeadThickness * unitNormal.x),\n\n da * (-webGLNodeRadius * unitNormal.x)\n + db * (-(webGLNodeRadius + webGLArrowHeadLength) * unitNormal.x + webGLArrowHeadThickness * unitNormal.y)\n + dc * (-(webGLNodeRadius + webGLArrowHeadLength) * unitNormal.x - webGLArrowHeadThickness * unitNormal.y)\n );\n\n vec2 position = (u_matrix * vec3(a_position + delta, 1)).xy;\n\n gl_Position = vec4(position, 0, 1);\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 v_opacity = a_opacity;\n #endif\n\n v_color.a *= bias;\n}\n";
|
|
2
|
+
export default SHADER_SOURCE;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type CreateEdgeCurveProgramOptions } from "@sigma/edge-curve/dist/declarations/src/utils";
|
|
2
|
+
import { type Attributes } from "graphology-types";
|
|
3
|
+
import { type EdgeLabelDrawingFunction } from "sigma/rendering";
|
|
4
|
+
export declare function createDrawCurvedEdgeLabel<N extends Attributes = Attributes, E extends Attributes = Attributes, G extends Attributes = Attributes>({ curvatureAttribute, defaultCurvature, keepLabelUpright, }: CreateEdgeCurveProgramOptions & {
|
|
5
|
+
keepLabelUpright?: boolean;
|
|
6
|
+
}): EdgeLabelDrawingFunction<N, E, G>;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
declare const SHADER = "\nprecision highp float;\n\nvarying vec4 v_color;\nvarying float v_opacity;\nvarying float v_thickness;\nvarying float v_feather;\nvarying vec2 v_cpA;\nvarying vec2 v_cpB;\nvarying vec2 v_cpC;\nvarying float v_sourceSize;\nvarying vec2 v_sourcePoint;\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 float epsilon = 0.7;\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\n if(v_sourceSize > 0.0) {\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\n if(v_targetSize > 0.0) {\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 }\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 gl_FragColor = mix(transparent, gl_FragColor, v_opacity);\n #endif\n } else {\n gl_FragColor = transparent;\n }\n}\n";
|
|
2
|
+
export default SHADER;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { type Attributes } from "graphology-types";
|
|
2
|
+
import { EdgeProgram, type ProgramInfo } from "sigma/rendering";
|
|
3
|
+
import { type EdgeDisplayData, type NodeDisplayData, type RenderParams } from "sigma/types";
|
|
4
|
+
import { InternalEdgeAttributes } from "../../types";
|
|
5
|
+
declare const UNIFORMS: readonly ["u_matrix", "u_sizeRatio", "u_dimensions", "u_pixelRatio", "u_feather", "u_minEdgeThickness", "u_lengthToThicknessRatio", "u_widenessToThicknessRatio"];
|
|
6
|
+
export declare class EdgeCurveProgramBase<N extends Attributes = Attributes, E extends Attributes = Attributes, G extends Attributes = Attributes> extends EdgeProgram<(typeof UNIFORMS)[number], N, E, G> {
|
|
7
|
+
getDefinition(): {
|
|
8
|
+
VERTICES: number;
|
|
9
|
+
VERTEX_SHADER_SOURCE: string;
|
|
10
|
+
FRAGMENT_SHADER_SOURCE: string;
|
|
11
|
+
METHOD: 4;
|
|
12
|
+
UNIFORMS: readonly ["u_matrix", "u_sizeRatio", "u_dimensions", "u_pixelRatio", "u_feather", "u_minEdgeThickness", "u_lengthToThicknessRatio", "u_widenessToThicknessRatio"];
|
|
13
|
+
ATTRIBUTES: ({
|
|
14
|
+
name: string;
|
|
15
|
+
size: number;
|
|
16
|
+
type: 5126;
|
|
17
|
+
normalized?: undefined;
|
|
18
|
+
} | {
|
|
19
|
+
name: string;
|
|
20
|
+
size: number;
|
|
21
|
+
type: 5121;
|
|
22
|
+
normalized: boolean;
|
|
23
|
+
})[];
|
|
24
|
+
CONSTANT_ATTRIBUTES: {
|
|
25
|
+
name: string;
|
|
26
|
+
size: number;
|
|
27
|
+
type: 5126;
|
|
28
|
+
}[];
|
|
29
|
+
CONSTANT_DATA: number[][];
|
|
30
|
+
};
|
|
31
|
+
processVisibleItem(edgeIndex: number, startIndex: number, sourceData: NodeDisplayData, targetData: NodeDisplayData, data: EdgeDisplayData & InternalEdgeAttributes): void;
|
|
32
|
+
setUniforms(params: RenderParams, { gl, uniformLocations }: ProgramInfo): void;
|
|
33
|
+
}
|
|
34
|
+
export declare const EdgeCurveProgram: {
|
|
35
|
+
new (_gl: WebGLRenderingContext, _pickingBuffer: WebGLFramebuffer | null, _renderer: import("sigma").default<Attributes, Attributes, Attributes>): {
|
|
36
|
+
drawLabel: import("sigma/rendering").EdgeLabelDrawingFunction<Attributes, Attributes, Attributes> | undefined;
|
|
37
|
+
kill(): void;
|
|
38
|
+
reallocate(_capacity: number): void;
|
|
39
|
+
process(_edgeIndex: number, _offset: number, _sourceData: NodeDisplayData, _targetData: NodeDisplayData, _data: EdgeDisplayData): void;
|
|
40
|
+
render(_params: RenderParams): void;
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
export {};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
declare const SHADER = "\nattribute vec4 a_id;\nattribute vec4 a_color;\nattribute float a_direction;\nattribute float a_thickness;\nattribute float a_opacity;\nattribute vec2 a_source;\nattribute vec2 a_target;\nattribute float a_current;\nattribute float a_curvature;\nattribute float a_sourceSize;\nattribute float a_targetSize;\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;\nuniform float u_widenessToThicknessRatio;\n\nvarying vec4 v_color;\nvarying float v_opacity;\nvarying float v_thickness;\nvarying float v_feather;\nvarying vec2 v_cpA;\nvarying vec2 v_cpB;\nvarying vec2 v_cpC;\nvarying float v_sourceSize;\nvarying vec2 v_sourcePoint;\nvarying float v_targetSize;\nvarying vec2 v_targetPoint;\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 // 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 float curveThickness = max(minThickness, a_thickness / 2.0 / u_sizeRatio * u_pixelRatio);\n\n v_thickness = curveThickness;\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) * (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 v_sourceSize = a_sourceSize * u_pixelRatio / u_sizeRatio;\n v_sourcePoint = viewportSource;\n \n v_targetSize = a_targetSize * u_pixelRatio / u_sizeRatio;\n v_targetPoint = viewportTarget;\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 v_opacity = a_opacity;\n #endif\n\n v_color.a *= bias;\n}\n";
|
|
2
|
+
export default SHADER;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type Attributes } from "graphology-types";
|
|
2
|
+
import { type Settings } from "sigma/settings";
|
|
3
|
+
import { type EdgeDisplayData, type NodeDisplayData, type PartialButFor } from "sigma/types";
|
|
4
|
+
export type EdgeLabelDrawingFunction<N extends Attributes = Attributes, E extends Attributes = Attributes, G extends Attributes = Attributes> = (context: CanvasRenderingContext2D, edgeData: PartialButFor<EdgeDisplayData, "label" | "color" | "size">, sourceData: PartialButFor<NodeDisplayData, "x" | "y" | "size">, targetData: PartialButFor<NodeDisplayData, "x" | "y" | "size">, settings: Settings<N, E, G>) => void;
|
|
5
|
+
export declare function drawLineLabel<N extends Attributes = Attributes, E extends Attributes = Attributes, G extends Attributes = Attributes>(context: CanvasRenderingContext2D, edgeData: PartialButFor<EdgeDisplayData, "label" | "color" | "size">, sourceData: PartialButFor<NodeDisplayData, "x" | "y" | "size">, targetData: PartialButFor<NodeDisplayData, "x" | "y" | "size">, settings: Settings<N, E, G>): void;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
declare const SHADER_SOURCE = "\nprecision mediump float;\n\nvarying vec4 v_color;\nvarying vec2 v_normal;\nvarying float v_opacity;\nvarying float v_thickness;\nvarying float v_feather;\n\nconst vec4 transparent = vec4(0.0, 0.0, 0.0, 0.0);\n\nvoid main(void) {\n // We only handle antialiasing for normal mode:\n #ifdef PICKING_MODE\n gl_FragColor = v_color;\n #else\n float dist = length(v_normal) * v_thickness;\n\n float t = smoothstep(\n v_thickness - v_feather,\n v_thickness,\n dist\n );\n\n gl_FragColor = mix(v_color, transparent, t);\n gl_FragColor = mix(transparent, gl_FragColor, v_opacity);\n #endif\n}\n";
|
|
2
|
+
export default SHADER_SOURCE;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type Attributes } from "graphology-types";
|
|
2
|
+
import { type EdgeDisplayData, type NodeDisplayData, type RenderParams } from "sigma/types";
|
|
3
|
+
export declare const EdgeLineProgram: {
|
|
4
|
+
new (_gl: WebGLRenderingContext, _pickingBuffer: WebGLFramebuffer | null, _renderer: import("sigma").default<Attributes, Attributes, Attributes>): {
|
|
5
|
+
drawLabel: import("sigma/rendering").EdgeLabelDrawingFunction<Attributes, Attributes, Attributes> | undefined;
|
|
6
|
+
kill(): void;
|
|
7
|
+
reallocate(_capacity: number): void;
|
|
8
|
+
process(_edgeIndex: number, _offset: number, _sourceData: NodeDisplayData, _targetData: NodeDisplayData, _data: EdgeDisplayData): void;
|
|
9
|
+
render(_params: RenderParams): void;
|
|
10
|
+
};
|
|
11
|
+
};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
declare const SHADER_SOURCE = "\nattribute vec4 a_id;\nattribute vec4 a_color;\nattribute vec2 a_normal;\nattribute float a_opacity;\nattribute float a_normalCoef;\nattribute vec2 a_positionStart;\nattribute vec2 a_positionEnd;\nattribute float a_positionCoef;\nattribute float a_sourceRadius;\nattribute float a_targetRadius;\nattribute float a_sourceRadiusCoef;\nattribute float a_targetRadiusCoef;\n\nuniform mat3 u_matrix;\nuniform float u_sizeRatio;\nuniform float u_zoomRatio;\nuniform float u_pixelRatio;\nuniform float u_correctionRatio;\nuniform float u_minEdgeThickness;\nuniform float u_lengthToThicknessRatio;\nuniform float u_feather;\n\nvarying vec4 v_color;\nvarying vec2 v_normal;\nvarying float v_opacity;\nvarying float v_thickness;\nvarying float v_feather;\n\nconst float minThickness = 1.7;\nconst float bias = 255.0 / 254.0;\n\nvoid main() {\n vec2 normal = a_normal * a_normalCoef;\n vec2 position = a_positionStart * (1.0 - a_positionCoef) + a_positionEnd * a_positionCoef;\n\n float normalLength = length(normal);\n vec2 unitNormal = normal / normalLength;\n\n // We require edges to be at least \"minThickness\" pixels thick *on screen*\n // (so we need to compensate the size ratio):\n float pixelsThickness = max(normalLength, minThickness * u_sizeRatio);\n\n // Then, we need to retrieve the normalized thickness of the edge in the WebGL\n // referential (in a ([0, 1], [0, 1]) space), using our \"magic\" correction\n // ratio:\n float webGLThickness = pixelsThickness * u_correctionRatio / u_sizeRatio;\n\n // Here, we move the point to leave space for the arrow heads:\n // Source arrow head\n float sourceRadius = a_sourceRadius * a_sourceRadiusCoef;\n float sourceDirection = sign(sourceRadius);\n float webGLSourceRadius = sourceDirection * sourceRadius * 2.0 * u_correctionRatio / u_sizeRatio;\n float webGLSourceArrowHeadLength = webGLThickness * u_lengthToThicknessRatio * 2.0;\n vec2 sourceCompensationVector =\n vec2(-sourceDirection * unitNormal.y, sourceDirection * unitNormal.x)\n * (webGLSourceRadius + webGLSourceArrowHeadLength);\n \n // Target arrow head\n float targetRadius = a_targetRadius * a_targetRadiusCoef;\n float targetDirection = sign(targetRadius);\n float webGLTargetRadius = targetDirection * targetRadius * 2.0 * u_correctionRatio / u_sizeRatio;\n float webGLTargetArrowHeadLength = webGLThickness * u_lengthToThicknessRatio * 2.0;\n vec2 targetCompensationVector =\n vec2(-targetDirection * unitNormal.y, targetDirection * unitNormal.x)\n * (webGLTargetRadius + webGLTargetArrowHeadLength);\n\n if(a_sourceRadius == 0.0) {\n sourceCompensationVector = vec2(0.0, 0.0);\n }\n if(a_targetRadius == 0.0) {\n targetCompensationVector = vec2(0.0, 0.0);\n }\n\n // Here is the proper position of the vertex\n gl_Position = vec4((u_matrix * vec3(position + unitNormal * webGLThickness + sourceCompensationVector + targetCompensationVector, 1)).xy, 0, 1);\n\n // For the fragment shader though, we need a thickness that takes the \"magic\"\n // correction ratio into account (as in webGLThickness), but so that the\n // antialiasing effect does not depend on the zoom level. So here's yet\n // another thickness version:\n v_thickness = webGLThickness / u_zoomRatio;\n\n v_normal = unitNormal;\n\n v_feather = u_feather * u_correctionRatio / u_zoomRatio / u_pixelRatio * 2.0;\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 v_opacity = a_opacity;\n #endif\n\n v_color.a *= bias;\n}\n";
|
|
2
|
+
export default SHADER_SOURCE;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { type Attributes } from "graphology-types";
|
|
2
|
+
import { type NodeHoverDrawingFunction, type NodeLabelDrawingFunction, type NodeProgramType } from "sigma/rendering";
|
|
3
|
+
import { type EdgeAttributes, type NodeAttributes } from "../../types";
|
|
4
|
+
import { type TextureManagerOptions } from "./texture";
|
|
5
|
+
interface CreateNodeImageProgramOptions<N extends Attributes, E extends Attributes, G extends Attributes> extends TextureManagerOptions {
|
|
6
|
+
drawingMode: "background" | "color";
|
|
7
|
+
keepWithinCircle: boolean;
|
|
8
|
+
drawLabel: NodeLabelDrawingFunction<N, E, G> | undefined;
|
|
9
|
+
drawHover: NodeHoverDrawingFunction<N, E, G> | undefined;
|
|
10
|
+
padding: number;
|
|
11
|
+
colorAttribute: string;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* To share the texture between the program instances of the graph and the
|
|
15
|
+
* hovered nodes (to prevent some flickering, mostly), this program must be
|
|
16
|
+
* "built" for each sigma instance:
|
|
17
|
+
*/
|
|
18
|
+
export default function getNodeImageProgram(options?: Partial<CreateNodeImageProgramOptions<NodeAttributes & {
|
|
19
|
+
bg: string;
|
|
20
|
+
opacity: number;
|
|
21
|
+
}, EdgeAttributes, Attributes>> & {
|
|
22
|
+
badgePosition: string;
|
|
23
|
+
}): NodeProgramType<NodeAttributes & {
|
|
24
|
+
bg: string;
|
|
25
|
+
opacity: number;
|
|
26
|
+
}, EdgeAttributes>;
|
|
27
|
+
export {};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
declare const SHADER_SOURCE = "\nprecision highp float;\n\nvarying vec4 v_fill;\nvarying vec4 v_color;\nvarying vec4 v_texture;\nvarying vec2 v_diffVector;\nvarying float v_opacity;\nvarying float v_radius;\n\nuniform sampler2D u_atlas;\nuniform float u_correctionRatio;\nuniform float u_cameraAngle;\nuniform float u_percentagePadding;\nuniform bool u_keepWithinCircle;\nuniform bool u_shape;\n\nconst vec4 transparent = vec4(0.0, 0.0, 0.0, 0.0);\n\nconst float radius = 0.5;\n\nvoid main(void) {\n float border = 2.0 * u_correctionRatio;\n float dist = length(v_diffVector);\n vec4 color = v_fill;\n\n float c = cos(-u_cameraAngle);\n float s = sin(-u_cameraAngle);\n vec2 diffVector = mat2(c, s, -s, c) * (v_diffVector);\n\n // No antialiasing for picking mode:\n #ifdef PICKING_MODE\n border = 0.0;\n gl_FragColor = v_color;\n\n #else\n // First case: No image to display\n if (v_texture.w <= 0.0) {\n color = v_fill;\n }\n\n // Second case: Image loaded into the texture\n else {\n float paddingRatio = 1.0 + 2.0 * u_percentagePadding;\n float coef = 1.0;\n vec2 coordinateInTexture = diffVector * vec2(paddingRatio, -paddingRatio) / v_radius / 2.0 * coef + vec2(0.5, 0.5);\n vec4 texel = texture2D(u_atlas, (v_texture.xy + coordinateInTexture * v_texture.zw), -1.0);\n\n // Colorize all visible image pixels:\n color = mix(v_fill, v_color, texel.a);\n \n // Erase pixels \"in the padding\":\n if (abs(diffVector.x) > v_radius / paddingRatio || abs(diffVector.y) > v_radius / paddingRatio) {\n color = v_fill;\n }\n }\n\n // Crop in a circle when u_keepWithinCircle is truthy:\n if(v_opacity == 0.0) {\n gl_FragColor = transparent;\n }\n else if (dist - v_radius + border > border)\n gl_FragColor = transparent;\n else if (dist - v_radius + border > 0.0) {\n gl_FragColor = mix(v_fill, transparent, (dist - v_radius + border) / border);\n }\n else {\n gl_FragColor = mix(v_fill, color, v_opacity);\n }\n #endif\n \n\n}\n";
|
|
2
|
+
export default SHADER_SOURCE;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { default as createNodeImageProgram } from "./factory";
|
|
2
|
+
export declare const NodeBadgeProgram: (isCircle: boolean) => import("sigma/rendering").NodeProgramType<import("../..").NodeAttributes<KeyValue<any>> & {
|
|
3
|
+
bg: string;
|
|
4
|
+
opacity: number;
|
|
5
|
+
}, import("../..").EdgeAttributes<KeyValue<any>>>[];
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { EventEmitter } from "events";
|
|
2
|
+
import { type Coordinates } from "sigma/types";
|
|
3
|
+
/**
|
|
4
|
+
* Useful types:
|
|
5
|
+
* *************
|
|
6
|
+
*/
|
|
7
|
+
export interface ImageLoading {
|
|
8
|
+
status: "loading";
|
|
9
|
+
}
|
|
10
|
+
export interface ImageError {
|
|
11
|
+
status: "error";
|
|
12
|
+
}
|
|
13
|
+
export interface ImageReady {
|
|
14
|
+
status: "ready";
|
|
15
|
+
image: HTMLImageElement;
|
|
16
|
+
sourceX: number;
|
|
17
|
+
sourceY: number;
|
|
18
|
+
sourceSize: number;
|
|
19
|
+
destinationSize: number;
|
|
20
|
+
}
|
|
21
|
+
export type ImageType = ImageLoading | ImageError | ImageReady;
|
|
22
|
+
export type Atlas = Record<string, Coordinates & {
|
|
23
|
+
size: number;
|
|
24
|
+
}>;
|
|
25
|
+
export interface TextureManagerOptions {
|
|
26
|
+
size: {
|
|
27
|
+
mode: "auto";
|
|
28
|
+
} | {
|
|
29
|
+
mode: "max";
|
|
30
|
+
value: number;
|
|
31
|
+
} | {
|
|
32
|
+
mode: "force";
|
|
33
|
+
value: number;
|
|
34
|
+
};
|
|
35
|
+
objectFit: "contain" | "cover" | "fill";
|
|
36
|
+
correctCentering: boolean;
|
|
37
|
+
}
|
|
38
|
+
export declare const DEFAULT_TEXTURE_MANAGER_OPTIONS: TextureManagerOptions;
|
|
39
|
+
export declare const DEBOUNCE_TIMEOUT = 100;
|
|
40
|
+
export declare const MARGIN_IN_TEXTURE = 1;
|
|
41
|
+
/**
|
|
42
|
+
* Helpers:
|
|
43
|
+
* ********
|
|
44
|
+
*/
|
|
45
|
+
/**
|
|
46
|
+
* This helper loads an image at a given URL, and returns an HTMLImageElement
|
|
47
|
+
* with it displayed once it's properly loaded, within a promise.
|
|
48
|
+
*/
|
|
49
|
+
export declare function loadRasterImage(imageSource: string): Promise<HTMLImageElement>;
|
|
50
|
+
export declare const makeSvg: (path?: string) => string;
|
|
51
|
+
/**
|
|
52
|
+
* This helper loads an SVG image at a given URL, adjusts its size to a given
|
|
53
|
+
* size, and returns an HTMLImageElement with it displayed once it's properly
|
|
54
|
+
* loaded, within a promise.
|
|
55
|
+
*/
|
|
56
|
+
export declare function loadSVGImage(imageSource: string, { size }?: {
|
|
57
|
+
size?: number;
|
|
58
|
+
}): Promise<HTMLImageElement>;
|
|
59
|
+
/**
|
|
60
|
+
* This helper loads an image using the proper function.
|
|
61
|
+
*/
|
|
62
|
+
export declare function loadImage(imageSource: string, { size }?: {
|
|
63
|
+
size?: number;
|
|
64
|
+
}): Promise<HTMLImageElement>;
|
|
65
|
+
/**
|
|
66
|
+
* This helper computes exact coordinates to draw an image onto a texture.
|
|
67
|
+
*/
|
|
68
|
+
export declare function refineImage(image: HTMLImageElement, corrector: PictogramCenteringCorrector, { objectFit, size, correctCentering }: TextureManagerOptions): Omit<ImageReady, "status" | "image">;
|
|
69
|
+
/**
|
|
70
|
+
* This helper takes a collection of image states and a context, draw all the
|
|
71
|
+
* images in the context, and returns an atlas to get where each image is drawn
|
|
72
|
+
* on the texture.
|
|
73
|
+
*/
|
|
74
|
+
export declare function drawTexture(ctx: CanvasRenderingContext2D, images: Record<string, ImageType>): Atlas;
|
|
75
|
+
/**
|
|
76
|
+
* This class helps to "correct" the centering of an SVG pictogram by finding
|
|
77
|
+
* the "true" visually correct center through the barycenter of the pictogram's
|
|
78
|
+
* alpha layer in x and y dimension.
|
|
79
|
+
*/
|
|
80
|
+
export declare class PictogramCenteringCorrector {
|
|
81
|
+
canvas: HTMLCanvasElement;
|
|
82
|
+
context: CanvasRenderingContext2D;
|
|
83
|
+
constructor();
|
|
84
|
+
getCorrectionOffset(image: HTMLImageElement, size: number): Coordinates;
|
|
85
|
+
}
|
|
86
|
+
export declare class TextureManager extends EventEmitter {
|
|
87
|
+
static NEW_TEXTURE_EVENT: string;
|
|
88
|
+
private readonly options;
|
|
89
|
+
private readonly canvas;
|
|
90
|
+
private readonly ctx;
|
|
91
|
+
private frameId?;
|
|
92
|
+
private readonly corrector;
|
|
93
|
+
private imageStates;
|
|
94
|
+
private texture;
|
|
95
|
+
private atlas;
|
|
96
|
+
constructor(options?: Partial<TextureManagerOptions>);
|
|
97
|
+
private scheduleGenerateTexture;
|
|
98
|
+
private generateTexture;
|
|
99
|
+
registerImage(source: string): Promise<void>;
|
|
100
|
+
getAtlas(): Atlas;
|
|
101
|
+
getTexture(): ImageData;
|
|
102
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type Settings } from "sigma/settings";
|
|
2
|
+
import { EdgeAttributes, NodeAttributes } from "../../../types";
|
|
3
|
+
export declare function drawNodeHover(context: CanvasRenderingContext2D, data: NodeAttributes & {
|
|
4
|
+
opacity: number;
|
|
5
|
+
x: number;
|
|
6
|
+
y: number;
|
|
7
|
+
size: number;
|
|
8
|
+
}, settings: Settings<NodeAttributes, EdgeAttributes>): void;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type Settings } from "sigma/settings";
|
|
2
|
+
import { EdgeAttributes, InternalNodeAttributes, NodeAttributes } from "../../../types";
|
|
3
|
+
export declare function drawNodeLabel(context: CanvasRenderingContext2D, data: InternalNodeAttributes & {
|
|
4
|
+
opacity: number;
|
|
5
|
+
x: number;
|
|
6
|
+
y: number;
|
|
7
|
+
size: number;
|
|
8
|
+
}, settings: Settings<NodeAttributes, EdgeAttributes>): void;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { NodeProgram, type ProgramInfo } from "sigma/rendering";
|
|
2
|
+
import { type NodeDisplayData, type RenderParams } from "sigma/types";
|
|
3
|
+
import { type EdgeAttributes, type NodeAttributes } from "../../../types";
|
|
4
|
+
declare const UNIFORMS: readonly ["u_sizeRatio", "u_correctionRatio", "u_matrix"];
|
|
5
|
+
export declare class NodeCircleBase extends NodeProgram<(typeof UNIFORMS)[number], NodeAttributes, EdgeAttributes> {
|
|
6
|
+
static readonly ANGLE_1 = 0;
|
|
7
|
+
static readonly ANGLE_2: number;
|
|
8
|
+
static readonly ANGLE_3: number;
|
|
9
|
+
getDefinition(): {
|
|
10
|
+
VERTICES: number;
|
|
11
|
+
VERTEX_SHADER_SOURCE: string;
|
|
12
|
+
FRAGMENT_SHADER_SOURCE: string;
|
|
13
|
+
METHOD: 4;
|
|
14
|
+
UNIFORMS: readonly ["u_sizeRatio", "u_correctionRatio", "u_matrix"];
|
|
15
|
+
ATTRIBUTES: ({
|
|
16
|
+
name: string;
|
|
17
|
+
size: number;
|
|
18
|
+
type: 5121;
|
|
19
|
+
normalized: boolean;
|
|
20
|
+
} | {
|
|
21
|
+
name: string;
|
|
22
|
+
size: number;
|
|
23
|
+
type: 5126;
|
|
24
|
+
})[];
|
|
25
|
+
CONSTANT_ATTRIBUTES: {
|
|
26
|
+
name: string;
|
|
27
|
+
size: number;
|
|
28
|
+
type: 5126;
|
|
29
|
+
}[];
|
|
30
|
+
CONSTANT_DATA: number[][];
|
|
31
|
+
};
|
|
32
|
+
processVisibleItem(nodeIndex: number, startIndex: number, data: NodeDisplayData & NodeAttributes & {
|
|
33
|
+
opacity: number;
|
|
34
|
+
}): void;
|
|
35
|
+
setUniforms(params: RenderParams, { gl, uniformLocations }: ProgramInfo): void;
|
|
36
|
+
}
|
|
37
|
+
export {};
|