DoubleYAxisSection.tsx 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. import React from 'react'
  2. import Row from 'antd/lib/row'
  3. import Col from 'antd/lib/col'
  4. import Checkbox from 'antd/lib/checkbox'
  5. import Select from 'antd/lib/select'
  6. const Option = Select.Option
  7. import InputNumber from 'antd/lib/input-number'
  8. import ColorPicker from 'components/ColorPicker'
  9. import { PIVOT_CHART_YAXIS_OPTIONS, PIVOT_CHART_LINE_STYLES, PIVOT_CHART_FONT_FAMILIES, PIVOT_CHART_FONT_SIZES } from 'app/globalConstants'
  10. const styles = require('../Workbench.less')
  11. export interface IDoubleYAxisConfig {
  12. yAxisLeft: string
  13. yAxisRight: string
  14. yAxisSplitNumber: number
  15. dataZoomThreshold: number
  16. inverse: boolean
  17. showLine: boolean
  18. lineStyle: 'solid' | 'dashed' | 'dotted'
  19. lineSize: string
  20. lineColor: string
  21. showLabel: boolean
  22. labelFontFamily: string
  23. labelFontSize: string
  24. labelColor: string
  25. }
  26. interface IDoubleYAxisSectionProps {
  27. title: string
  28. config: IDoubleYAxisConfig
  29. onChange: (prop: string, value: any) => void
  30. }
  31. export class DoubleYAxisSection extends React.PureComponent<IDoubleYAxisSectionProps, {}> {
  32. private selectChange = (prop) => (value) => {
  33. this.props.onChange(prop, value)
  34. }
  35. private inputNumberChange = (prop) => (value) => {
  36. this.props.onChange(prop, value)
  37. }
  38. private checkboxChange = (prop) => (e) => {
  39. this.props.onChange(prop, e.target.checked)
  40. }
  41. private colorChange = (prop) => (color) => {
  42. this.props.onChange(prop, color)
  43. }
  44. public render () {
  45. const { title, config } = this.props
  46. const {
  47. yAxisLeft,
  48. yAxisRight,
  49. yAxisSplitNumber,
  50. dataZoomThreshold,
  51. showLine,
  52. inverse,
  53. lineStyle,
  54. lineSize,
  55. lineColor,
  56. showLabel,
  57. labelFontFamily,
  58. labelFontSize,
  59. labelColor
  60. } = config
  61. const yAixsOptions = PIVOT_CHART_YAXIS_OPTIONS.map((f) => (
  62. <Option key={f.value} value={f.value}>{f.name}</Option>
  63. ))
  64. const lineStyles = PIVOT_CHART_LINE_STYLES.map((l) => (
  65. <Option key={l.value} value={l.value}>{l.name}</Option>
  66. ))
  67. const fontFamilies = PIVOT_CHART_FONT_FAMILIES.map((f) => (
  68. <Option key={f.value} value={f.value}>{f.name}</Option>
  69. ))
  70. const fontSizes = PIVOT_CHART_FONT_SIZES.map((f) => (
  71. <Option key={`${f}`} value={`${f}`}>{f}</Option>
  72. ))
  73. return (
  74. <div className={styles.paneBlock}>
  75. <h4>{title}</h4>
  76. <div className={styles.blockBody}>
  77. <Row gutter={8} type="flex" align="middle" className={styles.blockRow}>
  78. <Col span={10}>左Y轴</Col>
  79. <Col span={10}>右Y轴</Col>
  80. </Row>
  81. <Row gutter={8} type="flex" align="middle" className={styles.blockRow}>
  82. <Col span={10}>
  83. <Select
  84. placeholder="左Y轴"
  85. className={styles.blockElm}
  86. value={yAxisLeft}
  87. onChange={this.selectChange('yAxisLeft')}
  88. >
  89. {yAixsOptions}
  90. </Select>
  91. </Col>
  92. <Col span={10}>
  93. <Select
  94. placeholder="右Y轴"
  95. className={styles.blockElm}
  96. value={yAxisRight}
  97. onChange={this.selectChange('yAxisRight')}
  98. >
  99. {yAixsOptions}
  100. </Select>
  101. </Col>
  102. </Row>
  103. {/* <Row gutter={8} type="flex" align="middle" className={styles.blockRow}>
  104. <Col span={10}>y轴刻度条数</Col>
  105. <Col span={10}>超出后缩放</Col>
  106. </Row>
  107. <Row gutter={8} type="flex" align="middle" className={styles.blockRow}>
  108. <Col span={10}>
  109. <InputNumber
  110. placeholder="yAxisSplitNumber"
  111. className={styles.blockElm}
  112. value={yAxisSplitNumber}
  113. min={3}
  114. onChange={this.inputNumberChange('yAxisSplitNumber')}
  115. />
  116. </Col>
  117. <Col span={10}>
  118. <InputNumber
  119. placeholder="dataZoomThreshold"
  120. className={styles.blockElm}
  121. value={dataZoomThreshold}
  122. min={0}
  123. onChange={this.inputNumberChange('dataZoomThreshold')}
  124. />
  125. </Col>
  126. </Row> */}
  127. <Row gutter={8} type="flex" align="middle" className={styles.blockRow}>
  128. <Col span={12}>
  129. <Checkbox
  130. checked={showLine}
  131. onChange={this.checkboxChange('showLine')}
  132. >
  133. 显示坐标轴
  134. </Checkbox>
  135. </Col>
  136. <Col span={12}>
  137. <Checkbox
  138. checked={inverse}
  139. onChange={this.checkboxChange('inverse')}
  140. >
  141. 坐标轴反转
  142. </Checkbox>
  143. </Col>
  144. </Row>
  145. <Row gutter={8} type="flex" align="middle" className={styles.blockRow}>
  146. <Col span={10}>
  147. <Select
  148. placeholder="样式"
  149. className={styles.blockElm}
  150. value={lineStyle}
  151. onChange={this.selectChange('lineStyle')}
  152. >
  153. {lineStyles}
  154. </Select>
  155. </Col>
  156. <Col span={10}>
  157. <Select
  158. placeholder="粗细"
  159. className={styles.blockElm}
  160. value={lineSize}
  161. onChange={this.selectChange('lineSize')}
  162. >
  163. {Array.from(Array(10), (o, i) => (
  164. <Option key={`${i}`} value={`${i + 1}`}>{i + 1}</Option>
  165. ))}
  166. </Select>
  167. </Col>
  168. <Col span={4}>
  169. <ColorPicker
  170. value={lineColor}
  171. onChange={this.colorChange('lineColor')}
  172. />
  173. </Col>
  174. </Row>
  175. <Row gutter={8} type="flex" align="middle" className={styles.blockRow}>
  176. <Col span={24}>
  177. <Checkbox
  178. checked={showLabel}
  179. onChange={this.checkboxChange('showLabel')}
  180. >
  181. 显示标签文字
  182. </Checkbox>
  183. </Col>
  184. </Row>
  185. <Row gutter={8} type="flex" align="middle" className={styles.blockRow}>
  186. <Col span={10}>
  187. <Select
  188. placeholder="字体"
  189. className={styles.blockElm}
  190. value={labelFontFamily}
  191. onChange={this.selectChange('labelFontFamily')}
  192. >
  193. {fontFamilies}
  194. </Select>
  195. </Col>
  196. <Col span={10}>
  197. <Select
  198. placeholder="文字大小"
  199. className={styles.blockElm}
  200. value={labelFontSize}
  201. onChange={this.selectChange('labelFontSize')}
  202. >
  203. {fontSizes}
  204. </Select>
  205. </Col>
  206. <Col span={4}>
  207. <ColorPicker
  208. value={labelColor}
  209. onChange={this.colorChange('labelColor')}
  210. />
  211. </Col>
  212. </Row>
  213. </div>
  214. </div>
  215. )
  216. }
  217. }
  218. export default DoubleYAxisSection