[WIP] Refactor Plotly.js marker symbols to use constant SVG paths#8
Closed
[WIP] Refactor Plotly.js marker symbols to use constant SVG paths#8
Conversation
Owner
|
Duplicate |
Copilot stopped work on behalf of
gatopeich due to an error
March 21, 2026 04:28
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.
Thanks for asking me to work on this. I will get started on it and keep this PR's description up to date as I form a plan and make progress.
Original prompt
Summary
Refactor Plotly.js marker symbols from functions that compute SVG paths per-point to constant SVG path strings rendered via
<symbol>/<use>reuse. This eliminates per-point path computation, produces smaller SVG output, and creates a unified API for default and custom markers.Code Guidelines
Current Architecture (to be replaced)
src/components/drawing/symbol_defs.js{ n: <number>, f: function(r, angle, standoff) { ... return SVG path string }, needLine, noDot, noFill, backoff }.r,angle, andstandoff. It callsround()extensively and uses aparseSvgPath+align()function for rotation/standoff transforms.align()function (lines 721–813) parses the SVG path string, applies rotation and standoff transforms by manipulating path coordinates, and returns a new path string. It has a single-entry cache.parse-svg-pathnpm package just foralign().src/components/drawing/index.jsdrawing.symbolFuncs[],drawing.symbolNames[],drawing.symbolBackOffs[],drawing.symbolNeedLines{},drawing.symbolNoDot{},drawing.symbolNoFill{},drawing.symbolList[]fromsymbol_defs.js(lines 322–367).makePointPath(symbolNumber, r, t, s)(line 395): callsdrawing.symbolFuncs[base](r, t, s)to get a path string, appends DOTPATH if needed. Called for every single marker point in the SVG rendering pipeline.drawing.singlePointStyle()(line 892): for each point, computes angle/standoff, callsmakePointPath(), setssel.attr('d', path)— meaning every point gets a unique<path d="...">with a fully computed path string.drawing.selectedPointStyle()(line 1192): same pattern — recomputes path viamakePointPath()on selection size change.src/traces/scattergl/convert.jsgetSymbolSdf()(line 462): usesDrawing.symbolFuncs[symbolNumber % 100]to generate SVG path strings for SDF texture generation (WebGL). Calls the function withSYMBOL_SIZE(=20) and the angle.SYMBOL_SVG_CIRCLE = Drawing.symbolFuncs[0](SYMBOL_SIZE * 0.05)— used for dot overlay.viewBoxparameter, so it can work with any reference size.Current SVG output for 1000 markers of the same symbol
Target Architecture
1.
src/components/drawing/symbol_defs.js— Convert to constant path stringsReplace each symbol's
f: function(r, angle, standoff) {...}withp: "SVG path string"— a constant string pre-computed forr=10on a viewport from-10,-10to+10,+10centered on0,0.r=10, angle=0, standoff=0(the default/common case).align()function entirely (107 lines).skipAngle()function.parse-svg-pathdependency (it was only used byalign()).round()helper function.n,needLine,noDot,noFill,backoff.'M0,0Z'remains for theangle === nullcase, handled in the rendering pipeline.Example transformation:
Do this for ALL 55 symbols. Compute each path string by mentally/manually evaluating the function at r=10. Here are some to get started (compute all of them):
'M10,0A10,10 0 1,1 0,-10A10,10 0 0,1 10,0Z''M10,10H-10V-10H10Z''M13,0L0,13L-13,0L0,-13Z''M12,4H4V12H-4V4H-12V-4H-4V-12H4V-4H12Z'round(10 * 0.8 / sqrt2, 2)=round(5.657, 2)=5.66, then build the path withrx=5.66.rt = round(10 * 2 / sqrt3, 2) = 11.55,r2 = 5,rs = 10→'M-11.55,5H11.55L0,-10Z'For symbols with trigonometric computations (arrow, arrow-wide), evaluate at r=10:
headAngle = PI/2.5,x = 2*10*cos(PI/2.5) ≈ 12.36,y = 2*10*sin(PI/2.5) ≈ 19.02→'M0,0L-12.36,19.02L12.36,19.02Z'(round to 2 decimal places)2.
src/components/drawing/index.js— Use<symbol>/<use>pipelineReplace
drawing.symbolFuncs[]withdrawing.symbolPaths[]: