@yanqirenshi/d3.ter 0.1.24 → 0.1.26
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
|
@@ -8,11 +8,12 @@ import type { ComponentType } from 'react';
|
|
|
8
8
|
* 入力データ(data() に渡す構造)
|
|
9
9
|
* **************************************************************** */
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
11
|
+
// 名称ペアは共有型パッケージ(@yanqirenshi/types)に一本化した。
|
|
12
|
+
// 公開 API 名(TerName)はエイリアスで維持する(description? が増えるが互換)。
|
|
13
|
+
import type { Name } from '@yanqirenshi/types';
|
|
14
|
+
|
|
15
|
+
/** 名称(論理名 / 物理名) — 共有型 Name のエイリアス */
|
|
16
|
+
export type TerName = Name;
|
|
16
17
|
|
|
17
18
|
/** 識別子(主キー)のマスタ定義。entities から id 参照される */
|
|
18
19
|
export interface TerIdentifier {
|
|
@@ -133,7 +134,8 @@ export interface TerRelationship {
|
|
|
133
134
|
subset?: TerSubset;
|
|
134
135
|
/**
|
|
135
136
|
* 対応表/対照表の垂下(任意)。結線の中点の○から垂下線で指定エンティティへ
|
|
136
|
-
* ぶら下げる(tm3-1 §2「対応表(onto-mapping)」の書き方)
|
|
137
|
+
* ぶら下げる(tm3-1 §2「対応表(onto-mapping)」の書き方)。線は表の最寄りの
|
|
138
|
+
* 辺(上下左右)の中央に取り付く(中点から見た方向で自動選択)。指定できるのは
|
|
137
139
|
* 対応表(CORRESPONDENCE)/対照表(COMPARATIVE)のみ — それ以外は構築時に例外
|
|
138
140
|
*/
|
|
139
141
|
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
|
-
*
|
|
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
|
|
166
|
-
var
|
|
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.
|
|
3
|
+
"version": "0.1.26",
|
|
4
4
|
"author": "yanqirenshi@gmail.com",
|
|
5
5
|
"license": "GPL-3.0-or-later",
|
|
6
6
|
"description": "See `src/index.html`",
|
|
@@ -30,6 +30,7 @@
|
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"d3": "^7.9.0",
|
|
32
32
|
"@yanqirenshi/assh0le": "^0.5.0",
|
|
33
|
+
"@yanqirenshi/types": "^0.1.0",
|
|
33
34
|
"deepmerge": "^4.2.2"
|
|
34
35
|
},
|
|
35
36
|
"devDependencies": {
|
|
@@ -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
|
+
});
|