Skip to content

Conversation

@degzhaus
Copy link

@degzhaus degzhaus commented Oct 14, 2025

Overview

This PR adds a new quiver trace type to Plotly.js for visualizing 2D vector fields using arrows.

Features

  • Vector positioning: Arrows placed at x, y coordinates with direction/magnitude from u, v components
  • Sizing modes: scaled (normalized), absolute, or raw vector lengths via sizemode/sizeref
  • Arrow anchoring: Position arrows by tail, tip, or center/cm/middle
  • Colorscale support: Color arrows by magnitude or custom scalar field (c array)
  • Styling: Configurable line color, width, dash patterns via line.* attributes
  • Arrowhead sizing: Adjustable arrowhead size via arrowsize
  • Full interactivity: Hover support with customizable hovertemplate, point selection
  • Animation support: Animatable x, y, u, v, and c arrays

API

Plotly.newPlot('div', [{
  type: 'quiver',
  x: [0, 1, 2],
  y: [0, 1, 2],
  u: [1, 0, -1],  // x-component of vectors
  v: [0, 1, 0],   // y-component of vectors
  sizemode: 'scaled',  // 'scaled' | 'absolute' | 'raw'
  sizeref: 0.5,
  anchor: 'tail',  // 'tail' | 'tip' | 'center'
  colorscale: 'Viridis',
  line: { width: 2 }
}]);

Screenshots

Examples taken from plotly.com/python/quiver-plots

Gist with example code

Basic Quiver Plot

Basic quiver plot

With Colorscale

Quiver with Viridis colorscale

Testing

  • ✅ Jasmine unit tests
  • ✅ 9 visual regression test mocks

Files Changed

New files (src/traces/quiver/)

  • index.js - Trace module definition
  • attributes.js - Attribute schema
  • defaults.js - Default value handling
  • calc.js - Data calculation
  • plot.js - SVG rendering
  • style.js - Styling
  • hover.js - Hover behavior
  • select_points.js - Selection support
  • event_data.js - Event data formatting
  • format_labels.js - Label formatting

Modified

  • lib/index.js & lib/index-strict.js - Build integration

Tests

  • test/jasmine/tests/quiver_test.js - Unit tests
  • test/image/mocks/quiver_*.json - 9 mock files
  • test/image/baselines/quiver_*.png - Baseline images

@degzhaus degzhaus force-pushed the degzhaus/add_scatterquiver branch 4 times, most recently from dfd3c81 to 9463b3f Compare October 19, 2025 21:12
@degzhaus
Copy link
Author

degzhaus commented Oct 19, 2025

Hello, I am new to this project and attempting to contribute my first PR.

Unfortunately, I am struggling to get the build to pass. Specifically, the publish-dist-node-v22 step:
https://app.circleci.com/pipelines/github/plotly/plotly.js/12658/workflows/ae5271e7-9971-4db1-a713-b42f0625901f/jobs/282198

I tried running npm run schema and pushing the change here:
9463b3f

But still encountering the issue.

Any insight would be greatly appreciated. Thank you!

Edit: tagging a few recent commiters for visibility, thanks so much! (cc @camdecoster @alexshoe @emilykl)

@emilykl
Copy link
Contributor

emilykl commented Oct 20, 2025

Hi @degzhaus, thank you for working on this contribution!

