-
Notifications
You must be signed in to change notification settings - Fork 0
Allow custom SVG marker functions directly as marker.symbol values #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Co-authored-by: gatopeich <7722268+gatopeich@users.noreply.github.com>
Co-authored-by: gatopeich <7722268+gatopeich@users.noreply.github.com>
Co-authored-by: gatopeich <7722268+gatopeich@users.noreply.github.com>
Co-authored-by: gatopeich <7722268+gatopeich@users.noreply.github.com>
|
@copilot It would be simpler to pass the custom symbol function directly instead of symbol name. Then the drawing code can check if "symbol" attribute is callable, and call it instead of looking into the index. |
Co-authored-by: gatopeich <7722268+gatopeich@users.noreply.github.com>
Good point! I've simplified the implementation to allow passing custom marker functions directly as The new approach:
Example: function customMarker(r) {
return 'M' + r + ',0L0,' + r + 'L-' + r + ',0L0,-' + r + 'Z';
}
Plotly.newPlot('div', [{
marker: { symbol: customMarker } // Direct function!
}]);Changes in commit 86086e0. |
src/components/drawing/index.js
Outdated
| if (Lib.isArrayOrTypedArray(endMarkerSize)) endMarkerSize = endMarkerSize[endI]; | ||
|
|
||
| b = endMarker ? drawing.symbolBackOffs[drawing.symbolNumber(endMarkerSymbol)] * endMarkerSize : 0; | ||
| b = endMarker ? (drawing.symbolBackOffs[drawing.symbolNumber(endMarkerSymbol)] || 0) * endMarkerSize : 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check if end symbol is function before calling symbolNumber() instead of falsy check
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot address this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 099b0d6. Now checking typeof endMarkerSymbol !== 'function' before calling symbolNumber(), consistent with how it's handled elsewhere in the code.
…calculation Co-authored-by: gatopeich <7722268+gatopeich@users.noreply.github.com>
| var endMarkerSize = endMarker.size; | ||
| if (Lib.isArrayOrTypedArray(endMarkerSize)) endMarkerSize = endMarkerSize[endI]; | ||
|
|
||
| b = endMarker ? drawing.symbolBackOffs[drawing.symbolNumber(endMarkerSymbol)] * endMarkerSize : 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just add check && typeof endMarkerSymbol !== 'function' instead of this messy change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Simplified in 42ab66d. Now using the ternary operator with the function check instead of introducing extra variables.
Co-authored-by: gatopeich <7722268+gatopeich@users.noreply.github.com>
|
@copilot Remove "|| 0" from src/components/drawing/index.js:1509 |
gatopeich
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay we'll leave the additional falsy check since it was present in other places too.
Simplified Custom Marker API
This PR enables passing custom functions directly as
marker.symbolvalues to create custom SVG marker shapes for scatter plots and related trace types, without requiring any registration step.Changes Made
Core Implementation (
src/components/drawing/index.js)makePointPath()to accept either a symbol number or a custom functionsinglePointStyle()to detect function symbols and pass them through directlyselectedPointStyle()to handle function symbolssymbolNumber()on custom functionsTests (
test/jasmine/tests/drawing_test.js)marker.symbolDocumentation
CUSTOM_MARKER_FUNCTIONS.md: API reference with examplesdevtools/custom_marker_demo.html: Interactive demoUsage
Functions can be used in arrays and mixed with built-in symbol names:
Benefits
Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.