INNER CODE UNIT · TypeScript

components

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

  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 componentVars = components.map((c, i) => {
    const varName = components.length > 1 ? `${c.type.charAt(0).toLowerCase()}${c.type.slice(1)}${i + 1}` : c.type.charAt(0).toLowerCase() + c.type.slice(1)
    const props = c.props.map(p => `  ${p.name}: ${p.expr},`).join('\n')
    return { varName, code: `const ${varName} = new ${c.type}<DataRecord>({\n${props}\n})` }
  })

  const containerProps: string[] = []
  if (spec.container === 'xy') {
    containerProps.push(`components: [${componentVars.map(c => c.varName).join(', ')}]`)
    if (xAxis) containerProps.push(`xAxis: new Axis<DataRecord>({ ${xAxis.filter(p => p.name !== 'type').map(p => `${p.name}: ${p.expr}`).join(', ')} })`)
    if (yAxis) containerProps.push(`yAxis: new Axis<DataRecord>({ ${yAxis.filter(p => p.name !== 'type').map(p => `${p.name}: ${p.expr}`).join(', ')} })`)
  } else {
    containerProps.push(`component: ${componentVars[0].varName}`)
  }

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…