add configuration property per shape to prevent user edits
还没有人认领这个 Issue。
- 主要语言
- JavaScript
- 星标
- 18.3k
- 派生
- 2k
- 平均合并
- 2 天 12 小时
- 30 天内合并 PR
- 28
描述
Hello,
I've been looking for a means to easily configure shape definitions such that any user edits (e.g. repositioning the shape) to them are blocked.
At this time of writing, the figure reference for shapes doesn't appear to have a property where one can achieve the above (e.g. an editable property). In case I've missed something in the API that makes this effortless, I'd appreciate any pointers.
In the meanwhile, I guess there are workarounds, such as my following example below which makes use of mouse event handlers:
import Plotly from 'plotly.js';
const data = [
{
x: [1, 2, 3, 4],
y: [2, 4, 8, 16],
type: 'scatter',
mode: 'lines'
}
];
const layout = {
shapes: [
{
type: 'rect',
x0: 2,
x1: 3,
y0: 5,
y1: 10
}
]
};
const config = {
editable: true
};
const plot = document.getElementById('plot');
Plotly.newPlot(plot, data, layout, config);
let blockMoveEvents = false;
plot.addEventListener('mousedown', e => {
if (e.target.closest('.shapelayer') == null) {
return;
}
blockMoveEvents = true;
});
document.addEventListener('mousemove', e => {
if (blockMoveEvents) {
e.stopImmediatePropagation();
}
});
document.addEventListener('mouseup', e => {
blockMoveEvents = false;
});
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从报告中展示的布局 shapes 参考和 Plotly.newPlot 配置开始,包括 config.editable 以及链接的 CodeSandbox workaround。跟踪 shape 交互的处理方式,并确定应将逐个 shape 的可编辑性放在哪里。完成的标准是:受保护的 shapes 无法重新定位,同时其他可编辑的 plot 交互仍能正常工作。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- javascript
- 领域
- data-visualization
- Issue 类型
- 功能
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100