@keneth80/k-chart 1.26.0 → 1.27.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/CHANGELOG.md +72 -0
- package/README.md +129 -1095
- package/docs/code-graph-handoff.md +19 -37
- package/docs/configuration-reference.md +8 -1
- package/docs/functional-api.md +77 -0
- package/docs/react-nextjs.md +62 -8
- package/docs/refactor-plan.md +39 -23
- package/docs/release.md +9 -4
- package/examples/stackblitz-calendar-heatmap-basic/index.html +37 -0
- package/examples/stackblitz-calendar-heatmap-basic/package-lock.json +1548 -0
- package/examples/stackblitz-calendar-heatmap-basic/package.json +18 -0
- package/examples/stackblitz-calendar-heatmap-basic/src/main.ts +172 -0
- package/examples/stackblitz-calendar-heatmap-basic/src/style.css +33 -0
- package/examples/stackblitz-calendar-heatmap-basic/src/vite-env.d.ts +1 -0
- package/examples/stackblitz-dual-axis-combo-basic/index.html +27 -0
- package/examples/stackblitz-dual-axis-combo-basic/package-lock.json +1548 -0
- package/examples/stackblitz-dual-axis-combo-basic/package.json +18 -0
- package/examples/stackblitz-dual-axis-combo-basic/src/main.ts +88 -0
- package/examples/stackblitz-dual-axis-combo-basic/src/style.css +31 -0
- package/examples/stackblitz-dual-axis-combo-basic/src/vite-env.d.ts +1 -0
- package/examples/stackblitz-hybrid-operations-dashboard/index.html +53 -0
- package/examples/stackblitz-hybrid-operations-dashboard/package-lock.json +1548 -0
- package/examples/stackblitz-hybrid-operations-dashboard/package.json +18 -0
- package/examples/stackblitz-hybrid-operations-dashboard/src/main.ts +181 -0
- package/examples/stackblitz-hybrid-operations-dashboard/src/style.css +52 -0
- package/examples/stackblitz-pareto-basic/index.html +22 -0
- package/examples/stackblitz-pareto-basic/package-lock.json +1548 -0
- package/examples/stackblitz-pareto-basic/package.json +18 -0
- package/examples/stackblitz-pareto-basic/src/main.ts +101 -0
- package/examples/stackblitz-pareto-basic/src/style.css +31 -0
- package/examples/stackblitz-pareto-basic/src/vite-env.d.ts +1 -0
- package/examples/stackblitz-simple-api-basic/package-lock.json +96 -4
- package/examples/stackblitz-simple-api-basic/package.json +1 -1
- package/examples/stackblitz-subcell-heatmap-basic/README.md +48 -0
- package/examples/stackblitz-subcell-heatmap-basic/index.html +13 -0
- package/examples/stackblitz-subcell-heatmap-basic/package-lock.json +1788 -0
- package/examples/stackblitz-subcell-heatmap-basic/package.json +23 -0
- package/examples/stackblitz-subcell-heatmap-basic/src/app.ts +212 -0
- package/examples/stackblitz-subcell-heatmap-basic/src/component.css +169 -0
- package/examples/stackblitz-subcell-heatmap-basic/src/heatmap-demo-core.ts +505 -0
- package/examples/stackblitz-subcell-heatmap-basic/src/heatmap-demo.ts +23 -0
- package/examples/stackblitz-subcell-heatmap-basic/src/main.ts +15 -0
- package/examples/stackblitz-subcell-heatmap-basic/src/maplibre-compat.ts +6 -0
- package/examples/stackblitz-subcell-heatmap-basic/src/model.ts +242 -0
- package/examples/stackblitz-subcell-heatmap-basic/src/raster.ts +121 -0
- package/examples/stackblitz-subcell-heatmap-basic/src/style.css +15 -0
- package/examples/stackblitz-subcell-heatmap-basic/src/synthetic.ts +72 -0
- package/examples/stackblitz-subcell-heatmap-basic/src/vendor.d.ts +3 -0
- package/examples/stackblitz-subcell-heatmap-basic/src/vite-env.d.ts +1 -0
- package/examples/stackblitz-topology-basic/package-lock.json +96 -4
- package/examples/stackblitz-topology-basic/package.json +1 -1
- package/examples/stackblitz-us-transport-route/index.html +29 -0
- package/examples/stackblitz-us-transport-route/package.json +17 -0
- package/examples/stackblitz-us-transport-route/src/main.ts +211 -0
- package/examples/stackblitz-us-transport-route/src/style.css +178 -0
- package/examples/stackblitz-webgl-line-basic/package-lock.json +96 -4
- package/examples/stackblitz-webgl-line-basic/package.json +1 -1
- package/examples/stackblitz-world-activity-map/package.json +1 -1
- package/lib/core/contracts.d.ts +6 -2
- package/lib/core/contracts.d.ts.map +1 -1
- package/lib/series/svg-graph.d.ts +29 -0
- package/lib/series/svg-graph.d.ts.map +1 -1
- package/lib/series/svg-graph.js +509 -80
- package/lib/series/svg-graph.js.map +1 -1
- package/package.json +1 -1
package/lib/series/svg-graph.js
CHANGED
|
@@ -1,6 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
14
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
15
|
+
if (ar || !(i in from)) {
|
|
16
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
17
|
+
ar[i] = from[i];
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
21
|
+
};
|
|
2
22
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createGraphSeries = exports.resolveGraphData = void 0;
|
|
23
|
+
exports.createGraphSeries = exports.applyLayeredLayout = exports.applyForceLayout = exports.resolveGraphData = void 0;
|
|
4
24
|
var d3_force_1 = require("d3-force");
|
|
5
25
|
var d3_zoom_1 = require("d3-zoom");
|
|
6
26
|
var custom_1 = require("./custom");
|
|
@@ -134,16 +154,29 @@ var distanceToSegment = function (x, y, x1, y1, x2, y2) {
|
|
|
134
154
|
return Math.hypot(x - (x1 + ratio * dx), y - (y1 + ratio * dy));
|
|
135
155
|
};
|
|
136
156
|
var safeSvgId = function (value) { return value.replace(/[^a-zA-Z0-9_-]/g, '-'); };
|
|
157
|
+
var estimateGraphLabelWidth = function (value, fontSize) { return Array.from(value)
|
|
158
|
+
.reduce(function (width, character) {
|
|
159
|
+
if (/\s/.test(character))
|
|
160
|
+
return width + fontSize * 0.35;
|
|
161
|
+
return width + fontSize * (character.codePointAt(0) > 0xff ? 1 : 0.62);
|
|
162
|
+
}, fontSize * 0.4); };
|
|
137
163
|
var hashGraphValue = function (seed, value) {
|
|
138
164
|
var text = String(value !== null && value !== void 0 ? value : '');
|
|
139
|
-
|
|
165
|
+
// Include a length prefix so adjacent fields cannot collapse into the
|
|
166
|
+
// same byte stream (for example A + BC versus AB + C).
|
|
167
|
+
var hash = Math.imul(seed ^ text.length, 16777619);
|
|
140
168
|
for (var index = 0; index < text.length; index += 1) {
|
|
141
169
|
hash = Math.imul(hash ^ text.charCodeAt(index), 16777619);
|
|
142
170
|
}
|
|
143
|
-
return hash;
|
|
171
|
+
return Math.imul(hash ^ 0xff, 16777619);
|
|
144
172
|
};
|
|
145
173
|
var resolveGraphDataSignature = function (data, configuration) {
|
|
146
174
|
var hash = Math.imul(2166136261, data.length + 1);
|
|
175
|
+
hash = hashGraphValue(hash, configuration.sourceField);
|
|
176
|
+
hash = hashGraphValue(hash, configuration.targetField);
|
|
177
|
+
hash = hashGraphValue(hash, configuration.valueField);
|
|
178
|
+
hash = hashGraphValue(hash, configuration.categoryField);
|
|
179
|
+
hash = hashGraphValue(hash, configuration.categorySide);
|
|
147
180
|
data.forEach(function (row) {
|
|
148
181
|
hash = hashGraphValue(hash, row[configuration.sourceField]);
|
|
149
182
|
hash = hashGraphValue(hash, row[configuration.targetField]);
|
|
@@ -154,25 +187,357 @@ var resolveGraphDataSignature = function (data, configuration) {
|
|
|
154
187
|
});
|
|
155
188
|
return hash >>> 0;
|
|
156
189
|
};
|
|
190
|
+
var resolveNodeRanks = function (nodes, edges, configuredRank) {
|
|
191
|
+
if (configuredRank !== undefined) {
|
|
192
|
+
return nodes.map(function (node, index) {
|
|
193
|
+
var rank = typeof configuredRank === 'function'
|
|
194
|
+
? configuredRank(node, index)
|
|
195
|
+
: configuredRank;
|
|
196
|
+
return Number.isFinite(rank) ? rank : 0;
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
var nodeIndexes = new Map(nodes.map(function (node, index) { return [node, index]; }));
|
|
200
|
+
var outgoing = nodes.map(function () { return []; });
|
|
201
|
+
edges.forEach(function (edge) {
|
|
202
|
+
var sourceIndex = nodeIndexes.get(edge.source);
|
|
203
|
+
var targetIndex = nodeIndexes.get(edge.target);
|
|
204
|
+
if (sourceIndex === undefined || targetIndex === undefined || sourceIndex === targetIndex)
|
|
205
|
+
return;
|
|
206
|
+
outgoing[sourceIndex].push(targetIndex);
|
|
207
|
+
});
|
|
208
|
+
// Collapse strongly-connected components first. Iterative Kosaraju avoids
|
|
209
|
+
// overflowing the call stack on large production dependency graphs.
|
|
210
|
+
var reverseOutgoing = nodes.map(function () { return []; });
|
|
211
|
+
outgoing.forEach(function (targets, sourceIndex) {
|
|
212
|
+
targets.forEach(function (targetIndex) { return reverseOutgoing[targetIndex].push(sourceIndex); });
|
|
213
|
+
});
|
|
214
|
+
var visited = nodes.map(function () { return false; });
|
|
215
|
+
var finishOrder = [];
|
|
216
|
+
nodes.forEach(function (_node, startIndex) {
|
|
217
|
+
if (visited[startIndex])
|
|
218
|
+
return;
|
|
219
|
+
var walk = [{ nodeIndex: startIndex, nextTarget: 0 }];
|
|
220
|
+
visited[startIndex] = true;
|
|
221
|
+
while (walk.length) {
|
|
222
|
+
var frame = walk[walk.length - 1];
|
|
223
|
+
var targets = outgoing[frame.nodeIndex];
|
|
224
|
+
if (frame.nextTarget < targets.length) {
|
|
225
|
+
var targetIndex = targets[frame.nextTarget];
|
|
226
|
+
frame.nextTarget += 1;
|
|
227
|
+
if (!visited[targetIndex]) {
|
|
228
|
+
visited[targetIndex] = true;
|
|
229
|
+
walk.push({ nodeIndex: targetIndex, nextTarget: 0 });
|
|
230
|
+
}
|
|
231
|
+
continue;
|
|
232
|
+
}
|
|
233
|
+
finishOrder.push(frame.nodeIndex);
|
|
234
|
+
walk.pop();
|
|
235
|
+
}
|
|
236
|
+
});
|
|
237
|
+
var componentByNode = nodes.map(function () { return -1; });
|
|
238
|
+
var componentCount = 0;
|
|
239
|
+
var _loop_1 = function (orderIndex) {
|
|
240
|
+
var startIndex = finishOrder[orderIndex];
|
|
241
|
+
if (componentByNode[startIndex] !== -1)
|
|
242
|
+
return "continue";
|
|
243
|
+
var members = [startIndex];
|
|
244
|
+
componentByNode[startIndex] = componentCount;
|
|
245
|
+
while (members.length) {
|
|
246
|
+
var nodeIndex = members.pop();
|
|
247
|
+
reverseOutgoing[nodeIndex].forEach(function (sourceIndex) {
|
|
248
|
+
if (componentByNode[sourceIndex] !== -1)
|
|
249
|
+
return;
|
|
250
|
+
componentByNode[sourceIndex] = componentCount;
|
|
251
|
+
members.push(sourceIndex);
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
componentCount += 1;
|
|
255
|
+
};
|
|
256
|
+
for (var orderIndex = finishOrder.length - 1; orderIndex >= 0; orderIndex -= 1) {
|
|
257
|
+
_loop_1(orderIndex);
|
|
258
|
+
}
|
|
259
|
+
var componentOutgoing = Array.from({ length: componentCount }, function () { return new Set(); });
|
|
260
|
+
var componentIndegree = Array.from({ length: componentCount }, function () { return 0; });
|
|
261
|
+
outgoing.forEach(function (targets, sourceIndex) {
|
|
262
|
+
targets.forEach(function (targetIndex) {
|
|
263
|
+
var sourceComponent = componentByNode[sourceIndex];
|
|
264
|
+
var targetComponent = componentByNode[targetIndex];
|
|
265
|
+
if (sourceComponent === targetComponent || componentOutgoing[sourceComponent].has(targetComponent))
|
|
266
|
+
return;
|
|
267
|
+
componentOutgoing[sourceComponent].add(targetComponent);
|
|
268
|
+
componentIndegree[targetComponent] += 1;
|
|
269
|
+
});
|
|
270
|
+
});
|
|
271
|
+
var componentRanks = Array.from({ length: componentCount }, function () { return 0; });
|
|
272
|
+
var queue = componentIndegree.reduce(function (result, degree, index) {
|
|
273
|
+
if (degree === 0)
|
|
274
|
+
result.push(index);
|
|
275
|
+
return result;
|
|
276
|
+
}, []);
|
|
277
|
+
var _loop_2 = function (cursor) {
|
|
278
|
+
var sourceComponent = queue[cursor];
|
|
279
|
+
componentOutgoing[sourceComponent].forEach(function (targetComponent) {
|
|
280
|
+
componentRanks[targetComponent] = Math.max(componentRanks[targetComponent], componentRanks[sourceComponent] + 1);
|
|
281
|
+
componentIndegree[targetComponent] -= 1;
|
|
282
|
+
if (componentIndegree[targetComponent] === 0)
|
|
283
|
+
queue.push(targetComponent);
|
|
284
|
+
});
|
|
285
|
+
};
|
|
286
|
+
for (var cursor = 0; cursor < queue.length; cursor += 1) {
|
|
287
|
+
_loop_2(cursor);
|
|
288
|
+
}
|
|
289
|
+
return componentByNode.map(function (component) { var _a; return (_a = componentRanks[component]) !== null && _a !== void 0 ? _a : 0; });
|
|
290
|
+
};
|
|
291
|
+
var resolveLayoutSignature = function (configuration, ranks) {
|
|
292
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
293
|
+
var hash = 2166136261;
|
|
294
|
+
[
|
|
295
|
+
(_a = configuration.layout) !== null && _a !== void 0 ? _a : 'force',
|
|
296
|
+
(_b = configuration.nodeMinRadius) !== null && _b !== void 0 ? _b : 9,
|
|
297
|
+
(_c = configuration.nodeMaxRadius) !== null && _c !== void 0 ? _c : 28,
|
|
298
|
+
(_d = configuration.chargeStrength) !== null && _d !== void 0 ? _d : -360,
|
|
299
|
+
(_e = configuration.gravity) !== null && _e !== void 0 ? _e : 0,
|
|
300
|
+
(_f = configuration.linkDistance) !== null && _f !== void 0 ? _f : 'auto',
|
|
301
|
+
(_g = configuration.collisionPadding) !== null && _g !== void 0 ? _g : 8,
|
|
302
|
+
(_h = configuration.iterations) !== null && _h !== void 0 ? _h : 220
|
|
303
|
+
].forEach(function (value) {
|
|
304
|
+
hash = hashGraphValue(hash, value);
|
|
305
|
+
});
|
|
306
|
+
ranks.forEach(function (rank) {
|
|
307
|
+
hash = hashGraphValue(hash, rank);
|
|
308
|
+
});
|
|
309
|
+
return hash >>> 0;
|
|
310
|
+
};
|
|
311
|
+
var clampNodeCoordinate = function (value, size, radius, padding) {
|
|
312
|
+
var minimum = radius + padding;
|
|
313
|
+
var maximum = size - radius - padding;
|
|
314
|
+
return minimum <= maximum
|
|
315
|
+
? Math.max(minimum, Math.min(maximum, value))
|
|
316
|
+
: size / 2;
|
|
317
|
+
};
|
|
318
|
+
var applyForceLayout = function (nodes, edges, options) {
|
|
319
|
+
var _a, _b, _c;
|
|
320
|
+
var width = Math.max(1, options.width);
|
|
321
|
+
var height = Math.max(1, options.height);
|
|
322
|
+
var radii = nodes.map(function (node, index) { return Math.max(0, options.radius(node, index)); });
|
|
323
|
+
var initialRadius = Math.max(24, Math.min(width, height) * 0.3);
|
|
324
|
+
var simulationNodes = nodes.map(function (node, index) {
|
|
325
|
+
var angle = (Math.PI * 2 * index) / Math.max(1, nodes.length) - Math.PI / 2;
|
|
326
|
+
return __assign(__assign({}, node), { x: width / 2 + Math.cos(angle) * initialRadius, y: height / 2 + Math.sin(angle) * initialRadius });
|
|
327
|
+
});
|
|
328
|
+
var cloneByNode = new Map(nodes.map(function (node, index) { return [node, simulationNodes[index]]; }));
|
|
329
|
+
var simulationEdges = edges.map(function (edge) { return (__assign(__assign({}, edge), { source: cloneByNode.get(edge.source), target: cloneByNode.get(edge.target) })); });
|
|
330
|
+
if (simulationNodes.length > 1) {
|
|
331
|
+
var cloneIndexes_1 = new Map(simulationNodes.map(function (node, index) { return [node, index]; }));
|
|
332
|
+
var simulation = (0, d3_force_1.forceSimulation)(simulationNodes)
|
|
333
|
+
.force('link', (0, d3_force_1.forceLink)(simulationEdges)
|
|
334
|
+
.distance(options.linkDistance)
|
|
335
|
+
.strength(0.58))
|
|
336
|
+
.force('charge', (0, d3_force_1.forceManyBody)().strength((_a = options.chargeStrength) !== null && _a !== void 0 ? _a : -360))
|
|
337
|
+
.force('center', (0, d3_force_1.forceCenter)(width / 2, height / 2))
|
|
338
|
+
.force('collision', (0, d3_force_1.forceCollide)()
|
|
339
|
+
.radius(function (node) { var _a, _b; return radii[(_a = cloneIndexes_1.get(node)) !== null && _a !== void 0 ? _a : 0] + ((_b = options.collisionPadding) !== null && _b !== void 0 ? _b : 8); }))
|
|
340
|
+
.stop();
|
|
341
|
+
var gravity = Math.max(0, (_b = options.gravity) !== null && _b !== void 0 ? _b : 0);
|
|
342
|
+
if (gravity > 0) {
|
|
343
|
+
simulation
|
|
344
|
+
.force('x', (0, d3_force_1.forceX)(width / 2).strength(gravity))
|
|
345
|
+
.force('y', (0, d3_force_1.forceY)(height / 2).strength(gravity));
|
|
346
|
+
}
|
|
347
|
+
simulation.randomSource(function () { return 0.5; });
|
|
348
|
+
var iterations = Math.max(1, Math.floor((_c = options.iterations) !== null && _c !== void 0 ? _c : 220));
|
|
349
|
+
for (var index = 0; index < iterations; index += 1)
|
|
350
|
+
simulation.tick();
|
|
351
|
+
}
|
|
352
|
+
return {
|
|
353
|
+
positions: simulationNodes.map(function (node, index) { return ({
|
|
354
|
+
x: clampNodeCoordinate(node.x, width, radii[index], 8),
|
|
355
|
+
y: clampNodeCoordinate(node.y, height, radii[index], 8)
|
|
356
|
+
}); }),
|
|
357
|
+
radiusScale: 1
|
|
358
|
+
};
|
|
359
|
+
};
|
|
360
|
+
exports.applyForceLayout = applyForceLayout;
|
|
361
|
+
var orderLayerIndexes = function (nodes, edges, ranks) {
|
|
362
|
+
var nodeIndexes = new Map(nodes.map(function (node, index) { return [node, index]; }));
|
|
363
|
+
var neighbors = nodes.map(function () { return []; });
|
|
364
|
+
edges.forEach(function (edge) {
|
|
365
|
+
var sourceIndex = nodeIndexes.get(edge.source);
|
|
366
|
+
var targetIndex = nodeIndexes.get(edge.target);
|
|
367
|
+
if (sourceIndex === undefined || targetIndex === undefined || sourceIndex === targetIndex)
|
|
368
|
+
return;
|
|
369
|
+
neighbors[sourceIndex].push(targetIndex);
|
|
370
|
+
neighbors[targetIndex].push(sourceIndex);
|
|
371
|
+
});
|
|
372
|
+
var layersByRank = new Map();
|
|
373
|
+
nodes.forEach(function (node, index) {
|
|
374
|
+
var _a, _b;
|
|
375
|
+
var rank = (_a = ranks[index]) !== null && _a !== void 0 ? _a : 0;
|
|
376
|
+
var layer = (_b = layersByRank.get(rank)) !== null && _b !== void 0 ? _b : [];
|
|
377
|
+
layer.push(index);
|
|
378
|
+
layersByRank.set(rank, layer);
|
|
379
|
+
});
|
|
380
|
+
var orderedLayers = Array.from(layersByRank.entries())
|
|
381
|
+
.sort(function (_a, _b) {
|
|
382
|
+
var left = _a[0];
|
|
383
|
+
var right = _b[0];
|
|
384
|
+
return left - right;
|
|
385
|
+
})
|
|
386
|
+
.map(function (_a) {
|
|
387
|
+
var layer = _a[1];
|
|
388
|
+
return layer;
|
|
389
|
+
});
|
|
390
|
+
var sweep = function (start, end, step, towardEarlierRanks) {
|
|
391
|
+
var positions = new Map();
|
|
392
|
+
orderedLayers.forEach(function (layer) { return layer.forEach(function (nodeIndex, index) { return positions.set(nodeIndex, index); }); });
|
|
393
|
+
var _loop_3 = function (layerIndex) {
|
|
394
|
+
var layer = orderedLayers[layerIndex];
|
|
395
|
+
var priorPositions = new Map(layer.map(function (nodeIndex, index) { return [nodeIndex, index]; }));
|
|
396
|
+
layer.sort(function (left, right) {
|
|
397
|
+
var _a, _b;
|
|
398
|
+
var barycenter = function (nodeIndex) {
|
|
399
|
+
var _a;
|
|
400
|
+
var relevant = neighbors[nodeIndex].filter(function (neighborIndex) {
|
|
401
|
+
var _a, _b, _c, _d;
|
|
402
|
+
return towardEarlierRanks
|
|
403
|
+
? ((_a = ranks[neighborIndex]) !== null && _a !== void 0 ? _a : 0) < ((_b = ranks[nodeIndex]) !== null && _b !== void 0 ? _b : 0)
|
|
404
|
+
: ((_c = ranks[neighborIndex]) !== null && _c !== void 0 ? _c : 0) > ((_d = ranks[nodeIndex]) !== null && _d !== void 0 ? _d : 0);
|
|
405
|
+
});
|
|
406
|
+
if (!relevant.length)
|
|
407
|
+
return (_a = priorPositions.get(nodeIndex)) !== null && _a !== void 0 ? _a : 0;
|
|
408
|
+
return relevant.reduce(function (sum, neighborIndex) { var _a; return sum + ((_a = positions.get(neighborIndex)) !== null && _a !== void 0 ? _a : 0); }, 0)
|
|
409
|
+
/ relevant.length;
|
|
410
|
+
};
|
|
411
|
+
return barycenter(left) - barycenter(right)
|
|
412
|
+
|| ((_a = priorPositions.get(left)) !== null && _a !== void 0 ? _a : 0) - ((_b = priorPositions.get(right)) !== null && _b !== void 0 ? _b : 0);
|
|
413
|
+
});
|
|
414
|
+
layer.forEach(function (nodeIndex, index) { return positions.set(nodeIndex, index); });
|
|
415
|
+
};
|
|
416
|
+
for (var layerIndex = start; layerIndex !== end; layerIndex += step) {
|
|
417
|
+
_loop_3(layerIndex);
|
|
418
|
+
}
|
|
419
|
+
};
|
|
420
|
+
for (var iteration = 0; iteration < 2; iteration += 1) {
|
|
421
|
+
sweep(1, orderedLayers.length, 1, true);
|
|
422
|
+
sweep(orderedLayers.length - 2, -1, -1, false);
|
|
423
|
+
}
|
|
424
|
+
return orderedLayers;
|
|
425
|
+
};
|
|
426
|
+
var applyLayeredLayout = function (nodes, edges, options) {
|
|
427
|
+
var _a, _b;
|
|
428
|
+
if (!nodes.length)
|
|
429
|
+
return { positions: [], radiusScale: 1 };
|
|
430
|
+
var width = Math.max(1, options.width);
|
|
431
|
+
var height = Math.max(1, options.height);
|
|
432
|
+
var baseRadii = nodes.map(function (node, index) { return Math.max(0, options.radius(node, index)); });
|
|
433
|
+
var footprintWidths = nodes.map(function (node, index) {
|
|
434
|
+
var _a, _b;
|
|
435
|
+
return Math.max(baseRadii[index] * 2, Math.max(0, (_b = (_a = options.labelWidth) === null || _a === void 0 ? void 0 : _a.call(options, node, index)) !== null && _b !== void 0 ? _b : 0));
|
|
436
|
+
});
|
|
437
|
+
var footprintHeights = nodes.map(function (node, index) {
|
|
438
|
+
var _a, _b;
|
|
439
|
+
return (baseRadii[index] * 2 + Math.max(0, (_b = (_a = options.labelHeight) === null || _a === void 0 ? void 0 : _a.call(options, node, index)) !== null && _b !== void 0 ? _b : 0));
|
|
440
|
+
});
|
|
441
|
+
var orderedLayers = orderLayerIndexes(nodes, edges, options.ranks);
|
|
442
|
+
var collisionGap = Math.max(0, (_a = options.collisionPadding) !== null && _a !== void 0 ? _a : 8) * 2;
|
|
443
|
+
var rankGap = Math.max(0, (_b = options.rankGap) !== null && _b !== void 0 ? _b : 72);
|
|
444
|
+
var outerPadding = 8;
|
|
445
|
+
var availableWidth = Math.max(0, width - outerPadding * 2);
|
|
446
|
+
var layers = orderedLayers.map(function (layer) {
|
|
447
|
+
var lines = [];
|
|
448
|
+
layer.forEach(function (nodeIndex) {
|
|
449
|
+
var itemWidth = footprintWidths[nodeIndex];
|
|
450
|
+
var line = lines[lines.length - 1];
|
|
451
|
+
if (!line || line.width + collisionGap + itemWidth > availableWidth + Number.EPSILON) {
|
|
452
|
+
line = { indexes: [], width: 0, height: 0, radius: 0, bottomDepth: 0 };
|
|
453
|
+
lines.push(line);
|
|
454
|
+
}
|
|
455
|
+
if (line.indexes.length)
|
|
456
|
+
line.width += collisionGap;
|
|
457
|
+
line.indexes.push(nodeIndex);
|
|
458
|
+
line.width += itemWidth;
|
|
459
|
+
line.radius = Math.max(line.radius, baseRadii[nodeIndex]);
|
|
460
|
+
line.bottomDepth = Math.max(line.bottomDepth, footprintHeights[nodeIndex] - baseRadii[nodeIndex]);
|
|
461
|
+
line.height = line.radius + line.bottomDepth;
|
|
462
|
+
});
|
|
463
|
+
return {
|
|
464
|
+
lines: lines,
|
|
465
|
+
height: lines.reduce(function (sum, line) { return sum + line.height; }, 0)
|
|
466
|
+
+ collisionGap * Math.max(0, lines.length - 1)
|
|
467
|
+
};
|
|
468
|
+
});
|
|
469
|
+
var packedHeight = outerPadding * 2
|
|
470
|
+
+ layers.reduce(function (sum, layer) { return sum + layer.height; }, 0)
|
|
471
|
+
+ rankGap * Math.max(0, layers.length - 1);
|
|
472
|
+
var packedWidth = outerPadding * 2 + Math.max.apply(Math, __spreadArray([0], layers.flatMap(function (layer) { return layer.lines.map(function (line) { return line.width; }); }), false));
|
|
473
|
+
var scale = Math.max(0, Math.min(1, width / packedWidth, height / packedHeight));
|
|
474
|
+
var scaledHeight = packedHeight * scale;
|
|
475
|
+
var positions = nodes.map(function () { return ({ x: width / 2, y: height / 2 }); });
|
|
476
|
+
var itemGap = collisionGap * scale;
|
|
477
|
+
var yCursor = (height - scaledHeight) / 2 + outerPadding * scale;
|
|
478
|
+
layers.forEach(function (layer, layerIndex) {
|
|
479
|
+
layer.lines.forEach(function (line, lineIndex) {
|
|
480
|
+
var xCursor = (width - line.width * scale) / 2;
|
|
481
|
+
line.indexes.forEach(function (nodeIndex) {
|
|
482
|
+
var radius = baseRadii[nodeIndex] * scale;
|
|
483
|
+
var itemWidth = footprintWidths[nodeIndex] * scale;
|
|
484
|
+
positions[nodeIndex] = { x: xCursor + itemWidth / 2, y: yCursor + line.radius * scale };
|
|
485
|
+
xCursor += itemWidth + itemGap;
|
|
486
|
+
});
|
|
487
|
+
yCursor += line.height * scale;
|
|
488
|
+
if (lineIndex < layer.lines.length - 1)
|
|
489
|
+
yCursor += itemGap;
|
|
490
|
+
});
|
|
491
|
+
if (layerIndex < layers.length - 1)
|
|
492
|
+
yCursor += rankGap * scale;
|
|
493
|
+
});
|
|
494
|
+
return { positions: positions, radiusScale: scale };
|
|
495
|
+
};
|
|
496
|
+
exports.applyLayeredLayout = applyLayeredLayout;
|
|
497
|
+
var applyCircularLayout = function (nodes, width, height, radius) {
|
|
498
|
+
var initialRadius = Math.max(24, Math.min(width, height) * 0.3);
|
|
499
|
+
return {
|
|
500
|
+
positions: nodes.map(function (node, index) {
|
|
501
|
+
var angle = (Math.PI * 2 * index) / Math.max(1, nodes.length) - Math.PI / 2;
|
|
502
|
+
var nodeRadius = Math.max(0, radius(node));
|
|
503
|
+
return {
|
|
504
|
+
x: clampNodeCoordinate(width / 2 + Math.cos(angle) * initialRadius, width, nodeRadius, 8),
|
|
505
|
+
y: clampNodeCoordinate(height / 2 + Math.sin(angle) * initialRadius, height, nodeRadius, 8)
|
|
506
|
+
};
|
|
507
|
+
}),
|
|
508
|
+
radiusScale: 1
|
|
509
|
+
};
|
|
510
|
+
};
|
|
157
511
|
var createGraphSeries = function (configuration) {
|
|
158
512
|
var instanceId = ++graphSeriesInstanceSequence;
|
|
159
513
|
var resolvedGraph = { nodes: [], edges: [] };
|
|
160
514
|
var graphTransform = d3_zoom_1.zoomIdentity;
|
|
161
515
|
var lastData;
|
|
516
|
+
var lastRows = [];
|
|
162
517
|
var lastDataSignature = -1;
|
|
518
|
+
var lastLayoutSignature = -1;
|
|
163
519
|
var lastWidth = -1;
|
|
164
520
|
var lastHeight = -1;
|
|
521
|
+
var layeredNodeScale = 1;
|
|
522
|
+
var nodeIndexById = new Map();
|
|
523
|
+
var edgeIndexById = new Map();
|
|
165
524
|
var selectedIds = new Set();
|
|
166
525
|
var hoveredId;
|
|
167
526
|
var resolveNodeRadius = function () { var _a; return (_a = configuration.nodeMinRadius) !== null && _a !== void 0 ? _a : 8; };
|
|
168
527
|
var resolveEdgeWidth = function () { var _a; return (_a = configuration.edgeMinWidth) !== null && _a !== void 0 ? _a : 1; };
|
|
528
|
+
var resolveNodeColor = function () { var _a; return (_a = configuration.color) !== null && _a !== void 0 ? _a : defaultGraphPalette[0]; };
|
|
529
|
+
var resolveEdgeColor = function () { return (typeof configuration.edgeColor === 'string'
|
|
530
|
+
? configuration.edgeColor
|
|
531
|
+
: 'rgba(158, 181, 199, 0.58)'); };
|
|
532
|
+
var resolveEdgeDash = function () { return (typeof configuration.edgeDash === 'string' ? configuration.edgeDash : undefined); };
|
|
533
|
+
var reapplyInteractionStyle = function () { return undefined; };
|
|
169
534
|
var series = (0, custom_1.createCustomSeries)({
|
|
170
535
|
selector: configuration.selector,
|
|
171
536
|
displayName: configuration.displayName,
|
|
172
537
|
color: configuration.color,
|
|
173
538
|
pointerEvents: 'series',
|
|
174
539
|
render: function (_a) {
|
|
175
|
-
var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x
|
|
540
|
+
var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x;
|
|
176
541
|
var group = _a.group, data = _a.data, plotSize = _a.plotSize, color = _a.color, animation = _a.animation;
|
|
177
542
|
// The core recreates series DOM on every render, so a DOM hover
|
|
178
543
|
// cannot remain active even when the cached layout is reused.
|
|
@@ -180,16 +545,15 @@ var createGraphSeries = function (configuration) {
|
|
|
180
545
|
var width = Math.max(1, plotSize.width);
|
|
181
546
|
var height = Math.max(1, plotSize.height);
|
|
182
547
|
var dataSignature = resolveGraphDataSignature(data, configuration);
|
|
183
|
-
var
|
|
184
|
-
||
|
|
185
|
-
||
|
|
186
|
-
|
|
187
|
-
if (
|
|
548
|
+
var rowsChanged = data !== lastData
|
|
549
|
+
|| data.length !== lastRows.length
|
|
550
|
+
|| data.some(function (row, index) { return row !== lastRows[index]; });
|
|
551
|
+
var graphChanged = rowsChanged || dataSignature !== lastDataSignature;
|
|
552
|
+
if (graphChanged) {
|
|
188
553
|
resolvedGraph = (0, exports.resolveGraphData)(data, configuration);
|
|
189
554
|
lastData = data;
|
|
555
|
+
lastRows = data.slice();
|
|
190
556
|
lastDataSignature = dataSignature;
|
|
191
|
-
lastWidth = width;
|
|
192
|
-
lastHeight = height;
|
|
193
557
|
selectedIds.forEach(function (id) {
|
|
194
558
|
if (!resolvedGraph.nodes.some(function (node) { return node.id === id; }))
|
|
195
559
|
selectedIds.delete(id);
|
|
@@ -197,50 +561,110 @@ var createGraphSeries = function (configuration) {
|
|
|
197
561
|
}
|
|
198
562
|
var nodes = resolvedGraph.nodes;
|
|
199
563
|
var edges = resolvedGraph.edges;
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
var
|
|
203
|
-
var
|
|
204
|
-
var
|
|
205
|
-
var
|
|
206
|
-
var
|
|
564
|
+
nodeIndexById = new Map(nodes.map(function (node, index) { return [node.id, index]; }));
|
|
565
|
+
edgeIndexById = new Map(edges.map(function (edge, index) { return [edge.id, index]; }));
|
|
566
|
+
var layout = (_b = configuration.layout) !== null && _b !== void 0 ? _b : 'force';
|
|
567
|
+
var nodeMinRadius = Math.max(0, (_c = configuration.nodeMinRadius) !== null && _c !== void 0 ? _c : 9);
|
|
568
|
+
var nodeMaxRadius = Math.max(nodeMinRadius, (_d = configuration.nodeMaxRadius) !== null && _d !== void 0 ? _d : 28);
|
|
569
|
+
var edgeMinWidth = (_e = configuration.edgeMinWidth) !== null && _e !== void 0 ? _e : 1;
|
|
570
|
+
var edgeMaxWidth = Math.max(edgeMinWidth, (_f = configuration.edgeMaxWidth) !== null && _f !== void 0 ? _f : 7);
|
|
571
|
+
var defaultEdgeColor = 'rgba(158, 181, 199, 0.58)';
|
|
572
|
+
var edgeBaseColor = (_g = configuration.edgeColor) !== null && _g !== void 0 ? _g : defaultEdgeColor;
|
|
573
|
+
var markerColor = typeof edgeBaseColor === 'string' ? edgeBaseColor : defaultEdgeColor;
|
|
574
|
+
var nodeStroke = (_h = configuration.nodeStroke) !== null && _h !== void 0 ? _h : 'rgba(246, 250, 255, 0.92)';
|
|
575
|
+
var palette = ((_j = configuration.palette) === null || _j === void 0 ? void 0 : _j.length) ? configuration.palette : defaultGraphPalette;
|
|
207
576
|
var categories = new Map();
|
|
208
577
|
var nodeRadiusScale = createLinearResolver(nodes.map(function (node) { return node.value; }), nodeMinRadius, nodeMaxRadius, true);
|
|
578
|
+
var baseNodeRadius = function (node) { return nodeRadiusScale(node.value); };
|
|
209
579
|
var edgeWidthScale = createLinearResolver(edges.map(function (edge) { return edge.value; }), edgeMinWidth, edgeMaxWidth);
|
|
210
|
-
resolveNodeRadius = function (node) { return nodeRadiusScale(node.value); };
|
|
211
580
|
resolveEdgeWidth = function (edge) { return edgeWidthScale(edge.value); };
|
|
212
|
-
nodes.forEach(function (node
|
|
581
|
+
nodes.forEach(function (node) {
|
|
213
582
|
if (node.category && !categories.has(node.category)) {
|
|
214
583
|
categories.set(node.category, categories.size);
|
|
215
584
|
}
|
|
216
|
-
if (!layoutChanged)
|
|
217
|
-
return;
|
|
218
|
-
var angle = (Math.PI * 2 * index) / Math.max(1, nodes.length) - Math.PI / 2;
|
|
219
|
-
var initialRadius = Math.max(24, Math.min(width, height) * 0.3);
|
|
220
|
-
node.x = width / 2 + Math.cos(angle) * initialRadius;
|
|
221
|
-
node.y = height / 2 + Math.sin(angle) * initialRadius;
|
|
222
585
|
});
|
|
223
|
-
|
|
224
|
-
var
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
.
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
586
|
+
resolveNodeColor = function (node, index) {
|
|
587
|
+
var _a, _b;
|
|
588
|
+
if (typeof configuration.nodeColor === 'function')
|
|
589
|
+
return configuration.nodeColor(node, index);
|
|
590
|
+
if (configuration.nodeColor)
|
|
591
|
+
return configuration.nodeColor;
|
|
592
|
+
if (node.category)
|
|
593
|
+
return palette[((_a = categories.get(node.category)) !== null && _a !== void 0 ? _a : 0) % palette.length];
|
|
594
|
+
return (_b = configuration.color) !== null && _b !== void 0 ? _b : color;
|
|
595
|
+
};
|
|
596
|
+
resolveEdgeColor = function (edge, index) { return (typeof edgeBaseColor === 'function' ? edgeBaseColor(edge, index) : edgeBaseColor); };
|
|
597
|
+
resolveEdgeDash = function (edge, index) { return (typeof configuration.edgeDash === 'function'
|
|
598
|
+
? configuration.edgeDash(edge, index)
|
|
599
|
+
: configuration.edgeDash); };
|
|
600
|
+
var labelConfiguration = typeof configuration.labels === 'boolean'
|
|
601
|
+
? { visible: configuration.labels }
|
|
602
|
+
: (_k = configuration.labels) !== null && _k !== void 0 ? _k : { visible: true };
|
|
603
|
+
var labelFontSize = (_l = labelConfiguration.fontSize) !== null && _l !== void 0 ? _l : 11;
|
|
604
|
+
var nodeLabelVisible = nodes.map(function (node) {
|
|
605
|
+
var _a;
|
|
606
|
+
return (labelConfiguration.visible !== false
|
|
607
|
+
&& node.value >= ((_a = configuration.labelThreshold) !== null && _a !== void 0 ? _a : 0));
|
|
608
|
+
});
|
|
609
|
+
var nodeLabelText = nodes.map(function (node) {
|
|
610
|
+
var _a, _b;
|
|
611
|
+
return ((_b = (_a = labelConfiguration.formatter) === null || _a === void 0 ? void 0 : _a.call(labelConfiguration, node)) !== null && _b !== void 0 ? _b : node.label);
|
|
612
|
+
});
|
|
613
|
+
var nodeRanks = layout === 'layered'
|
|
614
|
+
? resolveNodeRanks(nodes, edges, configuration.nodeRank)
|
|
615
|
+
: [];
|
|
616
|
+
var layoutSignature = resolveLayoutSignature(configuration, nodeRanks);
|
|
617
|
+
var layoutChanged = graphChanged
|
|
618
|
+
|| layoutSignature !== lastLayoutSignature
|
|
619
|
+
|| width !== lastWidth
|
|
620
|
+
|| height !== lastHeight;
|
|
621
|
+
var linkDistance = (_m = configuration.linkDistance) !== null && _m !== void 0 ? _m : Math.max(72, Math.min(width, height) / 4);
|
|
622
|
+
if (layoutChanged) {
|
|
623
|
+
var layoutResult = void 0;
|
|
624
|
+
if (layout === 'layered') {
|
|
625
|
+
layoutResult = (0, exports.applyLayeredLayout)(nodes, edges, {
|
|
626
|
+
width: width,
|
|
627
|
+
height: height,
|
|
628
|
+
radius: baseNodeRadius,
|
|
629
|
+
ranks: nodeRanks,
|
|
630
|
+
collisionPadding: configuration.collisionPadding,
|
|
631
|
+
rankGap: linkDistance,
|
|
632
|
+
labelWidth: function (_node, index) { return nodeLabelVisible[index]
|
|
633
|
+
? estimateGraphLabelWidth(nodeLabelText[index], labelFontSize)
|
|
634
|
+
: 0; },
|
|
635
|
+
labelHeight: function (_node, index) { return nodeLabelVisible[index]
|
|
636
|
+
? 15 + labelFontSize * 0.3
|
|
637
|
+
: 0; }
|
|
638
|
+
});
|
|
639
|
+
}
|
|
640
|
+
else if (layout === 'force') {
|
|
641
|
+
layoutResult = (0, exports.applyForceLayout)(nodes, edges, {
|
|
642
|
+
width: width,
|
|
643
|
+
height: height,
|
|
644
|
+
radius: baseNodeRadius,
|
|
645
|
+
linkDistance: linkDistance,
|
|
646
|
+
chargeStrength: configuration.chargeStrength,
|
|
647
|
+
gravity: configuration.gravity,
|
|
648
|
+
collisionPadding: configuration.collisionPadding,
|
|
649
|
+
iterations: configuration.iterations
|
|
650
|
+
});
|
|
237
651
|
}
|
|
652
|
+
else {
|
|
653
|
+
layoutResult = applyCircularLayout(nodes, width, height, baseNodeRadius);
|
|
654
|
+
}
|
|
655
|
+
layeredNodeScale = layoutResult.radiusScale;
|
|
656
|
+
layoutResult.positions.forEach(function (position, index) {
|
|
657
|
+
nodes[index].x = position.x;
|
|
658
|
+
nodes[index].y = position.y;
|
|
659
|
+
});
|
|
660
|
+
resolveNodeRadius = function (node) { return nodeRadiusScale(node.value) * layeredNodeScale; };
|
|
661
|
+
lastLayoutSignature = layoutSignature;
|
|
662
|
+
lastWidth = width;
|
|
663
|
+
lastHeight = height;
|
|
664
|
+
}
|
|
665
|
+
else {
|
|
666
|
+
resolveNodeRadius = function (node) { return nodeRadiusScale(node.value) * layeredNodeScale; };
|
|
238
667
|
}
|
|
239
|
-
nodes.forEach(function (node) {
|
|
240
|
-
var radius = resolveNodeRadius(node);
|
|
241
|
-
node.x = Math.max(radius + 8, Math.min(width - radius - 8, node.x));
|
|
242
|
-
node.y = Math.max(radius + 8, Math.min(height - radius - 8, node.y));
|
|
243
|
-
});
|
|
244
668
|
var markerPrefix = "kchart-graph-".concat(safeSvgId(configuration.selector), "-").concat(instanceId);
|
|
245
669
|
var symbols = (_o = configuration.edgeSymbols) !== null && _o !== void 0 ? _o : (configuration.directed ? 'none-arrow' : 'none-none');
|
|
246
670
|
var showStartCircle = symbols === 'circle-circle' || symbols === 'circle-arrow';
|
|
@@ -265,7 +689,7 @@ var createGraphSeries = function (configuration) {
|
|
|
265
689
|
.data([undefined])
|
|
266
690
|
.join('path')
|
|
267
691
|
.attr('d', 'M0,-5L10,0L0,5Z')
|
|
268
|
-
.style('fill',
|
|
692
|
+
.style('fill', markerColor);
|
|
269
693
|
defs.selectAll("marker#".concat(markerPrefix, "-circle"))
|
|
270
694
|
.data(showStartCircle || showEndCircle ? [undefined] : [])
|
|
271
695
|
.join('marker')
|
|
@@ -281,7 +705,7 @@ var createGraphSeries = function (configuration) {
|
|
|
281
705
|
.data([undefined])
|
|
282
706
|
.join('circle')
|
|
283
707
|
.attr('r', 3)
|
|
284
|
-
.style('fill',
|
|
708
|
+
.style('fill', markerColor);
|
|
285
709
|
group.selectAll('rect.kchart-graph-interaction')
|
|
286
710
|
.data([undefined])
|
|
287
711
|
.join('rect')
|
|
@@ -322,9 +746,12 @@ var createGraphSeries = function (configuration) {
|
|
|
322
746
|
? 1
|
|
323
747
|
: (_b = configuration.dimOpacity) !== null && _b !== void 0 ? _b : 0.12;
|
|
324
748
|
})
|
|
325
|
-
.style('stroke', function (edge) {
|
|
326
|
-
|
|
327
|
-
|
|
749
|
+
.style('stroke', function (edge) {
|
|
750
|
+
var _a;
|
|
751
|
+
return hasFocus && (focusIds.has(edge.source.id) || focusIds.has(edge.target.id))
|
|
752
|
+
? '#eaf7ff'
|
|
753
|
+
: resolveEdgeColor(edge, (_a = edgeIndexById.get(edge.id)) !== null && _a !== void 0 ? _a : 0);
|
|
754
|
+
});
|
|
328
755
|
nodeLayer.selectAll('g.kchart-graph-node')
|
|
329
756
|
.style('opacity', function (node) {
|
|
330
757
|
var _a;
|
|
@@ -341,6 +768,7 @@ var createGraphSeries = function (configuration) {
|
|
|
341
768
|
: (_b = configuration.nodeStrokeWidth) !== null && _b !== void 0 ? _b : 1.5;
|
|
342
769
|
});
|
|
343
770
|
};
|
|
771
|
+
reapplyInteractionStyle = applyInteractionStyle;
|
|
344
772
|
edgeLayer.selectAll('path.kchart-graph-edge')
|
|
345
773
|
.data(edges, function (edge) { return edge.id; })
|
|
346
774
|
.join('path')
|
|
@@ -353,7 +781,8 @@ var createGraphSeries = function (configuration) {
|
|
|
353
781
|
? "url(#".concat(markerPrefix, "-circle)")
|
|
354
782
|
: null)
|
|
355
783
|
.style('fill', 'none')
|
|
356
|
-
.style('stroke',
|
|
784
|
+
.style('stroke', function (edge) { var _a; return resolveEdgeColor(edge, (_a = edgeIndexById.get(edge.id)) !== null && _a !== void 0 ? _a : 0); })
|
|
785
|
+
.style('stroke-dasharray', function (edge) { var _a; return resolveEdgeDash(edge, (_a = edgeIndexById.get(edge.id)) !== null && _a !== void 0 ? _a : 0); })
|
|
357
786
|
.style('stroke-width', function (edge) { return resolveEdgeWidth(edge); })
|
|
358
787
|
.style('opacity', ((_q = configuration.edgeOpacity) !== null && _q !== void 0 ? _q : 0.72) * (animation.enabled ? animation.progress : 1))
|
|
359
788
|
.each(function appendEdgeTitle(edge) {
|
|
@@ -416,13 +845,7 @@ var createGraphSeries = function (configuration) {
|
|
|
416
845
|
.join('circle')
|
|
417
846
|
.attr('class', 'kchart-graph-node-circle')
|
|
418
847
|
.attr('r', function (node) { return resolveNodeRadius(node) * (animation.enabled ? animation.progress : 1); })
|
|
419
|
-
.style('fill', function (node) {
|
|
420
|
-
var _a, _b;
|
|
421
|
-
if (!node.category)
|
|
422
|
-
return (_a = configuration.color) !== null && _a !== void 0 ? _a : color;
|
|
423
|
-
var categoryIndex = (_b = categories.get(node.category)) !== null && _b !== void 0 ? _b : 0;
|
|
424
|
-
return palette[categoryIndex % palette.length];
|
|
425
|
-
})
|
|
848
|
+
.style('fill', function (node) { var _a; return resolveNodeColor(node, (_a = nodeIndexById.get(node.id)) !== null && _a !== void 0 ? _a : 0); })
|
|
426
849
|
.style('fill-opacity', (_s = configuration.nodeOpacity) !== null && _s !== void 0 ? _s : 0.92)
|
|
427
850
|
.style('stroke', nodeStroke)
|
|
428
851
|
.style('stroke-width', (_t = configuration.nodeStrokeWidth) !== null && _t !== void 0 ? _t : 1.5);
|
|
@@ -430,27 +853,19 @@ var createGraphSeries = function (configuration) {
|
|
|
430
853
|
.data(function (node) { return [node]; })
|
|
431
854
|
.join('title')
|
|
432
855
|
.text(function (node) { return "".concat(node.label, ": ").concat(node.value); });
|
|
433
|
-
var labelConfiguration = typeof configuration.labels === 'boolean'
|
|
434
|
-
? { visible: configuration.labels }
|
|
435
|
-
: (_u = configuration.labels) !== null && _u !== void 0 ? _u : { visible: true };
|
|
436
856
|
nodeGroups.selectAll('text.kchart-graph-node-label')
|
|
437
|
-
.data(function (node) {
|
|
438
|
-
var _a;
|
|
439
|
-
return labelConfiguration.visible !== false && node.value >= ((_a = configuration.labelThreshold) !== null && _a !== void 0 ? _a : 0)
|
|
440
|
-
? [node]
|
|
441
|
-
: [];
|
|
442
|
-
})
|
|
857
|
+
.data(function (node) { var _a; return nodeLabelVisible[(_a = nodeIndexById.get(node.id)) !== null && _a !== void 0 ? _a : 0] ? [node] : []; })
|
|
443
858
|
.join('text')
|
|
444
859
|
.attr('class', 'kchart-graph-node-label')
|
|
445
|
-
.attr('y', function (node) { return resolveNodeRadius(node) + 15; })
|
|
860
|
+
.attr('y', function (node) { return resolveNodeRadius(node) + 15 * (layout === 'layered' ? layeredNodeScale : 1); })
|
|
446
861
|
.attr('text-anchor', 'middle')
|
|
447
|
-
.style('fill', (
|
|
448
|
-
.style('font-size', "".concat(
|
|
449
|
-
.style('font-weight', (
|
|
862
|
+
.style('fill', (_u = labelConfiguration.color) !== null && _u !== void 0 ? _u : '#edf3f8')
|
|
863
|
+
.style('font-size', "".concat(labelFontSize * (layout === 'layered' ? layeredNodeScale : 1), "px"))
|
|
864
|
+
.style('font-weight', (_v = labelConfiguration.fontWeight) !== null && _v !== void 0 ? _v : 700)
|
|
450
865
|
.style('pointer-events', 'none')
|
|
451
|
-
.text(function (node) { var _a
|
|
866
|
+
.text(function (node) { var _a; return nodeLabelText[(_a = nodeIndexById.get(node.id)) !== null && _a !== void 0 ? _a : 0]; });
|
|
452
867
|
applyInteractionStyle();
|
|
453
|
-
var roam = (
|
|
868
|
+
var roam = (_w = configuration.roam) !== null && _w !== void 0 ? _w : 'both';
|
|
454
869
|
var canMove = roam === 'move' || roam === 'both';
|
|
455
870
|
var canScale = roam === 'scale' || roam === 'both';
|
|
456
871
|
if (roam === 'disabled') {
|
|
@@ -458,7 +873,7 @@ var createGraphSeries = function (configuration) {
|
|
|
458
873
|
return;
|
|
459
874
|
}
|
|
460
875
|
var zoomBehavior = (0, d3_zoom_1.zoom)()
|
|
461
|
-
.scaleExtent((
|
|
876
|
+
.scaleExtent((_x = configuration.scaleExtent) !== null && _x !== void 0 ? _x : [0.45, 5])
|
|
462
877
|
.filter(function (event) {
|
|
463
878
|
if (event.type === 'wheel')
|
|
464
879
|
return canScale;
|
|
@@ -480,13 +895,15 @@ var createGraphSeries = function (configuration) {
|
|
|
480
895
|
tooltip: function (_a) {
|
|
481
896
|
var mouseX = _a.mouseX, mouseY = _a.mouseY;
|
|
482
897
|
var activeNode;
|
|
898
|
+
var activeNodeIndex = -1;
|
|
483
899
|
var activeDistance = Number.POSITIVE_INFINITY;
|
|
484
|
-
resolvedGraph.nodes.forEach(function (node) {
|
|
900
|
+
resolvedGraph.nodes.forEach(function (node, index) {
|
|
485
901
|
var x = graphTransform.applyX(node.x);
|
|
486
902
|
var y = graphTransform.applyY(node.y);
|
|
487
903
|
var distance = Math.hypot(mouseX - x, mouseY - y);
|
|
488
904
|
if (distance <= resolveNodeRadius(node) * graphTransform.k + 8 && distance < activeDistance) {
|
|
489
905
|
activeNode = node;
|
|
906
|
+
activeNodeIndex = index;
|
|
490
907
|
activeDistance = distance;
|
|
491
908
|
}
|
|
492
909
|
});
|
|
@@ -496,16 +913,18 @@ var createGraphSeries = function (configuration) {
|
|
|
496
913
|
x: graphTransform.applyX(activeNode.x),
|
|
497
914
|
y: graphTransform.applyY(activeNode.y),
|
|
498
915
|
distance: activeDistance,
|
|
499
|
-
color:
|
|
916
|
+
color: resolveNodeColor(activeNode, activeNodeIndex),
|
|
500
917
|
html: "<strong>".concat(activeNode.label, "</strong><br/>Connected metric: ").concat(activeNode.value).concat(activeNode.category ? "<br/>Category: ".concat(activeNode.category) : '')
|
|
501
918
|
};
|
|
502
919
|
}
|
|
503
920
|
var activeEdge;
|
|
921
|
+
var activeEdgeIndex = -1;
|
|
504
922
|
var edgeDistance = Number.POSITIVE_INFINITY;
|
|
505
|
-
resolvedGraph.edges.forEach(function (edge) {
|
|
923
|
+
resolvedGraph.edges.forEach(function (edge, index) {
|
|
506
924
|
var distance = distanceToSegment(mouseX, mouseY, graphTransform.applyX(edge.source.x), graphTransform.applyY(edge.source.y), graphTransform.applyX(edge.target.x), graphTransform.applyY(edge.target.y));
|
|
507
925
|
if (distance <= Math.max(7, resolveEdgeWidth(edge) * graphTransform.k + 4) && distance < edgeDistance) {
|
|
508
926
|
activeEdge = edge;
|
|
927
|
+
activeEdgeIndex = index;
|
|
509
928
|
edgeDistance = distance;
|
|
510
929
|
}
|
|
511
930
|
});
|
|
@@ -516,24 +935,34 @@ var createGraphSeries = function (configuration) {
|
|
|
516
935
|
x: graphTransform.applyX((activeEdge.source.x + activeEdge.target.x) / 2),
|
|
517
936
|
y: graphTransform.applyY((activeEdge.source.y + activeEdge.target.y) / 2),
|
|
518
937
|
distance: edgeDistance,
|
|
519
|
-
color:
|
|
938
|
+
color: resolveEdgeColor(activeEdge, activeEdgeIndex),
|
|
520
939
|
html: "<strong>".concat(activeEdge.source.label, " \u2192 ").concat(activeEdge.target.label, "</strong><br/>Metric: ").concat(activeEdge.value)
|
|
521
940
|
};
|
|
522
941
|
},
|
|
523
942
|
clearTooltip: function (_a) {
|
|
524
|
-
var _b;
|
|
525
943
|
var seriesGroup = _a.seriesGroup;
|
|
526
944
|
seriesGroup.selectAll("g.".concat(configuration.selector, " path.kchart-graph-edge"))
|
|
527
|
-
.style('stroke', (
|
|
945
|
+
.style('stroke', function (edge) { var _a; return resolveEdgeColor(edge, (_a = edgeIndexById.get(edge.id)) !== null && _a !== void 0 ? _a : 0); })
|
|
946
|
+
.style('stroke-dasharray', function (edge) {
|
|
947
|
+
var _a;
|
|
948
|
+
return (resolveEdgeDash(edge, (_a = edgeIndexById.get(edge.id)) !== null && _a !== void 0 ? _a : 0));
|
|
949
|
+
});
|
|
950
|
+
reapplyInteractionStyle();
|
|
528
951
|
},
|
|
529
952
|
destroy: function (_a) {
|
|
530
953
|
var seriesGroup = _a.seriesGroup;
|
|
531
954
|
seriesGroup.selectAll("g.".concat(configuration.selector)).on('.zoom', null);
|
|
532
955
|
resolvedGraph = { nodes: [], edges: [] };
|
|
533
956
|
lastData = undefined;
|
|
957
|
+
lastRows = [];
|
|
534
958
|
lastDataSignature = -1;
|
|
959
|
+
lastLayoutSignature = -1;
|
|
535
960
|
lastWidth = -1;
|
|
536
961
|
lastHeight = -1;
|
|
962
|
+
layeredNodeScale = 1;
|
|
963
|
+
nodeIndexById.clear();
|
|
964
|
+
edgeIndexById.clear();
|
|
965
|
+
reapplyInteractionStyle = function () { return undefined; };
|
|
537
966
|
selectedIds.clear();
|
|
538
967
|
hoveredId = undefined;
|
|
539
968
|
graphTransform = d3_zoom_1.zoomIdentity;
|