123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334 |
- import React from 'react'
- import { Row, Col, Checkbox, Select, InputNumber } from 'antd'
- const Option = Select.Option
- import ColorPicker from 'components/ColorPicker'
- import { PIVOT_CHART_FONT_FAMILIES, PIVOT_CHART_LINE_STYLES, PIVOT_CHART_FONT_SIZES } from 'app/globalConstants'
- import { getCorrectInputNumber } from '../../util'
- const styles = require('../Workbench.less')
- export interface IAxisConfig {
- inverse: boolean
- showLine: boolean
- lineStyle: 'solid' | 'dashed' | 'dotted'
- lineSize: string
- lineColor: string
- showLabel: boolean
- labelFontFamily: string
- labelFontSize: string
- labelColor: string
- labelStyle: 'normal' | 'italic' | 'oblique'
- labelWeight: 'normal' | 'bold' | 'bolder' | 'lighter'
- showTitleAndUnit?: boolean
- nameLocation: 'start' | 'middle' | 'center' | 'end'
- nameRotate?: number
- nameGap?: number
- titleFontFamily?: string
- titleFontStyle?: string
- titleFontSize?: string
- titleColor?: string
- showInterval?: boolean
- xAxisInterval?: number
- xAxisRotate?: number
- min?: number
- max?: number
- }
- interface IAxisSectionProps {
- title: string
- config: IAxisConfig
- onChange: (prop: string, value: any) => void
- }
- export class AxisSection extends React.PureComponent<IAxisSectionProps, {}> {
- private checkboxChange = (prop) => (e) => {
- this.props.onChange(prop, e.target.checked)
- }
- private selectChange = (prop) => (value) => {
- this.props.onChange(prop, value)
- }
- private inputNumberChange = (prop) => (value) => {
- this.props.onChange(prop, getCorrectInputNumber(value))
- }
- private colorChange = (prop) => (color) => {
- this.props.onChange(prop, color)
- }
- public render () {
- const { title, config } = this.props
- const {
- showLine,
- inverse,
- lineStyle,
- lineSize,
- lineColor,
- showLabel,
- labelFontFamily,
- labelFontSize,
- labelColor,
- labelStyle,
- labelWeight,
- showTitleAndUnit,
- nameLocation,
- nameRotate,
- nameGap,
- titleFontFamily,
- titleFontStyle,
- titleFontSize,
- titleColor,
- showInterval,
- xAxisInterval,
- xAxisRotate,
- min,
- max
- } = config
- const lineStyles = PIVOT_CHART_LINE_STYLES.map((l) => (
- <Option key={l.value} value={l.value}>{l.name}</Option>
- ))
- const fontFamilies = PIVOT_CHART_FONT_FAMILIES.map((f) => (
- <Option key={f.value} value={f.value}>{f.name}</Option>
- ))
- const fontSizes = PIVOT_CHART_FONT_SIZES.map((f) => (
- <Option key={`${f}`} value={`${f}`}>{f}</Option>
- ))
- const xAxisLabel = showTitleAndUnit === void 0 && [(
- <Row key="gap1" gutter={8} type="flex" align="middle" className={styles.blockRow}>
- <Col span={2} />
- <Col span={8}>旋转角度</Col>
- <Col span={10}>
- <InputNumber
- placeholder="x轴旋转角度"
- className={styles.blockElm}
- value={xAxisRotate}
- onChange={this.inputNumberChange('xAxisRotate')}
- />
- </Col>
- </Row>
- ), (
- <Row key="gap" gutter={8} type="flex" align="middle" className={styles.blockRow}>
- <Col span={2}>
- <Checkbox
- checked={showInterval}
- onChange={this.checkboxChange('showInterval')}
- />
- </Col>
- <Col span={8}>刻度间隔</Col>
- <Col span={10}>
- <InputNumber
- placeholder="刻度间隔"
- className={styles.blockElm}
- value={xAxisInterval}
- onChange={this.inputNumberChange('xAxisInterval')}
- disabled={!showInterval}
- />
- </Col>
- </Row>
- )]
- const titleAndUnit = showTitleAndUnit !== void 0 && [(
- <Row key="title" gutter={8} type="flex" align="middle" className={styles.blockRow}>
- <Col span={24}>
- <Checkbox
- checked={showTitleAndUnit}
- onChange={this.checkboxChange('showTitleAndUnit')}
- >
- 显示标题和单位
- </Checkbox>
- </Col>
- </Row>
- ), (
- <Row key="body" gutter={8} type="flex" align="middle" className={styles.blockRow}>
- <Col span={10}>
- <Select
- placeholder="字体"
- className={styles.blockElm}
- value={titleFontFamily}
- onChange={this.selectChange('titleFontFamily')}
- >
- {fontFamilies}
- </Select>
- </Col>
- <Col span={10}>
- <Select
- placeholder="文字大小"
- className={styles.blockElm}
- value={titleFontSize}
- onChange={this.selectChange('titleFontSize')}
- >
- {fontSizes}
- </Select>
- </Col>
- <Col span={4}>
- <ColorPicker
- value={titleColor}
- onChange={this.colorChange('titleColor')}
- />
- </Col>
- </Row>
- ), (
- <Row key="location" gutter={8} type="flex" align="middle" className={styles.blockRow}>
- <Col span={12}>标题位置</Col>
- <Col span={10}>
- <Select
- placeholder="位置"
- className={styles.blockElm}
- value={nameLocation}
- onChange={this.selectChange('nameLocation')}
- >
- <Option key="start" value="start">开始</Option>
- <Option key="center" value="middle">中间</Option>
- <Option key="end" value="end">结束</Option>
- </Select>
- </Col>
- </Row>
- ), (
- <Row key="rotate" gutter={8} type="flex" align="middle" className={styles.blockRow}>
- <Col span={12}>标题旋转</Col>
- <Col span={10}>
- <InputNumber
- placeholder="标题旋转"
- className={styles.blockElm}
- value={nameRotate}
- onChange={this.inputNumberChange('nameRotate')}
- />
- </Col>
- </Row>
- ), (
- <Row key="gap" gutter={8} type="flex" align="middle" className={styles.blockRow}>
- <Col span={12}>标题与轴线距离</Col>
- <Col span={10}>
- <InputNumber
- placeholder="标题与轴线距离"
- className={styles.blockElm}
- value={nameGap}
- onChange={this.inputNumberChange('nameGap')}
- />
- </Col>
- </Row>
- ), (
- <Row key="min" gutter={8} type="flex" align="middle" className={styles.blockRow}>
- <Col span={12}>最小值</Col>
- <Col span={10}>
- <InputNumber
- className={styles.blockElm}
- value={min}
- onChange={this.inputNumberChange('min')}
- />
- </Col>
- </Row>
- ), (
- <Row key="max" gutter={8} type="flex" align="middle" className={styles.blockRow}>
- <Col span={12}>最大值</Col>
- <Col span={10}>
- <InputNumber
- className={styles.blockElm}
- value={max}
- onChange={this.inputNumberChange('max')}
- />
- </Col>
- </Row>
- )]
- return (
- <div className={styles.paneBlock}>
- <h4>{title}</h4>
- <div className={styles.blockBody}>
- <Row gutter={8} type="flex" align="middle" className={styles.blockRow}>
- <Col span={12}>
- <Checkbox
- checked={showLine}
- onChange={this.checkboxChange('showLine')}
- >
- 显示坐标轴
- </Checkbox>
- </Col>
- <Col span={12}>
- <Checkbox
- checked={inverse}
- onChange={this.checkboxChange('inverse')}
- >
- 坐标轴反转
- </Checkbox>
- </Col>
- </Row>
- <Row gutter={8} type="flex" align="middle" className={styles.blockRow}>
- <Col span={10}>
- <Select
- placeholder="样式"
- className={styles.blockElm}
- value={lineStyle}
- onChange={this.selectChange('lineStyle')}
- >
- {lineStyles}
- </Select>
- </Col>
- <Col span={10}>
- <Select
- placeholder="粗细"
- className={styles.blockElm}
- value={lineSize}
- onChange={this.selectChange('lineSize')}
- >
- {Array.from(Array(10), (o, i) => (
- <Option key={i} value={`${i + 1}`}>{i + 1}</Option>
- ))}
- </Select>
- </Col>
- <Col span={4}>
- <ColorPicker
- value={lineColor}
- onChange={this.colorChange('lineColor')}
- />
- </Col>
- </Row>
- <Row gutter={8} type="flex" align="middle" className={styles.blockRow}>
- <Col span={24}>
- <Checkbox
- checked={showLabel}
- onChange={this.checkboxChange('showLabel')}
- >
- 显示标签文字
- </Checkbox>
- </Col>
- </Row>
- <Row gutter={8} type="flex" align="middle" className={styles.blockRow}>
- <Col span={10}>
- <Select
- placeholder="字体"
- className={styles.blockElm}
- value={labelFontFamily}
- onChange={this.selectChange('labelFontFamily')}
- >
- {fontFamilies}
- </Select>
- </Col>
- <Col span={10}>
- <Select
- placeholder="文字大小"
- className={styles.blockElm}
- value={labelFontSize}
- onChange={this.selectChange('labelFontSize')}
- >
- {fontSizes}
- </Select>
- </Col>
- <Col span={4}>
- <ColorPicker
- value={labelColor}
- onChange={this.colorChange('labelColor')}
- />
- </Col>
- </Row>
- {xAxisLabel}
- {titleAndUnit}
- </div>
- </div>
- )
- }
- }
- export default AxisSection
|