-
-
Save mbostock/2565344 to your computer and use it in GitHub Desktop.
Text Along a Path
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <meta http-equiv="Content-Type" content="text/html;charset=utf-8"> | |
| <title>Path Test</title> | |
| <script type="text/javascript" src="https://github.com/mbostock/d3/raw/v1.4.0/d3.js"></script> | |
| </head> | |
| <body> | |
| <!-- | |
| <svg viewBox = "0 0 500 300" version = "1.1"> | |
| <defs> | |
| <path id = "s3" d = "M 10,90 Q 100,15 200,70 Q 340,140 400,30"/> | |
| </defs> | |
| <g fill = "navy"> | |
| <text font-size = "20"> | |
| <textPath xlink:href = "#s3"> | |
| Wavy text is the gimmick for many years to come | |
| </textPath> | |
| </text> | |
| <use x = "0" y = "0" xlink:href = "#s3" stroke = "black" fill = "none"/> | |
| </g> | |
| </svg> | |
| --> | |
| <script type="text/javascript"> | |
| var svg = d3.select("body") | |
| .append("svg:svg") | |
| .attr("viewBox", "0 0 500 300"); | |
| svg.append("defs") | |
| .append("path") | |
| .attr("id", "s3") | |
| .attr("d", "M 10,90 Q 100,15 200,70 Q 340,140 400,30"); | |
| svg.append("svg:g") | |
| .attr("id", "thing") | |
| .attr("fill", "navy") | |
| .append("text") | |
| .attr("font-size", "20") | |
| .append("textPath") | |
| .attr("xlink:href", "#s3") | |
| .text("Wavy text is the gimmick for many years to come"); | |
| d3.select("#thing").append("use") | |
| .attr("x", 0) | |
| .attr("y", 0) | |
| .attr("xlink:href", "#s3") | |
| .attr("stroke", "black") | |
| .attr("fill", "none"); | |
| </script> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment