@yanqirenshi/d3.ter 0.1.16 → 0.1.18

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.
@@ -0,0 +1,175 @@
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
+ /** TM(T字形ER)のエンティティ種別(9種)。これ以外の値は描画時に例外になる */
32
+ export type TerEntityType =
33
+ | 'RESOURCE'
34
+ | 'RESOURCE-SUBSET'
35
+ | 'EVENT'
36
+ | 'EVENT-SUBSET'
37
+ | 'COMPARATIVE'
38
+ | 'CORRESPONDENCE'
39
+ | 'RECURSION'
40
+ | 'MANY-VALUED-OR'
41
+ | 'MANY-VALUED-AND';
42
+
43
+ /** カーディナリティ(1 または 多=3) */
44
+ export type TerCardinality = 1 | 3;
45
+
46
+ /** オプショナリティ(0=必須, 1=任意) */
47
+ export type TerOptionality = 0 | 1;
48
+
49
+ /** エンティティが持つ識別子インスタンス(identifier はマスタの id を参照) */
50
+ export interface TerIdentifierInstance {
51
+ id: number | string;
52
+ identifier: number | string;
53
+ description?: string;
54
+ }
55
+
56
+ /** エンティティが持つ属性インスタンス(attribute はマスタの id を参照) */
57
+ export interface TerAttributeInstance {
58
+ id: number | string;
59
+ attribute: number | string;
60
+ description?: string;
61
+ }
62
+
63
+ /** エンティティ(テーブル) */
64
+ export interface TerEntity {
65
+ id: number | string;
66
+ type: TerEntityType;
67
+ name: string;
68
+ description?: string;
69
+ position: { x: number; y: number; z?: number };
70
+ /** w/h に 0 を渡すと内容に自動フィットする */
71
+ size: { w: number; h: number };
72
+ identifiers: TerIdentifierInstance[];
73
+ attributes: TerAttributeInstance[];
74
+ }
75
+
76
+ /** リレーションシップの端点 */
77
+ export interface TerRelationshipEnd {
78
+ /** 接続先エンティティの id */
79
+ entity: number | string;
80
+ cardinality: TerCardinality;
81
+ optionality: TerOptionality;
82
+ /** ポートの取り付け角度(ノード中心から見て 0=真下・時計回り。90=左, 180=真上, 270=右) */
83
+ position?: number;
84
+ }
85
+
86
+ /** ポートの取付カラム(from/to とも識別子・属性インスタンスの id を参照) */
87
+ export interface TerRelationshipDetail {
88
+ from: { id: number | string; description?: string };
89
+ to: { id: number | string; description?: string };
90
+ }
91
+
92
+ /** エンティティ間のリレーションシップ */
93
+ export interface TerRelationship {
94
+ id: number | string;
95
+ type?: string | null;
96
+ from: TerRelationshipEnd;
97
+ to: TerRelationshipEnd;
98
+ /** 省略時は先頭の識別子インスタンスに取り付く */
99
+ details?: TerRelationshipDetail[];
100
+ description?: string;
101
+ }
102
+
103
+ /** data() に渡すデータ一式 */
104
+ export interface TerData {
105
+ identifiers: TerIdentifier[];
106
+ attributes: TerAttribute[];
107
+ entities: TerEntity[];
108
+ relationships: TerRelationship[];
109
+ }
110
+
111
+ /* **************************************************************** *
112
+ * Rectum / D3Ter
113
+ * **************************************************************** */
114
+
115
+ /**
116
+ * クリック通知などで渡される正規化済みエンティティ。
117
+ * _core に入力(TerEntity)がそのまま入る。内部レイアウト系のフィールドは省略。
118
+ */
119
+ export interface TerEntityDatum {
120
+ _id: number | string;
121
+ _core: TerEntity;
122
+ position: { x: number; y: number; z?: number };
123
+ size: { w: number; h: number };
124
+ [key: string]: unknown;
125
+ }
126
+
127
+ export interface TerCallbacks {
128
+ entity?: {
129
+ /** エンティティのクリック通知(正規化済みデータが渡される) */
130
+ click?: ((entity: TerEntityDatum) => void) | null;
131
+ };
132
+ }
133
+
134
+ /** Rectum のコンストラクタ引数(共通基盤 Colon の描画設定 + コールバック) */
135
+ export interface RectumParams {
136
+ /** ズーム初期値 */
137
+ transform?: { k?: number; x?: number; y?: number };
138
+ /** 背景グリッド */
139
+ grid?: { draw?: boolean; size?: number; span?: number };
140
+ svg?: { style?: { background?: string } };
141
+ callbacks?: TerCallbacks;
142
+ /** その他の Colon パラメータ(camera / layers 等) */
143
+ [key: string]: unknown;
144
+ }
145
+
146
+ /**
147
+ * ER 図(TER)の総括クラス。データ構築・レイアウト計算を行い、描画はペインタへ委譲する。
148
+ * (型を付けているのは利用側が触る代表的なメンバーのみ。内部 API は含めない)
149
+ */
150
+ export class Rectum {
151
+ constructor(params?: RectumParams);
152
+
153
+ /** ter 形式のデータを構築する。引数なしの場合は現在の内部データを返す */
154
+ data(data: TerData): unknown;
155
+ data(): unknown;
156
+
157
+ /** 描画先の SVG 要素(セレクタ文字列 or 要素)を設定する */
158
+ selector(v: string | Element): unknown;
159
+
160
+ /** SVG のピクセルサイズ */
161
+ bounds(v?: { w: number; h: number }): unknown;
162
+
163
+ /** 正規化済みエンティティのプール({ list, ht }) */
164
+ entities(): { list: TerEntityDatum[]; ht: Record<string | number, TerEntityDatum> };
165
+ }
166
+
167
+ export interface D3TerProps {
168
+ rectum: Rectum;
169
+ /** SVG コンテナの DOM id(既定 "d3-ter-graph") */
170
+ id?: string;
171
+ }
172
+
173
+ /** React ラッパコンポーネント */
174
+ declare const D3Ter: ComponentType<D3TerProps>;
175
+ export default D3Ter;
package/dist/js/Entity.js CHANGED
@@ -272,6 +272,11 @@ var Entity = exports["default"] = /*#__PURE__*/function (_Atman) {
272
272
  return 'Evt';
273
273
  case 'RECURSION':
274
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';
275
280
  default:
276
281
  throw new Error(type + " は知らないよ。");
277
282
  }
