# packages/core/src/features/viz/lib/axis-title.tsx
This is the source snapshot used to build these API details. [View this revision on GitHub](https://github.com/benlesh/pibbl/blob/272a94aaf62e0bd6ad8726a4c607a76a9ec44ca1/packages/core/src/features/viz/lib/axis-title.tsx#L25).

[Back to reference](/reference/components/axis-title/)

<pre class="api-source"><code><span id="L1"><a href="#L1" aria-label="Line 1">1</a> import { Group, Text, resolveSignalValue, type SignalValue } from &quot;@pibbl/core&quot;;</span>
<span id="L2"><a href="#L2" aria-label="Line 2">2</a> import type { SignalStyle } from &quot;@pibbl/core/internal&quot;;</span>
<span id="L3"><a href="#L3" aria-label="Line 3">3</a> import type { AxisProps, AxisStyle, ScaleId } from &quot;./types.js&quot;;</span>
<span id="L4"><a href="#L4" aria-label="Line 4">4</a> import { lookupScale } from &quot;./scale-context.js&quot;;</span>
<span id="L5"><a href="#L5" aria-label="Line 5">5</a> import { opacity } from &quot;./paint.js&quot;;</span>
<span id="L6"><a href="#L6" aria-label="Line 6">6</a> /** Scale-aligned axis text; callers reserve the margin outside the plot. See {@link AxisTitle}. */</span>
<span id="L7"><a href="#L7" aria-label="Line 7">7</a> export interface AxisTitleProps {</span>
<span id="L8"><a href="#L8" aria-label="Line 8">8</a>   /** Ancestor scale whose range supplies the title midpoint. */</span>
<span id="L9"><a href="#L9" aria-label="Line 9">9</a>   readonly scale: ScaleId;</span>
<span id="L10"><a href="#L10" aria-label="Line 10">10</a>   /** Plot edge; left/right titles rotate along the axis. */</span>
<span id="L11"><a href="#L11" aria-label="Line 11">11</a>   readonly position: AxisProps[&quot;position&quot;];</span>
<span id="L12"><a href="#L12" aria-label="Line 12">12</a>   /** Single-line title. */</span>
<span id="L13"><a href="#L13" aria-label="Line 13">13</a>   readonly label: SignalValue&lt;string&gt;;</span>
<span id="L14"><a href="#L14" aria-label="Line 14">14</a>   /** Optional unit appended in parentheses; empty string omits it. */</span>
<span id="L15"><a href="#L15" aria-label="Line 15">15</a>   readonly unit?: SignalValue&lt;string&gt;;</span>
<span id="L16"><a href="#L16" aria-label="Line 16">16</a>   /** Nonnegative finite distance outside the plot edge, default 40 pixels. */</span>
<span id="L17"><a href="#L17" aria-label="Line 17">17</a>   readonly offset?: SignalValue&lt;number&gt;;</span>
<span id="L18"><a href="#L18" aria-label="Line 18">18</a>   /** Font defaults to 12px sans-serif, fill to #617783, opacity to 1. */</span>
<span id="L19"><a href="#L19" aria-label="Line 19">19</a>   readonly style?: SignalValue&lt;SignalStyle&lt;Pick&lt;AxisStyle, &quot;font&quot; | &quot;fill&quot; | &quot;opacity&quot;&gt;&gt;&gt;;</span>
<span id="L20"><a href="#L20" aria-label="Line 20">20</a> }</span>
<span id="L21"><a href="#L21" aria-label="Line 21">21</a> /** Paint an axis title with optional units, without allocating margins or changing ticks.</span>
<span id="L22"><a href="#L22" aria-label="Line 22">22</a>  * @param props - Scale geometry and presentation. See {@link AxisTitleProps}.</span>
<span id="L23"><a href="#L23" aria-label="Line 23">23</a>  * @returns Decorative chart content in the caller's coordinate space.</span>
<span id="L24"><a href="#L24" aria-label="Line 24">24</a>  */</span>
<span id="L25"><a href="#L25" aria-label="Line 25">25</a> export function AxisTitle(props: AxisTitleProps) {</span>
<span id="L26"><a href="#L26" aria-label="Line 26">26</a>   if (![&quot;top&quot;, &quot;bottom&quot;, &quot;left&quot;, &quot;right&quot;].includes(props.position)) throw new TypeError(&quot;AxisTitle position must be top, bottom, left, or right.&quot;);</span>
<span id="L27"><a href="#L27" aria-label="Line 27">27</a>   const source = lookupScale(props.scale, &quot;AxisTitle&quot;);</span>
<span id="L28"><a href="#L28" aria-label="Line 28">28</a>   if (!source) throw new TypeError(&quot;AxisTitle requires a scale ID.&quot;);</span>
<span id="L29"><a href="#L29" aria-label="Line 29">29</a>   const scale = source.get(), label = resolveSignalValue(props.label), unit = resolveSignalValue(props.unit) ?? &quot;&quot;;</span>
<span id="L30"><a href="#L30" aria-label="Line 30">30</a>   if ([label, unit].some(value =&gt; typeof value !== &quot;string&quot; || /[\r\n]/.test(value))) throw new TypeError(&quot;AxisTitle label and unit must be single-line strings.&quot;);</span>
<span id="L31"><a href="#L31" aria-label="Line 31">31</a>   const offset = resolveSignalValue(props.offset) ?? 40;</span>
<span id="L32"><a href="#L32" aria-label="Line 32">32</a>   if (typeof offset !== &quot;number&quot; || !Number.isFinite(offset) || offset &lt; 0) throw new RangeError(&quot;AxisTitle offset must be finite and nonnegative.&quot;);</span>
<span id="L33"><a href="#L33" aria-label="Line 33">33</a>   const horizontal = props.position === &quot;top&quot; || props.position === &quot;bottom&quot;;</span>
<span id="L34"><a href="#L34" aria-label="Line 34">34</a>   const midpoint = scale.range[0] / 2 + scale.range[1] / 2;</span>
<span id="L35"><a href="#L35" aria-label="Line 35">35</a>   const x = horizontal ? midpoint : props.position === &quot;left&quot; ? -offset : scale.frame.width + offset;</span>
<span id="L36"><a href="#L36" aria-label="Line 36">36</a>   const y = horizontal ? props.position === &quot;top&quot; ? -offset : scale.frame.height + offset : midpoint;</span>
<span id="L37"><a href="#L37" aria-label="Line 37">37</a>   const style = resolveSignalValue(props.style) ?? {};</span>
<span id="L38"><a href="#L38" aria-label="Line 38">38</a>   return &lt;Group style={{ translateX: x, translateY: y }}&gt;&lt;Group style={{ rotationDegrees: horizontal ? 0 : props.position === &quot;left&quot; ? -90 : 90 }}&gt;</span>
<span id="L39"><a href="#L39" aria-label="Line 39">39</a>     &lt;Text pointerEvents=&quot;none&quot; style={{ textAlign: &quot;center&quot;, textBaseline: &quot;middle&quot;, font: resolveSignalValue(style.font) ?? &quot;12px sans-serif&quot;, fill: resolveSignalValue(style.fill) ?? &quot;#617783&quot;, opacity: opacity(resolveSignalValue(style.opacity) ?? 1, &quot;AxisTitle&quot;) }}&gt;{unit ? `${label} (${unit})` : label}&lt;/Text&gt;</span>
<span id="L40"><a href="#L40" aria-label="Line 40">40</a>   &lt;/Group&gt;&lt;/Group&gt;;</span>
<span id="L41"><a href="#L41" aria-label="Line 41">41</a> }</span>
<span id="L42"><a href="#L42" aria-label="Line 42">42</a> </span></code></pre>

## Documentation version

Documentation built with @pibbl/core 0.0.2, revision 272a94a. ALPHA — NOT FOR PRODUCTION USE.
