From 289fe94302320e489505a355c869a0f53d6617d0 Mon Sep 17 00:00:00 2001 From: sunhao Date: Tue, 11 Jun 2024 10:51:27 +0800 Subject: [PATCH 1/4] * [misc] add onReady and onContextmenu callback to treemap. --- lib/zin/wg/treemap/v1.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/zin/wg/treemap/v1.php b/lib/zin/wg/treemap/v1.php index 924568ef95..74ed267d45 100644 --- a/lib/zin/wg/treemap/v1.php +++ b/lib/zin/wg/treemap/v1.php @@ -36,7 +36,9 @@ class treemap extends wg 'nodeTemplate?: string', // 节点元素模板。 'onNodeClick?: function', // 节点元素模板。 'afterDrawLines?: function', // 节点元素模板。 - 'afterRender?: function' // 节点元素模板。 + 'afterRender?: function', // 节点元素模板。 + 'onContextMenu?: function', // 上下文菜单事件回调函数。 + 'onReady?: function' // 组件就绪回调函数。 ); protected function build(): array @@ -46,7 +48,7 @@ class treemap extends wg list($width, $height) = $this->prop(array('width', 'height')); $dataVarName = "_treemap_$this->gid"; $treemapPath = $app->getWebRoot() . 'js/zui/treemap/index.html?options=' . $dataVarName; - $options = $this->props->pick(array('hotkeyEnable', 'hotkeys', 'lang', 'langs', 'data', 'nodeTeamplate', 'hSpace', 'vSpace', 'canvasPadding', 'removingNodeTip', 'lineCurvature', 'subLineWidth', 'lineColor', 'lineOpacity', 'lineSaturation', 'lineLightness', 'nodeLineWidth', 'showToggleButton', 'readonly', 'minimap', 'toolbar', 'zoom', 'zoomMax', 'zoomMin', 'minimapHeight', 'onNodeClick', 'afterDrawLines', 'afterRender')); + $options = $this->props->pick(array('hotkeyEnable', 'hotkeys', 'lang', 'langs', 'data', 'nodeTeamplate', 'hSpace', 'vSpace', 'canvasPadding', 'removingNodeTip', 'lineCurvature', 'subLineWidth', 'lineColor', 'lineOpacity', 'lineSaturation', 'lineLightness', 'nodeLineWidth', 'showToggleButton', 'readonly', 'minimap', 'toolbar', 'zoom', 'zoomMax', 'zoomMin', 'minimapHeight', 'onNodeClick', 'afterDrawLines', 'afterRender', 'onReady', 'onContextMenu')); return array ( h::jsVar("window.$dataVarName", $options), From 1edad165f40db2aa79d172d5922f858886c62dbe Mon Sep 17 00:00:00 2001 From: sunhao Date: Tue, 11 Jun 2024 10:52:43 +0800 Subject: [PATCH 2/4] * [misc] trigger click on parent on click iframe of mindmap and treemap. --- www/js/mindmap/index.html | 1 + www/js/zui/treemap/index.html | 1 + 2 files changed, 2 insertions(+) diff --git a/www/js/mindmap/index.html b/www/js/mindmap/index.html index eeb69174ee..100bdbbbdc 100644 --- a/www/js/mindmap/index.html +++ b/www/js/mindmap/index.html @@ -29,6 +29,7 @@ if(!options.manual) $('#mindmap').mindmap(options); parent.createMindmap = function(userOptions){return $('#mindmap').mindmap($.extend({}, options, userOptions)).data('zui.mindmap');}; parent.getMindmap = function(){return $('#mindmap').data('zui.mindmap');}; parent.mindmap$ = $; +$('body').on('click', () => window.parent.$(window.frameElement).trigger('click')); diff --git a/www/js/zui/treemap/index.html b/www/js/zui/treemap/index.html index 057ecda922..ec735c9f67 100644 --- a/www/js/zui/treemap/index.html +++ b/www/js/zui/treemap/index.html @@ -25,6 +25,7 @@ window.parent.$(function() $('#treemap').treemap($.extend({}, window.parent[$.getSearchParam('options')])); const treemap = $('#treemap').data('zui.treemap'); window.parent.getTreemap = function() {return treemap;}; + $('body').on('click', () => window.parent.$(window.frameElement).trigger('click')); }); From f6338c37d4856eef3b58e6e7bd7d27048bfd0748 Mon Sep 17 00:00:00 2001 From: sunhao Date: Tue, 11 Jun 2024 10:54:22 +0800 Subject: [PATCH 3/4] * [misc] support for using onContextMenu in treemap. --- www/js/zui/treemap/index.html | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/www/js/zui/treemap/index.html b/www/js/zui/treemap/index.html index ec735c9f67..1425f673fc 100644 --- a/www/js/zui/treemap/index.html +++ b/www/js/zui/treemap/index.html @@ -26,6 +26,26 @@ window.parent.$(function() const treemap = $('#treemap').data('zui.treemap'); window.parent.getTreemap = function() {return treemap;}; $('body').on('click', () => window.parent.$(window.frameElement).trigger('click')); + if(treemap.options.onContextMenu) + { + treemap.$nodes.on('contextmenu', function(e) + { + const $node = $(e.target).closest('.treemap-node'); + const node = $node.data('node'); + const frameBounding = window.frameElement.getBoundingClientRect(); + const clientX = e.clientX + frameBounding.left; + const clientY = e.clientY + frameBounding.top; + let result = treemap.options.onContextMenu({node: node, clientX: clientX, clientY: clientY, treemap: treemap, event: e}); + if(!result) return; + if(Array.isArray(result)) result = {items: result}; + window.parent.zui.ContextMenu.show($.extend( + { + element: {getBoundingClientRect: () => ({x: clientX, y: clientY, width: 0, height: 0, left: clientX, top: clientY})}, + }, result)); + e.preventDefault(); + return false; + }); + } }); From 026f795fa4d3f2dc07f0e72502011a9ac861e9b1 Mon Sep 17 00:00:00 2001 From: sunhao Date: Tue, 11 Jun 2024 10:54:32 +0800 Subject: [PATCH 4/4] * [misc] support for using onReady in treemap. --- www/js/zui/treemap/index.html | 1 + 1 file changed, 1 insertion(+) diff --git a/www/js/zui/treemap/index.html b/www/js/zui/treemap/index.html index 1425f673fc..dfd936ede0 100644 --- a/www/js/zui/treemap/index.html +++ b/www/js/zui/treemap/index.html @@ -25,6 +25,7 @@ window.parent.$(function() $('#treemap').treemap($.extend({}, window.parent[$.getSearchParam('options')])); const treemap = $('#treemap').data('zui.treemap'); window.parent.getTreemap = function() {return treemap;}; + if(treemap.options.onReady) treemap.options.onReady(treemap, window); $('body').on('click', () => window.parent.$(window.frameElement).trigger('click')); if(treemap.options.onContextMenu) {