INNER CODE UNIT · TypeScript

emitJsx

f5/unovis · packages/mcp/src/codegen/index.ts:252

function emitJsx (spec: ChartSpec, emit: Emit, framework: 'react' | 'solid'): GeneratedFile {
  const components = spec.components.map(c => ({ type: c.type, props: componentProps(c, emit) }))
  const xAxis = axisProps(spec, 'x', emit)
  const yAxis = axisProps(spec, 'y', emit)

  const tag = (name: string): string => `Vis${name}`
  const renderProps = (props: Prop[]): string =>
    props.map(p => p.expr.startsWith("'") ? ` ${p.name}=${p.expr.replace(/'/g, '"')}` : ` ${p.name}={${p.expr}}`).join('')

  const children = [
    ...components.map(c => `<${tag(c.type)} data={data}${renderProps(c.props)} />`),
    ...(xAxis ? [`<${tag('Axis')}${renderProps(xAxis)} />`] : []),
    ...(yAxis ? [`<${tag('Axis')}${renderProps(yAxis)} />`] : []),
  ]

  const used = [`Vis${containerName(spec)}`, ...components.map(c => tag(c.type)), ...(xAxis || yAxis ? ['VisAxis'] : [])]
  const legendTag = spec.legend?.length ? `<VisBulletLegend items={${json(spec.legend.map(i => ({ name: i.name })), 0)}} />\n      ` : ''
  if (spec.legend?.length) used.push('VisBulletLegend')

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…