SpecSection.tsx 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import React from 'react'
  2. import { ISpecConfig } from './types'
  3. import {
  4. LineSection,
  5. PieSection,
  6. FunnelSection,
  7. MapSection,
  8. ParallelSection,
  9. SankeySection,
  10. DoubleYAxisSection
  11. } from './specs'
  12. interface ISpecSectionProps {
  13. name: string
  14. title: string
  15. config: ISpecConfig
  16. onChange: (value: string | number, propPath: string[]) => void
  17. isLegendSection: boolean
  18. }
  19. export class SpecSection extends React.PureComponent<ISpecSectionProps, {}> {
  20. private static readonly BasePropPath = ['spec']
  21. private specChange = (
  22. value: string | number,
  23. propPath: string | string[]
  24. ) => {
  25. this.props.onChange(value, SpecSection.BasePropPath.concat(propPath))
  26. }
  27. public render () {
  28. const { name, title, config, isLegendSection } = this.props
  29. let renderHtml: JSX.Element
  30. switch (name) {
  31. case 'line':
  32. renderHtml = <LineSection spec={config} title={title} onChange={this.specChange} />
  33. break
  34. case 'pie':
  35. renderHtml = <PieSection spec={config} title={title} onChange={this.specChange} />
  36. break
  37. case 'funnel':
  38. renderHtml = <FunnelSection spec={config} title={title} onChange={this.specChange} />
  39. break
  40. case 'map':
  41. renderHtml = <MapSection spec={config} title={title} isLegendSection={isLegendSection} onChange={this.specChange} />
  42. break
  43. case 'parallel':
  44. renderHtml = <ParallelSection spec={config} title={title} onChange={this.specChange}/>
  45. break
  46. case 'sankey':
  47. renderHtml = <SankeySection spec={config} title={title} onChange={this.specChange}/>
  48. break
  49. case 'doubleYAxis':
  50. renderHtml = <DoubleYAxisSection spec={config} title={title} onChange={this.specChange}/>
  51. break
  52. default:
  53. renderHtml = <div />
  54. break
  55. }
  56. return renderHtml
  57. }
  58. }
  59. export default SpecSection