/**
 * 
 *     @dfsj/echarts： 专业的水文曲线组件或构造函数以及通用的echart二次封装图表
 *     版本: v3.7.0
 *     作者：yangbo <1747837358@qq.com>
 *     日期：2025-05-27 15:53:33
 *     
 *     
 */

import _classCallCheck from '@babel/runtime/helpers/classCallCheck';
import _createClass from '@babel/runtime/helpers/createClass';
import * as echarts from 'echarts';
import { parsePercent } from '../utils.js';
import assign from '../../utils/assign.js';

var Factory = /*#__PURE__*/function () {
  function Factory() {
    _classCallCheck(this, Factory);
  }
  return _createClass(Factory, null, [{
    key: "symbol",
    value: function symbol(model, sys, finder) {
      var value = model.get('value');
      var axis = model.get('yAxisIndex');
      var style = model.get('itemStyle');
      var rect = sys.getRect();
      var x = axis % 2 === 0 ? rect.x : rect.width;
      var y = sys.convertToPixel(null, finder, [0, value])[1];
      var oSymbol = model.get('itemStyle.offset') || [0, 0];
      if (y <= rect.y + rect.height && y >= rect.y) {
        var group = new echarts.graphic.Group();
        group.add(echarts.graphic.makePath(model.get('symbol'), assign({
          z2: 10,
          x: x + oSymbol[0],
          y: y + oSymbol[1],
          scale: style.scale
        }, {
          style: style
        }), undefined));
        var label = model.get('label');
        var oLabel = model.get('label.offset') || [0, 0];
        group.add(new echarts.graphic.Text(assign({
          z2: 10,
          x: x + oLabel[0],
          y: y + oLabel[1]
        }, {
          style: label
        })));
        return group;
      }
    }
  }, {
    key: "index",
    value: function index(model, sys, finder, api) {
      var value = model.get('value');
      var axis = model.get('yAxisIndex');
      var rect = sys.getRect();
      var y = sys.convertToPixel(null, finder, [0, value])[1];
      if (y <= rect.y + rect.height && y >= rect.y) {
        var _model$get, _$indices$findIndex;
        var group = new echarts.graphic.Group();
        group.add(new echarts.graphic.Line(assign({
          z2: 10,
          shape: {
            x1: rect.x,
            y1: y,
            x2: rect.x + rect.width,
            y2: y
          }
        }, {
          style: model.get('lineStyle')
        })));
        var _index = 0;
        var label = model.get("label");
        var offset = model.get("label.offset");
        var width = (_model$get = model.get("label.width")) !== null && _model$get !== void 0 ? _model$get : 135;
        var x = axis % 2 === 0 ? rect.x : rect.width + rect.x;
        var d = axis % 2 === 0 ? 1 : -1;
        var series = model.ecModel.get("series");
        var name = model.get('name');
        var $indices = series === null || series === void 0 ? void 0 : series.filter(function (s) {
          return (s === null || s === void 0 ? void 0 : s.type) == 'mark';
        });
        _index = (_$indices$findIndex = $indices.findIndex(function (s) {
          return s.name == name;
        })) !== null && _$indices$findIndex !== void 0 ? _$indices$findIndex : 0;
        var offsetX = x + offset[0] + _index * width * d;
        var offsetY = y + offset[1];
        group.add(new echarts.graphic.Text(assign({
          z2: 10,
          x: offsetX,
          y: offsetY
        }, {
          style: label
        })));
        return group;
      }
    }
  }, {
    key: "rect",
    value: function rect(model, sys, finder, api) {
      var value = model.get('value');
      var x1 = sys.convertToPixel(null, finder, [value[0], 0])[0];
      var x2 = sys.convertToPixel(null, finder, [value[1], 0])[0];
      var rect = sys.getRect();
      var style = model.get('itemStyle');
      var shape = echarts.graphic.clipRectByRect({
        x: x1,
        y: rect.y,
        width: x2 - x1,
        height: rect.height
      }, rect);
      return shape && new echarts.graphic.Rect(assign({
        shape: shape
      }, {
        style: style
      }));
    }
  }, {
    key: "line",
    value: function line(model, sys, finder) {
      var value = model.get('value');
      var rect = sys.getRect();
      var x = sys.convertToPixel(null, finder, [value, 0])[0];
      if (x >= rect.x && x <= rect.x + rect.width) {
        var group = new echarts.graphic.Group();
        group.add(new echarts.graphic.Line(assign({
          z2: 1,
          shape: {
            x1: x,
            y1: rect.y,
            x2: x,
            y2: rect.y + rect.height
          }
        }, {
          style: model.get('itemStyle')
        })));
        var label = model.get('label');
        var offset = model.get('label.offset') || [0, 0];
        group.add(new echarts.graphic.Text(assign({
          x: x + parsePercent(offset[0], rect.width),
          y: rect.y + parsePercent(offset[1], rect.height)
        }, {
          style: label
        })));
        return group;
      }
    }
  }, {
    key: "text",
    value: function text(model, sys, finder) {
      console.log('0---------------/////--------------------------');
      var value = model.get('value');
      var x = sys.convertToPixel(null, finder, [value, 0])[0];
      var rect = sys.getRect();
      if (x >= rect.x && x <= rect.x + rect.width) {
        var label = model.get('label');
        var offset = model.get('label.offset') || [0, 0];
        return new echarts.graphic.Text(assign({
          position: [x + parsePercent(offset[0], rect.width), rect.y + parsePercent(offset[1], rect.height)]
        }, {
          style: label
        }));
      }
    }
  }]);
}();

export { Factory as default };
