jsplumb作的topology图

<div  id="vmstopologygraph" style="margin-top:10px;overflow-x:auto;"></div>

<script>
            function createGraph(source, container) {
                var jqContainer = $("#" + container);
                var nodeCount = vmsporperty.length + 1;

//VMSノードの作成
                var vmsNode = document.createElement("div");
                vmsNode.id = source.vms.name;
                if (vmsporperty.length <= 30) {
                    vmsNode.className = "vmsgraph";
                }
                else {
                    vmsNode.className = "vmsgraphMin";
                }

var xPos = jqContainer.get(0).scrollWidth / 2;
                var yPos = jqContainer.get(0).scrollHeight / 2;
                var nodeLoctions = [];
                nodeLoctions.push([xPos, yPos]);
                vmsNode.style.top = yPos + "px";
                vmsNode.style.left = xPos + "px";

vmsNode.textContent = source.vms.name;
                vmsNode.innerText = source.vms.name;
                vmsNode.style.textAlign = "center";
                jqContainer.get(0).appendChild(vmsNode);

//VM&Network&Strorageノードの作成
                for (var i = 0; i < vmsporperty.length; i++) {
                    var node = document.createElement("div");
                    node.id = vmsporperty[i].Pool + vmsporperty[i].Name;
                    while (true) {
                        var pos = getRandomCoordinates(130);
                        var xPs = parseFloat(pos[0]) + xPos;
                        var yPs = parseFloat(pos[1]) + yPos;

if (nodeLoctions.length == 0) {
                            nodeLoctions.push([xPs, yPs]);
                            break;
                        }
                        if (isCover(xPs, yPs, nodeLoctions)) {
                            continue;
                        }
                        else {
                            nodeLoctions.push([xPs, yPs]);
                            break;
                        }
                    }
                    createNodeGraph(vmsporperty[i], node);

node.style.top = yPs + "px";
                    node.style.left = xPs + "px";
                    node.textContent = vmsporperty[i].Name;
                    node.innerText = vmsporperty[i].Name;

node.style.textAlign = "center";
                    jqContainer.get(0).appendChild(node);
                }

}

function createNodeGraph(porperty, node) {
                if (porperty.type == "vm") {
                    if (vmsporperty.length <= 30) {
                        node.className = "vmgraph";
                    }
                    else if (vmsporperty.length > 30 && vmsporperty.length <= 60) {
                        node.className = "vmgraphMid";
                    }
                    else {
                        node.className = "vmgraphMin";
                    }

}
                else if (porperty.type == "network") {
                    if (vmsporperty.length <= 30) {
                        node.className = "networkgraph";
                    }
                    else if (vmsporperty.length > 30 && vmsporperty.length <= 60) {
                        node.className = "networkgraphMid";
                    }
                    else{
                        node.className = "networkgraphMin";
                    }

}
                else if (porperty.type == "storage") {
                    if (vmsporperty.length <= 30) {
                        node.className = "lungraph";
                    }
                    else if (vmsporperty.length > 30 && vmsporperty.length <= 60) {
                        node.className = "lungraphMid";
                    }
                   else {
                        node.className = "lungraphMin";
                    }

}
                else if (porperty.type == "vms") {
                    if (vmsporperty.length <= 30) {
                        node.className = "vmsgraphMid";
                    }
                    else if (vmsporperty.length > 30 && vmsporperty.length <= 60) {
                        node.className = "lungraphMid";
                    }
                    else {
                        node.className = "lungraphMin";
                    }

}
            }

function isCover(xPs, yPs, nodeLoctions) {
                for (var i = 0; i < nodeLoctions.length; i++) {
                    var distance = Math.sqrt((yPs - nodeLoctions[i][1]) * (yPs - nodeLoctions[i][1]) + (xPs - nodeLoctions[i][0]) * (xPs - nodeLoctions[i][0]));
                    if (distance <= 50) {
                        return true;
                    }
                }
                return false;
            }

function getRandomCoordinates(maxRadius) {
                var xyPos = [];

//半径がランダムに生成される
                var radius = 80 + Math.round(Math.random() * maxRadius);
                //角度がランダムに生成される
                //var Angle = Math.round(Math.random() * 360);
                // var rand = (3.14 * Math.round(Math.random() * 360)) / 180;
                var xPoint = 0;
                var yPoint = 0;
                while (true) {
                    xPoint = 400 * Math.cos(Math.random() * 360);
                    yPoint = 150 * Math.sin(Math.random() * 360);
                    if ((xPoint > -500 || xPiont < 500) && (yPoint > -150 || yPoint < 150)) {
                        break;

}
                    else {
                        continue;
                    }
                }

xyPos.push(xPoint.toFixed(2));
                xyPos.push(yPoint.toFixed(2));

return xyPos;
            }

