Feat: Improve the precision of label bounding box calculations and rendering#3418
Feat: Improve the precision of label bounding box calculations and rendering#3418fzaman-linz wants to merge 1 commit intocytoscape:unstablefrom
Conversation
577e69e to
652c2c8
Compare
|
Hi guys, could you please have a look cc: @d2fong |
|
Hi, thank you for your submission. Sorry for the long delay in response. Currently this repo isn't being actively maintained. The original maintainers (ie Max and me) have moved on to other things. I can only take a look at things when I have a bit of time here or there. Its been a policy to not add new visual properties unless there's a real demand for them. The reason is that all visual properties are public API, and any new ones need to be maintained and documented forever. Personally I don't think we should add visual properties for fine adjustments to bounding box calculations. They will be incomprehensible to most users of the library and they will make it harder to make changes to the bounding box calculations in the future. I quickly tested the changes on the demo page using label backgrounds. I set
Here are my suggestions for moving forward with this PR:
|
aef5c55 to
6809168
Compare
|
Thanks for the feedback @mikekucera. |
|
@maxkfranz Yes, label text baselines won't line up across the board. Tight bounding boxes need per‑word heights (which shifts baselines), while consistent baselines need fixed heights (which reintroduces the gaps we're trying to avoid). That's why keeping |
|
@fzaman-linz, the team will discuss this on a call on Thursday 23 April. |
|
@fzaman-linz, in the meantime, would you please update the OP with the current status of the feature (i.e. only currently proposed props)? |
6809168 to
8022d14
Compare
8022d14 to
f5acd09
Compare
|
@maxkfranz I've updated the OP and also updated the example URL to showcase default vs actual. |
|
Great. Thanks |
|
The team is discussing this feature and the details of the properties etc., and we'll have an update some time next week. |
| let halfBorderWidth = borderWidth / 2; | ||
| let padding = ele.pstyle( 'text-background-padding' ).pfValue; | ||
| let marginOfError = 2; // expand to work around browser dimension inaccuracies | ||
| let marginOfErrorX = ele.pstyle( 'bbox-margin-error-x' ).pfValue; // expand to work around browser dimension inaccuracies |
There was a problem hiding this comment.
Are larger values than 2 needed for specific cases?
There was a problem hiding this comment.
From @mikekucera :
Remove the bbox-margin-error-x / bbox-margin-error-y properties, the default of 2 is fine. Its not worth it to add two VPs just for this.
| valign: { enums: [ 'top', 'center', 'bottom' ] }, | ||
| halign: { enums: [ 'left', 'center', 'right' ] }, | ||
| justification: { enums: [ 'left', 'center', 'right', 'auto' ] }, | ||
| textMetrics: { enums: [ 'default', 'actual' ] }, |
There was a problem hiding this comment.
These values should be more descriptive so they're obvious as to what they do. E.g. 'aligned' | 'tight'. Or whatever names would be clear.
|
|
||
| let labelDims = this.calculateLabelDimensions( ele, text ); | ||
| let lineHeight = ele.pstyle('line-height').pfValue; | ||
| let size = ele.pstyle('font-size').pfValue; |
There was a problem hiding this comment.
Could you upload some screenshots of some line-height:1 multiline labels? We should verify that this change does not cause regressions. There are likely edge cases that normPerLineHeight was handling.




This PR improves the precision of label bounding box calculations and rendering by introducing new style properties and refining label metrics handling.
text-metrics (default | actual)Allows to choose between browser-default text metrics or actual font metrics (actualBoundingBoxAscent / Descent) for more accurate label height calculations.
bbox-margin-error-x/bbox-margin-error-yProvides fine-grained control over bounding box expansion to compensate for browser rendering inaccuracies. These replace the previous hardcoded marginOfError.
Label Dimension Calculation Enhancements
calculateLabelDimensions()now supportstext-metrics: actual, usingactualBoundingBoxAscentandactualBoundingBoxDescentfor more precise vertical alignment and height.Associated issues:
Checklist
Author:
unstable. Bug-fix patches can go on eitherunstableormaster.index.d.tsTypescript definition file has been appropriately updated.Reviewers:
masterbranch and theunstablebranch. Normally, this just requires cherry-picking the corresponding merge commit frommastertounstable-- or vice versa.