plotly / plotly/plotly.js

Feature request: access to layers and subplots with stable API

未關閉
#7,488 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

主要語言
JavaScript
星號
18.3k
分支
2k
平均合併
2 天 12 小時
30 天內合併 PR
28

描述

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

貢獻指南

開啟貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

研究方向

從 issue 中描述的 getInteractorLayer 範例以及 plotly_relayout、plotly_afterplot 和 plotly_relayouting 進入點開始。定義一種公開替代方案,以取代對私有 _fullLayout 的存取,使其公開 subplots、clipId 和最上層的 shape 圖層,或建立一個最上層圖層,然後驗證是否可以透過示範的回呼來定位並重新算繪 interactors。

由索引模型根據 Issue 內容生成。

評估

技術堆疊
d3js, javascript
領域
api, data-visualization, frontend
Issue 類型
功能
難度
5/5
預估耗時
一週以上
活躍度
停滯
描述清晰度
基本清楚
新手友好度
25/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。