Enable text selection on SVG text elements by changing CSS user-select properties from 'none' to 'text' and cursor from 'default' to 'text'. Add JavaScript event handling to intercept mousedown events on text elements, preventing dragscroll interference while allowing normal text selection. This preserves the existing drag-to-pan functionality for non-text areas while making text elements selectable and copyable. Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/9547>
134 lines
4.9 KiB
HTML
134 lines
4.9 KiB
HTML
<!--
|
|
Copyright (c) 2015 Mountainstorm
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
in the Software without restriction, including without limitation the rights
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
The above copyright notice and this permission notice shall be included in all
|
|
copies or substantial portions of the Software.
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
SOFTWARE.
|
|
-->
|
|
|
|
<html>
|
|
<head>
|
|
<link rel="stylesheet" href="/dist/bundle.css">
|
|
<link rel="stylesheet" href="/css/graphviz.svg.css">
|
|
</head>
|
|
|
|
<style>
|
|
.floating-rectangle {
|
|
position: fixed;
|
|
top: 0;
|
|
left: 0;
|
|
color: #000000;
|
|
border: 1px solid #d0d0d0;
|
|
padding: 10px;
|
|
z-index: 1000;
|
|
font-size: 14px;
|
|
text-align: left;
|
|
}
|
|
|
|
</style>
|
|
<body>
|
|
<h1 style="text-align: center" id="title"> {{ TITLE }}</h1>
|
|
|
|
<div id="graph" class="dragscroll" style="width: 100%; height: 100%; overflow: scroll;"></div>
|
|
<div class="floating-rectangle" id="instructions">
|
|
Click node to highlight<br/>Shift-Ctrl-scroll or w/s to zoom<br/>Esc to unhighlight
|
|
</div>
|
|
|
|
<div class="floating-rectangle" id="actions" style="top: auto; bottom: 100px; left: 10px;">
|
|
<button id="save-svg" class="btn btn-primary btn-sm" style="margin-right: 5px;">Save SVG</button>
|
|
</div>
|
|
|
|
<script src='/dist/bundle.js'></script>
|
|
<script type="text/javascript" src="/js/jquery.graphviz.svg.js"></script>
|
|
<script type="text/javascript">
|
|
let url = new URL(window.location.href);
|
|
let searchParams = new URLSearchParams(url.search);
|
|
document.getElementById("title").innerHTML = searchParams.get("title");
|
|
|
|
// Make text selection work while preserving drag functionality
|
|
function setupTextSelectionWithDrag() {
|
|
const graphDiv = document.getElementById('graph');
|
|
|
|
graphDiv.addEventListener('mousedown', function(e) {
|
|
if (e.target.tagName === 'text' || e.target.tagName === 'tspan') {
|
|
e.stopPropagation();
|
|
// Allow normal text selection behavior
|
|
return true;
|
|
}
|
|
}, true);
|
|
|
|
graphDiv.addEventListener('mouseover', function(e) {
|
|
if (e.target.tagName === 'text' || e.target.tagName === 'tspan') {
|
|
e.target.style.cursor = 'text';
|
|
}
|
|
});
|
|
|
|
graphDiv.addEventListener('mouseout', function(e) {
|
|
if (e.target.tagName === 'text' || e.target.tagName === 'tspan') {
|
|
// Reset cursor when leaving text elements
|
|
e.target.style.cursor = '';
|
|
}
|
|
});
|
|
}
|
|
|
|
$(document).ready(function(){
|
|
// Setup text selection behavior
|
|
setupTextSelectionWithDrag();
|
|
|
|
$("#graph").graphviz({
|
|
url: searchParams.get("svg"),
|
|
ready: function() {
|
|
var gv = this;
|
|
gv.nodes().click(function () {
|
|
var $set = $();
|
|
$set.push(this);
|
|
$set = $set.add(gv.linkedFrom(this, true));
|
|
$set = $set.add(gv.linkedTo(this, true));
|
|
gv.highlight($set, true);
|
|
gv.bringToFront($set);
|
|
});
|
|
$(document).keydown(function (evt) {
|
|
if (evt.key == "Escape") {
|
|
gv.highlight();
|
|
} else if (evt.key == "w") {
|
|
gv.scaleInView((gv.zoom.percentage + 100));
|
|
} else if (evt.key == "s") {
|
|
gv.scaleInView((gv.zoom.percentage - 100) || 100);
|
|
}
|
|
});
|
|
|
|
$("#save-svg").click(function() {
|
|
const svgElement = $("#graph svg")[0];
|
|
const svgData = new XMLSerializer().serializeToString(svgElement);
|
|
const blob = new Blob([svgData], {type: "image/svg+xml;charset=utf-8"});
|
|
const url = URL.createObjectURL(blob);
|
|
const title = document.getElementById("title").textContent.trim();
|
|
const downloadLink = document.createElement("a");
|
|
downloadLink.href = url;
|
|
downloadLink.download = title + ".svg";
|
|
document.body.appendChild(downloadLink);
|
|
downloadLink.click();
|
|
document.body.removeChild(downloadLink);
|
|
URL.revokeObjectURL(url);
|
|
});
|
|
}
|
|
});
|
|
});
|
|
</script>
|
|
</body>
|
|
</html>
|