INNER CODE UNIT · TypeScript

componentVars

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

  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}`)
  }
  containerProps.push(`height: ${spec.height}`)

  const imports = ['Axis', containerName(spec), ...components.map(c => c.type), ...emit.enumImports]
    .filter((name, i, all) => all.indexOf(name) === i && (name !== 'Axis' || xAxis || yAxis))

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…