var vm = [];
            for (var i = 0; i < 21; i++) {
                var vmNode = { type: ‘vm‘, Pool: ‘vmpool2‘, Name: ‘vm‘ + i };
                vm.push(vmNode);
            }

var network = [];
            for (var i = 0; i < 5; i++) {
                var networkNode = { type: ‘network‘, Pool: ‘netWorkpool1‘, Name: ‘netWork‘ + i };
                network.push(networkNode);
            }

var storage = [];
            for (var i = 0; i < 5; i++) {
                var storageNode = { type: ‘storage‘, Pool: ‘storagepool1‘, Name: ‘storage‘ + i };
                storage.push(storageNode);
            }

var source = {
                vms: { type: ‘vms‘, name: "vms1", serverProfile: "001" },
                vm: vm,
                netWork: network,
                Storage: storage
            };
            var vmsporperty = source.Storage.concat(source.vm.concat(source.netWork));

createGraph(source, "vmstopologygraph");

jsPlumb.ready(function () {

jsPlumb.importDefaults({
                    DragOptions: { cursor: ‘pointer‘, zIndex: 2000 },
                    PaintStyle: { strokeStyle: ‘#666‘ },
                    EndpointStyle: { width: 0.5, height: 0.5, strokeStyle: ‘#666‘ },
                    Endpoint: "Rectangle",
                    Anchors: ["Right"]
                });

jsPlumbConnect();

var exampleDropOptions = {
                    hoverClass: "dropHover",
                    activeClass: "dragActive"
                };

var color1 = "#316b31";
                var exampleEndpoint1 = {
                    endpoint: ["Dot", { radius: 11 }],
                    paintStyle: { fillStyle: color1 },
                    isSource: true,
                    anchor: "Left",
                    scope: "green dot",
                    connectorStyle: { strokeStyle: color1, lineWidth: 6 },
                    connector: ["Straight", { curviness: 63 }],
                    maxConnections: 10,
                    isTarget: true,
                    dropOptions: exampleDropOptions
                };

var color2 = "rgba(229,219,61,0.5)";
                var exampleEndpoint2 = {
                    endpoint: "Rectangle",
                    anchor: "Right",
                    paintStyle: { fillStyle: color2, opacity: 0.5 },
                    isSource: true,
                    scope: ‘yellow dot‘,
                    connectorStyle: { strokeStyle: color2, lineWidth: 4 },
                    connector: "Straight",
                    isTarget: true,
                    dropOptions: exampleDropOptions,
                    beforeDetach: function (conn) {
                        return confirm("Detach connection?");
                    },
                    onMaxConnections: function (info) {
                        alert("Cannot drop connection " + info.connection.id + " : maxConnections has been reached on Endpoint " + info.endpoint.id);
                    }
                };
            });
            function jsPlumbConnect() {
                for (var i = 0; i < vmsporperty.length; i++) {
                    var paintStyleClo;
                    if (vmsporperty[i].type == "vm") {
                        paintStyleClo = { lineWidth: 0.5, strokeStyle: ‘rgb(0,0,0)‘ };
                    }
                    else if (vmsporperty[i].type == "network") {
                        paintStyleClo = { lineWidth: 0.5, strokeStyle: ‘rgb(0,250,154)‘ };
                    }
                    else if (vmsporperty[i].type == "storage") {
                        paintStyleClo = { lineWidth: 0.5, strokeStyle: ‘rgb(184,134,11)‘ };
                    }

jsPlumb.connect({
                        source: vmsporperty[i].Pool + vmsporperty[i].Name,
                        target: source.vms.name,
                        paintStyle: paintStyleClo,
                        endpoint: ["Dot", { radius: 2 }],
                        connector: ["Straight", { curviness: 20 }],
                        endpointStyle: { fillStyle: ‘rgb(243,229,0)‘ },
                        // anchors: ["RightMiddle", [0, (0.2 + i) / 10, 0, 0]],
                        anchors: ["AutoDefault", "Center"],
                        //overlays: [
                        //    ["Label", { label: "VM" + i, location: 0.25 }, "VM" + i]]
                    });

}
            }
        </script>

时间: 2024-09-29 23:01:26

jsplumb作的topology图的相关文章

扩增子图表解读3热图:差异菌、OTU及功能

热图是使用颜色来展示数值矩阵的图形.通常还会结合行.列的聚类分析,以表达实验数据多方面的结果. 热图在生物学领域应用广泛,尤其在高通量测序的结果展示中很流行,如样品-基因表达,样品-OTU相对丰度矩阵非常适合采用热图呈现. 热图优点 因为人读数字需要思考和比较,而对颜色识别能力非常强,采用颜色的深浅代替数据表是非常高效的呈现方式,也便于从中挖掘规律. 热图在非常小的区域展示了大量的基因表达/细菌丰度数据,即可以快速比较组间的变化,同时还可以显示组内每个样品的的丰度,以及组内各样品间的重复情况.

扬州历史上的名家画马之作

▲<八骏图> 戈湘岚 作 <番马图> 金农 作 <马上代书> 李石湖 作 <百骏图>朱沆 作 ▲<沐马图> 顾让 作 今年是农历马年.马不仅是人类忠实的朋友,也是文人墨客笔下常见的表现题材.查寻史籍,我们发现:魏晋南北朝时期已陆续有名家画马的记录,如东晋之史道硕.戴逵,南朝宋之陆探微,南朝齐之毛惠远等皆善画马,还有北朝齐之杨子华更是以画马闻名:盛唐时期,曹霸.韩干画马名垂千古:宋代,以李公麟为代表的画家笔下的骏马骨肉兼备.神理清华:元代,画马第一

【 D3.js 入门系列 --- 9.1 】 饼状图的制作

本人的个人博客为: www.ourd3js.com csdn博客为: blog.csdn.net/lzhlzz 转载请注明出处,谢谢. 这一节用 Layout 做一个饼状图.第9节中说过, Layout 的作用只是转换数据,将不适合图形化的数据转化成适合图形化的数据.现在使用以下数据: var dataset = [ 30 , 10 , 43 , 55 , 13 ]; 这个数据要不能直接用于画饼状图,我们必须通过计算将它转换成角度.这个计算不需要我们手动计算,因为 D3 中提供了 d3.layo

storm学习笔记

Storm学习笔记 一.简介 本文使用的Storm版本为1.0.1 Storm是一个免费开源的分布式实时计算系统,它使得可靠地处理无限的数据流更加容易,可以实时的处理Hadoop的批量任务.Storm简单易用,且支持各种主流的程序语言. Storm有很多适用场景:实时分析.在线机器学习.连续计算.分布式RPC.分布式ETL.易扩展.支持容错,可确保你的数据得到处理,易于构建和操控. 下图是Storm"流式数据处理"的概念图,即数据像水流一样从数据源头源源不断的流出,经过每个节点,每个节

使用jdk的jps、jstack工具检测代码问题,提高程序性能

?? 今天给大家分享怎样利用jdk的jps和jstack工具结合定位代码的问题,提高程序的稳定性.健壮性和性能. 在jdk的bin,目录下面有很多的工具如图: jps.jstack工具介绍: jps: 是JDK1.5提供的一个显示当前所有java进程pid的命令,简单实用,非常适合在linux/unix平台上简单察看当前java进程的一些简单情况. 命令格式:jps [options ] [ hostid ] [options]选项 : -q:仅输出VM标识符,不包括classname,jar

数组指针/指针数组的使用

#include <stdio.h> #include <string.h> #include <iostream> using namespace std; #define M 4 #define N 5 int main() { int m = 4, n = 5; char arr[4][5] = { {'A','B','C','D','E'}, {'F','G','H','I','J'}, {'K','L','M','N','O'}, {'P','Q','R','

翻译经典之《Cisco Lan Switching》第六章(十一):Using Spanning Tree in Real-World Networks

[版权声明:原创翻译文章,翻译水平有限,错误在所难免,翻译作者对文章中存在的错误或遗漏所造成后果不承担任何责任,请谨慎转载.转载请保留本声明及出处:blog.csdn.net/shallnet ,下载该书英文版] 来看一下图6-20更复杂的拓扑,看看STP在实际中是如何应用的. Figure 6-20. A Complex Network with All Links Shown 图6-20为一个由7个交换机连接而成的有高度冗余(也就是环)配置的网络.除了最左端直立的那条10Based链路(开销

一些关于机器视觉的概念

http://blog.csdn.net/douglax/article/details/9528297 视觉引导的运动 如果你的应用需要一个视觉系统来引导机器人,那么必须知道视觉系统与运动系统是如何集成的.对于校准和操作,没集成的运动系统与视觉系统是初步的系统,机械人或机构和视觉系统是分开校准的.在操作中,一台独立的视觉系统根据在视觉坐标系统中的已知位置计算出零件位置的偏移量,然后发指令给机器人的手臂在离初始化编程的拾取位置的偏移量处拾取零件. 由于机器视觉系统可以快速获取大量信息,而且易于自

GXPT(一)——UI设计

通过长时间的积淀,TGB再次开始GXPT模式,JAVA版..NET版两条线同时进行.纯面向对象的底层架构的搭建:easyUI+MVC的界面设计:工作流的再次雄起:云平台的构想:Confluence.jenkins等工具的使用:数据库.UI灵活化的实现--似乎每一块现在都能武装到牙齿. 如果你是这个开发小组中的一员,你会不会感到无比的兴奋,不论你会与不会,反正我会了.或许见笑了,那又有什么办法,大四的我没有见过世面嘛! 万丈高楼平地起.先说说这几日的工作吧.对系统需求的了解,以及UI的设计,理应成