@yanqirenshi/d3.ter 0.4.1 → 0.4.2
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/README.md
CHANGED
|
@@ -108,6 +108,11 @@ TM の再帰がこれで、ループの中点の○から再帰表を垂下し
|
|
|
108
108
|
見た目は変わりません。サブセットの分岐は、垂下 1 本が関係 1 件なので垂下にだけ当たりがあり、
|
|
109
109
|
幹とバス(複数の関係で共有)にはありません。
|
|
110
110
|
|
|
111
|
+
当たりの太さ(`hit.width`)は**画面の px** です。拡大率に関わらず一定で、縮小しても細くなりません。
|
|
112
|
+
**0.4.1 までは図の単位**で、拡大率に合わせて太さが変わっていました(50% で、線から約 2px)。
|
|
113
|
+
縮小したときの当たりを補うために `hit.width` を大きくしていた場合は、値を見直してください。
|
|
114
|
+
9 倍を超えて拡大すると、見える線(1 × 拡大率)のほうが当たり(既定 9)より太くなり、見える線の縁の帯ではクリックが届きません(当たり判定の線だけで受けているため)。
|
|
115
|
+
|
|
111
116
|
## 開発
|
|
112
117
|
|
|
113
118
|
```bash
|
|
@@ -164,8 +164,9 @@ var Relationships = exports["default"] = /*#__PURE__*/function () {
|
|
|
164
164
|
});
|
|
165
165
|
this._lines.draw(place, plain);
|
|
166
166
|
|
|
167
|
-
// 当たり判定用の透明な線(#154)
|
|
168
|
-
|
|
167
|
+
// 当たり判定用の透明な線(#154)。見える線の後に描いて上に乗せる。
|
|
168
|
+
// non-scaling-stroke で、太さ(hit.width)を画面の px にする(縮小しても当たりが細くならない。#209)
|
|
169
|
+
this._hitLines.draw(place, plain).attr('pointer-events', 'stroke').attr('vector-effect', 'non-scaling-stroke');
|
|
169
170
|
this.drawSelfLoops(place, data);
|
|
170
171
|
this.drawSubsetTrees(place, data);
|
|
171
172
|
this.drawMappingDrops(place, data);
|
|
@@ -281,7 +282,8 @@ var Relationships = exports["default"] = /*#__PURE__*/function () {
|
|
|
281
282
|
return d._id;
|
|
282
283
|
});
|
|
283
284
|
hits.exit().remove();
|
|
284
|
-
var entered_hits = hits.enter().append('path').attr('class', 'connector-loop-hit').attr('fill', 'none').attr('stroke', 'transparent').attr('stroke-width', this.hitWidth()).attr('pointer-events', 'stroke').
|
|
285
|
+
var entered_hits = hits.enter().append('path').attr('class', 'connector-loop-hit').attr('fill', 'none').attr('stroke', 'transparent').attr('stroke-width', this.hitWidth()).attr('pointer-events', 'stroke').attr('vector-effect', 'non-scaling-stroke') // 太さを画面の px に(#209)
|
|
286
|
+
.on('click', function (event, d) {
|
|
285
287
|
return _this3.notifyClick(d);
|
|
286
288
|
});
|
|
287
289
|
this.applySelfLoops(entered_hits.merge(hits));
|
|
@@ -584,7 +586,7 @@ var Relationships = exports["default"] = /*#__PURE__*/function () {
|
|
|
584
586
|
this.applySubsetTrees(entered_paths.merge(paths), entered_labels.merge(labels));
|
|
585
587
|
|
|
586
588
|
// 当たり判定(関係 1 件 = 垂下 1 本)。見える分岐線より後に描いて上に乗せる(#154)
|
|
587
|
-
this._subsetHitLines.draw(place, this._subsetRels).attr('pointer-events', 'stroke');
|
|
589
|
+
this._subsetHitLines.draw(place, this._subsetRels).attr('pointer-events', 'stroke').attr('vector-effect', 'non-scaling-stroke'); // 太さを画面の px に(#209)
|
|
588
590
|
}
|
|
589
591
|
/** 分岐線の形状とラベル(バスの少し上・幹の位置)を適用する。 */
|
|
590
592
|
}, {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yanqirenshi/d3.ter",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.2",
|
|
4
4
|
"author": "yanqirenshi@gmail.com",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"description": "TM (T-shaped ER method) diagram renderer — 10 entity kinds, cardinality/optionality markers, and correspondence / comparative / recursion tables hung from a connector",
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/* ******************************************************** *
|
|
2
|
+
* 当たり判定の太さを、画面の px にする(#209)
|
|
3
|
+
* ******************************************************** */
|
|
4
|
+
|
|
5
|
+
// DOM の結果を確かめたいので、実物の d3 を使う(d3.network の Edges.events.test.js と同じ)
|
|
6
|
+
jest.mock('d3', () => jest.requireActual('../../../node_modules/d3/dist/d3.js'));
|
|
7
|
+
|
|
8
|
+
import * as d3 from 'd3';
|
|
9
|
+
import Relationships from '../src/js/Painters/Relationships.js';
|
|
10
|
+
|
|
11
|
+
const box = (id, x, y) => ({ _id: id, position: { x, y }, size: { w: 100, h: 50 } });
|
|
12
|
+
const port = (cls, owner, x, y) => ({ _class: cls, _owner: owner, position: ()=> ({ x, y }) });
|
|
13
|
+
|
|
14
|
+
const A = box('A', 0, 0);
|
|
15
|
+
const B = box('B', 300, 0);
|
|
16
|
+
const C = box('C', 0, 200);
|
|
17
|
+
const D = box('D', 200, 200);
|
|
18
|
+
|
|
19
|
+
const link = (id, from, to, extra = {}) => ({
|
|
20
|
+
_id: id,
|
|
21
|
+
from: port('PORT-FROM', from, 50, 50),
|
|
22
|
+
to: port('PORT-TO', to, 50, 0),
|
|
23
|
+
...extra,
|
|
24
|
+
});
|
|
25
|
+
const subset = (id, to) => link(id, A, to, { subsetLabel: ()=> '=kind', _core: { subset: { code: 'kind' } } });
|
|
26
|
+
|
|
27
|
+
const draw = () => {
|
|
28
|
+
document.body.innerHTML = '<svg><g class="background"></g></svg>';
|
|
29
|
+
|
|
30
|
+
const place = d3.select('g.background');
|
|
31
|
+
const painter = new Relationships({
|
|
32
|
+
rectum: ()=> ({ style: ()=> ({ relationship: { loop: { distance: 40 } } }) }),
|
|
33
|
+
callbacks: { relationship: {} },
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
painter.drawRelationships(place, { list: [
|
|
37
|
+
link('plain', A, B),
|
|
38
|
+
{ ...link('self', A, A), to: port('PORT-TO', A, 100, 25) },
|
|
39
|
+
subset('sub-c', C),
|
|
40
|
+
subset('sub-d', D),
|
|
41
|
+
] });
|
|
42
|
+
|
|
43
|
+
return place;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
describe('当たり判定の線は、拡大率に関わらず画面の上で同じ太さ(vector-effect: non-scaling-stroke)', () => {
|
|
47
|
+
it('直線・ループ・サブセットの垂下の当たり判定に付く', () => {
|
|
48
|
+
draw();
|
|
49
|
+
|
|
50
|
+
const hits = [...document.querySelectorAll('.connector-hit, .connector-loop-hit, .subset-drop-hit')];
|
|
51
|
+
|
|
52
|
+
expect(hits.map((e)=> e.getAttribute('class'))).toEqual(
|
|
53
|
+
['connector-hit', 'connector-loop-hit', 'subset-drop-hit', 'subset-drop-hit']);
|
|
54
|
+
|
|
55
|
+
for (const hit of hits) {
|
|
56
|
+
expect(hit.getAttribute('vector-effect')).toBe('non-scaling-stroke');
|
|
57
|
+
expect(hit.getAttribute('pointer-events')).toBe('stroke');
|
|
58
|
+
expect(hit.getAttribute('stroke-width')).toBe('9'); // 太さの値は変えない
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it('見える線には付けない(見た目は、拡大率に合わせて太さが変わるまま)', () => {
|
|
63
|
+
draw();
|
|
64
|
+
|
|
65
|
+
const visible = [...document.querySelectorAll('line.connector, path.connector-loop, path.subset-line')];
|
|
66
|
+
|
|
67
|
+
expect(visible).toHaveLength(3);
|
|
68
|
+
for (const e of visible)
|
|
69
|
+
expect(e.getAttribute('vector-effect')).toBeNull();
|
|
70
|
+
});
|
|
71
|
+
});
|