@yanqirenshi/d3.ter 0.1.24 → 0.1.25

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
@@ -133,7 +133,8 @@ export interface TerRelationship {
133
133
  subset?: TerSubset;
134
134
  /**
135
135
  * 対応表/対照表の垂下(任意)。結線の中点の○から垂下線で指定エンティティへ
136
- * ぶら下げる(tm3-1 §2「対応表(onto-mapping)」の書き方)。指定できるのは
136
+ * ぶら下げる(tm3-1 §2「対応表(onto-mapping)」の書き方)。線は表の最寄りの
137
+ * 辺(上下左右)の中央に取り付く(中点から見た方向で自動選択)。指定できるのは
137
138
  * 対応表(CORRESPONDENCE)/対照表(COMPARATIVE)のみ — それ以外は構築時に例外
138
139
  */
139
140
  mapping?: { entity: number | string };
@@ -151,8 +151,10 @@ var Relationships = exports["default"] = /*#__PURE__*/function () {
151
151
  /**
152
152
  * 対応表/対照表の垂下の幾何(tm3-1 §2「対応表(onto-mapping)」)。
153
153
  * 結線の中点(junction)に小さな○を置き、そこから対応表/対照表の
154
- * 上端中央(表が線より下にある場合。上なら下端中央)へ1本の線で
155
- * ぶら下げる。
154
+ * 最寄りの辺の中央へ1本の線でぶら下げる。
155
+ * 取り付く辺は中点から見た方向で自動選択する: 横方向のずれが支配的
156
+ * なら左辺/右辺の中央、縦方向が支配的なら上端/下端の中央。判定は
157
+ * 箱の縦横比で正規化する(横長の箱で不当に左右辺が選ばれないように)。
156
158
  */
157
159
  }, {
158
160
  key: "mappingGeometry",
@@ -162,8 +164,17 @@ var Relationships = exports["default"] = /*#__PURE__*/function () {
162
164
  var jx = (from.x + to.x) / 2;
163
165
  var jy = (from.y + to.y) / 2;
164
166
  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
+ var cx = m.position.x + m.size.w / 2;
168
+ var cy = m.position.y + m.size.h / 2;
169
+ var dx = jx - cx;
170
+ var dy = jy - cy;
171
+ var mx = cx;
172
+ var my = cy;
173
+ if (Math.abs(dx) * m.size.h > Math.abs(dy) * m.size.w) {
174
+ mx = dx < 0 ? m.position.x : m.position.x + m.size.w;
175
+ } else {
176
+ my = dy < 0 ? m.position.y : m.position.y + m.size.h;
177
+ }
167
178
  return {
168
179
  jx: jx,
169
180
  jy: jy,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yanqirenshi/d3.ter",
3
- "version": "0.1.24",
3
+ "version": "0.1.25",
4
4
  "author": "yanqirenshi@gmail.com",
5
5
  "license": "GPL-3.0-or-later",
6
6
  "description": "See `src/index.html`",
@@ -0,0 +1,45 @@
1
+ import Relationships from '../src/js/Painters/Relationships.js';
2
+
3
+ // 対応表/対照表の垂下(mapping)の取り付け辺。
4
+ // 結線の中点(○)から見て最寄りの辺の中央に接続する(上下だけでなく
5
+ // 左右の辺にも対応)。判定は箱の縦横比で正規化する。
6
+ describe('mappingGeometry: 垂下線は最寄りの辺の中央に取り付く', () => {
7
+ const painter = new Relationships(null);
8
+
9
+ // 結線: (100,100)-(300,100) → 中点(junction)は (200,100)
10
+ const rel = (mappingEntity) => ({
11
+ from: { position: () => ({ x: 0, y: 0 }), _owner: { position: { x: 100, y: 100 } } },
12
+ to: { position: () => ({ x: 0, y: 0 }), _owner: { position: { x: 300, y: 100 } } },
13
+ mapping: () => mappingEntity,
14
+ });
15
+
16
+ const box = (x, y) => ({ position: { x: x, y: y }, size: { w: 200, h: 100 } });
17
+
18
+ it('表が中点の下 → 上端中央(従来どおり)', () => {
19
+ const g = painter.mappingGeometry(rel(box(100, 400)));
20
+ expect(g).toEqual({ jx: 200, jy: 100, mx: 200, my: 400 });
21
+ });
22
+
23
+ it('表が中点の上 → 下端中央(従来どおり)', () => {
24
+ const g = painter.mappingGeometry(rel(box(100, -400)));
25
+ expect(g).toEqual({ jx: 200, jy: 100, mx: 200, my: -300 });
26
+ });
27
+
28
+ it('表が中点の右 → 左辺中央', () => {
29
+ const g = painter.mappingGeometry(rel(box(600, 50)));
30
+ expect(g).toEqual({ jx: 200, jy: 100, mx: 600, my: 100 });
31
+ });
32
+
33
+ it('表が中点の左 → 右辺中央', () => {
34
+ const g = painter.mappingGeometry(rel(box(-500, 50)));
35
+ expect(g).toEqual({ jx: 200, jy: 100, mx: -300, my: 100 });
36
+ });
37
+
38
+ it('斜め位置は箱の縦横比で正規化して支配的な方向の辺を選ぶ', () => {
39
+ // 中心からのずれ dx=250, dy=400。箱は横長(200×100)なので
40
+ // |dx|*h(25000) < |dy|*w(80000) → 縦方向が支配的 → 下端中央
41
+ const g = painter.mappingGeometry(rel(box(-150, -350)));
42
+ expect(g.mx).toBe(-50);
43
+ expect(g.my).toBe(-250);
44
+ });
45
+ });