Skip to content

Instantly share code, notes, and snippets.

@mbostock
Forked from dustin/index.html
Last active August 27, 2017 21:09
Show Gist options
  • Select an option

  • Save mbostock/2565344 to your computer and use it in GitHub Desktop.

Select an option

Save mbostock/2565344 to your computer and use it in GitHub Desktop.
Text Along a Path
<!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