Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: html node only render key shape #6544

Merged
merged 4 commits into from
Nov 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/healthy-penguins-study.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@antv/g6': patch
---

fix: html node only render key and ports shapes
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ jobs:
brew update
brew install python3 || : # python doesn't need to be linked
brew install pkg-config cairo pango libpng jpeg giflib librsvg

brew unlink pkg-config
brew link --overwrite pkgconf

pip install setuptools

- uses: pnpm/action-setup@v4
Expand Down
75 changes: 75 additions & 0 deletions packages/g6/__tests__/demos/element-node-html-2.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import { Graph } from '@antv/g6';

export const elementNodeHTML2: TestCase = async (context) => {
const ICON_MAP = {
error: '❌',
overload: '⚡',
running: '✅',
};

const COLOR_MAP = {
error: '#f5222d',
overload: '#faad14',
running: '#52c41a',
} as const;

const graph = new Graph({
...context,
data: {
nodes: [
{ id: 'node-1', data: { location: 'East', status: 'error', ip: '192.168.1.2' } },
{ id: 'node-2', data: { location: 'West', status: 'overload', ip: '192.168.1.3' } },
{ id: 'node-3', data: { location: 'South', status: 'running', ip: '192.168.1.4' }, states: ['active'] },
],
},
node: {
type: 'html',
style: {
size: [160, 60],
dx: -80,
dy: -30,
innerHTML: (d: any) => {
const {
data: { location, status, ip },
} = d;
const color = COLOR_MAP[status as keyof typeof COLOR_MAP];
return `
<div
style="
width:100%;
height: 100%;
background: ${color}bb;
border: 1px solid ${color};
color: #fff;
user-select: none;
display: flex;
padding: 10px;
"
>
<div style="display: flex;flex-direction: column;flex: 1;">
<div style="font-weight: bold;">
${location} Node
</div>
<div>
status: ${status} ${ICON_MAP[status as keyof typeof ICON_MAP]}
</div>
</div>
<div>
<span style="border: 1px solid white; padding: 2px;">
${ip}
</span>
</div>
</div>`;
},
},
},
layout: {
type: 'grid',
},
behaviors: ['drag-element', 'zoom-canvas'],
});

await graph.render();

return graph;
};
1 change: 1 addition & 0 deletions packages/g6/__tests__/demos/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export { elementNodeDonut } from './element-node-donut';
export { elementNodeEllipse } from './element-node-ellipse';
export { elementNodeHexagon } from './element-node-hexagon';
export { elementNodeHTML } from './element-node-html';
export { elementNodeHTML2 } from './element-node-html-2';
export { elementNodeImage } from './element-node-image';
export { elementNodeRect } from './element-node-rect';
export { elementNodeStar } from './element-node-star';
Expand Down
9 changes: 9 additions & 0 deletions packages/g6/src/elements/nodes/html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,15 @@ export class HTML extends BaseNode<HTMLStyleProps> {
return this.getShape<GHTML>('key').getDomElement();
}

/**
* @override
*/
public render(attributes: Required<HTMLStyleProps> = this.parsedAttributes, container: Group = this): void {
this.drawKeyShape(attributes, container);

this.drawPortShapes(attributes, container);
}

protected getKeyStyle(attributes: Required<HTMLStyleProps>): GHTMLStyleProps {
const {
dx = 0,
Expand Down
Loading