Search icon
Subscription
0
Cart icon
Close icon
You have no products in your basket yet
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Learning D3.js Mapping

You're reading from  Learning D3.js Mapping

Product type Book
Published in Dec 2014
Publisher
ISBN-13 9781783985609
Pages 126 pages
Edition 1st Edition
Languages

Table of Contents (14) Chapters

Learning D3.js Mapping
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
1. Gather Your Cartographer's Toolbox 2. Creating Images from Simple Text 3. Producing Graphics from Data – the Foundations of D3 4. Creating a Map 5. Click-click Boom! Applying Interactivity to Your Map 6. Finding and Working with Geographic Data 7. Testing Index

Text


The text element, as its name describes, is used to display text in SVG. The basic HTML code to create a text node is as follows:

<text x="250" y="150">Hello world!</text>

It has an x and a y coordinate to tell it where to begin writing in the SVG coordinate system. Styling can be achieved with a CSS class in order to have a clear separation of concerns within our code base. For example, check out the following code:

<text x="250" y="150" class="myText">Hello world!</text>

.myText{
  font-size:22px;
  font-family:Helvetica;
  stroke-width:2;
}

Text also supports rotation in order to provide flexibility when positioning it on the visualization:

<svg width="600" height="600">
        <text x="250" y="150" class="myText" transform="rotate(45,200,0)" font-family="Verdana" font-size="100">Hello world!</text>
</svg>

Some examples are located at http://localhost:8080/chapter-2/text.html and displayed as shown in the following image:

Keep in mind that...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}