-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix!: shim an implementation of
getSubStringLength
(#6663) (CP: 24.…
…4) (#6670) * Shim an implementation of `getSubStringLength` (#6663) * Shim an implementation of getSubStringLength Estimate the rendered length of a substring of text in an SVG element. Supports wrapping/truncation of long labels in charts. * Improve shimmed measurement routines Improve shims of getBBox and getSubStringLength: The prior implementations were relying on specific DOM structures that Highcharts used to create: if the measured element had children, all text was expected to be within those children, and none in the top-level element. Also, it did not handle arbitrary element nesting. The current version of Highcharts does not always follow these rules, and there were cases of structures like: <text>Some text here<tspan>and some in a nested element</tspan></text> In that example, 'Some text here' would be omitted from measurement. Replace that strategy with one that processes each text node separately, providing the context of the containing element, and recursing into all nested elements. Fix some bugs around new line management in getBBox that became apparent after that change. The previous method of computing string width was a rough approximation based on average character width. This method produced suboptimal results in many situtations, generating extra space or overlapping text. Instead, use the string-pixel-width library to provide a better estimate. This library has per-character widths for a number of font families and variants, and results in widths much closer to the actual rendered style. As Lucida is used heavily in at least the test charts, and it is not natively supported by the library, add a custom mapping file including metrics for it. Also, improve detection of font family and font size, walking up the element parent chain (even potentially outside of the measured element) to find settings of these attributes. * Review cleanup * Test getSubStringLength Add test for getSubStringLength to ensure proper handling of sub-strings crossing text nodes (and other cases). To support this, change the way methods are added to jsdom SVG elements: rather than adding them only for elements instantiated via createElementNS, add them to the SVGElement prototype. This makes them available for elements created by any method of instantiation (including by setting innerHTML, as used in the test). Use rewire to access private elements of the exporter during tests. * spotless * chore: pin npm dependencies --------- Co-authored-by: Aron Nopanen <[email protected]> Co-authored-by: Diego Cardoso <[email protected]>
- Loading branch information
1 parent
d8d78cc
commit 9c678b0
Showing
14 changed files
with
822 additions
and
100 deletions.
There are no files selected for viewing
583 changes: 583 additions & 0 deletions
583
vaadin-charts-flow-parent/vaadin-charts-flow-svg-generator/customWidthsMap.js
Large diffs are not rendered by default.
Oops, something went wrong.
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
2 changes: 1 addition & 1 deletion
2
...nt/vaadin-charts-flow-svg-generator/src/test/resources/column-without-title.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.