|
@@ -0,0 +1,270 @@
|
|
|
+<template>
|
|
|
+ <div style="position: relative">
|
|
|
+ <div :id="goid" :style="{ height: height }"></div>
|
|
|
+ </div>
|
|
|
+</template>
|
|
|
+<script>
|
|
|
+import pic01 from "../../../assets/images/bg.webp";
|
|
|
+import pic02 from "../../../assets/images/bg.webp";
|
|
|
+import icon1 from "../../../assets/images/bg.webp";
|
|
|
+import icon2 from "../../../assets/images/bg.webp";
|
|
|
+import go from "gojs";
|
|
|
+export default {
|
|
|
+ name: "ForceGuideChart",
|
|
|
+ props: {
|
|
|
+ dataList: {
|
|
|
+ type: Array,
|
|
|
+ required: true,
|
|
|
+ },
|
|
|
+ linkList: {
|
|
|
+ type: Array,
|
|
|
+ required: true,
|
|
|
+ },
|
|
|
+ modelParts: {
|
|
|
+ type: Array,
|
|
|
+ // required: true,
|
|
|
+ },
|
|
|
+ goid: {
|
|
|
+ type: String,
|
|
|
+ required: true,
|
|
|
+ },
|
|
|
+ dataTaskId: {
|
|
|
+ type: String | Number,
|
|
|
+ required: true,
|
|
|
+ },
|
|
|
+ height: {
|
|
|
+ type: String,
|
|
|
+ default() {
|
|
|
+ return "calc(50vh )";
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ data() {
|
|
|
+ return {
|
|
|
+ myDiagram: "",
|
|
|
+ };
|
|
|
+ },
|
|
|
+ watch: {
|
|
|
+ dataList: {
|
|
|
+ handler(newVal) {
|
|
|
+ if (newVal.length > 0) {
|
|
|
+ this.reloadModel();
|
|
|
+ }
|
|
|
+ },
|
|
|
+ immediate: true,
|
|
|
+ deep: true,
|
|
|
+ },
|
|
|
+ },
|
|
|
+ mounted() {
|
|
|
+ this.goInit();
|
|
|
+ },
|
|
|
+ methods: {
|
|
|
+ goInit() {
|
|
|
+ let _this = this;
|
|
|
+ let gm = go.GraphObject.make;
|
|
|
+ function ContinuousForceDirectedLayout() {
|
|
|
+ go.ForceDirectedLayout.call(this);
|
|
|
+ this._isObserving = false;
|
|
|
+ }
|
|
|
+ go.Diagram.inherit(ContinuousForceDirectedLayout, go.ForceDirectedLayout);
|
|
|
+ ContinuousForceDirectedLayout.prototype.isFixed = function (v) {
|
|
|
+ return v.node.isSelected;
|
|
|
+ };
|
|
|
+ ContinuousForceDirectedLayout.prototype.doLayout = function (coll) {
|
|
|
+ if (!this._isObserving) {
|
|
|
+ this._isObserving = true;
|
|
|
+ let lay = this;
|
|
|
+ this.diagram.addModelChangedListener(function (e) {
|
|
|
+ if (
|
|
|
+ e.modelParts !== "" ||
|
|
|
+ (e.change == go.ChangedEvent.Transaction &&
|
|
|
+ e.propertyName === "StartingFirstTransaction")
|
|
|
+ ) {
|
|
|
+ lay.network = null;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ let net = this.network;
|
|
|
+ if (net === null) {
|
|
|
+ this.network = net = this.makeNetwork(coll);
|
|
|
+ } else {
|
|
|
+ this.diagram.nodes.each(function (n) {
|
|
|
+ let v = net.findVertex(n);
|
|
|
+ if (v !== null) v.bounds = n.actualBounds;
|
|
|
+ });
|
|
|
+ }
|
|
|
+ go.ForceDirectedLayout.prototype.doLayout.call(this, coll);
|
|
|
+ this.network = net;
|
|
|
+ };
|
|
|
+
|
|
|
+ _this.myDiagram = gm(go.Diagram, _this.goid, {
|
|
|
+ initialAutoScale: go.Diagram.Uniform,
|
|
|
+ contentAlignment: go.Spot.Center,
|
|
|
+ layout: gm(ContinuousForceDirectedLayout, {
|
|
|
+ defaultSpringLength: 30,
|
|
|
+ defaultElectricalCharge: 100,
|
|
|
+ }),
|
|
|
+ SelectionMoved: function (e) {
|
|
|
+ e.diagram.layout.invalidateLayout();
|
|
|
+ },
|
|
|
+ });
|
|
|
+ _this.myDiagram.toolManager.draggingTool.doMouseMove = function () {
|
|
|
+ go.DraggingTool.prototype.doMouseMove.call(this);
|
|
|
+ if (this.isActive) {
|
|
|
+ this.diagram.layout.invalidateLayout();
|
|
|
+ }
|
|
|
+ };
|
|
|
+ let myContextMenu = gm(
|
|
|
+ "ContextMenu",
|
|
|
+ gm(
|
|
|
+ "ContextMenuButton",
|
|
|
+ gm(go.TextBlock, "交互诊断", {
|
|
|
+ alignment: go.Spot.Center,
|
|
|
+ margin: 10,
|
|
|
+ font: "16px 500 sans-serif",
|
|
|
+ opacity: 0.75,
|
|
|
+ stroke: "#404040",
|
|
|
+ }),
|
|
|
+ {
|
|
|
+ click: function (e, obj) {
|
|
|
+ _this.handleInteractive(e, obj);
|
|
|
+ },
|
|
|
+ }
|
|
|
+ )
|
|
|
+ );
|
|
|
+ _this.myDiagram.nodeTemplate = gm(
|
|
|
+ go.Node,
|
|
|
+ "Vertical",
|
|
|
+ {
|
|
|
+ selectionObjectName: "BODY",
|
|
|
+ deletable: false,
|
|
|
+ },
|
|
|
+ gm(
|
|
|
+ go.Panel,
|
|
|
+ "Auto",
|
|
|
+ { name: "BODY" },
|
|
|
+ { contextMenu: myContextMenu },
|
|
|
+ gm(
|
|
|
+ go.Panel,
|
|
|
+ go.Panel.Auto,
|
|
|
+ gm(
|
|
|
+ go.Picture,
|
|
|
+ new go.Binding("width", "category", _this.nodeTypeImageWidth),
|
|
|
+ new go.Binding("height", "category", _this.nodeTypeImageHeight),
|
|
|
+ new go.Binding("source", "diagnosisStatus", _this.nodeTypeImage)
|
|
|
+ )
|
|
|
+ ),
|
|
|
+ gm(
|
|
|
+ go.Panel,
|
|
|
+ go.Panel.Auto,
|
|
|
+ gm(
|
|
|
+ go.Panel,
|
|
|
+ "Horizontal",
|
|
|
+ gm(
|
|
|
+ go.Picture,
|
|
|
+ { margin: 5, width: 20, height: 20 },
|
|
|
+ new go.Binding("source", "category", _this.nodeIconImage)
|
|
|
+ ),
|
|
|
+ gm(
|
|
|
+ go.TextBlock,
|
|
|
+ {
|
|
|
+ font: "700 12px Droid Serif,sans-serif",
|
|
|
+ textAlign: "center",
|
|
|
+ maxSize: new go.Size(70, NaN),
|
|
|
+ },
|
|
|
+ new go.Binding("text", "name")
|
|
|
+ )
|
|
|
+ )
|
|
|
+ )
|
|
|
+ )
|
|
|
+ );
|
|
|
+
|
|
|
+ _this.myDiagram.linkTemplate = gm(
|
|
|
+ go.Link,
|
|
|
+ { routing: go.Link.AvoidsNodes },
|
|
|
+ { deletable: false, corner: 0 },
|
|
|
+ gm(go.Shape, { strokeWidth: 1, stroke: "rgb(135,195,255)" }),
|
|
|
+ gm(go.Shape, { toArrow: 1, stroke: "rgb(135,195,255)" }),
|
|
|
+ gm(
|
|
|
+ go.TextBlock,
|
|
|
+ go.Link.OrientUpright,
|
|
|
+ {
|
|
|
+ background: "rgb(135,195,255)",
|
|
|
+ visible: false,
|
|
|
+ segmentIndex: -2,
|
|
|
+ segmentOrientation: go.Link.None,
|
|
|
+ },
|
|
|
+ new go.Binding("text", "answer"),
|
|
|
+ new go.Binding("visible", "answer", function (a) {
|
|
|
+ return !!a;
|
|
|
+ })
|
|
|
+ )
|
|
|
+ );
|
|
|
+ let nodeDataArray = _this.dataList;
|
|
|
+ let linkDataArray = _this.linkList;
|
|
|
+
|
|
|
+ _this.myDiagram.model = new go.GraphLinksModel(
|
|
|
+ nodeDataArray,
|
|
|
+ linkDataArray
|
|
|
+ );
|
|
|
+
|
|
|
+ _this.myDiagram.addDiagramListener("ChangeSelection", function (e) {
|
|
|
+ if (_this.myDiagram.selection.iterator.count === 0) {
|
|
|
+ _this.$emit("unselectNode");
|
|
|
+ } else {
|
|
|
+ let selection = _this.myDiagram.selection.iterator.first();
|
|
|
+ const paths = _this.getPaths(selection.data);
|
|
|
+ _this.$emit("selectNode", selection.data, paths);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ },
|
|
|
+ reloadModel() {
|
|
|
+ if (this.myDiagram) {
|
|
|
+ this.myDiagram.model = new go.GraphLinksModel(
|
|
|
+ this.dataList,
|
|
|
+ this.linkList
|
|
|
+ );
|
|
|
+ }
|
|
|
+ },
|
|
|
+ nodeTypeImageWidth(category) {
|
|
|
+ if (category === "system") return 120;
|
|
|
+ else if (category === "unit") return 120;
|
|
|
+ },
|
|
|
+ nodeTypeImageHeight(category) {
|
|
|
+ if (category === "system") return 90;
|
|
|
+ else if (category === "unit") return 50;
|
|
|
+ },
|
|
|
+ genderBrushConverter(diagnosisStatus) {
|
|
|
+ if (diagnosisStatus === 0) return "#90caf9";
|
|
|
+ if (diagnosisStatus === 1) return "#f48fb1";
|
|
|
+ return "orange";
|
|
|
+ },
|
|
|
+ nodeTypeImage(diagnosisStatus) {
|
|
|
+ if (diagnosisStatus > 0) return pic02;
|
|
|
+ else return pic01;
|
|
|
+ },
|
|
|
+ nodeIconImage(category) {
|
|
|
+ if (category === "system") return icon1;
|
|
|
+ else if (category === "unit") return icon2;
|
|
|
+ },
|
|
|
+ nodeTypeWidth(category) {
|
|
|
+ if (category === "system") return "150 50";
|
|
|
+ else if (category === "unit") return "100 100";
|
|
|
+ },
|
|
|
+ handleDiaSync(e, obj) {
|
|
|
+ console.log(obj);
|
|
|
+ },
|
|
|
+ getPaths(data) {
|
|
|
+ console.log(data);
|
|
|
+ },
|
|
|
+ handleMechanism(e, obj) {
|
|
|
+ console.log(e, obj);
|
|
|
+ },
|
|
|
+ handleInteractive(e, obj) {
|
|
|
+ console.log(e, obj);
|
|
|
+ },
|
|
|
+ },
|
|
|
+};
|
|
|
+</script>
|
|
|
+<style scoped lang="scss"></style>
|