As it stands currently, the devtools dashboard needs to be running in order for npm run schema to work properly. So you should run npm start and leave it running, and then in another terminal run npm run schema. (@camdecoster is working on a PR to eliminate that step, see #7589)

You can also download plot-schema.json from the "Artifacts" tab in CircleCI and commit it.

@degzhaus degzhaus force-pushed the degzhaus/add_scatterquiver branch 18 times, most recently from b07de7b to a32678d Compare October 22, 2025 03:33
@degzhaus
Copy link
Author

degzhaus commented Oct 22, 2025

Hi @degzhaus, thank you for working on this contribution!

As it stands currently, the devtools dashboard needs to be running in order for npm run schema to work properly. So you should run npm start and leave it running, and then in another terminal run npm run schema. (@camdecoster is working on a PR to eliminate that step, see #7589)

You can also download plot-schema.json from the "Artifacts" tab in CircleCI and commit it.

Thank you so much, @emilykl! That was very helpful and unblocked me.

Unfortunately, I have been struggling with the no-gl-jasmine test in ci:
https://app.circleci.com/pipelines/github/plotly/plotly.js/12700/workflows/8b80de4d-1bad-455d-baef-72bc47c31042/jobs/283463

If you have any insight, I would greatly appreciate it. Thanks again!

Edit: @emilykl i figured it out! Pardon my flailing at last night. So exciting! I have a couple of tests to add and this will be ready for review.

Thanks again for your insights and help!

@degzhaus degzhaus force-pushed the degzhaus/add_scatterquiver branch 2 times, most recently from 64cf31d to 02c37f5 Compare October 22, 2025 15:56
@emilykl
Copy link
Contributor

emilykl commented Oct 22, 2025

@degzhaus Great news, glad you're unblocked! Thank you for your work on this. Quiver is a plot type we've gotten a lot of requests for.

A few high-level comments on the API:

  • This trace type is fairly distinct from existing scatter* trace types; let's go with the name quiver instead.

  • The most similar already-existing trace type is the 3d cone trace, so the attributes of quiver should match the existing API of cone as closely as possible for consistency. For example, rather than the scale property it should use sizemode and sizeref as the cone trace does. (Obviously, some attributes like z and w are not relevant in a 2d context).

  • Any attributes for configuring the size/scale of the arrowhead should match the arrowhead config options for annotations

    • It's also not necessary to include those options in a first version of this trace type, but any attributes that are added should be consistent with what's already in the library
  • There's a few other things I noticed in the attributes as well:

    • The scaleratio attribute doesn't belong; the scale ratio between the axes should be a property of the axes themselves, not the trace. The axis scale ratio can already be configured using the existing axis.scaleratio attribute.
    • It's unclear to me how the angle attribute interacts with u and v, since u and v are already sufficient to fully determine the arrow's angle. The angle attribute should probably be removed.

@degzhaus
Copy link
Author

@degzhaus Great news, glad you're unblocked! Thank you for your work on this. Quiver is a plot type we've gotten a lot of requests for.

A few high-level comments on the API:

  • This trace type is fairly distinct from existing scatter* trace types; let's go with the name quiver instead.

  • The most similar already-existing trace type is the 3d cone trace, so the attributes of quiver should match the existing API of cone as closely as possible for consistency. For example, rather than the scale property it should use sizemode and sizeref as the cone trace does. (Obviously, some attributes like z and w are not relevant in a 2d context).

  • Any attributes for configuring the size/scale of the arrowhead should match the arrowhead config options for annotations

    • It's also not necessary to include those options in a first version of this trace type, but any attributes that are added should be consistent with what's already in the library
  • There's a few other things I noticed in the attributes as well:

    • The scaleratio attribute doesn't belong; the scale ratio between the axes should be a property of the axes themselves, not the trace. The axis scale ratio can already be configured using the existing axis.scaleratio attribute.
    • It's unclear to me how the angle attribute interacts with u and v, since u and v are already sufficient to fully determine the arrow's angle. The angle attribute should probably be removed.

Amazing, thank you so much for taking a look and providing great guidance, Emily! Looking forward to spinning a cycle on this feedback.

@emilykl
Copy link
Contributor

emilykl commented Oct 22, 2025

@degzhaus One more comment — it would be great to include colorscale attributes in quiver so that arrows can be colored according to the magnitude of the vector. These attributes are added to the cone trace here; something similar can be done for the quiver trace. And then obviously those attributes need to be referenced in the plotting code to assign the appropriate color.

@degzhaus degzhaus force-pushed the degzhaus/add_scatterquiver branch 3 times, most recently from feea298 to f3ae9e2 Compare November 19, 2025 05:23
@degzhaus degzhaus force-pushed the degzhaus/add_scatterquiver branch from 60ca5c5 to a008dab Compare November 30, 2025 00:54
@degzhaus
Copy link
Author

Pardon the delay, @emilykl, i was finally able to make time to clean this up. I removed some of my recent comments/questions because they were noise around me understanding how to work with the tests/images, but i was able to figure it out.

Thanks again for all your help with this PR! Excited for next steps.

@emilykl
Copy link
Contributor

emilykl commented Dec 3, 2025

Hi @degzhaus ! I'm aiming to give this another review by the end of the week. Sorry for the delay in getting back to you — looking forward to it! Thanks for your work so far.

@degzhaus degzhaus force-pushed the degzhaus/add_scatterquiver branch from 60d1da9 to a8f8381 Compare December 18, 2025 21:20
@gpdf
Copy link

gpdf commented Dec 18, 2025

Thank you for this idea, @gpdf ! Added here:

That's great, thank you!

@degzhaus degzhaus force-pushed the degzhaus/add_scatterquiver branch 2 times, most recently from 69947b2 to b93b445 Compare December 18, 2025 23:10
@gpdf
Copy link

gpdf commented Dec 18, 2025

Perhaps for future readers' clarity of understanding, @degzhaus , you could edit the description at the top of the PR to say:

scatterquiver quiver

in the two places it appears, so that the as-merged plot type appears there.

@degzhaus degzhaus force-pushed the degzhaus/add_scatterquiver branch from b93b445 to 0252e03 Compare December 19, 2025 01:07
@degzhaus
Copy link
Author

Perhaps for future readers' clarity of understanding, @degzhaus , you could edit the description at the top of the PR to say:

scatterquiver quiver

in the two places it appears, so that the as-merged plot type appears there.

Great catch, thank you so much, @gpdf !

Updated per your recommendation, and did a little review/revision based on changes made during the review process as well.

@degzhaus
Copy link
Author

Hi @degzhaus ! I'm aiming to give this another review by the end of the week. Sorry for the delay in getting back to you — looking forward to it! Thanks for your work so far.

Hey there, @emilykl, hope you're having a wonderful week!

I rebased, cleaned up some code, and added some tests here:
0252e03

Thanks again for everything!

@gpdf
Copy link

gpdf commented Dec 19, 2025

I really appreciate all the effort in polishing, and very much look forward to using this.

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

Labels

community community contribution feature something new P2 considered for next cycle

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants