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

feat: add mindmap demo #6132

Merged
merged 3 commits into from
Aug 6, 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
20 changes: 17 additions & 3 deletions packages/g6/__tests__/demos/case-indented-tree.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import data from '@@/dataset/algorithm-category.json';
import type { BaseStyleProps, DisplayObject, DisplayObjectConfig, Group, RectStyleProps } from '@antv/g';
import { Rect } from '@antv/g';
import type {
BaseStyleProps,
DisplayObject,
DisplayObjectConfig,
Group,
RectStyleProps,
TextStyleProps,
} from '@antv/g';
import { Text as GText, Rect } from '@antv/g';
import type {
BadgeStyleProps,
BaseBehaviorOptions,
Expand Down Expand Up @@ -48,6 +55,13 @@ export const caseIndentedTree: TestCase = async (context) => {
'#5D7092',
];

let textShape: GText | null;
const measureText = (text: TextStyleProps) => {
if (!textShape) textShape = new GText({ style: text });
textShape.attr(text);
return textShape.getBBox().width;
};

interface IndentedNodeStyleProps extends BaseNodeStyleProps {
showIcon: boolean;
color: string;
Expand Down Expand Up @@ -506,7 +520,7 @@ export const caseIndentedTree: TestCase = async (context) => {
node: {
type: 'indented',
style: {
size: (d) => [d.id.length * 6 + 10, 20],
size: (d) => [measureText({ text: d.id, fontSize: 12 }) + 6, 20],
labelBackground: true,
labelBackgroundRadius: 0,
labelBackgroundFill: (d) => (d.id === rootId ? '#576286' : '#fff'),
Expand Down
Loading
Loading