Skip to content

Conversation

@gatopeich
Copy link

@gatopeich gatopeich commented Nov 22, 2025

This pull request introduces support for custom marker functions in Plotly.js scatter plots, allowing users to pass a function directly as the marker.symbol property to define custom SVG marker shapes.

Function Signature

Custom marker functions receive a simple signature:

function customMarker(r, customdata) {
    // r: radius (half of marker.size)
    // customdata: value from trace.customdata[i] for this point
    return 'M...Z';  // SVG path centered at (0,0)
}
  • Simple markers can use just (r): function diamond(r) { return 'M' + r + ',0L0,' + r + 'Z'; }
  • Data-aware markers use (r, customdata) to vary shape based on data
  • Rotation is handled automatically via marker.angle - functions return unrotated paths

Demo

Weather map with sun, cloud, and wind icons generated by custom marker functions:

Weather Map Demo

Live demo: https://gatopeich.github.io/plotly.js/

Changes

  • src/components/drawing/index.js: Handle functions as marker.symbol, passing (r, customdata) to custom functions and applying rotation/standoff via align()
  • src/components/drawing/symbol_defs.js: Export align() function
  • src/lib/coerce.js: Allow functions as valid symbol values
  • CUSTOM_MARKER_FUNCTIONS.md: Documentation with examples
  • devtools/demos/: Demo files (weather map, backward compatibility, custom markers)
  • test/jasmine/tests/drawing_test.js: Tests for custom marker functions

@camdecoster
Copy link
Contributor

Hello @gatopeich! Before we review this PR, could you please help us understand what use case prompted this change? Ideally, you'd create an issue describing the problem and explaining why it should be fixed.

@gatopeich
Copy link
Author

I've used this professionally over the last few years to plot meaningful icons on top of maps, e.g. pedestrians, cars, directional wind arrows based on data...
Copilot was able to recreate the concept but did not produce a meaningful demo.

@gatopeich gatopeich marked this pull request as draft December 2, 2025 18:38
@gatopeich
Copy link
Author

Let me add some nice example.
I also realize that the function could take more inputs that the size... I solved that with scoped lambdas in the past but now we can make it ellegant.

@camdecoster
Copy link
Contributor

Sounds good. While you're at it, could you double check the test you added? It's failing in CI.

@camdecoster camdecoster assigned gatopeich and unassigned camdecoster Jan 6, 2026
* Initial plan

* Add data point and trace context to custom marker functions

Co-authored-by: gatopeich <[email protected]>

* Improve comment clarity for custom marker function parameters

Co-authored-by: gatopeich <[email protected]>

* Add weather map demo and documentation for custom marker functions

Co-authored-by: gatopeich <[email protected]>

* Add backward compatibility test demo

Co-authored-by: gatopeich <[email protected]>

* Remove dist folder changes - these are build artifacts for maintainers

Co-authored-by: gatopeich <[email protected]>

* Fix coercion to allow function values for marker.symbol

Allow functions to pass through enumerated coercion for custom marker symbols.
Update weather map demo with proper meteorological wind barbs.

* Auto-rotate custom marker functions via align()

- Export align() from symbol_defs.js
- Apply align() automatically to custom function results in makePointPath()
- Simplify custom function signature to (r, d, trace)
- Update weather demo with cleaner wind barbs and compact layout

* Simplify custom marker function signature to (r, customdata)

- Custom functions now receive (r, customdata) instead of (r, d, trace)
- customdata is the value from trace.customdata[i] for each point
- Rotation and standoff handled automatically via align()
- Updated demos to use new signature

* Improve weather demo with jet stream wind pattern

* Add UTF-8 icons to weather demo legend

* Rename pt back to d to match call sites

* Remove unused trace parameter from makePointPath

* Update docs and tests for (r, customdata) signature

---------

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: gatopeich <[email protected]>
@gatopeich gatopeich marked this pull request as ready for review January 18, 2026 01:58
@gatopeich
Copy link
Author

I polished the implementation and added access to customdata.
See what you can do with my custom markers now:
image
live demo here: https://gatopeich.github.io/plotly.js/demos/weather_map_demo.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants