Auto merge of #14565 - Veykril:view-crate-graph, r=Veykril

minor: Allow copying the graphviz source from the view crategraph webview
This commit is contained in:
bors 2023-04-13 20:03:44 +00:00
commit 2c251a7e2b

View file

@ -667,17 +667,22 @@ function crateGraph(ctx: CtxInit, full: boolean): Cmd {
<script type="text/javascript" src="${uri}/d3-graphviz/build/d3-graphviz.min.js"></script> <script type="text/javascript" src="${uri}/d3-graphviz/build/d3-graphviz.min.js"></script>
<div id="graph"></div> <div id="graph"></div>
<script> <script>
let dot = \`${dot}\`;
let graph = d3.select("#graph") let graph = d3.select("#graph")
.graphviz({ useWorker: false, useSharedWorker: false }) .graphviz({ useWorker: false, useSharedWorker: false })
.fit(true) .fit(true)
.zoomScaleExtent([0.1, Infinity]) .zoomScaleExtent([0.1, Infinity])
.renderDot(\`${dot}\`); .renderDot(dot);
d3.select(window).on("click", (event) => { d3.select(window).on("click", (event) => {
if (event.ctrlKey) { if (event.ctrlKey) {
graph.resetZoom(d3.transition().duration(100)); graph.resetZoom(d3.transition().duration(100));
} }
}); });
d3.select(window).on("copy", (event) => {
event.clipboardData.setData("text/plain", dot);
event.preventDefault();
});
</script> </script>
</body> </body>
`; `;