king
2022-01-21 46f79b491173d284a4900d19e7aecf7509481438
src/tabviews/custom/components/chart/antv-bar-line/index.jsx
@@ -4,6 +4,7 @@
import { Chart } from '@antv/g2'
import DataSet from '@antv/data-set'
import { Spin, Empty, notification } from 'antd'
import { DownloadOutlined } from '@ant-design/icons'
import moment from 'moment'
import asyncComponent from './asyncButtonComponent'
@@ -41,6 +42,7 @@
    search: null,              // 搜索条件
    vFields: [],               // 数值字段
    vstFields: null,           // 统计数据值字段信息
    chart: null
  }
  UNSAFE_componentWillMount () {
@@ -124,7 +126,7 @@
      _config.plot.hasBar = Bar_axis.length > 0
      if (_config.plot.mutilBar !== 'overlap') {
      if (_config.plot.mutilBar !== 'overlap' && Bar_axis.length > 1) {
        _config.plot.Bar_axis = Bar_axis
      }
    } else {
@@ -235,7 +237,8 @@
      let axisIndex = 0
      let fields = []
      let legends = []
      let vFieldsShow = {}
      _config.plot.customs.forEach(item => {
        if (colors.has(item.name)) {
          item.color = colors.get(item.name)
@@ -292,10 +295,19 @@
          name: item.name,
          marker: { symbol: item.chartType === 'bar' ? 'square' : 'hyphen', style: { stroke: item.color,fill: item.color, r: 5, lineWidth: 2 } }
        })
        if ((!_config.plot.Bar_axis || item.chartType !== 'bar') && item.show) { // 折线图或重叠下的柱状图可单独设置显示类型
          vFieldsShow[item.type] = item.show
        }
      })
      _config.plot.customs = fields
      _config.plot.legends = legends
      _config.plot.axisIndex = axisIndex
      vFields.forEach(item => {
        if (vFieldsShow[item.field]) {
          item.show = vFieldsShow[item.field]
        }
      })
    }
    this.setState({
@@ -1059,6 +1071,8 @@
    }
    
    chart.render()
    this.setState({chart})
  }
  /**
@@ -1310,7 +1324,7 @@
    view2.data(dv.rows)
    view2.legend(false)
    plot.customs.forEach((item, i) => {
    plot.customs.forEach(item => {
      if (item.chartType === 'bar' && !plot.Bar_axis) {
        view2.axis(item.name, item.axis)
      
@@ -1335,7 +1349,7 @@
          .tooltip(`${item.name}`, (value) => {
            return {
              name: item.name,
              value: plot.show === 'percent' ? value + '%' : value
              value: item.show === 'percent' ? value + '%' : value
            }
          })
@@ -1344,7 +1358,7 @@
        }
        if (item.label !== 'false') {
          _chart.label(item.name, (value) => {
            if (plot.show === 'percent') {
            if (item.show === 'percent') {
              value = value + '%'
            }
            if (plot.label === 'true' && plot.labelColor === 'custom' && item.color) {
@@ -1386,13 +1400,13 @@
          .tooltip(`${item.name}`, (value) => {
            return {
              name: item.name,
              value: plot.show === 'percent' ? value + '%' : value
              value: item.show === 'percent' ? value + '%' : value
            }
          })
        if (item.label === 'true') {
          _chart.label(item.name, (value) => {
            if (plot.show === 'percent') {
            if (item.show === 'percent') {
              value = value + '%'
            }
            return {
@@ -1424,6 +1438,8 @@
    }
    chart.render()
    this.setState({chart})
  }
  /**
@@ -1697,12 +1713,51 @@
    }
    chart.render()
    this.setState({chart})
  }
  refreshSearch = (list) => {
    this.setState({search: list}, () => {
      this.loadData()
    })
  }
  downloadImage = () => {
    const { chart, config } = this.state
    const link = document.createElement('a');
    const filename = `${config.name}${moment().format('YYYY-MM-DD HH_mm_ss')}.png`;
    const canvas = chart.getCanvas();
    canvas.get('timeline').stopAllAnimations();
    setTimeout(() => {
      const canvas = chart.getCanvas();
      const canvasDom = canvas.get('el');
      const dataURL = canvasDom.toDataURL('image/png');
      if (window.Blob && window.URL) {
        const arr = dataURL.split(',');
        const mime = arr[0].match(/:(.*?);/)[1];
        const bstr = atob(arr[1]);
        let n = bstr.length;
        const u8arr = new Uint8Array(n);
        while (n--) {
          u8arr[n] = bstr.charCodeAt(n);
        }
        const blobObj = new Blob([u8arr], { type: mime });
        if (window.navigator.msSaveBlob) {
          window.navigator.msSaveBlob(blobObj, filename);
        } else {
          link.addEventListener('click', () => {
            link.download = filename;
            link.href = window.URL.createObjectURL(blobObj);
          });
        }
      }
      const e = document.createEvent('MouseEvents');
      e.initEvent('click', false, false);
      link.dispatchEvent(e);
    }, 16);
  }
  render() {
@@ -1718,7 +1773,8 @@
        }
        <NormalHeader config={config} BID={BID} menuType={this.props.menuType} refresh={this.refreshSearch} />
        <div className="canvas-wrap" ref={ref => this.wrap = ref}>
          <div className="chart-action">
          {config.plot.download === 'enable' && this.state.chart && !empty ? <DownloadOutlined onClick={this.downloadImage} className="system-color download"/> : null}
          <div className={'chart-action' + (config.plot.download === 'enable' ? ' downable' : '')}>
            {config.action.map(item => {
              if (item.OpenType === 'excelOut') {
                return (