@@ -17,28 +17,21 @@ import type {
1717 LegendLayout ,
1818 LineMark ,
1919 Mark ,
20- MeasureTextFn ,
2120 Point ,
2221 PointMark ,
2322 RectMark ,
2423 ResolvedAnimation ,
2524 ResolvedAnnotation ,
26- ResolvedChromeElement ,
2725 RuleMarkLayout ,
2826 TextMarkLayout ,
2927 TickMarkLayout ,
3028} from '@opendata-ai/openchart-core' ;
31- import { estimateTextWidth , wrapText } from '@opendata-ai/openchart-core' ;
29+ import { estimateTextWidth } from '@opendata-ai/openchart-core' ;
3230import { clampStaggerDelay } from '@opendata-ai/openchart-engine' ;
3331import { buildGradientDefs , resolveMarkFill } from './gradient-utils' ;
3432import { renderBrand } from './renderers/brand' ;
35- import {
36- applyTextStyle ,
37- computeXAxisExtent ,
38- createSVGElement ,
39- SVG_NS ,
40- setAttrs ,
41- } from './renderers/svg-dom' ;
33+ import { renderChrome } from './renderers/chrome' ;
34+ import { applyTextStyle , createSVGElement , SVG_NS , setAttrs } from './renderers/svg-dom' ;
4235import { nextSvgId } from './svg-ids' ;
4336
4437/**
@@ -75,95 +68,6 @@ const EASE_VAR_MAP: Record<string, string> = {
7568 snappy : 'var(--oc-ease-snappy)' ,
7669} ;
7770
78- // ---------------------------------------------------------------------------
79- // Chrome rendering
80- // ---------------------------------------------------------------------------
81-
82- function renderChromeElement (
83- parent : SVGElement ,
84- element : ResolvedChromeElement ,
85- className : string ,
86- chromeKey : string ,
87- measureText ?: MeasureTextFn ,
88- ) : void {
89- const text = createSVGElement ( 'text' ) ;
90- setAttrs ( text , { x : element . x , y : element . y } ) ;
91- applyTextStyle ( text , element . style ) ;
92- text . setAttribute ( 'class' , className ) ;
93- text . setAttribute ( 'data-chrome-key' , chromeKey ) ;
94-
95- const lines = wrapText (
96- element . text ,
97- element . style . fontSize ,
98- element . style . fontWeight ,
99- element . maxWidth ,
100- measureText ,
101- ) ;
102-
103- if ( lines . length === 1 ) {
104- text . textContent = element . text ;
105- } else {
106- const lineHeight = element . style . fontSize * ( element . style . lineHeight ?? 1.3 ) ;
107- for ( let i = 0 ; i < lines . length ; i ++ ) {
108- const tspan = createSVGElement ( 'tspan' ) ;
109- setAttrs ( tspan , { x : element . x , dy : i === 0 ? 0 : lineHeight } ) ;
110- tspan . textContent = lines [ i ] ;
111- text . appendChild ( tspan ) ;
112- }
113- }
114-
115- parent . appendChild ( text ) ;
116- }
117-
118- function renderChrome ( parent : SVGElement , layout : ChartLayout ) : void {
119- const g = createSVGElement ( 'g' ) ;
120- g . setAttribute ( 'class' , 'oc-chrome' ) ;
121-
122- const { chrome, measureText } = layout ;
123-
124- // Top chrome: render at their stored y positions (already absolute)
125- if ( chrome . title ) {
126- renderChromeElement ( g , chrome . title , 'oc-title' , 'title' , measureText ) ;
127- }
128- if ( chrome . subtitle ) {
129- renderChromeElement ( g , chrome . subtitle , 'oc-subtitle' , 'subtitle' , measureText ) ;
130- }
131-
132- // Bottom chrome starts below x-axis labels/title, not at chart area bottom.
133- // Accounts for rotated tick labels which need more vertical space.
134- const xAxisExtent = computeXAxisExtent ( layout ) ;
135- const bottomOffset = layout . area . y + layout . area . height + xAxisExtent ;
136- if ( chrome . source ) {
137- renderChromeElement (
138- g ,
139- { ...chrome . source , y : bottomOffset + chrome . source . y } ,
140- 'oc-source' ,
141- 'source' ,
142- measureText ,
143- ) ;
144- }
145- if ( chrome . byline ) {
146- renderChromeElement (
147- g ,
148- { ...chrome . byline , y : bottomOffset + chrome . byline . y } ,
149- 'oc-byline' ,
150- 'byline' ,
151- measureText ,
152- ) ;
153- }
154- if ( chrome . footer ) {
155- renderChromeElement (
156- g ,
157- { ...chrome . footer , y : bottomOffset + chrome . footer . y } ,
158- 'oc-footer' ,
159- 'footer' ,
160- measureText ,
161- ) ;
162- }
163-
164- parent . appendChild ( g ) ;
165- }
166-
16771// ---------------------------------------------------------------------------
16872// Axis rendering
16973// ---------------------------------------------------------------------------
0 commit comments