forked from airbnb/visx
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: text rendering with invalid x or y
- Loading branch information
Showing
6 changed files
with
124 additions
and
59 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// @ts-ignore | ||
let originalFn: typeof SVGElement.prototype.getComputedTextLength; | ||
|
||
/** | ||
* JSDom does not implement getComputedTextLength() | ||
* so this function add mock implementation for testing. | ||
*/ | ||
export function addMock() { | ||
// @ts-ignore | ||
originalFn = SVGElement.prototype.getComputedTextLength; | ||
|
||
// @ts-ignore | ||
SVGElement.prototype.getComputedTextLength = function getComputedTextLength() { | ||
// Make every character 10px wide | ||
return (this.textContent?.length ?? 0) * 10; | ||
}; | ||
} | ||
|
||
/** | ||
* Remove mock from addMock() | ||
*/ | ||
export function removeMock() { | ||
// @ts-ignore | ||
SVGElement.prototype.getComputedTextLength = originalFn; | ||
} |
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