'use strict';

var path = require('../../../../../zrender@6.0.0/node_modules/zrender/lib/tool/path.js');
var matrix = require('../../../../../zrender@6.0.0/node_modules/zrender/lib/core/matrix.js');
var vector = require('../../../../../zrender@6.0.0/node_modules/zrender/lib/core/vector.js');
var Path = require('../../../../../zrender@6.0.0/node_modules/zrender/lib/graphic/Path.js');
var Transformable = require('../../../../../zrender@6.0.0/node_modules/zrender/lib/core/Transformable.js');
var Image = require('../../../../../zrender@6.0.0/node_modules/zrender/lib/graphic/Image.js');
var Group = require('../../../../../zrender@6.0.0/node_modules/zrender/lib/graphic/Group.js');
var Text = require('../../../../../zrender@6.0.0/node_modules/zrender/lib/graphic/Text.js');
var Circle = require('../../../../../zrender@6.0.0/node_modules/zrender/lib/graphic/shape/Circle.js');
var Ellipse = require('../../../../../zrender@6.0.0/node_modules/zrender/lib/graphic/shape/Ellipse.js');
var Sector = require('../../../../../zrender@6.0.0/node_modules/zrender/lib/graphic/shape/Sector.js');
var Ring = require('../../../../../zrender@6.0.0/node_modules/zrender/lib/graphic/shape/Ring.js');
var Polygon = require('../../../../../zrender@6.0.0/node_modules/zrender/lib/graphic/shape/Polygon.js');
var Polyline = require('../../../../../zrender@6.0.0/node_modules/zrender/lib/graphic/shape/Polyline.js');
var Rect = require('../../../../../zrender@6.0.0/node_modules/zrender/lib/graphic/shape/Rect.js');
var Line = require('../../../../../zrender@6.0.0/node_modules/zrender/lib/graphic/shape/Line.js');
var BezierCurve = require('../../../../../zrender@6.0.0/node_modules/zrender/lib/graphic/shape/BezierCurve.js');
var Arc = require('../../../../../zrender@6.0.0/node_modules/zrender/lib/graphic/shape/Arc.js');
var CompoundPath = require('../../../../../zrender@6.0.0/node_modules/zrender/lib/graphic/CompoundPath.js');
var LinearGradient = require('../../../../../zrender@6.0.0/node_modules/zrender/lib/graphic/LinearGradient.js');
var RadialGradient = require('../../../../../zrender@6.0.0/node_modules/zrender/lib/graphic/RadialGradient.js');
var BoundingRect = require('../../../../../zrender@6.0.0/node_modules/zrender/lib/core/BoundingRect.js');
var OrientedBoundingRect = require('../../../../../zrender@6.0.0/node_modules/zrender/lib/core/OrientedBoundingRect.js');
var Point = require('../../../../../zrender@6.0.0/node_modules/zrender/lib/core/Point.js');
var IncrementalDisplayable = require('../../../../../zrender@6.0.0/node_modules/zrender/lib/graphic/IncrementalDisplayable.js');
var subPixelOptimize$1 = require('../../../../../zrender@6.0.0/node_modules/zrender/lib/graphic/helper/subPixelOptimize.js');
var util = require('../../../../../zrender@6.0.0/node_modules/zrender/lib/core/util.js');
var innerStore = require('./innerStore.js');
var basicTransition = require('../animation/basicTransition.js');
var number = require('./number.js');

var _customShapeMap = {};
var XY = ['x', 'y'];
var WH = ['width', 'height'];
/**
 * Extend shape with parameters
 */
function extendShape(opts) {
  return Path.default.extend(opts);
}
var extendPathFromString = path.extendFromString;
/**
 * Extend path
 */
function extendPath(pathData, opts) {
  return extendPathFromString(pathData, opts);
}
/**
 * Register a user defined shape.
 * The shape class can be fetched by `getShapeClass`
 * This method will overwrite the registered shapes, including
 * the registered built-in shapes, if using the same `name`.
 * The shape can be used in `custom series` and
 * `graphic component` by declaring `{type: name}`.
 *
 * @param name
 * @param ShapeClass Can be generated by `extendShape`.
 */
function registerShape(name, ShapeClass) {
  _customShapeMap[name] = ShapeClass;
}
/**
 * Find shape class registered by `registerShape`. Usually used in
 * fetching user defined shape.
 *
 * [Caution]:
 * (1) This method **MUST NOT be used inside echarts !!!**, unless it is prepared
 * to use user registered shapes.
 * Because the built-in shape (see `getBuiltInShape`) will be registered by
 * `registerShape` by default. That enables users to get both built-in
 * shapes as well as the shapes belonging to themsleves. But users can overwrite
 * the built-in shapes by using names like 'circle', 'rect' via calling
 * `registerShape`. So the echarts inner featrues should not fetch shapes from here
 * in case that it is overwritten by users, except that some features, like
 * `custom series`, `graphic component`, do it deliberately.
 *
 * (2) In the features like `custom series`, `graphic component`, the user input
 * `{tpye: 'xxx'}` does not only specify shapes but also specify other graphic
 * elements like `'group'`, `'text'`, `'image'` or event `'path'`. Those names
 * are reserved names, that is, if some user registers a shape named `'image'`,
 * the shape will not be used. If we intending to add some more reserved names
 * in feature, that might bring break changes (disable some existing user shape
 * names). But that case probably rarely happens. So we don't make more mechanism
 * to resolve this issue here.
 *
 * @param name
 * @return The shape class. If not found, return nothing.
 */
function getShapeClass(name) {
  if (_customShapeMap.hasOwnProperty(name)) {
    return _customShapeMap[name];
  }
}
/**
 * Create a path element from path data string
 * @param pathData
 * @param opts
 * @param rect
 * @param layout 'center' or 'cover' default to be cover
 */
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;
}
/**
 * Create a image element from image url
 * @param imageUrl image url
 * @param opts options
 * @param rect constrain rect
 * @param layout 'center' or 'cover'. Default to be 'cover'
 */
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;
}
/**
 * Get position of centered element in bounding box.
 *
 * @param  rect         element local bounding box
 * @param  boundingRect constraint bounding box
 * @return element position containing x, y, width, and height
 */
function centerGraphic(rect, boundingRect) {
  // Set rect to center, keep width / height ratio.
  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: width,
    height: height
  };
}
var mergePath = path.mergePath;
/**
 * Resize a path to fit the rect
 * @param path
 * @param rect
 */
function resizePath(path, rect) {
  if (!path.applyTransform) {
    return;
  }
  var pathRect = path.getBoundingRect();
  var m = pathRect.calculateTransform(rect);
  path.applyTransform(m);
}
/**
 * Sub pixel optimize line for canvas
 */
function subPixelOptimizeLine(shape, lineWidth) {
  subPixelOptimize$1.subPixelOptimizeLine(shape, shape, {
    lineWidth: lineWidth
  });
  return shape;
}
/**
 * Sub pixel optimize rect for canvas
 */
function subPixelOptimizeRect(shape, style) {
  subPixelOptimize$1.subPixelOptimizeRect(shape, shape, style);
  return shape;
}
/**
 * Sub pixel optimize for canvas
 *
 * @param position Coordinate, such as x, y
 * @param lineWidth Should be nonnegative integer.
 * @param positiveOrNegative Default false (negative).
 * @return Optimized position.
 */
var subPixelOptimize = subPixelOptimize$1.subPixelOptimize;
/**
 * Get transform matrix of target (param target),
 * in coordinate of its ancestor (param ancestor)
 *
 * @param target
 * @param [ancestor]
 */
function getTransform(target, ancestor) {
  var mat = matrix.identity([]);
  while (target && target !== ancestor) {
    matrix.mul(mat, target.getLocalTransform(), mat);
    target = target.parent;
  }
  return mat;
}
/**
 * Apply transform to an vertex.
 * @param target [x, y]
 * @param transform Can be:
 *      + Transform matrix: like [1, 0, 0, 1, 0, 0]
 *      + {position, rotation, scale}, the same as `zrender/Transformable`.
 * @param invert Whether use invert matrix.
 * @return [x, y]
 */
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);
}
/**
 * @param direction 'left' 'right' 'top' 'bottom'
 * @param transform Transform matrix: like [1, 0, 0, 1, 0, 0]
 * @param invert Whether use invert matrix.
 * @return Transformed direction. 'left' 'right' 'top' 'bottom'
 */
