@yanqirenshi/d3.ter 0.1.22 → 0.1.24
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 +20 -2
- package/dist/js/Painters/Relationships.js +93 -7
- package/dist/js/Rectum.js +19 -0
- package/dist/js/Relationship.js +11 -0
- package/package.json +1 -1
- package/tests/Rectum.test.js +59 -0
package/dist/index.d.ts
CHANGED
|
@@ -51,13 +51,22 @@ export type TerEntityType =
|
|
|
51
51
|
/** カーディナリティ(1 または 多=3) */
|
|
52
52
|
export type TerCardinality = 1 | 3;
|
|
53
53
|
|
|
54
|
-
/**
|
|
54
|
+
/**
|
|
55
|
+
* オプショナリティ(0=任意(○), 1=必須(横棒))。
|
|
56
|
+
* 0 は端点に○(0個もありうる)、1 は横棒(必ず1個以上)を描く。
|
|
57
|
+
*/
|
|
55
58
|
export type TerOptionality = 0 | 1;
|
|
56
59
|
|
|
57
60
|
/** エンティティが持つ識別子インスタンス(identifier はマスタの id を参照) */
|
|
58
61
|
export interface TerIdentifierInstance {
|
|
59
62
|
id: number | string;
|
|
60
63
|
identifier: number | string;
|
|
64
|
+
/**
|
|
65
|
+
* 表示名の上書き(任意。省略時はマスタの name)。
|
|
66
|
+
* TM の (R) 表記 — 継承した個体指定子だけ「〜(R)」と表示する — を
|
|
67
|
+
* マスタを重複させずに実現できる
|
|
68
|
+
*/
|
|
69
|
+
name?: TerName;
|
|
61
70
|
description?: string;
|
|
62
71
|
}
|
|
63
72
|
|
|
@@ -65,6 +74,8 @@ export interface TerIdentifierInstance {
|
|
|
65
74
|
export interface TerAttributeInstance {
|
|
66
75
|
id: number | string;
|
|
67
76
|
attribute: number | string;
|
|
77
|
+
/** 表示名の上書き(任意。省略時はマスタの name) */
|
|
78
|
+
name?: TerName;
|
|
68
79
|
description?: string;
|
|
69
80
|
}
|
|
70
81
|
|
|
@@ -72,7 +83,8 @@ export interface TerAttributeInstance {
|
|
|
72
83
|
export interface TerEntity {
|
|
73
84
|
id: number | string;
|
|
74
85
|
type: TerEntityType;
|
|
75
|
-
|
|
86
|
+
/** 文字列、または物理名/論理名のペア(識別子・属性のマスタと同じ形) */
|
|
87
|
+
name: string | TerName;
|
|
76
88
|
description?: string;
|
|
77
89
|
position: { x: number; y: number; z?: number };
|
|
78
90
|
/** w/h に 0 を渡すと内容に自動フィットする */
|
|
@@ -119,6 +131,12 @@ export interface TerRelationship {
|
|
|
119
131
|
details?: TerRelationshipDetail[];
|
|
120
132
|
/** サブセットへの結線に区分コード(= / ×)を表示する(任意) */
|
|
121
133
|
subset?: TerSubset;
|
|
134
|
+
/**
|
|
135
|
+
* 対応表/対照表の垂下(任意)。結線の中点の○から垂下線で指定エンティティへ
|
|
136
|
+
* ぶら下げる(tm3-1 §2「対応表(onto-mapping)」の書き方)。指定できるのは
|
|
137
|
+
* 対応表(CORRESPONDENCE)/対照表(COMPARATIVE)のみ — それ以外は構築時に例外
|
|
138
|
+
*/
|
|
139
|
+
mapping?: { entity: number | string };
|
|
122
140
|
/** 結線の中点に表示するラベル(任意。subset 指定時は区分コードが優先され表示されない) */
|
|
123
141
|
label?: string;
|
|
124
142
|
description?: string;
|
|
@@ -103,6 +103,7 @@ var Relationships = exports["default"] = /*#__PURE__*/function () {
|
|
|
103
103
|
});
|
|
104
104
|
this._lines.draw(place, plain);
|
|
105
105
|
this.drawSubsetTrees(place, data);
|
|
106
|
+
this.drawMappingDrops(place, data);
|
|
106
107
|
this.drawLabels(place, data);
|
|
107
108
|
}
|
|
108
109
|
/**
|
|
@@ -142,6 +143,88 @@ var Relationships = exports["default"] = /*#__PURE__*/function () {
|
|
|
142
143
|
value: function isSubset(d) {
|
|
143
144
|
return !!(d.subsetLabel && d.subsetLabel());
|
|
144
145
|
}
|
|
146
|
+
}, {
|
|
147
|
+
key: "hasMapping",
|
|
148
|
+
value: function hasMapping(d) {
|
|
149
|
+
return !!(d.mapping && d.mapping());
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* 対応表/対照表の垂下の幾何(tm3-1 §2「対応表(onto-mapping)」)。
|
|
153
|
+
* 結線の中点(junction)に小さな○を置き、そこから対応表/対照表の
|
|
154
|
+
* 上端中央(表が線より下にある場合。上なら下端中央)へ1本の線で
|
|
155
|
+
* ぶら下げる。
|
|
156
|
+
*/
|
|
157
|
+
}, {
|
|
158
|
+
key: "mappingGeometry",
|
|
159
|
+
value: function mappingGeometry(d) {
|
|
160
|
+
var from = this.fromPoint(d);
|
|
161
|
+
var to = this.toPoint(d);
|
|
162
|
+
var jx = (from.x + to.x) / 2;
|
|
163
|
+
var jy = (from.y + to.y) / 2;
|
|
164
|
+
var m = d.mapping();
|
|
165
|
+
var mx = m.position.x + m.size.w / 2;
|
|
166
|
+
var my = jy < m.position.y + m.size.h / 2 ? m.position.y : m.position.y + m.size.h;
|
|
167
|
+
return {
|
|
168
|
+
jx: jx,
|
|
169
|
+
jy: jy,
|
|
170
|
+
mx: mx,
|
|
171
|
+
my: my
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* 対応表/対照表の垂下(中点の○ + 表への線)を描く。
|
|
176
|
+
* enter/update join で冪等。
|
|
177
|
+
*/
|
|
178
|
+
}, {
|
|
179
|
+
key: "drawMappingDrops",
|
|
180
|
+
value: function drawMappingDrops(place, data) {
|
|
181
|
+
var _this5 = this;
|
|
182
|
+
this._mappingTargets = data.filter(function (d) {
|
|
183
|
+
return _this5.hasMapping(d);
|
|
184
|
+
});
|
|
185
|
+
var lines = place.selectAll('line.mapping-drop').data(this._mappingTargets, function (d) {
|
|
186
|
+
return d._id;
|
|
187
|
+
});
|
|
188
|
+
lines.exit().remove();
|
|
189
|
+
var entered_lines = lines.enter().append('line').attr('class', 'mapping-drop').attr('stroke', '#888888').attr('stroke-width', 1);
|
|
190
|
+
var circles = place.selectAll('circle.mapping-junction').data(this._mappingTargets, function (d) {
|
|
191
|
+
return d._id;
|
|
192
|
+
});
|
|
193
|
+
circles.exit().remove();
|
|
194
|
+
var entered_circles = circles.enter().append('circle').attr('class', 'mapping-junction').attr('r', 5).attr('fill', '#fefefe').attr('stroke', '#888888').attr('stroke-width', 1);
|
|
195
|
+
this.applyMappingDrops(entered_lines.merge(lines), entered_circles.merge(circles));
|
|
196
|
+
}
|
|
197
|
+
/** 垂下線の両端と中点の○の位置を適用する。 */
|
|
198
|
+
}, {
|
|
199
|
+
key: "applyMappingDrops",
|
|
200
|
+
value: function applyMappingDrops(lines, circles) {
|
|
201
|
+
var _this6 = this;
|
|
202
|
+
lines.attr('x1', function (d) {
|
|
203
|
+
return _this6.mappingGeometry(d).jx;
|
|
204
|
+
}).attr('y1', function (d) {
|
|
205
|
+
return _this6.mappingGeometry(d).jy;
|
|
206
|
+
}).attr('x2', function (d) {
|
|
207
|
+
return _this6.mappingGeometry(d).mx;
|
|
208
|
+
}).attr('y2', function (d) {
|
|
209
|
+
return _this6.mappingGeometry(d).my;
|
|
210
|
+
});
|
|
211
|
+
circles.attr('cx', function (d) {
|
|
212
|
+
return _this6.mappingGeometry(d).jx;
|
|
213
|
+
}).attr('cy', function (d) {
|
|
214
|
+
return _this6.mappingGeometry(d).jy;
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* ドラッグ追従: 垂下線・中点の○全体に現在のエンティティ位置を
|
|
219
|
+
* 再適用する。対応表/対照表自体はポートを持たないため、
|
|
220
|
+
* どのエンティティの移動でも全体を更新する(件数は少ない)。
|
|
221
|
+
*/
|
|
222
|
+
}, {
|
|
223
|
+
key: "updateMappingDrops",
|
|
224
|
+
value: function updateMappingDrops(place) {
|
|
225
|
+
if (!this._mappingTargets || this._mappingTargets.length === 0) return;
|
|
226
|
+
this.applyMappingDrops(place.selectAll('line.mapping-drop'), place.selectAll('circle.mapping-junction'));
|
|
227
|
+
}
|
|
145
228
|
/**
|
|
146
229
|
* サブセット結線のグループ化。同じ親エンティティ + 同じ区分コードの
|
|
147
230
|
* relationship を1つの分岐(幹 + バス + 垂下)として扱う。
|
|
@@ -246,14 +329,14 @@ var Relationships = exports["default"] = /*#__PURE__*/function () {
|
|
|
246
329
|
}, {
|
|
247
330
|
key: "applySubsetTrees",
|
|
248
331
|
value: function applySubsetTrees(paths, labels) {
|
|
249
|
-
var
|
|
332
|
+
var _this7 = this;
|
|
250
333
|
paths.attr('d', function (d) {
|
|
251
|
-
return
|
|
334
|
+
return _this7.subsetPath(d);
|
|
252
335
|
});
|
|
253
336
|
labels.attr('x', function (d) {
|
|
254
|
-
return
|
|
337
|
+
return _this7.subsetGeometry(d).px;
|
|
255
338
|
}).attr('y', function (d) {
|
|
256
|
-
return
|
|
339
|
+
return _this7.subsetGeometry(d).busY - 5;
|
|
257
340
|
}).text(function (d) {
|
|
258
341
|
return d.label;
|
|
259
342
|
});
|
|
@@ -271,12 +354,12 @@ var Relationships = exports["default"] = /*#__PURE__*/function () {
|
|
|
271
354
|
}, {
|
|
272
355
|
key: "redrawEntityEdges",
|
|
273
356
|
value: function redrawEntityEdges(place, entity) {
|
|
274
|
-
var
|
|
357
|
+
var _this8 = this;
|
|
275
358
|
var edges = entity.ports.items.list.map(function (p) {
|
|
276
359
|
return p._relationship;
|
|
277
360
|
});
|
|
278
361
|
var selection = place.selectAll('line.connector').data(edges.filter(function (d) {
|
|
279
|
-
return !
|
|
362
|
+
return !_this8.isSubset(d);
|
|
280
363
|
}), function (d) {
|
|
281
364
|
return d._id;
|
|
282
365
|
});
|
|
@@ -284,7 +367,7 @@ var Relationships = exports["default"] = /*#__PURE__*/function () {
|
|
|
284
367
|
|
|
285
368
|
// ラベルも追従させる
|
|
286
369
|
var labels = place.selectAll('text.relationship-label').data(edges.filter(function (d) {
|
|
287
|
-
return !
|
|
370
|
+
return !_this8.isSubset(d) && d.label && d.label();
|
|
288
371
|
}), function (d) {
|
|
289
372
|
return d._id;
|
|
290
373
|
});
|
|
@@ -292,6 +375,9 @@ var Relationships = exports["default"] = /*#__PURE__*/function () {
|
|
|
292
375
|
|
|
293
376
|
// サブセットの分岐線・区分コードも追従させる
|
|
294
377
|
this.updateSubsetTrees(place);
|
|
378
|
+
|
|
379
|
+
// 対応表/対照表の垂下(中点の○ + 表への線)も追従させる
|
|
380
|
+
this.updateMappingDrops(place);
|
|
295
381
|
}
|
|
296
382
|
}]);
|
|
297
383
|
}();
|
package/dist/js/Rectum.js
CHANGED
|
@@ -115,6 +115,22 @@ var Rectum = exports["default"] = /*#__PURE__*/function (_Colon) {
|
|
|
115
115
|
});
|
|
116
116
|
if (!is_parent) throw new Error('クラス(CLASS)は切り出し元(親)としか結線できません。' + 'relationship id=' + r.id + ', entity id=' + other._id);
|
|
117
117
|
}
|
|
118
|
+
/**
|
|
119
|
+
* 対応表/対照表(mapping)の解決と検証。
|
|
120
|
+
* relationship.mapping = { entity: id } は、この結線の中点(○)から
|
|
121
|
+
* 垂下線でぶら下げる対応表(CORRESPONDENCE)/対照表(COMPARATIVE)を指す
|
|
122
|
+
* (参照 tm3-1 §2「対応表(onto-mapping)」の書き方)。
|
|
123
|
+
*/
|
|
124
|
+
}, {
|
|
125
|
+
key: "resolveMapping",
|
|
126
|
+
value: function resolveMapping(r) {
|
|
127
|
+
if (!r.mapping) return null;
|
|
128
|
+
var entity = this.getEntity(r.mapping.entity);
|
|
129
|
+
if (!entity) throw new Error('mapping に指定されたエンティティが見つかりません。' + 'relationship id=' + r.id + ', entity id=' + r.mapping.entity);
|
|
130
|
+
var type = entity._core.type;
|
|
131
|
+
if (type !== 'CORRESPONDENCE' && type !== 'COMPARATIVE') throw new Error('mapping に指定できるのは対応表(CORRESPONDENCE)か' + '対照表(COMPARATIVE)だけです。' + 'relationship id=' + r.id + ', entity id=' + entity._id + ', type=' + type);
|
|
132
|
+
return entity;
|
|
133
|
+
}
|
|
118
134
|
}, {
|
|
119
135
|
key: "buildRelationshipsWithPort",
|
|
120
136
|
value: function buildRelationshipsWithPort(relationships) {
|
|
@@ -139,6 +155,9 @@ var Rectum = exports["default"] = /*#__PURE__*/function (_Colon) {
|
|
|
139
155
|
// Relationship のクラスインスタンスを作成する。
|
|
140
156
|
var element = new _Relationship["default"](r, port_from, port_to, _this2);
|
|
141
157
|
|
|
158
|
+
// 対応表/対照表の垂下(mapping)を解決する(不正なら例外)。
|
|
159
|
+
element._mapping = _this2.resolveMapping(r);
|
|
160
|
+
|
|
142
161
|
// entity(from) に port をセットする。
|
|
143
162
|
// entity_from.ports.items.ht[port_from._id] = port_from;
|
|
144
163
|
// entity_from.ports.items.list.push(port_from);
|
package/dist/js/Relationship.js
CHANGED
|
@@ -50,5 +50,16 @@ 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(垂下なし)。
|
|
58
|
+
*/
|
|
59
|
+
}, {
|
|
60
|
+
key: "mapping",
|
|
61
|
+
value: function mapping() {
|
|
62
|
+
return this._mapping || null;
|
|
63
|
+
}
|
|
53
64
|
}]);
|
|
54
65
|
}(_Atman2["default"]);
|
package/package.json
CHANGED
package/tests/Rectum.test.js
CHANGED
|
@@ -37,6 +37,15 @@ const DATA = (relationships) => ({
|
|
|
37
37
|
identifiers: [{ id: 7000101, identifier: 10000 }],
|
|
38
38
|
attributes: [{ id: 7000110, attribute: 20000 }],
|
|
39
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
|
+
},
|
|
40
49
|
],
|
|
41
50
|
relationships,
|
|
42
51
|
});
|
|
@@ -116,6 +125,56 @@ test('subsetLabel composes = / × with the code (default: different)', () => {
|
|
|
116
125
|
expect(rels[4].label()).toBe('defines'); // 指定があればそのまま
|
|
117
126
|
});
|
|
118
127
|
|
|
128
|
+
// 対応表/対照表の垂下(relationship.mapping)。
|
|
129
|
+
// tm3-1 §2「対応表(onto-mapping)」: 2エンティティ間の結線の中点(○)から
|
|
130
|
+
// 垂下線で対応表/対照表をぶら下げる。
|
|
131
|
+
test('mapping resolves the correspondence entity hung from the line', () => {
|
|
132
|
+
const rectum = new Rectum({});
|
|
133
|
+
rectum.data(DATA([{
|
|
134
|
+
id: 1, type: null,
|
|
135
|
+
from: { entity: 30000, cardinality: 3, optionality: 1, position: 270 },
|
|
136
|
+
to: { entity: 30001, cardinality: 1, optionality: 1, position: 90 },
|
|
137
|
+
details: [{ from: { id: 3000001 }, to: { id: 3000101 } }],
|
|
138
|
+
mapping: { entity: 80000 },
|
|
139
|
+
}, {
|
|
140
|
+
id: 2, type: null,
|
|
141
|
+
from: { entity: 30000, cardinality: 1, optionality: 0, position: 0 },
|
|
142
|
+
to: { entity: 30001, cardinality: 1, optionality: 0, position: 180 },
|
|
143
|
+
details: [{ from: { id: 3000001 }, to: { id: 3000101 } }],
|
|
144
|
+
}]));
|
|
145
|
+
|
|
146
|
+
const rels = rectum._relationships.ht;
|
|
147
|
+
expect(rels[1].mapping()).toBe(rectum.entities().ht[80000]);
|
|
148
|
+
expect(rels[2].mapping()).toBeNull(); // mapping 無し → 垂下なし
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
test('mapping to a non-correspondence/comparative entity throws', () => {
|
|
152
|
+
// RESOURCE(30001) は対応表/対照表ではない
|
|
153
|
+
const bad = [{
|
|
154
|
+
id: 1, type: null,
|
|
155
|
+
from: { entity: 30000, cardinality: 1, optionality: 0, position: 270 },
|
|
156
|
+
to: { entity: 70000, cardinality: 1, optionality: 0, position: 90 },
|
|
157
|
+
details: [{ from: { id: 3000001 }, to: { id: 7000001 } }],
|
|
158
|
+
mapping: { entity: 30001 },
|
|
159
|
+
}];
|
|
160
|
+
|
|
161
|
+
expect(() => new Rectum({}).data(DATA(bad)))
|
|
162
|
+
.toThrow(/対応表\(CORRESPONDENCE\)か対照表\(COMPARATIVE\)だけ/);
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
test('mapping to a missing entity throws', () => {
|
|
166
|
+
const bad = [{
|
|
167
|
+
id: 1, type: null,
|
|
168
|
+
from: { entity: 30000, cardinality: 1, optionality: 0, position: 270 },
|
|
169
|
+
to: { entity: 30001, cardinality: 1, optionality: 0, position: 90 },
|
|
170
|
+
details: [{ from: { id: 3000001 }, to: { id: 3000101 } }],
|
|
171
|
+
mapping: { entity: 99999 },
|
|
172
|
+
}];
|
|
173
|
+
|
|
174
|
+
expect(() => new Rectum({}).data(DATA(bad)))
|
|
175
|
+
.toThrow(/mapping に指定されたエンティティが見つかりません/);
|
|
176
|
+
});
|
|
177
|
+
|
|
119
178
|
test('a CLASS-to-CLASS relationship throws', () => {
|
|
120
179
|
const bad = [{
|
|
121
180
|
id: 1, type: null,
|