G6-图学习记录

这篇博客探讨了G6图形库中悬停操作的自定义实现,通过参考issue修复了默认悬停功能的局限性,创建了带有标题、内容和按钮的自定义tooltip。同时,针对数据更新的问题,博主提出了清空innerHTML的方法以强制渲染更新,与X6的changeData方法相比较。文章着重于提升图表交互体验和数据动态更新的解决方案。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

G6使用记录

1-悬停可操作:自带的悬停,只是悬停展示,无法操作悬停展示的内容,所以需要定位替代自带的悬停-----参考issue地址https://github.com/antvis/G6/issues/2637#issuecomment-781001127

  const tooltip = (
    <div
      className={styles.tooltip}
      style={{
        opacity: tooltipDisplayStates.opacity,
        display: tooltipDisplayStates.display,
        left: tooltipStates.x,
        top: tooltipStates.y,
      }}
    >
      fdsafsafsafad
      <div className={styles.tooltipTitle}>
        {tooltipStates.title.replace('\n', '')}
      </div>
      <div className={styles.tooltipContent}>
        <img
          className={styles.tooltipImg}
          src={tooltipStates.imgSrc}
          alt="tooltip"
        />
        <div className={styles.tooltipBtnsContainer}>
          <p className={styles.demoDescription}>demo</p>
          {tooltipStates.buttons}
        </div>
      </div>
    </div>
  );

.tooltip {
  position: absolute;
  width: 218px;
  height: 161px;
  border: 1px solid #ebedf0;
  border-radius: 4px 4px 4px 4px;
  background: rgba(255, 255, 255, 1);
  box-shadow: 0px 12px 16px rgba(49, 70, 89, 0.12);
  transition: all 0.3s;
  .tooltipTitle {
    width: 100%;
    text-align: center;
    padding: 10px;
    height: auto;
    font-size: 14px;
    font-weight: 500;
    color: #314659;
  }
  .tooltipContent {
    width: 100%;
    height: 118px;
    text-align: center;
    border-top: 1px solid #ebedf0;
    .tooltipImg {
      width: 214px;
      height: 118px;
      margin-left: 1px;
      border-radius: 0px 0px 3px 3px;
    }
    .tooltipBtnsContainer {
      position: absolute;
      width: 99%;
      margin-left: 1px;
      height: 118px;
      padding: auto;
      display: flex;
      background: #fff;
      border-top: 1px solid #ebedf0;
      opacity: 0;
      bottom: 0;
      flex-direction: column;
      .demoDescription {
        width: 100%;
        color: #ced4d9;
        position: relative;
        top: 30px;
        font-size: 12px;
        height: fit-content;
      }
      .buttons {
        display: flex;
        flex-direction: row;
        text-align: center;
        margin-top: 30px;
        .button {
          position: relative;
          height: 20px;
          text-align: center;
          border-right: 1px solid #ebedf0;
          a {
            color: #2f54eb;
          }
          &:hover {
            color: #597ef7;
          }
          &:last-child {
            border-right: 0px;
          }
        }
      }
      &:hover {
        opacity: 1;
        transition: all 0.3s;
      }
    }
  }
}

2-数据更新不会自动渲染,我这里使用的清空innnerHTML,同X6,也可以使用它的changeData方法强制更新

ref.current.innerHTML = '';

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值