Skip to content

Pass data point and trace context to custom marker functions (backward compatible)#2

Merged
gatopeich merged 14 commits intomasterfrom
copilot/add-custom-data-to-function
Jan 18, 2026
Merged

Pass data point and trace context to custom marker functions (backward compatible)#2
gatopeich merged 14 commits intomasterfrom
copilot/add-custom-data-to-function

Conversation

Copy link

Copilot AI commented Dec 2, 2025

  • Extend custom marker function API to pass (r, angle, standoff, d, trace)
  • Update makePointPath in src/components/drawing/index.js
  • Update call sites in singlePointStyle and selectedPointStyle
  • Add tests for new context parameters
  • Update CUSTOM_MARKER_FUNCTIONS.md with documentation and weather map example
  • Add weather map demo at devtools/demos/weather_map_demo.html
  • Add backward compatibility test at devtools/demos/backward_compatibility_test.html
  • Remove dist folder changes per CONTRIBUTING.md guidelines

Summary

Extended the custom marker function API to pass data point (d) and trace context to custom functions, enabling data-driven markers.

Backward Compatibility: ✅ Existing marker functions with 3 parameters continue to work without modification.

Source Code Changes:

  • src/components/drawing/index.js: Modified makePointPath() to pass d and trace to custom functions
  • test/jasmine/tests/drawing_test.js: Added tests for new functionality
  • CUSTOM_MARKER_FUNCTIONS.md: Updated documentation with examples
  • devtools/demos/*.html: Added demo files

Build Artifacts: Dist folder changes removed per CONTRIBUTING.md - these are updated by maintainers at release time.

API: function customMarker(r, angle, standoff, d, trace) - backward compatible, optional parameters.

Demo Screenshots

Weather Map Demo:

Weather Map Demo

Shows custom weather markers with sun symbols (☀️), cloud shapes (☁️), and directional wind arrows (🌬️) with speed bars based on customdata.

Backward Compatibility Test:

Backward Compatibility Test

Demonstrates that old style functions (3 params) and new style functions (5 params) work together seamlessly.

Original prompt

Can we pass more than a "size" value to the function? E.g. a custom data object. Something in line with existing plotly features.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@gatopeich
Copy link
Owner

Use case: place wind markers on a weather map where each marker shows direction and speed of wind at different spots. Speed adds bars to a directional arrow where 1 bar is low and 3 bars is high.

@gatopeich
Copy link
Owner

gatopeich commented Dec 2, 2025

Should we add more, maybe optional, parameters to the functions? Should we use dot attributes of a single param?

Copilot AI and others added 2 commits December 2, 2025 18:52
Co-authored-by: gatopeich <7722268+gatopeich@users.noreply.github.com>
Co-authored-by: gatopeich <7722268+gatopeich@users.noreply.github.com>
Copilot AI changed the title [WIP] Add support for custom data objects in function Pass data point and trace context to custom marker functions Dec 2, 2025
Copilot AI requested a review from gatopeich December 2, 2025 18:59
@gatopeich
Copy link
Owner

@copilot address my commente above and create a "weather map" demo with Clouds, Sunny, and directional wind markers. The demo should be an html snippet, ideally embeddable in GitHub comment or the PR description

Co-authored-by: gatopeich <7722268+gatopeich@users.noreply.github.com>
@gatopeich
Copy link
Owner

@copilot can't we achieve the same just placing a complex object in r, instead of making this change?
I am worried about having to change all existing marker functions just for this...

Copy link
Author

Copilot AI commented Jan 17, 2026

@copilot can't we achieve the same just placing a complex object in r, instead of making this change?
I am worried about having to change all existing marker functions just for this...

The current approach is backward compatible - existing marker functions don't need to change at all.

In JavaScript, if a function expects 3 parameters but receives 5, the extra parameters are simply ignored. So existing functions like function heartMarker(r, angle, standoff) continue to work perfectly when called with (r, angle, standoff, d, trace).

Passing a complex object in r would actually break all existing marker functions because:

  1. Built-in marker functions (circle, square, etc.) expect r to be a number for calculations like r * 0.5
  2. All existing custom marker functions use r as a numeric radius
  3. Functions would need to add if (typeof r === 'object') checks

The current design:

  • ✅ Existing functions work unchanged: function(r, angle, standoff)
  • ✅ New functions can access data: function(r, angle, standoff, d, trace)
  • ✅ Parameters are optional - only use d and trace when needed
  • ✅ Semantically clear - r stays as radius, data is in d

Co-authored-by: gatopeich <7722268+gatopeich@users.noreply.github.com>
Copilot AI changed the title Pass data point and trace context to custom marker functions Pass data point and trace context to custom marker functions (backward compatible) Jan 17, 2026
@gatopeich
Copy link
Owner

@copilot why do we have to change all those ids in so many places in the code?

Copy link
Author

Copilot AI commented Jan 17, 2026

@copilot why do we have to change all those ids in so many places in the code?

The ID changes you're seeing are not from my code changes. They're CSS injection IDs from the maplibre-gl library that got regenerated when running npm run build.

These IDs are content-based hashes that maplibre-gl uses to inject CSS only once. Every time the dist files are rebuilt, these hashes can change even if the actual CSS content is identical.

My actual code changes are minimal:

  • src/components/drawing/index.js: Modified makePointPath() to pass 2 extra parameters (d, trace) to custom functions
  • test/jasmine/tests/drawing_test.js: Added tests
  • CUSTOM_MARKER_FUNCTIONS.md: Updated documentation
  • devtools/demos/*.html: Added demo files

The dist folder changes (all the plotly.js, plotly.min.js, etc.) are automatically generated build artifacts that include the source changes bundled with all dependencies. The hash ID changes are just noise from the build process, not actual functional changes.

@gatopeich
Copy link
Owner

@copilot do we have to commit changes to the dist folder?
Furthermore, push them upstream?

Copy link
Author

Copilot AI commented Jan 17, 2026

@copilot do we have to commit changes to the dist folder?
Furthermore, push them upstream?

You're right - according to CONTRIBUTING.md: "please do not change and commit any files in the dist folder"

The dist files are build artifacts that maintainers update at release time. I'll remove them from the commits. The only files that should be in the PR are:

  • src/components/drawing/index.js (source changes)
  • test/jasmine/tests/drawing_test.js (tests)
  • CUSTOM_MARKER_FUNCTIONS.md (documentation)
  • devtools/demos/*.html (demo files)

Removing dist folder now...

@gatopeich
Copy link
Owner

@copilot how can we see the demos? Can we embed html here? can I download the html and have it include dist files from here?

Co-authored-by: gatopeich <7722268+gatopeich@users.noreply.github.com>
@gatopeich
Copy link
Owner

@copilot I need screenshots of the 2 demos

Copy link
Author

Copilot AI commented Jan 17, 2026

@copilot how can we see the demos? Can we embed html here? can I download the html and have it include dist files from here?

Viewing the demos:

  1. Local testing: Clone the repo and open the HTML files directly in a browser - they reference ../../dist/plotly.js which works locally
  2. Via web server: Run python -m http.server in the repo root and navigate to http://localhost:8000/devtools/demos/weather_map_demo.html
  3. GitHub Pages: The demos could be hosted via GitHub Pages if you enable it for this repo

Embedding in PR/comments: GitHub doesn't allow direct HTML embedding in comments for security reasons. However, you can:

  • Link to the demo files in the repo
  • Include screenshots (see next comment)
  • Copy the demo code into markdown code blocks

Using dist files from repo: Yes! The demos already reference ../../dist/plotly.js which points to the dist folder in this repo, so they work standalone once you have the repo locally.

@copilot I need screenshots of the 2 demos

Weather Map Demo:

Weather Map Demo

Shows custom weather markers with:

  • ☀️ Yellow sun symbols with rays
  • ☁️ Gray cloud shapes
  • 🌬️ Blue wind arrows with directional rotation and 1-3 speed bars based on customdata

Backward Compatibility Test:

Backward Compatibility Test

Demonstrates that:

  • Old style functions (3 params) work unchanged (blue diamonds)
  • New style functions (5 params) can access data (red circles, size varies by customdata)

gatopeich added 2 commits January 17, 2026 22:11
Allow functions to pass through enumerated coercion for custom marker symbols.
Update weather map demo with proper meteorological wind barbs.
- 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
@gatopeich
Copy link
Owner

Now we got it:
image

gatopeich added 3 commits January 18, 2026 00:37
- 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
@gatopeich
Copy link
Owner

Now we have a very nice demo:
image
https://gatopeich.github.io/plotly.js/demos/weather_map_demo.html

@gatopeich gatopeich marked this pull request as ready for review January 18, 2026 01:54
@gatopeich gatopeich merged commit 0cc49cc into master Jan 18, 2026
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