"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const path = require("../../../../../zrender@5.4.4/node_modules/zrender/lib/tool/path.js");
const matrix = require("../../../../../zrender@5.4.4/node_modules/zrender/lib/core/matrix.js");
const vector = require("../../../../../zrender@5.4.4/node_modules/zrender/lib/core/vector.js");
const Path = require("../../../../../zrender@5.4.4/node_modules/zrender/lib/graphic/Path.js");
const Transformable = require("../../../../../zrender@5.4.4/node_modules/zrender/lib/core/Transformable.js");
const Image = require("../../../../../zrender@5.4.4/node_modules/zrender/lib/graphic/Image.js");
const Group = require("../../../../../zrender@5.4.4/node_modules/zrender/lib/graphic/Group.js");
const Text = require("../../../../../zrender@5.4.4/node_modules/zrender/lib/graphic/Text.js");
const Circle = require("../../../../../zrender@5.4.4/node_modules/zrender/lib/graphic/shape/Circle.js");
const Ellipse = require("../../../../../zrender@5.4.4/node_modules/zrender/lib/graphic/shape/Ellipse.js");
const Sector = require("../../../../../zrender@5.4.4/node_modules/zrender/lib/graphic/shape/Sector.js");
const Ring = require("../../../../../zrender@5.4.4/node_modules/zrender/lib/graphic/shape/Ring.js");
const Polygon = require("../../../../../zrender@5.4.4/node_modules/zrender/lib/graphic/shape/Polygon.js");
const Polyline = require("../../../../../zrender@5.4.4/node_modules/zrender/lib/graphic/shape/Polyline.js");
const Rect = require("../../../../../zrender@5.4.4/node_modules/zrender/lib/graphic/shape/Rect.js");
const Line = require("../../../../../zrender@5.4.4/node_modules/zrender/lib/graphic/shape/Line.js");
const BezierCurve = require("../../../../../zrender@5.4.4/node_modules/zrender/lib/graphic/shape/BezierCurve.js");
const Arc = require("../../../../../zrender@5.4.4/node_modules/zrender/lib/graphic/shape/Arc.js");
const CompoundPath = require("../../../../../zrender@5.4.4/node_modules/zrender/lib/graphic/CompoundPath.js");
const LinearGradient = require("../../../../../zrender@5.4.4/node_modules/zrender/lib/graphic/LinearGradient.js");
const RadialGradient = require("../../../../../zrender@5.4.4/node_modules/zrender/lib/graphic/RadialGradient.js");
const BoundingRect = require("../../../../../zrender@5.4.4/node_modules/zrender/lib/core/BoundingRect.js");
const OrientedBoundingRect = require("../../../../../zrender@5.4.4/node_modules/zrender/lib/core/OrientedBoundingRect.js");
const Point = require("../../../../../zrender@5.4.4/node_modules/zrender/lib/core/Point.js");
const IncrementalDisplayable = require("../../../../../zrender@5.4.4/node_modules/zrender/lib/graphic/IncrementalDisplayable.js");
const subPixelOptimize$1 = require("../../../../../zrender@5.4.4/node_modules/zrender/lib/graphic/helper/subPixelOptimize.js");
const util = require("../../../../../zrender@5.4.4/node_modules/zrender/lib/core/util.js");
const innerStore = require("./innerStore.js");
const basicTransition = require("../animation/basicTransition.js");
var mathMax = Math.max;
var mathMin = Math.min;
var _customShapeMap = {};
function extendShape(opts) {
  return Path.default.extend(opts);
}
var extendPathFromString = path.extendFromString;
function extendPath(pathData, opts) {
  return extendPathFromString(pathData, opts);
}
function registerShape(name, ShapeClass) {
  _customShapeMap[name] = ShapeClass;
}
function getShapeClass(name) {
  if (_customShapeMap.hasOwnProperty(name)) {
    return _customShapeMap[name];
  }
}
function makePath(pathData, opts, rect, layout) {
  var path$1 = path.createFromString(pathData, opts);
  if (rect) {
    if (layout === "center") {
      rect = centerGraphic(rect, path$1.getBoundingRect());
    }
    resizePath(path$1, rect);
  }
  return path$1;
}
function makeImage(imageUrl, rect, layout) {
  var zrImg = new Image.default({
    style: {
      image: imageUrl,
      x: rect.x,
      y: rect.y,
      width: rect.width,
      height: rect.height
    },
    onload: function(img) {
      if (layout === "center") {
        var boundingRect = {
          width: img.width,
          height: img.height
        };
        zrImg.setStyle(centerGraphic(rect, boundingRect));
      }
    }
  });
  return zrImg;
}
function centerGraphic(rect, boundingRect) {
  var aspect = boundingRect.width / boundingRect.height;
  var width = rect.height * aspect;
  var height;
  if (width <= rect.width) {
    height = rect.height;
  } else {
    width = rect.width;
    height = width / aspect;
  }
  var cx = rect.x + rect.width / 2;
  var cy = rect.y + rect.height / 2;
  return {
    x: cx - width / 2,
    y: cy - height / 2,
    width,
    height
  };
}
var mergePath = path.mergePath;
function resizePath(path2, rect) {
  if (!path2.applyTransform) {
    return;
  }
  var pathRect = path2.getBoundingRect();
  var m = pathRect.calculateTransform(rect);
  path2.applyTransform(m);
}
function subPixelOptimizeLine(shape, lineWidth) {
  subPixelOptimize$1.subPixelOptimizeLine(shape, shape, {
    lineWidth
  });
  return shape;
}
function subPixelOptimizeRect(param) {
  subPixelOptimize$1.subPixelOptimizeRect(param.shape, param.shape, param.style);
  return param;
}
var subPixelOptimize = subPixelOptimize$1.subPixelOptimize;
function getTransform(target, ancestor) {
  var mat = matrix.identity([]);
  while (target && target !== ancestor) {
    matrix.mul(mat, target.getLocalTransform(), mat);
    target = target.parent;
  }
  return mat;
}
function applyTransform(target, transform, invert) {
  if (transform && !util.isArrayLike(transform)) {
    transform = Transformable.default.getLocalTransform(transform);
  }
  if (invert) {
    transform = matrix.invert([], transform);
  }
  return vector.applyTransform([], target, transform);
}
function transformDirection(direction, transform, invert) {
  var hBase = transform[4] === 0 || transform[5] === 0 || transform[0] === 0 ? 1 : Math.abs(2 * transform[4] / transform[0]);
  var vBase = transform[4] === 0 || transform[5] === 0 || transform[2] === 0 ? 1 : Math.abs(2 * transform[4] / transform[2]);
  var vertex = [direction === "left" ? -hBase : direction === "right" ? hBase : 0, direction === "top" ? -vBase : direction === "bottom" ? vBase : 0];
  vertex = applyTransform(vertex, transform, invert);
  return Math.abs(vertex[0]) > Math.abs(vertex[1]) ? vertex[0] > 0 ? "right" : "left" : vertex[1] > 0 ? "bottom" : "top";
}
function isNotGroup(el) {
  return !el.isGroup;
}
function isPath(el) {
  return el.shape != null;
}
function groupTransition(g1, g2, animatableModel) {
  if (!g1 || !g2) {
    return;
  }
  function getElMap(g) {
    var elMap = {};
    g.traverse(function(el) {
      if (isNotGroup(el) && el.anid) {
        elMap[el.anid] = el;
      }
    });
    return elMap;
  }
  function getAnimatableProps(el) {
    var obj = {
      x: el.x,
      y: el.y,
      rotation: el.rotation
    };
    if (isPath(el)) {
      obj.shape = util.extend({}, el.shape);
    }
    return obj;
  }
  var elMap1 = getElMap(g1);
  g2.traverse(function(el) {
    if (isNotGroup(el) && el.anid) {
      var oldEl = elMap1[el.anid];
      if (oldEl) {
        var newProp = getAnimatableProps(el);
        el.attr(getAnimatableProps(oldEl));
        basicTransition.updateProps(el, newProp, animatableModel, innerStore.getECData(el).dataIndex);
      }
    }
  });
}
function clipPointsByRect(points, rect) {
  return util.map(points, function(point) {
    var x = point[0];
    x = mathMax(x, rect.x);
    x = mathMin(x, rect.x + rect.width);
    var y = point[1];
    y = mathMax(y, rect.y);
    y = mathMin(y, rect.y + rect.height);
    return [x, y];
  });
}
function clipRectByRect(targetRect, rect) {
  var x = mathMax(targetRect.x, rect.x);
  var x2 = mathMin(targetRect.x + targetRect.width, rect.x + rect.width);
  var y = mathMax(targetRect.y, rect.y);
  var y2 = mathMin(targetRect.y + targetRect.height, rect.y + rect.height);
  if (x2 >= x && y2 >= y) {
    return {
      x,
      y,
      width: x2 - x,
      height: y2 - y
    };
  }
}
function createIcon(iconStr, opt, rect) {
  var innerOpts = util.extend({
    rectHover: true
  }, opt);
  var style = innerOpts.style = {
    strokeNoScale: true
  };
  rect = rect || {
    x: -1,
    y: -1,
    width: 2,
    height: 2
  };
  if (iconStr) {
    return iconStr.indexOf("image://") === 0 ? (style.image = iconStr.slice(8), util.defaults(style, rect), new Image.default(innerOpts)) : makePath(iconStr.replace("path://", ""), innerOpts, rect, "center");
  }
}
function linePolygonIntersect(a1x, a1y, a2x, a2y, points) {
  for (var i = 0, p2 = points[points.length - 1]; i < points.length; i++) {
    var p = points[i];
    if (lineLineIntersect(a1x, a1y, a2x, a2y, p[0], p[1], p2[0], p2[1])) {
      return true;
    }
    p2 = p;
  }
}
function lineLineIntersect(a1x, a1y, a2x, a2y, b1x, b1y, b2x, b2y) {
  var mx = a2x - a1x;
  var my = a2y - a1y;
  var nx = b2x - b1x;
  var ny = b2y - b1y;
  var nmCrossProduct = crossProduct2d(nx, ny, mx, my);
  if (nearZero(nmCrossProduct)) {
    return false;
  }
  var b1a1x = a1x - b1x;
  var b1a1y = a1y - b1y;
  var q = crossProduct2d(b1a1x, b1a1y, mx, my) / nmCrossProduct;
  if (q < 0 || q > 1) {
    return false;
  }
  var p = crossProduct2d(b1a1x, b1a1y, nx, ny) / nmCrossProduct;
  if (p < 0 || p > 1) {
    return false;
  }
  return true;
}
function crossProduct2d(x1, y1, x2, y2) {
  return x1 * y2 - x2 * y1;
}
function nearZero(val) {
  return val <= 1e-6 && val >= -1e-6;
}
function setTooltipConfig(opt) {
  var itemTooltipOption = opt.itemTooltipOption;
  var componentModel = opt.componentModel;
  var itemName = opt.itemName;
  var itemTooltipOptionObj = util.isString(itemTooltipOption) ? {
    formatter: itemTooltipOption
  } : itemTooltipOption;
  var mainType = componentModel.mainType;
  var componentIndex = componentModel.componentIndex;
  var formatterParams = {
    componentType: mainType,
    name: itemName,
    $vars: ["name"]
  };
  formatterParams[mainType + "Index"] = componentIndex;
  var formatterParamsExtra = opt.formatterParamsExtra;
  if (formatterParamsExtra) {
    util.each(util.keys(formatterParamsExtra), function(key) {
      if (!util.hasOwn(formatterParams, key)) {
        formatterParams[key] = formatterParamsExtra[key];
        formatterParams.$vars.push(key);
      }
    });
  }
  var ecData = innerStore.getECData(opt.el);
  ecData.componentMainType = mainType;
  ecData.componentIndex = componentIndex;
  ecData.tooltipConfig = {
    name: itemName,
    option: util.defaults({
      content: itemName,
      formatterParams
    }, itemTooltipOptionObj)
  };
}
function traverseElement(el, cb) {
  var stopped;
  if (el.isGroup) {
    stopped = cb(el);
  }
  if (!stopped) {
    el.traverse(cb);
  }
}
function traverseElements(els, cb) {
  if (els) {
    if (util.isArray(els)) {
      for (var i = 0; i < els.length; i++) {
        traverseElement(els[i], cb);
      }
    } else {
      traverseElement(els, cb);
    }
  }
}
registerShape("circle", Circle.default);
registerShape("ellipse", Ellipse.default);
registerShape("sector", Sector.default);
registerShape("ring", Ring.default);
registerShape("polygon", Polygon.default);
registerShape("polyline", Polyline.default);
registerShape("rect", Rect.default);
registerShape("line", Line.default);
registerShape("bezierCurve", BezierCurve.default);
registerShape("arc", Arc.default);
exports.Path = Path.default;
exports.Image = Image.default;
exports.Group = Group.default;
exports.Text = Text.default;
exports.Circle = Circle.default;
exports.Ellipse = Ellipse.default;
exports.Sector = Sector.default;
exports.Ring = Ring.default;
exports.Polygon = Polygon.default;
exports.Polyline = Polyline.default;
exports.Rect = Rect.default;
exports.Line = Line.default;
exports.BezierCurve = BezierCurve.default;
exports.Arc = Arc.default;
exports.CompoundPath = CompoundPath.default;
exports.LinearGradient = LinearGradient.default;
exports.RadialGradient = RadialGradient.default;
exports.BoundingRect = BoundingRect.default;
exports.OrientedBoundingRect = OrientedBoundingRect.default;
exports.Point = Point.default;
exports.IncrementalDisplayable = IncrementalDisplayable.default;
exports.initProps = basicTransition.initProps;
exports.isElementRemoved = basicTransition.isElementRemoved;
exports.removeElement = basicTransition.removeElement;
exports.removeElementWithFadeOut = basicTransition.removeElementWithFadeOut;
exports.updateProps = basicTransition.updateProps;
exports.applyTransform = applyTransform;
exports.clipPointsByRect = clipPointsByRect;
exports.clipRectByRect = clipRectByRect;
exports.createIcon = createIcon;
exports.extendPath = extendPath;
exports.extendShape = extendShape;
exports.getShapeClass = getShapeClass;
exports.getTransform = getTransform;
exports.groupTransition = groupTransition;
exports.lineLineIntersect = lineLineIntersect;
exports.linePolygonIntersect = linePolygonIntersect;
exports.makeImage = makeImage;
exports.makePath = makePath;
exports.mergePath = mergePath;
exports.registerShape = registerShape;
exports.resizePath = resizePath;
exports.setTooltipConfig = setTooltipConfig;
exports.subPixelOptimize = subPixelOptimize;
exports.subPixelOptimizeLine = subPixelOptimizeLine;
exports.subPixelOptimizeRect = subPixelOptimizeRect;
exports.transformDirection = transformDirection;
exports.traverseElements = traverseElements;
