基于CytoScape.js的可视化研究

这个过程相当痛苦,网上基本没有多少教程,完全摸索,到这里已经接近绝望,json数据读取失败,数据库更是奢望,只好嵌入进网页,以后接着解决

<!DOCTYPE html>
<html lang="en">
<head>

    <meta charset="UTF-8">
    <title>Learning Cytoscape.js</title>
    <style type="text/css">
        /* cytoscape graph */
        #cy {
            height: 600px;
            width: 800px;
            background-color: #f9f9f9;
        }
    </style>
    <script src="http://cdn.bootcss.com/jquery/1.11.2/jquery.min.js"></script>
    <script src="http://cdn.bootcss.com/cytoscape/2.3.16/cytoscape.min.js"></script>
    <script src="https://cdn.bootcss.com/cytoscape/3.2.3/cytoscape.js"></script>
    <script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.js"></script>
    <script src="https://cdn.bootcss.com/arbor/0.91.0/arbor.js"></script>
</head>
<body>
<div id="cy"></div>
</body>
<script type="text/javascript" src="data.js" charset="UTF-8">

    $(function(){
        cytoscape({
            container: document.getElementById('cy'),
            style: [
                { selector: 'node[label = "药物"]',
                    css: {'background-color': '#6FB1FC', 'content': 'data(name)'}
                },
                { selector: 'node[label = "疾病"]',
                    css: {'background-color': '#F5A45D', 'content': 'data(title)'}
                },
                { selector: 'edge',
                    css: {
                        'content': 'data(relationship)',
                        'target-arrow-shape': 'triangle',
                        'color':'red',
                        'targetArrowColor':'blue',
                        'line-color':'green'
                    }
                }
            ],
            charset: 'UTF-8',
//            elements: ele,
            layout: { name: 'grid'}
        });
    });
    var cy = $("#cy").cytoscape("get");


    for(i=0;i<nodes.size();i++){
        var tmpId = nodes.get(i).getid();
        var tmpName = nodes.get(i).getname();
        var tmpType = nodes.get(i).getWeight();
        cy.add({group: "nodes", data: { id: tmpId, name: tmpName , label: tmpType}});
    }
    for(i=0;i<edges.size();i++){
        var tmpSource=edges.get(i).getSource();
        var tmpTarget=edges.get(i).getTarget();
        cy.add({ group: "edges", data: { source: tmpSource, target: tmpTarget } });
    }
    options = {
        name: 'circle',
        fit: true, // whether to fit the viewport to the graph
        ready: undefined, // callback on layoutready
        stop: undefined, // callback on layoutstop
        rStepSize: 10, // the step size for increasing the radius if the nodes don't fit on screen
        padding: 30, // the padding on fit
        startAngle: 3/2 * Math.PI, // the position of the first node
        counterclockwise: false // whether the layout should go counterclockwise (true) or clockwise (false)
    };
    cy.layout( options );
</script>
</html>

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值