日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

G6-定制不同节点的参数 --组合图

發(fā)布時(shí)間:2024/3/13 编程问答 105 豆豆
生活随笔 收集整理的這篇文章主要介紹了 G6-定制不同节点的参数 --组合图 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

前言

G6官方地址:https://antv-g6.gitee.io/zh/examples/gallery

參考的G6案例有: 圖表決策、邊動(dòng)畫(huà)、定制不同節(jié)點(diǎn)的參數(shù)

實(shí)現(xiàn)的效果:動(dòng)畫(huà)、放大、縮小、拖拽、移動(dòng)、點(diǎn)擊交互等

有兩版代碼:一個(gè)是可以在G6官網(wǎng)里運(yùn)行的。一個(gè)是在angular里運(yùn)行的

我暫時(shí)未處理的問(wèn)題:圖的適配問(wèn)題,不能隨著屏幕大小變化而變化


變形

改變連接節(jié)點(diǎn)就行

代碼

可直接在官網(wǎng)上運(yùn)行的代碼:
ps:隨便找一個(gè)案例,替換掉里面的代碼就行

import G6 from '@antv/g6';G6.registerEdge('circle-running',{afterDraw(cfg, group) {// 得到組中的第一個(gè)形狀,它是邊的路徑在這里const shape = group.get('children')[0];// 邊緣路徑的起始位置const startPoint = shape.getPoint(0);// 添加一個(gè)在線上運(yùn)動(dòng)的圓球const circle = group.addShape('circle', {attrs: {x: startPoint.x,y: startPoint.y,fill: '#1890ff',r: 3,},name: 'circle-shape',});// 小球的動(dòng)畫(huà)circle.animate((ratio) => {// 每個(gè)幀的操作。比率范圍從0到1,表示動(dòng)畫(huà)的進(jìn)度。返回修改后的配置// 根據(jù)比例得到邊緣的位置const tmpPoint = shape.getPoint(ratio);// 這里返回修改后的配置,這里是x和yreturn {x: tmpPoint.x,y: tmpPoint.y,};},{repeat: true, // 是否重復(fù)執(zhí)行動(dòng)畫(huà)duration: 3000, // 執(zhí)行一次的持續(xù)時(shí)間},);},},'line', // 擴(kuò)展內(nèi)置邊'cubic' );const lightColors = ['#8FE9FF','#87EAEF','#FFC9E3','#A7C2FF','#FFA1E3','#FFE269','#BFCFEE','#FFA0C5','#D5FF86', ]; const darkColors = ['#7DA8FF','#44E6C1','#FF68A7','#7F86FF','#AE6CFF','#FF5A34','#5D7092','#FF6565','#6BFFDE', ]; const uLightColors = ['#CFF6FF','#BCFCFF','#FFECF5','#ECFBFF','#EAD9FF','#FFF8DA','#DCE2EE','#FFE7F0','#EEFFCE', ]; const uDarkColors = ['#CADBFF','#A9FFEB','#FFC4DD','#CACDFF','#FFD4F2','#FFD3C9','#EBF2FF','#FFCBCB','#CAFFF3', ];const gColors = []; const unlightColorMap = new Map();const container = document.getElementById('container'); const width = container.scrollWidth; const height = container.scrollHeight || 500; const graph = new G6.Graph({container: 'container',width,height,defaultEdge: {type: 'circle-running',style: {lineWidth: 2,stroke: '#bae7ff',},},defaultNode: {type: 'circle', // 'bubble'size: 95,labelCfg: {position: 'center',style: {fill: 'white',fontStyle: 'bold',},},},animate: true,layout: {type: 'force',preventOverlap: true,linkDistance: (d) => {if (d.source.id === 'node0') {return 200;}return 30;},nodeStrength: (d) => {if (d.isLeaf) {return -200;}return -100;},},defaultNode: {color: '#5B8FF9',},// 整個(gè)圖可以拖動(dòng)、放大縮小modes: {default: ['drag-canvas', 'zoom-canvas'],}, });const data = {nodes: [{ id: 'node0', label: `組織管理\n(12)`, size: 100 },{ id: 'node1', label: '管理單位', size: 100 },{ id: 'node2', label: '角色管理', size: 100 },{ id: 'node3', label: '崗位管理', size: 100 },{ id: 'node4', label: '崗位管理', size: 100 },{ id: 'node5', label: '崗位管理', size: 100 },],edges: [{ source: 'node0', target: 'node1' },{ source: 'node0', target: 'node2' },{ source: 'node0', target: 'node3' },{ source: 'node0', target: 'node4' },{ source: 'node0', target: 'node5' },], };lightColors.forEach((lcolor, i) => {gColors.push('l(0) 0:' + lcolor + ' 1:' + darkColors[i]);unlightColorMap.set(gColors[i], 'l(0) 0:' + uLightColors[i] + ' 1:' + uDarkColors[i]); }); console.log(gColors);for ( let i = 0; i < data.nodes.length; i++ ) {data.nodes[i].color = gColors[i];data.nodes[i].style = {fill: gColors[i],lineWidth: 0};data.nodes[i].labelCfg = {style: {fontSize: 20,fill: '#fff',fontWeight: 300,},}; }const nodes = data.nodes; graph.data({nodes,edges: data.edges.map(function (edge, i) {edge.id = 'edge' + i;return Object.assign({}, edge);}), }); graph.render();graph.on('node:dragstart', function (e) {graph.layout();refreshDragedNodePosition(e); }); graph.on('node:drag', function (e) {refreshDragedNodePosition(e); }); graph.on('node:dragend', function (e) {e.item.get('model').fx = null;e.item.get('model').fy = null; }); graph.on('node:click', (evt) => {window.alert('點(diǎn)擊了');});if (typeof window !== 'undefined')window.onresize = () => {if (!graph || graph.get('destroyed')) return;if (!container || !container.scrollWidth || !container.scrollHeight) return;graph.changeSize(container.scrollWidth, container.scrollHeight);};function refreshDragedNodePosition(e) {const model = e.item.get('model');model.fx = e.x;model.fy = e.y; }

我的代碼

我是在angular11里使用的G6

<div #mountNodeLeft></div> import { Component, OnInit, ViewChild } from '@angular/core';@ViewChild('mountNodeLeft', { static: false }) mountNodeLeft!: any;constructor() { }ngOnInit(): void {}// tslint:disable-next-line:use-lifecycle-interfacengAfterViewInit(): void {setTimeout(() => { this.render(); }, 100);}// 下面兩個(gè)函數(shù)是g6的圖// tslint:disable-next-line:typedefrender() {const lightColors = ['#8FE9FF','#87EAEF','#FFC9E3','#A7C2FF','#FFA1E3','#FFE269','#BFCFEE','#FFA0C5','#D5FF86',];const darkColors = ['#7DA8FF','#44E6C1','#FF68A7','#7F86FF','#AE6CFF','#FF5A34','#5D7092','#FF6565','#6BFFDE',];const uLightColors = ['#CFF6FF','#BCFCFF','#FFECF5','#ECFBFF','#EAD9FF','#FFF8DA','#DCE2EE','#FFE7F0','#EEFFCE',];const uDarkColors = ['#CADBFF','#A9FFEB','#FFC4DD','#CACDFF','#FFD4F2','#FFD3C9','#EBF2FF','#FFCBCB','#CAFFF3',];const gColors: any = [];const unlightColorMap = new Map();lightColors.forEach((lcolor, i) => {gColors.push('l(0) 0:' + lcolor + ' 1:' + darkColors[i]);unlightColorMap.set(gColors[i], 'l(0) 0:' + uLightColors[i] + ' 1:' + uDarkColors[i]);});G6.registerEdge('circle-running',{// tslint:disable-next-line:typedefafterDraw(cfg, group: any) {// 得到組中的第一個(gè)形狀,它是邊的路徑在這里const shape = group.get('children')[0];// 邊緣路徑的起始位置const startPoint = shape.getPoint(0);// 添加一個(gè)在線上運(yùn)動(dòng)的圓球const circle = group.addShape('circle', {attrs: {x: startPoint.x,y: startPoint.y,fill: '#1890ff',r: 3,},name: 'circle-shape',});// 小球的動(dòng)畫(huà)circle.animate((ratio: any) => {// 每個(gè)幀的操作。比率范圍從0到1,表示動(dòng)畫(huà)的進(jìn)度。返回修改后的配置// 根據(jù)比例得到邊緣的位置const tmpPoint = shape.getPoint(ratio);// 這里返回修改后的配置,這里是x和yreturn {x: tmpPoint.x,y: tmpPoint.y,};},{repeat: true, // 是否重復(fù)執(zhí)行動(dòng)畫(huà)duration: 3000, // 執(zhí)行一次的持續(xù)時(shí)間},);},},'line', // 擴(kuò)展內(nèi)置邊'cubic');const width = window.innerWidth / 2;const height = window.innerHeight - 300;const graph = new G6.Graph({container: this.mountNodeLeft.nativeElement,width,height,// 改變線的顏色 綁定動(dòng)畫(huà)defaultEdge: {type: 'circle-running',style: {lineWidth: 2,stroke: '#bae7ff',},},layout: {type: 'force',preventOverlap: true,linkDistance: (d: any) => {// if (d.source.id === 'node0') {// return 200;// }// return 30;return 200;},// nodeStrength: (d: any) => {// if (d.isLeaf) {// return -200;// }// return -100;},},defaultNode: {color: '#5B8FF9',},// 整個(gè)圖可以拖動(dòng)、放大縮小modes: {default: ['drag-canvas', 'zoom-canvas'],},});const data: any = {nodes: [{ id: 'node0', label: `組織管理\n(12)`, size: 110 },{ id: 'node1', label: '管理單位', size: 110 },{ id: 'node2', label: '角色管理', size: 110 },{ id: 'node3', label: '崗位管理', size: 110 },{ id: 'node4', label: '崗位管理', size: 110 },{ id: 'node5', label: '崗位管理', size: 110 },],edges: [{ source: 'node0', target: 'node1' },{ source: 'node0', target: 'node2' },{ source: 'node0', target: 'node3' },{ source: 'node0', target: 'node4' },{ source: 'node0', target: 'node5' },],};// 修改圖中的圓for (let i = 0; i < data.nodes.length; i++) {data.nodes[i].color = gColors[i];data.nodes[i].style = {fill: gColors[i],lineWidth: 0,cursor: 'pointer',};data.nodes[i].labelCfg = {style: {fontSize: 18,fill: '#fff',fontWeight: 300,cursor: 'pointer',},};}const nodes = data.nodes;graph.data({nodes,edges: data.edges.map((edge: any, i: any) => {edge.id = 'edge' + i;return Object.assign({}, edge);}),});graph.render();graph.on('node:dragstart', (e) => {graph.layout();this.refreshDragedNodePosition(e);});graph.on('node:drag', (e) => {this.refreshDragedNodePosition(e);});graph.on('node:dragend', (e: any) => {e.item.get('model').fx = null;e.item.get('model').fy = null;});graph.on('node:click', (evt) => {window.alert('點(diǎn)擊了');});}// tslint:disable-next-line:typedefrefreshDragedNodePosition(e: any) {const model = e.item.get('model');model.fx = e.x;model.fy = e.y;}

總結(jié)

以上是生活随笔為你收集整理的G6-定制不同节点的参数 --组合图的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。