function transformDirection(direction, transform, invert) {
  // Pick a base, ensure that transform result will not be (0, 0).
  var hBase = transform[4] === 0 || transform[5] === 0 || transform[0] === 0 ? 1 : number.mathAbs(2 * transform[4] / transform[0]);
  var vBase = transform[4] === 0 || transform[5] === 0 || transform[2] === 0 ? 1 : number.mathAbs(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 number.mathAbs(vertex[0]) > number.mathAbs(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;
}
/**
 * Apply group transition animation from g1 to g2.
 * If no animatableModel, no animation.
 */
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.clone(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) {
  // FIXME: This way might be incorrect when graphic clipped by a corner
  // and when element has a border.
  return util.map(points, function (point) {
    var x = point[0];
    x = number.mathMax(x, rect.x);
    x = number.mathMin(x, rect.x + rect.width);
    var y = point[1];
    y = number.mathMax(y, rect.y);
    y = number.mathMin(y, rect.y + rect.height);
    return [x, y];
  });
}
/**
 * Return a new clipped rect. If rect size are negative, return undefined.
 */
function clipRectByRect(targetRect, rect) {
  var x = number.mathMax(targetRect.x, rect.x);
  var x2 = number.mathMin(targetRect.x + targetRect.width, rect.x + rect.width);
  var y = number.mathMax(targetRect.y, rect.y);
  var y2 = number.mathMin(targetRect.y + targetRect.height, rect.y + rect.height);
  // If the total rect is cliped, nothing, including the border,
  // should be painted. So return undefined.
  if (x2 >= x && y2 >= y) {
    return {
      x: x,
      y: y,
      width: x2 - x,
      height: y2 - y
    };
  }
}
function createIcon(iconStr,
// Support 'image://' or 'path://' or direct svg path.
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');
  }
}
/**
 * Return `true` if the given line (line `a`) and the given polygon
 * are intersect.
 * Note that we do not count colinear as intersect here because no
 * requirement for that. We could do that if required in future.
 */
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;
  }
}
/**
 * Return `true` if the given two lines (line `a` and line `b`)
 * are intersect.
 * Note that we do not count colinear as intersect here because no
 * requirement for that. We could do that if required in future.
 */
function lineLineIntersect(a1x, a1y, a2x, a2y, b1x, b1y, b2x, b2y) {
  // let `vec_m` to be `vec_a2 - vec_a1` and `vec_n` to be `vec_b2 - vec_b1`.
  var mx = a2x - a1x;
  var my = a2y - a1y;
  var nx = b2x - b1x;
  var ny = b2y - b1y;
  // `vec_m` and `vec_n` are parallel iff
  //     existing `k` such that `vec_m = k · vec_n`, equivalent to `vec_m X vec_n = 0`.
  var nmCrossProduct = crossProduct2d(nx, ny, mx, my);
  if (nearZero(nmCrossProduct)) {
    return false;
  }
  // `vec_m` and `vec_n` are intersect iff
  //     existing `p` and `q` in [0, 1] such that `vec_a1 + p * vec_m = vec_b1 + q * vec_n`,
  //     such that `q = ((vec_a1 - vec_b1) X vec_m) / (vec_n X vec_m)`
  //           and `p = ((vec_a1 - vec_b1) X vec_n) / (vec_n X vec_m)`.
  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;
}
/**
 * Cross product of 2-dimension vector.
 */
function crossProduct2d(x1, y1, x2, y2) {
  return x1 * y2 - x2 * y1;
}
function nearZero(val) {
  return val <= 1e-6 && val >= -1e-6;
}
/**
 * NOTE:
 *  A negative-width/height rect (due to negative margins) is not supported;
 *  it will be clampped to zero width/height.
 *  Although negative-width/height rects can be defined reasonably following the
 *  similar sense in CSS, but they are rarely used, hard to understand and complicated.
 *
 * @param rect Assume its width/height >= 0 if existing.
 *  x/y/width/height is allowed to be NaN,
 *  for the case that only x/width or y/height is intended to be computed.
 * @param delta
 *  If be `number[]`, should be `[top, right, bottom, left]`,
 *      which can be used in padding or margin case.
 *      @see `normalizeCssArray` in `util/format.ts`
 *  If be `number`, it means [delta, delta, delta, delta],
 *      which can be used in lineWidth (borderWith) case,
 *      [NOTICE]: commonly pass lineWidth / 2, following the convention that border is
 *      half inside half outside of the rect.
 * @param shrinkOrExpand
 *  `true` - shrink if `delta[i]` is positive, commmonly used in `padding` case.
 *  `false` - expand if `delta[i]` is positive, commmonly used in `margin` case. (default)
 * @param noNegative
 *  `true` - negative `delta[i]` will be clampped to 0.
 *  `false` - No clamp to `delta`. (default).
 * @return The input `rect`.
 */
