nodejs25: 图数据绘制库(知识图谱可视化) Cytoscape.js的节点操作菜单插件

官方示例

在这里插入图片描述

cy.cxtmenu({
   
   
	selector: 'node, edge',

	commands: [
		{
   
   
			content: '<span class="fa fa-flash fa-2x"></span>',
			select: function(ele){
   
   
				console.log( ele.id() );
			}
		},

		{
   
   
			content: '<span class="fa fa-star fa-2x"></span>',
			select: function(ele){
   
   
				console.log( ele.data('name') );
			},
			enabled: false
		},

		{
   
   
			content: 'Text',
			select: function(ele){
   
   
				console.log( ele.position() );
			}
		}
	]
});

在这里插入图片描述

	cy.cxtmenu({
   
   
		selector: 'core',

		commands: [
			{
   
   
				content: 'bg1',
				select: function(){
   
   
					console.log( 'bg1' );
				}
			},

			{
   
   
				content: 'bg2',
				select: function(){
   
   
					console.log( 'bg2' );
				}
			}
		]
	});

});

完整示例代码

<!DOCTYPE html>

<html>

	<head>
		<title>cytoscape-cxtmenu.js demo</title>

		<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1, maximum-scale=1">

		<link href="https://unpkg.com/font-awesome@4.7.0/css/font-awesome.min.css" rel="stylesheet" type="text/css" />
		<script src="https://unpkg.com/cytoscape/dist/cytoscape.min.js"></script>

		<!-- for testing with local version of cytoscape.js -->
		<!--<script src="../cytoscape.js/build/cytoscape.js"></script>-->

		<script src="cytoscape-cxtmenu.js"></script>

		<style>
			body {
   
   
				font-family: helvetica;
				font-size: 14px;
				overflow: hidden;
			}

			#cy {
     
     
				width: 100%;
				height: 100%;
				position: absolute;
				left: 0;
				top: 0;
				z-index: 999;
			}

			h1 {
   
   
				opacity: 0.5;
				font-size: 1em;
			}

			/* you can set the disabled style how you like on the text/icon */
			.cxtmenu-disabled {
   
   
				opacity: 0.333;
			}
		</style>

		<script>
			window.addEventListener('DOMContentLoaded', function(){
   
   

				var cy = window.cy = cytoscape({
   
   
					container: document.getElementById('cy'),

					ready: function(){
   
   
					},

					style: [
						{
   
   
							selector: 'node'
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值