G6文件配置____自定义线条以及自定义节点

本文展示了如何在G6图表库中自定义线条样式和节点内容,通过代码块提供了实现效果的示例,适用于前端开发者进行动态生成节点的场景。
摘要由CSDN通过智能技术生成

效果图

在这里插入图片描述

代码块

<template>
  <div>
    <div :id="id"></div>
  </div>
</template>

<script>
import G6 from "@antv/g6";
export default {
   
  name: "g6Node1",
  props: ["data", "biaoShiFu", "indexValue"],
  data() {
   
    return {
   
      id: "0",
      idValue: 0
    };
  },
  watch: {
   
    idValue(newQuestion, oldQuestion) {
   
      console.log(oldQuestion, newQuestion);
      // return newQuestion;
    }
  },

  mounted() {
   
    // console.log('id',this.biaoShiFu)
    // this.id = this.biaoShiFu['id']
    // window.addEventListener('setItemEvent', function(e) {
   
    // const newdata = JSON.parse(e.newValue)
    //  console.log('值改变了',newdata)
    //  this.idValue = newdata;
    //  console.log('_id',this.idValue)
    // })
    console.log("22222222222222222222", this.indexValue);
    this.id = "g6_" + this.indexValue;
    this.render();
    console.log("id", this.id);
  },
  methods: {
   
    render() {
   
      // let _this = this;
      // window.addEventListener("setItemEvent", function (e) {
   
      //     const newdata = JSON.parse(e.newValue);
      //     console.log("值改变了", newdata);
      //     this.idValue = newdata;
      //     console.log("_id", this.idValue);
      // if (this.id == 0) {
   

      //     let G6Init = {
   
      //         // container: 'contentLeftTwo', // 指定图画布的容器 id,与第 9 行的容器对应
      //         // 画布宽高
      //         container: '0',
      //         renderer: "svg",
      //         width: 800,
      //         height: 500
      //     }
      //     alert(1);
      //     this.g6Init(G6Init);
      // } else if (this.id == 1) {
   
      //     // _this.id = "def";
      //     let G6Init = {
   
      //         // container: 'contentLeftTwo', // 指定图画布的容器 id,与第 9 行的容器对应
      //         // 画布宽高
      //         container: '1',
      //         renderer: "svg",
      //         width: 800,
      //         height: 500
      //     }
      //     this.g6Init(G6Init);
      // } else if (this.id == 2) {
   
      //     // _this.id = "ghi";

      //     let G6Init = {
   
      //         // container: 'contentLeftTwo', // 指定图画布的容器 id,与第 9 行的容器对应
      //         // 画布宽高
      //         container: '2',
      //         renderer: "svg",
      //         width: 800,
      //         height: 500
      //     }
      //     this.g6Init(G6Init);
      // }

      // });
      // console.log("idValue", this.idValue);

      // console.log("2222id", this.id);

      //  console.log(_this.biaoShiFu['id'])

      setTimeout(() => {
   
        this.g6Init();
      }, 1000);
    },
    g6Init() {
   
      let that = this;
      G6.registerNode("dom-node-1", {
   
        draw(cfg, group) {
   
          console.log("cfg", cfg);

          return group.addShape("dom", {
   
            attrs: {
   
              width: cfg.size[0],
              height: cfg.size[1],
              html: `<div>   
              
              <div style="height:100%;width:100%;position:relative;margin-bottom:10px;">
                <div style=" padding: 4px;width:120px;height:36px;background-color:${
     
                  cfg.style.fill
                };border-radius:10px;">
                <div style="margin-top:-1px;text-align: center;border-radius:10px;border:1px solid #fff;background-color:${
     
                  cfg.style.fill
                };height:100%;width:100%;">
                 <div style="text-align:center;">
                 
                  <div> ${
     cfg.id}</div>
                  <div>${
     2}</div>
                 </div>
                 </div>
                </div>
                    <div style="width: 38px;
                      height: 38px; 
                      background-color: #AFD4F7;
                      border-radius: 50%;
                      position: absolute;
                      top: 50%;
                      right: 0;
                      margin-top: -22px;
                      margin-right: 4px;
                      background-color: #fff;
                      padding:3px;
                      ">
                      <div style="margin-top: -2px;margin-left:-2px;width:100%;height:100%;border:2px solid ${
     
                        cfg.style.fill
                      };border-radius: 50
  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
感谢您的提问。G6 是一个由阿里巴巴开源的图表库,支持多种图表类型和布局方式。在 G6 中,自定义扩展点是一种常见的扩展方式,可以用于在已有功能的基础上,增加新的功能或改进现有功能。 实现自定义扩展点的关键在于理解 G6 的插件机制。G6 的插件机制基于事件机制,通过监听 G6 触发的事件,实现插件的功能。具体来说,开发者可以通过以下步骤实现自定义扩展点: 1. 定义插件类,继承 G6 的插件基类,并实现相应的事件处理方法。 2. 在 G6 实例中注册插件,以便在 G6 运行时能够触发插件的事件处理方法。 3. 在需要使用插件的地方,调用 G6 实例的相应方法,触发插件的事件处理方法,以实现插件的功能。 例如,可以通过实现 G6 中的 `afteritemselected` 事件处理方法,来实现在图表节点被选中时执行自定义操作的插件。代码如下: ```javascript class MyPlugin extends G6.Plugins.Base { constructor(cfg) { super(cfg); } getEvents() { return { 'afteritemselected': 'onItemSelected' }; } onItemSelected(ev) { // 在这里实现自定义操作 } } const graph = new G6.Graph({ container: 'container', plugins: [new MyPlugin()] }); graph.on('node:click', ev => { graph.emit('afteritemselected', ev); }); ``` 通过这种方式,我们可以在 G6 中实现自定义扩展点,扩展 G6 的功能,满足不同的需求。希望这能对您有所帮助。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值