Skip to content

Commit

Permalink
feat: adjust label text
Browse files Browse the repository at this point in the history
  • Loading branch information
pomelo-nwu committed Aug 24, 2024
1 parent 536f51a commit a6374fb
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ const LengendContent: React.FunctionComponent<ILengendContentProps> = props => {
};
const activeStyle = `2px solid ${token.colorPrimary}`;
return (
<div style={{ maxWidth: '380px', overflow: 'hidden' }}>
<div style={{ maxWidth: '220px', overflow: 'hidden', padding: '12px' }}>
<Flex gap={12} style={{ padding: '6px 0px' }}>
<Typography.Text style={{ flexShrink: 0 }}>
<FormattedMessage id="Color" />
Expand Down
4 changes: 2 additions & 2 deletions packages/studio-graph/src/graph/const.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
export const colors: string[] = [
'#569480',
'#F79767',
'#1978fe',
'#FFE081',
'#C990C0',
'#F79767',
'#57C7E3',
'#D9C8AE',
'#FFE081',
'#8DCC93',
'#ECB5C9',
'#FFC454',
Expand Down
34 changes: 17 additions & 17 deletions packages/studio-graph/src/graph/custom-node/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,24 +44,9 @@ export const nodeCanvasObject =
//@TODO
}

if (captionMode === 'inner') {
const fontSize = 16 / globalScale;
ctx.font = `${fontSize}px Sans-Serif`;
ctx.fillStyle = NODE_TEXT_COLOR;
ctx.textAlign = 'center';
ctx.textBaseline = 'middle';
ctx.fillStyle = '#fff';
drawText(ctx, {
text: textLabel,
x: node.x,
y: node.y + fontSize / 2,
maxWidth: R * 2 * 0.8, //预留 20% pandding
lineHeight: fontSize * 1.2,
});
} else if (captionStatus !== 'hidden' && textLabel) {
if (captionStatus !== 'hidden' && textLabel) {
const fontSize = Math.min(0.5 * globalScale, 14 / globalScale);
// console.log(globalScale, 12 / globalScale, fontSize);
if (true) {
if (globalScale > 4 && globalScale < 15) {
ctx.font = `${fontSize}px Sans-Serif`;
const textWidth = ctx.measureText(textLabel).width;
const bckgDimensions = [textWidth, fontSize].map(n => n + fontSize * 0.2); // some padding
Expand All @@ -75,6 +60,21 @@ export const nodeCanvasObject =
// @ts-ignore
node.__bckgDimensions = bckgDimensions; // to re-use in nodePointerAreaPaint
}
if (globalScale >= 15) {
const fontSize = 16 / globalScale;
ctx.font = `${fontSize}px Sans-Serif`;
ctx.fillStyle = NODE_TEXT_COLOR;
ctx.textAlign = 'center';
ctx.textBaseline = 'middle';
ctx.fillStyle = '#fff';
drawText(ctx, {
text: textLabel,
x: node.x,
y: node.y + fontSize / 2,
maxWidth: R * 2 * 0.8, //预留 20% pandding
lineHeight: fontSize * 1.2,
});
}
}
ctx.restore();
return;
Expand Down
1 change: 0 additions & 1 deletion packages/studio-graph/src/graph/useGraph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ export default function useGraph<P extends GraphProps>(props: P) {
}, [render]);
useEffect(() => {
if (graphRef.current) {
console.log('render>>>> data', data);
graphRef.current.graphData(Utils.fakeSnapshot({ nodes: data.nodes, links: data.edges }));
}
}, [data]);
Expand Down

0 comments on commit a6374fb

Please sign in to comment.