-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: 1053 Truncate histogram and dataset info panel (#1054)
- Loading branch information
Showing
7 changed files
with
102 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const EMPTY_ARRAY = []; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
export function truncateText( | ||
text: string, | ||
node: SVGTextElement, | ||
maxWidth: number | ||
) { | ||
let textLength = node.getComputedTextLength(); | ||
|
||
if (textLength <= maxWidth) return text; // No truncation needed | ||
|
||
// Calculate average character width and estimate visible characters | ||
const avgCharWidth = textLength / text.length; | ||
const visibleChars = Math.floor(maxWidth / avgCharWidth); | ||
|
||
// Initial truncation guess | ||
let truncatedText = `${text.slice(0, visibleChars - 1)}...`; | ||
node.textContent = truncatedText; | ||
textLength = node.getComputedTextLength(); | ||
|
||
// Fine-tune adjustment if the text is too long | ||
if (textLength > maxWidth) { | ||
while (textLength > maxWidth && truncatedText.length > 3) { | ||
truncatedText = `${truncatedText.slice(0, -4)}...`; | ||
node.textContent = truncatedText; | ||
textLength = node.getComputedTextLength(); | ||
} | ||
} else { | ||
// Fine-tune adjustment if the text is too short | ||
while (textLength < maxWidth && truncatedText.length < text.length) { | ||
const newTruncatedText = `${text.slice( | ||
0, | ||
truncatedText.length - 3 + 1 | ||
)}...`; | ||
node.textContent = newTruncatedText; | ||
textLength = node.getComputedTextLength(); | ||
if (textLength > maxWidth) break; | ||
truncatedText = newTruncatedText; | ||
} | ||
} | ||
|
||
return truncatedText; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters