@yanqirenshi/d3.deployment 0.9.1 → 0.10.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/README.markdown CHANGED
@@ -5,7 +5,7 @@
5
5
  - ノードは `children` で入れ子にできます。宣言サイズより子が大きい場合は親が自動で広がります。
6
6
  - ノードはドラッグで移動でき、**親を動かすとサブツリーごと追従**します。
7
7
  - エッジの取り付け位置はポートの角度で指定します(0=真下・時計回り。90=左 / 180=真上 / 270=右)。
8
- - **このライブラリは描画のみを行います。** クリックはコールバックで通知するだけで、
8
+ - **このライブラリは描画のみを行います。** クリックと右クリックはコールバックで通知するだけで、
9
9
  編集 UI は利用側が用意します(ショーケースではインスペクタ `@yanqirenshi/colonoscope` を繋いでいます)。
10
10
 
11
11
  ## インストール
@@ -33,8 +33,10 @@ export default function Graph({ data }) {
33
33
  transform: { k: 0.6, x: 120, y: 120 }, // 初期のズーム / パン
34
34
  callbacks: {
35
35
  // 描画は行わず通知のみ。core は入力データそのもの
36
- node: { click: (core, node) => {} },
37
- edge: { click: (core, edge) => {} },
36
+ // contextmenu は右クリック。引数は click と同じで、最後に event(MouseEvent)。
37
+ // 渡したときだけブラウザ標準のメニューを止める。ドラッグ中は呼ばれない
38
+ node: { click: (core, node) => {}, contextmenu: (core, node, event) => {} },
39
+ edge: { click: (core, edge) => {}, contextmenu: (core, edge, event) => {} },
38
40
  },
39
41
  });
40
42
  r.data(data);
package/babel.config.js CHANGED
@@ -1,14 +1,14 @@
1
- module.exports = {
2
- presets: [
3
- [
4
- "@babel/preset-env"
5
- ]
6
- ],
7
- env: {
8
- test: {
9
- plugins: [
10
- "babel-plugin-transform-es2015-modules-commonjs",
11
- ],
12
- },
13
- },
14
- };
1
+ module.exports = {
2
+ presets: [
3
+ [
4
+ "@babel/preset-env"
5
+ ]
6
+ ],
7
+ env: {
8
+ test: {
9
+ plugins: [
10
+ "babel-plugin-transform-es2015-modules-commonjs",
11
+ ],
12
+ },
13
+ },
14
+ };
package/dist/js/Rectum.js CHANGED
@@ -33,6 +33,26 @@ function _superPropBase(t, o) { for (; !{}.hasOwnProperty.call(t, o) && null !==
33
33
  function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, _getPrototypeOf(t); }
34
34
  function _inherits(t, e) { if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); t.prototype = Object.create(e && e.prototype, { constructor: { value: t, writable: !0, configurable: !0 } }), Object.defineProperty(t, "prototype", { writable: !1 }), e && _setPrototypeOf(t, e); }
35
35
  function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); }
