@yanqirenshi/d3.ter 0.4.0 → 0.4.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/README.md +10 -0
- package/dist/js/Painters/Relationships.js +149 -14
- package/dist/js/Rectum.js +4 -0
- package/jest.config.js +3 -0
- package/package.json +1 -1
- package/tests/Relationships.hit.test.js +71 -0
- package/tests/Relationships.test.js +42 -0
package/README.md
CHANGED
|
@@ -103,6 +103,16 @@ TM の再帰がこれで、ループの中点の○から再帰表を垂下し
|
|
|
103
103
|
ループ上の○(`circle.mapping-junction`)とラベル(`text.relationship-label`)は、
|
|
104
104
|
ともにベジエの中点(t=0.5)に乗ります。
|
|
105
105
|
|
|
106
|
+
結線のクリック(`callbacks.relationship.click`)は、見える線(1px)の上に重ねた透明な線で受けます
|
|
107
|
+
(`line.connector-hit` / `path.connector-loop-hit` / `line.subset-drop-hit`。太さは `style().relationship.hit.width`、既定 9)。
|
|
108
|
+
見た目は変わりません。サブセットの分岐は、垂下 1 本が関係 1 件なので垂下にだけ当たりがあり、
|
|
109
|
+
幹とバス(複数の関係で共有)にはありません。
|
|
110
|
+
|
|
111
|
+
当たりの太さ(`hit.width`)は**画面の px** です。拡大率に関わらず一定で、縮小しても細くなりません。
|
|
112
|
+
**0.4.1 までは図の単位**で、拡大率に合わせて太さが変わっていました(50% で、線から約 2px)。
|
|
113
|
+
縮小したときの当たりを補うために `hit.width` を大きくしていた場合は、値を見直してください。
|
|
114
|
+
9 倍を超えて拡大すると、見える線(1 × 拡大率)のほうが当たり(既定 9)より太くなり、見える線の縁の帯ではクリックが届きません(当たり判定の線だけで受けているため)。
|
|
115
|
+
|
|
106
116
|
## 開発
|
|
107
117
|
|
|
108
118
|
```bash
|
|
@@ -13,6 +13,9 @@ function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(
|
|
|
13
13
|
function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
|
|
14
14
|
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
15
15
|
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
16
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
17
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
18
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
16
19
|
function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
|
|
17
20
|
function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
|
|
18
21
|
function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
|
|
@@ -26,8 +29,7 @@ var Relationships = exports["default"] = /*#__PURE__*/function () {
|
|
|
26
29
|
|
|
27
30
|
// 線の描画は共通基盤(assh0le の ConnectorLines)に委譲。
|
|
28
31
|
// port の座標は entity 相対なので、owner の位置を足して絶対座標にする。
|
|
29
|
-
|
|
30
|
-
className: 'connector',
|
|
32
|
+
var ends = {
|
|
31
33
|
key: function key(d) {
|
|
32
34
|
return d._id;
|
|
33
35
|
},
|
|
@@ -42,16 +44,60 @@ var Relationships = exports["default"] = /*#__PURE__*/function () {
|
|
|
42
44
|
},
|
|
43
45
|
y2: function y2(d) {
|
|
44
46
|
return _this.toPoint(d).y;
|
|
45
|
-
}
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
this._lines = new _assh0le.ConnectorLines(_objectSpread(_objectSpread({}, ends), {}, {
|
|
50
|
+
className: 'connector',
|
|
46
51
|
stroke: function stroke() {
|
|
47
52
|
return '#888888';
|
|
48
53
|
},
|
|
49
54
|
strokeWidth: function strokeWidth() {
|
|
50
55
|
return 1;
|
|
56
|
+
}
|
|
57
|
+
}));
|
|
58
|
+
|
|
59
|
+
// クリックの当たり判定(#154)。見える線は 1px で当てにくいので、同じ座標に透明な太い線を重ねて
|
|
60
|
+
// そちらで click を受ける(見た目は変えない)。太さは style().relationship.hit.width。
|
|
61
|
+
// 見える線より後に描くので上に乗る。描く先は background レイヤなので、エンティティのクリックは奪わない。
|
|
62
|
+
this._hitLines = new _assh0le.ConnectorLines(_objectSpread(_objectSpread({}, ends), {}, {
|
|
63
|
+
className: 'connector-hit',
|
|
64
|
+
stroke: function stroke() {
|
|
65
|
+
return 'transparent';
|
|
66
|
+
},
|
|
67
|
+
strokeWidth: function strokeWidth() {
|
|
68
|
+
return _this.hitWidth();
|
|
51
69
|
},
|
|
52
70
|
onClick: function onClick(event, d) {
|
|
53
|
-
|
|
54
|
-
|
|
71
|
+
return _this.notifyClick(d);
|
|
72
|
+
}
|
|
73
|
+
}));
|
|
74
|
+
|
|
75
|
+
// サブセット結線の当たり判定。幹とバスは同じ親の関係で共有するので、関係 1 件 = 垂下 1 本にだけ付ける。
|
|
76
|
+
this._subsetHitLines = new _assh0le.ConnectorLines({
|
|
77
|
+
className: 'subset-drop-hit',
|
|
78
|
+
key: function key(d) {
|
|
79
|
+
return d._id;
|
|
80
|
+
},
|
|
81
|
+
x1: function x1(d) {
|
|
82
|
+
return _this.subsetDrop(d).x;
|
|
83
|
+
},
|
|
84
|
+
y1: function y1(d) {
|
|
85
|
+
return _this.subsetDrop(d).busY;
|
|
86
|
+
},
|
|
87
|
+
x2: function x2(d) {
|
|
88
|
+
return _this.subsetDrop(d).x;
|
|
89
|
+
},
|
|
90
|
+
y2: function y2(d) {
|
|
91
|
+
return _this.subsetDrop(d).y;
|
|
92
|
+
},
|
|
93
|
+
stroke: function stroke() {
|
|
94
|
+
return 'transparent';
|
|
95
|
+
},
|
|
96
|
+
strokeWidth: function strokeWidth() {
|
|
97
|
+
return _this.hitWidth();
|
|
98
|
+
},
|
|
99
|
+
onClick: function onClick(event, d) {
|
|
100
|
+
return _this.notifyClick(d);
|
|
55
101
|
}
|
|
56
102
|
});
|
|
57
103
|
}
|
|
@@ -70,6 +116,20 @@ var Relationships = exports["default"] = /*#__PURE__*/function () {
|
|
|
70
116
|
value: function callbacks() {
|
|
71
117
|
return this._parent.callbacks;
|
|
72
118
|
}
|
|
119
|
+
/** 当たり判定用の透明な線の太さ(style().relationship.hit.width。無ければ 9)。 */
|
|
120
|
+
}, {
|
|
121
|
+
key: "hitWidth",
|
|
122
|
+
value: function hitWidth() {
|
|
123
|
+
var hit = this.style().relationship.hit;
|
|
124
|
+
return hit && hit.width ? hit.width : 9;
|
|
125
|
+
}
|
|
126
|
+
/** 結線のクリックを通知する(callbacks.relationship.click)。 */
|
|
127
|
+
}, {
|
|
128
|
+
key: "notifyClick",
|
|
129
|
+
value: function notifyClick(d) {
|
|
130
|
+
var func = this.callbacks().relationship.click;
|
|
131
|
+
if (func) func(d);
|
|
132
|
+
}
|
|
73
133
|
/** port の entity 相対座標を絶対座標にする。 */
|
|
74
134
|
}, {
|
|
75
135
|
key: "fromPoint",
|
|
@@ -103,6 +163,10 @@ var Relationships = exports["default"] = /*#__PURE__*/function () {
|
|
|
103
163
|
return !_this2.isSubset(d) && !_this2.isSelfLink(d);
|
|
104
164
|
});
|
|
105
165
|
this._lines.draw(place, plain);
|
|
166
|
+
|
|
167
|
+
// 当たり判定用の透明な線(#154)。見える線の後に描いて上に乗せる。
|
|
168
|
+
// non-scaling-stroke で、太さ(hit.width)を画面の px にする(縮小しても当たりが細くならない。#209)
|
|
169
|
+
this._hitLines.draw(place, plain).attr('pointer-events', 'stroke').attr('vector-effect', 'non-scaling-stroke');
|
|
106
170
|
this.drawSelfLoops(place, data);
|
|
107
171
|
this.drawSubsetTrees(place, data);
|
|
108
172
|
this.drawMappingDrops(place, data);
|
|
@@ -210,11 +274,19 @@ var Relationships = exports["default"] = /*#__PURE__*/function () {
|
|
|
210
274
|
return d._id;
|
|
211
275
|
});
|
|
212
276
|
paths.exit().remove();
|
|
213
|
-
var entered = paths.enter().append('path').attr('class', 'connector-loop').attr('fill', 'none').attr('stroke', '#888888').attr('stroke-width', 1)
|
|
214
|
-
var func = _this3.callbacks().relationship.click;
|
|
215
|
-
if (func) func(d);
|
|
216
|
-
});
|
|
277
|
+
var entered = paths.enter().append('path').attr('class', 'connector-loop').attr('fill', 'none').attr('stroke', '#888888').attr('stroke-width', 1);
|
|
217
278
|
this.applySelfLoops(entered.merge(paths));
|
|
279
|
+
|
|
280
|
+
// 当たり判定用の透明なループ(#154)。見える線の上に重ね、click はこちらで受ける
|
|
281
|
+
var hits = place.selectAll('path.connector-loop-hit').data(this._selfLinks, function (d) {
|
|
282
|
+
return d._id;
|
|
283
|
+
});
|
|
284
|
+
hits.exit().remove();
|
|
285
|
+
var entered_hits = hits.enter().append('path').attr('class', 'connector-loop-hit').attr('fill', 'none').attr('stroke', 'transparent').attr('stroke-width', this.hitWidth()).attr('pointer-events', 'stroke').attr('vector-effect', 'non-scaling-stroke') // 太さを画面の px に(#209)
|
|
286
|
+
.on('click', function (event, d) {
|
|
287
|
+
return _this3.notifyClick(d);
|
|
288
|
+
});
|
|
289
|
+
this.applySelfLoops(entered_hits.merge(hits));
|
|
218
290
|
}
|
|
219
291
|
}, {
|
|
220
292
|
key: "applySelfLoops",
|
|
@@ -230,6 +302,7 @@ var Relationships = exports["default"] = /*#__PURE__*/function () {
|
|
|
230
302
|
value: function updateSelfLoops(place) {
|
|
231
303
|
if (!this._selfLinks || this._selfLinks.length === 0) return;
|
|
232
304
|
this.applySelfLoops(place.selectAll('path.connector-loop'));
|
|
305
|
+
this.applySelfLoops(place.selectAll('path.connector-loop-hit'));
|
|
233
306
|
}
|
|
234
307
|
/**
|
|
235
308
|
* 結線のラベル(relationship.label)を線の中点の少し上に描く。
|
|
@@ -441,6 +514,57 @@ var Relationships = exports["default"] = /*#__PURE__*/function () {
|
|
|
441
514
|
}
|
|
442
515
|
return path;
|
|
443
516
|
}
|
|
517
|
+
/**
|
|
518
|
+
* サブセットの分岐を描く前に、グループと「関係 → グループ」の索引を作る。
|
|
519
|
+
* クリックの当たり判定は関係 1 件 = 垂下 1 本に付けるので、関係からグループ(バスの高さ)を引けるようにする(#154)。
|
|
520
|
+
*/
|
|
521
|
+
}, {
|
|
522
|
+
key: "indexSubsets",
|
|
523
|
+
value: function indexSubsets(data) {
|
|
524
|
+
this._subsetGroups = this.subsetGroups(data);
|
|
525
|
+
this._subsetRels = [];
|
|
526
|
+
this._subsetGroupOf = new Map();
|
|
527
|
+
var _iterator3 = _createForOfIteratorHelper(this._subsetGroups),
|
|
528
|
+
_step3;
|
|
529
|
+
try {
|
|
530
|
+
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
531
|
+
var group = _step3.value;
|
|
532
|
+
var _iterator4 = _createForOfIteratorHelper(group.rels),
|
|
533
|
+
_step4;
|
|
534
|
+
try {
|
|
535
|
+
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
|
|
536
|
+
var d = _step4.value;
|
|
537
|
+
this._subsetRels.push(d);
|
|
538
|
+
this._subsetGroupOf.set(d._id, group);
|
|
539
|
+
}
|
|
540
|
+
} catch (err) {
|
|
541
|
+
_iterator4.e(err);
|
|
542
|
+
} finally {
|
|
543
|
+
_iterator4.f();
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
} catch (err) {
|
|
547
|
+
_iterator3.e(err);
|
|
548
|
+
} finally {
|
|
549
|
+
_iterator3.f();
|
|
550
|
+
}
|
|
551
|
+
return this._subsetGroups;
|
|
552
|
+
}
|
|
553
|
+
/**
|
|
554
|
+
* サブセット結線 1 件ぶんの垂下(バスの高さ → 子の上端中央)。
|
|
555
|
+
* 幹とバスは同じ親・同じ区分コードの関係で共有するので、関係ごとのクリックはこの線で受ける。
|
|
556
|
+
*/
|
|
557
|
+
}, {
|
|
558
|
+
key: "subsetDrop",
|
|
559
|
+
value: function subsetDrop(d) {
|
|
560
|
+
var g = this.subsetGeometry(this._subsetGroupOf.get(d._id));
|
|
561
|
+
var child = d.to._owner;
|
|
562
|
+
return {
|
|
563
|
+
x: child.position.x + child.size.w / 2,
|
|
564
|
+
y: child.position.y,
|
|
565
|
+
busY: g.busY
|
|
566
|
+
};
|
|
567
|
+
}
|
|
444
568
|
/**
|
|
445
569
|
* サブセットの分岐(幹 + バス + 垂下)と、幹の分岐点に添える区分コード
|
|
446
570
|
* (=区分コード / ×区分コード)を描く。enter/update join で冪等。
|
|
@@ -448,7 +572,7 @@ var Relationships = exports["default"] = /*#__PURE__*/function () {
|
|
|
448
572
|
}, {
|
|
449
573
|
key: "drawSubsetTrees",
|
|
450
574
|
value: function drawSubsetTrees(place, data) {
|
|
451
|
-
this.
|
|
575
|
+
this.indexSubsets(data);
|
|
452
576
|
var paths = place.selectAll('path.subset-line').data(this._subsetGroups, function (d) {
|
|
453
577
|
return d.key;
|
|
454
578
|
});
|
|
@@ -460,6 +584,9 @@ var Relationships = exports["default"] = /*#__PURE__*/function () {
|
|
|
460
584
|
labels.exit().remove();
|
|
461
585
|
var entered_labels = labels.enter().append('text').attr('class', 'subset-code').attr('text-anchor', 'middle').attr('font-size', '12px').attr('fill', '#333333');
|
|
462
586
|
this.applySubsetTrees(entered_paths.merge(paths), entered_labels.merge(labels));
|
|
587
|
+
|
|
588
|
+
// 当たり判定(関係 1 件 = 垂下 1 本)。見える分岐線より後に描いて上に乗せる(#154)
|
|
589
|
+
this._subsetHitLines.draw(place, this._subsetRels).attr('pointer-events', 'stroke').attr('vector-effect', 'non-scaling-stroke'); // 太さを画面の px に(#209)
|
|
463
590
|
}
|
|
464
591
|
/** 分岐線の形状とラベル(バスの少し上・幹の位置)を適用する。 */
|
|
465
592
|
}, {
|
|
@@ -483,6 +610,9 @@ var Relationships = exports["default"] = /*#__PURE__*/function () {
|
|
|
483
610
|
value: function updateSubsetTrees(place) {
|
|
484
611
|
if (!this._subsetGroups || this._subsetGroups.length === 0) return;
|
|
485
612
|
this.applySubsetTrees(place.selectAll('path.subset-line'), place.selectAll('text.subset-code'));
|
|
613
|
+
|
|
614
|
+
// 当たり判定用の線も追従させる(#154)
|
|
615
|
+
this._subsetHitLines.update(place.selectAll('line.subset-drop-hit'));
|
|
486
616
|
}
|
|
487
617
|
// Entity のドラッグ追従(Painters/Entities.js)から呼ばれる。
|
|
488
618
|
// 指定 entity に接続する線を選択して座標を再適用する。
|
|
@@ -494,12 +624,17 @@ var Relationships = exports["default"] = /*#__PURE__*/function () {
|
|
|
494
624
|
var edges = entity.ports.items.list.map(function (p) {
|
|
495
625
|
return p._relationship;
|
|
496
626
|
});
|
|
497
|
-
var
|
|
627
|
+
var plain = edges.filter(function (d) {
|
|
498
628
|
return !_this0.isSubset(d) && !_this0.isSelfLink(d);
|
|
499
|
-
}), function (d) {
|
|
500
|
-
return d._id;
|
|
501
629
|
});
|
|
502
|
-
this._lines.update(
|
|
630
|
+
this._lines.update(place.selectAll('line.connector').data(plain, function (d) {
|
|
631
|
+
return d._id;
|
|
632
|
+
}));
|
|
633
|
+
|
|
634
|
+
// 当たり判定用の線も追従させる(#154)
|
|
635
|
+
this._hitLines.update(place.selectAll('line.connector-hit').data(plain, function (d) {
|
|
636
|
+
return d._id;
|
|
637
|
+
}));
|
|
503
638
|
|
|
504
639
|
// 自己結線のループも追従させる
|
|
505
640
|
this.updateSelfLoops(place);
|
package/dist/js/Rectum.js
CHANGED
package/jest.config.js
CHANGED
|
@@ -14,6 +14,9 @@ module.exports = {
|
|
|
14
14
|
// CommonJS 版(model.tm の build が dist/cjs/ に出す)へ直接マップする。
|
|
15
15
|
// model.tm を先にビルドしておくこと(npm run build -w @yanqirenshi/model.tm)。
|
|
16
16
|
'^@yanqirenshi/model.tm$': '<rootDir>/../model.tm/dist/cjs/index.js',
|
|
17
|
+
// model.tm の CommonJS 版は @yanqirenshi/model.core を require する。同じ理由でこちらも CommonJS 版へマップする
|
|
18
|
+
// (model.core を先にビルドしておくこと。外してよくなる条件は上と同じ)。
|
|
19
|
+
'^@yanqirenshi/model.core$': '<rootDir>/../model.core/dist/cjs/index.js',
|
|
17
20
|
},
|
|
18
21
|
collectCoverageFrom: [
|
|
19
22
|
"**/src/**/*.js",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yanqirenshi/d3.ter",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.2",
|
|
4
4
|
"author": "yanqirenshi@gmail.com",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"description": "TM (T-shaped ER method) diagram renderer — 10 entity kinds, cardinality/optionality markers, and correspondence / comparative / recursion tables hung from a connector",
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/* ******************************************************** *
|
|
2
|
+
* 当たり判定の太さを、画面の px にする(#209)
|
|
3
|
+
* ******************************************************** */
|
|
4
|
+
|
|
5
|
+
// DOM の結果を確かめたいので、実物の d3 を使う(d3.network の Edges.events.test.js と同じ)
|
|
6
|
+
jest.mock('d3', () => jest.requireActual('../../../node_modules/d3/dist/d3.js'));
|
|
7
|
+
|
|
8
|
+
import * as d3 from 'd3';
|
|
9
|
+
import Relationships from '../src/js/Painters/Relationships.js';
|
|
10
|
+
|
|
11
|
+
const box = (id, x, y) => ({ _id: id, position: { x, y }, size: { w: 100, h: 50 } });
|
|
12
|
+
const port = (cls, owner, x, y) => ({ _class: cls, _owner: owner, position: ()=> ({ x, y }) });
|
|
13
|
+
|
|
14
|
+
const A = box('A', 0, 0);
|
|
15
|
+
const B = box('B', 300, 0);
|
|
16
|
+
const C = box('C', 0, 200);
|
|
17
|
+
const D = box('D', 200, 200);
|
|
18
|
+
|
|
19
|
+
const link = (id, from, to, extra = {}) => ({
|
|
20
|
+
_id: id,
|
|
21
|
+
from: port('PORT-FROM', from, 50, 50),
|
|
22
|
+
to: port('PORT-TO', to, 50, 0),
|
|
23
|
+
...extra,
|
|
24
|
+
});
|
|
25
|
+
const subset = (id, to) => link(id, A, to, { subsetLabel: ()=> '=kind', _core: { subset: { code: 'kind' } } });
|
|
26
|
+
|
|
27
|
+
const draw = () => {
|
|
28
|
+
document.body.innerHTML = '<svg><g class="background"></g></svg>';
|
|
29
|
+
|
|
30
|
+
const place = d3.select('g.background');
|
|
31
|
+
const painter = new Relationships({
|
|
32
|
+
rectum: ()=> ({ style: ()=> ({ relationship: { loop: { distance: 40 } } }) }),
|
|
33
|
+
callbacks: { relationship: {} },
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
painter.drawRelationships(place, { list: [
|
|
37
|
+
link('plain', A, B),
|
|
38
|
+
{ ...link('self', A, A), to: port('PORT-TO', A, 100, 25) },
|
|
39
|
+
subset('sub-c', C),
|
|
40
|
+
subset('sub-d', D),
|
|
41
|
+
] });
|
|
42
|
+
|
|
43
|
+
return place;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
describe('当たり判定の線は、拡大率に関わらず画面の上で同じ太さ(vector-effect: non-scaling-stroke)', () => {
|
|
47
|
+
it('直線・ループ・サブセットの垂下の当たり判定に付く', () => {
|
|
48
|
+
draw();
|
|
49
|
+
|
|
50
|
+
const hits = [...document.querySelectorAll('.connector-hit, .connector-loop-hit, .subset-drop-hit')];
|
|
51
|
+
|
|
52
|
+
expect(hits.map((e)=> e.getAttribute('class'))).toEqual(
|
|
53
|
+
['connector-hit', 'connector-loop-hit', 'subset-drop-hit', 'subset-drop-hit']);
|
|
54
|
+
|
|
55
|
+
for (const hit of hits) {
|
|
56
|
+
expect(hit.getAttribute('vector-effect')).toBe('non-scaling-stroke');
|
|
57
|
+
expect(hit.getAttribute('pointer-events')).toBe('stroke');
|
|
58
|
+
expect(hit.getAttribute('stroke-width')).toBe('9'); // 太さの値は変えない
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it('見える線には付けない(見た目は、拡大率に合わせて太さが変わるまま)', () => {
|
|
63
|
+
draw();
|
|
64
|
+
|
|
65
|
+
const visible = [...document.querySelectorAll('line.connector, path.connector-loop, path.subset-line')];
|
|
66
|
+
|
|
67
|
+
expect(visible).toHaveLength(3);
|
|
68
|
+
for (const e of visible)
|
|
69
|
+
expect(e.getAttribute('vector-effect')).toBeNull();
|
|
70
|
+
});
|
|
71
|
+
});
|
|
@@ -127,3 +127,45 @@ describe('自己結線(再帰)はループとして描く', () => {
|
|
|
127
127
|
expect({ x: g.jx, y: g.jy }).toEqual(j);
|
|
128
128
|
});
|
|
129
129
|
});
|
|
130
|
+
|
|
131
|
+
// #154: 結線のクリックは、見える線(1px)の上に重ねた透明な線で受ける(見た目は変えずに当たりだけ広げる)。
|
|
132
|
+
describe('クリックの当たり判定(#154)', () => {
|
|
133
|
+
const painterWith = (style) => new Relationships({
|
|
134
|
+
rectum: ()=> ({ style: ()=> style }),
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
it('hitWidth は style().relationship.hit.width。無ければ 9', () => {
|
|
138
|
+
expect(painterWith({ relationship: { hit: { width: 12 } } }).hitWidth()).toBe(12);
|
|
139
|
+
expect(painterWith({ relationship: { loop: { distance: 40 } } }).hitWidth()).toBe(9);
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
it('サブセットは関係 1 件 = 垂下 1 本。垂下はバスの高さから子の上端中央へ', () => {
|
|
143
|
+
const painter = painterWith({ relationship: {} });
|
|
144
|
+
|
|
145
|
+
// 親: 下端 y=200、中央 x=200。子 A の上端中央 (50, 400)、子 B の上端中央 (350, 300)
|
|
146
|
+
const parent = { _id: 'p', position: { x: 100, y: 100 }, size: { w: 200, h: 100 } };
|
|
147
|
+
const childA = { position: { x: 0, y: 400 }, size: { w: 100, h: 50 } };
|
|
148
|
+
const childB = { position: { x: 300, y: 300 }, size: { w: 100, h: 50 } };
|
|
149
|
+
|
|
150
|
+
const subset = (id, child) => ({
|
|
151
|
+
_id: id,
|
|
152
|
+
_core: { subset: { code: 'kind' } },
|
|
153
|
+
subsetLabel: ()=> '=kind',
|
|
154
|
+
from: { _owner: parent },
|
|
155
|
+
to: { _owner: child },
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
const a = subset('r-a', childA);
|
|
159
|
+
const b = subset('r-b', childB);
|
|
160
|
+
const plain = { _id: 'r-plain', subsetLabel: ()=> null, from: { _owner: parent }, to: { _owner: childA } };
|
|
161
|
+
|
|
162
|
+
const groups = painter.indexSubsets([a, plain, b]);
|
|
163
|
+
|
|
164
|
+
expect(groups).toHaveLength(1); // 同じ親・同じ区分コードは 1 つの分岐
|
|
165
|
+
expect(painter._subsetRels).toEqual([a, b]); // 当たり判定は関係ごと(通常の結線は含まない)
|
|
166
|
+
|
|
167
|
+
// バスは親の下端(200)と一番高い子の上端(300)の中間 → 250
|
|
168
|
+
expect(painter.subsetDrop(a)).toEqual({ x: 50, y: 400, busY: 250 });
|
|
169
|
+
expect(painter.subsetDrop(b)).toEqual({ x: 350, y: 300, busY: 250 });
|
|
170
|
+
});
|
|
171
|
+
});
|