Appending a new mark after Plot.plot has been called

Is there a way to add a new mark to a Plot after it has been created?

More broadly, I have a few lines I want to display, but only one of the lines (call this the prediction line) will be displayed when the pointer moves across the chart. I want to be able to only display the prediction line to the right of pointerX.

I imagine one option will be to use the input EventListener to feed into a callback that can dynamically filter what should be displayed for the prediction line, but this would require being able to also append a Plot.line mark in the callback.

I hope this is clear! Any help is much appreciated, thanks in advance!

It’s not possible to add marks after the chart is rendered, but here are two ways to do what you want:

  1. create the mark initially, and use the render option to display it later (interactively); or
  2. create the line as a new path in the generated SVG, possibly building on the scales to make it consistent with the other marks.

See document the custom render option by Fil · Pull Request #1811 · observablehq/plot · GitHub and Interactions | Observable Plot

1 Like