HT for web编辑器实现管道流动

1,340 阅读1分钟
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>测试</title>
    <style>
        html, body {
            padding: 0px;
            margin: 0px;
        }
    </style>
</head>
<body>

</body>
<script src='lib/ht.js'></script>
<script src='lib/ht-dashflow.js'></script>
<script src="index.js"></script>
</html>
js

(function(){
'use strict';
    let gv=window.gv=new ht.graph.GraphView();
     // 反序列化2d的图纸
     <!--使用虚线流动的方式实现-->
gv.deserialize('displays/shanbei.json',(json,dm)=>{
     let guan=dm.getDataByTag('guan')//guan管道的标签名
        guan.s("shape.dash", true);
        guan.s("shape.dash.flow", true);
        guan.s("shape.color", "yellow");
        guan.s("shape.width", 5);
        gv.enableFlow();
        gv.enableDashFlow();
})

<!--使用调度的方法实现-->
 let rotationTask = {
        interval: 200,
        action: function(data){
            let guan=dm.getDataByTag('guan')//shape和edge的区别
            if(data==guan){
                guan.s('shape.dash.offset',data.s('shape.dash.offset')+100);
            }else{
                return
            }

        }
    };
    dm.addScheduleTask(rotationTask);
}())