@yanqirenshi/d3.ter 0.4.1 → 0.4.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -0
- package/dist/index.d.ts +1 -1
- package/dist/js/Painters/Relationships.js +14 -5
- package/dist/js/Relationship.js +10 -10
- package/package.json +1 -1
- package/jest.config.js +0 -25
- package/tests/Entity.test.js +0 -59
- package/tests/Rectum.test.js +0 -297
- package/tests/Relationships.test.js +0 -171
- package/tests/d3-stub.js +0 -4
package/README.md
CHANGED
|
@@ -108,6 +108,16 @@ TM の再帰がこれで、ループの中点の○から再帰表を垂下し
|
|
|
108
108
|
見た目は変わりません。サブセットの分岐は、垂下 1 本が関係 1 件なので垂下にだけ当たりがあり、
|
|
109
109
|
幹とバス(複数の関係で共有)にはありません。
|
|
110
110
|
|
|
111
|
+
結線のラベル(`text.relationship-label`)の上のクリックも、その結線の `relationship.click` として知らせます(v0.4.3+)。
|
|
112
|
+
ラベルは当たり判定の線の上に描かれるので、0.4.2 までは、線の近くでもラベルの文字の上では届きませんでした(#213)。
|
|
113
|
+
当たり判定の線と同じく、外側へも伝わり(`stopPropagation` しない)、カーソルは変えません。
|
|
114
|
+
サブセットの区分コード(`text.subset-code`)と、中点の○(`circle.mapping-junction`)・垂下線(`line.mapping-drop`)では知らせません。
|
|
115
|
+
|
|
116
|
+
当たりの太さ(`hit.width`)は**画面の px** です。拡大率に関わらず一定で、縮小しても細くなりません。
|
|
117
|
+
**0.4.1 までは図の単位**で、拡大率に合わせて太さが変わっていました(50% で、線から約 2px)。
|
|
118
|
+
縮小したときの当たりを補うために `hit.width` を大きくしていた場合は、値を見直してください。
|
|
119
|
+
9 倍を超えて拡大すると、見える線(1 × 拡大率)のほうが当たり(既定 9)より太くなり、見える線の縁の帯ではクリックが届きません(当たり判定の線だけで受けているため)。
|
|
120
|
+
|
|
111
121
|
## 開発
|
|
112
122
|
|
|
113
123
|
```bash
|
package/dist/index.d.ts
CHANGED
|
@@ -198,7 +198,7 @@ export interface TerCallbacks {
|
|
|
198
198
|
dragend?: ((core: TerEntity, entity: TerEntityDatum, move: { dx: number; dy: number }) => void) | null;
|
|
199
199
|
};
|
|
200
200
|
relationship?: {
|
|
201
|
-
/** 結線(
|
|
201
|
+
/** 結線(線・自己結線のループ・結線のラベル)のクリック通知。ラベルでも受けるのは v0.4.3+。_core に入力(TerRelationship)が入る */
|
|
202
202
|
click?: ((relationship: { _id: number | string; _core: TerRelationship; [key: string]: unknown }) => void) | null;
|
|
203
203
|
};
|
|
204
204
|
identifier?: {
|
|
@@ -164,8 +164,9 @@ var Relationships = exports["default"] = /*#__PURE__*/function () {
|
|
|
164
164
|
});
|
|
165
165
|
this._lines.draw(place, plain);
|
|
166
166
|
|
|
167
|
-
// 当たり判定用の透明な線(#154)
|
|
168
|
-
|
|
167
|
+
// 当たり判定用の透明な線(#154)。見える線の後に描いて上に乗せる。
|
|
168
|
+
// non-scaling-stroke で、太さ(hit.width)を画面の px にする(縮小しても当たりが細くならない。#209)
|
|
169
|
+
this._hitLines.draw(place, plain).attr('pointer-events', 'stroke').attr('vector-effect', 'non-scaling-stroke');
|
|
169
170
|
this.drawSelfLoops(place, data);
|
|
170
171
|
this.drawSubsetTrees(place, data);
|
|
171
172
|
this.drawMappingDrops(place, data);
|
|
@@ -281,7 +282,8 @@ var Relationships = exports["default"] = /*#__PURE__*/function () {
|
|
|
281
282
|
return d._id;
|
|
282
283
|
});
|
|
283
284
|
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').
|
|
285
|
+
var entered_hits = hits.enter().append('path').attr('class', 'connector-loop-hit').attr('fill', 'none').attr('stroke', 'transparent').attr('stroke-width', this.hitWidth()).attr('pointer-events', 'stroke').attr('vector-effect', 'non-scaling-stroke') // 太さを画面の px に(#209)
|
|
286
|
+
.on('click', function (event, d) {
|
|
285
287
|
return _this3.notifyClick(d);
|
|
286
288
|
});
|
|
287
289
|
this.applySelfLoops(entered_hits.merge(hits));
|
|
@@ -306,6 +308,11 @@ var Relationships = exports["default"] = /*#__PURE__*/function () {
|
|
|
306
308
|
* 結線のラベル(relationship.label)を線の中点の少し上に描く。
|
|
307
309
|
* enter/update join で冪等。サブセット結線は区分コード(=/×)を
|
|
308
310
|
* 分岐点に描くため対象外。
|
|
311
|
+
*
|
|
312
|
+
* ラベルの上のクリックも、その結線のクリックとして知らせる(#213。v0.4.3+)。
|
|
313
|
+
* ラベルは当たり判定の線より後に描くので上に乗り、0.4.2 まではラベルの文字の上では知らせなかった。
|
|
314
|
+
* 当たり判定の線(ループの :220 と同じ)にそろえて、stopPropagation はせず、カーソルも変えない。
|
|
315
|
+
* リスナーは新しく作ったラベルにだけ付ける(d3 の data join で、描き直しやドラッグの追従で結び直しても重ならない)。
|
|
309
316
|
*/
|
|
310
317
|
}, {
|
|
311
318
|
key: "drawLabels",
|
|
@@ -318,7 +325,9 @@ var Relationships = exports["default"] = /*#__PURE__*/function () {
|
|
|
318
325
|
return d._id;
|
|
319
326
|
});
|
|
320
327
|
texts.exit().remove();
|
|
321
|
-
var entered = texts.enter().append('text').attr('class', 'relationship-label').attr('text-anchor', 'middle').attr('font-size', '12px').attr('fill', '#333333')
|
|
328
|
+
var entered = texts.enter().append('text').attr('class', 'relationship-label').attr('text-anchor', 'middle').attr('font-size', '12px').attr('fill', '#333333').on('click', function (event, d) {
|
|
329
|
+
return _this5.notifyClick(d);
|
|
330
|
+
});
|
|
322
331
|
this.applyLabels(entered.merge(texts));
|
|
323
332
|
}
|
|
324
333
|
/** ラベルの位置(結線の中点の少し上)とテキストを適用する。 */
|
|
@@ -584,7 +593,7 @@ var Relationships = exports["default"] = /*#__PURE__*/function () {
|
|
|
584
593
|
this.applySubsetTrees(entered_paths.merge(paths), entered_labels.merge(labels));
|
|
585
594
|
|
|
586
595
|
// 当たり判定(関係 1 件 = 垂下 1 本)。見える分岐線より後に描いて上に乗せる(#154)
|
|
587
|
-
this._subsetHitLines.draw(place, this._subsetRels).attr('pointer-events', 'stroke');
|
|
596
|
+
this._subsetHitLines.draw(place, this._subsetRels).attr('pointer-events', 'stroke').attr('vector-effect', 'non-scaling-stroke'); // 太さを画面の px に(#209)
|
|
588
597
|
}
|
|
589
598
|
/** 分岐線の形状とラベル(バスの少し上・幹の位置)を適用する。 */
|
|
590
599
|
}, {
|
package/dist/js/Relationship.js
CHANGED
|
@@ -37,11 +37,11 @@ var Relationship = exports["default"] = /*#__PURE__*/function (_Atman) {
|
|
|
37
37
|
value: function label() {
|
|
38
38
|
return this._core.label || null;
|
|
39
39
|
}
|
|
40
|
-
/**
|
|
41
|
-
* TM のサブセット結線に添える区分コードの表記。
|
|
42
|
-
* =区分コード … 同一のサブセット(kind: 'same')
|
|
43
|
-
* ×区分コード … 相違のサブセット(kind: 'different'。'same' 以外は×扱い)
|
|
44
|
-
* 入力の relationship.subset = { kind, code }。無ければ null(表示なし)。
|
|
40
|
+
/**
|
|
41
|
+
* TM のサブセット結線に添える区分コードの表記。
|
|
42
|
+
* =区分コード … 同一のサブセット(kind: 'same')
|
|
43
|
+
* ×区分コード … 相違のサブセット(kind: 'different'。'same' 以外は×扱い)
|
|
44
|
+
* 入力の relationship.subset = { kind, code }。無ければ null(表示なし)。
|
|
45
45
|
*/
|
|
46
46
|
}, {
|
|
47
47
|
key: "subsetLabel",
|
|
@@ -50,11 +50,11 @@ var Relationship = exports["default"] = /*#__PURE__*/function (_Atman) {
|
|
|
50
50
|
if (!subset || !subset.code) return null;
|
|
51
51
|
return (subset.kind === 'same' ? '=' : '×') + subset.code;
|
|
52
52
|
}
|
|
53
|
-
/**
|
|
54
|
-
* TM の対応表/対照表(mapping)。この結線の中点(○)から垂下線で
|
|
55
|
-
* ぶら下げる対応表(CORRESPONDENCE)/対照表(COMPARATIVE)の Entity。
|
|
56
|
-
* 入力の relationship.mapping = { entity: id } を Rectum が
|
|
57
|
-
* データ構築時に解決してセットする。無ければ null(垂下なし)。
|
|
53
|
+
/**
|
|
54
|
+
* TM の対応表/対照表(mapping)。この結線の中点(○)から垂下線で
|
|
55
|
+
* ぶら下げる対応表(CORRESPONDENCE)/対照表(COMPARATIVE)の Entity。
|
|
56
|
+
* 入力の relationship.mapping = { entity: id } を Rectum が
|
|
57
|
+
* データ構築時に解決してセットする。無ければ null(垂下なし)。
|
|
58
58
|
*/
|
|
59
59
|
}, {
|
|
60
60
|
key: "mapping",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yanqirenshi/d3.ter",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.3",
|
|
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",
|
package/jest.config.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
module.exports = {
|
|
2
|
-
// テストファイルは tests ディレクトリに指定
|
|
3
|
-
testMatch: [
|
|
4
|
-
"**/tests/**/?(*.)+(spec|test).[tj]s?(x)"
|
|
5
|
-
],
|
|
6
|
-
// monorepo では babel-jest がルートに hoist されるため名前解決に任せる
|
|
7
|
-
transform: {
|
|
8
|
-
"^.+\\.js$": 'babel-jest',
|
|
9
|
-
},
|
|
10
|
-
// d3 v7 は ESM-only で CJS ランタイムの jest では読めないため、スタブにマップする
|
|
11
|
-
moduleNameMapper: {
|
|
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',
|
|
20
|
-
},
|
|
21
|
-
collectCoverageFrom: [
|
|
22
|
-
"**/src/**/*.js",
|
|
23
|
-
"!**/node_modules/**",
|
|
24
|
-
],
|
|
25
|
-
};
|
package/tests/Entity.test.js
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import Entity from '../src/js/Entity.js';
|
|
2
|
-
|
|
3
|
-
const entityData = (type) => ({
|
|
4
|
-
id: 1,
|
|
5
|
-
type: type,
|
|
6
|
-
name: 'Entity A',
|
|
7
|
-
description: '',
|
|
8
|
-
position: { x: 0, y: 0, z: 0 },
|
|
9
|
-
size: { w: 0, h: 0 },
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
test('entity type marker and background color follow the entity type', () => {
|
|
13
|
-
const resource = new Entity(entityData('RESOURCE'), null);
|
|
14
|
-
expect(resource.type.contents).toBe('Rsc');
|
|
15
|
-
expect(resource.background.color).toBe('#89c3eb');
|
|
16
|
-
|
|
17
|
-
const event = new Entity(entityData('EVENT'), null);
|
|
18
|
-
expect(event.type.contents).toBe('Evt');
|
|
19
|
-
expect(event.background.color).toBe('#f09199');
|
|
20
|
-
|
|
21
|
-
// issue #18: 対照表(COMPARATIVE)のバッジは「対照」(「対象」は誤字)
|
|
22
|
-
const comparative = new Entity(entityData('COMPARATIVE'), null);
|
|
23
|
-
expect(comparative.type.contents).toBe('対照');
|
|
24
|
-
|
|
25
|
-
const correspondence = new Entity(entityData('CORRESPONDENCE'), null);
|
|
26
|
-
expect(correspondence.type.contents).toBe('対応');
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
// issue #14: TM(T字形ER)の多値。MO=多値のOR、MA=多値のAND(HDR-DTL)
|
|
30
|
-
test('many-valued types render MO / MA badges with their own colors', () => {
|
|
31
|
-
const mo = new Entity(entityData('MANY-VALUED-OR'), null);
|
|
32
|
-
expect(mo.type.contents).toBe('MO');
|
|
33
|
-
expect(mo.background.color).toBe('#fddea5');
|
|
34
|
-
|
|
35
|
-
const ma = new Entity(entityData('MANY-VALUED-AND'), null);
|
|
36
|
-
expect(ma.type.contents).toBe('MA');
|
|
37
|
-
expect(ma.background.color).toBe('#9fd5c9');
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
// issue #17: TM の「クラス」— 種別バッジを持たない箱
|
|
41
|
-
test('CLASS renders without a type badge (empty badge, zero badge width)', () => {
|
|
42
|
-
const klass = new Entity(entityData('CLASS'), null);
|
|
43
|
-
|
|
44
|
-
expect(klass.type.contents).toBe('');
|
|
45
|
-
expect(klass.background.color).toBe('#bdc0ba');
|
|
46
|
-
|
|
47
|
-
// バッジ無しなので幅 0(名称エリアがヘッダ全幅を使う)
|
|
48
|
-
klass.sizingType();
|
|
49
|
-
expect(klass.type.size.w).toBe(0);
|
|
50
|
-
|
|
51
|
-
// 通常種別のバッジ幅は従来どおり正
|
|
52
|
-
const resource = new Entity(entityData('RESOURCE'), null);
|
|
53
|
-
resource.sizingType();
|
|
54
|
-
expect(resource.type.size.w).toBeGreaterThan(0);
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
test('unknown entity type throws', () => {
|
|
58
|
-
expect(() => new Entity(entityData('UNKNOWN'), null)).toThrow();
|
|
59
|
-
});
|
package/tests/Rectum.test.js
DELETED
|
@@ -1,297 +0,0 @@
|
|
|
1
|
-
import Rectum from '../src/js/Rectum.js';
|
|
2
|
-
|
|
3
|
-
// issue #17: TM の「クラス」は切り出し元(親)としか結線できない
|
|
4
|
-
// (tm3-1 §7「クラスで整える」: 親→クラスの線はあるが、他のモノとは結線不可)。
|
|
5
|
-
// selector 未設定の Rectum.data() は描画せずデータ構築のみ行う(DOM 不要)。
|
|
6
|
-
const DATA = (relationships) => ({
|
|
7
|
-
identifiers: [
|
|
8
|
-
{ id: 10000, name: { logical: 'Entity ID', physical: 'entity_id' }, description: '' },
|
|
9
|
-
{ id: 10001, name: { logical: 'Attribute ID', physical: 'attribute_id' }, description: '' },
|
|
10
|
-
],
|
|
11
|
-
attributes: [
|
|
12
|
-
{ id: 20000, name: { physical: 'name', logical: '名称' } },
|
|
13
|
-
],
|
|
14
|
-
entities: [
|
|
15
|
-
{
|
|
16
|
-
id: 30000, type: 'RESOURCE', name: 'Entity', description: '',
|
|
17
|
-
position: { x: 0, y: 0, z: 0 }, size: { w: 0, h: 0 },
|
|
18
|
-
identifiers: [{ id: 3000001, identifier: 10000 }],
|
|
19
|
-
attributes: [{ id: 3000010, attribute: 20000 }],
|
|
20
|
-
},
|
|
21
|
-
{
|
|
22
|
-
// クラスと個体指定子を共有しない別のモノ(親ではない)
|
|
23
|
-
id: 30001, type: 'RESOURCE', name: 'Attribute', description: '',
|
|
24
|
-
position: { x: 600, y: 0, z: 0 }, size: { w: 0, h: 0 },
|
|
25
|
-
identifiers: [{ id: 3000101, identifier: 10001 }],
|
|
26
|
-
attributes: [{ id: 3000110, attribute: 20000 }],
|
|
27
|
-
},
|
|
28
|
-
{
|
|
29
|
-
id: 70000, type: 'CLASS', name: 'Entity.廃止', description: '',
|
|
30
|
-
position: { x: 0, y: 400, z: 0 }, size: { w: 0, h: 0 },
|
|
31
|
-
identifiers: [{ id: 7000001, identifier: 10000 }],
|
|
32
|
-
attributes: [{ id: 7000010, attribute: 20000 }],
|
|
33
|
-
},
|
|
34
|
-
{
|
|
35
|
-
id: 70001, type: 'CLASS', name: 'Entity.別区分', description: '',
|
|
36
|
-
position: { x: 300, y: 400, z: 0 }, size: { w: 0, h: 0 },
|
|
37
|
-
identifiers: [{ id: 7000101, identifier: 10000 }],
|
|
38
|
-
attributes: [{ id: 7000110, attribute: 20000 }],
|
|
39
|
-
},
|
|
40
|
-
{
|
|
41
|
-
id: 80000, type: 'CORRESPONDENCE', name: 'Entity.Attribute.対応表', description: '',
|
|
42
|
-
position: { x: 300, y: 700, z: 0 }, size: { w: 0, h: 0 },
|
|
43
|
-
identifiers: [
|
|
44
|
-
{ id: 8000001, identifier: 10000 },
|
|
45
|
-
{ id: 8000002, identifier: 10001 },
|
|
46
|
-
],
|
|
47
|
-
attributes: [],
|
|
48
|
-
},
|
|
49
|
-
{
|
|
50
|
-
id: 82000, type: 'RECURSION', name: 'Entity.Entity.再帰表', description: '',
|
|
51
|
-
position: { x: 0, y: 700, z: 0 }, size: { w: 0, h: 0 },
|
|
52
|
-
identifiers: [
|
|
53
|
-
{ id: 8200001, identifier: 10000 },
|
|
54
|
-
{ id: 8200002, identifier: 10000 },
|
|
55
|
-
],
|
|
56
|
-
attributes: [],
|
|
57
|
-
},
|
|
58
|
-
],
|
|
59
|
-
relationships,
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
test('CLASS entity builds fine when it has no relationships', () => {
|
|
63
|
-
const rectum = new Rectum({});
|
|
64
|
-
|
|
65
|
-
expect(() => rectum.data(DATA([]))).not.toThrow();
|
|
66
|
-
expect(rectum.entities().ht[70000]).toBeDefined();
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
test('a parent → CLASS relationship is allowed (identifier master is shared)', () => {
|
|
70
|
-
const rectum = new Rectum({});
|
|
71
|
-
const parentLink = [{
|
|
72
|
-
id: 1, type: null,
|
|
73
|
-
from: { entity: 30000, cardinality: 1, optionality: 0, position: 270 },
|
|
74
|
-
to: { entity: 70000, cardinality: 1, optionality: 0, position: 90 },
|
|
75
|
-
details: [{ from: { id: 3000001 }, to: { id: 7000001 } }],
|
|
76
|
-
}];
|
|
77
|
-
|
|
78
|
-
expect(() => rectum.data(DATA(parentLink))).not.toThrow();
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
test('a CLASS relationship to a non-parent throws', () => {
|
|
82
|
-
// Attribute(30001) はクラスの個体指定子(Entity ID)を持たない = 親ではない
|
|
83
|
-
const bad = [{
|
|
84
|
-
id: 1, type: null,
|
|
85
|
-
from: { entity: 30001, cardinality: 1, optionality: 0, position: 270 },
|
|
86
|
-
to: { entity: 70000, cardinality: 1, optionality: 0, position: 90 },
|
|
87
|
-
details: [{ from: { id: 3000101 }, to: { id: 7000001 } }],
|
|
88
|
-
}];
|
|
89
|
-
|
|
90
|
-
expect(() => new Rectum({}).data(DATA(bad)))
|
|
91
|
-
.toThrow(/クラス\(CLASS\)は切り出し元\(親\)としか結線できません/);
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
// issue #15: サブセット結線の区分コード表記(=同一 / ×相違)
|
|
95
|
-
test('subsetLabel composes = / × with the code (default: different)', () => {
|
|
96
|
-
const rectum = new Rectum({});
|
|
97
|
-
rectum.data(DATA([
|
|
98
|
-
{
|
|
99
|
-
id: 1, type: null,
|
|
100
|
-
from: { entity: 30000, cardinality: 1, optionality: 0, position: 270 },
|
|
101
|
-
to: { entity: 30001, cardinality: 1, optionality: 0, position: 90 },
|
|
102
|
-
details: [{ from: { id: 3000001 }, to: { id: 3000101 } }],
|
|
103
|
-
subset: { kind: 'different', code: '状態区分' },
|
|
104
|
-
},
|
|
105
|
-
{
|
|
106
|
-
id: 2, type: null,
|
|
107
|
-
from: { entity: 30000, cardinality: 1, optionality: 0, position: 0 },
|
|
108
|
-
to: { entity: 30001, cardinality: 1, optionality: 0, position: 180 },
|
|
109
|
-
details: [{ from: { id: 3000001 }, to: { id: 3000101 } }],
|
|
110
|
-
subset: { kind: 'same', code: '行種別' },
|
|
111
|
-
},
|
|
112
|
-
{
|
|
113
|
-
id: 3, type: null,
|
|
114
|
-
from: { entity: 30000, cardinality: 1, optionality: 0, position: 315 },
|
|
115
|
-
to: { entity: 30001, cardinality: 1, optionality: 0, position: 45 },
|
|
116
|
-
details: [{ from: { id: 3000001 }, to: { id: 3000101 } }],
|
|
117
|
-
},
|
|
118
|
-
{
|
|
119
|
-
id: 4, type: null,
|
|
120
|
-
from: { entity: 30000, cardinality: 1, optionality: 0, position: 90 },
|
|
121
|
-
to: { entity: 30001, cardinality: 1, optionality: 0, position: 270 },
|
|
122
|
-
details: [{ from: { id: 3000001 }, to: { id: 3000101 } }],
|
|
123
|
-
label: 'defines',
|
|
124
|
-
},
|
|
125
|
-
]));
|
|
126
|
-
|
|
127
|
-
const rels = rectum._relationships.ht;
|
|
128
|
-
expect(rels[1].subsetLabel()).toBe('×状態区分');
|
|
129
|
-
expect(rels[2].subsetLabel()).toBe('=行種別');
|
|
130
|
-
expect(rels[3].subsetLabel()).toBeNull(); // subset 無し → 表示なし
|
|
131
|
-
|
|
132
|
-
// issue #16: 汎用ラベル(relationship.label)
|
|
133
|
-
expect(rels[3].label()).toBeNull(); // label 無し → 表示なし
|
|
134
|
-
expect(rels[4].label()).toBe('defines'); // 指定があればそのまま
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
// 対応表/対照表の垂下(relationship.mapping)。
|
|
138
|
-
// tm3-1 §2「対応表(onto-mapping)」: 2エンティティ間の結線の中点(○)から
|
|
139
|
-
// 垂下線で対応表/対照表をぶら下げる。
|
|
140
|
-
test('mapping resolves the correspondence entity hung from the line', () => {
|
|
141
|
-
const rectum = new Rectum({});
|
|
142
|
-
rectum.data(DATA([{
|
|
143
|
-
id: 1, type: null,
|
|
144
|
-
from: { entity: 30000, cardinality: 3, optionality: 1, position: 270 },
|
|
145
|
-
to: { entity: 30001, cardinality: 1, optionality: 1, position: 90 },
|
|
146
|
-
details: [{ from: { id: 3000001 }, to: { id: 3000101 } }],
|
|
147
|
-
mapping: { entity: 80000 },
|
|
148
|
-
}, {
|
|
149
|
-
id: 2, type: null,
|
|
150
|
-
from: { entity: 30000, cardinality: 1, optionality: 0, position: 0 },
|
|
151
|
-
to: { entity: 30001, cardinality: 1, optionality: 0, position: 180 },
|
|
152
|
-
details: [{ from: { id: 3000001 }, to: { id: 3000101 } }],
|
|
153
|
-
}]));
|
|
154
|
-
|
|
155
|
-
const rels = rectum._relationships.ht;
|
|
156
|
-
expect(rels[1].mapping()).toBe(rectum.entities().ht[80000]);
|
|
157
|
-
expect(rels[2].mapping()).toBeNull(); // mapping 無し → 垂下なし
|
|
158
|
-
});
|
|
159
|
-
|
|
160
|
-
test('mapping to a non-correspondence/comparative/recursion entity throws', () => {
|
|
161
|
-
// RESOURCE(30001) は対応表/対照表/再帰表ではない
|
|
162
|
-
const bad = [{
|
|
163
|
-
id: 1, type: null,
|
|
164
|
-
from: { entity: 30000, cardinality: 1, optionality: 0, position: 270 },
|
|
165
|
-
to: { entity: 70000, cardinality: 1, optionality: 0, position: 90 },
|
|
166
|
-
details: [{ from: { id: 3000001 }, to: { id: 7000001 } }],
|
|
167
|
-
mapping: { entity: 30001 },
|
|
168
|
-
}];
|
|
169
|
-
|
|
170
|
-
expect(() => new Rectum({}).data(DATA(bad)))
|
|
171
|
-
.toThrow(/対応表\(CORRESPONDENCE\)・対照表\(COMPARATIVE\)・再帰表\(RECURSION\)だけ/);
|
|
172
|
-
});
|
|
173
|
-
|
|
174
|
-
// issue #73: 再帰(自己結線 + 再帰表の垂下)
|
|
175
|
-
// 本(佐藤正美)の書き方では、モノから出た線がそのモノ自身に戻るループを描き、
|
|
176
|
-
// ループの途中の○から再帰表をぶら下げる。
|
|
177
|
-
const SELF_LINK = (extra={}) => ([{
|
|
178
|
-
id: 10, type: null,
|
|
179
|
-
from: { entity: 30000, cardinality: 3, optionality: 0, position: 270 },
|
|
180
|
-
to: { entity: 30000, cardinality: 3, optionality: 0, position: 0 },
|
|
181
|
-
details: [{ from: { id: 3000001 }, to: { id: 3000001 } }],
|
|
182
|
-
...extra,
|
|
183
|
-
}]);
|
|
184
|
-
|
|
185
|
-
test('自己結線の両端のポートは id が別になり、ht も両端を保持する', () => {
|
|
186
|
-
const rectum = new Rectum({});
|
|
187
|
-
rectum.data(DATA(SELF_LINK()));
|
|
188
|
-
|
|
189
|
-
const entity = rectum.entities().ht[30000];
|
|
190
|
-
const ports = entity.ports.items.list;
|
|
191
|
-
|
|
192
|
-
// 両端が同じエンティティなので、同じ箱に2つのポートが付く
|
|
193
|
-
expect(ports).toHaveLength(2);
|
|
194
|
-
|
|
195
|
-
// id は端の種別(from / to)で分かれる。
|
|
196
|
-
// 旧実装は relationship.id + entity._id だったため自己結線で重複し、
|
|
197
|
-
// ht では一方がもう一方を上書きしていた。
|
|
198
|
-
const ids = ports.map((p)=> p.id());
|
|
199
|
-
expect(new Set(ids).size).toBe(2);
|
|
200
|
-
expect(ids[0]).toContain('_from_');
|
|
201
|
-
expect(ids[1]).toContain('_to_');
|
|
202
|
-
|
|
203
|
-
expect(Object.keys(entity.ports.items.ht)).toHaveLength(2);
|
|
204
|
-
});
|
|
205
|
-
|
|
206
|
-
test('通常の結線でもポート id は端ごとに別になる', () => {
|
|
207
|
-
const rectum = new Rectum({});
|
|
208
|
-
rectum.data(DATA([{
|
|
209
|
-
id: 1, type: null,
|
|
210
|
-
from: { entity: 30000, cardinality: 1, optionality: 0, position: 270 },
|
|
211
|
-
to: { entity: 30001, cardinality: 1, optionality: 0, position: 90 },
|
|
212
|
-
details: [{ from: { id: 3000001 }, to: { id: 3000101 } }],
|
|
213
|
-
}]));
|
|
214
|
-
|
|
215
|
-
const from_port = rectum.entities().ht[30000].ports.items.list[0];
|
|
216
|
-
const to_port = rectum.entities().ht[30001].ports.items.list[0];
|
|
217
|
-
|
|
218
|
-
expect(from_port.id()).not.toBe(to_port.id());
|
|
219
|
-
});
|
|
220
|
-
|
|
221
|
-
test('mapping に再帰表(RECURSION)を指定できる(自己結線)', () => {
|
|
222
|
-
const rectum = new Rectum({});
|
|
223
|
-
rectum.data(DATA(SELF_LINK({ mapping: { entity: 82000 } })));
|
|
224
|
-
|
|
225
|
-
const rel = rectum._relationships.ht[10];
|
|
226
|
-
expect(rel.mapping()).toBe(rectum.entities().ht[82000]);
|
|
227
|
-
});
|
|
228
|
-
|
|
229
|
-
test('再帰表(RECURSION)を通常の結線に指定すると例外になる', () => {
|
|
230
|
-
// 再帰表は自己結線から垂下するもの。別のモノどうしの結線に付けるのは
|
|
231
|
-
// modeling のミスなので、描画が壊れる前に検出する。
|
|
232
|
-
const bad = [{
|
|
233
|
-
id: 10, type: null,
|
|
234
|
-
from: { entity: 30000, cardinality: 3, optionality: 0, position: 270 },
|
|
235
|
-
to: { entity: 30001, cardinality: 3, optionality: 0, position: 90 },
|
|
236
|
-
details: [{ from: { id: 3000001 }, to: { id: 3000101 } }],
|
|
237
|
-
mapping: { entity: 82000 },
|
|
238
|
-
}];
|
|
239
|
-
|
|
240
|
-
expect(() => new Rectum({}).data(DATA(bad)))
|
|
241
|
-
.toThrow(/再帰表\(RECURSION\)は自己結線/);
|
|
242
|
-
});
|
|
243
|
-
|
|
244
|
-
test('自己結線に対応表(CORRESPONDENCE)を指定するのは従来どおり許可する', () => {
|
|
245
|
-
const rectum = new Rectum({});
|
|
246
|
-
|
|
247
|
-
expect(() => rectum.data(DATA(SELF_LINK({ mapping: { entity: 80000 } }))))
|
|
248
|
-
.not.toThrow();
|
|
249
|
-
});
|
|
250
|
-
|
|
251
|
-
test('同じモノに複数のループ(角度違い)を作れる', () => {
|
|
252
|
-
const rectum = new Rectum({});
|
|
253
|
-
rectum.data(DATA([
|
|
254
|
-
{
|
|
255
|
-
id: 10, type: null,
|
|
256
|
-
from: { entity: 30000, cardinality: 3, optionality: 0, position: 270 },
|
|
257
|
-
to: { entity: 30000, cardinality: 3, optionality: 0, position: 0 },
|
|
258
|
-
details: [{ from: { id: 3000001 }, to: { id: 3000001 } }],
|
|
259
|
-
},
|
|
260
|
-
{
|
|
261
|
-
id: 11, type: null,
|
|
262
|
-
from: { entity: 30000, cardinality: 3, optionality: 0, position: 90 },
|
|
263
|
-
to: { entity: 30000, cardinality: 3, optionality: 0, position: 180 },
|
|
264
|
-
details: [{ from: { id: 3000001 }, to: { id: 3000001 } }],
|
|
265
|
-
},
|
|
266
|
-
]));
|
|
267
|
-
|
|
268
|
-
const ports = rectum.entities().ht[30000].ports.items.list;
|
|
269
|
-
|
|
270
|
-
expect(ports).toHaveLength(4);
|
|
271
|
-
expect(new Set(ports.map((p)=> p.id())).size).toBe(4);
|
|
272
|
-
});
|
|
273
|
-
|
|
274
|
-
test('mapping to a missing entity throws', () => {
|
|
275
|
-
const bad = [{
|
|
276
|
-
id: 1, type: null,
|
|
277
|
-
from: { entity: 30000, cardinality: 1, optionality: 0, position: 270 },
|
|
278
|
-
to: { entity: 30001, cardinality: 1, optionality: 0, position: 90 },
|
|
279
|
-
details: [{ from: { id: 3000001 }, to: { id: 3000101 } }],
|
|
280
|
-
mapping: { entity: 99999 },
|
|
281
|
-
}];
|
|
282
|
-
|
|
283
|
-
expect(() => new Rectum({}).data(DATA(bad)))
|
|
284
|
-
.toThrow(/mapping に指定されたエンティティが見つかりません/);
|
|
285
|
-
});
|
|
286
|
-
|
|
287
|
-
test('a CLASS-to-CLASS relationship throws', () => {
|
|
288
|
-
const bad = [{
|
|
289
|
-
id: 1, type: null,
|
|
290
|
-
from: { entity: 70000, cardinality: 1, optionality: 0, position: 270 },
|
|
291
|
-
to: { entity: 70001, cardinality: 1, optionality: 0, position: 90 },
|
|
292
|
-
details: [{ from: { id: 7000001 }, to: { id: 7000101 } }],
|
|
293
|
-
}];
|
|
294
|
-
|
|
295
|
-
expect(() => new Rectum({}).data(DATA(bad)))
|
|
296
|
-
.toThrow(/クラス\(CLASS\)同士は結線できません/);
|
|
297
|
-
});
|
|
@@ -1,171 +0,0 @@
|
|
|
1
|
-
import Relationships from '../src/js/Painters/Relationships.js';
|
|
2
|
-
|
|
3
|
-
// 対応表/対照表の垂下(mapping)の取り付け辺。
|
|
4
|
-
// 結線の中点(○)から見て最寄りの辺の中央に接続する(上下だけでなく
|
|
5
|
-
// 左右の辺にも対応)。判定は箱の縦横比で正規化する。
|
|
6
|
-
describe('mappingGeometry: 垂下線は最寄りの辺の中央に取り付く', () => {
|
|
7
|
-
const painter = new Relationships(null);
|
|
8
|
-
|
|
9
|
-
// 結線: (100,100)-(300,100) → 中点(junction)は (200,100)
|
|
10
|
-
const rel = (mappingEntity) => ({
|
|
11
|
-
from: { position: () => ({ x: 0, y: 0 }), _owner: { position: { x: 100, y: 100 } } },
|
|
12
|
-
to: { position: () => ({ x: 0, y: 0 }), _owner: { position: { x: 300, y: 100 } } },
|
|
13
|
-
mapping: () => mappingEntity,
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
const box = (x, y) => ({ position: { x: x, y: y }, size: { w: 200, h: 100 } });
|
|
17
|
-
|
|
18
|
-
it('表が中点の下 → 上端中央(従来どおり)', () => {
|
|
19
|
-
const g = painter.mappingGeometry(rel(box(100, 400)));
|
|
20
|
-
expect(g).toEqual({ jx: 200, jy: 100, mx: 200, my: 400 });
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
it('表が中点の上 → 下端中央(従来どおり)', () => {
|
|
24
|
-
const g = painter.mappingGeometry(rel(box(100, -400)));
|
|
25
|
-
expect(g).toEqual({ jx: 200, jy: 100, mx: 200, my: -300 });
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
it('表が中点の右 → 左辺中央', () => {
|
|
29
|
-
const g = painter.mappingGeometry(rel(box(600, 50)));
|
|
30
|
-
expect(g).toEqual({ jx: 200, jy: 100, mx: 600, my: 100 });
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
it('表が中点の左 → 右辺中央', () => {
|
|
34
|
-
const g = painter.mappingGeometry(rel(box(-500, 50)));
|
|
35
|
-
expect(g).toEqual({ jx: 200, jy: 100, mx: -300, my: 100 });
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
it('斜め位置は箱の縦横比で正規化して支配的な方向の辺を選ぶ', () => {
|
|
39
|
-
// 中心からのずれ dx=250, dy=400。箱は横長(200×100)なので
|
|
40
|
-
// |dx|*h(25000) < |dy|*w(80000) → 縦方向が支配的 → 下端中央
|
|
41
|
-
const g = painter.mappingGeometry(rel(box(-150, -350)));
|
|
42
|
-
expect(g.mx).toBe(-50);
|
|
43
|
-
expect(g.my).toBe(-250);
|
|
44
|
-
});
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
// issue #73: 自己結線(再帰)のループ。
|
|
48
|
-
// 本(佐藤正美)の書き方では、モノから出た線がそのモノ自身に戻るループを描き、
|
|
49
|
-
// ループの途中の○から再帰表をぶら下げる。
|
|
50
|
-
describe('自己結線(再帰)はループとして描く', () => {
|
|
51
|
-
// style() は rectum 経由で引くので、テスト用の parent を噛ませる
|
|
52
|
-
const painter = new Relationships({
|
|
53
|
-
rectum: ()=> ({ style: ()=> ({ relationship: { loop: { distance: 40 } } }) }),
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
// 箱(100,100)-(300,200)。中心は (200,150)
|
|
57
|
-
const owner = { position: { x: 100, y: 100 }, size: { w: 200, h: 100 } };
|
|
58
|
-
const other = { position: { x: 600, y: 100 }, size: { w: 200, h: 100 } };
|
|
59
|
-
|
|
60
|
-
// port の座標は owner 相対。上辺中央(100,-33)と右辺中央(233,50)に付ける
|
|
61
|
-
const selfLink = (mappingEntity=null) => ({
|
|
62
|
-
_id: 'r-self',
|
|
63
|
-
from: { position: ()=> ({ x: 100, y: -33 }), _owner: owner },
|
|
64
|
-
to: { position: ()=> ({ x: 233, y: 50 }), _owner: owner },
|
|
65
|
-
mapping: ()=> mappingEntity,
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
const plainLink = () => ({
|
|
69
|
-
_id: 'r-plain',
|
|
70
|
-
from: { position: ()=> ({ x: 100, y: -33 }), _owner: owner },
|
|
71
|
-
to: { position: ()=> ({ x: -33, y: 50 }), _owner: other },
|
|
72
|
-
mapping: ()=> null,
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
it('isSelfLink は from と to の owner が同じときだけ真', () => {
|
|
76
|
-
expect(painter.isSelfLink(selfLink())).toBe(true);
|
|
77
|
-
expect(painter.isSelfLink(plainLink())).toBe(false);
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
it('ループは3次ベジエで、制御点が箱の外へ伸びる', () => {
|
|
81
|
-
const g = painter.loopGeometry(selfLink());
|
|
82
|
-
|
|
83
|
-
// 端点は port の絶対座標
|
|
84
|
-
expect(g.p0).toEqual({ x: 200, y: 67 }); // (100,100)+(100,-33)
|
|
85
|
-
expect(g.p3).toEqual({ x: 333, y: 150 }); // (100,100)+(233,50)
|
|
86
|
-
|
|
87
|
-
// 制御点は中心(200,150)から見て外向き。上辺の端は上へ、右辺の端は右へ
|
|
88
|
-
expect(g.p1.y).toBeLessThan(g.p0.y);
|
|
89
|
-
expect(g.p1.x).toBe(g.p0.x); // 真上なので x は動かない
|
|
90
|
-
expect(g.p2.x).toBeGreaterThan(g.p3.x);
|
|
91
|
-
expect(g.p2.y).toBe(g.p3.y); // 真右なので y は動かない
|
|
92
|
-
|
|
93
|
-
// 伸ばす距離は style の loop.distance
|
|
94
|
-
expect(g.p0.y - g.p1.y).toBeCloseTo(40, 6);
|
|
95
|
-
expect(g.p2.x - g.p3.x).toBeCloseTo(40, 6);
|
|
96
|
-
|
|
97
|
-
expect(painter.loopPath(selfLink())).toMatch(/^M 200 67 C /);
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
it('junctionPoint は直線なら中点、自己結線ならループの膨らんだ点', () => {
|
|
101
|
-
// 直線: from(200,67) と to(567,150) の中点
|
|
102
|
-
expect(painter.junctionPoint(plainLink())).toEqual({ x: 383.5, y: 108.5 });
|
|
103
|
-
|
|
104
|
-
// 自己結線: 箱の外(右上)へ膨らむので、端点の単純な中点より
|
|
105
|
-
// 右かつ上に寄る
|
|
106
|
-
const j = painter.junctionPoint(selfLink());
|
|
107
|
-
const naive = { x: (200 + 333) / 2, y: (67 + 150) / 2 };
|
|
108
|
-
|
|
109
|
-
expect(j.x).toBeGreaterThan(naive.x);
|
|
110
|
-
expect(j.y).toBeLessThan(naive.y);
|
|
111
|
-
|
|
112
|
-
// ○とラベルが箱の中に入らないこと(箱は x:100-300, y:100-200)。
|
|
113
|
-
// このケースは上辺の外へ抜ける(j = 281.5, 93.5)
|
|
114
|
-
const inside = j.x >= 100 && j.x <= 300 && j.y >= 100 && j.y <= 200;
|
|
115
|
-
expect(inside).toBe(false);
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
it('垂下の○とラベルは同じ点(junctionPoint)に乗る', () => {
|
|
119
|
-
const table = { position: { x: 100, y: 700 }, size: { w: 200, h: 100 } };
|
|
120
|
-
const d = selfLink(table);
|
|
121
|
-
|
|
122
|
-
const j = painter.junctionPoint(d);
|
|
123
|
-
const g = painter.mappingGeometry(d);
|
|
124
|
-
|
|
125
|
-
// mappingGeometry の junction が junctionPoint と一致する
|
|
126
|
-
// (ここがズレると○は正しいのにラベルだけ箱に重なる)
|
|
127
|
-
expect({ x: g.jx, y: g.jy }).toEqual(j);
|
|
128
|
-
});
|
|
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
|
-
});
|
package/tests/d3-stub.js
DELETED