Repository navigation
[profiler] Rasterize the node chips at 4x so they stay sharp in Safari - #7827
Merged
Merged
Conversation
WebKit rasterizes an SVG image at its intrinsic size before cytoscape draws it to the canvas. The chips had a 1x intrinsic size, so on a Retina screen Safari upscaled a 1x bitmap and the icons looked blurry. Chrome re-renders the SVG at the target size, so it did not show the problem. The chip SVGs now have a 4x intrinsic size. The viewBox and the cytoscape background size stay the same, so the layout does not change. Cytoscape caches each node at a power-of-two scale of up to 4, so 4x matches its largest cache scale. Fixes #7738
| it('rasterizes above the size it is drawn at, so Safari does not upscale a 1x bitmap', () => { | ||
| // WebKit rasterizes an SVG image at its intrinsic size. Cytoscape then scales that bitmap by | ||
| // zoom (up to 1.5) and devicePixelRatio (2 on Retina). | ||
| const MIN_SCALE = 1.5 * 2 |
Contributor
There was a problem hiding this comment.
pitfall (medium): This floor (3) doesn't match the reasoning in chips.ts. There, cytoscape caches at power-of-two scales, so on Retina at zoom > 1 the scale is 4, and "a 3x image would still be upscaled" (from the PR description). If someone drops CHIP_RASTER_SCALE to 3, this test still passes and the blur comes back. Set the floor to the cache scale, e.g. 2 ** Math.ceil(Math.log2(1.5 * 2)) (= 4), so the test checks the stated invariant. Also, 1.5 duplicates maxZoom(1.5) from viewport.ts. Consider exporting that as a constant.
Contributor
|
What I ran (profiler-lib):
Otherwise LGTM. The layout and hit boxes stay the same because |
The test floor was zoom * devicePixelRatio (3), so a CHIP_RASTER_SCALE of 3 passed although cytoscape caches nodes at scale 4 on Retina at zoom above 1. The floor is now that power-of-two cache scale. The max zoom is the MAX_ZOOM constant, shared by viewport.ts and the test.
mihaibudiu
approved these changes
Nov 4, 2026
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #7738
Cause
The node chips (
</>and the operator count with the network icon) are SVGdata:URIs that cytoscape draws withdrawImage. WebKit rasterizes an SVG image at its intrinsicwidth/heightbefore the draw. The chips had a 1x intrinsic size, so on a Retina screen Safari upscaled a 1x bitmap. Chrome re-renders the SVG at the target size, so it did not show the problem.Fix
chips.ts: the SVGwidth/heightareCHIP_RASTER_SCALE(4) times theviewBox. TheviewBoxand the cytoscapebackground-width/background-heightdo not change, so the layout and the chip hit boxes stay the same.2^ceil(log2(zoom * devicePixelRatio)), max 4). On Retina at zoom above 1 that scale is 4, so a 3x image would still be upscaled.Cytoscape decodes each distinct image URI once, and all nodes share it.
Tests
chips.test.ts: the intrinsic size is at least 3x theviewBox(zoom 1.5 x devicePixelRatio 2), with the same aspect ratio. It fails without the fix.viewBoxinstead of the SVGwidth/height.viewport.test.tshas 2 failures that also occur onmain. This PR does not touch that file.