plotly / plotly/plotly.js

Feature request: access to layers and subplots with stable API

Open
#7,488 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
18.3k
Forks
2k
Avg merge
2d 12h
Merged PRs (30d)
28

Description

Context

We want to display interactive SVG elements on a plotly plot in data coordinates. In order to do this, we currently use the _fullLayout "private" API in order to get a handle to

  • subplots
  • clipId
  • top shape layer.

We then add a new layer for positioning interactive elements right above _fullLayout._shapeUpperLayer, as seen here:

import { select as d3_select } from 'd3-selection';

export function getInteractorLayer(plotlyPlot, plot='xy') {
  // plotlyPlot is a plotly plot object, e.g. from Plotly.newPlot() or Plotly.react()
  // plot is the subplot name, e.g. 'xy', 'x2y2'
  const subplot = plotlyPlot._fullLayout._plots[plot];
  const shapelayer = plotlyPlot._fullLayout._shapeUpperLayer;
  const layer_above = d3_select(shapelayer.node().parentNode);
  // create interactor layer, if not exists:
  layer_above.selectAll("g.interactorlayer")
    .data(["interactors"])
    .enter().append("g")
    .classed("interactorlayer", true);
  const interactorlayer = layer_above.selectAll("g.interactorlayer");
  const clipid = subplot.clipId.replace(/plot$/, '');
  return { interactorlayer, subplot, clipid };
}
Request

A public interface for getting handles to subplots, the clipId, and the top shape layer (or a simple API function for creating a new top layer!)

Once we have the items above, we can create interactors on top of a plotly plot and re-render them as needed with e.g.

  plotlyPlot.on('plotly_relayout', relayout);
  plotlyPlot.on('plotly_afterplot', relayout);
  plotlyPlot.on('plotly_relayouting', relayout);

as seen in this demo: https://bmaranville.github.io/plotly-interactors/demo.html (drag the interactors around and look at the console to see the callbacks being called with the updated state of the interactor)

Image

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the getInteractorLayer example and the plotly_relayout, plotly_afterplot, and plotly_relayouting entry points described in the issue. Define a public alternative to the private _fullLayout access that exposes subplots, clipId, and the top shape layer or creates a top layer, then verify that interactors can be positioned and re-rendered through the demonstrated callbacks.

Written by the indexing model from the issue text.

Assessment

Tech stack
d3js, javascript
Domain
api, data-visualization, frontend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.