@yanqirenshi/d3.ter 0.1.26 → 0.3.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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2018-2026 Satoshi Iwasaki (yanqirenshi@gmail.com)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,68 +1,106 @@
1
- This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
2
-
3
- ## Available Scripts
4
-
5
- In the project directory, you can run:
6
-
7
- ### `npm start`
8
-
9
- Runs the app in the development mode.<br />
10
- Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
11
-
12
- The page will reload if you make edits.<br />
13
- You will also see any lint errors in the console.
14
-
15
- ### `npm test`
16
-
17
- Launches the test runner in the interactive watch mode.<br />
18
- See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
19
-
20
- ### `npm run build`
21
-
22
- Builds the app for production to the `build` folder.<br />
23
- It correctly bundles React in production mode and optimizes the build for the best performance.
24
-
25
- The build is minified and the filenames include the hashes.<br />
26
- Your app is ready to be deployed!
27
-
28
- See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
29
-
30
- ### `npm run eject`
31
-
32
- **Note: this is a one-way operation. Once you `eject`, you can’t go back!**
33
-
34
- If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
35
-
36
- Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.
37
-
38
- You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.
39
-
40
- ## Learn More
41
-
42
- You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
43
-
44
- To learn React, check out the [React documentation](https://reactjs.org/).
45
-
46
- ### Code Splitting
47
-
48
- This section has moved here: https://facebook.github.io/create-react-app/docs/code-splitting
49
-
50
- ### Analyzing the Bundle Size
51
-
52
- This section has moved here: https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size
53
-
54
- ### Making a Progressive Web App
55
-
56
- This section has moved here: https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app
57
-
58
- ### Advanced Configuration
59
-
60
- This section has moved here: https://facebook.github.io/create-react-app/docs/advanced-configuration
61
-
62
- ### Deployment
63
-
64
- This section has moved here: https://facebook.github.io/create-react-app/docs/deployment
65
-
66
- ### `npm run build` fails to minify
67
-
68
- This section has moved here: https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify
1
+ # @yanqirenshi/d3.ter
2
+
3
+ TM(T字形ER手法)の ER 図(TER)を SVG で描画する React コンポーネントです。
4
+
5
+ - エンティティは TM の10種の種別(リソース / イベント / それぞれのサブセット /
6
+ 対応表 / 対照表 / 再帰表 / 多値 MO・MA / クラス)を配色とバッジで描き分けます。
7
+ - 結線はポートの角度で取り付け位置を指定し、カーディナリティ(1 / 多)と
8
+ オプショナリティ(必須 / 任意)を記号で表します。
9
+ - サブセットへの結線は区分コード(=同一 / ×相違)付きの分岐(幹 + バス + 垂下)で描きます。
10
+ - 対応表・対照表・再帰表は、結線の中点の○から垂下線でぶら下げます(`mapping`)。
11
+ - エンティティはドラッグで移動でき、結線・記号・垂下線が追従します。
12
+
13
+ ## インストール
14
+
15
+ ```bash
16
+ npm install @yanqirenshi/d3.ter
17
+ ```
18
+
19
+ React 18 / 19 に対応しています(`peerDependencies`)。
20
+
21
+ ## 使い方
22
+
23
+ 描画の管理オブジェクト `Rectum` を作って React コンポーネント `D3Ter` に渡し、
24
+ `data()` でデータを流し込みます。
25
+
26
+ ```jsx
27
+ import React from 'react';
28
+ import D3Ter, { Rectum } from '@yanqirenshi/d3.ter';
29
+
30
+ export default function Graph({ data }) {
31
+ const [rectum, setRectum] = React.useState(null);
32
+
33
+ React.useEffect(() => {
34
+ setRectum(new Rectum({
35
+ transform: { k: 0.7, x: 200, y: 60 }, // 初期のズーム / パン
36
+ svg: { style: { background: '#fff' } },
37
+ callbacks: {
38
+ // contextmenu は右クリック。引数は click と同じで、最後に event(MouseEvent)。
39
+ // 渡したときだけブラウザ標準のメニューを止める。ドラッグ中は呼ばれない
40
+ entity: { click: (d) => {}, contextmenu: (d, event) => {} },
41
+ identifier: { click: (d) => {}, contextmenu: (d, event) => {} },
42
+ attribute: { click: (d) => {}, contextmenu: (d, event) => {} },
43
+ relationship: { click: (d) => {} },
44
+ },
45
+ }));
46
+ }, []);
47
+
48
+ React.useEffect(() => {
49
+ if (rectum) rectum.data(data);
50
+ }, [rectum, data]);
51
+
52
+ if (!rectum) return null;
53
+
54
+ return (
55
+ <div style={{ width: '100%', height: '100%' }}>
56
+ <D3Ter rectum={rectum} />
57
+ </div>
58
+ );
59
+ }
60
+ ```
61
+
62
+ ## 入力データ
63
+
64
+ `{ identifiers, attributes, entities, relationships }` の連想配列です。
65
+ 識別子・属性を「定義」として持ち、エンティティとリレーションシップがそれを参照します。
66
+
67
+ **フィールドの詳細は [`src/index.d.ts`](src/index.d.ts) が正**なので、そちらを参照してください。
68
+ 動く例はショーケースの d3.ter のページ(「データ」タブ)にあります。
69
+ サンプルの実データは `showcase/src/demos/data/ter-sample.js` です。
70
+
71
+ ## 再帰(RECURSION)の書き方(v0.2.0+)
72
+
73
+ `from.entity` と `to.entity` に**同じエンティティ**を指定すると「自己結線」になり、
74
+ 直線ではなく**箱の外側を回るループ**(3次ベジエ)で描かれます。
75
+ TM の再帰がこれで、ループの中点の○から再帰表を垂下します。
76
+
77
+ ```js
78
+ {
79
+ id: 9, type: null,
80
+ // 両端に同じモノ(部品)を指定 → ループになる
81
+ from: { entity: 30002, cardinality: 3, optionality: 0, position: 340 },
82
+ to: { entity: 30002, cardinality: 3, optionality: 0, position: 20 },
83
+ details: [{ from: { id: 3000201 }, to: { id: 3000201 } }],
84
+ // ループの中点(○)から再帰表へ垂下する
85
+ mapping: { entity: 82000 }, // 部品.部品.再帰表 (RECURSION)
86
+ }
87
+ ```
88
+
89
+ - **ループの向きは両端の `position`(角度)で決まります。** 0=真下・時計回り。
90
+ 上の例のように両端を近い角度(340 / 20)にすると、箱の下に U 字のループが下がります。
91
+ - **再帰表は自己結線にだけ垂下できます。** 通常の結線(`from.entity !== to.entity`)に
92
+ `mapping` で RECURSION を指定すると、データ構築時に例外になります。
93
+ - 1つのモノに複数のループを描くときは、**角度を変えて**指定してください
94
+ (同じ角度どうしは重なります。自動のオフセットは入りません)。
95
+ - ループの膨らむ距離は `style().relationship.loop.distance`(既定 40)です。
96
+
97
+ 描画される要素は `path.connector-loop` で、通常の結線(`line.connector`)とは別です。
98
+ ループ上の○(`circle.mapping-junction`)とラベル(`text.relationship-label`)は、
99
+ ともにベジエの中点(t=0.5)に乗ります。
100
+
101
+ ## 開発
102
+
103
+ ```bash
104
+ npm run transpile -w @yanqirenshi/d3.ter # src -> dist(dist はコミット対象)
105
+ npm test -w @yanqirenshi/d3.ter # jest
106
+ ```
@@ -1,14 +1,12 @@
1
1
  "use strict";
2
2
 
3
- function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
4
3
  Object.defineProperty(exports, "__esModule", {
5
4
  value: true
6
5
  });
7
6
  exports["default"] = D3Ter;
8
- var _react = _interopRequireWildcard(require("react"));
7
+ var _react = _interopRequireDefault(require("react"));
9
8
  var _assh0le = _interopRequireDefault(require("@yanqirenshi/assh0le"));
10
9
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
11
- function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, "default": e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
12
10
  function D3Ter(props) {
13
11
  var rectum = props.rectum;
14
12
  var id = props.id || "d3-ter-graph";
package/dist/index.d.ts CHANGED
@@ -122,7 +122,15 @@ export interface TerSubset {
122
122
  code: string;
123
123
  }
124
124
 
125
- /** エンティティ間のリレーションシップ */
125
+ /**
126
+ * エンティティ間のリレーションシップ。
127
+ *
128
+ * from.entity と to.entity に同じエンティティを指定すると「自己結線」になり、
129
+ * 直線ではなく**箱の外側を回るループ**(3次ベジエ)で描かれる。TM の再帰が
130
+ * これで、ループの中点の○から再帰表(RECURSION)を垂下する(mapping)。
131
+ * ループの膨らむ向きは両端のポートの position(角度)で決まるので、
132
+ * 1つのモノに複数のループを描くときは角度を変える(自動の重なり回避はしない)。
133
+ */
126
134
  export interface TerRelationship {
127
135
  id: number | string;
128
136
  type?: string | null;
@@ -133,10 +141,14 @@ export interface TerRelationship {
133
141
  /** サブセットへの結線に区分コード(= / ×)を表示する(任意) */
134
142
  subset?: TerSubset;
135
143
  /**
136
- * 対応表/対照表の垂下(任意)。結線の中点の○から垂下線で指定エンティティへ
144
+ * 対応表/対照表/再帰表の垂下(任意)。結線の中点の○から垂下線で指定エンティティへ
137
145
  * ぶら下げる(tm3-1 §2「対応表(onto-mapping)」の書き方)。線は表の最寄りの
138
146
  * 辺(上下左右)の中央に取り付く(中点から見た方向で自動選択)。指定できるのは
139
- * 対応表(CORRESPONDENCE)/対照表(COMPARATIVE)のみ — それ以外は構築時に例外
147
+ * 対応表(CORRESPONDENCE)/対照表(COMPARATIVE)/再帰表(RECURSION)のみ —
148
+ * それ以外は構築時に例外。
149
+ *
150
+ * 再帰表(RECURSION)は**自己結線(from.entity === to.entity)にだけ**指定できる。
151
+ * 通常の結線に指定すると構築時に例外になる。
140
152
  */
141
153
  mapping?: { entity: number | string };
142
154
  /** 結線の中点に表示するラベル(任意。subset 指定時は区分コードが優先され表示されない) */
@@ -172,6 +184,24 @@ export interface TerCallbacks {
172
184
  entity?: {
173
185
  /** エンティティのクリック通知(正規化済みデータが渡される) */
174
186
  click?: ((entity: TerEntityDatum) => void) | null;
187
+ /**
188
+ * エンティティの右クリック通知。引数は click と同じで、最後に event が付く。
189
+ * 渡したときだけブラウザ標準のコンテキストメニューを止める。
190
+ * 左ボタンを押したまま(ドラッグ中)の右クリックでは呼ばれない。
191
+ */
192
+ contextmenu?: ((entity: TerEntityDatum, event: MouseEvent) => void) | null;
193
+ };
194
+ identifier?: {
195
+ /** 識別子の行のクリック通知 */
196
+ click?: ((identifier: unknown) => void) | null;
197
+ /** 識別子の行の右クリック通知(扱いは entity.contextmenu と同じ) */
198
+ contextmenu?: ((identifier: unknown, event: MouseEvent) => void) | null;
199
+ };
200
+ attribute?: {
201
+ /** 属性の行のクリック通知 */
202
+ click?: ((attribute: unknown) => void) | null;
203
+ /** 属性の行の右クリック通知(扱いは entity.contextmenu と同じ) */
204
+ contextmenu?: ((attribute: unknown, event: MouseEvent) => void) | null;
175
205
  };
176
206
  }
177
207
 
@@ -8,6 +8,12 @@ var d3 = _interopRequireWildcard(require("d3"));
8
8
  var _assh0le = require("@yanqirenshi/assh0le");
9
9
  function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, "default": e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
10
10
  function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
11
+ function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
12
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
13
+ 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; } }
14
+ 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; }
15
+ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
16
+ function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
11
17
  function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
12
18
  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); } }