@@ -303,6 +308,12 @@ var Entity = exports["default"] = /*#__PURE__*/function (_Atman) {
303
308
  },
304
309
  "recursion": {
305
310
  color: '#dbd0e6'
311
+ },
312
+ "many-valued-or": {
313
+ color: '#fddea5'
314
+ },
315
+ "many-valued-and": {
316
+ color: '#9fd5c9'
306
317
  }
307
318
  };
308
319
  var key = this._core.type.toLowerCase();
@@ -465,7 +476,15 @@ var Entity = exports["default"] = /*#__PURE__*/function (_Atman) {
465
476
  var data = this.type;
466
477
  if (!data.contents) data.contents = '??';
467
478
  data.size.h = this._default.line.height + data.padding * 2;
468
- data.size.w = this.strLen(data.contents) * this._default.line.font.size;
479
+
480
+ // 幅 = テキストの概算幅 + 両側の padding。
481
+ // ラベルは box 左端から padding 分内側に描かれるため、旧実装
482
+ // (strLen × フォントサイズのみ)では右側の余白が無く、MO / MA の
483
+ // ような幅広の半角グリフがはみ出ていた。バッジは英大文字か漢字の
484
+ // 2〜3文字なので、1文字 = 1em で概算すれば確実に収まる。
485
+ var font = this._default.line.font.size;
486
+ var chars = Array.from(String(data.contents)).length;
487
+ data.size.w = chars * font + data.padding * 2;
469
488
  }
470
489
  }, {
471
490
  key: "sizing",
package/package.json CHANGED
@@ -1,10 +1,11 @@
1
1
  {
2
2
  "name": "@yanqirenshi/d3.ter",
3
- "version": "0.1.16",
3
+ "version": "0.1.18",
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"
@@ -19,6 +19,17 @@ test('entity type marker and background color follow the entity type', () => {
19
19
  expect(event.background.color).toBe('#f09199');
20
20
  });
21
21
 
22
+ // issue #14: TM(T字形ER)の多値。MO=多値のOR、MA=多値のAND(HDR-DTL)
23
+ test('many-valued types render MO / MA badges with their own colors', () => {
24
+ const mo = new Entity(entityData('MANY-VALUED-OR'), null);
25
+ expect(mo.type.contents).toBe('MO');
26
+ expect(mo.background.color).toBe('#fddea5');
27
+
28
+ const ma = new Entity(entityData('MANY-VALUED-AND'), null);
29
+ expect(ma.type.contents).toBe('MA');
30
+ expect(ma.background.color).toBe('#9fd5c9');
31
+ });
32
+
22
33
  test('unknown entity type throws', () => {
23
34
  expect(() => new Entity(entityData('UNKNOWN'), null)).toThrow();
24
35
  });