Skip to content

Commit

Permalink
fix: full title not visible
Browse files Browse the repository at this point in the history
  • Loading branch information
yari-dewalt committed Jun 24, 2024
1 parent 0044aa3 commit a501a88
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions packages/mermaid/src/diagrams/pie/pieRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,14 +166,28 @@ export const draw: DrawDefinition = (text, id, _version, diagObj) => {
return label;
});

const longestTextWidth = Math.max(
const titleTextElement = group.select('.pieTitleText');
const titleTextLeft = titleTextElement.node().getBoundingClientRect().left;

Check failure on line 170 in packages/mermaid/src/diagrams/pie/pieRenderer.ts

View workflow job for this annotation

GitHub Actions / build-mermaid

Object is possibly 'null'.

Check failure on line 170 in packages/mermaid/src/diagrams/pie/pieRenderer.ts

View workflow job for this annotation

GitHub Actions / build-mermaid

Property 'getBoundingClientRect' does not exist on type 'Element | EnterElement | Document | Window'.

Check failure on line 170 in packages/mermaid/src/diagrams/pie/pieRenderer.ts

View workflow job for this annotation

GitHub Actions / build-mermaid

Object is possibly 'null'.

Check failure on line 170 in packages/mermaid/src/diagrams/pie/pieRenderer.ts

View workflow job for this annotation

GitHub Actions / build-mermaid

Property 'getBoundingClientRect' does not exist on type 'Element | Window | Document | EnterElement'.
const titleTextWidth = titleTextElement.node().getBoundingClientRect().width;

Check failure on line 171 in packages/mermaid/src/diagrams/pie/pieRenderer.ts

View workflow job for this annotation

GitHub Actions / build-mermaid

Object is possibly 'null'.

Check failure on line 171 in packages/mermaid/src/diagrams/pie/pieRenderer.ts

View workflow job for this annotation

GitHub Actions / build-mermaid

Property 'getBoundingClientRect' does not exist on type 'Element | EnterElement | Document | Window'.

Check failure on line 171 in packages/mermaid/src/diagrams/pie/pieRenderer.ts

View workflow job for this annotation

GitHub Actions / build-mermaid

Object is possibly 'null'.

Check failure on line 171 in packages/mermaid/src/diagrams/pie/pieRenderer.ts

View workflow job for this annotation

GitHub Actions / build-mermaid

Property 'getBoundingClientRect' does not exist on type 'Element | Window | Document | EnterElement'.

// Adjust chart placement.
if (titleTextLeft < MARGIN && titleTextElement.text()) {
group.attr(
'transform',
'translate(' + (pieWidth / 2 - (titleTextLeft - MARGIN)) + ',' + height / 2 + ')'
);
}

const circleOffset = group.select('circle').node().getBoundingClientRect().left;

Check failure on line 181 in packages/mermaid/src/diagrams/pie/pieRenderer.ts

View workflow job for this annotation

GitHub Actions / build-mermaid

Object is possibly 'null'.

Check failure on line 181 in packages/mermaid/src/diagrams/pie/pieRenderer.ts

View workflow job for this annotation

GitHub Actions / build-mermaid

Property 'getBoundingClientRect' does not exist on type 'Element | EnterElement | Document | Window'.

const furthestTextPos = Math.max(
...legend
.selectAll('text')
.nodes()
.map((node) => (node as Element)?.getBoundingClientRect().width ?? 0)
.map((node) => (node as Element)?.getBoundingClientRect().right ?? 0)
);

const totalWidth = pieWidth + MARGIN + LEGEND_RECT_SIZE + LEGEND_SPACING + longestTextWidth;
const totalWidth = Math.max(circleOffset + furthestTextPos, MARGIN * 2 + titleTextWidth);

// Set viewBox
svg.attr('viewBox', `0 0 ${totalWidth} ${height}`);
Expand Down

0 comments on commit a501a88

Please sign in to comment.