function expandOrShrinkRect(rect, delta, shrinkOrExpand, noNegative, minSize // by default [0, 0].
) {
  if (delta == null) {
    return rect;
  } else if (util.isNumber(delta)) {
    _tmpExpandRectDelta[0] = _tmpExpandRectDelta[1] = _tmpExpandRectDelta[2] = _tmpExpandRectDelta[3] = delta;
  } else {
    if (process.env.NODE_ENV !== 'production') {
      util.assert(delta.length === 4);
    }
    _tmpExpandRectDelta[0] = delta[0];
    _tmpExpandRectDelta[1] = delta[1];
    _tmpExpandRectDelta[2] = delta[2];
    _tmpExpandRectDelta[3] = delta[3];
  }
  if (noNegative) {
    _tmpExpandRectDelta[0] = number.mathMax(0, _tmpExpandRectDelta[0]);
    _tmpExpandRectDelta[1] = number.mathMax(0, _tmpExpandRectDelta[1]);
    _tmpExpandRectDelta[2] = number.mathMax(0, _tmpExpandRectDelta[2]);
    _tmpExpandRectDelta[3] = number.mathMax(0, _tmpExpandRectDelta[3]);
  }
  if (shrinkOrExpand) {
    _tmpExpandRectDelta[0] = -_tmpExpandRectDelta[0];
    _tmpExpandRectDelta[1] = -_tmpExpandRectDelta[1];
    _tmpExpandRectDelta[2] = -_tmpExpandRectDelta[2];
    _tmpExpandRectDelta[3] = -_tmpExpandRectDelta[3];
  }
  expandRectOnOneDimension(rect, _tmpExpandRectDelta, 'x', 'width', 3, 1, minSize && minSize[0] || 0);
  expandRectOnOneDimension(rect, _tmpExpandRectDelta, 'y', 'height', 0, 2, minSize && minSize[1] || 0);
  return rect;
}
var _tmpExpandRectDelta = [0, 0, 0, 0];
function expandRectOnOneDimension(rect, delta, xy, wh, ltIdx, rbIdx, minSize) {
  var deltaSum = delta[rbIdx] + delta[ltIdx];
  var oldSize = rect[wh];
  rect[wh] += deltaSum;
  minSize = number.mathMax(0, number.mathMin(minSize, oldSize));
  if (rect[wh] < minSize) {
    rect[wh] = minSize;
    // Try to make the position of the zero rect reasonable in most visual cases.
    rect[xy] += delta[ltIdx] >= 0 ? -delta[ltIdx] : delta[rbIdx] >= 0 ? oldSize + delta[rbIdx] : number.mathAbs(deltaSum) > 1e-8 ? (oldSize - minSize) * delta[ltIdx] / deltaSum : 0;
  } else {
    rect[xy] -= delta[ltIdx];
  }
}
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,
      encodeHTMLContent: true,
      formatterParams: formatterParams
    }, itemTooltipOptionObj)
  };
}
function traverseElement(el, cb) {
  var stopped;
  // TODO
  // Polyfill for fixing zrender group traverse don't visit it's root issue.
  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);
    }
  }
}
/**
 * After a boundingRect applying a `transform`, whether to be still parallel screen X and Y.
 */
function isBoundingRectAxisAligned(transform) {
  return !transform || number.mathAbs(transform[1]) < AXIS_ALIGN_EPSILON && number.mathAbs(transform[2]) < AXIS_ALIGN_EPSILON || number.mathAbs(transform[0]) < AXIS_ALIGN_EPSILON && number.mathAbs(transform[3]) < AXIS_ALIGN_EPSILON;
}
var AXIS_ALIGN_EPSILON = 1e-5;
/**
 * Create or copy to the existing bounding rect to avoid modifying `source`.
 *
 * @usage
 *  out.rect = ensureCopyRect(out.rect, sourceRect);
 */
function ensureCopyRect(target, source) {
  return target ? BoundingRect.default.copy(target, source) : source.clone();
}
/**
 * Create or copy to the existing transform to avoid modifying `source`.
 *
 * [CAUTION]: transform is `NullUndefined` if no transform, following convention of zrender,
 *  and enable to bypass some unnecessary calculation, since in most cases there is no transform.
 *
 * @usage
 *  out.transform = ensureCopyTransform(out.transform, sourceTransform);
 */
function ensureCopyTransform(target, source) {
  return source ? matrix.copy(target || matrix.create(), source) : undefined;
}
function retrieveZInfo(model) {
  return {
    z: model.get('z') || 0,
    zlevel: model.get('zlevel') || 0
  };
}
/**
 * Assume all of the elements has the same `z` and `zlevel`.
 */
