Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add verovio option svgBoundingBoxes #897

Open
craigsapp opened this issue Aug 20, 2024 · 0 comments
Open

Add verovio option svgBoundingBoxes #897

craigsapp opened this issue Aug 20, 2024 · 0 comments
Assignees

Comments

@craigsapp
Copy link
Member

Add svgBoundingBoxes: "true" as a verovio option (or --svg-bounding-boxes on the command line). This make clicking on notes easier:

Screenshot 2024-08-19 at 6 59 54 PM

The blue box is the new clickable region (previously only the black pixels of the note were clickable.

For slurs, the bounding box element is before in the clicking hierarchy than the slur, but probably not a problem:

Screenshot 2024-08-19 at 7 07 51 PM

(using the example HTML code below, which will list the element ancestors of the SVG image that are <g> elements when clicking on the page.


This CSS allows the white holes in half and whole noteheads to be clickable in Chrome:

g[id^="note-"],
g[id^="rest-"],
g[id^="chord-"] {
    pointer-events: bounding-box;
}

Keeping this, but probably not necessary anymore.

Test example:

<html>
<head>
<title>My Score</title>
<script src="https://plugin.humdrum.org/scripts/humdrum-notation-plugin-worker.js"></script>
</head>
<body>
<script>
   displayHumdrum({
      source: "my-score",
      autoResize: "true",
      pageWidth: 1500,
      header: "true",
      svgBoundingBoxes: "true"
   });
</script>

<script type="text/x-humdrum" id="my-score">
!!!OTL: Twinkle, Twinkle, Little Star
!!!header-right: W.A. Mozart
**kern	**harm
*clefG2	*
*M4/4	*
=1	=1
4c	I
(4c	.
4g)	V
4g 4b	.
=2	=2
4a	vi
4a	.
2g	V
=3	=3
4f	IV
4f	.
4e	Ib
4e	.
=4	=4
4d	Vc
4d	.
2c	I
==	==
*-	*-
</script>

<div id="click-elements"></div>

<script>

document.addEventListener("click", function (event) {
	let target = event.target;
	let gelements = [];
	while (target) {
		if (target.nodeName === "svg") {
			break;
		}
		if (target.nodeName === "g") {
			gelements.push(target);
		}
		target = target.parentNode;
	}
	let infoElement = document.querySelector("#click-elements");
	if (gelements.length === 0) {
		infoElement.innerHTML = "";
		return;
	}
	let output = "<table>";
	output += "<tr><th>Element</th><th>ID</th><th>Class(es)</th></tr>";
	for (let i = 0; i < gelements.length; i++) {
		output += "<tr>";
		output += `<td>${gelements[i].nodeName}</td>`;
		output += `<td>${gelements[i].id}</td>`;
		output += `<td>${gelements[i].getAttribute('class')}</td>`;
		output += "</tr>";
	}
	output += "</table>";
	infoElement.innerHTML = output;
});

</script>

<style>
svg tspan { cursor: default; }
th, td { text-align: left; }

g[id^="rest-"],
g[id^="note-"],
g[id^="chord-"] {
    pointer-events: bounding-box;
}

g[id^="harm-"]:hover,
g[id^="note-"]:hover,
g[id^="rest-"]:hover,
g[id^="tie-"]:hover,
g[id^="fermata-"]:hover,
g[id^="slur-"]:hover {
	fill: orange;
}

</style>

</body>
</html>

Remove svgBoundingBoxes: "true" to compare.

@craigsapp craigsapp self-assigned this Aug 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant