当前位置:网站首页>Use vis network to locate the circular toolbar according to the node coordinates
Use vis network to locate the circular toolbar according to the node coordinates
2022-07-22 21:01:00 【checkMa】
Use vis-network Locate according to node coordinates demo
Code
<!doctype html>
<html>
<head>
<title></title>
<style type="text/css"> body{
padding:0; margin:0; } #mynetwork {
width: 100%; height: 600px; border: 1px solid lightgray; } .cricle{
position: absolute; left: 0px; top: 0px; width: 100px; height: 100px; border: 30px solid rgba(200,200,200,0.7); border-radius: 50px; box-sizing: border-box; z-index: 10; display: none; } .cricle > span{
position: absolute; left: 0; right: 0; width: 30px; height: 20px; line-height: 20px; text-align: center; font-size: 10px; cursor: pointer; } .cricle > span:hover{
color: #1b68ff; } .cricle > span:nth-child(1){
left: 5px; top: -25px; } .cricle > span:nth-child(2){
left: 37px; top: -5px; } .cricle > span:nth-child(3){
left: 37px; top: 25px; } .cricle > span:nth-child(4){
left: 5px; top: 44px; } .cricle > span:nth-child(5){
left: -27px; top: 25px; } .cricle > span:nth-child(6){
left: -27px; top: -5px; } </style>
</head>
<body>
<div id="mynetwork"></div>
<div id="cricle" class="cricle">
<span> Options </span>
<span> Options </span>
<span> Options </span>
<span> Options </span>
<span> Options </span>
<span> Options </span>
</div>
<script type="text/javascript" src="https://unpkg.com/vis-network/standalone/umd/vis-network.min.js"></script>
<script type="text/javascript" > // Create nodes var nodes = new vis.DataSet([ {
id: 1, label: 'Node 1',image:'https://ai-open-platform-1251483553.cos.ap-guangzhou.myqcloud.com/m1.png',shape: 'circularImage'}, {
id: 2, label: 'Node 2',image:'https://ai-open-platform-1251483553.cos.ap-guangzhou.myqcloud.com/m1.png',shape: 'circularImage'}, {
id: 3, label: 'Node 3',image:'https://ai-open-platform-1251483553.cos.ap-guangzhou.myqcloud.com/m1.png',shape: 'circularImage'}, {
id: 4, label: 'Node 4',image:'https://ai-open-platform-1251483553.cos.ap-guangzhou.myqcloud.com/m1.png',shape: 'circularImage'}, {
id: 5, label: 'Node 5',image:'https://ai-open-platform-1251483553.cos.ap-guangzhou.myqcloud.com/m1.png',shape: 'circularImage'} ]); // Create relationships var edges = new vis.DataSet([ {
from: 1, to: 2}, {
from: 2, to: 4}, {
from: 2, to: 5}, ]); var container = document.getElementById('mynetwork'); var data = {
nodes: nodes, edges: edges }; // Node related parameters var options = {
interaction:{
hover:true}, // locale: 1.5, height:'100%', width:'100%', layout:{
randomSeed: 2, // hierarchical: {
// direction: 'LR', // sortMethod:'directed' // } }, nodes: {
borderWidth:4, size:20, font: {
color:'#333', size: 14 }, color: {
border: 'rgba(167, 173, 221, 1)', hover:'rgba(2, 126, 238, 1)', highlight:'rgba(2, 126, 238, 1)' } }, edges: {
arrows: {
to: {
enabled: true, scaleFactor: 0.5, type: 'arrow' } // Display of arrows }, color: {
color:'rgba(167, 173, 221, 1)', hover:'rgba(2, 126, 238, 1)', highlight:'rgba(2, 126, 238, 1)' }, font:{
color:'#999', size:12 } } }; // Create topology objects var network = new vis.Network(container, data, options); // Global event monitoring network.on("click", function(e){
console.log(e) console.log(network) // Access to the node canvas coordinate let p = network.getPosition(e.nodes[0]); console.log(p) // Get the zoom size let scale = network.getScale(); console.log(scale) // canvas->dom Coordinate transformation console.log(network.canvasToDOM({
x:p.x, y:p.y})) let domPosi = network.canvasToDOM({
x:p.x, y:p.y}); // Set the circular position setCriclePosition(domPosi.x - 50, domPosi.y - 50, scale); }) network.on("dragStart", function(e){
console.log(e) hideCricle(); }) network.on("dragging", function(e){
console.log(e) }) network.on("dragEnd", function(e){
console.log(e) }) network.on("controlNodeDragging", function(e){
console.log(e) hideCricle(); }) network.on("zoom", function(e){
console.log(e) hideCricle(); }) // location div function setCriclePosition(x,y, scale){
let cricle = document.getElementById("cricle"); cricle.style = `left: ${
x}px; top: ${
y}px;transform:scale(${
scale});display:block;`; } // hide div function hideCricle(){
let cricle = document.getElementById("cricle"); cricle.style = `display:none;`; } </script>
</body>
</body>
</html>
边栏推荐
- Using MySQL database in Django
- Redis series 15 -- redis cache cleaning
- 解决微信小程序 thirdScriptError错误
- Pytest testing framework built quickly
- Use VBScript on xshell and CRT to connect and locate servers, directories and databases more efficiently
- Redis 系列14--Redis Cluster
- Steps and common methods of data analysis
- Commonly used operators of spark
- 线程池02--源码
- Airtest 进行WebUI自动化测试(selenium)
猜你喜欢
多线程01--创建线程和线程状态
Jmeter性能测试
微信小程序入门教程学习笔记——UI篇之布局基础
A new checkerboard placement and sizing method for capacitors in charge scaling DAC based on nonlinear worst-case analysis
Tree structure
JMeter performance test
Mysql 导入3亿数据
Multithreading 04 -- order of threads
Multithreading 05 -- reentrantlock principle
BUUCTF闯关日记--[SUCTF 2019]CheckIn1()
随机推荐
项目上线,旧数据需要修改,写SQL太麻烦,看Excel配合简单SQL的强大功能
Buuctf breakthrough diary -- [ciscn2019 North China division Day2 web1]hack world
Desensitization of mobile phone, name and ID card information in the project in the log and response data
locust测试框架快速搭建
L'applet Wechat ne peut pas lire la propriété 'setdata' de NULL Error
Monkey 介绍及使用
(7) Vulhub column: log4j Remote Code Execution Vulnerability recurrence
微信小程序综合案例实践2
spark常见问题
Redis series 15 -- redis cache cleaning
文件
Wechat applet cannot read property'setdata'of null error
微信小程序Cannot read property 'setData' of null错误
字符串split操作到底有多少坑
测试相关基础概念
树结构
Django中使用Mysql数据库
Bash变量—数值运算与运算符
Multithreading 03 -- synchronized and lock escalation
测试用例设计