function calcZ2Range(el) {
  var max = -Infinity;
  var min = Infinity;
  traverseElement(el, function (el) {
    visitEl(el);
    visitEl(el.getTextContent());
    visitEl(el.getTextGuideLine());
  });
  function visitEl(el) {
    if (!el || el.isGroup) {
      return;
    }
    var currentStates = el.currentStates;
    if (currentStates.length) {
      for (var idx = 0; idx < currentStates.length; idx++) {
        calcZ2(el.states[currentStates[idx]]);
      }
    }
    calcZ2(el);
  }
  function calcZ2(entity) {
    if (entity) {
      var z2 = entity.z2;
      // Consider z2 may be NullUndefined
      if (z2 > max) {
        max = z2;
      }
      if (z2 < min) {
        min = z2;
      }
    }
  }
  if (min > max) {
    min = max = 0;
  }
  return {
    min: min,
    max: max
  };
}
function traverseUpdateZ(el, z, zlevel) {
  doUpdateZ(el, z, zlevel, -Infinity);
}
function doUpdateZ(el, z, zlevel,
// FIXME: Ideally all the labels should be above all the glyphs by default,
//  e.g. in graph, edge labels should be above node elements.
//  Currently impl does not guarantee that.
maxZ2) {
  // `ignoreModelZ` is used to intentionally lift elements to cover other elements,
  // where maxZ2 (for label.z2) should also not be counted for its parents.
  if (el.ignoreModelZ) {
    return maxZ2;
  }
  // Group may also have textContent
  var label = el.getTextContent();
  var labelLine = el.getTextGuideLine();
  var isGroup = el.isGroup;
  if (isGroup) {
    // set z & zlevel of children elements of Group
    var children = el.childrenRef();
    for (var i = 0; i < children.length; i++) {
      maxZ2 = number.mathMax(doUpdateZ(children[i], z, zlevel, maxZ2), maxZ2);
    }
  } else {
    // not Group
    el.z = z;
    el.zlevel = zlevel;
    maxZ2 = number.mathMax(el.z2 || 0, maxZ2);
  }
  // always set z and zlevel if label/labelLine exists
  if (label) {
    label.z = z;
    label.zlevel = zlevel;
    // lift z2 of text content
    // TODO if el.emphasis.z2 is spcefied, what about textContent.
    isFinite(maxZ2) && (label.z2 = maxZ2 + 2);
  }
  if (labelLine) {
    var textGuideLineConfig = el.textGuideLineConfig;
    labelLine.z = z;
    labelLine.zlevel = zlevel;
    isFinite(maxZ2) && (labelLine.z2 = maxZ2 + (textGuideLineConfig && textGuideLineConfig.showAbove ? 1 : -1));
  }
  return maxZ2;
}
// Register built-in shapes. These shapes might be overwritten
// by users, although we do not recommend that.
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.WH = WH;
exports.XY = XY;
exports.applyTransform = applyTransform;
exports.calcZ2Range = calcZ2Range;
exports.clipPointsByRect = clipPointsByRect;
exports.clipRectByRect = clipRectByRect;
exports.createIcon = createIcon;
exports.ensureCopyRect = ensureCopyRect;
exports.ensureCopyTransform = ensureCopyTransform;
exports.expandOrShrinkRect = expandOrShrinkRect;
exports.extendPath = extendPath;
exports.extendShape = extendShape;
exports.getShapeClass = getShapeClass;
exports.getTransform = getTransform;
exports.groupTransition = groupTransition;
exports.isBoundingRectAxisAligned = isBoundingRectAxisAligned;
exports.lineLineIntersect = lineLineIntersect;
exports.linePolygonIntersect = linePolygonIntersect;
exports.makeImage = makeImage;
exports.makePath = makePath;
exports.mergePath = mergePath;
exports.registerShape = registerShape;
exports.resizePath = resizePath;
exports.retrieveZInfo = retrieveZInfo;
exports.setTooltipConfig = setTooltipConfig;
exports.subPixelOptimize = subPixelOptimize;
exports.subPixelOptimizeLine = subPixelOptimizeLine;
exports.subPixelOptimizeRect = subPixelOptimizeRect;
exports.transformDirection = transformDirection;
exports.traverseElements = traverseElements;
exports.traverseUpdateZ = traverseUpdateZ;
