LegendSection.tsx 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. import React from 'react'
  2. import { Row, Col, Checkbox, Select } from 'antd'
  3. const Option = Select.Option
  4. import ColorPicker from 'components/ColorPicker'
  5. import {
  6. PIVOT_CHART_FONT_FAMILIES,
  7. PIVOT_CHART_LINE_STYLES,
  8. PIVOT_CHART_FONT_SIZES,
  9. CHART_LEGEND_POSITIONS,
  10. CHART_LEGEND_TYPE
  11. } from 'app/globalConstants'
  12. const styles = require('../Workbench.less')
  13. export interface ILegendConfig {
  14. showLegend: boolean
  15. legendPosition: string
  16. legendType?: string
  17. selectAll: boolean
  18. fontFamily: string
  19. fontSize: string
  20. color: string
  21. }
  22. interface ILegendSectionProps {
  23. title: string
  24. config: ILegendConfig
  25. onChange: (prop: string, value: any) => void
  26. }
  27. export class LegendSection extends React.PureComponent<
  28. ILegendSectionProps,
  29. {}
  30. > {
  31. private checkboxChange = (prop) => (e) => {
  32. this.props.onChange(prop, e.target.checked)
  33. }
  34. private selectChange = (prop) => (value) => {
  35. this.props.onChange(prop, value)
  36. }
  37. private colorChange = (prop) => (color) => {
  38. this.props.onChange(prop, color)
  39. }
  40. public render() {
  41. const { title, config } = this.props
  42. const {
  43. showLegend,
  44. legendPosition,
  45. legendType,
  46. selectAll,
  47. fontFamily,
  48. fontSize,
  49. color
  50. } = config
  51. const positions = CHART_LEGEND_POSITIONS.map((p) => (
  52. <Option key={p.value} value={p.value}>
  53. {p.name}
  54. </Option>
  55. ))
  56. const types = CHART_LEGEND_TYPE.map((p) => (
  57. <Option key={p.value} value={p.value}>
  58. {p.name}
  59. </Option>
  60. ))
  61. const fontFamilies = PIVOT_CHART_FONT_FAMILIES.map((f) => (
  62. <Option key={f.value} value={f.value}>
  63. {f.name}
  64. </Option>
  65. ))
  66. const fontSizes = PIVOT_CHART_FONT_SIZES.map((f) => (
  67. <Option key={f} value={`${f}`}>
  68. {f}
  69. </Option>
  70. ))
  71. return (
  72. <div className={styles.paneBlock}>
  73. <h4>{title}</h4>
  74. <div className={styles.blockBody}>
  75. <Row
  76. gutter={8}
  77. type="flex"
  78. align="middle"
  79. className={styles.blockRow}
  80. >
  81. <Col span={10}>
  82. <Checkbox
  83. checked={showLegend}
  84. onChange={this.checkboxChange('showLegend')}
  85. >
  86. 显示图例
  87. </Checkbox>
  88. </Col>
  89. <Col span={4}>类型</Col>
  90. <Col span={10}>
  91. <Select
  92. placeholder="类型"
  93. className={styles.blockElm}
  94. value={legendType}
  95. onChange={this.selectChange('legendType')}
  96. >
  97. {types}
  98. </Select>
  99. </Col>
  100. </Row>
  101. <Row
  102. gutter={8}
  103. type="flex"
  104. align="middle"
  105. className={styles.blockRow}
  106. >
  107. <Col span={10}>
  108. <Checkbox
  109. checked={selectAll}
  110. onChange={this.checkboxChange('selectAll')}
  111. >
  112. 是否全选
  113. </Checkbox>
  114. </Col>
  115. <Col span={4}>位置</Col>
  116. <Col span={10}>
  117. <Select
  118. placeholder="位置"
  119. className={styles.blockElm}
  120. value={legendPosition}
  121. onChange={this.selectChange('legendPosition')}
  122. >
  123. {positions}
  124. </Select>
  125. </Col>
  126. </Row>
  127. <Row
  128. gutter={8}
  129. type="flex"
  130. align="middle"
  131. className={styles.blockRow}
  132. >
  133. <Col span={10}>
  134. <Select
  135. placeholder="字体"
  136. className={styles.blockElm}
  137. value={fontFamily}
  138. onChange={this.selectChange('fontFamily')}
  139. >
  140. {fontFamilies}
  141. </Select>
  142. </Col>
  143. <Col span={10}>
  144. <Select
  145. placeholder="文字大小"
  146. className={styles.blockElm}
  147. value={fontSize}
  148. onChange={this.selectChange('fontSize')}
  149. >
  150. {fontSizes}
  151. </Select>
  152. </Col>
  153. <Col span={4}>
  154. <ColorPicker value={color} onChange={this.colorChange('color')} />
  155. </Col>
  156. </Row>
  157. </div>
  158. </div>
  159. )
  160. }
  161. }
  162. export default LegendSection