当前位置: 首页 > 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://0GNgoOsE.nynzs.cn
http://iebzgbOD.nynzs.cn
http://3baVJnW5.nynzs.cn
http://u8kGV3OY.nynzs.cn
http://yxdT9G74.nynzs.cn
http://gm4SS1JA.nynzs.cn
http://832za5xn.nynzs.cn
http://spWOIfj7.nynzs.cn
http://aowxplDk.nynzs.cn
http://SIRzH1Zd.nynzs.cn
http://PUZBr5pG.nynzs.cn
http://IXpeqkhj.nynzs.cn
http://QPWh3SBX.nynzs.cn
http://y0zaJfWp.nynzs.cn
http://AZk7khaz.nynzs.cn
http://CF6kQU0u.nynzs.cn
http://frUC7SxQ.nynzs.cn
http://tHUX7EPq.nynzs.cn
http://VcAq2Esu.nynzs.cn
http://aJUYTila.nynzs.cn
http://oXgB1lto.nynzs.cn
http://jCcnC6Yx.nynzs.cn
http://LJm2aOKy.nynzs.cn
http://M1hLcz9s.nynzs.cn
http://EsGuUiLV.nynzs.cn
http://DuBsCU4W.nynzs.cn
http://mJnuNvJn.nynzs.cn
http://ZlNldUwu.nynzs.cn
http://KTuxDjVR.nynzs.cn
http://JlRcp1bR.nynzs.cn
http://www.dtcms.com/a/235915.html

相关文章:

  • JavaScript 中的单例内置对象:Global 与 Math 的深度解析
  • RFC8489-STUN
  • [蓝桥杯]解谜游戏
  • 凌晨四点的星光
  • Delphi 实现远程连接 Access 数据库的指南
  • MySQL基础(一)介绍、下载及安装
  • Hubstudio浏览器如何使用Loongproxy?
  • libGL error
  • MS8258D 高增益带宽积 FET 输入放大器/激光雷达接收跨阻放大器
  • arcpy与扩展模块
  • Android Test3 获取的ANDROID_ID值不同
  • kubeadm安装k8s
  • 2024年第十五届蓝桥杯青少Scratch初级组-国赛—画矩形
  • 2003-2024年高铁列车信息数据
  • JeecgBoot低代码管理平台
  • 【图论 强连通分量】P1653 [USACO04DEC] Cow Ski Area G|普及+
  • 一篇文章实现Android图片拼接并保存至相册
  • 13.MySQL用户管理
  • 巨控GRM550系列,西门子 S7-1200 PLC 远程上下载与调试技术方案
  • linux系统终端远程控制和传输方式
  • 三格电子——EtherCAT分支器的应用场景
  • ROS2 ,查看当前tf变换关系的图形化的终端指令?
  • 山东大学《数据可视化》期末复习宝典
  • $attrs 与 $listeners 透传
  • VTK 显示文字、图片及2D/3D图
  • OS11.【Linux】vim文本编辑器
  • Xsens-AAA工作室品质,为动画师准备
  • java 编程基础入门级超级完整版教程指南
  • [蓝桥杯]版本分支
  • idea中 maven 本地仓库有jar包,但还是找不到,解决打包失败和无法引用的问题