wente
2024-10-31 a7892d2ab77735063408c24be9bddfba01740e1d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
<template>
    <div id="timeDiagramThumbnail"></div>
</template>
 
<script>
  import {Graph, Shape, Addon, Cell} from '@antv/x6'
 
  export default {
    name: "timeDiagramThumbnail",
    data(){
      return{
        thumbnailGraph:null,
        smallWidth:0,
        targetNode:{},
      }
    },
    methods:{
      init() {
        console.log(document.documentElement.clientWidth, 'document.documentElement.clientWidth')
        console.log(document.documentElement.clientHeight, 'document.documentElement.clientHeight')
 
        this.thumbnailGraph = new Graph({
          container: document.getElementById('timeDiagramThumbnail'),
          // width:250,
          height: 150,
          grid: {
            visible: false,
          },
          translating: {
            restrict(view) {
              const cell = view.cell
              if (cell.isNode() || cell.isEdge()) {
                const parent = cell.getParent()
                if (parent) {
                  return parent.getBBox()
                }
              }
              return null
            },
          },
          interacting: function (cellView) {
            const data = cellView.cell.getData();
            if (cellView.cell.isEdge()) {
              return { edgeMovable : false };
            }
            else if (data && data.nodeMovable ) {
              return { nodeMovable : false };
            }
            return true;
          },
          // embedding: {
          //   enabled: true,
          //   findParent({node}) {
          //     const bbox = node.getBBox()
          //     return this.getNodes().filter((node) => {
          //       // 只有 data.parent 为 true 的节点才是父节点
          //       const data = node.getData()
          //       if (data && data.parent) {
          //         const targetBBox = node.getBBox()
          //         return bbox.isIntersectWithRect(targetBBox)
          //       }
          //       return false
          //     })
          //   }
          // },
          // autoResize: true,
          // keyboard: true,
        })
        this.thumbnailGraph.centerContent()
        Graph.registerNode(
          'custom-rect',
          {
            inherit: 'rect',
            width: 86,
            height: 26,
            zIndex: 10,
            data: {
              dataId: '',
              finishDate: '',
              inspectName: ''
            },
            attrs: {
              body: {
                strokeWidth: 1,
                stroke: 'none',
                fill: 'none',
              },
              text: {
                // fontFamily: '仿宋',
                fontSize: 20,
                fill: '#000',
              },
              label: {
                refX: 0,
                refY: 0.5,
                textAnchor: 'start',
                textVerticalAnchor: 'middle',
                textWrap: {
                  text: '文字模板',
                  width: -10,      // 宽度减少 10px
                  ellipsis: false,  // 文本超出显示范围时,自动添加省略号
                  breakWord: true, // 是否截断单词
                }
              },
            },
            ports: {...this.ports},
          },
          true,
        )
 
        Graph.registerNode(
          'custom-polygon',
          {
            inherit: 'polygon',
            width: 86,
            height: 56,
            attrs: {
              body: {
                strokeWidth: 1,
                stroke: '#5F95FF',
                fill: '#EFF4FF',
              },
              text: {
                fontSize: 20,
                fill: '#262626',
              },
            },
            ports: {
              ...this.ports
              // items: [
              //   {
              //     group: 'top',
              //   },
              //   {
              //     group: 'bottom',
              //   },
              // ],
            },
          },
          true,
        )
        //
        Graph.registerNode(
          'custom-circle',
          {
            inherit: 'ellipse',
            width: 120,
            height: 120,
            data: {
              dataId: '',
              finishDate: ''
            },
            attrs: {
              body: {
                strokeWidth: 1,
                stroke: '#5F95FF',
                fill: '#EFF4FF',
              },
              //日期
              title: {
                text: '',
                fontSize: 12,
                fill: '#262626',
                refX: 0.5,
                refY: '100%',
                refY2: -10,
                textAnchor: 'middle',
                textVerticalAnchor: 'bottom',
              },
              // 名称
              text: {
                // fontFamily: '仿宋',
                fontSize: 20,
                fill: '#262626',
                textWrap: {
                  width: 80,      // 宽度为 80px换行
                  ellipsis: false,  // 文本超出显示范围时,自动添加省略号
                  breakWord: true, // 是否截断单词
                }
              },
            },
            markup: [
              {
                tagName: 'ellipse',
                selector: 'body',
              },
              {
                tagName: 'text',
                selector: 'title',
              },
              {
                tagName: 'text',
                selector: 'text',
              },
            ],
            ports: {...this.ports},
          },
          true,
        )
        Graph.registerNode(
          'custom-circle1',
          {
            inherit: 'ellipse',
            width: 65,
            height: 65,
            data: {
              dataId: '',
              finishDate: ''
            },
            attrs: {
              body: {
                strokeWidth: 1,
                stroke: '#5F95FF',
                fill: '#EFF4FF',
              },
              //日期
              text: {
                // fontFamily: '仿宋',
                fontSize: 12,
                text: '日期节点',
                fill: '#262626',
              },
            },
            ports: {...this.ports},
          },
          true,
        )
        Graph.registerNode(
          'custom-text',
          {
            inherit: 'text-block',
            width: 86,
            height: 56,
            attrs: {
              body: {
                strokeWidth: 1,
                stroke: '#5F95FF',
                fill: '#EFF4FF',
              },
              text: {
                text: '专业',
                fontSize: 20,
                style: {
                  color:'#080808'
                },
                refX: '0',
                refY: -0.5,
                refY2: 1,
                textAnchor: 'middle',
                textVerticalAnchor: 'middle',
              },
            },
            markup: [
              {
                tagName: 'rect',
                selector: 'body',
              },
              {
                tagName: 'text',
                selector: 'text',
              },
            ],
            ports: {...this.ports},
          },
          true,
        )
 
        this.thumbnailGraph.on('node:moving', ({ e, x, y, node, view }) => {
         this.$emit('getPoint',x,this.smallWidth)
        })
      },
      getThumbnail(smallDiagramJson){
        this.thumbnailGraph.fromJSON(smallDiagramJson)
        this.thumbnailGraph.centerContent()
        this.smallWidth = this.thumbnailGraph.getContentBBox().width
        const nodes = this.thumbnailGraph.getNodes()
        for (const otherNode of nodes) {
          if (otherNode.hasParent()){
            this.targetNode = otherNode
            console.log(this.targetNode,'targetNode')
          }
        }
        // console.log(this.thumbnailGraph.getContentBBox().width,'DiagramJson11')
        // this.thumbnailGraph.zoomToFit()
      },
      getNodePointX(x,bigWidth){
        let pointX = Number((x / ( bigWidth /this.smallWidth)).toFixed(0))
        if(this.targetNode){
          this.targetNode.position(pointX, this.targetNode.position().y)
          return false
        }
 
      },
      // setScroll(top){
      //   this.thumbnailGraph.setScrollbarPosition(null, top)
      // }
    },
  }
</script>
 
<style >
  #timeDiagramThumbnail {
    border: 1px solid #dfe3e8;
    width: 100% !important;
  }
  /*#timeDiagramThumbnail .x6-graph-scroller.x6-graph-scroller-pannable {*/
  /*  width:100% !important;*/
  /*}*/
  #timeDiagramThumbnail .x6-edge {
    cursor: default !important; ;
  }
  /*#timeDiagramThumbnail .x6-node {*/
  /*  cursor: default ;*/
  /*}*/
  .x6-widget-stencil {
    position: relative;
    height: 100%;
  }
 
  .x6-widget-stencil-content {
    position: relative;
    height: 100%;
  }
  .my-scroller-text {
    overflow: auto; /* 需要滚动时保持这个属性 */
    scrollbar-width: none; /* 对于Firefox */
  }
 
  .my-scroller-text::-webkit-scrollbar {
    display: none; /* 对于Chrome, Safari和Opera */
  }
</style>