import { pictorialBarChart, CATEGORIES } from '../../configuration/constants'
import { echartsBasicListen } from '../../feature/traits/common'
import { throttle } from '../../utils'

export default {

  // 组件名称
  name: pictorialBarChart,

  // 前面板html模板
  viewTemplate() {
    return `
      <div data-gjs-type="${pictorialBarChart}" class="${pictorialBarChart}"></div>
    `
  },
  // 前面板html样式
  viewStyle() {
    return `
      <style>
        .${pictorialBarChart} {
          position: absolute;
          border-radius: 5px;
          border-style: solid;
          border-width: 1px;
          border-color: transparent;
          padding: 10px;
          width: 600px;
          height: 400px;
        }
      </style>
    `
  },

  // 编辑器右侧块管理器中显示属性配置
  blockOptions() {
    return {
      category: CATEGORIES.ECHARTS,
      label: `
      <svg class="gjs-block-svg" viewBox="0 0 1024 1024" xmlns="http://www.w3.org/2000/svg" ><path d="M928 807.872V896h-832v-88.128h832zM273.408 480.384v197.248H182.848V480.384h90.56z m287.744-125.952v323.2H470.592v-323.2h90.56zM846.656 128v545.28h-90.496V128h90.496z"></path></svg>
        <div class="gjs-block-label">象形柱图</div>
      `,
    };
  },

  // 后面板显示属性配置
  spOptions() {
    return {
      label: '象形柱图',
      icon: 'globe',
      docUrl: '#',
      author: '秋水',
      email: 'qiushui.smy@xuelangyun.com',
      inPorts: [{
        uuid: 'in1',
        subType: 'json',
        description: {
          zh_CN: '输入1'
        }
      }],
      outPorts: [{
        uuid: 'out1',
        subType: 'json',
        description: {
          zh_CN: '输出1'
        }
      }]
    }
  },

  // 组件属性
  componentOptions() {
    return {
      name: pictorialBarChart,
      resizable: true,
      dmode: 'absolute',
      droppable: false,
      traits: [
        {
          name: 'gridPadding',
          label: '容器边距(左,上,右,下)',
          changeProp: 1
        }, {
          name: 'containLabel',
          label: '包含刻度标签',
          changeProp: 1,
          type: 'checkbox'
        }, {
          name: 'labelPosition',
          label: '标签',
          type: 'select',
          changeProp: 1,
          options: [{ id: 'null', name: '无标签' }, { id: 'top', name: '上' }, { id: 'left', name: '左' }, { id: 'right', name: '右' }, { id: 'bottom', name: '下' }, { id: 'inside', name: '内部' }, { id: 'insideLeft', name: '内部左侧' }, { id: 'insideRight', name: '内部右侧' }, { id: 'insideTop', name: '内部上侧' }, { id: 'insideBottom', name: '内部下侧' }, { id: 'insideRight', name: '内部右侧' }, { id: 'insideRight', name: '内部右侧' }]
        }, {
          name: 'labelDistance',
          label: '标签边距',
          changeProp: 1,
          type: 'number',
        }, {
          name: 'labelFontsize',
          label: '标签字号',
          changeProp: 1,
          type: 'number',
          min: 9,
        }, {
          name: 'labelFontFamily',
          label: '标签字体',
          changeProp: 1,
          type: 'select',
          options: [
            { id: 'sans-serif', name: '默认' },
            { id: '庞门正道', name: '庞门正道' },
            { id: 'DS-Digital', name: 'DS-Digital' }
          ]
        }, {
          name: 'labelColor',
          label: '标签颜色',
          changeProp: 1,
          type: 'color',
        }, {
          name: 'barWidth',
          label: '柱宽',
          changeProp: 1,
          type: "number"
        }, {
          name: 'symbolType',
          label: '图形类型',
          changeProp: 1,
          type: "select",
          options: [
            { id: 'customer', name: '自定义' },
            { id: 'circle', name: '圆形' },
            { id: 'rect', name: '矩形' },
            { id: 'roundRect', name: '圆角矩形' },
            { id: 'triangle', name: '三角形' },
            { id: 'diamond', name: '菱形' },
            { id: 'pin', name: '大头针' },
            { id: 'arrow', name: '箭头' },
            { id: 'none', name: '无' }
          ]
        }, {
          name: 'symbol',
          label: '自定义图形1',
          changeProp: 1,
          type: "imageSelector"
        }, {
          name: 'symbol2',
          label: '自定义图形2',
          changeProp: 1,
          type: "imageSelector"
        }, {
          name: 'symbol3',
          label: '自定义图形3',
          changeProp: 1,
          type: "imageSelector"
        }, {
          name: 'symbolSize',
          label: '图形大小',
          changeProp: 1
        }, {
          name: 'symbolRotate',
          label: '图形角度',
          changeProp: 1,
          type: 'number'
        }, {
          name: 'symbolRepeat',
          label: '图形重复',
          changeProp: 1,
          type: 'checkbox'
        }, {
          name: 'symbolMargin',
          label: '图形间隔',
          changeProp: 1,
          type: 'number'
        }, {
          name: 'pointerType',
          label: 'Tooltip指示器类型',
          changeProp: 1,
          type: 'select',
          options: [{ id: 'line', name: '直线' }, { id: 'shadow', name: '阴影' }, { id: 'cross', name: ' 十字准星' }, { id: 'none', name: '无' }]
        }, {
          name: 'pointerColor',
          label: '指示器颜色',
          changeProp: 1,
          type: 'color'
        }, {
          name: 'clickEvent',
          label: '鼠标事件',
          changeProp: 1,
          type: 'select',
          options: [{ id: 'null', name: '无' }, { id: 'click', name: '单击' }, { id: 'dblclick', name: '双击' }, { id: 'mousedown', name: '按下' }, { id: 'mouseup', name: '松开' }, { id: 'mouseover', name: '滑过' }, { id: 'mouseout', name: '滑出' }]
        }, {
          name: 'xAxisType',
          label: 'x轴类型',
          changeProp: 1,
          type: 'select',
          options: [{ id: 'category', name: '类目轴' }, { id: 'value', name: '数值轴' }, { id: 'time', name: '时间轴' }]
        }, {
          name: 'yAxisType',
          label: 'y轴类型',
          changeProp: 1,
          type: 'select',
          options: [{ id: 'category', name: '类目轴' }, { id: 'value', name: '数值轴' }, { id: 'time', name: '时间轴' }]
        }, {
          name: 'xAxisName',
          label: 'x轴名称',
          changeProp: 1
        }, {
          name: 'xAxisNameLocation',
          label: 'x轴名称位置',
          changeProp: 1,
          type: 'select',
          options: [{ id: 'start', name: '开始' }, { id: 'center', name: '中间' }, { id: 'end', name: '末尾' }]
        }, {
          name: 'yAxisName',
          label: 'y轴名称',
          changeProp: 1
        }, {
          name: 'yAxisNameLocation',
          label: 'y轴名称位置',
          changeProp: 1,
          type: 'select',
          options: [{ id: 'start', name: '开始' }, { id: 'middle', name: '中间' }, { id: 'end', name: '末尾' }]
        }, {
          name: 'axisNameFontsize',
          label: '轴名称字号',
          changeProp: 1,
          type: 'number',
          min: 9,
          step: 1
        }, {
          name: 'xAxisLine',
          label: 'x轴轴线',
          changeProp: 1,
          type: 'checkbox'
        }, {
          name: 'yAxisLine',
          label: 'y轴轴线',
          changeProp: 1,
          type: 'checkbox'
        }, {
          name: 'axisColor',
          label: '坐标轴颜色',
          changeProp: 1,
          type: 'color'
        }, {
          name: 'axisLineWidth',
          label: '坐标轴线宽',
          changeProp: 1,
          type: 'number',
          min: 1,
          step: 1
        }, {
          name: 'xAxisTick',
          label: 'x轴刻度线',
          changeProp: 1,
          type: 'checkbox'
        }, {
          name: 'yAxisTick',
          label: 'y轴刻度线',
          changeProp: 1,
          type: 'checkbox'
        }, {
          name: 'xAxisLabel',
          label: 'x轴刻度值',
          changeProp: 1,
          type: 'checkbox'
        }, {
          name: 'yAxisLabel',
          label: 'y轴刻度值',
          changeProp: 1,
          type: 'checkbox'
        }, {
          name: 'yAxisLabelAlign',
          label: 'y轴刻度值对齐',
          changeProp: 1,
          type: 'select',
          options: [{ id: 'right', name: '右对齐' }, { id: 'left', name: '左对齐' }, { id: 'center', name: '居中对齐' }]
        }, {
          name: 'axisLabelFontsize',
          label: '刻度值字号',
          changeProp: 1,
          type: 'number',
          min: 9,
          step: 1
        }, {
          name: 'axisLabelFontFamily',
          label: '刻度值字体',
          changeProp: 1,
          type: 'select',
          options: [
            { id: 'sans-serif', name: '默认' },
            { id: '庞门正道', name: '庞门正道' },
            { id: 'DS-Digital', name: 'DS-Digital' }
          ]
        }, {
          name: 'xAxisSplitLine',
          label: 'x轴分割线',
          changeProp: 1,
          type: 'checkbox'
        }, {
          name: 'yAxisSplitLine',
          label: 'y轴分割线',
          changeProp: 1,
          type: 'checkbox'
        }, {
          name: 'axisSplitLineColor',
          label: '分割线颜色',
          changeProp: 1,
          type: 'color'
        }, {
          name: 'axisSplitLineType',
          label: '分割线类型',
          changeProp: 1,
          type: 'select',
          options: [{ id: 'solid', name: '实线' }, { id: 'dashed', name: '虚线' }, { id: 'dotted', name: '点线' }]
        }, {
          name: 'yAxisInverse',
          label: 'y轴反向',
          changeProp: 1,
          type: 'checkbox'
        }, {
          name: 'yAxisOffset',
          label: 'y轴偏移',
          changeProp: 1,
          type: 'number'
        }, {
          name: 'csv',
          label: '示例数据',
          changeProp: 1,
          type: 'csvDownload',
          preFileName: '象形柱图',
          datas: [["name", "DEMO", "Other"], ["one", 1, 7], ["two", 2, 3], ["three", 3, 1], ["four", 4, 2], ["five", 5, 4]]
        }, {
          name: 'defaultData',
          changeProp: 1,
          type: 'hide'
        }
      ],
      'defaultData': JSON.stringify([
        ["name", "DEMO", "Other"], ["one", 1, 7], ["two", 2, 3], ["three", 3, 1], ["four", 4, 2], ["five", 5, 4]
      ]).replace(/\"/g, "\\\""),
      'gridPadding': '10%,60,10%,60',
      'containLabel': true,
      'xAxisType': 'category',
      'yAxisType': 'value',
      'xAxisName': null,
      'xAxisNameLocation': 'end',
      'yAxisName': null,
      'yAxisNameLocation': 'end',
      'axisNameFontsize': 12,
      'xAxisLine': true,
      'xAxisSplitLine': false,
      'xAxisTick': true,
      'xAxisLabel': true,
      'yAxisLine': true,
      'yAxisSplitLine': true,
      'yAxisTick': true,
      'yAxisLabel': true,
      'yAxisInverse': false,
      'yAxisOffset': 0,
      'yAxisLabelAlign': 'right',
      'axisColor': '#333333',
      'axisLineWidth': 1,
      'axisSplitLineColor': '#333333',
      'axisSplitLineType': 'dashed',
      'axisLabelFontsize': 12,
      'axisLabelFontFamily': 'sans-serif',
      'labelPosition': 'null',
      'labelDistance': 5,
      'labelFontFamily': "sans-serif",
      'labelFontsize': 12,
      'labelColor': '#333333',
      'barWidth': null,
      'symbolType': 'triangle',
      'symbol': null,
      'symbol2': null,
      'symbol3': null,
      'symbolSize': '100%, 100%',
      'symbolRotate': 0,
      'symbolRepeat': true,
      'symbolMargin': null,
      'zoomStart': -1,
      'zoomEnd': 100,
      'axisType': false,
      'pointerType': 'line',
      'pointerColor': 'rgba(255,255,255,1)',
      'clickEvent': 'null'
    }
  },

  onModelScript() {
    const dataSource = '{[ dataSource ]}';
    const bgColor = '{[ bgColor ]}';
    const borderColor = '{[ borderColor ]}';
    const fontColor = '{[ fontColor ]}';
    const fontSize = Number('{[ fontSize ]}');
    let colors = '{[ colors ]}';
    let legendPosition = ('{[ legendPosition ]}').toString();
    const legendOrient = ('{[ legendOrient ]}').toString();
    const legendItemGap = Number('{[ legendItemGap ]}');
    const legendItemWidth = Number('{[ legendItemWidth ]}');
    const legendItemHeight = Number('{[ legendItemHeight ]}');
    const legendFontSize = Number('{[ legendFontSize ]}');
    const legendFontFamily = ('{[ legendFontFamily ]}').toString();
    const labelPosition = ('{[ labelPosition ]}').toString();
    const labelFontFamily = ('{[ labelFontFamily ]}').toString();
    const labelFontsize = Number('{[ labelFontsize ]}');
    const labelDistance = Boolean('{[ labelDistance ]}') ? Number('{[ labelDistance ]}') : 0;
    const labelColor = '{[ labelColor ]}';
    const titleText = '{[ titleText ]}';
    const titleColor = '{[ titleColor ]}';
    const titlePosition = ('{[ titlePosition ]}').toString();
    const xAxisType = '{[ xAxisType ]}';
    const yAxisType = '{[ yAxisType ]}';
    const xAxisName = '{[ xAxisName ]}';
    const xAxisNameLocation = '{[ xAxisNameLocation ]}';
    const yAxisName = '{[ yAxisName ]}';
    const yAxisNameLocation = '{[ yAxisNameLocation ]}';
    const axisColor = '{[ axisColor ]}';
    const xAxisLine = Boolean('{[ xAxisLine ]}');
    const axisLineWidth = Number('{[ axisLineWidth ]}');
    const xAxisSplitLine = Boolean('{[ xAxisSplitLine ]}');
    const xAxisTick = Boolean('{[ xAxisTick ]}');
    const xAxisLabel = Boolean('{[ xAxisLabel ]}');
    const yAxisLine = Boolean('{[ yAxisLine ]}');
    const yAxisSplitLine = Boolean('{[ yAxisSplitLine ]}');
    const yAxisTick = Boolean('{[ yAxisTick ]}');
    const yAxisLabel = Boolean('{[ yAxisLabel ]}');
    const yAxisInverse = Boolean('{[ yAxisInverse ]}');
    const axisNameFontsize = Number('{[ axisNameFontsize ]}');
    const yAxisOffset = Boolean('{[ yAxisOffset ]}') ? parseInt('{[ yAxisOffset ]}') : 0;
    const yAxisLabelAlign = '{[ yAxisLabelAlign ]}';
    const axisLabelFontsize = Number('{[ axisLabelFontsize ]}');
    const axisLabelFontFamily = ('{[ axisLabelFontFamily ]}').toString();
    const axisSplitLineColor = '{[ axisSplitLineColor ]}';
    const axisSplitLineType = ('{[ axisSplitLineType ]}').toString();
    let gridPadding = '{[ gridPadding ]}';
    const symbolType = '{[ symbolType ]}';
    const symbolSize = '{[ symbolSize ]}';
    const symbol = '{[ symbol ]}';
    const symbol2 = '{[ symbol2 ]}';
    const symbol3 = '{[ symbol3 ]}';
    const barWidth = '{[ barWidth ]}';
    const symbolRotate = '{[ symbolRotate ]}';
    const symbolRepeat = Boolean('{[ symbolRepeat ]}');
    const symbolMargin = Boolean('{[ symbolMargin ]}') ? parseInt('{[ symbolMargin ]}') : 0;
    const legendMap = ('{[ legendMap ]}').toString();
    const pointerType = ('{[ pointerType ]}').toString();
    const pointerColor = '{[ pointerColor ]}';
    const containLabel = Boolean('{[ containLabel ]}');
    const clickEvent = ('{[ clickEvent ]}').toString();
    const defaultData = JSON.parse('{[ defaultData ]}'.replace(/\\\"/g, "\""));

    Boolean(bgColor) ? $(this).css({ backgroundColor: bgColor }) : $(this).css({ backgroundColor: 'transparent' });
    Boolean(borderColor) ? $(this).css({ borderColor: borderColor }) : $(this).css({ borderColor: 'transparent' });
    if (colors.indexOf(',') > -1) {
      colors = colors.split(',').map(item => item.trim())
    } else if (Boolean(colors)) {
      colors = [colors]
    } else {
      colors = ['#c23531', '#2f4554', '#61a0a8', '#d48265', '#91c7ae', '#749f83', '#ca8622', '#bda29a', '#6e7074', '#546570', '#c4ccd3'];
    }

    const grid = {
      containLabel: containLabel
    };
    if (gridPadding.indexOf(',') > -1) {
      gridPadding = gridPadding.split(',').map(item => item.trim());
      grid.left = gridPadding[0];
      grid.top = gridPadding[1];
      grid.right = gridPadding[2] || gridPadding[0];
      grid.bottom = gridPadding[3] || gridPadding[1];
    } else if (Boolean(gridPadding)) {
      grid.left = gridPadding;
      grid.top = gridPadding;
      grid.right = gridPadding;
      grid.bottom = gridPadding;
    }

    const titlePositionArr = titlePosition.split(',');
    const title = {
      text: titleText,
      left: titlePositionArr[0],
      top: titlePosition.indexOf(',') > 0 ? titlePositionArr[1] : titlePositionArr[0],
      textStyle: {
        fontSize: fontSize ? fontSize + 4 : 16,
        color: titleColor || fontColor
      }
    };

    const legendShow = legendOrient != 'null';
    const legend = {
      show: legendShow,
      type: 'scroll',
      itemGap: legendItemGap,
      itemWidth: legendItemWidth,
      itemHeight: legendItemHeight,
      textStyle: {
        fontFamily: legendFontFamily,
        fontSize: legendFontSize || fontSize,
        color: fontColor,
      }
    };
    if (Boolean(legendPosition)) {
      legendPosition.split(',').forEach((item, i) => {
        if (item.indexOf(':') > 0) {
          const key = item.split(':')[0].trim();
          const value = item.split(':')[1].trim();
          legend[`${key}`] = value;
        } else {
          legend[`${i ? 'top' : 'left'}`] = item.trim();
        }
      });
    }
    if (legendShow) {
      legend.orient = legendOrient;
    } else {
      legend.show = false;
    }

    let _legendMap;
    if (legendMap.indexOf(':') > 0) {
      _legendMap = {};
      let _legendArr;
      if (legendMap.indexOf(',') > 0) {
        _legendArr = legendMap.split(',');
      } else {
        _legendArr = [legendMap]
      }
      _legendArr.forEach(function (item) {
        if (item.indexOf(':') > 0) {
          const _item = item.trim().split(':').map(v => v.trim());
          _legendMap[_item[0].toString().toLocaleLowerCase()] = _item[1];
        }
      });
      legend.formatter = function (name) {
        return _legendMap[name.toString().toLocaleLowerCase()] || name
      }
    } else {
      legend.formatter = null
    }

    const labelShow = labelPosition != 'null'
    const serieTemp = {
      type: 'pictorialBar',
      label: {
        show: labelShow,
        color: labelColor,
        distance: labelDistance,
        fontSize: labelFontsize,
        fontFamily: labelFontFamily
      },
      barWidth: barWidth,
      symbol: symbolType === 'customer' ? "image://" + symbol : symbolType,
      symbolSize: symbolSize.split(','),
      symbolRotate: symbolRotate,
      symbolRepeat: symbolRepeat,
      symbolMargin: symbolMargin
    };
    if (labelShow) {
      serieTemp.label.position = labelPosition
    }

    const xAxis = {
      type: xAxisType,
      name: xAxisName,
      scale: xAxisType == 'value',
      nameLocation: xAxisNameLocation,
      axisLine: {
        show: xAxisLine,
        lineStyle: {
          color: axisColor,
          width: axisLineWidth,
        }
      },
      axisTick: {
        show: xAxisTick,
        lineStyle: {
          width: axisLineWidth,
        }
      },
      axisLabel: {
        show: xAxisLabel,
        color: fontColor,
        fontFamily: axisLabelFontFamily,
        fontSize: axisLabelFontsize || fontSize
      },
      splitLine: {
        show: xAxisSplitLine,
        lineStyle: {
          color: axisSplitLineColor,
          type: axisSplitLineType,
          opacity: 0.4,
        }
      }
    };
    if (Boolean(xAxisName)) {
      xAxis.nameTextStyle = {
        fontSize: axisNameFontsize || fontSize,
        color: fontColor
      }
    }
    const yAxis = {
      type: yAxisType,
      name: yAxisName,
      nameLocation: yAxisNameLocation,
      inverse: yAxisInverse,
      offset: yAxisOffset,
      axisLine: {
        show: yAxisLine,
        lineStyle: {
          width: axisLineWidth,
          color: axisColor
        }
      },
      axisTick: {
        show: yAxisTick,
        lineStyle: {
          width: axisLineWidth,
        }
      },
      axisLabel: {
        show: yAxisLabel,
        align: yAxisLabelAlign,
        color: fontColor,
        fontFamily: axisLabelFontFamily,
        fontSize: axisLabelFontsize || fontSize
      },
      splitLine: {
        show: yAxisSplitLine,
        lineStyle: {
          color: axisSplitLineColor,
          type: axisSplitLineType,
          opacity: 0.4,
        }
      }
    };
    if (Boolean(yAxisName)) {
      yAxis.nameTextStyle = {
        fontSize: axisNameFontsize || fontSize,
        color: fontColor
      }
    }

    const tooltip = {
      trigger: 'axis',
      axisPointer: {
        type: pointerType,
        lineStyle: {
          color: pointerColor
        },
        shadowStyle: {
          color: pointerColor
        },
        crossStyle: {
          color: pointerColor
        }
      },
      lineStyle: {
        color: axisColor,
        opacity: 0.6
      },
      textStyle: {
        fontSize: fontSize
      }
    };
    if (_legendMap) {
      tooltip.formatter = function (params) {
        if (params.length) {
          const xAxisName = params[0].name;
          const list = params.map(function (item) {
            const seriesName = _legendMap ? _legendMap[item.seriesName.toString().toLocaleLowerCase()] || item.seriesName : item.seriesName;
            return "<br /><span style='display:inline-block;margin-right:5px;border-radius:10px;width:10px;height:10px;background-color:" + item.color + "'></span>" + seriesName + ": " + item.data[1]
          })
          return xAxisName + list.join(' ')
        }
      }
    }

    const self = this;
    const eventName = `call-` + self.getAttribute('id');
    // const defaultSource = [["name", "DEMO", "Other"], ["one", 1, 7], ["two", 2, 3], ["three", 3, 1], ["four", 4, 2], ["five", 5, 4]];
    const myChart = window.echarts.init(this);

    function initChart(source) {
      myChart.clear();
      const series = source[0].slice(1).map(function (item, index) {
        let url;
        if (index % 3 == 0) {
          url = symbol;
        } else if (index % 3 == 1) {
          url = symbol2;
        } else if (index % 3 == 2) {
          url = symbol3;
        }
        const _symbol = symbolType === 'customer' ? "image://" + url : symbolType;
        return Object.assign({}, serieTemp, { name: item, symbol: _symbol });
      });
      const option = {
        title: title,
        tooltip: tooltip,
        legend: legend,
        grid: grid,
        xAxis: xAxis,
        yAxis: yAxis,
        dataset: {
          source: source
        },
        series: series
      };
      if (Boolean(colors)) option.color = colors;

      myChart.setOption(option);
      myChart.resize();

      if (window.prevEventType && window.prevEventType[eventName]) {
        myChart.off(window.prevEventType[eventName]);
      }
      if (clickEvent != 'null') {
        myChart.on(clickEvent, function (params) {
          var _data = params.data;
          if (window.spSocket && clickEvent != 'null') {
            window.spSocket.send({
              eventName: eventName,
              data: {
                success: true,
                out1: JSON.stringify(_data)
              }
            });
          }
        });
        if (!window.prevEventType) {
          window.prevEventType = {};
        }
        window.prevEventType[eventName] = clickEvent;
      }
    }

    initChart(defaultData);

    const loader = $('<div class="loader"><span class="dot"></span><span class="dot"></span><span class="dot"></span><span class="dot"></span><span class="dot"></span></div>')

    window.addEventListener('resize', function () {
      myChart.resize();
    }, false)
    let hasTransfer = false;
    // 有 dashboardHost 说明是运行模式
    if (window.spSocket) {
      $(self).append(loader);

      window.spSocket.subscribe({
        eventName: eventName,
        callback: function (_data) {
          let _in1Str = _data.data.in1;
          if (_in1Str) {
            const source = JSON.parse(_in1Str);
            $(self).children('.loader').remove();
            if (!hasTransfer) {
              initChart(source);
              hasTransfer = true
            } else {
              myChart.setOption({
                dataset: {
                  source: source
                },
                series: source[0].slice(1).map(function () {
                  let url;
                  if (index % 3 == 0) {
                    url = symbol;
                  } else if (index % 3 == 1) {
                    url = symbol2;
                  } else if (index % 3 == 2) {
                    url = symbol3;
                  }
                  const symbol = symbolType === 'customer' ? "image://" + url : symbolType;
                  return Object.assign({}, serieTemp, { name: item, symbol: symbol })
                })
              })
            }
          }
        }
      });
    }

    Boolean(dataSource) && $.get(dataSource, function (ds) {
      myChart.hideLoading();
      initChart(JSON.parse(ds))
    });
  },

  onViewInit() {
    this.updateScript();
    const evn = echartsBasicListen + `
    change:defaultData 
    change:xAxisType 
    change:yAxisType 
    change:axisLabelFontsize 
    change:xAxisName 
    change:xAxisNameLocation 
    change:yAxisName 
    change:yAxisNameLocation
    change:axisNameFontsize
    change:axisColor 
    change:axisLineWidth
    change:xAxisLine 
    change:xAxisSplitLine 
    change:xAxisTick 
    change:xAxisLabel 
    change:yAxisLine 
    change:yAxisSplitLine 
    change:yAxisTick 
    change:yAxisLabel
    change:yAxisInverse 
    change:yAxisLabelAlign 
    change:axisSplitLineColor 
    change:axisSplitLineType 
    change:yAxisOffset 
    change:axisLabelFontFamily 
    change:gridPadding
    change:containLabel
    change:labelPosition 
    change:labelFontFamily 
    change:labelFontsize 
    change:labelDistance 
    change:labelColor 
    change:symbolType 
    change:symbol 
    change:symbol2 
    change:symbol3
    change:symbolSize 
    change:symbolRotate 
    change:symbolRepeat 
    change:symbolMargin 
    change:pointerType 
    change:pointerColor 
    change:clickEvent 
    change:barWidth
    `;
    this.listenTo(this.model, evn, this.updateScript);
    this.listenTo(this.model, evn, this.em.handleUpdates.bind(this.em));
    this.listenTo(this.em, 'update:component:style:height update:component:style:width', throttle.bind(this, this.updateScript.bind(this)));
  }
}
