@yanqirenshi/d3.ter 0.1.25 → 0.2.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/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,104 @@
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
+ entity: { click: (d) => {} },
39
+ identifier: { click: (d) => {} },
40
+ attribute: { click: (d) => {} },
41
+ relationship: { click: (d) => {} },
42
+ },
43
+ }));
44
+ }, []);
45
+
46
+ React.useEffect(() => {
47
+ if (rectum) rectum.data(data);
48
+ }, [rectum, data]);
49
+
50
+ if (!rectum) return null;
51
+
52
+ return (
53
+ <div style={{ width: '100%', height: '100%' }}>
54
+ <D3Ter rectum={rectum} />
55
+ </div>
56
+ );
57
+ }
58
+ ```
59
+
60
+ ## 入力データ
61
+
62
+ `{ identifiers, attributes, entities, relationships }` の連想配列です。
63
+ 識別子・属性を「定義」として持ち、エンティティとリレーションシップがそれを参照します。
64
+
65
+ **フィールドの詳細は [`src/index.d.ts`](src/index.d.ts) が正**なので、そちらを参照してください。
66
+ 動く例はショーケースの d3.ter のページ(「データ」タブ)にあります。
67
+ サンプルの実データは `showcase/src/demos/data/ter-sample.js` です。
68
+
69
+ ## 再帰(RECURSION)の書き方(v0.2.0+)
70
+
71
+ `from.entity` と `to.entity` に**同じエンティティ**を指定すると「自己結線」になり、
72
+ 直線ではなく**箱の外側を回るループ**(3次ベジエ)で描かれます。
73
+ TM の再帰がこれで、ループの中点の○から再帰表を垂下します。
74
+
75
+ ```js
76
+ {
77
+ id: 9, type: null,
78
+ // 両端に同じモノ(部品)を指定 → ループになる
79
+ from: { entity: 30002, cardinality: 3, optionality: 0, position: 340 },
80
+ to: { entity: 30002, cardinality: 3, optionality: 0, position: 20 },
81
+ details: [{ from: { id: 3000201 }, to: { id: 3000201 } }],
82
+ // ループの中点(○)から再帰表へ垂下する
83
+ mapping: { entity: 82000 }, // 部品.部品.再帰表 (RECURSION)
84
+ }
85
+ ```
86
+
87
+ - **ループの向きは両端の `position`(角度)で決まります。** 0=真下・時計回り。
88
+ 上の例のように両端を近い角度(340 / 20)にすると、箱の下に U 字のループが下がります。
89
+ - **再帰表は自己結線にだけ垂下できます。** 通常の結線(`from.entity !== to.entity`)に
90
+ `mapping` で RECURSION を指定すると、データ構築時に例外になります。
91
+ - 1つのモノに複数のループを描くときは、**角度を変えて**指定してください
92
+ (同じ角度どうしは重なります。自動のオフセットは入りません)。
93
+ - ループの膨らむ距離は `style().relationship.loop.distance`(既定 40)です。
94
+
95
+ 描画される要素は `path.connector-loop` で、通常の結線(`line.connector`)とは別です。
96
+ ループ上の○(`circle.mapping-junction`)とラベル(`text.relationship-label`)は、
97
+ ともにベジエの中点(t=0.5)に乗ります。
98
+
99
+ ## 開発
100
+
101
+ ```bash
102
+ npm run transpile -w @yanqirenshi/d3.ter # src -> dist(dist はコミット対象)
103
+ npm test -w @yanqirenshi/d3.ter # jest
104
+ ```
@@ -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
@@ -8,11 +8,12 @@ import type { ComponentType } from 'react';
8
8
  * 入力データ(data() に渡す構造)
9
9
  * **************************************************************** */
10
10
 
11
- /** 名称(論理名 / 物理名) */
12
- export interface TerName {
13
- logical?: string;
14
- physical?: string;
15
- }
11
+ // 名称ペアは共有型パッケージ(@yanqirenshi/types)に一本化した。
12
+ // 公開 API 名(TerName)はエイリアスで維持する(description? が増えるが互換)。
13
+ import type { Name } from '@yanqirenshi/types';
14
+
15
+ /** 名称(論理名 / 物理名) — 共有型 Name のエイリアス */
16
+ export type TerName = Name;
16
17
 
17
18
  /** 識別子(主キー)のマスタ定義。entities から id 参照される */
18
19
  export interface TerIdentifier {
@@ -121,7 +122,15 @@ export interface TerSubset {
121
122
  code: string;
122
123
  }
123
124
 
124
- /** エンティティ間のリレーションシップ */
125
+ /**
126
+ * エンティティ間のリレーションシップ。
127
+ *
128
+ * from.entity と to.entity に同じエンティティを指定すると「自己結線」になり、
129
+ * 直線ではなく**箱の外側を回るループ**(3次ベジエ)で描かれる。TM の再帰が
130
+ * これで、ループの中点の○から再帰表(RECURSION)を垂下する(mapping)。
131
+ * ループの膨らむ向きは両端のポートの position(角度)で決まるので、
132
+ * 1つのモノに複数のループを描くときは角度を変える(自動の重なり回避はしない)。
133
+ */
125
134
  export interface TerRelationship {
126
135
  id: number | string;
127
136
  type?: string | null;
@@ -132,10 +141,14 @@ export interface TerRelationship {
132
141
  /** サブセットへの結線に区分コード(= / ×)を表示する(任意) */
133
142
  subset?: TerSubset;
134
143
  /**
135
- * 対応表/対照表の垂下(任意)。結線の中点の○から垂下線で指定エンティティへ
144
+ * 対応表/対照表/再帰表の垂下(任意)。結線の中点の○から垂下線で指定エンティティへ
136
145
  * ぶら下げる(tm3-1 §2「対応表(onto-mapping)」の書き方)。線は表の最寄りの
137
146
  * 辺(上下左右)の中央に取り付く(中点から見た方向で自動選択)。指定できるのは
138
- * 対応表(CORRESPONDENCE)/対照表(COMPARATIVE)のみ — それ以外は構築時に例外
147
+ * 対応表(CORRESPONDENCE)/対照表(COMPARATIVE)/再帰表(RECURSION)のみ —
148
+ * それ以外は構築時に例外。
149
+ *
150
+ * 再帰表(RECURSION)は**自己結線(from.entity === to.entity)にだけ**指定できる。
151
+ * 通常の結線に指定すると構築時に例外になる。
139
152
  */
140
153
  mapping?: { entity: number | string };
141
154
  /** 結線の中点に表示するラベル(任意。subset 指定時は区分コードが優先され表示されない) */
package/dist/js/Entity.js CHANGED
@@ -66,8 +66,8 @@ var Entity = exports["default"] = /*#__PURE__*/function (_Atman) {
66
66
  value: function style() {
67
67
  return this.rectum().style();
68
68
  }
69
- /* **************************************************************** *
70
- * Builder
69
+ /* **************************************************************** *
70
+ * Builder
71
71
  * **************************************************************** */
72
72
  }, {
73
73
  key: "init",
@@ -152,8 +152,8 @@ var Entity = exports["default"] = /*#__PURE__*/function (_Atman) {
152
152
  }
153
153
  };
154
154
  }
155
- /** **************************************************************** *
156
- *
155
+ /** **************************************************************** *
156
+ *
157
157
  * **************************************************************** */
158
158
  }, {
159
159
  key: "template",
@@ -250,8 +250,8 @@ var Entity = exports["default"] = /*#__PURE__*/function (_Atman) {
250
250
  }
251
251
  };
252
252
  }
253
- /** **************************************************************** *
254
- *
253
+ /** **************************************************************** *
254
+ *
255
255
  * **************************************************************** */
256
256
  }, {
257
257
  key: "entityTypeContents",
@@ -285,8 +285,8 @@ var Entity = exports["default"] = /*#__PURE__*/function (_Atman) {
285
285
  throw new Error(type + " は知らないよ。");
286
286
  }
287
287
  }
288
- /** **************************************************************** *
289
- *
288
+ /** **************************************************************** *
289
+ *
290
290
  * **************************************************************** */
291
291
  }, {
292
292
  key: "entityBackground",
@@ -326,8 +326,8 @@ var Entity = exports["default"] = /*#__PURE__*/function (_Atman) {
326
326
  var key = this._core.type.toLowerCase();
327
327
  return background[key];
328
328
  }
329
- /** **************************************************************** *
330
- *
329
+ /** **************************************************************** *
330
+ *
331
331
  * **************************************************************** */
332
332
  }, {
333
333
  key: "buildIdentifiers",
@@ -370,8 +370,8 @@ var Entity = exports["default"] = /*#__PURE__*/function (_Atman) {
370
370
  padding: 11
371
371
  };
372
372
  }
373
- /** **************************************************************** *
374
- *
373
+ /** **************************************************************** *
374
+ *
375
375
  * **************************************************************** */
376
376
  }, {
377
377
  key: "buildAttributes",
@@ -414,8 +414,8 @@ var Entity = exports["default"] = /*#__PURE__*/function (_Atman) {
414
414
  padding: 11
415
415
  };
416
416
  }
417
- /** **************************************************************** *
418
- *
417
+ /** **************************************************************** *
418
+ *
419
419
  * **************************************************************** */
420
420
  }, {
421
421
  key: "build",
@@ -424,8 +424,8 @@ var Entity = exports["default"] = /*#__PURE__*/function (_Atman) {
424
424
  this.attributes = this.buildAttributes(state);
425
425
  return this;
426
426
  }
427
- /* **************************************************************** *
428
- * Size
427
+ /* **************************************************************** *
428
+ * Size
429
429
  * **************************************************************** */
430
430
  }, {
431
431
  key: "strLen",
@@ -538,8 +538,8 @@ var Entity = exports["default"] = /*#__PURE__*/function (_Atman) {
538
538
  }
539
539
  return this;
540
540
  }
541
- /* **************************************************************** *
542
- * Position
541
+ /* **************************************************************** *
542
+ * Position
543
543
  * **************************************************************** */
544
544
  }, {
545
545
  key: "positioning",
@@ -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
  });