@yanqirenshi/d3.ter 0.4.0 → 0.4.1

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 CHANGED
@@ -103,6 +103,11 @@ 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
+
106
111
  ## 開発
107
112
 
108
113
  ```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
- this._lines = new _assh0le.ConnectorLines({
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
- var func = _this.callbacks().relationship.click;
54
- if (func) func(d);
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,9 @@ 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
+ this._hitLines.draw(place, plain).attr('pointer-events', 'stroke');
106
169
  this.drawSelfLoops(place, data);
107
170
  this.drawSubsetTrees(place, data);
108
171
  this.drawMappingDrops(place, data);
@@ -210,11 +273,18 @@ var Relationships = exports["default"] = /*#__PURE__*/function () {
210
273
  return d._id;
211
274
  });
212
275
  paths.exit().remove();
213
- var entered = paths.enter().append('path').attr('class', 'connector-loop').attr('fill', 'none').attr('stroke', '#888888').attr('stroke-width', 1).on('click', function (event, d) {
214
- var func = _this3.callbacks().relationship.click;
215
- if (func) func(d);
216
- });
276
+ var entered = paths.enter().append('path').attr('class', 'connector-loop').attr('fill', 'none').attr('stroke', '#888888').attr('stroke-width', 1);
217
277
  this.applySelfLoops(entered.merge(paths));
278
+
279
+ // 当たり判定用の透明なループ(#154)。見える線の上に重ね、click はこちらで受ける
280
+ var hits = place.selectAll('path.connector-loop-hit').data(this._selfLinks, function (d) {
281
+ return d._id;
282
+ });
283
+ hits.exit().remove();
284
+ 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').on('click', function (event, d) {
285
+ return _this3.notifyClick(d);
286
+ });
287
+ this.applySelfLoops(entered_hits.merge(hits));
218
288
  }
219
289
  }, {
220
290
  key: "applySelfLoops",
@@ -230,6 +300,7 @@ var Relationships = exports["default"] = /*#__PURE__*/function () {
230
300
  value: function updateSelfLoops(place) {
231
301
  if (!this._selfLinks || this._selfLinks.length === 0) return;
232
302
  this.applySelfLoops(place.selectAll('path.connector-loop'));
303
+ this.applySelfLoops(place.selectAll('path.connector-loop-hit'));
233
304
  }
234
305
  /**
235
306
  * 結線のラベル(relationship.label)を線の中点の少し上に描く。
@@ -441,6 +512,57 @@ var Relationships = exports["default"] = /*#__PURE__*/function () {
441
512
  }
442
513
  return path;
443
514
  }
515
+ /**
516
+ * サブセットの分岐を描く前に、グループと「関係 → グループ」の索引を作る。
517
+ * クリックの当たり判定は関係 1 件 = 垂下 1 本に付けるので、関係からグループ(バスの高さ)を引けるようにする(#154)。
518
+ */
519
+ }, {
520
+ key: "indexSubsets",
521
+ value: function indexSubsets(data) {
522
+ this._subsetGroups = this.subsetGroups(data);
523
+ this._subsetRels = [];
524
+ this._subsetGroupOf = new Map();
525
+ var _iterator3 = _createForOfIteratorHelper(this._subsetGroups),
526
+ _step3;
527
+ try {
528
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
529
+ var group = _step3.value;
530
+ var _iterator4 = _createForOfIteratorHelper(group.rels),
531
+ _step4;
532
+ try {
533
+ for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
534
+ var d = _step4.value;
535
+ this._subsetRels.push(d);
536
+ this._subsetGroupOf.set(d._id, group);
537
+ }
538
+ } catch (err) {
539
+ _iterator4.e(err);
540
+ } finally {
541
+ _iterator4.f();
542
+ }
543
+ }
544
+ } catch (err) {
545
+ _iterator3.e(err);
546
+ } finally {
547
+ _iterator3.f();
548
+ }
549
+ return this._subsetGroups;
550
+ }
551
+ /**
552
+ * サブセット結線 1 件ぶんの垂下(バスの高さ → 子の上端中央)。
553
+ * 幹とバスは同じ親・同じ区分コードの関係で共有するので、関係ごとのクリックはこの線で受ける。
554
+ */
555
+ }, {
556
+ key: "subsetDrop",
557
+ value: function subsetDrop(d) {
558
+ var g = this.subsetGeometry(this._subsetGroupOf.get(d._id));
559
+ var child = d.to._owner;
560
+ return {
561
+ x: child.position.x + child.size.w / 2,
562
+ y: child.position.y,
563
+ busY: g.busY
564
+ };
565
+ }
444
566
  /**
445
567
  * サブセットの分岐(幹 + バス + 垂下)と、幹の分岐点に添える区分コード
446
568
  * (=区分コード / ×区分コード)を描く。enter/update join で冪等。
@@ -448,7 +570,7 @@ var Relationships = exports["default"] = /*#__PURE__*/function () {
448
570
  }, {
449
571
  key: "drawSubsetTrees",
450
572
  value: function drawSubsetTrees(place, data) {
451
- this._subsetGroups = this.subsetGroups(data);
573
+ this.indexSubsets(data);
452
574
  var paths = place.selectAll('path.subset-line').data(this._subsetGroups, function (d) {
453
575
  return d.key;
454
576
  });
@@ -460,6 +582,9 @@ var Relationships = exports["default"] = /*#__PURE__*/function () {
460
582
  labels.exit().remove();
461
583
  var entered_labels = labels.enter().append('text').attr('class', 'subset-code').attr('text-anchor', 'middle').attr('font-size', '12px').attr('fill', '#333333');
462
584
  this.applySubsetTrees(entered_paths.merge(paths), entered_labels.merge(labels));
585
+
586
+ // 当たり判定(関係 1 件 = 垂下 1 本)。見える分岐線より後に描いて上に乗せる(#154)
587
+ this._subsetHitLines.draw(place, this._subsetRels).attr('pointer-events', 'stroke');
463
588
  }
464
589
  /** 分岐線の形状とラベル(バスの少し上・幹の位置)を適用する。 */
465
590
  }, {
@@ -483,6 +608,9 @@ var Relationships = exports["default"] = /*#__PURE__*/function () {
483
608
  value: function updateSubsetTrees(place) {
484
609
  if (!this._subsetGroups || this._subsetGroups.length === 0) return;
485
610
  this.applySubsetTrees(place.selectAll('path.subset-line'), place.selectAll('text.subset-code'));
611
+
612
+ // 当たり判定用の線も追従させる(#154)
613
+ this._subsetHitLines.update(place.selectAll('line.subset-drop-hit'));
486
614
  }
487
615
  // Entity のドラッグ追従(Painters/Entities.js)から呼ばれる。
488
616
  // 指定 entity に接続する線を選択して座標を再適用する。
@@ -494,12 +622,17 @@ var Relationships = exports["default"] = /*#__PURE__*/function () {
494
622
  var edges = entity.ports.items.list.map(function (p) {
495
623
  return p._relationship;
496
624
  });
497
- var selection = place.selectAll('line.connector').data(edges.filter(function (d) {
625
+ var plain = edges.filter(function (d) {
498
626
  return !_this0.isSubset(d) && !_this0.isSelfLink(d);
499
- }), function (d) {
500
- return d._id;
501
627
  });
502
- this._lines.update(selection);
628
+ this._lines.update(place.selectAll('line.connector').data(plain, function (d) {
629
+ return d._id;
630
+ }));
631
+
632
+ // 当たり判定用の線も追従させる(#154)
633
+ this._hitLines.update(place.selectAll('line.connector-hit').data(plain, function (d) {
634
+ return d._id;
635
+ }));
503
636
 
504
637
  // 自己結線のループも追従させる
505
638
  this.updateSelfLoops(place);
package/dist/js/Rectum.js CHANGED
@@ -244,6 +244,10 @@ var Rectum = exports["default"] = /*#__PURE__*/function (_Colon) {
244
244
  // 制御点を各ポートの外向きにこの距離だけ伸ばす。
245
245
  loop: {
246
246
  distance: 40
247
+ },
248
+ // クリックの当たり判定の太さ(#154)。見える線(1px)の上に、この太さの透明な線を重ねて click を受ける。
249
+ hit: {
250
+ width: 9
247
251
  }
248
252
  }
249
253
  };
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.0",
3
+ "version": "0.4.1",
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",
@@ -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
+ });