@yanqirenshi/d3.ter 0.1.20 → 0.1.21
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 +2 -0
- package/dist/js/Painters/Relationships.js +47 -6
- package/dist/js/Relationship.js +12 -6
- package/package.json +1 -1
- package/tests/Rectum.test.js +11 -0
package/dist/index.d.ts
CHANGED
|
@@ -119,6 +119,8 @@ export interface TerRelationship {
|
|
|
119
119
|
details?: TerRelationshipDetail[];
|
|
120
120
|
/** サブセットへの結線に区分コード(= / ×)を表示する(任意) */
|
|
121
121
|
subset?: TerSubset;
|
|
122
|
+
/** 結線の中点に表示するラベル(任意。subset 指定時は区分コードが優先され表示されない) */
|
|
123
|
+
label?: string;
|
|
122
124
|
description?: string;
|
|
123
125
|
}
|
|
124
126
|
|
|
@@ -103,6 +103,39 @@ var Relationships = exports["default"] = /*#__PURE__*/function () {
|
|
|
103
103
|
});
|
|
104
104
|
this._lines.draw(place, plain);
|
|
105
105
|
this.drawSubsetTrees(place, data);
|
|
106
|
+
this.drawLabels(place, data);
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* 結線のラベル(relationship.label)を線の中点の少し上に描く。
|
|
110
|
+
* enter/update join で冪等。サブセット結線は区分コード(=/×)を
|
|
111
|
+
* 分岐点に描くため対象外。
|
|
112
|
+
*/
|
|
113
|
+
}, {
|
|
114
|
+
key: "drawLabels",
|
|
115
|
+
value: function drawLabels(place, data) {
|
|
116
|
+
var _this3 = this;
|
|
117
|
+
var targets = data.filter(function (d) {
|
|
118
|
+
return !_this3.isSubset(d) && d.label && d.label();
|
|
119
|
+
});
|
|
120
|
+
var texts = place.selectAll('text.relationship-label').data(targets, function (d) {
|
|
121
|
+
return d._id;
|
|
122
|
+
});
|
|
123
|
+
texts.exit().remove();
|
|
124
|
+
var entered = texts.enter().append('text').attr('class', 'relationship-label').attr('text-anchor', 'middle').attr('font-size', '12px').attr('fill', '#333333');
|
|
125
|
+
this.applyLabels(entered.merge(texts));
|
|
126
|
+
}
|
|
127
|
+
/** ラベルの位置(線の中点の少し上)とテキストを適用する。 */
|
|
128
|
+
}, {
|
|
129
|
+
key: "applyLabels",
|
|
130
|
+
value: function applyLabels(selection) {
|
|
131
|
+
var _this4 = this;
|
|
132
|
+
selection.attr('x', function (d) {
|
|
133
|
+
return (_this4.fromPoint(d).x + _this4.toPoint(d).x) / 2;
|
|
134
|
+
}).attr('y', function (d) {
|
|
135
|
+
return (_this4.fromPoint(d).y + _this4.toPoint(d).y) / 2 - 6;
|
|
136
|
+
}).text(function (d) {
|
|
137
|
+
return d.label();
|
|
138
|
+
});
|
|
106
139
|
}
|
|
107
140
|
}, {
|
|
108
141
|
key: "isSubset",
|
|
@@ -213,14 +246,14 @@ var Relationships = exports["default"] = /*#__PURE__*/function () {
|
|
|
213
246
|
}, {
|
|
214
247
|
key: "applySubsetTrees",
|
|
215
248
|
value: function applySubsetTrees(paths, labels) {
|
|
216
|
-
var
|
|
249
|
+
var _this5 = this;
|
|
217
250
|
paths.attr('d', function (d) {
|
|
218
|
-
return
|
|
251
|
+
return _this5.subsetPath(d);
|
|
219
252
|
});
|
|
220
253
|
labels.attr('x', function (d) {
|
|
221
|
-
return
|
|
254
|
+
return _this5.subsetGeometry(d).px;
|
|
222
255
|
}).attr('y', function (d) {
|
|
223
|
-
return
|
|
256
|
+
return _this5.subsetGeometry(d).busY - 5;
|
|
224
257
|
}).text(function (d) {
|
|
225
258
|
return d.label;
|
|
226
259
|
});
|
|
@@ -238,17 +271,25 @@ var Relationships = exports["default"] = /*#__PURE__*/function () {
|
|
|
238
271
|
}, {
|
|
239
272
|
key: "redrawEntityEdges",
|
|
240
273
|
value: function redrawEntityEdges(place, entity) {
|
|
241
|
-
var
|
|
274
|
+
var _this6 = this;
|
|
242
275
|
var edges = entity.ports.items.list.map(function (p) {
|
|
243
276
|
return p._relationship;
|
|
244
277
|
});
|
|
245
278
|
var selection = place.selectAll('line.connector').data(edges.filter(function (d) {
|
|
246
|
-
return !
|
|
279
|
+
return !_this6.isSubset(d);
|
|
247
280
|
}), function (d) {
|
|
248
281
|
return d._id;
|
|
249
282
|
});
|
|
250
283
|
this._lines.update(selection);
|
|
251
284
|
|
|
285
|
+
// ラベルも追従させる
|
|
286
|
+
var labels = place.selectAll('text.relationship-label').data(edges.filter(function (d) {
|
|
287
|
+
return !_this6.isSubset(d) && d.label && d.label();
|
|
288
|
+
}), function (d) {
|
|
289
|
+
return d._id;
|
|
290
|
+
});
|
|
291
|
+
this.applyLabels(labels);
|
|
292
|
+
|
|
252
293
|
// サブセットの分岐線・区分コードも追従させる
|
|
253
294
|
this.updateSubsetTrees(place);
|
|
254
295
|
}
|
package/dist/js/Relationship.js
CHANGED
|
@@ -30,14 +30,20 @@ var Relationship = exports["default"] = /*#__PURE__*/function (_Atman) {
|
|
|
30
30
|
port_to._relationship = _this;
|
|
31
31
|
return _this;
|
|
32
32
|
}
|
|
33
|
-
/**
|
|
34
|
-
* TM のサブセット結線に添える区分コードの表記。
|
|
35
|
-
* =区分コード … 同一のサブセット(kind: 'same')
|
|
36
|
-
* ×区分コード … 相違のサブセット(kind: 'different'。'same' 以外は×扱い)
|
|
37
|
-
* 入力の relationship.subset = { kind, code }。無ければ null(表示なし)。
|
|
38
|
-
*/
|
|
33
|
+
/** 結線に表示するラベル(入力の relationship.label。無ければ null = 表示なし) */
|
|
39
34
|
_inherits(Relationship, _Atman);
|
|
40
35
|
return _createClass(Relationship, [{
|
|
36
|
+
key: "label",
|
|
37
|
+
value: function label() {
|
|
38
|
+
return this._core.label || null;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* TM のサブセット結線に添える区分コードの表記。
|
|
42
|
+
* =区分コード … 同一のサブセット(kind: 'same')
|
|
43
|
+
* ×区分コード … 相違のサブセット(kind: 'different'。'same' 以外は×扱い)
|
|
44
|
+
* 入力の relationship.subset = { kind, code }。無ければ null(表示なし)。
|
|
45
|
+
*/
|
|
46
|
+
}, {
|
|
41
47
|
key: "subsetLabel",
|
|
42
48
|
value: function subsetLabel() {
|
|
43
49
|
var subset = this._core.subset;
|
package/package.json
CHANGED
package/tests/Rectum.test.js
CHANGED
|
@@ -97,12 +97,23 @@ test('subsetLabel composes = / × with the code (default: different)', () => {
|
|
|
97
97
|
to: { entity: 30001, cardinality: 1, optionality: 0, position: 45 },
|
|
98
98
|
details: [{ from: { id: 3000001 }, to: { id: 3000101 } }],
|
|
99
99
|
},
|
|
100
|
+
{
|
|
101
|
+
id: 4, type: null,
|
|
102
|
+
from: { entity: 30000, cardinality: 1, optionality: 0, position: 90 },
|
|
103
|
+
to: { entity: 30001, cardinality: 1, optionality: 0, position: 270 },
|
|
104
|
+
details: [{ from: { id: 3000001 }, to: { id: 3000101 } }],
|
|
105
|
+
label: 'defines',
|
|
106
|
+
},
|
|
100
107
|
]));
|
|
101
108
|
|
|
102
109
|
const rels = rectum._relationships.ht;
|
|
103
110
|
expect(rels[1].subsetLabel()).toBe('×状態区分');
|
|
104
111
|
expect(rels[2].subsetLabel()).toBe('=行種別');
|
|
105
112
|
expect(rels[3].subsetLabel()).toBeNull(); // subset 無し → 表示なし
|
|
113
|
+
|
|
114
|
+
// issue #16: 汎用ラベル(relationship.label)
|
|
115
|
+
expect(rels[3].label()).toBeNull(); // label 無し → 表示なし
|
|
116
|
+
expect(rels[4].label()).toBe('defines'); // 指定があればそのまま
|
|
106
117
|
});
|
|
107
118
|
|
|
108
119
|
test('a CLASS-to-CLASS relationship throws', () => {
|