# packages/core/src/features/viz/lib/chart-lines.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/chart-lines.tsx#L58).

[Back to reference](/reference/components/chart-lines/)

<pre class="api-source"><code><span id="L1"><a href="#L1" aria-label="Line 1">1</a> import { Line, resolveSignalValue, type SignalValue } from &quot;@pibbl/core&quot;;</span>
<span id="L2"><a href="#L2" aria-label="Line 2">2</a> import type { AxisProps, AxisStyle, BandCategory, ScaleId } from &quot;./types.js&quot;;</span>
<span id="L3"><a href="#L3" aria-label="Line 3">3</a> import type { SignalStyle } from &quot;@pibbl/core/internal&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 { ticks, position } from &quot;./scale-ticks.js&quot;;</span>
<span id="L6"><a href="#L6" aria-label="Line 6">6</a> import { width, opacity } from &quot;./paint.js&quot;;</span>
<span id="L7"><a href="#L7" aria-label="Line 7">7</a> /** Shared geometry and paint for decorative chart lines; no layout is allocated. See {@link GridLines}. */</span>
<span id="L8"><a href="#L8" aria-label="Line 8">8</a> export interface ChartLineProps {</span>
<span id="L9"><a href="#L9" aria-label="Line 9">9</a>   /** Ancestor scale providing the line's mapped coordinate. */</span>
<span id="L10"><a href="#L10" aria-label="Line 10">10</a>   readonly scale: ScaleId;</span>
<span id="L11"><a href="#L11" aria-label="Line 11">11</a>   /** Direction the painted line extends. */</span>
<span id="L12"><a href="#L12" aria-label="Line 12">12</a>   readonly direction: &quot;horizontal&quot; | &quot;vertical&quot;;</span>
<span id="L13"><a href="#L13" aria-label="Line 13">13</a>   /** Explicit perpendicular pixel endpoints, in the caller's local coordinate space. */</span>
<span id="L14"><a href="#L14" aria-label="Line 14">14</a>   readonly span: SignalValue&lt;readonly [number, number]&gt;;</span>
<span id="L15"><a href="#L15" aria-label="Line 15">15</a>   /** Stroke defaults to #dce5e8, width to 1, opacity to 1. */</span>
<span id="L16"><a href="#L16" aria-label="Line 16">16</a>   readonly style?: SignalValue&lt;SignalStyle&lt;Pick&lt;AxisStyle, &quot;stroke&quot; | &quot;strokeWidth&quot; | &quot;opacity&quot;&gt;&gt;&gt;;</span>
<span id="L17"><a href="#L17" aria-label="Line 17">17</a> }</span>
<span id="L18"><a href="#L18" aria-label="Line 18">18</a> /** Grid positions use Axis tick rules, independent of Axis label visibility. See {@link GridLines}. */</span>
<span id="L19"><a href="#L19" aria-label="Line 19">19</a> export type GridLinesProps = ChartLineProps &amp; (</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>     /** Explicit domain ticks; same validation as Axis. */</span>
<span id="L22"><a href="#L22" aria-label="Line 22">22</a>     readonly tickValues: AxisProps[&quot;tickValues&quot;];</span>
<span id="L23"><a href="#L23" aria-label="Line 23">23</a>     /** Mutually exclusive with explicit values. */</span>
<span id="L24"><a href="#L24" aria-label="Line 24">24</a>     readonly tickCount?: never;</span>
<span id="L25"><a href="#L25" aria-label="Line 25">25</a>   } |</span>
<span id="L26"><a href="#L26" aria-label="Line 26">26</a>   {</span>
<span id="L27"><a href="#L27" aria-label="Line 27">27</a>     /** Mutually exclusive with generated ticks. */</span>
<span id="L28"><a href="#L28" aria-label="Line 28">28</a>     readonly tickValues?: never;</span>
<span id="L29"><a href="#L29" aria-label="Line 29">29</a>     /** Requested tick count; defaults to five. */</span>
<span id="L30"><a href="#L30" aria-label="Line 30">30</a>     readonly tickCount?: AxisProps[&quot;tickCount&quot;];</span>
<span id="L31"><a href="#L31" aria-label="Line 31">31</a>   }</span>
<span id="L32"><a href="#L32" aria-label="Line 32">32</a> );</span>
<span id="L33"><a href="#L33" aria-label="Line 33">33</a> /** A reference value must belong to the selected scale's domain. See {@link ReferenceLine}. */</span>
<span id="L34"><a href="#L34" aria-label="Line 34">34</a> export interface ReferenceLineProps extends ChartLineProps {</span>
<span id="L35"><a href="#L35" aria-label="Line 35">35</a>   /** Numeric domain value or categorical identity; signals update the line. */</span>
<span id="L36"><a href="#L36" aria-label="Line 36">36</a>   readonly value: SignalValue&lt;BandCategory&gt;;</span>
<span id="L37"><a href="#L37" aria-label="Line 37">37</a> }</span>
<span id="L38"><a href="#L38" aria-label="Line 38">38</a> function lines(props: ChartLineProps, selection: Pick&lt;AxisProps, &quot;tickCount&quot; | &quot;tickValues&quot;&gt;) {</span>
<span id="L39"><a href="#L39" aria-label="Line 39">39</a>   if (props.direction !== &quot;horizontal&quot; &amp;&amp; props.direction !== &quot;vertical&quot;) throw new TypeError(&quot;Chart line direction must be horizontal or vertical.&quot;);</span>
<span id="L40"><a href="#L40" aria-label="Line 40">40</a>   const source = lookupScale(props.scale, &quot;Chart line&quot;);</span>
<span id="L41"><a href="#L41" aria-label="Line 41">41</a>   if (!source) throw new TypeError(&quot;Chart lines require a scale ID.&quot;);</span>
<span id="L42"><a href="#L42" aria-label="Line 42">42</a>   const scale = source.get(), span = resolveSignalValue(props.span);</span>
<span id="L43"><a href="#L43" aria-label="Line 43">43</a>   if (!Array.isArray(span) || span.length !== 2 || !span.every(v =&gt; typeof v === &quot;number&quot; &amp;&amp; Number.isFinite(v))) throw new RangeError(&quot;Chart line span must have two finite pixel endpoints.&quot;);</span>
<span id="L44"><a href="#L44" aria-label="Line 44">44</a>   const style = resolveSignalValue(props.style) ?? {};</span>
<span id="L45"><a href="#L45" aria-label="Line 45">45</a>   const stroke = resolveSignalValue(style.stroke) ?? &quot;#dce5e8&quot;;</span>
<span id="L46"><a href="#L46" aria-label="Line 46">46</a>   const strokeWidth = width(resolveSignalValue(style.strokeWidth) ?? 1, &quot;Chart line&quot;);</span>
<span id="L47"><a href="#L47" aria-label="Line 47">47</a>   const alpha = opacity(resolveSignalValue(style.opacity) ?? 1, &quot;Chart line&quot;);</span>
<span id="L48"><a href="#L48" aria-label="Line 48">48</a>   return ticks(scale, selection).map((value, index) =&gt; {</span>
<span id="L49"><a href="#L49" aria-label="Line 49">49</a>     const p = position(scale, value);</span>
<span id="L50"><a href="#L50" aria-label="Line 50">50</a>     const coords: [number, number][] = props.direction === &quot;horizontal&quot; ? [[span[0], p], [span[1], p]] : [[p, span[0]], [p, span[1]]];</span>
<span id="L51"><a href="#L51" aria-label="Line 51">51</a>     return &lt;Line key={index} pointerEvents=&quot;none&quot; style={{ coords, stroke, strokeWidth, opacity: alpha }} /&gt;;</span>
<span id="L52"><a href="#L52" aria-label="Line 52">52</a>   });</span>
<span id="L53"><a href="#L53" aria-label="Line 53">53</a> }</span>
<span id="L54"><a href="#L54" aria-label="Line 54">54</a> /** Paint grid lines at scale ticks, without labels or allocation.</span>
<span id="L55"><a href="#L55" aria-label="Line 55">55</a>  * @param props - Scale geometry and presentation. See {@link GridLinesProps}.</span>
<span id="L56"><a href="#L56" aria-label="Line 56">56</a>  * @returns Decorative chart content in the caller's coordinate space.</span>
<span id="L57"><a href="#L57" aria-label="Line 57">57</a>  */</span>
<span id="L58"><a href="#L58" aria-label="Line 58">58</a> export function GridLines(props: GridLinesProps) { return lines(props, props); }</span>
<span id="L59"><a href="#L59" aria-label="Line 59">59</a> /** Paint one decorative line at a domain value, without labels or allocation.</span>
<span id="L60"><a href="#L60" aria-label="Line 60">60</a>  * @param props - Scale geometry and presentation. See {@link ReferenceLineProps}.</span>
<span id="L61"><a href="#L61" aria-label="Line 61">61</a>  * @returns Decorative chart content in the caller's coordinate space.</span>
<span id="L62"><a href="#L62" aria-label="Line 62">62</a>  */</span>
<span id="L63"><a href="#L63" aria-label="Line 63">63</a> export function ReferenceLine(props: ReferenceLineProps) { return lines(props, { tickValues: [resolveSignalValue(props.value)] }); }</span>
<span id="L64"><a href="#L64" aria-label="Line 64">64</a> </span></code></pre>

## Documentation version

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