@standarx/graph 0.0.0-stage → 1.0.0
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.fr.md +436 -0
- package/README.md +435 -2
- package/THIRD_PARTY_NOTICES.md +22 -0
- package/assets/fonts/Inter-Regular.ttf +0 -0
- package/assets/fonts/Inter-SemiBold.ttf +0 -0
- package/assets/fonts/OFL.txt +92 -0
- package/dist/adapter-0bggwh8x.js +393 -0
- package/dist/cli-4m00785g.js +20 -0
- package/dist/cli-5v9761s9.js +330 -0
- package/dist/cli-9f1pdw5q.js +462 -0
- package/dist/cli-a4ax1vkc.js +172 -0
- package/dist/cli-b4n941t8.js +1439 -0
- package/dist/cli-eqq7a3wz.js +1144 -0
- package/dist/cli-gh5166k6.js +1565 -0
- package/dist/cli-kzp16pt5.js +207 -0
- package/dist/cli-mzmjkk5v.js +11 -0
- package/dist/cli-njgyf690.js +1060 -0
- package/dist/cli-nkm2j980.js +141 -0
- package/dist/cli-nyckgf1t.js +4 -0
- package/dist/cli-sfdqkbd1.js +433 -0
- package/dist/cli-txrzzr2q.js +0 -0
- package/dist/cli-vecew2na.js +709 -0
- package/dist/cli-wt9dmbhm.js +560 -0
- package/dist/cli-xhdxp3cj.js +387 -0
- package/dist/cli-ywgtv1cg.js +39 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +415 -0
- package/dist/core/index.d.ts +6 -0
- package/dist/core/index.js +93 -0
- package/dist/core/spatial.d.ts +16 -0
- package/dist/core/threshold.d.ts +1 -0
- package/dist/core/view.d.ts +80 -0
- package/dist/export/index.d.ts +18 -0
- package/dist/export/index.js +172 -0
- package/dist/export/pdf.d.ts +5 -0
- package/dist/export/png.d.ts +4 -0
- package/dist/format/index.d.ts +4 -0
- package/dist/format/index.js +71 -0
- package/dist/format/json-schema.d.ts +2 -0
- package/dist/format/schema.d.ts +787 -0
- package/dist/format/semantic/er.d.ts +3 -0
- package/dist/format/semantic/graph.d.ts +3 -0
- package/dist/format/semantic/sequence.d.ts +3 -0
- package/dist/format/semantic/shared.d.ts +14 -0
- package/dist/format/semantic/state.d.ts +3 -0
- package/dist/format/semantic/tree.d.ts +3 -0
- package/dist/format/transition-label.d.ts +2 -0
- package/dist/format/validate.d.ts +11 -0
- package/dist/html/index.d.ts +3 -0
- package/dist/html/index.js +127 -0
- package/dist/html/layout-worker.d.ts +1 -0
- package/dist/html/layout-worker.generated.d.ts +1 -0
- package/dist/html/mount.d.ts +12 -0
- package/dist/html/page.d.ts +14 -0
- package/dist/html/render.d.ts +7 -0
- package/dist/html/runtime.d.ts +1 -0
- package/dist/html/runtime.generated.d.ts +1 -0
- package/dist/html/shell.d.ts +10 -0
- package/dist/html/svg-adapter.d.ts +8 -0
- package/dist/html/ui.d.ts +34 -0
- package/dist/language/analysis.d.ts +38 -0
- package/dist/language/complete.d.ts +3 -0
- package/dist/language/docs.d.ts +11 -0
- package/dist/language/format.d.ts +17 -0
- package/dist/language/hover.d.ts +3 -0
- package/dist/language/index.d.ts +6 -0
- package/dist/language/index.js +1385 -0
- package/dist/language/navigation.d.ts +9 -0
- package/dist/language/positions.d.ts +7 -0
- package/dist/language/symbols.d.ts +3 -0
- package/dist/language/types.d.ts +34 -0
- package/dist/layout/elk.d.ts +35 -0
- package/dist/layout/er.d.ts +3 -0
- package/dist/layout/font-metrics.d.ts +9 -0
- package/dist/layout/graph.d.ts +3 -0
- package/dist/layout/index.d.ts +5 -0
- package/dist/layout/index.js +17 -0
- package/dist/layout/measure.d.ts +10 -0
- package/dist/layout/sequence.d.ts +3 -0
- package/dist/layout/shapes.d.ts +16 -0
- package/dist/layout/shared.d.ts +31 -0
- package/dist/layout/state.d.ts +3 -0
- package/dist/layout/tree.d.ts +3 -0
- package/dist/layout/types.d.ts +198 -0
- package/dist/layout-worker.generated-emmvgfb1.js +34 -0
- package/dist/mermaid/common.d.ts +36 -0
- package/dist/mermaid/er.d.ts +3 -0
- package/dist/mermaid/graph.d.ts +4 -0
- package/dist/mermaid/index.d.ts +6 -0
- package/dist/mermaid/index.js +6 -0
- package/dist/mermaid/mindmap.d.ts +3 -0
- package/dist/mermaid/sequence.d.ts +3 -0
- package/dist/mermaid/state.d.ts +3 -0
- package/dist/remark/index.d.ts +9 -0
- package/dist/remark/index.js +104 -0
- package/dist/shared/errors.d.ts +6 -0
- package/dist/shared/package-root.d.ts +5 -0
- package/dist/svg/escape.d.ts +1 -0
- package/dist/svg/index.d.ts +3 -0
- package/dist/svg/index.js +25 -0
- package/dist/svg/render.d.ts +9 -0
- package/dist/svg/theme.d.ts +62 -0
- package/dist/svg-adapter-gq5vmp6q.js +227 -0
- package/dist/text/build.d.ts +10 -0
- package/dist/text/canonical.d.ts +10 -0
- package/dist/text/errors.d.ts +33 -0
- package/dist/text/highlight.d.ts +13 -0
- package/dist/text/index.d.ts +33 -0
- package/dist/text/index.js +27 -0
- package/dist/text/lexer.d.ts +29 -0
- package/dist/text/parser.d.ts +160 -0
- package/dist/text/print.d.ts +6 -0
- package/dist/text/slug.d.ts +1 -0
- package/dist/text/syntax.d.ts +8 -0
- package/dist/version.d.ts +1 -0
- package/dist/webgl/adapter.d.ts +4 -0
- package/dist/webgl/index.d.ts +7 -0
- package/dist/webgl/index.js +15 -0
- package/dist/webgl/runtime.d.ts +1 -0
- package/dist/webgl/runtime.generated.d.ts +1 -0
- package/grammars/standargraph.tmLanguage.json +599 -0
- package/language-configuration.json +35 -0
- package/licenses/EPL-2.0.txt +277 -0
- package/licenses/MPL-2.0.txt +373 -0
- package/package.json +133 -4
- package/schema/graph-document.v1.json +1737 -0
|
@@ -0,0 +1,393 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createView2
|
|
3
|
+
} from "./cli-vecew2na.js";
|
|
4
|
+
import {
|
|
5
|
+
part,
|
|
6
|
+
bindScheme,
|
|
7
|
+
createPanel,
|
|
8
|
+
bindInteraction
|
|
9
|
+
} from "./cli-9f1pdw5q.js";
|
|
10
|
+
|
|
11
|
+
// src/webgl/adapter.ts
|
|
12
|
+
import Graph from "graphology";
|
|
13
|
+
import Sigma from "sigma";
|
|
14
|
+
import { sdfCircle, sdfDiamond, sdfRectangle } from "sigma/rendering";
|
|
15
|
+
var IDLE_MS = 150;
|
|
16
|
+
var DIM_OPACITY = 0.25;
|
|
17
|
+
var EDGE_SIZE = 1.5;
|
|
18
|
+
function parseColor(value) {
|
|
19
|
+
const text = value.trim();
|
|
20
|
+
if (text.startsWith("#")) {
|
|
21
|
+
const hex = text.length === 4 ? text.slice(1).split("").map((digit) => digit + digit).join("") : text.slice(1, 7);
|
|
22
|
+
const number = Number.parseInt(hex, 16);
|
|
23
|
+
return [number >> 16 & 255, number >> 8 & 255, number & 255];
|
|
24
|
+
}
|
|
25
|
+
const parts = text.match(/[\d.]+/g)?.map(Number) ?? [0, 0, 0];
|
|
26
|
+
return [parts[0] ?? 0, parts[1] ?? 0, parts[2] ?? 0];
|
|
27
|
+
}
|
|
28
|
+
function mix(a, b, weight) {
|
|
29
|
+
return [
|
|
30
|
+
a[0] + (b[0] - a[0]) * weight,
|
|
31
|
+
a[1] + (b[1] - a[1]) * weight,
|
|
32
|
+
a[2] + (b[2] - a[2]) * weight
|
|
33
|
+
];
|
|
34
|
+
}
|
|
35
|
+
function css(color) {
|
|
36
|
+
return `rgb(${Math.round(color[0])},${Math.round(color[1])},${Math.round(color[2])})`;
|
|
37
|
+
}
|
|
38
|
+
function luminance(color) {
|
|
39
|
+
const [r, g, b] = color.map((channel) => {
|
|
40
|
+
const unit = channel / 255;
|
|
41
|
+
return unit <= 0.03928 ? unit / 12.92 : ((unit + 0.055) / 1.055) ** 2.4;
|
|
42
|
+
});
|
|
43
|
+
return 0.2126 * r + 0.7152 * g + 0.0722 * b;
|
|
44
|
+
}
|
|
45
|
+
function contrast(a, b) {
|
|
46
|
+
const [high, low] = [luminance(a), luminance(b)].sort((x, y) => y - x);
|
|
47
|
+
return (high + 0.05) / (low + 0.05);
|
|
48
|
+
}
|
|
49
|
+
function typeFills(app, types) {
|
|
50
|
+
const ns = "http://www.w3.org/2000/svg";
|
|
51
|
+
const svg = document.createElementNS(ns, "svg");
|
|
52
|
+
svg.setAttribute("class", "sg-root");
|
|
53
|
+
svg.style.display = "none";
|
|
54
|
+
const probe = (type) => {
|
|
55
|
+
const holder = document.createElementNS(ns, "g");
|
|
56
|
+
if (type !== undefined)
|
|
57
|
+
holder.setAttribute("data-type", type);
|
|
58
|
+
const rect = document.createElementNS(ns, "rect");
|
|
59
|
+
rect.setAttribute("class", "sg-node");
|
|
60
|
+
holder.append(rect);
|
|
61
|
+
svg.append(holder);
|
|
62
|
+
return rect;
|
|
63
|
+
};
|
|
64
|
+
const plain = probe(undefined);
|
|
65
|
+
const probes = types.map((type) => [type, probe(type)]);
|
|
66
|
+
app.append(svg);
|
|
67
|
+
const base = getComputedStyle(plain).fill;
|
|
68
|
+
const fills = new Map;
|
|
69
|
+
for (const [type, rect] of probes) {
|
|
70
|
+
const fill = getComputedStyle(rect).fill;
|
|
71
|
+
if (fill !== base)
|
|
72
|
+
fills.set(type, parseColor(fill));
|
|
73
|
+
}
|
|
74
|
+
svg.remove();
|
|
75
|
+
return fills;
|
|
76
|
+
}
|
|
77
|
+
function startWebgl(doc, scene) {
|
|
78
|
+
if (scene.kind !== "graph")
|
|
79
|
+
return;
|
|
80
|
+
const graphScene = scene;
|
|
81
|
+
const rectangleShape = sdfRectangle({
|
|
82
|
+
aspectRatio: { attribute: "aspect", default: 3 },
|
|
83
|
+
cornerRadius: 0.18
|
|
84
|
+
});
|
|
85
|
+
const diamondShape = sdfDiamond();
|
|
86
|
+
const circleShape = sdfCircle();
|
|
87
|
+
const app = part("sg-app");
|
|
88
|
+
const viewport = part("sg-viewport");
|
|
89
|
+
const glElement = part("sg-gl");
|
|
90
|
+
const groupsCanvas = part("sg-groups");
|
|
91
|
+
const panel = part("sg-panel");
|
|
92
|
+
const search = part("sg-search");
|
|
93
|
+
bindScheme(app);
|
|
94
|
+
const fonts = "Inter, system-ui, sans-serif";
|
|
95
|
+
const typeNames = [
|
|
96
|
+
...new Set(graphScene.nodes.flatMap((node) => node.type === undefined ? [] : [node.type]))
|
|
97
|
+
];
|
|
98
|
+
const readColors = () => {
|
|
99
|
+
const style = getComputedStyle(app);
|
|
100
|
+
const token = (name) => parseColor(style.getPropertyValue(name));
|
|
101
|
+
return {
|
|
102
|
+
bg: token("--sg-bg"),
|
|
103
|
+
fg: token("--sg-fg"),
|
|
104
|
+
muted: token("--sg-muted"),
|
|
105
|
+
stroke: token("--sg-node-stroke"),
|
|
106
|
+
edge: token("--sg-edge"),
|
|
107
|
+
groupFill: css(token("--sg-group-fill")),
|
|
108
|
+
groupStroke: css(token("--sg-group-stroke")),
|
|
109
|
+
accent: css(token("--sg-accent")),
|
|
110
|
+
typed: typeFills(app, typeNames)
|
|
111
|
+
};
|
|
112
|
+
};
|
|
113
|
+
let colors = readColors();
|
|
114
|
+
const view = createView2(graphScene);
|
|
115
|
+
const panelControl = createPanel(view, doc, panel);
|
|
116
|
+
const graph = new Graph({ multi: true, type: "directed" });
|
|
117
|
+
const confidence = (meta) => meta?.provenance?.confidence;
|
|
118
|
+
const nodeColors = (node) => {
|
|
119
|
+
const { bg, fg, muted, stroke, typed } = colors;
|
|
120
|
+
const level = confidence(node.meta);
|
|
121
|
+
const own = node.type === undefined ? undefined : typed.get(node.type);
|
|
122
|
+
const base = own ?? stroke;
|
|
123
|
+
const fill = level === "unknown" ? mix(muted, bg, 0.55) : level === "inferred" ? mix(base, bg, 0.88) : own ?? mix(base, bg, 0.75);
|
|
124
|
+
return { color: css(fill), labelColor: css(contrast(fill, fg) >= contrast(fill, bg) ? fg : bg) };
|
|
125
|
+
};
|
|
126
|
+
const edgeColorOf = (edge) => {
|
|
127
|
+
const level = confidence(edge.meta);
|
|
128
|
+
return css(level === "unknown" ? mix(colors.edge, colors.bg, 0.7) : level === "inferred" ? mix(colors.edge, colors.bg, 0.4) : colors.edge);
|
|
129
|
+
};
|
|
130
|
+
for (const node of graphScene.nodes) {
|
|
131
|
+
graph.addNode(node.id, {
|
|
132
|
+
x: node.x + node.width / 2,
|
|
133
|
+
y: -(node.y + node.height / 2),
|
|
134
|
+
size: node.width / 2,
|
|
135
|
+
aspect: node.width / node.height,
|
|
136
|
+
shape: node.shape === "diamond" ? diamondShape.name : node.shape === "circle" ? circleShape.name : rectangleShape.name,
|
|
137
|
+
label: node.label,
|
|
138
|
+
...nodeColors(node)
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
for (const edge of graphScene.edges) {
|
|
142
|
+
if (!graph.hasNode(edge.from) || !graph.hasNode(edge.to))
|
|
143
|
+
continue;
|
|
144
|
+
graph.addEdgeWithKey(edge.id, edge.from, edge.to, {
|
|
145
|
+
size: EDGE_SIZE,
|
|
146
|
+
color: edgeColorOf(edge),
|
|
147
|
+
directed: edge.directed
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
let hl = view.highlight();
|
|
151
|
+
let selected = view.selected();
|
|
152
|
+
const accentSelected = () => ({
|
|
153
|
+
backdropVisibility: "visible",
|
|
154
|
+
backdropColor: colors.accent,
|
|
155
|
+
backdropPadding: 4
|
|
156
|
+
});
|
|
157
|
+
const dimmedNode = { opacity: DIM_OPACITY, labelVisibility: "hidden" };
|
|
158
|
+
let labelUnit = 1;
|
|
159
|
+
const sigma = new Sigma(graph, glElement, {
|
|
160
|
+
primitives: {
|
|
161
|
+
nodes: {
|
|
162
|
+
shapes: [rectangleShape, diamondShape, circleShape],
|
|
163
|
+
label: { zoomToLabelSizeRatioFunction: (ratio) => ratio / labelUnit }
|
|
164
|
+
}
|
|
165
|
+
},
|
|
166
|
+
styles: {
|
|
167
|
+
nodes: {
|
|
168
|
+
x: { attribute: "x" },
|
|
169
|
+
y: { attribute: "y" },
|
|
170
|
+
size: { attribute: "size" },
|
|
171
|
+
color: { attribute: "color" },
|
|
172
|
+
shape: { attribute: "shape" },
|
|
173
|
+
label: { attribute: "label" },
|
|
174
|
+
labelColor: { attribute: "labelColor" },
|
|
175
|
+
labelPosition: "over",
|
|
176
|
+
labelSize: 14,
|
|
177
|
+
labelFont: `600 ${fonts}`
|
|
178
|
+
},
|
|
179
|
+
edges: {
|
|
180
|
+
size: { attribute: "size" },
|
|
181
|
+
color: { attribute: "color" }
|
|
182
|
+
}
|
|
183
|
+
},
|
|
184
|
+
settings: {
|
|
185
|
+
itemSizesReference: "positions",
|
|
186
|
+
zoomToSizeRatioFunction: (ratio) => ratio,
|
|
187
|
+
autoRescale: false,
|
|
188
|
+
enableCameraRotation: false,
|
|
189
|
+
enableNodeDrag: false,
|
|
190
|
+
renderLabels: view.lod().labels,
|
|
191
|
+
renderEdgeLabels: false,
|
|
192
|
+
hideEdgesOnMove: false,
|
|
193
|
+
hideLabelsOnMove: false,
|
|
194
|
+
labelRenderedSizeThreshold: 0,
|
|
195
|
+
labelDensity: 1000
|
|
196
|
+
},
|
|
197
|
+
nodeReducer(key) {
|
|
198
|
+
const out = {};
|
|
199
|
+
if (hl.focused && !hl.active.has(`node:${key}`))
|
|
200
|
+
Object.assign(out, dimmedNode);
|
|
201
|
+
if (selected !== null && selected.kind === "node" && selected.id === key) {
|
|
202
|
+
Object.assign(out, accentSelected());
|
|
203
|
+
}
|
|
204
|
+
return out;
|
|
205
|
+
},
|
|
206
|
+
edgeReducer(key) {
|
|
207
|
+
if (selected !== null && selected.kind === "edge" && selected.id === key) {
|
|
208
|
+
return { color: colors.accent, size: EDGE_SIZE * 2 };
|
|
209
|
+
}
|
|
210
|
+
if (hl.focused && !hl.active.has(`edge:${key}`))
|
|
211
|
+
return { opacity: DIM_OPACITY };
|
|
212
|
+
return {};
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
sigma.getMouseCaptor().kill();
|
|
216
|
+
sigma.getTouchCaptor().kill();
|
|
217
|
+
sigma.setCustomBBox({ x: [0, graphScene.width], y: [-graphScene.height, 0] });
|
|
218
|
+
function calibrate() {
|
|
219
|
+
const at = (x, y, gx) => sigma.graphToViewport({ x: gx, y: 0 }, { cameraState: { x, y, ratio: 1, angle: 0 } });
|
|
220
|
+
const base = at(0.5, 0.5, 0);
|
|
221
|
+
const { width, height } = sigma.getDimensions();
|
|
222
|
+
return {
|
|
223
|
+
unit: at(0.5, 0.5, 1).x - base.x,
|
|
224
|
+
span: base.x - at(1.5, 0.5, 0).x,
|
|
225
|
+
offsetX: base.x - width / 2,
|
|
226
|
+
offsetY: base.y - height / 2
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
let calibration = calibrate();
|
|
230
|
+
labelUnit = calibration.unit;
|
|
231
|
+
function applyCamera() {
|
|
232
|
+
const camera = view.camera();
|
|
233
|
+
const { width, height } = view.viewport();
|
|
234
|
+
const { unit, span, offsetX, offsetY } = calibration;
|
|
235
|
+
const ratio = unit / camera.scale;
|
|
236
|
+
sigma.getCamera().setState({
|
|
237
|
+
ratio,
|
|
238
|
+
x: 0.5 + (offsetX - (camera.x - width / 2) * ratio) / span,
|
|
239
|
+
y: 0.5 + ((camera.y - height / 2) * ratio - offsetY) / span,
|
|
240
|
+
angle: 0
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
const groupsContext = groupsCanvas.getContext("2d");
|
|
244
|
+
function drawGroups() {
|
|
245
|
+
const ratio = window.devicePixelRatio || 1;
|
|
246
|
+
const { width, height } = view.viewport();
|
|
247
|
+
const pixelWidth = Math.round(width * ratio);
|
|
248
|
+
const pixelHeight = Math.round(height * ratio);
|
|
249
|
+
if (groupsCanvas.width !== pixelWidth || groupsCanvas.height !== pixelHeight) {
|
|
250
|
+
groupsCanvas.width = pixelWidth;
|
|
251
|
+
groupsCanvas.height = pixelHeight;
|
|
252
|
+
}
|
|
253
|
+
const context = groupsContext;
|
|
254
|
+
context.setTransform(1, 0, 0, 1, 0, 0);
|
|
255
|
+
context.clearRect(0, 0, pixelWidth, pixelHeight);
|
|
256
|
+
const camera = view.camera();
|
|
257
|
+
context.setTransform(ratio * camera.scale, 0, 0, ratio * camera.scale, ratio * camera.x, ratio * camera.y);
|
|
258
|
+
context.lineWidth = 1 / camera.scale;
|
|
259
|
+
const { groupFill, groupStroke } = colors;
|
|
260
|
+
context.fillStyle = groupFill;
|
|
261
|
+
context.strokeStyle = groupStroke;
|
|
262
|
+
const captions = view.lod().edgeLabels;
|
|
263
|
+
const labelFill = css(colors.muted);
|
|
264
|
+
context.font = `600 12px ${fonts}`;
|
|
265
|
+
context.textBaseline = "top";
|
|
266
|
+
for (const ref of view.visible().items) {
|
|
267
|
+
if (ref.kind !== "group")
|
|
268
|
+
continue;
|
|
269
|
+
const group = view.item({ kind: "group", id: ref.id });
|
|
270
|
+
if (group === undefined)
|
|
271
|
+
continue;
|
|
272
|
+
context.beginPath();
|
|
273
|
+
context.roundRect(group.x, group.y, group.width, group.height, 8);
|
|
274
|
+
context.fill();
|
|
275
|
+
context.stroke();
|
|
276
|
+
if (captions && group.label !== undefined) {
|
|
277
|
+
context.fillStyle = labelFill;
|
|
278
|
+
context.fillText(group.label, group.x + 12, group.y + 8);
|
|
279
|
+
context.fillStyle = groupFill;
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
sigma.on("afterRender", () => {
|
|
284
|
+
drawGroups();
|
|
285
|
+
if (app.dataset.sgReady === undefined)
|
|
286
|
+
app.dataset.sgReady = "1";
|
|
287
|
+
});
|
|
288
|
+
let scheduled = false;
|
|
289
|
+
let highlightDirty = false;
|
|
290
|
+
let lastMove = 0;
|
|
291
|
+
let idleTimer = 0;
|
|
292
|
+
function touch() {
|
|
293
|
+
lastMove = performance.now();
|
|
294
|
+
if (idleTimer === 0)
|
|
295
|
+
idleTimer = window.setTimeout(idle, IDLE_MS);
|
|
296
|
+
}
|
|
297
|
+
function idle() {
|
|
298
|
+
const remaining = IDLE_MS - (performance.now() - lastMove);
|
|
299
|
+
if (remaining > 1) {
|
|
300
|
+
idleTimer = window.setTimeout(idle, remaining);
|
|
301
|
+
return;
|
|
302
|
+
}
|
|
303
|
+
idleTimer = 0;
|
|
304
|
+
if (ui.pointer !== null)
|
|
305
|
+
schedule();
|
|
306
|
+
}
|
|
307
|
+
function applyHover() {
|
|
308
|
+
const pointer = ui.pointer;
|
|
309
|
+
if (pointer === null || ui.dragging)
|
|
310
|
+
return;
|
|
311
|
+
if (performance.now() - ui.lastWheel < IDLE_MS)
|
|
312
|
+
return;
|
|
313
|
+
const hit = view.hitTest(pointer.x, pointer.y);
|
|
314
|
+
ui.pointer = null;
|
|
315
|
+
view.hover(hit !== null && hit.kind === "node" ? hit : null);
|
|
316
|
+
}
|
|
317
|
+
function frame() {
|
|
318
|
+
applyHover();
|
|
319
|
+
scheduled = false;
|
|
320
|
+
if (highlightDirty) {
|
|
321
|
+
highlightDirty = false;
|
|
322
|
+
hl = view.highlight();
|
|
323
|
+
selected = view.selected();
|
|
324
|
+
sigma.refresh({ skipIndexation: true, schedule: true });
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
function schedule() {
|
|
328
|
+
if (scheduled)
|
|
329
|
+
return;
|
|
330
|
+
scheduled = true;
|
|
331
|
+
requestAnimationFrame(frame);
|
|
332
|
+
}
|
|
333
|
+
view.subscribe((changes) => {
|
|
334
|
+
if (changes.has("selection"))
|
|
335
|
+
panelControl.update();
|
|
336
|
+
if (changes.has("camera")) {
|
|
337
|
+
touch();
|
|
338
|
+
applyCamera();
|
|
339
|
+
}
|
|
340
|
+
if (changes.has("lod"))
|
|
341
|
+
sigma.setSetting("renderLabels", view.lod().labels);
|
|
342
|
+
if (changes.has("hover") || changes.has("search") || changes.has("selection")) {
|
|
343
|
+
highlightDirty = true;
|
|
344
|
+
}
|
|
345
|
+
schedule();
|
|
346
|
+
});
|
|
347
|
+
function pick(_event, x, y) {
|
|
348
|
+
const hit = view.hitTest(x, y);
|
|
349
|
+
return hit === null || hit.kind === "group" ? null : hit;
|
|
350
|
+
}
|
|
351
|
+
const ui = bindInteraction({
|
|
352
|
+
view,
|
|
353
|
+
viewport,
|
|
354
|
+
search,
|
|
355
|
+
pick,
|
|
356
|
+
onPointer: schedule,
|
|
357
|
+
onResize() {
|
|
358
|
+
sigma.resize();
|
|
359
|
+
calibration = calibrate();
|
|
360
|
+
labelUnit = calibration.unit;
|
|
361
|
+
applyCamera();
|
|
362
|
+
drawGroups();
|
|
363
|
+
}
|
|
364
|
+
});
|
|
365
|
+
app.addEventListener("sg-scheme", () => {
|
|
366
|
+
colors = readColors();
|
|
367
|
+
for (const node of graphScene.nodes)
|
|
368
|
+
graph.mergeNodeAttributes(node.id, nodeColors(node));
|
|
369
|
+
for (const edge of graphScene.edges) {
|
|
370
|
+
if (graph.hasEdge(edge.id))
|
|
371
|
+
graph.setEdgeAttribute(edge.id, "color", edgeColorOf(edge));
|
|
372
|
+
}
|
|
373
|
+
drawGroups();
|
|
374
|
+
sigma.refresh();
|
|
375
|
+
});
|
|
376
|
+
sigma.resize();
|
|
377
|
+
calibration = calibrate();
|
|
378
|
+
labelUnit = calibration.unit;
|
|
379
|
+
applyCamera();
|
|
380
|
+
sigma.refresh();
|
|
381
|
+
return {
|
|
382
|
+
view,
|
|
383
|
+
destroy() {
|
|
384
|
+
ui.destroy();
|
|
385
|
+
panelControl.destroy();
|
|
386
|
+
clearTimeout(idleTimer);
|
|
387
|
+
sigma.kill();
|
|
388
|
+
}
|
|
389
|
+
};
|
|
390
|
+
}
|
|
391
|
+
export {
|
|
392
|
+
startWebgl
|
|
393
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// src/shared/errors.ts
|
|
2
|
+
function formatErrors(errors) {
|
|
3
|
+
return errors.map((error) => `${error.path === "" ? "/" : error.path}: ${error.message}`).join(`
|
|
4
|
+
`);
|
|
5
|
+
}
|
|
6
|
+
function formatLoadErrors(errors, file) {
|
|
7
|
+
return errors.map((error) => {
|
|
8
|
+
if (error.line !== undefined) {
|
|
9
|
+
const where = `${file === undefined ? "" : `${file}:`}${error.line}:${error.column ?? 1}`;
|
|
10
|
+
return `${where}: ${error.message}${error.code === undefined ? "" : ` [${error.code}]`}`;
|
|
11
|
+
}
|
|
12
|
+
if (error.path !== undefined) {
|
|
13
|
+
return `${error.path === "" ? "/" : error.path}: ${error.message}`;
|
|
14
|
+
}
|
|
15
|
+
return error.message;
|
|
16
|
+
}).join(`
|
|
17
|
+
`);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export { formatErrors, formatLoadErrors };
|