36
+ /**
37
+ * click / contextmenu のコールバックを呼ぶ。
38
+ *
39
+ * contextmenu(右クリック)のときだけ次のようにする。
40
+ * - 左ボタンを押したまま(ドラッグ中)の右クリックは通知しない
41
+ * - ブラウザ標準のコンテキストメニューを止める(コールバックがあるときだけ
42
+ * ここに来るので、渡していなければ標準のメニューが出る)
43
+ * - 最後の引数に event を渡す(clientX / clientY を使えるように)
44
+ */
45
+ var notify = function notify(callback, event, core, datum) {
46
+ if (event.type === 'contextmenu') {
47
+ if (event.buttons & 1) return;
48
+ event.preventDefault();
49
+ event.stopPropagation();
50
+ callback(core, datum, event);
51
+ return;
52
+ }
53
+ event.stopPropagation();
54
+ callback(core, datum);
55
+ };
36
56
  var Rectum = exports["default"] = /*#__PURE__*/function (_Colon) {
37
57
  function Rectum(params) {
38
58
  var _this;
@@ -67,10 +87,12 @@ var Rectum = exports["default"] = /*#__PURE__*/function (_Colon) {
67
87
  var edge = callbacks.edge || {};
68
88
  return {
69
89
  node: {
70
- click: node.click || null
90
+ click: node.click || null,
91
+ contextmenu: node.contextmenu || null
71
92
  },
72
93
  edge: {
73
- click: edge.click || null
94
+ click: edge.click || null,
95
+ contextmenu: edge.contextmenu || null
74
96
  }
75
97
  };
76
98
  }
@@ -414,56 +436,61 @@ var Rectum = exports["default"] = /*#__PURE__*/function (_Colon) {
414
436
  _iterator8.f();
415
437
  }
416
438
  this.attachNodeDrag(place, data);
417
- this.attachNodeClick(place);
418
- this.attachEdgeClick(place);
439
+ this.attachNodeEvent(place, 'click');
440
+ this.attachNodeEvent(place, 'contextmenu');
441
+ this.attachEdgeEvent(place, 'click');
442
+ this.attachEdgeEvent(place, 'contextmenu');
419
443
  }
420
444
  /**
421
- * ノードのクリック通知(callbacks.node.click)。
445
+ * ノードのクリック通知(callbacks.node.click)と
446
+ * 右クリック通知(callbacks.node.contextmenu)。
422
447
  * d3.drag は移動を伴ったクリックを抑止するため、静止クリックだけが届く。
423
448
  *
424
- * コールバックには (core, node) を渡す。
449
+ * コールバックには (core, node) を渡す。contextmenu は最後に event も渡す。
425
450
  * core: 入力データそのまま(ライブラリが解釈しないフィールドも落ちない)
426
451
  * node: 正規化済みデータ(位置・サイズ等が必要な場合に使う)
427
452
  *
428
453
  * リンク(a.link-alt)のクリックはリンク側を優先し、コールバックは発火しない。
454
+ *
455
+ * @param {string} type 'click' | 'contextmenu'
429
456
  */
430
457
  }, {
431
- key: "attachNodeClick",
432
- value: function attachNodeClick(place) {
433
- var callback = this._callbacks.node.click;
458
+ key: "attachNodeEvent",
459
+ value: function attachNodeEvent(place, type) {
460
+ var callback = this._callbacks.node[type];
434
461
  if (!callback) return;
435
- place.selectAll('g.node, g.component').on('click', function (event, d) {
462
+ place.selectAll('g.node, g.component').on(type, function (event, d) {
436
463
  var target = event.target;
437
464
  if (target && target.closest && target.closest('a.link-alt')) return; // リンク優先(既存の <a target="_blank"> と干渉しない)
438
465
 
439
- event.stopPropagation();
440
- callback(d._core, d);
466
+ notify(callback, event, d._core, d);
441
467
  });
442
468
  }
443
469
  /**
444
- * エッジのクリック通知(callbacks.edge.click)。
470
+ * エッジのクリック通知(callbacks.edge.click)と
471
+ * 右クリック通知(callbacks.edge.contextmenu)。
445
472
  * エッジ path のほか、両端のポート円からも同じエッジを通知する
446
473
  * (細い線より円のほうが掴みやすい)。(core, edge) を渡す契約は
447
- * node.click と同じ(core = 入力のエッジオブジェクトそのまま)。
474
+ * node.click / node.contextmenu と同じ(core = 入力のエッジオブジェクトそのまま)。
475
+ *
476
+ * @param {string} type 'click' | 'contextmenu'
448
477
  */
449
478
  }, {
450
- key: "attachEdgeClick",
451
- value: function attachEdgeClick(place) {
479
+ key: "attachEdgeEvent",
480
+ value: function attachEdgeEvent(place, type) {
452
481
  var _this5 = this;
453
- var callback = this._callbacks.edge.click;
482
+ var callback = this._callbacks.edge[type];
454
483
  if (!callback) return;
455
- place.selectAll('path.edge').style('cursor', 'pointer').on('click', function (event) {
484
+ place.selectAll('path.edge').style('cursor', 'pointer').on(type, function (event) {
456
485
  // path の datum は線分データのため data-edge-id からエッジを引く
457
486
  var el = event.currentTarget;
458
487
  var id = el && el.getAttribute && el.getAttribute('data-edge-id');
459
488
  var edge = _this5.findEdge(id);
460
489
  if (!edge) return;
461
- event.stopPropagation();
462
- callback(edge._core, edge);
490
+ notify(callback, event, edge._core, edge);
463
491
  });
464
- place.selectAll('circle.port').style('cursor', 'pointer').on('click', function (event, d) {
465
- event.stopPropagation();
466
- callback(d.edge._core, d.edge);
492
+ place.selectAll('circle.port').style('cursor', 'pointer').on(type, function (event, d) {
493
+ notify(callback, event, d.edge._core, d.edge);
467
494
  });
468
495
  }
469
496
  /** id(入力 id。DOM の data-edge-id は文字列)からエッジを引く。 */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yanqirenshi/d3.deployment",
3
- "version": "0.9.1",
3
+ "version": "0.10.0",
4
4
  "description": "Deployment diagram renderer (nestable nodes / edges / ports) — dragging a parent moves its whole subtree",
5
5
  "main": "dist/index.js",
6
6
  "directories": {