6 changed files with 141 additions and 62 deletions
@ -0,0 +1,11 @@
@@ -0,0 +1,11 @@
|
||||
<script setup lang="ts"> |
||||
|
||||
</script> |
||||
|
||||
<template> |
||||
<div>node</div> |
||||
</template> |
||||
|
||||
<style scoped lang="scss"> |
||||
|
||||
</style> |
@ -0,0 +1,43 @@
@@ -0,0 +1,43 @@
|
||||
import { Graph, register, Rect, ExtensionCategory } from '@antv/g6'; |
||||
import { NODE_SIZE } from "./index"; |
||||
|
||||
export class UserCardNode extends Rect { |
||||
get nodeData() { |
||||
return this.context.graph.getNodeData(this.id); |
||||
} |
||||
|
||||
get data() { |
||||
return this.nodeData.data || {}; |
||||
} |
||||
|
||||
// 用户名样式
|
||||
getUsernameStyle(attributes: any) { |
||||
return { |
||||
// x: -20,
|
||||
text: this.data.name || '', |
||||
fontSize: 12, |
||||
fill: '#262626', |
||||
fontWeight: 'bold', |
||||
textAlign: 'center', |
||||
textBaseline: 'middle', |
||||
}; |
||||
} |
||||
|
||||
drawUsernameShape(attributes: any, container: any) { |
||||
if (!attributes.customData.name) return; |
||||
|
||||
const usernameStyle = this.getUsernameStyle(attributes); |
||||
this.upsert('username', 'text', usernameStyle, container); |
||||
} |
||||
|
||||
|
||||
render(attributes: any, container: any) { |
||||
// 渲染基础矩形
|
||||
super.render(attributes, container); |
||||
|
||||
|
||||
this.drawUsernameShape(attributes, container); |
||||
} |
||||
} |
||||
|
||||
|
Loading…
Reference in new issue