| | |
| | | |
| | | import asyncComponent from './asyncButtonComponent' |
| | | import Utils from '@/utils/utils.js' |
| | | import zhCN from '@/locales/zh-CN/model.js' |
| | | import enUS from '@/locales/en-US/model.js' |
| | | import zhCN from '@/locales/zh-CN/main.js' |
| | | import enUS from '@/locales/en-US/main.js' |
| | | import './index.scss' |
| | | |
| | | const ExcelOutButton = asyncComponent(() => import('@/tabviews/zshare/actionList/exceloutbutton')) |
| | |
| | | |
| | | class LineChart extends Component { |
| | | static propTpyes = { |
| | | BID: PropTypes.any, |
| | | Tab: PropTypes.any, |
| | | plot: PropTypes.object, |
| | | data: PropTypes.array, |
| | | loading: PropTypes.bool, |
| | | config: PropTypes.object, |
| | | getexceloutparam: PropTypes.func |
| | | BID: PropTypes.any, // 父级Id |
| | | Tab: PropTypes.any, // 标签信息 |
| | | plot: PropTypes.object, // 图标设置信息 |
| | | data: PropTypes.array, // 图表传入数据 |
| | | loading: PropTypes.bool, // 数据加载中 |
| | | config: PropTypes.object, // 页面配置信息 |
| | | getexceloutparam: PropTypes.func // 获取excel导出参数 |
| | | } |
| | | |
| | | state = { |
| | | dict: localStorage.getItem('lang') !== 'en-US' ? zhCN : enUS, |
| | | empty: true, |
| | | actions: [], |
| | | chartId: Utils.getuuid(), |
| | | chartData: [], |
| | | chartFields: [], |
| | | selectFields: [] |
| | | dict: localStorage.getItem('lang') !== 'en-US' ? zhCN : enUS, // 字典 |
| | | empty: true, // 图表数据为空 |
| | | actions: [], // 图表绑定的按钮组 |
| | | chartId: Utils.getuuid(), // 图表Id |
| | | chartData: [], // 图表数据 |
| | | chartFields: [], // 统计图表生成字段集 |
| | | selectFields: [], // 统计图表选择字段 |
| | | percentFields: [] // 设置为百分比的字段,tooltip时增加% |
| | | } |
| | | |
| | | /** |
| | | * @description 校验图表的按钮组,如果为统计图表,计算图表字段 |
| | | */ |
| | | componentDidMount () { |
| | | const { plot, data, config } = this.props |
| | | let _state = {} |
| | | let actions = [] |
| | | let percentFields = [] |
| | | |
| | | config.action.forEach(item => { |
| | | if (!plot.actions || plot.actions.length === 0) return |
| | | if (!(item.OpenType === 'excelOut' || (item.OpenType === 'excelIn' && item.Ot === 'notRequired'))) return |
| | |
| | | _state.selectFields = result.selectFields |
| | | _state.actions = actions |
| | | |
| | | let _column = config.columns.filter(col => plot.InfoValue === col.field)[0] |
| | | |
| | | if (_column && _column.format === 'percent') { |
| | | percentFields.push(plot.InfoValue) |
| | | _state.percentFields = percentFields |
| | | } |
| | | |
| | | this.setState(_state, () => { |
| | | this.viewrender() |
| | | }) |
| | | } else { |
| | | this.setState({ actions }) |
| | | this.viewrender() |
| | | if (plot.chartType === 'line' || plot.chartType === 'bar') { |
| | | try { |
| | | plot.Yaxis.forEach(yaxis => { |
| | | let _column = config.columns.filter(col => yaxis === col.field)[0] |
| | | if (_column && _column.format === 'percent') { |
| | | percentFields.push(_column.label) |
| | | } |
| | | }) |
| | | } catch { |
| | | console.warn('Incorrect percentage setting') |
| | | } |
| | | } |
| | | this.setState({ actions, percentFields }, () => { |
| | | this.viewrender() |
| | | }) |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * @description 图表数据更新,刷新内容 |
| | | */ |
| | | UNSAFE_componentWillReceiveProps (nextProps) { |
| | | const { plot } = this.props |
| | | if (!is(fromJS(this.props.data), fromJS(nextProps.data))) { |
| | |
| | | return !is(fromJS(this.props), fromJS(nextProps)) || !is(fromJS(this.state), fromJS(nextState)) |
| | | } |
| | | |
| | | /** |
| | | * @description 图表数据预处理 |
| | | * 1、通过显示列进行数据类型转换 |
| | | * 2、重复数据:取平均值、累计、去重 |
| | | * 3、柱状图数据补齐 |
| | | */ |
| | | getdata = () => { |
| | | const { data, plot, config } = this.props |
| | | let vFields = plot.Yaxis && typeof(plot.Yaxis) === 'string' ? [plot.Yaxis] : plot.Yaxis |
| | |
| | | return _data |
| | | } |
| | | |
| | | /** |
| | | * @description 统计数据预处理,动态生成统计字段并进行数据转换 |
| | | */ |
| | | getStaticMsg = (data) => { |
| | | const { plot, config } = this.props |
| | | |
| | |
| | | |
| | | item.$uuid = item[plot.InfoType] + item[plot.Xaxis] |
| | | if (typeof(item[plot.InfoValue]) !== 'number') { |
| | | item[plot.InfoValue] = parseFloat(plot.InfoValue) |
| | | item[plot.InfoValue] = parseFloat(item[plot.InfoValue]) |
| | | if (isNaN(item[plot.InfoValue])) { |
| | | item[plot.InfoValue] = 0 |
| | | } |
| | |
| | | item.$uuid = item[plot.InfoType] + item[plot.Xaxis] |
| | | |
| | | if (typeof(item[plot.InfoValue]) !== 'number') { |
| | | item[plot.InfoValue] = parseFloat(plot.InfoValue) |
| | | item[plot.InfoValue] = parseFloat(item[plot.InfoValue]) |
| | | if (isNaN(item[plot.InfoValue])) { |
| | | item[plot.InfoValue] = 0 |
| | | } |
| | |
| | | |
| | | if (!_mdata.has(item.$uuid)) { |
| | | if (typeof(item[plot.InfoValue]) !== 'number') { |
| | | item[plot.InfoValue] = parseFloat(plot.InfoValue) |
| | | item[plot.InfoValue] = parseFloat(item[plot.InfoValue]) |
| | | if (isNaN(item[plot.InfoValue])) { |
| | | item[plot.InfoValue] = 0 |
| | | } |
| | |
| | | return {data: _data, chartFields: _chartFields, selectFields: _selectFields} |
| | | } |
| | | |
| | | /** |
| | | * @description 获取统计图表展示数据,通过选择类型筛选 |
| | | */ |
| | | getStaticData = () => { |
| | | const { plot } = this.props |
| | | const { chartData, chartFields, selectFields } = this.state |
| | |
| | | return _data |
| | | } |
| | | |
| | | /** |
| | | * @description 图表渲染分组 |
| | | */ |
| | | viewrender = () => { |
| | | const { plot } = this.props |
| | | |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * @description 折线图渲染 |
| | | */ |
| | | linerender = () => { |
| | | const { plot, config } = this.props |
| | | const { percentFields } = this.state |
| | | |
| | | let _data = [] |
| | | let _valfield = 'value' |
| | |
| | | .position(`${plot.Xaxis}*${_valfield}`) |
| | | .color(_typefield) |
| | | .shape(plot.shape || 'smooth') |
| | | .tooltip(`${plot.Xaxis}*${_valfield}*${_typefield}`, (name, value, type) => { |
| | | return { |
| | | name: type, |
| | | value: percentFields.includes(type) ? value + '%' : value |
| | | } |
| | | }) |
| | | |
| | | if (plot.label === 'true') { |
| | | _chart.label(_valfield) |
| | |
| | | chart.render() |
| | | } |
| | | |
| | | /** |
| | | * @description 自定义渲染 |
| | | */ |
| | | customrender = (data, transfield) => { |
| | | const { plot } = this.props |
| | | const { percentFields } = this.state |
| | | |
| | | let barfields = [] |
| | | let fields = [] |
| | |
| | | label: null |
| | | }) |
| | | } |
| | | |
| | | |
| | | if (item.chartType === 'bar') { |
| | | let _chart = chart |
| | | .interval() |
| | | .position(`${plot.Xaxis}*${item.name}`) |
| | | .color(item.color) |
| | | .shape(item.shape) |
| | | .tooltip(`${item.name}`, (value) => { |
| | | return { |
| | | name: item.name, |
| | | value: percentFields.includes(item.name) ? value + '%' : value |
| | | } |
| | | }) |
| | | |
| | | if (item.label === 'true') { |
| | | _chart.label(item.name) |
| | |
| | | .position(`${plot.Xaxis}*${item.name}`) |
| | | .color(item.color) |
| | | .shape(item.shape) |
| | | .tooltip(`${item.name}`, (value) => { |
| | | return { |
| | | name: item.name, |
| | | value: percentFields.includes(item.name) ? value + '%' : value |
| | | } |
| | | }) |
| | | |
| | | if (item.label === 'true') { |
| | | _chart.label(item.name) |
| | |
| | | chart.render() |
| | | } |
| | | |
| | | /** |
| | | * @description 柱状图渲染 |
| | | */ |
| | | barrender = () => { |
| | | const { plot, config } = this.props |
| | | const { percentFields } = this.state |
| | | |
| | | let _data = [] |
| | | let _valfield = 'value' |
| | |
| | | } |
| | | ]) |
| | | .shape(plot.shape || 'rect') |
| | | .tooltip(`${plot.Xaxis}*${_valfield}*${_typefield}`, (name, value, type) => { |
| | | return { |
| | | name: type, |
| | | value: percentFields.includes(type) ? value + '%' : value |
| | | } |
| | | }) |
| | | |
| | | if (plot.label === 'true') { |
| | | _chart.label(_valfield) |
| | |
| | | .color(_typefield) |
| | | .adjust('stack') |
| | | .shape(plot.shape || 'rect') |
| | | .tooltip(`${plot.Xaxis}*${_valfield}*${_typefield}`, (name, value, type) => { |
| | | return { |
| | | name: type, |
| | | value: percentFields.includes(type) ? value + '%' : value |
| | | } |
| | | }) |
| | | |
| | | if (plot.label === 'true') { |
| | | _chart.label(_valfield) |
| | |
| | | chart.render() |
| | | } |
| | | |
| | | /** |
| | | * @description 饼图渲染 |
| | | */ |
| | | pierender = () => { |
| | | const { plot, config } = this.props |
| | | |
| | |
| | | chart.render() |
| | | } |
| | | |
| | | /** |
| | | * @description 统计图表,统计类型切换 |
| | | */ |
| | | handleChange = (val) => { |
| | | this.setState({selectFields: val}, () => { |
| | | let _element = document.getElementById(this.state.chartId) |