AxisSection.tsx 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  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 } from 'app/globalConstants'
  6. import { getCorrectInputNumber } from '../../util'
  7. const styles = require('../Workbench.less')
  8. export interface IAxisConfig {
  9. inverse: boolean
  10. showLine: boolean
  11. lineStyle: 'solid' | 'dashed' | 'dotted'
  12. lineSize: string
  13. lineColor: string
  14. showLabel: boolean
  15. labelFontFamily: string
  16. labelFontSize: string
  17. labelColor: string
  18. labelStyle: 'normal' | 'italic' | 'oblique'
  19. labelWeight: 'normal' | 'bold' | 'bolder' | 'lighter'
  20. showTitleAndUnit?: boolean
  21. nameLocation: 'start' | 'middle' | 'center' | 'end'
  22. nameRotate?: number
  23. nameGap?: number
  24. titleFontFamily?: string
  25. titleFontStyle?: string
  26. titleFontSize?: string
  27. titleColor?: string
  28. showInterval?: boolean
  29. xAxisInterval?: number
  30. xAxisRotate?: number
  31. min?: number
  32. max?: number
  33. }
  34. interface IAxisSectionProps {
  35. title: string
  36. config: IAxisConfig
  37. onChange: (prop: string, value: any) => void
  38. }
  39. export class AxisSection extends React.PureComponent<IAxisSectionProps, {}> {
  40. private checkboxChange = (prop) => (e) => {
  41. this.props.onChange(prop, e.target.checked)
  42. }
  43. private selectChange = (prop) => (value) => {
  44. this.props.onChange(prop, value)
  45. }
  46. private inputNumberChange = (prop) => (value) => {
  47. this.props.onChange(prop, getCorrectInputNumber(value))
  48. }
  49. private colorChange = (prop) => (color) => {
  50. this.props.onChange(prop, color)
  51. }
  52. public render () {
  53. const { title, config } = this.props
  54. const {
  55. showLine,
  56. inverse,
  57. lineStyle,
  58. lineSize,
  59. lineColor,
  60. showLabel,
  61. labelFontFamily,
  62. labelFontSize,
  63. labelColor,
  64. labelStyle,
  65. labelWeight,
  66. showTitleAndUnit,
  67. nameLocation,
  68. nameRotate,
  69. nameGap,
  70. titleFontFamily,
  71. titleFontStyle,
  72. titleFontSize,
  73. titleColor,
  74. showInterval,
  75. xAxisInterval,
  76. xAxisRotate,
  77. min,
  78. max
  79. } = config
  80. const lineStyles = PIVOT_CHART_LINE_STYLES.map((l) => (
  81. <Option key={l.value} value={l.value}>{l.name}</Option>
  82. ))
  83. const fontFamilies = PIVOT_CHART_FONT_FAMILIES.map((f) => (
  84. <Option key={f.value} value={f.value}>{f.name}</Option>
  85. ))
  86. const fontSizes = PIVOT_CHART_FONT_SIZES.map((f) => (
  87. <Option key={`${f}`} value={`${f}`}>{f}</Option>
  88. ))
  89. const xAxisLabel = showTitleAndUnit === void 0 && [(
  90. <Row key="gap1" gutter={8} type="flex" align="middle" className={styles.blockRow}>
  91. <Col span={2} />
  92. <Col span={8}>旋转角度</Col>
  93. <Col span={10}>
  94. <InputNumber
  95. placeholder="x轴旋转角度"
  96. className={styles.blockElm}
  97. value={xAxisRotate}
  98. onChange={this.inputNumberChange('xAxisRotate')}
  99. />
  100. </Col>
  101. </Row>
  102. ), (
  103. <Row key="gap" gutter={8} type="flex" align="middle" className={styles.blockRow}>
  104. <Col span={2}>
  105. <Checkbox
  106. checked={showInterval}
  107. onChange={this.checkboxChange('showInterval')}
  108. />
  109. </Col>
  110. <Col span={8}>刻度间隔</Col>
  111. <Col span={10}>
  112. <InputNumber
  113. placeholder="刻度间隔"
  114. className={styles.blockElm}
  115. value={xAxisInterval}
  116. onChange={this.inputNumberChange('xAxisInterval')}
  117. disabled={!showInterval}
  118. />
  119. </Col>
  120. </Row>
  121. )]
  122. const titleAndUnit = showTitleAndUnit !== void 0 && [(
  123. <Row key="title" gutter={8} type="flex" align="middle" className={styles.blockRow}>
  124. <Col span={24}>
  125. <Checkbox
  126. checked={showTitleAndUnit}
  127. onChange={this.checkboxChange('showTitleAndUnit')}
  128. >
  129. 显示标题和单位
  130. </Checkbox>
  131. </Col>
  132. </Row>
  133. ), (
  134. <Row key="body" gutter={8} type="flex" align="middle" className={styles.blockRow}>
  135. <Col span={10}>
  136. <Select
  137. placeholder="字体"
  138. className={styles.blockElm}
  139. value={titleFontFamily}
  140. onChange={this.selectChange('titleFontFamily')}
  141. >
  142. {fontFamilies}
  143. </Select>
  144. </Col>
  145. <Col span={10}>
  146. <Select
  147. placeholder="文字大小"
  148. className={styles.blockElm}
  149. value={titleFontSize}
  150. onChange={this.selectChange('titleFontSize')}
  151. >
  152. {fontSizes}
  153. </Select>
  154. </Col>
  155. <Col span={4}>
  156. <ColorPicker
  157. value={titleColor}
  158. onChange={this.colorChange('titleColor')}
  159. />
  160. </Col>
  161. </Row>
  162. ), (
  163. <Row key="location" gutter={8} type="flex" align="middle" className={styles.blockRow}>
  164. <Col span={12}>标题位置</Col>
  165. <Col span={10}>
  166. <Select
  167. placeholder="位置"
  168. className={styles.blockElm}
  169. value={nameLocation}
  170. onChange={this.selectChange('nameLocation')}
  171. >
  172. <Option key="start" value="start">开始</Option>
  173. <Option key="center" value="middle">中间</Option>
  174. <Option key="end" value="end">结束</Option>
  175. </Select>
  176. </Col>
  177. </Row>
  178. ), (
  179. <Row key="rotate" gutter={8} type="flex" align="middle" className={styles.blockRow}>
  180. <Col span={12}>标题旋转</Col>
  181. <Col span={10}>
  182. <InputNumber
  183. placeholder="标题旋转"
  184. className={styles.blockElm}
  185. value={nameRotate}
  186. onChange={this.inputNumberChange('nameRotate')}
  187. />
  188. </Col>
  189. </Row>
  190. ), (
  191. <Row key="gap" gutter={8} type="flex" align="middle" className={styles.blockRow}>
  192. <Col span={12}>标题与轴线距离</Col>
  193. <Col span={10}>
  194. <InputNumber
  195. placeholder="标题与轴线距离"
  196. className={styles.blockElm}
  197. value={nameGap}
  198. onChange={this.inputNumberChange('nameGap')}
  199. />
  200. </Col>
  201. </Row>
  202. ), (
  203. <Row key="min" gutter={8} type="flex" align="middle" className={styles.blockRow}>
  204. <Col span={12}>最小值</Col>
  205. <Col span={10}>
  206. <InputNumber
  207. className={styles.blockElm}
  208. value={min}
  209. onChange={this.inputNumberChange('min')}
  210. />
  211. </Col>
  212. </Row>
  213. ), (
  214. <Row key="max" gutter={8} type="flex" align="middle" className={styles.blockRow}>
  215. <Col span={12}>最大值</Col>
  216. <Col span={10}>
  217. <InputNumber
  218. className={styles.blockElm}
  219. value={max}
  220. onChange={this.inputNumberChange('max')}
  221. />
  222. </Col>
  223. </Row>
  224. )]
  225. return (
  226. <div className={styles.paneBlock}>
  227. <h4>{title}</h4>
  228. <div className={styles.blockBody}>
  229. <Row gutter={8} type="flex" align="middle" className={styles.blockRow}>
  230. <Col span={12}>
  231. <Checkbox
  232. checked={showLine}
  233. onChange={this.checkboxChange('showLine')}
  234. >
  235. 显示坐标轴
  236. </Checkbox>
  237. </Col>
  238. <Col span={12}>
  239. <Checkbox
  240. checked={inverse}
  241. onChange={this.checkboxChange('inverse')}
  242. >
  243. 坐标轴反转
  244. </Checkbox>
  245. </Col>
  246. </Row>
  247. <Row gutter={8} type="flex" align="middle" className={styles.blockRow}>
  248. <Col span={10}>
  249. <Select
  250. placeholder="样式"
  251. className={styles.blockElm}
  252. value={lineStyle}
  253. onChange={this.selectChange('lineStyle')}
  254. >
  255. {lineStyles}
  256. </Select>
  257. </Col>
  258. <Col span={10}>
  259. <Select
  260. placeholder="粗细"
  261. className={styles.blockElm}
  262. value={lineSize}
  263. onChange={this.selectChange('lineSize')}
  264. >
  265. {Array.from(Array(10), (o, i) => (
  266. <Option key={i} value={`${i + 1}`}>{i + 1}</Option>
  267. ))}
  268. </Select>
  269. </Col>
  270. <Col span={4}>
  271. <ColorPicker
  272. value={lineColor}
  273. onChange={this.colorChange('lineColor')}
  274. />
  275. </Col>
  276. </Row>
  277. <Row gutter={8} type="flex" align="middle" className={styles.blockRow}>
  278. <Col span={24}>
  279. <Checkbox
  280. checked={showLabel}
  281. onChange={this.checkboxChange('showLabel')}
  282. >
  283. 显示标签文字
  284. </Checkbox>
  285. </Col>
  286. </Row>
  287. <Row gutter={8} type="flex" align="middle" className={styles.blockRow}>
  288. <Col span={10}>
  289. <Select
  290. placeholder="字体"
  291. className={styles.blockElm}
  292. value={labelFontFamily}
  293. onChange={this.selectChange('labelFontFamily')}
  294. >
  295. {fontFamilies}
  296. </Select>
  297. </Col>
  298. <Col span={10}>
  299. <Select
  300. placeholder="文字大小"
  301. className={styles.blockElm}
  302. value={labelFontSize}
  303. onChange={this.selectChange('labelFontSize')}
  304. >
  305. {fontSizes}
  306. </Select>
  307. </Col>
  308. <Col span={4}>
  309. <ColorPicker
  310. value={labelColor}
  311. onChange={this.colorChange('labelColor')}
  312. />
  313. </Col>
  314. </Row>
  315. {xAxisLabel}
  316. {titleAndUnit}
  317. </div>
  318. </div>
  319. )
  320. }
  321. }
  322. export default AxisSection