@yanqirenshi/d3.deployment 0.5.2 → 0.7.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.
package/dist/js/Rectum.js CHANGED
@@ -52,13 +52,28 @@ var Rectum = exports["default"] = /*#__PURE__*/function (_Colon) {
52
52
  EDGE: new _Edges["default"](),
53
53
  PORT: new _Ports["default"]()
54
54
  };
55
+
56
+ // コールバック(任意)。描画は行わず通知のみ
57
+ // (インスペクタ等の外部ツールはこの通知に接続する)
58
+ _this._callbacks = _this.initCallbacks(params);
55
59
  return _this;
56
60
  }
57
- /* ******** */
58
- /* Getter */
59
- /* ******** */
60
61
  _inherits(Rectum, _Colon);
61
62
  return _createClass(Rectum, [{
63
+ key: "initCallbacks",
64
+ value: function initCallbacks(params) {
65
+ var callbacks = params && params.callbacks || {};
66
+ var node = callbacks.node || {};
67
+ return {
68
+ node: {
69
+ click: node.click || null
70
+ }
71
+ };
72
+ }
73
+ /* ******** */
74
+ /* Getter */
75
+ /* ******** */
76
+ }, {
62
77
  key: "node",
63
78
  value: function node() {
64
79
  return this._node;
@@ -403,6 +418,21 @@ var Rectum = exports["default"] = /*#__PURE__*/function (_Colon) {
403
418
  _iterator8.f();
404
419
  }
405
420
  this.attachNodeDrag(place, data);
421
+ this.attachNodeClick(place);
422
+ }
423
+ /**
424
+ * ノードのクリック通知(callbacks.node.click)。
425
+ * d3.drag は移動を伴ったクリックを抑止するため、静止クリックだけが届く。
426
+ */
427
+ }, {
428
+ key: "attachNodeClick",
429
+ value: function attachNodeClick(place) {
430
+ var callback = this._callbacks.node.click;
431
+ if (!callback) return;
432
+ place.selectAll('g.node, g.component').on('click', function (event, d) {
433
+ event.stopPropagation();
434
+ callback(d);
435
+ });
406
436
  }
407
437
  ///// ////////////////////////////////////////////////////////////////
408
438
  ///// Drag (grab + drag でノードを移動)
@@ -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.2",
3
+ "version": "0.7.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
  {
@@ -76,6 +77,13 @@ test('edges without an explicit id inherit the auto-numbered _id (drag redraw ne
76
77
  expect(typeof edges[0]._id).toBe('number');
77
78
  });
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
+
79
87
  test('collectSubtree gathers a node and all descendants', () => {
80
88
  const { rectum, data } = buildData();
81
89