13
19
  function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
@@ -373,6 +379,7 @@ var Entities = exports["default"] = /*#__PURE__*/function () {
373
379
  key: "draw",
374
380
  value: function draw(entities) {
375
381
  var groups = this._box.draw(this.foreground(), entities);
382
+ this.attachContextmenu(groups);
376
383
 
377
384
  // resizing & redraw
378
385
  groups.each(function (entity) {
@@ -381,5 +388,35 @@ var Entities = exports["default"] = /*#__PURE__*/function () {
381
388
  this.redraw(groups);
382
389
  return groups;
383
390
  }
391
+ /**
392
+ * 右クリックの通知(callbacks.entity / identifier / attribute の contextmenu)。
393
+ * 引数は click と同じで、最後に event を付ける。
394
+ *
395
+ * CompartmentBox は onClick しか持たないので、描いたあとで click と同じ
396
+ * 要素に付ける(共通基盤の assh0le には手を入れない)。
397
+ * コールバックが無いときと、左ボタンを押したまま(ドラッグ中)のときは
398
+ * 何もしない(ブラウザ標準のコンテキストメニューが出る)。
399
+ */
400
+ }, {
401
+ key: "attachContextmenu",
402
+ value: function attachContextmenu(groups) {
403
+ var _this3 = this;
404
+ var targets = [['entity', 'rect.entity-title, text.entity-title'], ['identifier', 'text.identifier'], ['attribute', 'text.attribute']];
405
+ var _loop = function _loop() {
406
+ var _targets$_i = _slicedToArray(_targets[_i], 2),
407
+ name = _targets$_i[0],
408
+ selector = _targets$_i[1];
409
+ groups.selectAll(selector).on('contextmenu', function (event, d) {
410
+ var func = (_this3.callbacks()[name] || {}).contextmenu;
411
+ if (!func || event.buttons & 1) return;
412
+ event.preventDefault();
413
+ event.stopPropagation();
414
+ func(d, event);
415
+ });
416
+ };
417
+ for (var _i = 0, _targets = targets; _i < _targets.length; _i++) {
418
+ _loop();
419
+ }
420
+ }
384
421
  }]);
385
422
  }();
