You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Pass customdata to custom marker functions (backward compatible) (#2)
* 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]>
@@ -6,30 +6,60 @@ This document describes how to use custom SVG marker functions in plotly.js scat
6
6
7
7
You can now pass a custom function directly as the `marker.symbol` value to create custom marker shapes. This provides a simple, flexible way to extend the built-in marker symbols without any registration required.
8
8
9
-
## Usage
9
+
## Function Signature
10
+
11
+
Custom marker functions receive:
12
+
13
+
```javascript
14
+
functioncustomMarker(r, customdata) {
15
+
// r: radius/size of the marker (half of marker.size)
16
+
// customdata: the value from trace.customdata[i] for this point (optional)
17
+
18
+
// Return an SVG path string centered at (0,0)
19
+
return'M...Z';
20
+
}
21
+
```
22
+
23
+
**Simple markers** can use just `(r)`:
24
+
```javascript
25
+
functiondiamond(r) {
26
+
return'M'+ r +',0L0,'+ r +'L-'+ r +',0L0,-'+ r +'Z';
27
+
}
28
+
```
29
+
30
+
**Data-aware markers** use `(r, customdata)`:
31
+
```javascript
32
+
functioncategoryMarker(r, customdata) {
33
+
if (customdata ==='high') {
34
+
return'M0,-'+ r +'L'+ r +','+ r +'L-'+ r +','+ r +'Z'; // up triangle
35
+
}
36
+
return'M0,'+ r +'L'+ r +',-'+ r +'L-'+ r +',-'+ r +'Z'; // down triangle
37
+
}
38
+
```
39
+
40
+
Note: Rotation is handled automatically via `marker.angle` - your function just returns an unrotated path.
0 commit comments