@yanqirenshi/d3.ter 0.1.21 → 0.1.23

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 CHANGED
@@ -119,6 +119,12 @@ export interface TerRelationship {
119
119
  details?: TerRelationshipDetail[];
120
120
  /** サブセットへの結線に区分コード(= / ×)を表示する(任意) */
121
121
  subset?: TerSubset;
122
+ /**
123
+ * 対応表/対照表の垂下(任意)。結線の中点の○から垂下線で指定エンティティへ
124
+ * ぶら下げる(tm3-1 §2「対応表(onto-mapping)」の書き方)。指定できるのは
125
+ * 対応表(CORRESPONDENCE)/対照表(COMPARATIVE)のみ — それ以外は構築時に例外
126
+ */
127
+ mapping?: { entity: number | string };
122
128
  /** 結線の中点に表示するラベル(任意。subset 指定時は区分コードが優先され表示されない) */
123
129
  label?: string;
124
130
  description?: string;
package/dist/js/Entity.js CHANGED
@@ -263,7 +263,7 @@ var Entity = exports["default"] = /*#__PURE__*/function (_Atman) {
263
263
  case 'RESOURCE-SUBSET':
264
264
  return 'Rsc';
265
265
  case 'COMPARATIVE':
266
- return '対象';
266
+ return '対照';
267
267
  case 'CORRESPONDENCE':
268
268
  return '対応';
269
269
  case 'EVENT':
@@ -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 _this5 = this;
332
+ var _this7 = this;
250
333
  paths.attr('d', function (d) {
251
- return _this5.subsetPath(d);
334
+ return _this7.subsetPath(d);
252
335
  });
253
336
  labels.attr('x', function (d) {
254
- return _this5.subsetGeometry(d).px;
337
+ return _this7.subsetGeometry(d).px;
255
338
  }).attr('y', function (d) {
256
- return _this5.subsetGeometry(d).busY - 5;
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 _this6 = this;
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 !_this6.isSubset(d);
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 !_this6.isSubset(d) && d.label && d.label();
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);
@@ -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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yanqirenshi/d3.ter",
3
- "version": "0.1.21",
3
+ "version": "0.1.23",
4
4
  "author": "yanqirenshi@gmail.com",
5
5
  "license": "GPL-3.0-or-later",
6
6
  "description": "See `src/index.html`",
@@ -17,6 +17,13 @@ test('entity type marker and background color follow the entity type', () => {
17
17
  const event = new Entity(entityData('EVENT'), null);
18
18
  expect(event.type.contents).toBe('Evt');
19
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('対応');
20
27
  });
21
28
 
22
29
  // issue #14: TM(T字形ER)の多値。MO=多値のOR、MA=多値のAND(HDR-DTL)
@@ -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,