@yanqirenshi/d3.ter 0.3.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 +11 -1
- package/dist/index.d.ts +10 -0
- package/dist/js/Entity.js +31 -79
- package/dist/js/Painters/Entities.js +21 -0
- package/dist/js/Painters/Relationships.js +147 -14
- package/dist/js/Port.js +5 -2
- package/dist/js/Rectum.js +4 -0
- package/jest.config.js +7 -0
- package/package.json +2 -1
- package/tests/Relationships.test.js +42 -0
package/README.md
CHANGED
|
@@ -9,6 +9,9 @@ TM(T字形ER手法)の ER 図(TER)を SVG で描画する React コン
|
|
|
9
9
|
- サブセットへの結線は区分コード(=同一 / ×相違)付きの分岐(幹 + バス + 垂下)で描きます。
|
|
10
10
|
- 対応表・対照表・再帰表は、結線の中点の○から垂下線でぶら下げます(`mapping`)。
|
|
11
11
|
- エンティティはドラッグで移動でき、結線・記号・垂下線が追従します。
|
|
12
|
+
動かし終えたことは `callbacks.entity.dragend(core, entity, move)` で受け取れます(v0.4.0+)。
|
|
13
|
+
- 種別バッジ・配色・端点の角度の既定(0=真下)は [`@yanqirenshi/model.tm`](../model.tm) から取ります。
|
|
14
|
+
インスペクタや保存は model.tm と組み合わせます(ショーケースの `model.tm` のデモ)。
|
|
12
15
|
|
|
13
16
|
## インストール
|
|
14
17
|
|
|
@@ -37,7 +40,9 @@ export default function Graph({ data }) {
|
|
|
37
40
|
callbacks: {
|
|
38
41
|
// contextmenu は右クリック。引数は click と同じで、最後に event(MouseEvent)。
|
|
39
42
|
// 渡したときだけブラウザ標準のメニューを止める。ドラッグ中は呼ばれない
|
|
40
|
-
entity: { click: (d) => {}, contextmenu: (d, event) => {}
|
|
43
|
+
entity: { click: (d) => {}, contextmenu: (d, event) => {},
|
|
44
|
+
// ドラッグの終わり(動いたときだけ)。core は入力の entity、move は移動量 { dx, dy }
|
|
45
|
+
dragend: (core, entity, move) => {} },
|
|
41
46
|
identifier: { click: (d) => {}, contextmenu: (d, event) => {} },
|
|
42
47
|
attribute: { click: (d) => {}, contextmenu: (d, event) => {} },
|
|
43
48
|
relationship: { click: (d) => {} },
|
|
@@ -98,6 +103,11 @@ TM の再帰がこれで、ループの中点の○から再帰表を垂下し
|
|
|
98
103
|
ループ上の○(`circle.mapping-junction`)とラベル(`text.relationship-label`)は、
|
|
99
104
|
ともにベジエの中点(t=0.5)に乗ります。
|
|
100
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
|
+
|
|
101
111
|
## 開発
|
|
102
112
|
|
|
103
113
|
```bash
|
package/dist/index.d.ts
CHANGED
|
@@ -190,6 +190,16 @@ export interface TerCallbacks {
|
|
|
190
190
|
* 左ボタンを押したまま(ドラッグ中)の右クリックでは呼ばれない。
|
|
191
191
|
*/
|
|
192
192
|
contextmenu?: ((entity: TerEntityDatum, event: MouseEvent) => void) | null;
|
|
193
|
+
/**
|
|
194
|
+
* エンティティをドラッグして動かし終えたときの通知(動いたときだけ。v0.4.0+)。
|
|
195
|
+
* core は入力の TerEntity、move は移動量 { dx, dy }(世界座標)。
|
|
196
|
+
* @yanqirenshi/model.tm の movePatch(core, move) にそのまま渡せる。
|
|
197
|
+
*/
|
|
198
|
+
dragend?: ((core: TerEntity, entity: TerEntityDatum, move: { dx: number; dy: number }) => void) | null;
|
|
199
|
+
};
|
|
200
|
+
relationship?: {
|
|
201
|
+
/** 結線(線・自己結線のループ)のクリック通知。_core に入力(TerRelationship)が入る */
|
|
202
|
+
click?: ((relationship: { _id: number | string; _core: TerRelationship; [key: string]: unknown }) => void) | null;
|
|
193
203
|
};
|
|
194
204
|
identifier?: {
|
|
195
205
|
/** 識別子の行のクリック通知 */
|
package/dist/js/Entity.js
CHANGED
|
@@ -9,6 +9,7 @@ var _Atman2 = _interopRequireDefault(require("./Atman.js"));
|
|
|
9
9
|
var _IdentifierInstance = _interopRequireDefault(require("./IdentifierInstance.js"));
|
|
10
10
|
var _AttributeInstance = _interopRequireDefault(require("./AttributeInstance.js"));
|
|
11
11
|
var _assh0le = require("@yanqirenshi/assh0le");
|
|
12
|
+
var _model = require("@yanqirenshi/model.tm");
|
|
12
13
|
var _Name = _interopRequireDefault(require("./utils/Name.js"));
|
|
13
14
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
14
15
|
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; } } }; }
|
|
@@ -28,7 +29,7 @@ function _assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError(
|
|
|
28
29
|
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
29
30
|
function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, _getPrototypeOf(t); }
|
|
30
31
|
function _inherits(t, e) { if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); t.prototype = Object.create(e && e.prototype, { constructor: { value: t, writable: !0, configurable: !0 } }), Object.defineProperty(t, "prototype", { writable: !1 }), e && _setPrototypeOf(t, e); }
|
|
31
|
-
function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); }
|
|
32
|
+
function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); } // 種別バッジと配色は図ごとの知識なので model.tm が持つ(Foolsgolds/Assholes#144)
|
|
32
33
|
var Entity = exports["default"] = /*#__PURE__*/function (_Atman) {
|
|
33
34
|
function Entity(data, rectum) {
|
|
34
35
|
var _this;
|
|
@@ -66,8 +67,8 @@ var Entity = exports["default"] = /*#__PURE__*/function (_Atman) {
|
|
|
66
67
|
value: function style() {
|
|
67
68
|
return this.rectum().style();
|
|
68
69
|
}
|
|
69
|
-
/* **************************************************************** *
|
|
70
|
-
* Builder
|
|
70
|
+
/* **************************************************************** *
|
|
71
|
+
* Builder
|
|
71
72
|
* **************************************************************** */
|
|
72
73
|
}, {
|
|
73
74
|
key: "init",
|
|
@@ -152,8 +153,8 @@ var Entity = exports["default"] = /*#__PURE__*/function (_Atman) {
|
|
|
152
153
|
}
|
|
153
154
|
};
|
|
154
155
|
}
|
|
155
|
-
/** **************************************************************** *
|
|
156
|
-
*
|
|
156
|
+
/** **************************************************************** *
|
|
157
|
+
*
|
|
157
158
|
* **************************************************************** */
|
|
158
159
|
}, {
|
|
159
160
|
key: "template",
|
|
@@ -250,84 +251,35 @@ var Entity = exports["default"] = /*#__PURE__*/function (_Atman) {
|
|
|
250
251
|
}
|
|
251
252
|
};
|
|
252
253
|
}
|
|
253
|
-
/** **************************************************************** *
|
|
254
|
-
*
|
|
254
|
+
/** **************************************************************** *
|
|
255
|
+
*
|
|
255
256
|
* **************************************************************** */
|
|
257
|
+
/**
|
|
258
|
+
* 種別バッジ(箱のヘッダ右の文字)。値は model.tm の TYPE_BADGES
|
|
259
|
+
* (Rsc / Evt / 対照 / 対応 / 再帰 / MO / MA。CLASS は意図的にバッジ無し = 空文字)。
|
|
260
|
+
* 知らない種別は例外(model.tm の check でも事前に検出できる)。
|
|
261
|
+
*/
|
|
256
262
|
}, {
|
|
257
263
|
key: "entityTypeContents",
|
|
258
264
|
value: function entityTypeContents() {
|
|
259
265
|
var type = this._core.type;
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
case 'RESOURCE-SUBSET':
|
|
264
|
-
return 'Rsc';
|
|
265
|
-
case 'COMPARATIVE':
|
|
266
|
-
return '対照';
|
|
267
|
-
case 'CORRESPONDENCE':
|
|
268
|
-
return '対応';
|
|
269
|
-
case 'EVENT':
|
|
270
|
-
return 'Evt';
|
|
271
|
-
case 'EVENT-SUBSET':
|
|
272
|
-
return 'Evt';
|
|
273
|
-
case 'RECURSION':
|
|
274
|
-
return '再帰';
|
|
275
|
-
// TM(T字形ER)の多値。MO=多値のOR(配列の正規形)、MA=多値のAND(HDR-DTL 構成)
|
|
276
|
-
case 'MANY-VALUED-OR':
|
|
277
|
-
return 'MO';
|
|
278
|
-
case 'MANY-VALUED-AND':
|
|
279
|
-
return 'MA';
|
|
280
|
-
// TM の「クラス」(モノに混入した別の性質の切り出し。例: 従業員.入社)。
|
|
281
|
-
// 種別バッジを持たない(空文字 = 意図的なバッジ無し)
|
|
282
|
-
case 'CLASS':
|
|
283
|
-
return '';
|
|
284
|
-
default:
|
|
285
|
-
throw new Error(type + " は知らないよ。");
|
|
286
|
-
}
|
|
266
|
+
var badge = _model.TYPE_BADGES[type];
|
|
267
|
+
if (badge === undefined) throw new Error(type + " は知らないよ。");
|
|
268
|
+
return badge;
|
|
287
269
|
}
|
|
288
|
-
/** **************************************************************** *
|
|
289
|
-
*
|
|
270
|
+
/** **************************************************************** *
|
|
271
|
+
*
|
|
290
272
|
* **************************************************************** */
|
|
273
|
+
/** 箱の背景色。値は model.tm の TYPE_COLORS(種別ごと) */
|
|
291
274
|
}, {
|
|
292
275
|
key: "entityBackground",
|
|
293
276
|
value: function entityBackground() {
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
color: '#89c3eb'
|
|
297
|
-
},
|
|
298
|
-
"resource-subset": {
|
|
299
|
-
color: '#a0d8ef'
|
|
300
|
-
},
|
|
301
|
-
"event": {
|
|
302
|
-
color: '#f09199'
|
|
303
|
-
},
|
|
304
|
-
"event-subset": {
|
|
305
|
-
color: '#f6bfbc'
|
|
306
|
-
},
|
|
307
|
-
"comparative": {
|
|
308
|
-
color: '#c8d5bb'
|
|
309
|
-
},
|
|
310
|
-
"correspondence": {
|
|
311
|
-
color: '#f2f2b0'
|
|
312
|
-
},
|
|
313
|
-
"recursion": {
|
|
314
|
-
color: '#dbd0e6'
|
|
315
|
-
},
|
|
316
|
-
"many-valued-or": {
|
|
317
|
-
color: '#fddea5'
|
|
318
|
-
},
|
|
319
|
-
"many-valued-and": {
|
|
320
|
-
color: '#9fd5c9'
|
|
321
|
-
},
|
|
322
|
-
"class": {
|
|
323
|
-
color: '#bdc0ba'
|
|
324
|
-
}
|
|
277
|
+
return {
|
|
278
|
+
color: _model.TYPE_COLORS[this._core.type]
|
|
325
279
|
};
|
|
326
|
-
var key = this._core.type.toLowerCase();
|
|
327
|
-
return background[key];
|
|
328
280
|
}
|
|
329
|
-
/** **************************************************************** *
|
|
330
|
-
*
|
|
281
|
+
/** **************************************************************** *
|
|
282
|
+
*
|
|
331
283
|
* **************************************************************** */
|
|
332
284
|
}, {
|
|
333
285
|
key: "buildIdentifiers",
|
|
@@ -370,8 +322,8 @@ var Entity = exports["default"] = /*#__PURE__*/function (_Atman) {
|
|
|
370
322
|
padding: 11
|
|
371
323
|
};
|
|
372
324
|
}
|
|
373
|
-
/** **************************************************************** *
|
|
374
|
-
*
|
|
325
|
+
/** **************************************************************** *
|
|
326
|
+
*
|
|
375
327
|
* **************************************************************** */
|
|
376
328
|
}, {
|
|
377
329
|
key: "buildAttributes",
|
|
@@ -414,8 +366,8 @@ var Entity = exports["default"] = /*#__PURE__*/function (_Atman) {
|
|
|
414
366
|
padding: 11
|
|
415
367
|
};
|
|
416
368
|
}
|
|
417
|
-
/** **************************************************************** *
|
|
418
|
-
*
|
|
369
|
+
/** **************************************************************** *
|
|
370
|
+
*
|
|
419
371
|
* **************************************************************** */
|
|
420
372
|
}, {
|
|
421
373
|
key: "build",
|
|
@@ -424,8 +376,8 @@ var Entity = exports["default"] = /*#__PURE__*/function (_Atman) {
|
|
|
424
376
|
this.attributes = this.buildAttributes(state);
|
|
425
377
|
return this;
|
|
426
378
|
}
|
|
427
|
-
/* **************************************************************** *
|
|
428
|
-
* Size
|
|
379
|
+
/* **************************************************************** *
|
|
380
|
+
* Size
|
|
429
381
|
* **************************************************************** */
|
|
430
382
|
}, {
|
|
431
383
|
key: "strLen",
|
|
@@ -538,8 +490,8 @@ var Entity = exports["default"] = /*#__PURE__*/function (_Atman) {
|
|
|
538
490
|
}
|
|
539
491
|
return this;
|
|
540
492
|
}
|
|
541
|
-
/* **************************************************************** *
|
|
542
|
-
* Position
|
|
493
|
+
/* **************************************************************** *
|
|
494
|
+
* Position
|
|
543
495
|
* **************************************************************** */
|
|
544
496
|
}, {
|
|
545
497
|
key: "positioning",
|
|
@@ -326,6 +326,11 @@ var Entities = exports["default"] = /*#__PURE__*/function () {
|
|
|
326
326
|
start: {
|
|
327
327
|
x: event.x,
|
|
328
328
|
y: event.y
|
|
329
|
+
},
|
|
330
|
+
// dragend で移動量を出すために、掴んだときのエンティティの位置も覚える
|
|
331
|
+
origin: {
|
|
332
|
+
x: entity.position.x,
|
|
333
|
+
y: entity.position.y
|
|
329
334
|
}
|
|
330
335
|
};
|
|
331
336
|
}
|
|
@@ -337,10 +342,26 @@ var Entities = exports["default"] = /*#__PURE__*/function () {
|
|
|
337
342
|
this.moveEntity(entity);
|
|
338
343
|
this.moveEdges(entity);
|
|
339
344
|
}
|
|
345
|
+
/**
|
|
346
|
+
* ドラッグの終わり。動いたときだけ callbacks.entity.dragend(core, entity, move) を呼ぶ。
|
|
347
|
+
* core: 入力のレコード(entity._core。TerEntity)
|
|
348
|
+
* entity: 正規化済みのエンティティ(position は動かしたあとの位置)
|
|
349
|
+
* move: 移動量 { dx, dy }(世界座標)。model.tm の movePatch(core, move) にそのまま渡せる
|
|
350
|
+
* 動かさずに離したとき(クリック)は呼ばない(保存が走らないように)。
|
|
351
|
+
*/
|
|
340
352
|
}, {
|
|
341
353
|
key: "dragEnd",
|
|
342
354
|
value: function dragEnd(event, entity) {
|
|
355
|
+
var origin = entity._drag && entity._drag.origin;
|
|
343
356
|
delete entity._drag;
|
|
357
|
+
if (!origin) return;
|
|
358
|
+
var move = {
|
|
359
|
+
dx: entity.position.x - origin.x,
|
|
360
|
+
dy: entity.position.y - origin.y
|
|
361
|
+
};
|
|
362
|
+
if (move.dx === 0 && move.dy === 0) return;
|
|
363
|
+
var func = this.callbacks().entity.dragend;
|
|
364
|
+
if (func) func(entity._core, entity, move);
|
|
344
365
|
}
|
|
345
366
|
}, {
|
|
346
367
|
key: "addMoveEvents",
|
|
@@ -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,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)
|
|
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.
|
|
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
|
|
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(
|
|
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/Port.js
CHANGED
|
@@ -7,6 +7,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
exports["default"] = void 0;
|
|
8
8
|
var _Atman2 = _interopRequireDefault(require("./Atman.js"));
|
|
9
9
|
var _assh0le = require("@yanqirenshi/assh0le");
|
|
10
|
+
var _model = require("@yanqirenshi/model.tm");
|
|
10
11
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
11
12
|
function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
|
|
12
13
|
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); } }
|
|
@@ -19,7 +20,7 @@ function _assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError(
|
|
|
19
20
|
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
20
21
|
function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, _getPrototypeOf(t); }
|
|
21
22
|
function _inherits(t, e) { if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); t.prototype = Object.create(e && e.prototype, { constructor: { value: t, writable: !0, configurable: !0 } }), Object.defineProperty(t, "prototype", { writable: !1 }), e && _setPrototypeOf(t, e); }
|
|
22
|
-
function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); }
|
|
23
|
+
function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); } // 端点の角度の既定(0=真下)は図ごとの知識なので model.tm が持つ(Foolsgolds/Assholes#144)
|
|
23
24
|
var Port = exports["default"] = /*#__PURE__*/function (_Atman) {
|
|
24
25
|
function Port(type, entity, relatihonship_data, rectum) {
|
|
25
26
|
var _this;
|
|
@@ -79,10 +80,12 @@ var Port = exports["default"] = /*#__PURE__*/function (_Atman) {
|
|
|
79
80
|
value: function core() {
|
|
80
81
|
return this._core;
|
|
81
82
|
}
|
|
83
|
+
/** 取り付け角度。無ければ model.tm の既定(0=真下) */
|
|
82
84
|
}, {
|
|
83
85
|
key: "degree",
|
|
84
86
|
value: function degree() {
|
|
85
|
-
|
|
87
|
+
var position = this._core.position;
|
|
88
|
+
return typeof position === 'number' && Number.isFinite(position) ? position : _model.RELATIONSHIP_DEFAULTS.end.position;
|
|
86
89
|
}
|
|
87
90
|
}, {
|
|
88
91
|
key: "position",
|
package/dist/js/Rectum.js
CHANGED
package/jest.config.js
CHANGED
|
@@ -10,6 +10,13 @@ module.exports = {
|
|
|
10
10
|
// d3 v7 は ESM-only で CJS ランタイムの jest では読めないため、スタブにマップする
|
|
11
11
|
moduleNameMapper: {
|
|
12
12
|
'^d3$': '<rootDir>/tests/d3-stub.js',
|
|
13
|
+
// model.tm は ESM のみを main にしている。jest 25 は package.json の exports を見ないので、
|
|
14
|
+
// CommonJS 版(model.tm の build が dist/cjs/ に出す)へ直接マップする。
|
|
15
|
+
// model.tm を先にビルドしておくこと(npm run build -w @yanqirenshi/model.tm)。
|
|
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',
|
|
13
20
|
},
|
|
14
21
|
collectCoverageFrom: [
|
|
15
22
|
"**/src/**/*.js",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yanqirenshi/d3.ter",
|
|
3
|
-
"version": "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",
|
|
@@ -31,6 +31,7 @@
|
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"d3": "^7.9.0",
|
|
33
33
|
"@yanqirenshi/assh0le": "^0.5.0",
|
|
34
|
+
"@yanqirenshi/model.tm": "^0.1.0",
|
|
34
35
|
"@yanqirenshi/types": "^0.1.0",
|
|
35
36
|
"deepmerge": "^4.2.2"
|
|
36
37
|
},
|
|
@@ -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
|
+
});
|