@yanqirenshi/d3.deployment 0.5.1 → 0.6.0

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.
@@ -58,7 +58,11 @@ var Edge = exports["default"] = /*#__PURE__*/function () {
58
58
  value: function normalize(data) {
59
59
  var new_data = this.dataTemplate();
60
60
  new_data._core = data;
61
- if (data.id) new_data._id = data.id;
61
+
62
+ // 入力に id があればそれを、無ければ Rectum.makeEdges が採番した _id を引き継ぐ。
63
+ // (これを落とすと _id=null → data-edge-id="null" になり、
64
+ // ドラッグ時の redraw が対象 path を特定できず接続線が追従しない)
65
+ if (data.id || data.id === 0) new_data._id = data.id;else if (data._id || data._id === 0) new_data._id = data._id;
62
66
  if (data.from.id) new_data.from.id = data.from.id;
63
67
  if (data.to.id) new_data.to.id = data.to.id;
64
68
  if (data.stroke) {
@@ -86,6 +86,7 @@ var Node = exports["default"] = /*#__PURE__*/function () {
86
86
  color: '#333333'
87
87
  }
88
88
  },
89
+ description: '',
89
90
  position: null,
90
91
  size: null,
91
92
  background: null,
@@ -103,6 +104,7 @@ var Node = exports["default"] = /*#__PURE__*/function () {
103
104
  var core = data._core;
104
105
  if (core.id || core.id === 0) data._id = core.id;
105
106
  if (core.type) data.type = core.type;
107
+ if (core.description) data.description = core.description;
106
108
  if (core.link) data.link = core.link;else data.link = {
107
109
  url: null
108
110
  };
@@ -37,13 +37,21 @@ var Nodes = exports["default"] = /*#__PURE__*/function () {
37
37
  }, {
38
38
  key: "drawGroup",
39
39
  value: function drawGroup(place, data, type) {
40
- return place.selectAll('g.' + type).data([data], function (d) {
40
+ var groups = place.selectAll('g.' + type).data([data], function (d) {
41
41
  return d._id;
42
42
  }).enter().append('g').attr('class', type).attr("transform", function (d) {
43
43
  return "translate(" + d._position.x + "," + d._position.y + ")";
44
44
  }).attr('level', function (d) {
45
45
  return d._level;
46
46
  });
47
+
48
+ // description はホバーツールチップ(SVG <title>)として表示する
49
+ groups.filter(function (d) {
50
+ return !!d.description;
51
+ }).append('title').text(function (d) {
52
+ return d.description;
53
+ });
54
+ return groups;
47
55
  }
48
56
  }, {
49
57
  key: "drawBody",
package/package.json CHANGED
@@ -1,11 +1,10 @@
1
1
  {
2
2
  "name": "@yanqirenshi/d3.deployment",
3
- "version": "0.5.1",
3
+ "version": "0.6.0",
4
4
  "description": "See [Documents](https://yanqirenshi.github.io/D3.Deployment/)",
5
5
  "main": "dist/index.js",
6
6
  "directories": {
7
- "doc": "docs",
8
- "example": "example"
7
+ "doc": "docs"
9
8
  },
10
9
  "peerDependencies": {
11
10
  "react": "^18.2.0",
@@ -6,6 +6,7 @@ const NESTED_SAMPLE = () => ({
6
6
  {
7
7
  type: 'NODE', id: 1,
8
8
  label: { text: 'P', position: { x: 20, y: 20 } },
9
+ description: '親ノードの説明',
9
10
  size: { w: 300, h: 300 }, position: { x: 0, y: 0 },
10
11
  children: [
11
12
  {
@@ -53,6 +54,36 @@ const buildData = () => {
53
54
  return { rectum, data: rectum.data() };
54
55
  };
55
56
 
57
+ test('edges without an explicit id inherit the auto-numbered _id (drag redraw needs it)', () => {
58
+ const rectum = new Rectum({});
59
+
60
+ // 入力エッジに id を与えない → makeEdges が _id を採番、normalize が引き継ぐべき。
61
+ rectum.data({
62
+ nodes: [
63
+ { type: 'NODE', id: 1, label: { text: 'A' }, size: { w: 100, h: 100 }, position: { x: 0, y: 0 } },
64
+ { type: 'NODE', id: 2, label: { text: 'B' }, size: { w: 100, h: 100 }, position: { x: 300, y: 0 } },
65
+ ],
66
+ edges: [
67
+ { from: { id: 1, position: 0 }, to: { id: 2, position: 180 }, port: 45 },
68
+ ],
69
+ });
70
+
71
+ const edges = rectum.data().edges.list;
72
+
73
+ expect(edges).toHaveLength(1);
74
+ // _id が null のままだと data-edge-id="null" になり redraw が対象を見つけられない。
75
+ expect(edges[0]._id).not.toBeNull();
76
+ expect(edges[0]._id).not.toBeUndefined();
77
+ expect(typeof edges[0]._id).toBe('number');
78
+ });
79
+
80
+ test('node description is normalized (kept when given, empty by default)', () => {
81
+ const { data } = buildData();
82
+
83
+ expect(data.nodes.ht[1].description).toBe('親ノードの説明');
84
+ expect(data.nodes.ht[2].description).toBe(''); // 未指定は空文字
85
+ });
86
+
56
87
  test('collectSubtree gathers a node and all descendants', () => {
57
88
  const { rectum, data } = buildData();
58
89