Browse Source

fix: 去除调试节点

sy-water-data-board-ui
chenhaojie 1 year ago
parent
commit
764ff63329
  1. 97
      src/utils/JSONData.js
  2. 1
      src/views/aiSupervision/waterSetting/runScene/detail/index.vue
  3. 215
      src/views/system/testD3/index.vue

97
src/utils/JSONData.js

@ -1,7 +1,8 @@
import * as d3 from 'd3';
let colorNumber = 0;
const colorScale = d3.scaleOrdinal(d3.schemePaired);// 颜色列表
function isEqualJSON(a, b) { // 判断a,b是否完全一致
const colorScale = d3.scaleOrdinal(d3.schemePaired); // 颜色列表
function isEqualJSON(a, b) {
// 判断a,b是否完全一致
// 局限性:
// 如果对象里属性的位置发生变化,转换来的字符串就不相等
// 但实际我们只需要看他们的内容是否一致,与顺序没有关系,所以这种方法有局限性。
@ -12,7 +13,8 @@ function isEqualJSON(a, b) { // 判断a,b是否完全一致
}
return false;
}
function breadthTraverse(d, c) { // 广度遍历
function breadthTraverse(d, c) {
// 广度遍历
if (d.children) {
for (let index = 0; index < d.children.length; index += 1) {
const dChild = d.children[index];
@ -29,7 +31,8 @@ function breadthTraverse(d, c) { // 广度遍历
}
}
}
function inheritColor(d, c) { // 赋予新颜色,并更新子节点的颜色
function inheritColor(d, c) {
// 赋予新颜色,并更新子节点的颜色
if (d.children) {
for (let index = 0; index < d.children.length; index += 1) {
const dChild = d.children[index];
@ -39,14 +42,16 @@ function inheritColor(d, c) { // 赋予新颜色,并更新子节点的颜色
}
}
class JSONData {
constructor(d) { // d为数组
this.data = JSON.parse(JSON.stringify(d));// 深拷贝对象
constructor(d) {
// d为数组
this.data = JSON.parse(JSON.stringify(d)); // 深拷贝对象
breadthTraverse(this.data[0]);
this._addId();
console.log(this.data[0])
console.log(this.data[0]);
}
_addId(ides = '', d = this.data) { // 添加唯一标识
_addId(ides = '', d = this.data) {
// 添加唯一标识
for (let index = 0; index < d.length; index += 1) {
const dChild = d[index];
dChild.ides = `${ides}${index}`;
@ -77,7 +82,8 @@ class JSONData {
return d;
}
del(s) { // 删除s
del(s) {
// 删除s
const parent = this.getParent(s);
if (parent) {
const children = parent.children;
@ -96,7 +102,7 @@ class JSONData {
getItself(d, data = this.data) {
let dSelf = data;
const ides = d.ides.split('').map(s => parseInt(s, 10));
const ides = d.ides.split('').map((s) => parseInt(s, 10));
if (ides.length > 0) {
for (let index = 0; index < ides.length - 1; index++) {
const number = ides[index];
@ -108,9 +114,11 @@ class JSONData {
return false;
}
add(dParent, d) { // dParent添加子节点d
add(dParent, d) {
// dParent添加子节点d
const parent = this.getItself(dParent);
if (parent.ides === '0') { // 根节点
if (parent.ides === '0') {
// 根节点
if (!d.color) {
d.color = colorScale(colorNumber);
colorNumber += 1;
@ -126,7 +134,7 @@ class JSONData {
getParent(d, data = this.data) {
let dParent = data;
const ides = d.ides.split('').map(s => parseInt(s, 10));
const ides = d.ides.split('').map((s) => parseInt(s, 10));
ides.pop();
if (ides.length > 0) {
for (let index = 0; index < ides.length - 1; index++) {
@ -139,8 +147,8 @@ class JSONData {
return false;
}
insert(dPosition, d, i = 0) { // 把d插入到dPosition的前面(i=0)或者后面(i=1)
debugger
insert(dPosition, d, i = 0) {
// 把d插入到dPosition的前面(i=0)或者后面(i=1)
const parent = this.getParent(dPosition);
if (parent) {
const children = parent.children;
@ -152,8 +160,10 @@ class JSONData {
position = index;
}
}
if ((position+i) < children.length) { // 更新id
if (parent.ides === '0') { // 根节点
if (position + i < children.length) {
// 更新id
if (parent.ides === '0') {
// 根节点
if (!d.color) {
d.color = colorScale(colorNumber);
colorNumber += 1;
@ -162,52 +172,57 @@ class JSONData {
d.color = parent.color; // 继承父节点的color
}
children.splice(position + i, 0, d);
this._addId(parent.ides, children)
this._addId(parent.ides, children);
} else {
this.add(parent, d);
}
}
}
collapse(mid) { // 折叠
const arr = Array.isArray(mid) ? mid : [mid]
collapse(mid) {
// 折叠
const arr = Array.isArray(mid) ? mid : [mid];
for (let i = 0; i < arr.length; i++) {
const idChild = arr[i]
const d = this.find(idChild)
const idChild = arr[i];
const d = this.find(idChild);
if (d && (!d._children || d._children.length === 0) && !d.collapse) {
d.collapse = true
d._children = d.children
d.children = []
d.collapse = true;
d._children = d.children;
d.children = [];
}
}
}
expand(mid) { // 展开
const arr = Array.isArray(mid) ? mid : [mid]
expand(mid) {
// 展开
const arr = Array.isArray(mid) ? mid : [mid];
for (let i = 0; i < arr.length; i++) {
const idChild = arr[i]
const d = this.find(idChild)
const idChild = arr[i];
const d = this.find(idChild);
if (d && (!d.children || d.children.length === 0) && d.collapse) {
// console.log('展开', d)
d.collapse = false
d.children = d._children
d._children = []
d.collapse = false;
d.children = d._children;
d._children = [];
}
}
}
find(mid) { // 根据id找到数据
const array = mid.split('-').map(n => ~~n)
let data = this.data
find(mid) {
// 根据id找到数据
const array = mid.split('-').map((n) => ~~n);
let data = this.data;
for (let i = 1; i < array.length; i++) {
if (data && data.children?.length) {
data = data.children[array[i]]
} else if (data && data._children?.length) { // No data matching mid
data = data._children[array[i]]
} else { // No data matching mid
return null
data = data.children[array[i]];
} else if (data && data._children?.length) {
// No data matching mid
data = data._children[array[i]];
} else {
// No data matching mid
return null;
}
}
return data
return data;
}
}

1
src/views/aiSupervision/waterSetting/runScene/detail/index.vue

@ -92,7 +92,6 @@ export default {
tableData: {
handler(val) {
this.checkedKeys = [];
debugger;
val?.forEach((item) => {
this.checkedKeys.push(item.id);
});

215
src/views/system/testD3/index.vue

@ -1,7 +1,7 @@
<template>
<div style="position: relative">
<!--width,height 画布的宽度高度 可以是百分比或像素一般在dom元素上设置 -->
<div id="network_id" class="network" style="height:80vh"></div>
<div id="network_id" class="network" style="height: 80vh"></div>
<!-- <div class="type-box" v-if="labelList && labelList.length">-->
<!-- <el-radio-group v-model="type" @change="initRelation" style="width: 150px;">-->
<!-- <el-radio label="" style="width: 120px;display: block;margin-right: 0px;margin: 5px 0px">-->
@ -44,33 +44,33 @@
</div>
</template>
<script>
import Vis from "vis";
import Vis from 'vis';
export default {
name: "vis-graph",
name: 'vis-graph',
props: {
relationsView: {
type: Object,
default() {
return {}
return {};
}
},
showTools: {
type: Boolean,
default() {
return true
return true;
}
},
labelList: {
type: Array,
default() {
return []
return [];
}
},
colorMap: {
type: Map,
default() {
return new Map()
return new Map();
}
}
},
@ -93,14 +93,14 @@ export default {
edgesArray: [],
options: {},
data: {},
isInit: false,
isInit: false
};
},
methods: {
deleteRelation() {
if (this.currentId) {
this.$emit("deleteRelation", this.currentId);
this.hideCircle()
this.$emit('deleteRelation', this.currentId);
this.hideCircle();
}
},
deleteNode() {
@ -111,34 +111,32 @@ export default {
this.dataSet = new Set();
this.linkSet = new Set();
let _this = this;
links.forEach(d => {
links.forEach((d) => {
if (!_this.linkSet.has(d.id)) {
_this.edgesArray.push({
to: d.to,
from: d.from,
label: d.properties ? d.properties.name : "",
'arrows': 'to',
label: d.properties ? d.properties.name : '',
arrows: 'to',
id: d.id
})
});
_this.linkSet.add(d.id);
}
})
datas.forEach(d => {
});
datas.forEach((d) => {
if (!_this.dataSet.has(d.id)) {
_this.nodesArray.push({
id: d.id,
labelId: d.labelId,
label: d.name, color: {background: _this.colorMap.get(d.labelId)}
label: d.name,
color: { background: _this.colorMap.get(d.labelId) }
});
_this.dataSet.add(d.id);
}
})
});
_this.init();
},
init() {
debugger
if (this.network) {
this.network.destroy();
}
@ -147,14 +145,14 @@ export default {
_this.nodes = new Vis.DataSet(_this.nodesArray);
//2.edges
_this.edges = new Vis.DataSet(_this.edgesArray);
_this.container = document.getElementById("network_id");
_this.container = document.getElementById('network_id');
_this.data = {
nodes: _this.nodes,
edges: _this.edges
};
_this.options = {
autoResize: true, //
locale: "cn", //
locale: 'cn', //
// configure:{
// showButton: true
// },
@ -162,18 +160,18 @@ export default {
locales: {
cn: {
//
edit: "编辑",
del: "删除当前节点或关系",
back: "返回",
addNode: "添加节点",
addEdge: "添加连线",
editNode: "编辑节点",
editEdge: "编辑连线",
addDescription: "点击空白处可添加节点",
edgeDescription: "点击某个节点拖拽连线可连接另一个节点",
editEdgeDescription: "可拖拽连线改变关系",
createEdgeError: "无法将边连接到集群",
deleteClusterError: "无法删除集群.",
edit: '编辑',
del: '删除当前节点或关系',
back: '返回',
addNode: '添加节点',
addEdge: '添加连线',
editNode: '编辑节点',
editEdge: '编辑连线',
addDescription: '点击空白处可添加节点',
edgeDescription: '点击某个节点拖拽连线可连接另一个节点',
editEdgeDescription: '可拖拽连线改变关系',
createEdgeError: '无法将边连接到集群',
deleteClusterError: '无法删除集群.',
editClusterError: "无法编辑群集'"
}
},
@ -183,34 +181,34 @@ export default {
myGroupId: {},
ws: {
// dot
shape: "dot",
color: "white"
shape: 'dot',
color: 'white'
}
},
//
nodes: {
//circlelabeldotlabel
shape: "dot",
shape: 'dot',
size: 50,
fixed: false,
font: {
//
size: 24,
size: 24
//
// vadjust:-75
},
color: {
border: "#2B7CE9", //
background: "#97C2FC", //
border: '#2B7CE9', //
background: '#97C2FC', //
highlight: {
//
border: "#2B7CE9",
background: "#D2E5FF"
border: '#2B7CE9',
background: '#D2E5FF'
},
hover: {
//
border: "#2B7CE9",
background: "#D2E5FF"
border: '#2B7CE9',
background: '#D2E5FF'
}
},
mass: 5,
@ -224,10 +222,10 @@ export default {
width: 1,
length: 260,
color: {
color: "#848484",
highlight: "#848484",
hover: "#848484",
inherit: "from",
color: '#848484',
highlight: '#848484',
hover: '#848484',
inherit: 'from',
opacity: 1.0
},
shadow: true,
@ -235,7 +233,7 @@ export default {
//线
enabled: true //truefalse线线线
},
arrows: {to: true} //to
arrows: { to: true } //to
},
//
physics: {
@ -272,11 +270,7 @@ export default {
}
};
_this.network = new Vis.Network(
_this.container,
_this.data,
_this.options
);
_this.network = new Vis.Network(_this.container, _this.data, _this.options);
},
resetAllNodes() {
@ -290,11 +284,7 @@ export default {
edges: _this.edges
};
// network线
_this.network = new Vis.Network(
_this.container,
_this.data,
_this.options
);
_this.network = new Vis.Network(_this.container, _this.data, _this.options);
},
resetAllNodesStabilize() {
let _this = this;
@ -303,65 +293,61 @@ export default {
},
parentDeleteRelation(id) {
console.log(id);
this.edgesArray = this.edgesArray.filter(row => row.id != id)
this.edgesArray = this.edgesArray.filter((row) => row.id != id);
console.log(this.data.edges);
this.data.edges.remove(id)
this.data.edges.remove(id);
console.log(this.data.edges);
this.linkSet.delete(id)
this.linkSet.delete(id);
},
addDatas(datas) {
let _this = this;
if (datas.nodes && datas.nodes.length > 0) {
datas.links.forEach(d => {
datas.links.forEach((d) => {
if (!_this.linkSet.has(d.id)) {
_this.linkSet.add(d.id);
let link = {
to: d.to,
from: d.from,
label: d.properties ? d.properties.name : "",
'arrows': 'to',
label: d.properties ? d.properties.name : '',
arrows: 'to',
id: d.id
};
_this.edgesArray.push(link)
_this.data.edges.add(link)
_this.edgesArray.push(link);
_this.data.edges.add(link);
}
})
datas.nodes.forEach(d => {
});
datas.nodes.forEach((d) => {
if (!_this.dataSet.has(d.id)) {
_this.dataSet.add(d.id);
let node = {
id: d.id,
labelId: d.labelId,
label: d.name, color: {background: _this.colorMap.get(d.labelId)}
}
label: d.name,
color: { background: _this.colorMap.get(d.labelId) }
};
_this.nodesArray.push(node);
_this.data.nodes.add(node);
}
})
});
}
},
addOneNode() {
if (this.currentId) {
this.$emit("nextNode", this.currentId);
this.$emit('nextNode', this.currentId);
}
},
addRelation() {
if (this.currentId) {
this.$emit("addNode", this.currentId);
this.$emit('addNode', this.currentId);
}
},
editNode() {
this.$emit("updateNode", this.currentId)
this.hideCircle()
this.$emit('updateNode', this.currentId);
this.hideCircle();
},
toDetail() {
this.$emit("toDetail", this.currentId)
this.$emit('toDetail', this.currentId);
},
//
setCirclePosition() {
@ -369,14 +355,16 @@ export default {
// this.domPosi["y"] + 10,
// this.scale + 0.4
let circle = document.getElementById("circle-option");
circle.style = `left: ${this.domPosi["x"] - 50}px; top: ${this.domPosi["y"] - 50}px;transform:scale(${this.scale * 2.5});display:block;`;
let circle = document.getElementById('circle-option');
circle.style = `left: ${this.domPosi['x'] - 50}px; top: ${this.domPosi['y'] - 50}px;transform:scale(${
this.scale * 2.5
});display:block;`;
},
//
hideCircle() {
let circle = document.getElementById("circle-option");
let circle = document.getElementById('circle-option');
circle.style = `display:none;`;
},
}
},
watch: {
domPosi(newval) {
@ -395,15 +383,15 @@ export default {
}
},
deep: true,
immediate: true,
immediate: true
},
labelList: {
handler(newVal) {
this.labelList = newVal;
},
deep: true,
immediate: true,
},
immediate: true
}
},
mounted() {
//
@ -411,38 +399,38 @@ export default {
this.init();
this.network.on("stabilized", param => {
this.network.on('stabilized', (param) => {
// console.log("", param)
})
this.network.on("zoom", param => {
});
this.network.on('zoom', (param) => {
if (this.currentId) {
let circle = document.getElementById("circle-option");
if ("none" !== circle.style.display) {
let circle = document.getElementById('circle-option');
if ('none' !== circle.style.display) {
this.scale = param.scale;
let p = this.network.getPositions(this.currentId);
// this.scale = _this.network.getScale();
this.domPosi = this.network.canvasToDOM({
x: p[this.currentId]["x"],
y: p[this.currentId]["y"],
x: p[this.currentId]['x'],
y: p[this.currentId]['y']
});
}
} else {
this.hideCircle();
}
})
this.network.on("dragStart", param => {
});
this.network.on('dragStart', (param) => {
// this.currentId = param.nodes[0]
this.isInit = false;
this.hideCircle();
})
this.network.on("dragEnd", param => {
});
this.network.on('dragEnd', (param) => {
if (param.nodes && param.nodes.length > 0) {
this.network.clustering.updateClusteredNode(param.nodes[0], {physics: false});
this.network.clustering.updateClusteredNode(param.nodes[0], { physics: false });
}
this.hideCircle();
})
});
//
this.network.on("click", params => {
this.network.on('click', (params) => {
if (!this.showTools) {
return;
}
@ -450,32 +438,32 @@ export default {
let _this = this;
if (params.nodes && params.nodes.length > 0) {
_this.currentId = params.nodes[0];
_this.network.clustering.updateClusteredNode(_this.currentId, {physics: false});
if (_this.currentId) { //
_this.network.clustering.updateClusteredNode(_this.currentId, { physics: false });
if (_this.currentId) {
//
// _this.network.
let p = _this.network.getPositions(_this.currentId);
_this.scale = _this.network.getScale();
_this.domPosi = _this.network.canvasToDOM({
x: p[_this.currentId]["x"],
y: p[_this.currentId]["y"],
x: p[_this.currentId]['x'],
y: p[_this.currentId]['y']
});
// ;
_this.setCirclePosition();
$(".custom-menu").hide();
$('.custom-menu').hide();
} else {
this.hideCircle();
}
} else if (params.edges && params.edges.length) {
} else {
this.hideCircle();
$(".custom-menu").hide();
$('.custom-menu').hide();
}
});
}
};
</script>
<style lang="scss">
.circle-option {
position: absolute;
left: 0px;
@ -560,12 +548,13 @@ export default {
}
.custom-menu div a {
font-family: "微软雅黑";
font-family: '微软雅黑';
font-size: 14px;
color: rgb(255, 255, 255);
}
.custom-menu div a:HOVER, .custom-menu div a:ACTIVE {
.custom-menu div a:hover,
.custom-menu div a:active {
cursor: pointer;
color: orange;
}

Loading…
Cancel
Save