当前位置: 首页 > news >正文

Gojs渲染实线、虚线

在这里插入图片描述

渲染页面

<template><div><div id="topology-container"></div></div>
</template>

js逻辑渲染实线、虚线

<script>
import go from 'gojs';export default {mounted() {this.initDiagram();},methods: {// 加载initDiagram() {const $ = go.GraphObject.make;const diagram = $(go.Diagram, "topology-container", {initialContentAlignment: go.Spot.Center,"undoManager.isEnabled": true,// layout: $(go.ForceDirectedLayout) // 自动布局});// 节点模板diagram.nodeTemplate = $(go.Node, "Auto",$(go.Shape, {fill: "white",strokeWidth: 2,stroke: "black"},new go.Binding("fill", "status", (status) =>status === "正常" ? "lightgreen" : "lightcoral")),$(go.TextBlock, {margin: 20,stroke: "black",font: "12px sans-serif"},new go.Binding("text", "name")));// 创建模板映射const templmap = new go.Map();const lineColor = "white";// 默认实线模板const defaultTemplate = $(go.Link,{ routing: go.Link.AvoidsNodes },$(go.Shape, {stroke: lineColor,strokeWidth: 2}),$(go.Shape, {toArrow: "Standard",fill: lineColor,stroke: lineColor}));// 虚线模板(带动画支持)const dashedTemplate = $(go.Link,{routing: go.Link.AvoidsNodes,selectionAdorned: false},$(go.Shape, {name: "dashedLink",stroke: "#FFA500",  // 橙色虚线strokeWidth: 3,strokeDashArray: [8, 4]  // 虚线样式}),$(go.Shape, {toArrow: "Standard",fill: "#FFA500",stroke: "#FFA500"}));// 添加到模板映射templmap.add("", defaultTemplate);  // 默认模板templmap.add("dashed", dashedTemplate);  // 虚线模板diagram.linkTemplateMap = templmap;// 节点数据const nodeDataArray = [{ key: 1, name: "遥测处理", status: "正常" },{ key: 2, name: "系统监控", status: "异常" },{ key: 3, name: "拓扑指标1", status: "正常" },{ key: 4, name: "站监控", status: "异常" },{ key: 5, name: "轨道计算管理", status: "正常" },{ key: 6, name: "遥测处理服务器", status: "正常" },{ key: 7, name: "任务编排服务器", status: "正常" },{ key: 8, name: "站监控服务器", status: "异常" },];// 连接数据(使用category指定虚线)const linkDataArray = [{ from: 3, to: 4, category: "solid", id: 2 },{ from: 4, to: 5, category: "dashed", id: 3 },{ from: 5, to: 6, category: "dashed", id: 4 },{ from: 6, to: 7, category: "solid", id: 5 }];diagram.model = new go.GraphLinksModel(nodeDataArray, linkDataArray);// 保存diagram引用到Vue实例this.diagram = diagram;// 虚线动画效果this.animateDashedLinks(diagram);},animateDashedLinks(diagram) {// 找到所有虚线连接const dashedLinks = [];diagram.links.each(link => {if (link.category === "dashed") {dashedLinks.push(link);}});// 为每条虚线添加动画let offset = 0;setInterval(() => {offset = (offset + 2) % 24;  // 24是虚线样式的总长度(8+4)*2dashedLinks.forEach(link => {const shape = link.findObject("dashedLink");if (shape) {shape.strokeDashOffset = offset;}});this.diagram.updateAllTargetBindings();}, 50);},}
};
</script>
<style scoped>
#topology-container {width: 100%;height: 600px;background-color: #3740be;border: 1px solid #ccc;
}
</style>
http://www.xdnf.cn/news/910315.html

相关文章:

  • 单周期cpu和多周期cpu、单周期数据通路和多周期数据通路与总线结构数据通路和专用数据通路的关系
  • JAVA学习 DAY2 java程序运行、注意事项、转义字符
  • 实现echarts全屏的放大/缩小最优解
  • Kyosan K5BMC ELECTRONIC INTERLOCKING MANUAL 电子联锁
  • 【PmHub面试篇】性能监控与分布式追踪利器Skywalking面试专题分析
  • pp-ocrv5改进
  • 核弹级漏洞深度解析:Log4j2 JNDI注入攻击原理与防御实战
  • [IMX][UBoot] 01.UBoot 常用命令
  • 【八股消消乐】MySQL参数优化大汇总
  • 使用 Python 和 HuggingFace Transformers 进行对象检测
  • xpath表达式的常用知识点
  • K7 系列各种PCIE IP核的对比
  • 每日算法 -【Swift 算法】电话号码字母组合
  • Keil调试模式下,排查程序崩溃简述
  • 六、【ESP32开发全栈指南:深入解析ESP32 IDF中的WiFi AP模式开发】
  • 读《创新者的窘境》二分 - 破坏性创新与延续性创新
  • 飞牛使用Docker部署Tailscale 内网穿透教程
  • KL散度计算示例:用户画像 vs. 专辑播放分布的性别偏好分析
  • MySQL查询语句
  • 02 nginx 的环境搭建
  • 禅道5月更新速览 | 新增交付物配置功能,支持建立跨执行任务依赖关系,研发效能平台上线
  • 6个可提升社媒投资回报率的Facebook KPI
  • 基于tensorflow实现的猫狗识别
  • 配置git命令缩写
  • 学习记录aigc
  • 智能制造数字孪生全要素交付一张网:智造中枢,孪生领航,共建智造生态共同体
  • Verilog编程技巧01——如何编写三段式状态机
  • 数论——同余问题全家桶3 __int128和同余方程组
  • Linux非管理员用户安装python环境
  • Ubuntu创建修改 Swap 文件分区的步骤——解决嵌入式开发板编译ROS2程序卡死问题