@yanqirenshi/d3.deployment 0.5.0 → 0.5.2
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/dist/js/Rectum.js +10 -3
- package/dist/js/datamodels/Edge.js +5 -1
- package/dist/js/painters/Edges.js +6 -2
- package/package.json +1 -1
- package/tests/Rectum.test.js +23 -0
package/dist/js/Rectum.js
CHANGED
|
@@ -415,12 +415,19 @@ var Rectum = exports["default"] = /*#__PURE__*/function (_Colon) {
|
|
|
415
415
|
key: "attachNodeDrag",
|
|
416
416
|
value: function attachNodeDrag(place, data) {
|
|
417
417
|
var self = this;
|
|
418
|
-
|
|
419
|
-
|
|
418
|
+
|
|
419
|
+
// d3 コールバック内で `this`(= DOM 要素)に依存しない。
|
|
420
|
+
// Next.js(Webpack/SWC)のトランスパイルで `this` が書き換わり得るため、
|
|
421
|
+
// 掴んだ要素は sourceEvent から closest() で取り、クロージャで保持する。
|
|
422
|
+
var grabbed = null;
|
|
423
|
+
var drag = d3.drag().on('start', function (event) {
|
|
424
|
+
grabbed = event.sourceEvent.target.closest('g.node, g.component');
|
|
425
|
+
if (grabbed) grabbed.style.cursor = 'grabbing';
|
|
420
426
|
}).on('drag', function (event, node) {
|
|
421
427
|
self.moveSubtree(place, data, node, event.dx, event.dy);
|
|
422
428
|
}).on('end', function () {
|
|
423
|
-
|
|
429
|
+
if (grabbed) grabbed.style.cursor = 'grab';
|
|
430
|
+
grabbed = null;
|
|
424
431
|
});
|
|
425
432
|
place.selectAll('g.node, g.component').style('cursor', 'grab').call(drag);
|
|
426
433
|
}
|
|
@@ -58,7 +58,11 @@ var Edge = exports["default"] = /*#__PURE__*/function () {
|
|
|
58
58
|
value: function normalize(data) {
|
|
59
59
|
var new_data = this.dataTemplate();
|
|
60
60
|
new_data._core = data;
|
|
61
|
-
|
|
61
|
+
|
|
62
|
+
// 入力に id があればそれを、無ければ Rectum.makeEdges が採番した _id を引き継ぐ。
|
|
63
|
+
// (これを落とすと _id=null → data-edge-id="null" になり、
|
|
64
|
+
// ドラッグ時の redraw が対象 path を特定できず接続線が追従しない)
|
|
65
|
+
if (data.id || data.id === 0) new_data._id = data.id;else if (data._id || data._id === 0) new_data._id = data._id;
|
|
62
66
|
if (data.from.id) new_data.from.id = data.from.id;
|
|
63
67
|
if (data.to.id) new_data.to.id = data.to.id;
|
|
64
68
|
if (data.stroke) {
|
|
@@ -31,8 +31,12 @@ var Edges = exports["default"] = /*#__PURE__*/function () {
|
|
|
31
31
|
key: "redraw",
|
|
32
32
|
value: function redraw(place, data) {
|
|
33
33
|
var id = String(data._id);
|
|
34
|
-
|
|
35
|
-
|
|
34
|
+
|
|
35
|
+
// d3 コールバック内では `this`(= DOM 要素)に依存しない。
|
|
36
|
+
// Next.js(Webpack/SWC)などのトランスパイル環境で `this` が
|
|
37
|
+
// 書き換わり得るため、引数 (d, i, nodes) の nodes[i] で要素へアクセスする。
|
|
38
|
+
var path = place.selectAll('path.edge').filter(function (d, i, nodes) {
|
|
39
|
+
return nodes[i].getAttribute('data-edge-id') === id;
|
|
36
40
|
});
|
|
37
41
|
if (!path.empty()) this.applyGeometry(path, data);
|
|
38
42
|
}
|
package/package.json
CHANGED
package/tests/Rectum.test.js
CHANGED
|
@@ -53,6 +53,29 @@ const buildData = () => {
|
|
|
53
53
|
return { rectum, data: rectum.data() };
|
|
54
54
|
};
|
|
55
55
|
|
|
56
|
+
test('edges without an explicit id inherit the auto-numbered _id (drag redraw needs it)', () => {
|
|
57
|
+
const rectum = new Rectum({});
|
|
58
|
+
|
|
59
|
+
// 入力エッジに id を与えない → makeEdges が _id を採番、normalize が引き継ぐべき。
|
|
60
|
+
rectum.data({
|
|
61
|
+
nodes: [
|
|
62
|
+
{ type: 'NODE', id: 1, label: { text: 'A' }, size: { w: 100, h: 100 }, position: { x: 0, y: 0 } },
|
|
63
|
+
{ type: 'NODE', id: 2, label: { text: 'B' }, size: { w: 100, h: 100 }, position: { x: 300, y: 0 } },
|
|
64
|
+
],
|
|
65
|
+
edges: [
|
|
66
|
+
{ from: { id: 1, position: 0 }, to: { id: 2, position: 180 }, port: 45 },
|
|
67
|
+
],
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
const edges = rectum.data().edges.list;
|
|
71
|
+
|
|
72
|
+
expect(edges).toHaveLength(1);
|
|
73
|
+
// _id が null のままだと data-edge-id="null" になり redraw が対象を見つけられない。
|
|
74
|
+
expect(edges[0]._id).not.toBeNull();
|
|
75
|
+
expect(edges[0]._id).not.toBeUndefined();
|
|
76
|
+
expect(typeof edges[0]._id).toBe('number');
|
|
77
|
+
});
|
|
78
|
+
|
|
56
79
|
test('collectSubtree gathers a node and all descendants', () => {
|
|
57
80
|
const { rectum, data } = buildData();
|
|
58
81
|
|