fix: 优化桑基图
Showing
2 changed files
with
30 additions
and
16 deletions
| ... | @@ -82,7 +82,7 @@ watch(() => props.treeData, (val) => { | ... | @@ -82,7 +82,7 @@ watch(() => props.treeData, (val) => { |
| 82 | 82 | ||
| 83 | const renderGraph = (graph: any, lineageData: any) => { | 83 | const renderGraph = (graph: any, lineageData: any) => { |
| 84 | if (!graph || !lineageData) return; | 84 | if (!graph || !lineageData) return; |
| 85 | graph.setMinZoom(0.7); | 85 | graph.setMinZoom(1); |
| 86 | graph.setMaxZoom(1); | 86 | graph.setMaxZoom(1); |
| 87 | graph.data(lineageData); | 87 | graph.data(lineageData); |
| 88 | graph.render(); | 88 | graph.render(); |
| ... | @@ -265,7 +265,7 @@ const initGraph = () => { | ... | @@ -265,7 +265,7 @@ const initGraph = () => { |
| 265 | ], | 265 | ], |
| 266 | }, | 266 | }, |
| 267 | defaultNode: { | 267 | defaultNode: { |
| 268 | size: 24, | 268 | size: 20, |
| 269 | anchorPoints: [ | 269 | anchorPoints: [ |
| 270 | [0, 0.5], | 270 | [0, 0.5], |
| 271 | [1, 0.5], | 271 | [1, 0.5], |
| ... | @@ -292,7 +292,7 @@ const initGraph = () => { | ... | @@ -292,7 +292,7 @@ const initGraph = () => { |
| 292 | return 16; | 292 | return 16; |
| 293 | }, | 293 | }, |
| 294 | getVGap: function getVGap() { | 294 | getVGap: function getVGap() { |
| 295 | return 25; | 295 | return 15; |
| 296 | }, | 296 | }, |
| 297 | getHGap: function getHGap() { | 297 | getHGap: function getHGap() { |
| 298 | return 120; | 298 | return 120; |
| ... | @@ -306,7 +306,7 @@ const initGraph = () => { | ... | @@ -306,7 +306,7 @@ const initGraph = () => { |
| 306 | label: handleLabelLength((node.isField ? node.metaStandardId : node.standardName) as string), | 306 | label: handleLabelLength((node.isField ? node.metaStandardId : node.standardName) as string), |
| 307 | collapsed: node.children?.length ? false : true, | 307 | collapsed: node.children?.length ? false : true, |
| 308 | labelCfg: { | 308 | labelCfg: { |
| 309 | offset: 10, | 309 | offset: 7, |
| 310 | style: { | 310 | style: { |
| 311 | fontSize: 13, | 311 | fontSize: 13, |
| 312 | fill: '#212121', | 312 | fill: '#212121', |
| ... | @@ -369,7 +369,7 @@ const observeResize = () => { | ... | @@ -369,7 +369,7 @@ const observeResize = () => { |
| 369 | return; | 369 | return; |
| 370 | } | 370 | } |
| 371 | graphRef.value.changeSize(width, height); | 371 | graphRef.value.changeSize(width, height); |
| 372 | graphRef.value.setMinZoom(0.7); | 372 | graphRef.value.setMinZoom(1); |
| 373 | graphRef.value.setMaxZoom(1); | 373 | graphRef.value.setMaxZoom(1); |
| 374 | graphRef.value.fitView(40, { direction: 'both' }); | 374 | graphRef.value.fitView(40, { direction: 'both' }); |
| 375 | graphRef.value.fitCenter(); | 375 | graphRef.value.fitCenter(); |
| ... | @@ -385,7 +385,7 @@ const observeResize = () => { | ... | @@ -385,7 +385,7 @@ const observeResize = () => { |
| 385 | return; | 385 | return; |
| 386 | } | 386 | } |
| 387 | graphRef.value.changeSize(width, height); | 387 | graphRef.value.changeSize(width, height); |
| 388 | graphRef.value.setMinZoom(0.7); | 388 | graphRef.value.setMinZoom(1); |
| 389 | graphRef.value.setMaxZoom(1); | 389 | graphRef.value.setMaxZoom(1); |
| 390 | graphRef.value.fitView(40, { direction: 'both' }); | 390 | graphRef.value.fitView(40, { direction: 'both' }); |
| 391 | graphRef.value.fitCenter(); | 391 | graphRef.value.fitCenter(); |
| ... | @@ -607,7 +607,7 @@ defineExpose({ | ... | @@ -607,7 +607,7 @@ defineExpose({ |
| 607 | overflow-y: auto; | 607 | overflow-y: auto; |
| 608 | 608 | ||
| 609 | .title { | 609 | .title { |
| 610 | font-size: 16px; | 610 | font-size: 14px; |
| 611 | color: #212121; | 611 | color: #212121; |
| 612 | line-height: 24px; | 612 | line-height: 24px; |
| 613 | font-weight: 600; | 613 | font-weight: 600; |
| ... | @@ -615,7 +615,7 @@ defineExpose({ | ... | @@ -615,7 +615,7 @@ defineExpose({ |
| 615 | 615 | ||
| 616 | .row { | 616 | .row { |
| 617 | margin-top: 8px; | 617 | margin-top: 8px; |
| 618 | font-size: 14px; | 618 | font-size: 12px; |
| 619 | color: #666666; | 619 | color: #666666; |
| 620 | word-break: break-all; | 620 | word-break: break-all; |
| 621 | line-height: 21px; | 621 | line-height: 21px; | ... | ... |
| ... | @@ -78,6 +78,7 @@ const sankeyInstance: any = ref(); | ... | @@ -78,6 +78,7 @@ const sankeyInstance: any = ref(); |
| 78 | const containerRef = ref(); | 78 | const containerRef = ref(); |
| 79 | 79 | ||
| 80 | const setChartsOption = () => { | 80 | const setChartsOption = () => { |
| 81 | |||
| 81 | let option = { | 82 | let option = { |
| 82 | tooltip: { | 83 | tooltip: { |
| 83 | trigger: 'item', | 84 | trigger: 'item', |
| ... | @@ -85,19 +86,33 @@ const setChartsOption = () => { | ... | @@ -85,19 +86,33 @@ const setChartsOption = () => { |
| 85 | if (params.data.name) { | 86 | if (params.data.name) { |
| 86 | return null; | 87 | return null; |
| 87 | } | 88 | } |
| 88 | return params.data.source + ' --> ' + params.data.target | 89 | return params.data.source + ' > ' + params.data.target |
| 89 | } | 90 | } |
| 90 | }, | 91 | }, |
| 91 | color: ["#3DBCBE", "#6b67d1", "#7BBCE0", "#2B8EF3", "#51dca2", "#E19D46"], | 92 | color: ["#3DBCBE", "#6b67d1", "#7BBCE0", "#2B8EF3", "#51dca2", "#E19D46"], |
| 92 | series: [ | 93 | series: [ |
| 93 | { | 94 | { |
| 94 | type: 'sankey', | 95 | type: 'sankey', |
| 95 | top: 80, | 96 | top: 60, |
| 96 | bottom: 40, | 97 | bottom: 20, |
| 97 | draggable: false, | 98 | draggable: false, |
| 98 | left: 40, | 99 | left: 50, |
| 99 | right: 80, | 100 | right: 100, |
| 100 | data: props.names, | 101 | label: { |
| 102 | fontSize: 10, | ||
| 103 | }, | ||
| 104 | data: props.names?.map(n => { | ||
| 105 | if (n.isLast) { | ||
| 106 | return { | ||
| 107 | ...n, | ||
| 108 | label: { | ||
| 109 | width: 97, | ||
| 110 | overflow: 'breakAll' | ||
| 111 | } | ||
| 112 | } | ||
| 113 | } | ||
| 114 | return n; | ||
| 115 | }), | ||
| 101 | links: props.treeData, | 116 | links: props.treeData, |
| 102 | lineStyle: { | 117 | lineStyle: { |
| 103 | color: 'source', | 118 | color: 'source', |
| ... | @@ -113,10 +128,9 @@ const setChartsOption = () => { | ... | @@ -113,10 +128,9 @@ const setChartsOption = () => { |
| 113 | const resizeObserver = ref(); | 128 | const resizeObserver = ref(); |
| 114 | 129 | ||
| 115 | const observeResize = () => { | 130 | const observeResize = () => { |
| 116 | resizeObserver.value = new ResizeObserver(() => { | 131 | window.addEventListener('resize', (e) => { |
| 117 | sankeyInstance.value?.resize(); | 132 | sankeyInstance.value?.resize(); |
| 118 | }); | 133 | }); |
| 119 | resizeObserver.value.observe(containerRef.value); | ||
| 120 | } | 134 | } |
| 121 | 135 | ||
| 122 | onMounted(() => { | 136 | onMounted(() => { | ... | ... |
-
Please register or sign in to post a comment