VisualMapSection.tsx 5.4 KB

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