UNPKG

cione-comp-lib

Version:

`$ yarn add cione-comp-lib` 或者 `$ npm i cione-comp-lib -S`

341 lines (340 loc) 11.9 kB
import { createFromString, mergePath as mergePath$1, extendFromString } from "../../../zrender/lib/tool/path.mjs"; import { identity, mul, invert } from "../../../zrender/lib/core/matrix.mjs"; import { applyTransform as applyTransform$1 } from "../../../zrender/lib/core/vector.mjs"; import Path from "../../../zrender/lib/graphic/Path.mjs"; export { default as Path } from "../../../zrender/lib/graphic/Path.mjs"; import Transformable from "../../../zrender/lib/core/Transformable.mjs"; import ZRImage from "../../../zrender/lib/graphic/Image.mjs"; export { default as Image } from "../../../zrender/lib/graphic/Image.mjs"; export { default as Group } from "../../../zrender/lib/graphic/Group.mjs"; export { default as Text } from "../../../zrender/lib/graphic/Text.mjs"; import Circle from "../../../zrender/lib/graphic/shape/Circle.mjs"; export { default as Circle } from "../../../zrender/lib/graphic/shape/Circle.mjs"; import Ellipse from "../../../zrender/lib/graphic/shape/Ellipse.mjs"; export { default as Ellipse } from "../../../zrender/lib/graphic/shape/Ellipse.mjs"; import Sector from "../../../zrender/lib/graphic/shape/Sector.mjs"; export { default as Sector } from "../../../zrender/lib/graphic/shape/Sector.mjs"; import Ring from "../../../zrender/lib/graphic/shape/Ring.mjs"; export { default as Ring } from "../../../zrender/lib/graphic/shape/Ring.mjs"; import Polygon from "../../../zrender/lib/graphic/shape/Polygon.mjs"; export { default as Polygon } from "../../../zrender/lib/graphic/shape/Polygon.mjs"; import Polyline from "../../../zrender/lib/graphic/shape/Polyline.mjs"; export { default as Polyline } from "../../../zrender/lib/graphic/shape/Polyline.mjs"; import Rect from "../../../zrender/lib/graphic/shape/Rect.mjs"; export { default as Rect } from "../../../zrender/lib/graphic/shape/Rect.mjs"; import Line from "../../../zrender/lib/graphic/shape/Line.mjs"; export { default as Line } from "../../../zrender/lib/graphic/shape/Line.mjs"; import BezierCurve from "../../../zrender/lib/graphic/shape/BezierCurve.mjs"; export { default as BezierCurve } from "../../../zrender/lib/graphic/shape/BezierCurve.mjs"; import Arc from "../../../zrender/lib/graphic/shape/Arc.mjs"; export { default as Arc } from "../../../zrender/lib/graphic/shape/Arc.mjs"; export { default as CompoundPath } from "../../../zrender/lib/graphic/CompoundPath.mjs"; export { default as LinearGradient } from "../../../zrender/lib/graphic/LinearGradient.mjs"; export { default as RadialGradient } from "../../../zrender/lib/graphic/RadialGradient.mjs"; export { default as BoundingRect } from "../../../zrender/lib/core/BoundingRect.mjs"; export { default as OrientedBoundingRect } from "../../../zrender/lib/core/OrientedBoundingRect.mjs"; export { default as Point } from "../../../zrender/lib/core/Point.mjs"; export { default as IncrementalDisplayable } from "../../../zrender/lib/graphic/IncrementalDisplayable.mjs"; import { subPixelOptimizeLine as subPixelOptimizeLine$1, subPixelOptimizeRect as subPixelOptimizeRect$1, subPixelOptimize as subPixelOptimize$1 } from "../../../zrender/lib/graphic/helper/subPixelOptimize.mjs"; import { map, extend, defaults, isArray, isArrayLike, each, hasOwn, keys, isString } from "../../../zrender/lib/core/util.mjs"; import { getECData } from "./innerStore.mjs"; import { updateProps } from "../animation/basicTransition.mjs"; export { initProps, isElementRemoved, removeElement, removeElementWithFadeOut, updateProps } from "../animation/basicTransition.mjs"; var mathMax = Math.max; var mathMin = Math.min; var _customShapeMap = {}; function extendShape(opts) { return Path.extend(opts); } var extendPathFromString = 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 = createFromString(pathData, opts); if (rect) { if (layout === "center") { rect = centerGraphic(rect, path.getBoundingRect()); } resizePath(path, rect); } return path; } function makeImage(imageUrl, rect, layout) { var zrImg = new ZRImage({ 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 = mergePath$1; function resizePath(path, rect) { if (!path.applyTransform) { return; } var pathRect = path.getBoundingRect(); var m = pathRect.calculateTransform(rect); path.applyTransform(m); } function subPixelOptimizeLine(shape, lineWidth) { subPixelOptimizeLine$1(shape, shape, { lineWidth }); return shape; } function subPixelOptimizeRect(param) { subPixelOptimizeRect$1(param.shape, param.shape, param.style); return param; } var subPixelOptimize = subPixelOptimize$1; function getTransform(target, ancestor) { var mat = identity([]); while (target && target !== ancestor) { mul(mat, target.getLocalTransform(), mat); target = target.parent; } return mat; } function applyTransform(target, transform, invert$1) { if (transform && !isArrayLike(transform)) { transform = Transformable.getLocalTransform(transform); } if (invert$1) { transform = invert([], transform); } return applyTransform$1([], target, transform); } function transformDirection(direction, transform, invert2) { 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, invert2); 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 = 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)); updateProps(el, newProp, animatableModel, getECData(el).dataIndex); } } }); } function clipPointsByRect(points, rect) { return 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 = 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), defaults(style, rect), new ZRImage(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 = 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) { each(keys(formatterParamsExtra), function(key) { if (!hasOwn(formatterParams, key)) { formatterParams[key] = formatterParamsExtra[key]; formatterParams.$vars.push(key); } }); } var ecData = getECData(opt.el); ecData.componentMainType = mainType; ecData.componentIndex = componentIndex; ecData.tooltipConfig = { name: itemName, option: 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 (isArray(els)) { for (var i = 0; i < els.length; i++) { traverseElement(els[i], cb); } } else { traverseElement(els, cb); } } } registerShape("circle", Circle); registerShape("ellipse", Ellipse); registerShape("sector", Sector); registerShape("ring", Ring); registerShape("polygon", Polygon); registerShape("polyline", Polyline); registerShape("rect", Rect); registerShape("line", Line); registerShape("bezierCurve", BezierCurve); registerShape("arc", Arc); export { applyTransform, clipPointsByRect, clipRectByRect, createIcon, extendPath, extendShape, getShapeClass, getTransform, groupTransition, lineLineIntersect, linePolygonIntersect, makeImage, makePath, mergePath, registerShape, resizePath, setTooltipConfig, subPixelOptimize, subPixelOptimizeLine, subPixelOptimizeRect, transformDirection, traverseElements };