@@ -39,8 +39,6 @@ var PortCardinalities = exports["default"] = /*#__PURE__*/function () {
39
39
  }, function (d) {
40
40
  return d.id();
41
41
  });
42
- console.log();
43
- console.log();
44
42
  var draw = function draw(selection) {
45
43
  selection.attr("x1", function (d) {
46
44
  return d.linePosition().from.x;
@@ -97,15 +97,140 @@ var Relationships = exports["default"] = /*#__PURE__*/function () {
97
97
  });
98
98
 
99
99
  // サブセット結線は直線ではなく「幹 + 水平バス + 垂下」のグループ線
100
- // (tm3-1 §5、組織図と同じ直交スタイル)で描くため、直線からは除外する
100
+ // (tm3-1 §5、組織図と同じ直交スタイル)で描くため、直線からは除外する。
101
+ // 自己結線(再帰)も直線では箱を横切るので、ループ(3次ベジエ)で別に描く。
101
102
  var plain = data.filter(function (d) {
102
- return !_this2.isSubset(d);
103
+ return !_this2.isSubset(d) && !_this2.isSelfLink(d);
103
104
  });
104
105
  this._lines.draw(place, plain);
106
+ this.drawSelfLoops(place, data);
105
107
  this.drawSubsetTrees(place, data);
106
108
  this.drawMappingDrops(place, data);
107
109
  this.drawLabels(place, data);
108
110
  }
111
+ /** 自己結線(from と to が同じエンティティ)か。TM の再帰がこれ。 */
112
+ }, {
113
+ key: "isSelfLink",
114
+ value: function isSelfLink(d) {
115
+ return d.from._owner === d.to._owner;
116
+ }
117
+ }, {
118
+ key: "loopDistance",
119
+ value: function loopDistance() {
120
+ return this.style().relationship.loop.distance;
121
+ }
122
+ /**
123
+ * port の外向き方向(エンティティ中心 → port の単位ベクトル)。
124
+ * ループの制御点を箱の外へ伸ばすのに使う。
125
+ */
126
+ }, {
127
+ key: "outwardOf",
128
+ value: function outwardOf(port, point) {
129
+ var owner = port._owner;
130
+ var cx = owner.position.x + owner.size.w / 2;
131
+ var cy = owner.position.y + owner.size.h / 2;
132
+ var dx = point.x - cx;
133
+ var dy = point.y - cy;
134
+ var length = Math.sqrt(dx * dx + dy * dy) || 1;
135
+ return {
136
+ x: dx / length,
137
+ y: dy / length
138
+ };
139
+ }
140
+ /**
141
+ * 自己結線のループ(3次ベジエ)の制御点。
142
+ * 両端のポートから、それぞれの外向きへ loop.distance だけ伸ばした点を
143
+ * 制御点にすることで、箱を横切らず外側に膨らむ弧になる。
144
+ * 複数のループはポートの角度(position)を変えて描き分ける。
145
+ */
146
+ }, {
147
+ key: "loopGeometry",
148
+ value: function loopGeometry(d) {
149
+ var p0 = this.fromPoint(d);
150
+ var p3 = this.toPoint(d);
151
+ var distance = this.loopDistance();
152
+ var v0 = this.outwardOf(d.from, p0);
153
+ var v3 = this.outwardOf(d.to, p3);
154
+ return {
155
+ p0: p0,
156
+ p1: {
157
+ x: p0.x + v0.x * distance,
158
+ y: p0.y + v0.y * distance
159
+ },
160
+ p2: {
161
+ x: p3.x + v3.x * distance,
162
+ y: p3.y + v3.y * distance
163
+ },
164
+ p3: p3
165
+ };
166
+ }
167
+ }, {
168
+ key: "loopPath",
169
+ value: function loopPath(d) {
170
+ var g = this.loopGeometry(d);
171
+ return 'M ' + g.p0.x + ' ' + g.p0.y + ' C ' + g.p1.x + ' ' + g.p1.y + ' ' + g.p2.x + ' ' + g.p2.y + ' ' + g.p3.x + ' ' + g.p3.y;
172
+ }
173
+ /**
174
+ * 結線の「中点」。垂下の○とラベルはともにこの点に乗せる。
175
+ * ここを一本化しないと、○は正しい位置なのにラベルだけ箱に重なる、
176
+ * といったズレが出る。
177
+ * 直線 … from/to の中点
178
+ * 自己結線 … ループ(3次ベジエ)の t=0.5 の点(外側に膨らんだ位置)
179
+ */
180
+ }, {
181
+ key: "junctionPoint",
182
+ value: function junctionPoint(d) {
183
+ if (!this.isSelfLink(d)) {
184
+ var from = this.fromPoint(d);
185
+ var to = this.toPoint(d);
186
+ return {
187
+ x: (from.x + to.x) / 2,
188
+ y: (from.y + to.y) / 2
189
+ };
190
+ }
191
+ var g = this.loopGeometry(d);
192
+
193
+ // 3次ベジエの t=0.5: (p0 + 3p1 + 3p2 + p3) / 8
194
+ return {
195
+ x: (g.p0.x + 3 * g.p1.x + 3 * g.p2.x + g.p3.x) / 8,
196
+ y: (g.p0.y + 3 * g.p1.y + 3 * g.p2.y + g.p3.y) / 8
197
+ };
198
+ }
199
+ /**
200
+ * 自己結線のループを描く。enter/update join で冪等。
201
+ */
202
+ }, {
203
+ key: "drawSelfLoops",
204
+ value: function drawSelfLoops(place, data) {
205
+ var _this3 = this;
206
+ this._selfLinks = data.filter(function (d) {
207
+ return !_this3.isSubset(d) && _this3.isSelfLink(d);
208
+ });
209
+ var paths = place.selectAll('path.connector-loop').data(this._selfLinks, function (d) {
210
+ return d._id;
211
+ });
212
+ 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
+ });
217
+ this.applySelfLoops(entered.merge(paths));
218
+ }
219
+ }, {
220
+ key: "applySelfLoops",
221
+ value: function applySelfLoops(selection) {
222
+ var _this4 = this;
223
+ selection.attr('d', function (d) {
224
+ return _this4.loopPath(d);
225
+ });
226
+ }
227
+ /** ドラッグ追従: ループ全体に現在のエンティティ位置を再適用する。 */
228
+ }, {
229
+ key: "updateSelfLoops",
230
+ value: function updateSelfLoops(place) {
231
+ if (!this._selfLinks || this._selfLinks.length === 0) return;
232
+ this.applySelfLoops(place.selectAll('path.connector-loop'));
233
+ }
109
234
  /**
110
235
  * 結線のラベル(relationship.label)を線の中点の少し上に描く。
111
236
  * enter/update join で冪等。サブセット結線は区分コード(=/×)を
@@ -114,9 +239,9 @@ var Relationships = exports["default"] = /*#__PURE__*/function () {
114
239
  }, {
115
240
  key: "drawLabels",
116
241
  value: function drawLabels(place, data) {
117
- var _this3 = this;
242
+ var _this5 = this;
118
243
  var targets = data.filter(function (d) {
119
- return !_this3.isSubset(d) && d.label && d.label();
244
+ return !_this5.isSubset(d) && d.label && d.label();
120
245
  });
121
246
  var texts = place.selectAll('text.relationship-label').data(targets, function (d) {
122
247
  return d._id;
@@ -125,15 +250,15 @@ var Relationships = exports["default"] = /*#__PURE__*/function () {
125
250
  var entered = texts.enter().append('text').attr('class', 'relationship-label').attr('text-anchor', 'middle').attr('font-size', '12px').attr('fill', '#333333');
126
251
  this.applyLabels(entered.merge(texts));
127
252
  }
128
- /** ラベルの位置(線の中点の少し上)とテキストを適用する。 */
253
+ /** ラベルの位置(結線の中点の少し上)とテキストを適用する。 */
129
254
  }, {
130
255
  key: "applyLabels",
131
256
  value: function applyLabels(selection) {
132
- var _this4 = this;
257
+ var _this6 = this;
133
258
  selection.attr('x', function (d) {
134
- return (_this4.fromPoint(d).x + _this4.toPoint(d).x) / 2;
259
+ return _this6.junctionPoint(d).x;
135
260
  }).attr('y', function (d) {
136
- return (_this4.fromPoint(d).y + _this4.toPoint(d).y) / 2 - 6;
261
+ return _this6.junctionPoint(d).y - 6;
137
262
  }).text(function (d) {
138
263
  return d.label();
139
264
  });
@@ -149,9 +274,10 @@ var Relationships = exports["default"] = /*#__PURE__*/function () {
149
274
  return !!(d.mapping && d.mapping());
150
275
  }
151
276
  /**
152
- * 対応表/対照表の垂下の幾何(tm3-1 §2「対応表(onto-mapping)」)。
153
- * 結線の中点(junction)に小さな○を置き、そこから対応表/対照表の
277
+ * 対応表/対照表/再帰表の垂下の幾何(tm3-1 §2「対応表(onto-mapping)」)。
278
+ * 結線の中点(junctionPoint)に小さな○を置き、そこから表の
154
279
  * 最寄りの辺の中央へ1本の線でぶら下げる。
280
+ * 自己結線(再帰)ではループの膨らんだ位置が中点になる。
155
281
  * 取り付く辺は中点から見た方向で自動選択する: 横方向のずれが支配的
156
282
  * なら左辺/右辺の中央、縦方向が支配的なら上端/下端の中央。判定は
157
283
  * 箱の縦横比で正規化する(横長の箱で不当に左右辺が選ばれないように)。
@@ -159,10 +285,9 @@ var Relationships = exports["default"] = /*#__PURE__*/function () {
159
285
  }, {
160
286
  key: "mappingGeometry",
161
287
  value: function mappingGeometry(d) {
162
- var from = this.fromPoint(d);
163
- var to = this.toPoint(d);
164
- var jx = (from.x + to.x) / 2;
165
- var jy = (from.y + to.y) / 2;
288
+ var junction = this.junctionPoint(d);
289
+ var jx = junction.x;
290
+ var jy = junction.y;
166
291
  var m = d.mapping();
167
292
  var cx = m.position.x + m.size.w / 2;
168
293
  var cy = m.position.y + m.size.h / 2;
@@ -189,9 +314,9 @@ var Relationships = exports["default"] = /*#__PURE__*/function () {
189
314
  }, {
190
315
  key: "drawMappingDrops",
191
316
  value: function drawMappingDrops(place, data) {
192
- var _this5 = this;
317
+ var _this7 = this;
193
318
  this._mappingTargets = data.filter(function (d) {
194
- return _this5.hasMapping(d);
319
+ return _this7.hasMapping(d);
195
320
  });
196
321
  var lines = place.selectAll('line.mapping-drop').data(this._mappingTargets, function (d) {
197
322
  return d._id;
@@ -209,20 +334,20 @@ var Relationships = exports["default"] = /*#__PURE__*/function () {
209
334
  }, {
210
335
  key: "applyMappingDrops",
211
336
  value: function applyMappingDrops(lines, circles) {
212
- var _this6 = this;
337
+ var _this8 = this;
213
338
  lines.attr('x1', function (d) {
214
- return _this6.mappingGeometry(d).jx;
339
+ return _this8.mappingGeometry(d).jx;
215
340
  }).attr('y1', function (d) {
216
- return _this6.mappingGeometry(d).jy;
341
+ return _this8.mappingGeometry(d).jy;
217
342
  }).attr('x2', function (d) {
218
- return _this6.mappingGeometry(d).mx;
343
+ return _this8.mappingGeometry(d).mx;
219
344
  }).attr('y2', function (d) {
220
- return _this6.mappingGeometry(d).my;
345
+ return _this8.mappingGeometry(d).my;
221
346
  });
222
347
  circles.attr('cx', function (d) {
223
- return _this6.mappingGeometry(d).jx;
348
+ return _this8.mappingGeometry(d).jx;
224
349
  }).attr('cy', function (d) {
225
- return _this6.mappingGeometry(d).jy;
350
+ return _this8.mappingGeometry(d).jy;
226
351
  });
227
352
  }
228
353
  /**
@@ -340,14 +465,14 @@ var Relationships = exports["default"] = /*#__PURE__*/function () {
340
465
  }, {
341
466
  key: "applySubsetTrees",
342
467
  value: function applySubsetTrees(paths, labels) {
343
- var _this7 = this;
468
+ var _this9 = this;
344
469
  paths.attr('d', function (d) {
345
- return _this7.subsetPath(d);
470
+ return _this9.subsetPath(d);
346
471
  });
347
472
  labels.attr('x', function (d) {
348
- return _this7.subsetGeometry(d).px;
473
+ return _this9.subsetGeometry(d).px;
349
474
  }).attr('y', function (d) {
350
- return _this7.subsetGeometry(d).busY - 5;
475
+ return _this9.subsetGeometry(d).busY - 5;
351
476
  }).text(function (d) {
352
477
  return d.label;
353
478
  });
@@ -365,20 +490,23 @@ var Relationships = exports["default"] = /*#__PURE__*/function () {
365
490
  }, {
366
491
  key: "redrawEntityEdges",
367
492
  value: function redrawEntityEdges(place, entity) {
368
- var _this8 = this;
493
+ var _this0 = this;
369
494
  var edges = entity.ports.items.list.map(function (p) {
370
495
  return p._relationship;
371
496
  });
372
497
  var selection = place.selectAll('line.connector').data(edges.filter(function (d) {
373
- return !_this8.isSubset(d);
498
+ return !_this0.isSubset(d) && !_this0.isSelfLink(d);
374
499
  }), function (d) {
375
500
  return d._id;
376
501
  });
377
502
  this._lines.update(selection);
378
503
 
504
+ // 自己結線のループも追従させる
505
+ this.updateSelfLoops(place);
506
+
379
507
  // ラベルも追従させる
380
508
  var labels = place.selectAll('text.relationship-label').data(edges.filter(function (d) {
381
- return !_this8.isSubset(d) && d.label && d.label();
509
+ return !_this0.isSubset(d) && d.label && d.label();
382
510
  }), function (d) {
383
511
  return d._id;
384
512
  });