Frontory

Open code, practice, and notes →

Download source with English comments · for reading

SVG · 12 Text and Data Labels

Series contents · Technology map

Stage: Styles, Effects, and DOM Input · Editable example · Storage ID: svg-step-12

Goals and learning outcomes

Prerequisites

Prerequisite concepts: Filter graph, Filter boundaries. Prepare the result files and observation records from Unit 11.

Key concepts and explanations

Text placement

text-anchor sets alignment relative to the x coordinate. It lets you align labels with data points even when string widths differ.

Alternative information

Text in a graphic may not explain all of a complex dataset. Adding a table or description lets people explore the information in another way.

Practice setup

First check the execution scope guidance on the example screen. The following describes preparation for extending the assignment in a separate project. Implement this yourself in an HTML and ES module project on a separate local HTTP development server. Record the browser version, viewport, and DPR.

The linked example is a starting point. It does not implement every task below. Complete work beyond its supported scope in a separate project.

Practice tasks

  1. Prepare day-12.js and index.html in an external practice project. Display node names and values using text and tspan.
  2. Enter long names, adjust overlapping label positions, and output the same data as an HTML table.
  3. Save the output under the input condition Short name, then run again with Long Korean name. Compare the hypothesis, "Fixed spacing causes overlap and requires a layout policy," against the display and logs, and record the actual result and the causes of any differences in day-12-notes.md.

Variables to observe

VariableBaselineChangeExpected change / hypothesis
Label lengthShort nameLong Korean nameFixed spacing causes overlap and requires a layout policy

Predictions in this table are not measured results. Change one condition at a time and record why the actual result differs.

Completion criteria

Self-check

  1. Are text-anchor and CSS text-align the same?
  2. How can you resolve overlap besides reducing the font size?

Official references

Linked example and execution scope

Example source · Runtime environments and limits

An editable browser experiment. Measurements vary with the current device and browser.

Source code and records are not overwritten automatically. Resetting an existing example also preserves your notes.

Next learning

Previous: Filter Regions and Cost · Next: Screen Coordinates to SVG

Open code, practice, and notes →