@yanqirenshi/d3.ter 0.1.17 → 0.1.19
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/dist/index.d.ts +183 -0
- package/dist/js/Entity.js +16 -1
- package/dist/js/Rectum.js +31 -1
- package/package.json +2 -1
- package/tests/Entity.test.js +17 -0
- package/tests/Rectum.test.js +86 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
// @yanqirenshi/d3.ter の型定義(手書き同梱)。
|
|
2
|
+
// 実装は Babel(JavaScript)のため、この宣言が公開 API の正となる。
|
|
3
|
+
// Babel の --copy-files で dist/ へコピーされ、package.json の types が指す。
|
|
4
|
+
|
|
5
|
+
import type { ComponentType } from 'react';
|
|
6
|
+
|
|
7
|
+
/* **************************************************************** *
|
|
8
|
+
* 入力データ(data() に渡す構造)
|
|
9
|
+
* **************************************************************** */
|
|
10
|
+
|
|
11
|
+
/** 名称(論理名 / 物理名) */
|
|
12
|
+
export interface TerName {
|
|
13
|
+
logical?: string;
|
|
14
|
+
physical?: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** 識別子(主キー)のマスタ定義。entities から id 参照される */
|
|
18
|
+
export interface TerIdentifier {
|
|
19
|
+
id: number | string;
|
|
20
|
+
name: TerName;
|
|
21
|
+
description?: string;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** 属性(カラム)のマスタ定義。entities から id 参照される */
|
|
25
|
+
export interface TerAttribute {
|
|
26
|
+
id: number | string;
|
|
27
|
+
name: TerName;
|
|
28
|
+
description?: string;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* TM(T字形ER)のエンティティ種別(10種)。これ以外の値は描画時に例外になる。
|
|
33
|
+
* 'CLASS' は「クラスで整える」の箱(モノに混入した別の性質の切り出し。
|
|
34
|
+
* 例: 従業員.入社)で、種別バッジを持たない。
|
|
35
|
+
* **結線できるのは切り出し元(親)のみ**(クラスの識別子=親の個体指定子の
|
|
36
|
+
* マスタを相手が共有していること)。それ以外のモノやクラス同士を
|
|
37
|
+
* relationships の端点に指定するとデータ構築時に例外になる。
|
|
38
|
+
*/
|
|
39
|
+
export type TerEntityType =
|
|
40
|
+
| 'RESOURCE'
|
|
41
|
+
| 'RESOURCE-SUBSET'
|
|
42
|
+
| 'EVENT'
|
|
43
|
+
| 'EVENT-SUBSET'
|
|
44
|
+
| 'COMPARATIVE'
|
|
45
|
+
| 'CORRESPONDENCE'
|
|
46
|
+
| 'RECURSION'
|
|
47
|
+
| 'MANY-VALUED-OR'
|
|
48
|
+
| 'MANY-VALUED-AND'
|
|
49
|
+
| 'CLASS';
|
|
50
|
+
|
|
51
|
+
/** カーディナリティ(1 または 多=3) */
|
|
52
|
+
export type TerCardinality = 1 | 3;
|
|
53
|
+
|
|
54
|
+
/** オプショナリティ(0=必須, 1=任意) */
|
|
55
|
+
export type TerOptionality = 0 | 1;
|
|
56
|
+
|
|
57
|
+
/** エンティティが持つ識別子インスタンス(identifier はマスタの id を参照) */
|
|
58
|
+
export interface TerIdentifierInstance {
|
|
59
|
+
id: number | string;
|
|
60
|
+
identifier: number | string;
|
|
61
|
+
description?: string;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** エンティティが持つ属性インスタンス(attribute はマスタの id を参照) */
|
|
65
|
+
export interface TerAttributeInstance {
|
|
66
|
+
id: number | string;
|
|
67
|
+
attribute: number | string;
|
|
68
|
+
description?: string;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** エンティティ(テーブル) */
|
|
72
|
+
export interface TerEntity {
|
|
73
|
+
id: number | string;
|
|
74
|
+
type: TerEntityType;
|
|
75
|
+
name: string;
|
|
76
|
+
description?: string;
|
|
77
|
+
position: { x: number; y: number; z?: number };
|
|
78
|
+
/** w/h に 0 を渡すと内容に自動フィットする */
|
|
79
|
+
size: { w: number; h: number };
|
|
80
|
+
identifiers: TerIdentifierInstance[];
|
|
81
|
+
attributes: TerAttributeInstance[];
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** リレーションシップの端点(CLASS は切り出し元(親)との結線のみ可 — それ以外は構築時に例外) */
|
|
85
|
+
export interface TerRelationshipEnd {
|
|
86
|
+
/** 接続先エンティティの id */
|
|
87
|
+
entity: number | string;
|
|
88
|
+
cardinality: TerCardinality;
|
|
89
|
+
optionality: TerOptionality;
|
|
90
|
+
/** ポートの取り付け角度(ノード中心から見て 0=真下・時計回り。90=左, 180=真上, 270=右) */
|
|
91
|
+
position?: number;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** ポートの取付カラム(from/to とも識別子・属性インスタンスの id を参照) */
|
|
95
|
+
export interface TerRelationshipDetail {
|
|
96
|
+
from: { id: number | string; description?: string };
|
|
97
|
+
to: { id: number | string; description?: string };
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** エンティティ間のリレーションシップ */
|
|
101
|
+
export interface TerRelationship {
|
|
102
|
+
id: number | string;
|
|
103
|
+
type?: string | null;
|
|
104
|
+
from: TerRelationshipEnd;
|
|
105
|
+
to: TerRelationshipEnd;
|
|
106
|
+
/** 省略時は先頭の識別子インスタンスに取り付く */
|
|
107
|
+
details?: TerRelationshipDetail[];
|
|
108
|
+
description?: string;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/** data() に渡すデータ一式 */
|
|
112
|
+
export interface TerData {
|
|
113
|
+
identifiers: TerIdentifier[];
|
|
114
|
+
attributes: TerAttribute[];
|
|
115
|
+
entities: TerEntity[];
|
|
116
|
+
relationships: TerRelationship[];
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/* **************************************************************** *
|
|
120
|
+
* Rectum / D3Ter
|
|
121
|
+
* **************************************************************** */
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* クリック通知などで渡される正規化済みエンティティ。
|
|
125
|
+
* _core に入力(TerEntity)がそのまま入る。内部レイアウト系のフィールドは省略。
|
|
126
|
+
*/
|
|
127
|
+
export interface TerEntityDatum {
|
|
128
|
+
_id: number | string;
|
|
129
|
+
_core: TerEntity;
|
|
130
|
+
position: { x: number; y: number; z?: number };
|
|
131
|
+
size: { w: number; h: number };
|
|
132
|
+
[key: string]: unknown;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export interface TerCallbacks {
|
|
136
|
+
entity?: {
|
|
137
|
+
/** エンティティのクリック通知(正規化済みデータが渡される) */
|
|
138
|
+
click?: ((entity: TerEntityDatum) => void) | null;
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/** Rectum のコンストラクタ引数(共通基盤 Colon の描画設定 + コールバック) */
|
|
143
|
+
export interface RectumParams {
|
|
144
|
+
/** ズーム初期値 */
|
|
145
|
+
transform?: { k?: number; x?: number; y?: number };
|
|
146
|
+
/** 背景グリッド */
|
|
147
|
+
grid?: { draw?: boolean; size?: number; span?: number };
|
|
148
|
+
svg?: { style?: { background?: string } };
|
|
149
|
+
callbacks?: TerCallbacks;
|
|
150
|
+
/** その他の Colon パラメータ(camera / layers 等) */
|
|
151
|
+
[key: string]: unknown;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* ER 図(TER)の総括クラス。データ構築・レイアウト計算を行い、描画はペインタへ委譲する。
|
|
156
|
+
* (型を付けているのは利用側が触る代表的なメンバーのみ。内部 API は含めない)
|
|
157
|
+
*/
|
|
158
|
+
export class Rectum {
|
|
159
|
+
constructor(params?: RectumParams);
|
|
160
|
+
|
|
161
|
+
/** ter 形式のデータを構築する。引数なしの場合は現在の内部データを返す */
|
|
162
|
+
data(data: TerData): unknown;
|
|
163
|
+
data(): unknown;
|
|
164
|
+
|
|
165
|
+
/** 描画先の SVG 要素(セレクタ文字列 or 要素)を設定する */
|
|
166
|
+
selector(v: string | Element): unknown;
|
|
167
|
+
|
|
168
|
+
/** SVG のピクセルサイズ */
|
|
169
|
+
bounds(v?: { w: number; h: number }): unknown;
|
|
170
|
+
|
|
171
|
+
/** 正規化済みエンティティのプール({ list, ht }) */
|
|
172
|
+
entities(): { list: TerEntityDatum[]; ht: Record<string | number, TerEntityDatum> };
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
export interface D3TerProps {
|
|
176
|
+
rectum: Rectum;
|
|
177
|
+
/** SVG コンテナの DOM id(既定 "d3-ter-graph") */
|
|
178
|
+
id?: string;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/** React ラッパコンポーネント */
|
|
182
|
+
declare const D3Ter: ComponentType<D3TerProps>;
|
|
183
|
+
export default D3Ter;
|
package/dist/js/Entity.js
CHANGED
|
@@ -277,6 +277,10 @@ var Entity = exports["default"] = /*#__PURE__*/function (_Atman) {
|
|
|
277
277
|
return 'MO';
|
|
278
278
|
case 'MANY-VALUED-AND':
|
|
279
279
|
return 'MA';
|
|
280
|
+
// TM の「クラス」(モノに混入した別の性質の切り出し。例: 従業員.入社)。
|
|
281
|
+
// 種別バッジを持たない(空文字 = 意図的なバッジ無し)
|
|
282
|
+
case 'CLASS':
|
|
283
|
+
return '';
|
|
280
284
|
default:
|
|
281
285
|
throw new Error(type + " は知らないよ。");
|
|
282
286
|
}
|
|
@@ -314,6 +318,9 @@ var Entity = exports["default"] = /*#__PURE__*/function (_Atman) {
|
|
|
314
318
|
},
|
|
315
319
|
"many-valued-and": {
|
|
316
320
|
color: '#9fd5c9'
|
|
321
|
+
},
|
|
322
|
+
"class": {
|
|
323
|
+
color: '#bdc0ba'
|
|
317
324
|
}
|
|
318
325
|
};
|
|
319
326
|
var key = this._core.type.toLowerCase();
|
|
@@ -474,8 +481,16 @@ var Entity = exports["default"] = /*#__PURE__*/function (_Atman) {
|
|
|
474
481
|
key: "sizingType",
|
|
475
482
|
value: function sizingType() {
|
|
476
483
|
var data = this.type;
|
|
477
|
-
|
|
484
|
+
|
|
485
|
+
// 空文字は「意図的なバッジ無し」(CLASS)。未設定(null/undefined)とは
|
|
486
|
+
// 区別し、'??' への補完は未設定のときだけ行う。
|
|
487
|
+
if (data.contents === undefined || data.contents === null) data.contents = '??';
|
|
478
488
|
data.size.h = this._default.line.height + data.padding * 2;
|
|
489
|
+
if (data.contents === '') {
|
|
490
|
+
// バッジ無し: 幅 0 にして名称エリアがヘッダ全幅を使う
|
|
491
|
+
data.size.w = 0;
|
|
492
|
+
return;
|
|
493
|
+
}
|
|
479
494
|
|
|
480
495
|
// 幅 = テキストの概算幅 + 両側の padding。
|
|
481
496
|
// ラベルは box 左端から padding 分内側に描かれるため、旧実装
|
package/dist/js/Rectum.js
CHANGED
|
@@ -53,7 +53,9 @@ var Rectum = exports["default"] = /*#__PURE__*/function (_Colon) {
|
|
|
53
53
|
click: null
|
|
54
54
|
}
|
|
55
55
|
};
|
|
56
|
-
|
|
56
|
+
|
|
57
|
+
// callbacks 未指定でも落ちないように既定へフォールバック
|
|
58
|
+
return (0, _deepmerge["default"])(template, callbacks || {});
|
|
57
59
|
}
|
|
58
60
|
}, {
|
|
59
61
|
key: "entities",
|
|
@@ -90,6 +92,29 @@ var Rectum = exports["default"] = /*#__PURE__*/function (_Colon) {
|
|
|
90
92
|
var entities = this.entities();
|
|
91
93
|
return entities.ht[id] || null;
|
|
92
94
|
}
|
|
95
|
+
/**
|
|
96
|
+
* クラス(CLASS)を端点に持つリレーションシップの検証。
|
|
97
|
+
* クラスは切り出し元(親)としか結線できない。親かどうかは
|
|
98
|
+
* 「クラスが持つ識別子(親の個体指定子 R)のマスタを相手も持つか」で判定する。
|
|
99
|
+
*/
|
|
100
|
+
}, {
|
|
101
|
+
key: "assertClassLink",
|
|
102
|
+
value: function assertClassLink(r, entity_from, entity_to) {
|
|
103
|
+
var isClass = function isClass(e) {
|
|
104
|
+
return !!e && e._core.type === 'CLASS';
|
|
105
|
+
};
|
|
106
|
+
if (!isClass(entity_from) && !isClass(entity_to)) return;
|
|
107
|
+
if (isClass(entity_from) && isClass(entity_to)) throw new Error('クラス(CLASS)同士は結線できません。relationship id=' + r.id);
|
|
108
|
+
var klass = isClass(entity_from) ? entity_from : entity_to;
|
|
109
|
+
var other = isClass(entity_from) ? entity_to : entity_from;
|
|
110
|
+
var masters = new Set((klass._core.identifiers || []).map(function (d) {
|
|
111
|
+
return d.identifier;
|
|
112
|
+
}));
|
|
113
|
+
var is_parent = (other._core.identifiers || []).some(function (d) {
|
|
114
|
+
return masters.has(d.identifier);
|
|
115
|
+
});
|
|
116
|
+
if (!is_parent) throw new Error('クラス(CLASS)は切り出し元(親)としか結線できません。' + 'relationship id=' + r.id + ', entity id=' + other._id);
|
|
117
|
+
}
|
|
93
118
|
}, {
|
|
94
119
|
key: "buildRelationshipsWithPort",
|
|
95
120
|
value: function buildRelationshipsWithPort(relationships) {
|
|
@@ -102,6 +127,11 @@ var Rectum = exports["default"] = /*#__PURE__*/function (_Colon) {
|
|
|
102
127
|
var entity_from = _this2.getEntity(from.entity);
|
|
103
128
|
var entity_to = _this2.getEntity(to.entity);
|
|
104
129
|
|
|
130
|
+
// TM の「クラス」は切り出し元(親)としか結線できない
|
|
131
|
+
// (参照 tm3-1 §7「クラスで整える」: 親→クラスの線はあるが、
|
|
132
|
+
// 他のモノとの結線は不可)。誤結線は描画が壊れる前に検出する。
|
|
133
|
+
_this2.assertClassLink(r, entity_from, entity_to);
|
|
134
|
+
|
|
105
135
|
// Port のクラスインスタンスを作成する。
|
|
106
136
|
var port_from = new _Port["default"]('from', entity_from, r, _this2);
|
|
107
137
|
var port_to = new _Port["default"]('to', entity_to, r, _this2);
|
package/package.json
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yanqirenshi/d3.ter",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.19",
|
|
4
4
|
"author": "yanqirenshi@gmail.com",
|
|
5
5
|
"license": "GPL-3.0-or-later",
|
|
6
6
|
"description": "See `src/index.html`",
|
|
7
7
|
"main": "dist/index.js",
|
|
8
|
+
"types": "dist/index.d.ts",
|
|
8
9
|
"directories": {
|
|
9
10
|
"doc": "docs",
|
|
10
11
|
"example": "example"
|
package/tests/Entity.test.js
CHANGED
|
@@ -30,6 +30,23 @@ test('many-valued types render MO / MA badges with their own colors', () => {
|
|
|
30
30
|
expect(ma.background.color).toBe('#9fd5c9');
|
|
31
31
|
});
|
|
32
32
|
|
|
33
|
+
// issue #17: TM の「クラス」— 種別バッジを持たない箱
|
|
34
|
+
test('CLASS renders without a type badge (empty badge, zero badge width)', () => {
|
|
35
|
+
const klass = new Entity(entityData('CLASS'), null);
|
|
36
|
+
|
|
37
|
+
expect(klass.type.contents).toBe('');
|
|
38
|
+
expect(klass.background.color).toBe('#bdc0ba');
|
|
39
|
+
|
|
40
|
+
// バッジ無しなので幅 0(名称エリアがヘッダ全幅を使う)
|
|
41
|
+
klass.sizingType();
|
|
42
|
+
expect(klass.type.size.w).toBe(0);
|
|
43
|
+
|
|
44
|
+
// 通常種別のバッジ幅は従来どおり正
|
|
45
|
+
const resource = new Entity(entityData('RESOURCE'), null);
|
|
46
|
+
resource.sizingType();
|
|
47
|
+
expect(resource.type.size.w).toBeGreaterThan(0);
|
|
48
|
+
});
|
|
49
|
+
|
|
33
50
|
test('unknown entity type throws', () => {
|
|
34
51
|
expect(() => new Entity(entityData('UNKNOWN'), null)).toThrow();
|
|
35
52
|
});
|
|
@@ -0,0 +1,86 @@
|
|
|
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
|
+
relationships,
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
test('CLASS entity builds fine when it has no relationships', () => {
|
|
45
|
+
const rectum = new Rectum({});
|
|
46
|
+
|
|
47
|
+
expect(() => rectum.data(DATA([]))).not.toThrow();
|
|
48
|
+
expect(rectum.entities().ht[70000]).toBeDefined();
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
test('a parent → CLASS relationship is allowed (identifier master is shared)', () => {
|
|
52
|
+
const rectum = new Rectum({});
|
|
53
|
+
const parentLink = [{
|
|
54
|
+
id: 1, type: null,
|
|
55
|
+
from: { entity: 30000, cardinality: 1, optionality: 0, position: 270 },
|
|
56
|
+
to: { entity: 70000, cardinality: 1, optionality: 0, position: 90 },
|
|
57
|
+
details: [{ from: { id: 3000001 }, to: { id: 7000001 } }],
|
|
58
|
+
}];
|
|
59
|
+
|
|
60
|
+
expect(() => rectum.data(DATA(parentLink))).not.toThrow();
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
test('a CLASS relationship to a non-parent throws', () => {
|
|
64
|
+
// Attribute(30001) はクラスの個体指定子(Entity ID)を持たない = 親ではない
|
|
65
|
+
const bad = [{
|
|
66
|
+
id: 1, type: null,
|
|
67
|
+
from: { entity: 30001, cardinality: 1, optionality: 0, position: 270 },
|
|
68
|
+
to: { entity: 70000, cardinality: 1, optionality: 0, position: 90 },
|
|
69
|
+
details: [{ from: { id: 3000101 }, to: { id: 7000001 } }],
|
|
70
|
+
}];
|
|
71
|
+
|
|
72
|
+
expect(() => new Rectum({}).data(DATA(bad)))
|
|
73
|
+
.toThrow(/クラス\(CLASS\)は切り出し元\(親\)としか結線できません/);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
test('a CLASS-to-CLASS relationship throws', () => {
|
|
77
|
+
const bad = [{
|
|
78
|
+
id: 1, type: null,
|
|
79
|
+
from: { entity: 70000, cardinality: 1, optionality: 0, position: 270 },
|
|
80
|
+
to: { entity: 70001, cardinality: 1, optionality: 0, position: 90 },
|
|
81
|
+
details: [{ from: { id: 7000001 }, to: { id: 7000101 } }],
|
|
82
|
+
}];
|
|
83
|
+
|
|
84
|
+
expect(() => new Rectum({}).data(DATA(bad)))
|
|
85
|
+
.toThrow(/クラス\(CLASS\)同士は結線できません/);
|
|
86
|
+
});
|