npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@antv/x6-angular-shape

v2.0.2

Published

X6 shape for rendering angular components.

Downloads

646

Readme

@antv/x6-angular-shape

渲染节点

我们提供了一个独立的包 @antv/x6-angular-shape 以支持将 Angular 的组件/模板作为节点进行渲染。

Component 渲染

@Component({
  selector: 'app-node',
  templateUrl: './node.component.html',
  styleUrls: ['./node.component.scss'],
})
export class NodeComponent implements AfterViewInit, OnChanges {
  @Input() value: string
}
import { register } from '@antv/x6-angular-shape'

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss'],
})
export class AppComponent implements AfterViewInit {
  ngAfterViewInit(): void {
    register({
      shape: 'custom-angular-component-node',
      width: 120,
      height: 20,
      content: NodeComponent,
      injector: this.injector,
    })

    this.graph.addNode({
      shape: 'custom-angular-component-node',
      x: 100,
      y: 100,
      data: {
        // Input 的参数必须放在这里
        ngArguments: {
          value: '糟糕糟糕 Oh my god',
        },
      },
    })
  }
}

TemplateRef 渲染

<ng-template #template let-data="ngArguments">
  <section class="template-container">
    <span class="value">{{ data.value }}</span>
  </section>
</ng-template>
import { register } from '@antv/x6-angular-shape'

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss'],
})
export class AppComponent implements AfterViewInit {
  @ViewChild('template') template: TemplateRef<{}>

  ngAfterViewInit(): void {
    register({
      shape: 'custom-angular-template-node',
      width: 120,
      height: 20,
      content: this.template,
      injector: this.injector,
    })

    this.graph.addNode({
      shape: 'custom-angular-template-node',
      x: 100,
      y: 100,
      data: {
        ngArguments: {
          value: '魔法怎么失灵啦',
        },
      },
    })
  }
}

更新节点

无论是使用 Component 还是 TemplateRef, 都是一样的更新方式.

node.setData({
  ngArguments: {
    value: '晚风中闪过 几帧从前啊',
  },
})

有 demo 吗?

有的, 因为 X6 渲染节点部分与框架是解耦的. 因此 x6-angular-shape 包并非是直接在源代码里改的, 而是在一个单独的 Angular 环境中开发的. 该 demo 还提供了多种节点类型的性能测试, 详情请参考Eve-Sama/x6-angular-shapeX6 与 G6 的性能对比, 以及 X6 多节点类型下的 FPS 临界点讨论

FAQ

为什么输入属性不能直接放在 data 中而需要放在 ngArguments 中? 且为什么不叫 ngInput?

因为并非所有 node.data 中的属性都是输入属性, 所以遍历 data 中的所有属性进行赋值是不合适的. 至于为什么叫 ngArguments 主要是有两点考虑.

  • 1.x 版本中已经这么用了, 沿用该 API 可以降低用户升级成本
  • Input 的概念其实是来自 Component, 而 TemplateRef 中是 context, 在二者的基础上抽象一个 Arguments 的概念更通用些

2.x 版本的 x6-angular-shape 相比较 1.x 版本有什么新特性吗?

实现思路其实和之前是差不多的. 但是确实有几个点值得一提.

demo 更聚焦

1.x 版本的 demo 除了渲染组件外, 还写了连线、清除等一系列案例. 看似扩展, 实则眼花缭乱. 作为 x6-angular-shape的 demo, 2.x 版本更加聚焦, 更加聚焦于 shape 的使用与性能测试等, 与插件无关的内容请查看 X6 官网.

功能更稳定

在 1.x 版本中, 虽然实现了功能, 但是使用场景的思考不够全面. 比如ngArguments的变化, 对 TemplateRef的场景并不生效. 虽然对Component生效但是无法触发ngOnChanges. 而在新版本中, 这些问题都将不复存在.

版本要求

你的 Angular 版本至少在 14 及以上才可以. 14 以下需要用 hack 的方式实现一些特性, 比较麻烦. 暂时不提供, 如有需要可提 issue, 我再专门介绍下如何实现.