echarts_renderers.js 77 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495
  1. import {
  2. BoundingRect_default,
  3. CompoundPath_default,
  4. DEFAULT_FONT,
  5. DEFAULT_FONT_FAMILY,
  6. DEFAULT_PATH_STYLE,
  7. Eventful_default,
  8. Image_default,
  9. PathProxy_default,
  10. Path_default,
  11. REDRAW_BIT,
  12. TEXT_ALIGN_TO_ANCHOR,
  13. TSpan_default,
  14. __extends,
  15. adjustTextY,
  16. assert,
  17. brush,
  18. brushSingle,
  19. clone,
  20. copyTransform,
  21. createCanvasPattern,
  22. createCubicEasingFunc,
  23. createOrUpdateImage,
  24. devicePixelRatio,
  25. disableUserSelect,
  26. each,
  27. encodeBase64,
  28. encodeHTML,
  29. env_default,
  30. extend,
  31. filter,
  32. getCanvasGradient,
  33. getElementSSRData,
  34. getIdURL,
  35. getLineDash,
  36. getLineHeight,
  37. getMatrixStr,
  38. getPathPrecision,
  39. getSRTTransformString,
  40. getShadowKey,
  41. getSize,
  42. hasSeparateFont,
  43. hasShadow,
  44. indexOf,
  45. isAroundZero,
  46. isArray,
  47. isFunction,
  48. isGradient,
  49. isGradientObject,
  50. isImagePattern,
  51. isImagePatternObject,
  52. isLinearGradient,
  53. isNumber,
  54. isObject,
  55. isPattern,
  56. isRadialGradient,
  57. isString,
  58. keys,
  59. liftColor,
  60. logError,
  61. map,
  62. merge,
  63. noop,
  64. normalizeColor,
  65. parseFontSize,
  66. platformApi,
  67. requestAnimationFrame_default,
  68. retrieve2,
  69. round4
  70. } from "./chunk-7YIZLZUW.js";
  71. import "./chunk-HM4MQYWN.js";
  72. // node_modules/zrender/lib/svg/SVGPathRebuilder.js
  73. var mathSin = Math.sin;
  74. var mathCos = Math.cos;
  75. var PI = Math.PI;
  76. var PI2 = Math.PI * 2;
  77. var degree = 180 / PI;
  78. var SVGPathRebuilder = function() {
  79. function SVGPathRebuilder2() {
  80. }
  81. SVGPathRebuilder2.prototype.reset = function(precision) {
  82. this._start = true;
  83. this._d = [];
  84. this._str = "";
  85. this._p = Math.pow(10, precision || 4);
  86. };
  87. SVGPathRebuilder2.prototype.moveTo = function(x, y) {
  88. this._add("M", x, y);
  89. };
  90. SVGPathRebuilder2.prototype.lineTo = function(x, y) {
  91. this._add("L", x, y);
  92. };
  93. SVGPathRebuilder2.prototype.bezierCurveTo = function(x, y, x2, y2, x3, y3) {
  94. this._add("C", x, y, x2, y2, x3, y3);
  95. };
  96. SVGPathRebuilder2.prototype.quadraticCurveTo = function(x, y, x2, y2) {
  97. this._add("Q", x, y, x2, y2);
  98. };
  99. SVGPathRebuilder2.prototype.arc = function(cx, cy, r, startAngle, endAngle, anticlockwise) {
  100. this.ellipse(cx, cy, r, r, 0, startAngle, endAngle, anticlockwise);
  101. };
  102. SVGPathRebuilder2.prototype.ellipse = function(cx, cy, rx, ry, psi, startAngle, endAngle, anticlockwise) {
  103. var dTheta = endAngle - startAngle;
  104. var clockwise = !anticlockwise;
  105. var dThetaPositive = Math.abs(dTheta);
  106. var isCircle = isAroundZero(dThetaPositive - PI2) || (clockwise ? dTheta >= PI2 : -dTheta >= PI2);
  107. var unifiedTheta = dTheta > 0 ? dTheta % PI2 : dTheta % PI2 + PI2;
  108. var large = false;
  109. if (isCircle) {
  110. large = true;
  111. } else if (isAroundZero(dThetaPositive)) {
  112. large = false;
  113. } else {
  114. large = unifiedTheta >= PI === !!clockwise;
  115. }
  116. var x0 = cx + rx * mathCos(startAngle);
  117. var y0 = cy + ry * mathSin(startAngle);
  118. if (this._start) {
  119. this._add("M", x0, y0);
  120. }
  121. var xRot = Math.round(psi * degree);
  122. if (isCircle) {
  123. var p = 1 / this._p;
  124. var dTheta_1 = (clockwise ? 1 : -1) * (PI2 - p);
  125. this._add("A", rx, ry, xRot, 1, +clockwise, cx + rx * mathCos(startAngle + dTheta_1), cy + ry * mathSin(startAngle + dTheta_1));
  126. if (p > 0.01) {
  127. this._add("A", rx, ry, xRot, 0, +clockwise, x0, y0);
  128. }
  129. } else {
  130. var x = cx + rx * mathCos(endAngle);
  131. var y = cy + ry * mathSin(endAngle);
  132. this._add("A", rx, ry, xRot, +large, +clockwise, x, y);
  133. }
  134. };
  135. SVGPathRebuilder2.prototype.rect = function(x, y, w, h) {
  136. this._add("M", x, y);
  137. this._add("l", w, 0);
  138. this._add("l", 0, h);
  139. this._add("l", -w, 0);
  140. this._add("Z");
  141. };
  142. SVGPathRebuilder2.prototype.closePath = function() {
  143. if (this._d.length > 0) {
  144. this._add("Z");
  145. }
  146. };
  147. SVGPathRebuilder2.prototype._add = function(cmd, a, b, c, d, e, f, g, h) {
  148. var vals = [];
  149. var p = this._p;
  150. for (var i = 1; i < arguments.length; i++) {
  151. var val = arguments[i];
  152. if (isNaN(val)) {
  153. this._invalid = true;
  154. return;
  155. }
  156. vals.push(Math.round(val * p) / p);
  157. }
  158. this._d.push(cmd + vals.join(" "));
  159. this._start = cmd === "Z";
  160. };
  161. SVGPathRebuilder2.prototype.generateStr = function() {
  162. this._str = this._invalid ? "" : this._d.join("");
  163. this._d = [];
  164. };
  165. SVGPathRebuilder2.prototype.getStr = function() {
  166. return this._str;
  167. };
  168. return SVGPathRebuilder2;
  169. }();
  170. var SVGPathRebuilder_default = SVGPathRebuilder;
  171. // node_modules/zrender/lib/svg/mapStyleToAttrs.js
  172. var NONE = "none";
  173. var mathRound = Math.round;
  174. function pathHasFill(style) {
  175. var fill = style.fill;
  176. return fill != null && fill !== NONE;
  177. }
  178. function pathHasStroke(style) {
  179. var stroke = style.stroke;
  180. return stroke != null && stroke !== NONE;
  181. }
  182. var strokeProps = ["lineCap", "miterLimit", "lineJoin"];
  183. var svgStrokeProps = map(strokeProps, function(prop) {
  184. return "stroke-" + prop.toLowerCase();
  185. });
  186. function mapStyleToAttrs(updateAttr, style, el, forceUpdate) {
  187. var opacity = style.opacity == null ? 1 : style.opacity;
  188. if (el instanceof Image_default) {
  189. updateAttr("opacity", opacity);
  190. return;
  191. }
  192. if (pathHasFill(style)) {
  193. var fill = normalizeColor(style.fill);
  194. updateAttr("fill", fill.color);
  195. var fillOpacity = style.fillOpacity != null ? style.fillOpacity * fill.opacity * opacity : fill.opacity * opacity;
  196. if (forceUpdate || fillOpacity < 1) {
  197. updateAttr("fill-opacity", fillOpacity);
  198. }
  199. } else {
  200. updateAttr("fill", NONE);
  201. }
  202. if (pathHasStroke(style)) {
  203. var stroke = normalizeColor(style.stroke);
  204. updateAttr("stroke", stroke.color);
  205. var strokeScale = style.strokeNoScale ? el.getLineScale() : 1;
  206. var strokeWidth = strokeScale ? (style.lineWidth || 0) / strokeScale : 0;
  207. var strokeOpacity = style.strokeOpacity != null ? style.strokeOpacity * stroke.opacity * opacity : stroke.opacity * opacity;
  208. var strokeFirst = style.strokeFirst;
  209. if (forceUpdate || strokeWidth !== 1) {
  210. updateAttr("stroke-width", strokeWidth);
  211. }
  212. if (forceUpdate || strokeFirst) {
  213. updateAttr("paint-order", strokeFirst ? "stroke" : "fill");
  214. }
  215. if (forceUpdate || strokeOpacity < 1) {
  216. updateAttr("stroke-opacity", strokeOpacity);
  217. }
  218. if (style.lineDash) {
  219. var _a = getLineDash(el), lineDash = _a[0], lineDashOffset = _a[1];
  220. if (lineDash) {
  221. lineDashOffset = mathRound(lineDashOffset || 0);
  222. updateAttr("stroke-dasharray", lineDash.join(","));
  223. if (lineDashOffset || forceUpdate) {
  224. updateAttr("stroke-dashoffset", lineDashOffset);
  225. }
  226. }
  227. } else if (forceUpdate) {
  228. updateAttr("stroke-dasharray", NONE);
  229. }
  230. for (var i = 0; i < strokeProps.length; i++) {
  231. var propName = strokeProps[i];
  232. if (forceUpdate || style[propName] !== DEFAULT_PATH_STYLE[propName]) {
  233. var val = style[propName] || DEFAULT_PATH_STYLE[propName];
  234. val && updateAttr(svgStrokeProps[i], val);
  235. }
  236. }
  237. } else if (forceUpdate) {
  238. updateAttr("stroke", NONE);
  239. }
  240. }
  241. // node_modules/zrender/lib/svg/core.js
  242. var SVGNS = "http://www.w3.org/2000/svg";
  243. var XLINKNS = "http://www.w3.org/1999/xlink";
  244. var XMLNS = "http://www.w3.org/2000/xmlns/";
  245. var XML_NAMESPACE = "http://www.w3.org/XML/1998/namespace";
  246. var META_DATA_PREFIX = "ecmeta_";
  247. function createElement(name) {
  248. return document.createElementNS(SVGNS, name);
  249. }
  250. function createVNode(tag, key, attrs, children, text) {
  251. return {
  252. tag,
  253. attrs: attrs || {},
  254. children,
  255. text,
  256. key
  257. };
  258. }
  259. function createElementOpen(name, attrs) {
  260. var attrsStr = [];
  261. if (attrs) {
  262. for (var key in attrs) {
  263. var val = attrs[key];
  264. var part = key;
  265. if (val === false) {
  266. continue;
  267. } else if (val !== true && val != null) {
  268. part += '="' + val + '"';
  269. }
  270. attrsStr.push(part);
  271. }
  272. }
  273. return "<" + name + " " + attrsStr.join(" ") + ">";
  274. }
  275. function createElementClose(name) {
  276. return "</" + name + ">";
  277. }
  278. function vNodeToString(el, opts) {
  279. opts = opts || {};
  280. var S = opts.newline ? "\n" : "";
  281. function convertElToString(el2) {
  282. var children = el2.children, tag = el2.tag, attrs = el2.attrs, text = el2.text;
  283. return createElementOpen(tag, attrs) + (tag !== "style" ? encodeHTML(text) : text || "") + (children ? "" + S + map(children, function(child) {
  284. return convertElToString(child);
  285. }).join(S) + S : "") + createElementClose(tag);
  286. }
  287. return convertElToString(el);
  288. }
  289. function getCssString(selectorNodes, animationNodes, opts) {
  290. opts = opts || {};
  291. var S = opts.newline ? "\n" : "";
  292. var bracketBegin = " {" + S;
  293. var bracketEnd = S + "}";
  294. var selectors = map(keys(selectorNodes), function(className) {
  295. return className + bracketBegin + map(keys(selectorNodes[className]), function(attrName) {
  296. return attrName + ":" + selectorNodes[className][attrName] + ";";
  297. }).join(S) + bracketEnd;
  298. }).join(S);
  299. var animations = map(keys(animationNodes), function(animationName) {
  300. return "@keyframes " + animationName + bracketBegin + map(keys(animationNodes[animationName]), function(percent) {
  301. return percent + bracketBegin + map(keys(animationNodes[animationName][percent]), function(attrName) {
  302. var val = animationNodes[animationName][percent][attrName];
  303. if (attrName === "d") {
  304. val = 'path("' + val + '")';
  305. }
  306. return attrName + ":" + val + ";";
  307. }).join(S) + bracketEnd;
  308. }).join(S) + bracketEnd;
  309. }).join(S);
  310. if (!selectors && !animations) {
  311. return "";
  312. }
  313. return ["<![CDATA[", selectors, animations, "]]>"].join(S);
  314. }
  315. function createBrushScope(zrId) {
  316. return {
  317. zrId,
  318. shadowCache: {},
  319. patternCache: {},
  320. gradientCache: {},
  321. clipPathCache: {},
  322. defs: {},
  323. cssNodes: {},
  324. cssAnims: {},
  325. cssStyleCache: {},
  326. cssAnimIdx: 0,
  327. shadowIdx: 0,
  328. gradientIdx: 0,
  329. patternIdx: 0,
  330. clipPathIdx: 0
  331. };
  332. }
  333. function createSVGVNode(width, height, children, useViewBox) {
  334. return createVNode("svg", "root", {
  335. "width": width,
  336. "height": height,
  337. "xmlns": SVGNS,
  338. "xmlns:xlink": XLINKNS,
  339. "version": "1.1",
  340. "baseProfile": "full",
  341. "viewBox": useViewBox ? "0 0 " + width + " " + height : false
  342. }, children);
  343. }
  344. // node_modules/zrender/lib/svg/cssClassId.js
  345. var cssClassIdx = 0;
  346. function getClassId() {
  347. return cssClassIdx++;
  348. }
  349. // node_modules/zrender/lib/svg/cssAnimation.js
  350. var EASING_MAP = {
  351. cubicIn: "0.32,0,0.67,0",
  352. cubicOut: "0.33,1,0.68,1",
  353. cubicInOut: "0.65,0,0.35,1",
  354. quadraticIn: "0.11,0,0.5,0",
  355. quadraticOut: "0.5,1,0.89,1",
  356. quadraticInOut: "0.45,0,0.55,1",
  357. quarticIn: "0.5,0,0.75,0",
  358. quarticOut: "0.25,1,0.5,1",
  359. quarticInOut: "0.76,0,0.24,1",
  360. quinticIn: "0.64,0,0.78,0",
  361. quinticOut: "0.22,1,0.36,1",
  362. quinticInOut: "0.83,0,0.17,1",
  363. sinusoidalIn: "0.12,0,0.39,0",
  364. sinusoidalOut: "0.61,1,0.88,1",
  365. sinusoidalInOut: "0.37,0,0.63,1",
  366. exponentialIn: "0.7,0,0.84,0",
  367. exponentialOut: "0.16,1,0.3,1",
  368. exponentialInOut: "0.87,0,0.13,1",
  369. circularIn: "0.55,0,1,0.45",
  370. circularOut: "0,0.55,0.45,1",
  371. circularInOut: "0.85,0,0.15,1"
  372. };
  373. var transformOriginKey = "transform-origin";
  374. function buildPathString(el, kfShape, path) {
  375. var shape = extend({}, el.shape);
  376. extend(shape, kfShape);
  377. el.buildPath(path, shape);
  378. var svgPathBuilder = new SVGPathRebuilder_default();
  379. svgPathBuilder.reset(getPathPrecision(el));
  380. path.rebuildPath(svgPathBuilder, 1);
  381. svgPathBuilder.generateStr();
  382. return svgPathBuilder.getStr();
  383. }
  384. function setTransformOrigin(target, transform) {
  385. var originX = transform.originX, originY = transform.originY;
  386. if (originX || originY) {
  387. target[transformOriginKey] = originX + "px " + originY + "px";
  388. }
  389. }
  390. var ANIMATE_STYLE_MAP = {
  391. fill: "fill",
  392. opacity: "opacity",
  393. lineWidth: "stroke-width",
  394. lineDashOffset: "stroke-dashoffset"
  395. };
  396. function addAnimation(cssAnim, scope) {
  397. var animationName = scope.zrId + "-ani-" + scope.cssAnimIdx++;
  398. scope.cssAnims[animationName] = cssAnim;
  399. return animationName;
  400. }
  401. function createCompoundPathCSSAnimation(el, attrs, scope) {
  402. var paths = el.shape.paths;
  403. var composedAnim = {};
  404. var cssAnimationCfg;
  405. var cssAnimationName;
  406. each(paths, function(path) {
  407. var subScope = createBrushScope(scope.zrId);
  408. subScope.animation = true;
  409. createCSSAnimation(path, {}, subScope, true);
  410. var cssAnims = subScope.cssAnims;
  411. var cssNodes = subScope.cssNodes;
  412. var animNames = keys(cssAnims);
  413. var len = animNames.length;
  414. if (!len) {
  415. return;
  416. }
  417. cssAnimationName = animNames[len - 1];
  418. var lastAnim = cssAnims[cssAnimationName];
  419. for (var percent in lastAnim) {
  420. var kf = lastAnim[percent];
  421. composedAnim[percent] = composedAnim[percent] || { d: "" };
  422. composedAnim[percent].d += kf.d || "";
  423. }
  424. for (var className in cssNodes) {
  425. var val = cssNodes[className].animation;
  426. if (val.indexOf(cssAnimationName) >= 0) {
  427. cssAnimationCfg = val;
  428. }
  429. }
  430. });
  431. if (!cssAnimationCfg) {
  432. return;
  433. }
  434. attrs.d = false;
  435. var animationName = addAnimation(composedAnim, scope);
  436. return cssAnimationCfg.replace(cssAnimationName, animationName);
  437. }
  438. function getEasingFunc(easing) {
  439. return isString(easing) ? EASING_MAP[easing] ? "cubic-bezier(" + EASING_MAP[easing] + ")" : createCubicEasingFunc(easing) ? easing : "" : "";
  440. }
  441. function createCSSAnimation(el, attrs, scope, onlyShape) {
  442. var animators = el.animators;
  443. var len = animators.length;
  444. var cssAnimations = [];
  445. if (el instanceof CompoundPath_default) {
  446. var animationCfg = createCompoundPathCSSAnimation(el, attrs, scope);
  447. if (animationCfg) {
  448. cssAnimations.push(animationCfg);
  449. } else if (!len) {
  450. return;
  451. }
  452. } else if (!len) {
  453. return;
  454. }
  455. var groupAnimators = {};
  456. for (var i = 0; i < len; i++) {
  457. var animator = animators[i];
  458. var cfgArr = [animator.getMaxTime() / 1e3 + "s"];
  459. var easing = getEasingFunc(animator.getClip().easing);
  460. var delay = animator.getDelay();
  461. if (easing) {
  462. cfgArr.push(easing);
  463. } else {
  464. cfgArr.push("linear");
  465. }
  466. if (delay) {
  467. cfgArr.push(delay / 1e3 + "s");
  468. }
  469. if (animator.getLoop()) {
  470. cfgArr.push("infinite");
  471. }
  472. var cfg = cfgArr.join(" ");
  473. groupAnimators[cfg] = groupAnimators[cfg] || [cfg, []];
  474. groupAnimators[cfg][1].push(animator);
  475. }
  476. function createSingleCSSAnimation(groupAnimator) {
  477. var animators2 = groupAnimator[1];
  478. var len2 = animators2.length;
  479. var transformKfs = {};
  480. var shapeKfs = {};
  481. var finalKfs = {};
  482. var animationTimingFunctionAttrName = "animation-timing-function";
  483. function saveAnimatorTrackToCssKfs(animator3, cssKfs, toCssAttrName) {
  484. var tracks = animator3.getTracks();
  485. var maxTime = animator3.getMaxTime();
  486. for (var k = 0; k < tracks.length; k++) {
  487. var track = tracks[k];
  488. if (track.needsAnimate()) {
  489. var kfs = track.keyframes;
  490. var attrName = track.propName;
  491. toCssAttrName && (attrName = toCssAttrName(attrName));
  492. if (attrName) {
  493. for (var i3 = 0; i3 < kfs.length; i3++) {
  494. var kf = kfs[i3];
  495. var percent2 = Math.round(kf.time / maxTime * 100) + "%";
  496. var kfEasing = getEasingFunc(kf.easing);
  497. var rawValue = kf.rawValue;
  498. if (isString(rawValue) || isNumber(rawValue)) {
  499. cssKfs[percent2] = cssKfs[percent2] || {};
  500. cssKfs[percent2][attrName] = kf.rawValue;
  501. if (kfEasing) {
  502. cssKfs[percent2][animationTimingFunctionAttrName] = kfEasing;
  503. }
  504. }
  505. }
  506. }
  507. }
  508. }
  509. }
  510. for (var i2 = 0; i2 < len2; i2++) {
  511. var animator2 = animators2[i2];
  512. var targetProp = animator2.targetName;
  513. if (!targetProp) {
  514. !onlyShape && saveAnimatorTrackToCssKfs(animator2, transformKfs);
  515. } else if (targetProp === "shape") {
  516. saveAnimatorTrackToCssKfs(animator2, shapeKfs);
  517. }
  518. }
  519. for (var percent in transformKfs) {
  520. var transform = {};
  521. copyTransform(transform, el);
  522. extend(transform, transformKfs[percent]);
  523. var str = getSRTTransformString(transform);
  524. var timingFunction = transformKfs[percent][animationTimingFunctionAttrName];
  525. finalKfs[percent] = str ? {
  526. transform: str
  527. } : {};
  528. setTransformOrigin(finalKfs[percent], transform);
  529. if (timingFunction) {
  530. finalKfs[percent][animationTimingFunctionAttrName] = timingFunction;
  531. }
  532. }
  533. ;
  534. var path;
  535. var canAnimateShape = true;
  536. for (var percent in shapeKfs) {
  537. finalKfs[percent] = finalKfs[percent] || {};
  538. var isFirst = !path;
  539. var timingFunction = shapeKfs[percent][animationTimingFunctionAttrName];
  540. if (isFirst) {
  541. path = new PathProxy_default();
  542. }
  543. var len_1 = path.len();
  544. path.reset();
  545. finalKfs[percent].d = buildPathString(el, shapeKfs[percent], path);
  546. var newLen = path.len();
  547. if (!isFirst && len_1 !== newLen) {
  548. canAnimateShape = false;
  549. break;
  550. }
  551. if (timingFunction) {
  552. finalKfs[percent][animationTimingFunctionAttrName] = timingFunction;
  553. }
  554. }
  555. ;
  556. if (!canAnimateShape) {
  557. for (var percent in finalKfs) {
  558. delete finalKfs[percent].d;
  559. }
  560. }
  561. if (!onlyShape) {
  562. for (var i2 = 0; i2 < len2; i2++) {
  563. var animator2 = animators2[i2];
  564. var targetProp = animator2.targetName;
  565. if (targetProp === "style") {
  566. saveAnimatorTrackToCssKfs(animator2, finalKfs, function(propName) {
  567. return ANIMATE_STYLE_MAP[propName];
  568. });
  569. }
  570. }
  571. }
  572. var percents = keys(finalKfs);
  573. var allTransformOriginSame = true;
  574. var transformOrigin;
  575. for (var i2 = 1; i2 < percents.length; i2++) {
  576. var p0 = percents[i2 - 1];
  577. var p1 = percents[i2];
  578. if (finalKfs[p0][transformOriginKey] !== finalKfs[p1][transformOriginKey]) {
  579. allTransformOriginSame = false;
  580. break;
  581. }
  582. transformOrigin = finalKfs[p0][transformOriginKey];
  583. }
  584. if (allTransformOriginSame && transformOrigin) {
  585. for (var percent in finalKfs) {
  586. if (finalKfs[percent][transformOriginKey]) {
  587. delete finalKfs[percent][transformOriginKey];
  588. }
  589. }
  590. attrs[transformOriginKey] = transformOrigin;
  591. }
  592. if (filter(percents, function(percent2) {
  593. return keys(finalKfs[percent2]).length > 0;
  594. }).length) {
  595. var animationName = addAnimation(finalKfs, scope);
  596. return animationName + " " + groupAnimator[0] + " both";
  597. }
  598. }
  599. for (var key in groupAnimators) {
  600. var animationCfg = createSingleCSSAnimation(groupAnimators[key]);
  601. if (animationCfg) {
  602. cssAnimations.push(animationCfg);
  603. }
  604. }
  605. if (cssAnimations.length) {
  606. var className = scope.zrId + "-cls-" + getClassId();
  607. scope.cssNodes["." + className] = {
  608. animation: cssAnimations.join(",")
  609. };
  610. attrs["class"] = className;
  611. }
  612. }
  613. // node_modules/zrender/lib/svg/cssEmphasis.js
  614. function createCSSEmphasis(el, attrs, scope) {
  615. if (!el.ignore) {
  616. if (el.isSilent()) {
  617. var style = {
  618. "pointer-events": "none"
  619. };
  620. setClassAttribute(style, attrs, scope, true);
  621. } else {
  622. var emphasisStyle = el.states.emphasis && el.states.emphasis.style ? el.states.emphasis.style : {};
  623. var fill = emphasisStyle.fill;
  624. if (!fill) {
  625. var normalFill = el.style && el.style.fill;
  626. var selectFill = el.states.select && el.states.select.style && el.states.select.style.fill;
  627. var fromFill = el.currentStates.indexOf("select") >= 0 ? selectFill || normalFill : normalFill;
  628. if (fromFill) {
  629. fill = liftColor(fromFill);
  630. }
  631. }
  632. var lineWidth = emphasisStyle.lineWidth;
  633. if (lineWidth) {
  634. var scaleX = !emphasisStyle.strokeNoScale && el.transform ? el.transform[0] : 1;
  635. lineWidth = lineWidth / scaleX;
  636. }
  637. var style = {
  638. cursor: "pointer"
  639. };
  640. if (fill) {
  641. style.fill = fill;
  642. }
  643. if (emphasisStyle.stroke) {
  644. style.stroke = emphasisStyle.stroke;
  645. }
  646. if (lineWidth) {
  647. style["stroke-width"] = lineWidth;
  648. }
  649. setClassAttribute(style, attrs, scope, true);
  650. }
  651. }
  652. }
  653. function setClassAttribute(style, attrs, scope, withHover) {
  654. var styleKey = JSON.stringify(style);
  655. var className = scope.cssStyleCache[styleKey];
  656. if (!className) {
  657. className = scope.zrId + "-cls-" + getClassId();
  658. scope.cssStyleCache[styleKey] = className;
  659. scope.cssNodes["." + className + (withHover ? ":hover" : "")] = style;
  660. }
  661. attrs["class"] = attrs["class"] ? attrs["class"] + " " + className : className;
  662. }
  663. // node_modules/zrender/lib/svg/graphic.js
  664. var round = Math.round;
  665. function isImageLike(val) {
  666. return val && isString(val.src);
  667. }
  668. function isCanvasLike(val) {
  669. return val && isFunction(val.toDataURL);
  670. }
  671. function setStyleAttrs(attrs, style, el, scope) {
  672. mapStyleToAttrs(function(key, val) {
  673. var isFillStroke = key === "fill" || key === "stroke";
  674. if (isFillStroke && isGradient(val)) {
  675. setGradient(style, attrs, key, scope);
  676. } else if (isFillStroke && isPattern(val)) {
  677. setPattern(el, attrs, key, scope);
  678. } else if (isFillStroke && val === "none") {
  679. attrs[key] = "transparent";
  680. } else {
  681. attrs[key] = val;
  682. }
  683. }, style, el, false);
  684. setShadow(el, attrs, scope);
  685. }
  686. function setMetaData(attrs, el) {
  687. var metaData = getElementSSRData(el);
  688. if (metaData) {
  689. metaData.each(function(val, key) {
  690. val != null && (attrs[(META_DATA_PREFIX + key).toLowerCase()] = val + "");
  691. });
  692. if (el.isSilent()) {
  693. attrs[META_DATA_PREFIX + "silent"] = "true";
  694. }
  695. }
  696. }
  697. function noRotateScale(m) {
  698. return isAroundZero(m[0] - 1) && isAroundZero(m[1]) && isAroundZero(m[2]) && isAroundZero(m[3] - 1);
  699. }
  700. function noTranslate(m) {
  701. return isAroundZero(m[4]) && isAroundZero(m[5]);
  702. }
  703. function setTransform(attrs, m, compress) {
  704. if (m && !(noTranslate(m) && noRotateScale(m))) {
  705. var mul = compress ? 10 : 1e4;
  706. attrs.transform = noRotateScale(m) ? "translate(" + round(m[4] * mul) / mul + " " + round(m[5] * mul) / mul + ")" : getMatrixStr(m);
  707. }
  708. }
  709. function convertPolyShape(shape, attrs, mul) {
  710. var points = shape.points;
  711. var strArr = [];
  712. for (var i = 0; i < points.length; i++) {
  713. strArr.push(round(points[i][0] * mul) / mul);
  714. strArr.push(round(points[i][1] * mul) / mul);
  715. }
  716. attrs.points = strArr.join(" ");
  717. }
  718. function validatePolyShape(shape) {
  719. return !shape.smooth;
  720. }
  721. function createAttrsConvert(desc) {
  722. var normalizedDesc = map(desc, function(item) {
  723. return typeof item === "string" ? [item, item] : item;
  724. });
  725. return function(shape, attrs, mul) {
  726. for (var i = 0; i < normalizedDesc.length; i++) {
  727. var item = normalizedDesc[i];
  728. var val = shape[item[0]];
  729. if (val != null) {
  730. attrs[item[1]] = round(val * mul) / mul;
  731. }
  732. }
  733. };
  734. }
  735. var builtinShapesDef = {
  736. circle: [createAttrsConvert(["cx", "cy", "r"])],
  737. polyline: [convertPolyShape, validatePolyShape],
  738. polygon: [convertPolyShape, validatePolyShape]
  739. };
  740. function hasShapeAnimation(el) {
  741. var animators = el.animators;
  742. for (var i = 0; i < animators.length; i++) {
  743. if (animators[i].targetName === "shape") {
  744. return true;
  745. }
  746. }
  747. return false;
  748. }
  749. function brushSVGPath(el, scope) {
  750. var style = el.style;
  751. var shape = el.shape;
  752. var builtinShpDef = builtinShapesDef[el.type];
  753. var attrs = {};
  754. var needsAnimate = scope.animation;
  755. var svgElType = "path";
  756. var strokePercent = el.style.strokePercent;
  757. var precision = scope.compress && getPathPrecision(el) || 4;
  758. if (builtinShpDef && !scope.willUpdate && !(builtinShpDef[1] && !builtinShpDef[1](shape)) && !(needsAnimate && hasShapeAnimation(el)) && !(strokePercent < 1)) {
  759. svgElType = el.type;
  760. var mul = Math.pow(10, precision);
  761. builtinShpDef[0](shape, attrs, mul);
  762. } else {
  763. var needBuildPath = !el.path || el.shapeChanged();
  764. if (!el.path) {
  765. el.createPathProxy();
  766. }
  767. var path = el.path;
  768. if (needBuildPath) {
  769. path.beginPath();
  770. el.buildPath(path, el.shape);
  771. el.pathUpdated();
  772. }
  773. var pathVersion = path.getVersion();
  774. var elExt = el;
  775. var svgPathBuilder = elExt.__svgPathBuilder;
  776. if (elExt.__svgPathVersion !== pathVersion || !svgPathBuilder || strokePercent !== elExt.__svgPathStrokePercent) {
  777. if (!svgPathBuilder) {
  778. svgPathBuilder = elExt.__svgPathBuilder = new SVGPathRebuilder_default();
  779. }
  780. svgPathBuilder.reset(precision);
  781. path.rebuildPath(svgPathBuilder, strokePercent);
  782. svgPathBuilder.generateStr();
  783. elExt.__svgPathVersion = pathVersion;
  784. elExt.__svgPathStrokePercent = strokePercent;
  785. }
  786. attrs.d = svgPathBuilder.getStr();
  787. }
  788. setTransform(attrs, el.transform);
  789. setStyleAttrs(attrs, style, el, scope);
  790. setMetaData(attrs, el);
  791. scope.animation && createCSSAnimation(el, attrs, scope);
  792. scope.emphasis && createCSSEmphasis(el, attrs, scope);
  793. return createVNode(svgElType, el.id + "", attrs);
  794. }
  795. function brushSVGImage(el, scope) {
  796. var style = el.style;
  797. var image = style.image;
  798. if (image && !isString(image)) {
  799. if (isImageLike(image)) {
  800. image = image.src;
  801. } else if (isCanvasLike(image)) {
  802. image = image.toDataURL();
  803. }
  804. }
  805. if (!image) {
  806. return;
  807. }
  808. var x = style.x || 0;
  809. var y = style.y || 0;
  810. var dw = style.width;
  811. var dh = style.height;
  812. var attrs = {
  813. href: image,
  814. width: dw,
  815. height: dh
  816. };
  817. if (x) {
  818. attrs.x = x;
  819. }
  820. if (y) {
  821. attrs.y = y;
  822. }
  823. setTransform(attrs, el.transform);
  824. setStyleAttrs(attrs, style, el, scope);
  825. setMetaData(attrs, el);
  826. scope.animation && createCSSAnimation(el, attrs, scope);
  827. return createVNode("image", el.id + "", attrs);
  828. }
  829. function brushSVGTSpan(el, scope) {
  830. var style = el.style;
  831. var text = style.text;
  832. text != null && (text += "");
  833. if (!text || isNaN(style.x) || isNaN(style.y)) {
  834. return;
  835. }
  836. var font = style.font || DEFAULT_FONT;
  837. var x = style.x || 0;
  838. var y = adjustTextY(style.y || 0, getLineHeight(font), style.textBaseline);
  839. var textAlign = TEXT_ALIGN_TO_ANCHOR[style.textAlign] || style.textAlign;
  840. var attrs = {
  841. "dominant-baseline": "central",
  842. "text-anchor": textAlign
  843. };
  844. if (hasSeparateFont(style)) {
  845. var separatedFontStr = "";
  846. var fontStyle = style.fontStyle;
  847. var fontSize = parseFontSize(style.fontSize);
  848. if (!parseFloat(fontSize)) {
  849. return;
  850. }
  851. var fontFamily = style.fontFamily || DEFAULT_FONT_FAMILY;
  852. var fontWeight = style.fontWeight;
  853. separatedFontStr += "font-size:" + fontSize + ";font-family:" + fontFamily + ";";
  854. if (fontStyle && fontStyle !== "normal") {
  855. separatedFontStr += "font-style:" + fontStyle + ";";
  856. }
  857. if (fontWeight && fontWeight !== "normal") {
  858. separatedFontStr += "font-weight:" + fontWeight + ";";
  859. }
  860. attrs.style = separatedFontStr;
  861. } else {
  862. attrs.style = "font: " + font;
  863. }
  864. if (text.match(/\s/)) {
  865. attrs["xml:space"] = "preserve";
  866. }
  867. if (x) {
  868. attrs.x = x;
  869. }
  870. if (y) {
  871. attrs.y = y;
  872. }
  873. setTransform(attrs, el.transform);
  874. setStyleAttrs(attrs, style, el, scope);
  875. setMetaData(attrs, el);
  876. scope.animation && createCSSAnimation(el, attrs, scope);
  877. return createVNode("text", el.id + "", attrs, void 0, text);
  878. }
  879. function brush2(el, scope) {
  880. if (el instanceof Path_default) {
  881. return brushSVGPath(el, scope);
  882. } else if (el instanceof Image_default) {
  883. return brushSVGImage(el, scope);
  884. } else if (el instanceof TSpan_default) {
  885. return brushSVGTSpan(el, scope);
  886. }
  887. }
  888. function setShadow(el, attrs, scope) {
  889. var style = el.style;
  890. if (hasShadow(style)) {
  891. var shadowKey = getShadowKey(el);
  892. var shadowCache = scope.shadowCache;
  893. var shadowId = shadowCache[shadowKey];
  894. if (!shadowId) {
  895. var globalScale = el.getGlobalScale();
  896. var scaleX = globalScale[0];
  897. var scaleY = globalScale[1];
  898. if (!scaleX || !scaleY) {
  899. return;
  900. }
  901. var offsetX = style.shadowOffsetX || 0;
  902. var offsetY = style.shadowOffsetY || 0;
  903. var blur_1 = style.shadowBlur;
  904. var _a = normalizeColor(style.shadowColor), opacity = _a.opacity, color = _a.color;
  905. var stdDx = blur_1 / 2 / scaleX;
  906. var stdDy = blur_1 / 2 / scaleY;
  907. var stdDeviation = stdDx + " " + stdDy;
  908. shadowId = scope.zrId + "-s" + scope.shadowIdx++;
  909. scope.defs[shadowId] = createVNode("filter", shadowId, {
  910. "id": shadowId,
  911. "x": "-100%",
  912. "y": "-100%",
  913. "width": "300%",
  914. "height": "300%"
  915. }, [
  916. createVNode("feDropShadow", "", {
  917. "dx": offsetX / scaleX,
  918. "dy": offsetY / scaleY,
  919. "stdDeviation": stdDeviation,
  920. "flood-color": color,
  921. "flood-opacity": opacity
  922. })
  923. ]);
  924. shadowCache[shadowKey] = shadowId;
  925. }
  926. attrs.filter = getIdURL(shadowId);
  927. }
  928. }
  929. function setGradient(style, attrs, target, scope) {
  930. var val = style[target];
  931. var gradientTag;
  932. var gradientAttrs = {
  933. "gradientUnits": val.global ? "userSpaceOnUse" : "objectBoundingBox"
  934. };
  935. if (isLinearGradient(val)) {
  936. gradientTag = "linearGradient";
  937. gradientAttrs.x1 = val.x;
  938. gradientAttrs.y1 = val.y;
  939. gradientAttrs.x2 = val.x2;
  940. gradientAttrs.y2 = val.y2;
  941. } else if (isRadialGradient(val)) {
  942. gradientTag = "radialGradient";
  943. gradientAttrs.cx = retrieve2(val.x, 0.5);
  944. gradientAttrs.cy = retrieve2(val.y, 0.5);
  945. gradientAttrs.r = retrieve2(val.r, 0.5);
  946. } else {
  947. if (true) {
  948. logError("Illegal gradient type.");
  949. }
  950. return;
  951. }
  952. var colors = val.colorStops;
  953. var colorStops = [];
  954. for (var i = 0, len = colors.length; i < len; ++i) {
  955. var offset = round4(colors[i].offset) * 100 + "%";
  956. var stopColor = colors[i].color;
  957. var _a = normalizeColor(stopColor), color = _a.color, opacity = _a.opacity;
  958. var stopsAttrs = {
  959. "offset": offset
  960. };
  961. stopsAttrs["stop-color"] = color;
  962. if (opacity < 1) {
  963. stopsAttrs["stop-opacity"] = opacity;
  964. }
  965. colorStops.push(createVNode("stop", i + "", stopsAttrs));
  966. }
  967. var gradientVNode = createVNode(gradientTag, "", gradientAttrs, colorStops);
  968. var gradientKey = vNodeToString(gradientVNode);
  969. var gradientCache = scope.gradientCache;
  970. var gradientId = gradientCache[gradientKey];
  971. if (!gradientId) {
  972. gradientId = scope.zrId + "-g" + scope.gradientIdx++;
  973. gradientCache[gradientKey] = gradientId;
  974. gradientAttrs.id = gradientId;
  975. scope.defs[gradientId] = createVNode(gradientTag, gradientId, gradientAttrs, colorStops);
  976. }
  977. attrs[target] = getIdURL(gradientId);
  978. }
  979. function setPattern(el, attrs, target, scope) {
  980. var val = el.style[target];
  981. var boundingRect = el.getBoundingRect();
  982. var patternAttrs = {};
  983. var repeat = val.repeat;
  984. var noRepeat = repeat === "no-repeat";
  985. var repeatX = repeat === "repeat-x";
  986. var repeatY = repeat === "repeat-y";
  987. var child;
  988. if (isImagePattern(val)) {
  989. var imageWidth_1 = val.imageWidth;
  990. var imageHeight_1 = val.imageHeight;
  991. var imageSrc = void 0;
  992. var patternImage = val.image;
  993. if (isString(patternImage)) {
  994. imageSrc = patternImage;
  995. } else if (isImageLike(patternImage)) {
  996. imageSrc = patternImage.src;
  997. } else if (isCanvasLike(patternImage)) {
  998. imageSrc = patternImage.toDataURL();
  999. }
  1000. if (typeof Image === "undefined") {
  1001. var errMsg = "Image width/height must been given explictly in svg-ssr renderer.";
  1002. assert(imageWidth_1, errMsg);
  1003. assert(imageHeight_1, errMsg);
  1004. } else if (imageWidth_1 == null || imageHeight_1 == null) {
  1005. var setSizeToVNode_1 = function(vNode, img) {
  1006. if (vNode) {
  1007. var svgEl = vNode.elm;
  1008. var width = imageWidth_1 || img.width;
  1009. var height = imageHeight_1 || img.height;
  1010. if (vNode.tag === "pattern") {
  1011. if (repeatX) {
  1012. height = 1;
  1013. width /= boundingRect.width;
  1014. } else if (repeatY) {
  1015. width = 1;
  1016. height /= boundingRect.height;
  1017. }
  1018. }
  1019. vNode.attrs.width = width;
  1020. vNode.attrs.height = height;
  1021. if (svgEl) {
  1022. svgEl.setAttribute("width", width);
  1023. svgEl.setAttribute("height", height);
  1024. }
  1025. }
  1026. };
  1027. var createdImage = createOrUpdateImage(imageSrc, null, el, function(img) {
  1028. noRepeat || setSizeToVNode_1(patternVNode, img);
  1029. setSizeToVNode_1(child, img);
  1030. });
  1031. if (createdImage && createdImage.width && createdImage.height) {
  1032. imageWidth_1 = imageWidth_1 || createdImage.width;
  1033. imageHeight_1 = imageHeight_1 || createdImage.height;
  1034. }
  1035. }
  1036. child = createVNode("image", "img", {
  1037. href: imageSrc,
  1038. width: imageWidth_1,
  1039. height: imageHeight_1
  1040. });
  1041. patternAttrs.width = imageWidth_1;
  1042. patternAttrs.height = imageHeight_1;
  1043. } else if (val.svgElement) {
  1044. child = clone(val.svgElement);
  1045. patternAttrs.width = val.svgWidth;
  1046. patternAttrs.height = val.svgHeight;
  1047. }
  1048. if (!child) {
  1049. return;
  1050. }
  1051. var patternWidth;
  1052. var patternHeight;
  1053. if (noRepeat) {
  1054. patternWidth = patternHeight = 1;
  1055. } else if (repeatX) {
  1056. patternHeight = 1;
  1057. patternWidth = patternAttrs.width / boundingRect.width;
  1058. } else if (repeatY) {
  1059. patternWidth = 1;
  1060. patternHeight = patternAttrs.height / boundingRect.height;
  1061. } else {
  1062. patternAttrs.patternUnits = "userSpaceOnUse";
  1063. }
  1064. if (patternWidth != null && !isNaN(patternWidth)) {
  1065. patternAttrs.width = patternWidth;
  1066. }
  1067. if (patternHeight != null && !isNaN(patternHeight)) {
  1068. patternAttrs.height = patternHeight;
  1069. }
  1070. var patternTransform = getSRTTransformString(val);
  1071. patternTransform && (patternAttrs.patternTransform = patternTransform);
  1072. var patternVNode = createVNode("pattern", "", patternAttrs, [child]);
  1073. var patternKey = vNodeToString(patternVNode);
  1074. var patternCache = scope.patternCache;
  1075. var patternId = patternCache[patternKey];
  1076. if (!patternId) {
  1077. patternId = scope.zrId + "-p" + scope.patternIdx++;
  1078. patternCache[patternKey] = patternId;
  1079. patternAttrs.id = patternId;
  1080. patternVNode = scope.defs[patternId] = createVNode("pattern", patternId, patternAttrs, [child]);
  1081. }
  1082. attrs[target] = getIdURL(patternId);
  1083. }
  1084. function setClipPath(clipPath, attrs, scope) {
  1085. var clipPathCache = scope.clipPathCache, defs = scope.defs;
  1086. var clipPathId = clipPathCache[clipPath.id];
  1087. if (!clipPathId) {
  1088. clipPathId = scope.zrId + "-c" + scope.clipPathIdx++;
  1089. var clipPathAttrs = {
  1090. id: clipPathId
  1091. };
  1092. clipPathCache[clipPath.id] = clipPathId;
  1093. defs[clipPathId] = createVNode("clipPath", clipPathId, clipPathAttrs, [brushSVGPath(clipPath, scope)]);
  1094. }
  1095. attrs["clip-path"] = getIdURL(clipPathId);
  1096. }
  1097. // node_modules/zrender/lib/svg/domapi.js
  1098. function createTextNode(text) {
  1099. return document.createTextNode(text);
  1100. }
  1101. function insertBefore(parentNode2, newNode, referenceNode) {
  1102. parentNode2.insertBefore(newNode, referenceNode);
  1103. }
  1104. function removeChild(node, child) {
  1105. node.removeChild(child);
  1106. }
  1107. function appendChild(node, child) {
  1108. node.appendChild(child);
  1109. }
  1110. function parentNode(node) {
  1111. return node.parentNode;
  1112. }
  1113. function nextSibling(node) {
  1114. return node.nextSibling;
  1115. }
  1116. function setTextContent(node, text) {
  1117. node.textContent = text;
  1118. }
  1119. // node_modules/zrender/lib/svg/patch.js
  1120. var colonChar = 58;
  1121. var xChar = 120;
  1122. var emptyNode = createVNode("", "");
  1123. function isUndef(s) {
  1124. return s === void 0;
  1125. }
  1126. function isDef(s) {
  1127. return s !== void 0;
  1128. }
  1129. function createKeyToOldIdx(children, beginIdx, endIdx) {
  1130. var map2 = {};
  1131. for (var i = beginIdx; i <= endIdx; ++i) {
  1132. var key = children[i].key;
  1133. if (key !== void 0) {
  1134. if (true) {
  1135. if (map2[key] != null) {
  1136. console.error("Duplicate key " + key);
  1137. }
  1138. }
  1139. map2[key] = i;
  1140. }
  1141. }
  1142. return map2;
  1143. }
  1144. function sameVnode(vnode1, vnode2) {
  1145. var isSameKey = vnode1.key === vnode2.key;
  1146. var isSameTag = vnode1.tag === vnode2.tag;
  1147. return isSameTag && isSameKey;
  1148. }
  1149. function createElm(vnode) {
  1150. var i;
  1151. var children = vnode.children;
  1152. var tag = vnode.tag;
  1153. if (isDef(tag)) {
  1154. var elm = vnode.elm = createElement(tag);
  1155. updateAttrs(emptyNode, vnode);
  1156. if (isArray(children)) {
  1157. for (i = 0; i < children.length; ++i) {
  1158. var ch = children[i];
  1159. if (ch != null) {
  1160. appendChild(elm, createElm(ch));
  1161. }
  1162. }
  1163. } else if (isDef(vnode.text) && !isObject(vnode.text)) {
  1164. appendChild(elm, createTextNode(vnode.text));
  1165. }
  1166. } else {
  1167. vnode.elm = createTextNode(vnode.text);
  1168. }
  1169. return vnode.elm;
  1170. }
  1171. function addVnodes(parentElm, before, vnodes, startIdx, endIdx) {
  1172. for (; startIdx <= endIdx; ++startIdx) {
  1173. var ch = vnodes[startIdx];
  1174. if (ch != null) {
  1175. insertBefore(parentElm, createElm(ch), before);
  1176. }
  1177. }
  1178. }
  1179. function removeVnodes(parentElm, vnodes, startIdx, endIdx) {
  1180. for (; startIdx <= endIdx; ++startIdx) {
  1181. var ch = vnodes[startIdx];
  1182. if (ch != null) {
  1183. if (isDef(ch.tag)) {
  1184. var parent_1 = parentNode(ch.elm);
  1185. removeChild(parent_1, ch.elm);
  1186. } else {
  1187. removeChild(parentElm, ch.elm);
  1188. }
  1189. }
  1190. }
  1191. }
  1192. function updateAttrs(oldVnode, vnode) {
  1193. var key;
  1194. var elm = vnode.elm;
  1195. var oldAttrs = oldVnode && oldVnode.attrs || {};
  1196. var attrs = vnode.attrs || {};
  1197. if (oldAttrs === attrs) {
  1198. return;
  1199. }
  1200. for (key in attrs) {
  1201. var cur = attrs[key];
  1202. var old = oldAttrs[key];
  1203. if (old !== cur) {
  1204. if (cur === true) {
  1205. elm.setAttribute(key, "");
  1206. } else if (cur === false) {
  1207. elm.removeAttribute(key);
  1208. } else {
  1209. if (key === "style") {
  1210. elm.style.cssText = cur;
  1211. } else if (key.charCodeAt(0) !== xChar) {
  1212. elm.setAttribute(key, cur);
  1213. } else if (key === "xmlns:xlink" || key === "xmlns") {
  1214. elm.setAttributeNS(XMLNS, key, cur);
  1215. } else if (key.charCodeAt(3) === colonChar) {
  1216. elm.setAttributeNS(XML_NAMESPACE, key, cur);
  1217. } else if (key.charCodeAt(5) === colonChar) {
  1218. elm.setAttributeNS(XLINKNS, key, cur);
  1219. } else {
  1220. elm.setAttribute(key, cur);
  1221. }
  1222. }
  1223. }
  1224. }
  1225. for (key in oldAttrs) {
  1226. if (!(key in attrs)) {
  1227. elm.removeAttribute(key);
  1228. }
  1229. }
  1230. }
  1231. function updateChildren(parentElm, oldCh, newCh) {
  1232. var oldStartIdx = 0;
  1233. var newStartIdx = 0;
  1234. var oldEndIdx = oldCh.length - 1;
  1235. var oldStartVnode = oldCh[0];
  1236. var oldEndVnode = oldCh[oldEndIdx];
  1237. var newEndIdx = newCh.length - 1;
  1238. var newStartVnode = newCh[0];
  1239. var newEndVnode = newCh[newEndIdx];
  1240. var oldKeyToIdx;
  1241. var idxInOld;
  1242. var elmToMove;
  1243. var before;
  1244. while (oldStartIdx <= oldEndIdx && newStartIdx <= newEndIdx) {
  1245. if (oldStartVnode == null) {
  1246. oldStartVnode = oldCh[++oldStartIdx];
  1247. } else if (oldEndVnode == null) {
  1248. oldEndVnode = oldCh[--oldEndIdx];
  1249. } else if (newStartVnode == null) {
  1250. newStartVnode = newCh[++newStartIdx];
  1251. } else if (newEndVnode == null) {
  1252. newEndVnode = newCh[--newEndIdx];
  1253. } else if (sameVnode(oldStartVnode, newStartVnode)) {
  1254. patchVnode(oldStartVnode, newStartVnode);
  1255. oldStartVnode = oldCh[++oldStartIdx];
  1256. newStartVnode = newCh[++newStartIdx];
  1257. } else if (sameVnode(oldEndVnode, newEndVnode)) {
  1258. patchVnode(oldEndVnode, newEndVnode);
  1259. oldEndVnode = oldCh[--oldEndIdx];
  1260. newEndVnode = newCh[--newEndIdx];
  1261. } else if (sameVnode(oldStartVnode, newEndVnode)) {
  1262. patchVnode(oldStartVnode, newEndVnode);
  1263. insertBefore(parentElm, oldStartVnode.elm, nextSibling(oldEndVnode.elm));
  1264. oldStartVnode = oldCh[++oldStartIdx];
  1265. newEndVnode = newCh[--newEndIdx];
  1266. } else if (sameVnode(oldEndVnode, newStartVnode)) {
  1267. patchVnode(oldEndVnode, newStartVnode);
  1268. insertBefore(parentElm, oldEndVnode.elm, oldStartVnode.elm);
  1269. oldEndVnode = oldCh[--oldEndIdx];
  1270. newStartVnode = newCh[++newStartIdx];
  1271. } else {
  1272. if (isUndef(oldKeyToIdx)) {
  1273. oldKeyToIdx = createKeyToOldIdx(oldCh, oldStartIdx, oldEndIdx);
  1274. }
  1275. idxInOld = oldKeyToIdx[newStartVnode.key];
  1276. if (isUndef(idxInOld)) {
  1277. insertBefore(parentElm, createElm(newStartVnode), oldStartVnode.elm);
  1278. } else {
  1279. elmToMove = oldCh[idxInOld];
  1280. if (elmToMove.tag !== newStartVnode.tag) {
  1281. insertBefore(parentElm, createElm(newStartVnode), oldStartVnode.elm);
  1282. } else {
  1283. patchVnode(elmToMove, newStartVnode);
  1284. oldCh[idxInOld] = void 0;
  1285. insertBefore(parentElm, elmToMove.elm, oldStartVnode.elm);
  1286. }
  1287. }
  1288. newStartVnode = newCh[++newStartIdx];
  1289. }
  1290. }
  1291. if (oldStartIdx <= oldEndIdx || newStartIdx <= newEndIdx) {
  1292. if (oldStartIdx > oldEndIdx) {
  1293. before = newCh[newEndIdx + 1] == null ? null : newCh[newEndIdx + 1].elm;
  1294. addVnodes(parentElm, before, newCh, newStartIdx, newEndIdx);
  1295. } else {
  1296. removeVnodes(parentElm, oldCh, oldStartIdx, oldEndIdx);
  1297. }
  1298. }
  1299. }
  1300. function patchVnode(oldVnode, vnode) {
  1301. var elm = vnode.elm = oldVnode.elm;
  1302. var oldCh = oldVnode.children;
  1303. var ch = vnode.children;
  1304. if (oldVnode === vnode) {
  1305. return;
  1306. }
  1307. updateAttrs(oldVnode, vnode);
  1308. if (isUndef(vnode.text)) {
  1309. if (isDef(oldCh) && isDef(ch)) {
  1310. if (oldCh !== ch) {
  1311. updateChildren(elm, oldCh, ch);
  1312. }
  1313. } else if (isDef(ch)) {
  1314. if (isDef(oldVnode.text)) {
  1315. setTextContent(elm, "");
  1316. }
  1317. addVnodes(elm, null, ch, 0, ch.length - 1);
  1318. } else if (isDef(oldCh)) {
  1319. removeVnodes(elm, oldCh, 0, oldCh.length - 1);
  1320. } else if (isDef(oldVnode.text)) {
  1321. setTextContent(elm, "");
  1322. }
  1323. } else if (oldVnode.text !== vnode.text) {
  1324. if (isDef(oldCh)) {
  1325. removeVnodes(elm, oldCh, 0, oldCh.length - 1);
  1326. }
  1327. setTextContent(elm, vnode.text);
  1328. }
  1329. }
  1330. function patch(oldVnode, vnode) {
  1331. if (sameVnode(oldVnode, vnode)) {
  1332. patchVnode(oldVnode, vnode);
  1333. } else {
  1334. var elm = oldVnode.elm;
  1335. var parent_2 = parentNode(elm);
  1336. createElm(vnode);
  1337. if (parent_2 !== null) {
  1338. insertBefore(parent_2, vnode.elm, nextSibling(elm));
  1339. removeVnodes(parent_2, [oldVnode], 0, 0);
  1340. }
  1341. }
  1342. return vnode;
  1343. }
  1344. // node_modules/zrender/lib/svg/Painter.js
  1345. var svgId = 0;
  1346. var SVGPainter = function() {
  1347. function SVGPainter2(root, storage, opts) {
  1348. this.type = "svg";
  1349. this.refreshHover = createMethodNotSupport("refreshHover");
  1350. this.configLayer = createMethodNotSupport("configLayer");
  1351. this.storage = storage;
  1352. this._opts = opts = extend({}, opts);
  1353. this.root = root;
  1354. this._id = "zr" + svgId++;
  1355. this._oldVNode = createSVGVNode(opts.width, opts.height);
  1356. if (root && !opts.ssr) {
  1357. var viewport = this._viewport = document.createElement("div");
  1358. viewport.style.cssText = "position:relative;overflow:hidden";
  1359. var svgDom = this._svgDom = this._oldVNode.elm = createElement("svg");
  1360. updateAttrs(null, this._oldVNode);
  1361. viewport.appendChild(svgDom);
  1362. root.appendChild(viewport);
  1363. }
  1364. this.resize(opts.width, opts.height);
  1365. }
  1366. SVGPainter2.prototype.getType = function() {
  1367. return this.type;
  1368. };
  1369. SVGPainter2.prototype.getViewportRoot = function() {
  1370. return this._viewport;
  1371. };
  1372. SVGPainter2.prototype.getViewportRootOffset = function() {
  1373. var viewportRoot = this.getViewportRoot();
  1374. if (viewportRoot) {
  1375. return {
  1376. offsetLeft: viewportRoot.offsetLeft || 0,
  1377. offsetTop: viewportRoot.offsetTop || 0
  1378. };
  1379. }
  1380. };
  1381. SVGPainter2.prototype.getSvgDom = function() {
  1382. return this._svgDom;
  1383. };
  1384. SVGPainter2.prototype.refresh = function() {
  1385. if (this.root) {
  1386. var vnode = this.renderToVNode({
  1387. willUpdate: true
  1388. });
  1389. vnode.attrs.style = "position:absolute;left:0;top:0;user-select:none";
  1390. patch(this._oldVNode, vnode);
  1391. this._oldVNode = vnode;
  1392. }
  1393. };
  1394. SVGPainter2.prototype.renderOneToVNode = function(el) {
  1395. return brush2(el, createBrushScope(this._id));
  1396. };
  1397. SVGPainter2.prototype.renderToVNode = function(opts) {
  1398. opts = opts || {};
  1399. var list = this.storage.getDisplayList(true);
  1400. var width = this._width;
  1401. var height = this._height;
  1402. var scope = createBrushScope(this._id);
  1403. scope.animation = opts.animation;
  1404. scope.willUpdate = opts.willUpdate;
  1405. scope.compress = opts.compress;
  1406. scope.emphasis = opts.emphasis;
  1407. var children = [];
  1408. var bgVNode = this._bgVNode = createBackgroundVNode(width, height, this._backgroundColor, scope);
  1409. bgVNode && children.push(bgVNode);
  1410. var mainVNode = !opts.compress ? this._mainVNode = createVNode("g", "main", {}, []) : null;
  1411. this._paintList(list, scope, mainVNode ? mainVNode.children : children);
  1412. mainVNode && children.push(mainVNode);
  1413. var defs = map(keys(scope.defs), function(id) {
  1414. return scope.defs[id];
  1415. });
  1416. if (defs.length) {
  1417. children.push(createVNode("defs", "defs", {}, defs));
  1418. }
  1419. if (opts.animation) {
  1420. var animationCssStr = getCssString(scope.cssNodes, scope.cssAnims, { newline: true });
  1421. if (animationCssStr) {
  1422. var styleNode = createVNode("style", "stl", {}, [], animationCssStr);
  1423. children.push(styleNode);
  1424. }
  1425. }
  1426. return createSVGVNode(width, height, children, opts.useViewBox);
  1427. };
  1428. SVGPainter2.prototype.renderToString = function(opts) {
  1429. opts = opts || {};
  1430. return vNodeToString(this.renderToVNode({
  1431. animation: retrieve2(opts.cssAnimation, true),
  1432. emphasis: retrieve2(opts.cssEmphasis, true),
  1433. willUpdate: false,
  1434. compress: true,
  1435. useViewBox: retrieve2(opts.useViewBox, true)
  1436. }), { newline: true });
  1437. };
  1438. SVGPainter2.prototype.setBackgroundColor = function(backgroundColor) {
  1439. this._backgroundColor = backgroundColor;
  1440. };
  1441. SVGPainter2.prototype.getSvgRoot = function() {
  1442. return this._mainVNode && this._mainVNode.elm;
  1443. };
  1444. SVGPainter2.prototype._paintList = function(list, scope, out) {
  1445. var listLen = list.length;
  1446. var clipPathsGroupsStack = [];
  1447. var clipPathsGroupsStackDepth = 0;
  1448. var currentClipPathGroup;
  1449. var prevClipPaths;
  1450. var clipGroupNodeIdx = 0;
  1451. for (var i = 0; i < listLen; i++) {
  1452. var displayable = list[i];
  1453. if (!displayable.invisible) {
  1454. var clipPaths = displayable.__clipPaths;
  1455. var len = clipPaths && clipPaths.length || 0;
  1456. var prevLen = prevClipPaths && prevClipPaths.length || 0;
  1457. var lca = void 0;
  1458. for (lca = Math.max(len - 1, prevLen - 1); lca >= 0; lca--) {
  1459. if (clipPaths && prevClipPaths && clipPaths[lca] === prevClipPaths[lca]) {
  1460. break;
  1461. }
  1462. }
  1463. for (var i_1 = prevLen - 1; i_1 > lca; i_1--) {
  1464. clipPathsGroupsStackDepth--;
  1465. currentClipPathGroup = clipPathsGroupsStack[clipPathsGroupsStackDepth - 1];
  1466. }
  1467. for (var i_2 = lca + 1; i_2 < len; i_2++) {
  1468. var groupAttrs = {};
  1469. setClipPath(clipPaths[i_2], groupAttrs, scope);
  1470. var g = createVNode("g", "clip-g-" + clipGroupNodeIdx++, groupAttrs, []);
  1471. (currentClipPathGroup ? currentClipPathGroup.children : out).push(g);
  1472. clipPathsGroupsStack[clipPathsGroupsStackDepth++] = g;
  1473. currentClipPathGroup = g;
  1474. }
  1475. prevClipPaths = clipPaths;
  1476. var ret = brush2(displayable, scope);
  1477. if (ret) {
  1478. (currentClipPathGroup ? currentClipPathGroup.children : out).push(ret);
  1479. }
  1480. }
  1481. }
  1482. };
  1483. SVGPainter2.prototype.resize = function(width, height) {
  1484. var opts = this._opts;
  1485. var root = this.root;
  1486. var viewport = this._viewport;
  1487. width != null && (opts.width = width);
  1488. height != null && (opts.height = height);
  1489. if (root && viewport) {
  1490. viewport.style.display = "none";
  1491. width = getSize(root, 0, opts);
  1492. height = getSize(root, 1, opts);
  1493. viewport.style.display = "";
  1494. }
  1495. if (this._width !== width || this._height !== height) {
  1496. this._width = width;
  1497. this._height = height;
  1498. if (viewport) {
  1499. var viewportStyle = viewport.style;
  1500. viewportStyle.width = width + "px";
  1501. viewportStyle.height = height + "px";
  1502. }
  1503. if (!isPattern(this._backgroundColor)) {
  1504. var svgDom = this._svgDom;
  1505. if (svgDom) {
  1506. svgDom.setAttribute("width", width);
  1507. svgDom.setAttribute("height", height);
  1508. }
  1509. var bgEl = this._bgVNode && this._bgVNode.elm;
  1510. if (bgEl) {
  1511. bgEl.setAttribute("width", width);
  1512. bgEl.setAttribute("height", height);
  1513. }
  1514. } else {
  1515. this.refresh();
  1516. }
  1517. }
  1518. };
  1519. SVGPainter2.prototype.getWidth = function() {
  1520. return this._width;
  1521. };
  1522. SVGPainter2.prototype.getHeight = function() {
  1523. return this._height;
  1524. };
  1525. SVGPainter2.prototype.dispose = function() {
  1526. if (this.root) {
  1527. this.root.innerHTML = "";
  1528. }
  1529. this._svgDom = this._viewport = this.storage = this._oldVNode = this._bgVNode = this._mainVNode = null;
  1530. };
  1531. SVGPainter2.prototype.clear = function() {
  1532. if (this._svgDom) {
  1533. this._svgDom.innerHTML = null;
  1534. }
  1535. this._oldVNode = null;
  1536. };
  1537. SVGPainter2.prototype.toDataURL = function(base64) {
  1538. var str = this.renderToString();
  1539. var prefix = "data:image/svg+xml;";
  1540. if (base64) {
  1541. str = encodeBase64(str);
  1542. return str && prefix + "base64," + str;
  1543. }
  1544. return prefix + "charset=UTF-8," + encodeURIComponent(str);
  1545. };
  1546. return SVGPainter2;
  1547. }();
  1548. function createMethodNotSupport(method) {
  1549. return function() {
  1550. if (true) {
  1551. logError('In SVG mode painter not support method "' + method + '"');
  1552. }
  1553. };
  1554. }
  1555. function createBackgroundVNode(width, height, backgroundColor, scope) {
  1556. var bgVNode;
  1557. if (backgroundColor && backgroundColor !== "none") {
  1558. bgVNode = createVNode("rect", "bg", {
  1559. width,
  1560. height,
  1561. x: "0",
  1562. y: "0"
  1563. });
  1564. if (isGradient(backgroundColor)) {
  1565. setGradient({ fill: backgroundColor }, bgVNode.attrs, "fill", scope);
  1566. } else if (isPattern(backgroundColor)) {
  1567. setPattern({
  1568. style: {
  1569. fill: backgroundColor
  1570. },
  1571. dirty: noop,
  1572. getBoundingRect: function() {
  1573. return { width, height };
  1574. }
  1575. }, bgVNode.attrs, "fill", scope);
  1576. } else {
  1577. var _a = normalizeColor(backgroundColor), color = _a.color, opacity = _a.opacity;
  1578. bgVNode.attrs.fill = color;
  1579. opacity < 1 && (bgVNode.attrs["fill-opacity"] = opacity);
  1580. }
  1581. }
  1582. return bgVNode;
  1583. }
  1584. var Painter_default = SVGPainter;
  1585. // node_modules/echarts/lib/renderer/installSVGRenderer.js
  1586. function install(registers) {
  1587. registers.registerPainter("svg", Painter_default);
  1588. }
  1589. // node_modules/zrender/lib/canvas/Layer.js
  1590. function createDom(id, painter, dpr) {
  1591. var newDom = platformApi.createCanvas();
  1592. var width = painter.getWidth();
  1593. var height = painter.getHeight();
  1594. var newDomStyle = newDom.style;
  1595. if (newDomStyle) {
  1596. newDomStyle.position = "absolute";
  1597. newDomStyle.left = "0";
  1598. newDomStyle.top = "0";
  1599. newDomStyle.width = width + "px";
  1600. newDomStyle.height = height + "px";
  1601. newDom.setAttribute("data-zr-dom-id", id);
  1602. }
  1603. newDom.width = width * dpr;
  1604. newDom.height = height * dpr;
  1605. return newDom;
  1606. }
  1607. var Layer = function(_super) {
  1608. __extends(Layer2, _super);
  1609. function Layer2(id, painter, dpr) {
  1610. var _this = _super.call(this) || this;
  1611. _this.motionBlur = false;
  1612. _this.lastFrameAlpha = 0.7;
  1613. _this.dpr = 1;
  1614. _this.virtual = false;
  1615. _this.config = {};
  1616. _this.incremental = false;
  1617. _this.zlevel = 0;
  1618. _this.maxRepaintRectCount = 5;
  1619. _this.__dirty = true;
  1620. _this.__firstTimePaint = true;
  1621. _this.__used = false;
  1622. _this.__drawIndex = 0;
  1623. _this.__startIndex = 0;
  1624. _this.__endIndex = 0;
  1625. _this.__prevStartIndex = null;
  1626. _this.__prevEndIndex = null;
  1627. var dom;
  1628. dpr = dpr || devicePixelRatio;
  1629. if (typeof id === "string") {
  1630. dom = createDom(id, painter, dpr);
  1631. } else if (isObject(id)) {
  1632. dom = id;
  1633. id = dom.id;
  1634. }
  1635. _this.id = id;
  1636. _this.dom = dom;
  1637. var domStyle = dom.style;
  1638. if (domStyle) {
  1639. disableUserSelect(dom);
  1640. dom.onselectstart = function() {
  1641. return false;
  1642. };
  1643. domStyle.padding = "0";
  1644. domStyle.margin = "0";
  1645. domStyle.borderWidth = "0";
  1646. }
  1647. _this.painter = painter;
  1648. _this.dpr = dpr;
  1649. return _this;
  1650. }
  1651. Layer2.prototype.getElementCount = function() {
  1652. return this.__endIndex - this.__startIndex;
  1653. };
  1654. Layer2.prototype.afterBrush = function() {
  1655. this.__prevStartIndex = this.__startIndex;
  1656. this.__prevEndIndex = this.__endIndex;
  1657. };
  1658. Layer2.prototype.initContext = function() {
  1659. this.ctx = this.dom.getContext("2d");
  1660. this.ctx.dpr = this.dpr;
  1661. };
  1662. Layer2.prototype.setUnpainted = function() {
  1663. this.__firstTimePaint = true;
  1664. };
  1665. Layer2.prototype.createBackBuffer = function() {
  1666. var dpr = this.dpr;
  1667. this.domBack = createDom("back-" + this.id, this.painter, dpr);
  1668. this.ctxBack = this.domBack.getContext("2d");
  1669. if (dpr !== 1) {
  1670. this.ctxBack.scale(dpr, dpr);
  1671. }
  1672. };
  1673. Layer2.prototype.createRepaintRects = function(displayList, prevList, viewWidth, viewHeight) {
  1674. if (this.__firstTimePaint) {
  1675. this.__firstTimePaint = false;
  1676. return null;
  1677. }
  1678. var mergedRepaintRects = [];
  1679. var maxRepaintRectCount = this.maxRepaintRectCount;
  1680. var full = false;
  1681. var pendingRect = new BoundingRect_default(0, 0, 0, 0);
  1682. function addRectToMergePool(rect) {
  1683. if (!rect.isFinite() || rect.isZero()) {
  1684. return;
  1685. }
  1686. if (mergedRepaintRects.length === 0) {
  1687. var boundingRect = new BoundingRect_default(0, 0, 0, 0);
  1688. boundingRect.copy(rect);
  1689. mergedRepaintRects.push(boundingRect);
  1690. } else {
  1691. var isMerged = false;
  1692. var minDeltaArea = Infinity;
  1693. var bestRectToMergeIdx = 0;
  1694. for (var i2 = 0; i2 < mergedRepaintRects.length; ++i2) {
  1695. var mergedRect = mergedRepaintRects[i2];
  1696. if (mergedRect.intersect(rect)) {
  1697. var pendingRect_1 = new BoundingRect_default(0, 0, 0, 0);
  1698. pendingRect_1.copy(mergedRect);
  1699. pendingRect_1.union(rect);
  1700. mergedRepaintRects[i2] = pendingRect_1;
  1701. isMerged = true;
  1702. break;
  1703. } else if (full) {
  1704. pendingRect.copy(rect);
  1705. pendingRect.union(mergedRect);
  1706. var aArea = rect.width * rect.height;
  1707. var bArea = mergedRect.width * mergedRect.height;
  1708. var pendingArea = pendingRect.width * pendingRect.height;
  1709. var deltaArea = pendingArea - aArea - bArea;
  1710. if (deltaArea < minDeltaArea) {
  1711. minDeltaArea = deltaArea;
  1712. bestRectToMergeIdx = i2;
  1713. }
  1714. }
  1715. }
  1716. if (full) {
  1717. mergedRepaintRects[bestRectToMergeIdx].union(rect);
  1718. isMerged = true;
  1719. }
  1720. if (!isMerged) {
  1721. var boundingRect = new BoundingRect_default(0, 0, 0, 0);
  1722. boundingRect.copy(rect);
  1723. mergedRepaintRects.push(boundingRect);
  1724. }
  1725. if (!full) {
  1726. full = mergedRepaintRects.length >= maxRepaintRectCount;
  1727. }
  1728. }
  1729. }
  1730. for (var i = this.__startIndex; i < this.__endIndex; ++i) {
  1731. var el = displayList[i];
  1732. if (el) {
  1733. var shouldPaint = el.shouldBePainted(viewWidth, viewHeight, true, true);
  1734. var prevRect = el.__isRendered && (el.__dirty & REDRAW_BIT || !shouldPaint) ? el.getPrevPaintRect() : null;
  1735. if (prevRect) {
  1736. addRectToMergePool(prevRect);
  1737. }
  1738. var curRect = shouldPaint && (el.__dirty & REDRAW_BIT || !el.__isRendered) ? el.getPaintRect() : null;
  1739. if (curRect) {
  1740. addRectToMergePool(curRect);
  1741. }
  1742. }
  1743. }
  1744. for (var i = this.__prevStartIndex; i < this.__prevEndIndex; ++i) {
  1745. var el = prevList[i];
  1746. var shouldPaint = el && el.shouldBePainted(viewWidth, viewHeight, true, true);
  1747. if (el && (!shouldPaint || !el.__zr) && el.__isRendered) {
  1748. var prevRect = el.getPrevPaintRect();
  1749. if (prevRect) {
  1750. addRectToMergePool(prevRect);
  1751. }
  1752. }
  1753. }
  1754. var hasIntersections;
  1755. do {
  1756. hasIntersections = false;
  1757. for (var i = 0; i < mergedRepaintRects.length; ) {
  1758. if (mergedRepaintRects[i].isZero()) {
  1759. mergedRepaintRects.splice(i, 1);
  1760. continue;
  1761. }
  1762. for (var j = i + 1; j < mergedRepaintRects.length; ) {
  1763. if (mergedRepaintRects[i].intersect(mergedRepaintRects[j])) {
  1764. hasIntersections = true;
  1765. mergedRepaintRects[i].union(mergedRepaintRects[j]);
  1766. mergedRepaintRects.splice(j, 1);
  1767. } else {
  1768. j++;
  1769. }
  1770. }
  1771. i++;
  1772. }
  1773. } while (hasIntersections);
  1774. this._paintRects = mergedRepaintRects;
  1775. return mergedRepaintRects;
  1776. };
  1777. Layer2.prototype.debugGetPaintRects = function() {
  1778. return (this._paintRects || []).slice();
  1779. };
  1780. Layer2.prototype.resize = function(width, height) {
  1781. var dpr = this.dpr;
  1782. var dom = this.dom;
  1783. var domStyle = dom.style;
  1784. var domBack = this.domBack;
  1785. if (domStyle) {
  1786. domStyle.width = width + "px";
  1787. domStyle.height = height + "px";
  1788. }
  1789. dom.width = width * dpr;
  1790. dom.height = height * dpr;
  1791. if (domBack) {
  1792. domBack.width = width * dpr;
  1793. domBack.height = height * dpr;
  1794. if (dpr !== 1) {
  1795. this.ctxBack.scale(dpr, dpr);
  1796. }
  1797. }
  1798. };
  1799. Layer2.prototype.clear = function(clearAll, clearColor, repaintRects) {
  1800. var dom = this.dom;
  1801. var ctx = this.ctx;
  1802. var width = dom.width;
  1803. var height = dom.height;
  1804. clearColor = clearColor || this.clearColor;
  1805. var haveMotionBLur = this.motionBlur && !clearAll;
  1806. var lastFrameAlpha = this.lastFrameAlpha;
  1807. var dpr = this.dpr;
  1808. var self = this;
  1809. if (haveMotionBLur) {
  1810. if (!this.domBack) {
  1811. this.createBackBuffer();
  1812. }
  1813. this.ctxBack.globalCompositeOperation = "copy";
  1814. this.ctxBack.drawImage(dom, 0, 0, width / dpr, height / dpr);
  1815. }
  1816. var domBack = this.domBack;
  1817. function doClear(x, y, width2, height2) {
  1818. ctx.clearRect(x, y, width2, height2);
  1819. if (clearColor && clearColor !== "transparent") {
  1820. var clearColorGradientOrPattern = void 0;
  1821. if (isGradientObject(clearColor)) {
  1822. var shouldCache = clearColor.global || clearColor.__width === width2 && clearColor.__height === height2;
  1823. clearColorGradientOrPattern = shouldCache && clearColor.__canvasGradient || getCanvasGradient(ctx, clearColor, {
  1824. x: 0,
  1825. y: 0,
  1826. width: width2,
  1827. height: height2
  1828. });
  1829. clearColor.__canvasGradient = clearColorGradientOrPattern;
  1830. clearColor.__width = width2;
  1831. clearColor.__height = height2;
  1832. } else if (isImagePatternObject(clearColor)) {
  1833. clearColor.scaleX = clearColor.scaleX || dpr;
  1834. clearColor.scaleY = clearColor.scaleY || dpr;
  1835. clearColorGradientOrPattern = createCanvasPattern(ctx, clearColor, {
  1836. dirty: function() {
  1837. self.setUnpainted();
  1838. self.painter.refresh();
  1839. }
  1840. });
  1841. }
  1842. ctx.save();
  1843. ctx.fillStyle = clearColorGradientOrPattern || clearColor;
  1844. ctx.fillRect(x, y, width2, height2);
  1845. ctx.restore();
  1846. }
  1847. if (haveMotionBLur) {
  1848. ctx.save();
  1849. ctx.globalAlpha = lastFrameAlpha;
  1850. ctx.drawImage(domBack, x, y, width2, height2);
  1851. ctx.restore();
  1852. }
  1853. }
  1854. ;
  1855. if (!repaintRects || haveMotionBLur) {
  1856. doClear(0, 0, width, height);
  1857. } else if (repaintRects.length) {
  1858. each(repaintRects, function(rect) {
  1859. doClear(rect.x * dpr, rect.y * dpr, rect.width * dpr, rect.height * dpr);
  1860. });
  1861. }
  1862. };
  1863. return Layer2;
  1864. }(Eventful_default);
  1865. var Layer_default = Layer;
  1866. // node_modules/zrender/lib/canvas/Painter.js
  1867. var HOVER_LAYER_ZLEVEL = 1e5;
  1868. var CANVAS_ZLEVEL = 314159;
  1869. var EL_AFTER_INCREMENTAL_INC = 0.01;
  1870. var INCREMENTAL_INC = 1e-3;
  1871. function isLayerValid(layer) {
  1872. if (!layer) {
  1873. return false;
  1874. }
  1875. if (layer.__builtin__) {
  1876. return true;
  1877. }
  1878. if (typeof layer.resize !== "function" || typeof layer.refresh !== "function") {
  1879. return false;
  1880. }
  1881. return true;
  1882. }
  1883. function createRoot(width, height) {
  1884. var domRoot = document.createElement("div");
  1885. domRoot.style.cssText = [
  1886. "position:relative",
  1887. "width:" + width + "px",
  1888. "height:" + height + "px",
  1889. "padding:0",
  1890. "margin:0",
  1891. "border-width:0"
  1892. ].join(";") + ";";
  1893. return domRoot;
  1894. }
  1895. var CanvasPainter = function() {
  1896. function CanvasPainter2(root, storage, opts, id) {
  1897. this.type = "canvas";
  1898. this._zlevelList = [];
  1899. this._prevDisplayList = [];
  1900. this._layers = {};
  1901. this._layerConfig = {};
  1902. this._needsManuallyCompositing = false;
  1903. this.type = "canvas";
  1904. var singleCanvas = !root.nodeName || root.nodeName.toUpperCase() === "CANVAS";
  1905. this._opts = opts = extend({}, opts || {});
  1906. this.dpr = opts.devicePixelRatio || devicePixelRatio;
  1907. this._singleCanvas = singleCanvas;
  1908. this.root = root;
  1909. var rootStyle = root.style;
  1910. if (rootStyle) {
  1911. disableUserSelect(root);
  1912. root.innerHTML = "";
  1913. }
  1914. this.storage = storage;
  1915. var zlevelList = this._zlevelList;
  1916. this._prevDisplayList = [];
  1917. var layers = this._layers;
  1918. if (!singleCanvas) {
  1919. this._width = getSize(root, 0, opts);
  1920. this._height = getSize(root, 1, opts);
  1921. var domRoot = this._domRoot = createRoot(this._width, this._height);
  1922. root.appendChild(domRoot);
  1923. } else {
  1924. var rootCanvas = root;
  1925. var width = rootCanvas.width;
  1926. var height = rootCanvas.height;
  1927. if (opts.width != null) {
  1928. width = opts.width;
  1929. }
  1930. if (opts.height != null) {
  1931. height = opts.height;
  1932. }
  1933. this.dpr = opts.devicePixelRatio || 1;
  1934. rootCanvas.width = width * this.dpr;
  1935. rootCanvas.height = height * this.dpr;
  1936. this._width = width;
  1937. this._height = height;
  1938. var mainLayer = new Layer_default(rootCanvas, this, this.dpr);
  1939. mainLayer.__builtin__ = true;
  1940. mainLayer.initContext();
  1941. layers[CANVAS_ZLEVEL] = mainLayer;
  1942. mainLayer.zlevel = CANVAS_ZLEVEL;
  1943. zlevelList.push(CANVAS_ZLEVEL);
  1944. this._domRoot = root;
  1945. }
  1946. }
  1947. CanvasPainter2.prototype.getType = function() {
  1948. return "canvas";
  1949. };
  1950. CanvasPainter2.prototype.isSingleCanvas = function() {
  1951. return this._singleCanvas;
  1952. };
  1953. CanvasPainter2.prototype.getViewportRoot = function() {
  1954. return this._domRoot;
  1955. };
  1956. CanvasPainter2.prototype.getViewportRootOffset = function() {
  1957. var viewportRoot = this.getViewportRoot();
  1958. if (viewportRoot) {
  1959. return {
  1960. offsetLeft: viewportRoot.offsetLeft || 0,
  1961. offsetTop: viewportRoot.offsetTop || 0
  1962. };
  1963. }
  1964. };
  1965. CanvasPainter2.prototype.refresh = function(paintAll) {
  1966. var list = this.storage.getDisplayList(true);
  1967. var prevList = this._prevDisplayList;
  1968. var zlevelList = this._zlevelList;
  1969. this._redrawId = Math.random();
  1970. this._paintList(list, prevList, paintAll, this._redrawId);
  1971. for (var i = 0; i < zlevelList.length; i++) {
  1972. var z = zlevelList[i];
  1973. var layer = this._layers[z];
  1974. if (!layer.__builtin__ && layer.refresh) {
  1975. var clearColor = i === 0 ? this._backgroundColor : null;
  1976. layer.refresh(clearColor);
  1977. }
  1978. }
  1979. if (this._opts.useDirtyRect) {
  1980. this._prevDisplayList = list.slice();
  1981. }
  1982. return this;
  1983. };
  1984. CanvasPainter2.prototype.refreshHover = function() {
  1985. this._paintHoverList(this.storage.getDisplayList(false));
  1986. };
  1987. CanvasPainter2.prototype._paintHoverList = function(list) {
  1988. var len = list.length;
  1989. var hoverLayer = this._hoverlayer;
  1990. hoverLayer && hoverLayer.clear();
  1991. if (!len) {
  1992. return;
  1993. }
  1994. var scope = {
  1995. inHover: true,
  1996. viewWidth: this._width,
  1997. viewHeight: this._height
  1998. };
  1999. var ctx;
  2000. for (var i = 0; i < len; i++) {
  2001. var el = list[i];
  2002. if (el.__inHover) {
  2003. if (!hoverLayer) {
  2004. hoverLayer = this._hoverlayer = this.getLayer(HOVER_LAYER_ZLEVEL);
  2005. }
  2006. if (!ctx) {
  2007. ctx = hoverLayer.ctx;
  2008. ctx.save();
  2009. }
  2010. brush(ctx, el, scope, i === len - 1);
  2011. }
  2012. }
  2013. if (ctx) {
  2014. ctx.restore();
  2015. }
  2016. };
  2017. CanvasPainter2.prototype.getHoverLayer = function() {
  2018. return this.getLayer(HOVER_LAYER_ZLEVEL);
  2019. };
  2020. CanvasPainter2.prototype.paintOne = function(ctx, el) {
  2021. brushSingle(ctx, el);
  2022. };
  2023. CanvasPainter2.prototype._paintList = function(list, prevList, paintAll, redrawId) {
  2024. if (this._redrawId !== redrawId) {
  2025. return;
  2026. }
  2027. paintAll = paintAll || false;
  2028. this._updateLayerStatus(list);
  2029. var _a = this._doPaintList(list, prevList, paintAll), finished = _a.finished, needsRefreshHover = _a.needsRefreshHover;
  2030. if (this._needsManuallyCompositing) {
  2031. this._compositeManually();
  2032. }
  2033. if (needsRefreshHover) {
  2034. this._paintHoverList(list);
  2035. }
  2036. if (!finished) {
  2037. var self_1 = this;
  2038. requestAnimationFrame_default(function() {
  2039. self_1._paintList(list, prevList, paintAll, redrawId);
  2040. });
  2041. } else {
  2042. this.eachLayer(function(layer) {
  2043. layer.afterBrush && layer.afterBrush();
  2044. });
  2045. }
  2046. };
  2047. CanvasPainter2.prototype._compositeManually = function() {
  2048. var ctx = this.getLayer(CANVAS_ZLEVEL).ctx;
  2049. var width = this._domRoot.width;
  2050. var height = this._domRoot.height;
  2051. ctx.clearRect(0, 0, width, height);
  2052. this.eachBuiltinLayer(function(layer) {
  2053. if (layer.virtual) {
  2054. ctx.drawImage(layer.dom, 0, 0, width, height);
  2055. }
  2056. });
  2057. };
  2058. CanvasPainter2.prototype._doPaintList = function(list, prevList, paintAll) {
  2059. var _this = this;
  2060. var layerList = [];
  2061. var useDirtyRect = this._opts.useDirtyRect;
  2062. for (var zi = 0; zi < this._zlevelList.length; zi++) {
  2063. var zlevel = this._zlevelList[zi];
  2064. var layer = this._layers[zlevel];
  2065. if (layer.__builtin__ && layer !== this._hoverlayer && (layer.__dirty || paintAll)) {
  2066. layerList.push(layer);
  2067. }
  2068. }
  2069. var finished = true;
  2070. var needsRefreshHover = false;
  2071. var _loop_1 = function(k2) {
  2072. var layer2 = layerList[k2];
  2073. var ctx = layer2.ctx;
  2074. var repaintRects = useDirtyRect && layer2.createRepaintRects(list, prevList, this_1._width, this_1._height);
  2075. var start = paintAll ? layer2.__startIndex : layer2.__drawIndex;
  2076. var useTimer = !paintAll && layer2.incremental && Date.now;
  2077. var startTime = useTimer && Date.now();
  2078. var clearColor = layer2.zlevel === this_1._zlevelList[0] ? this_1._backgroundColor : null;
  2079. if (layer2.__startIndex === layer2.__endIndex) {
  2080. layer2.clear(false, clearColor, repaintRects);
  2081. } else if (start === layer2.__startIndex) {
  2082. var firstEl = list[start];
  2083. if (!firstEl.incremental || !firstEl.notClear || paintAll) {
  2084. layer2.clear(false, clearColor, repaintRects);
  2085. }
  2086. }
  2087. if (start === -1) {
  2088. console.error("For some unknown reason. drawIndex is -1");
  2089. start = layer2.__startIndex;
  2090. }
  2091. var i;
  2092. var repaint = function(repaintRect) {
  2093. var scope = {
  2094. inHover: false,
  2095. allClipped: false,
  2096. prevEl: null,
  2097. viewWidth: _this._width,
  2098. viewHeight: _this._height
  2099. };
  2100. for (i = start; i < layer2.__endIndex; i++) {
  2101. var el = list[i];
  2102. if (el.__inHover) {
  2103. needsRefreshHover = true;
  2104. }
  2105. _this._doPaintEl(el, layer2, useDirtyRect, repaintRect, scope, i === layer2.__endIndex - 1);
  2106. if (useTimer) {
  2107. var dTime = Date.now() - startTime;
  2108. if (dTime > 15) {
  2109. break;
  2110. }
  2111. }
  2112. }
  2113. if (scope.prevElClipPaths) {
  2114. ctx.restore();
  2115. }
  2116. };
  2117. if (repaintRects) {
  2118. if (repaintRects.length === 0) {
  2119. i = layer2.__endIndex;
  2120. } else {
  2121. var dpr = this_1.dpr;
  2122. for (var r = 0; r < repaintRects.length; ++r) {
  2123. var rect = repaintRects[r];
  2124. ctx.save();
  2125. ctx.beginPath();
  2126. ctx.rect(rect.x * dpr, rect.y * dpr, rect.width * dpr, rect.height * dpr);
  2127. ctx.clip();
  2128. repaint(rect);
  2129. ctx.restore();
  2130. }
  2131. }
  2132. } else {
  2133. ctx.save();
  2134. repaint();
  2135. ctx.restore();
  2136. }
  2137. layer2.__drawIndex = i;
  2138. if (layer2.__drawIndex < layer2.__endIndex) {
  2139. finished = false;
  2140. }
  2141. };
  2142. var this_1 = this;
  2143. for (var k = 0; k < layerList.length; k++) {
  2144. _loop_1(k);
  2145. }
  2146. if (env_default.wxa) {
  2147. each(this._layers, function(layer2) {
  2148. if (layer2 && layer2.ctx && layer2.ctx.draw) {
  2149. layer2.ctx.draw();
  2150. }
  2151. });
  2152. }
  2153. return {
  2154. finished,
  2155. needsRefreshHover
  2156. };
  2157. };
  2158. CanvasPainter2.prototype._doPaintEl = function(el, currentLayer, useDirtyRect, repaintRect, scope, isLast) {
  2159. var ctx = currentLayer.ctx;
  2160. if (useDirtyRect) {
  2161. var paintRect = el.getPaintRect();
  2162. if (!repaintRect || paintRect && paintRect.intersect(repaintRect)) {
  2163. brush(ctx, el, scope, isLast);
  2164. el.setPrevPaintRect(paintRect);
  2165. }
  2166. } else {
  2167. brush(ctx, el, scope, isLast);
  2168. }
  2169. };
  2170. CanvasPainter2.prototype.getLayer = function(zlevel, virtual) {
  2171. if (this._singleCanvas && !this._needsManuallyCompositing) {
  2172. zlevel = CANVAS_ZLEVEL;
  2173. }
  2174. var layer = this._layers[zlevel];
  2175. if (!layer) {
  2176. layer = new Layer_default("zr_" + zlevel, this, this.dpr);
  2177. layer.zlevel = zlevel;
  2178. layer.__builtin__ = true;
  2179. if (this._layerConfig[zlevel]) {
  2180. merge(layer, this._layerConfig[zlevel], true);
  2181. } else if (this._layerConfig[zlevel - EL_AFTER_INCREMENTAL_INC]) {
  2182. merge(layer, this._layerConfig[zlevel - EL_AFTER_INCREMENTAL_INC], true);
  2183. }
  2184. if (virtual) {
  2185. layer.virtual = virtual;
  2186. }
  2187. this.insertLayer(zlevel, layer);
  2188. layer.initContext();
  2189. }
  2190. return layer;
  2191. };
  2192. CanvasPainter2.prototype.insertLayer = function(zlevel, layer) {
  2193. var layersMap = this._layers;
  2194. var zlevelList = this._zlevelList;
  2195. var len = zlevelList.length;
  2196. var domRoot = this._domRoot;
  2197. var prevLayer = null;
  2198. var i = -1;
  2199. if (layersMap[zlevel]) {
  2200. if (true) {
  2201. logError("ZLevel " + zlevel + " has been used already");
  2202. }
  2203. return;
  2204. }
  2205. if (!isLayerValid(layer)) {
  2206. if (true) {
  2207. logError("Layer of zlevel " + zlevel + " is not valid");
  2208. }
  2209. return;
  2210. }
  2211. if (len > 0 && zlevel > zlevelList[0]) {
  2212. for (i = 0; i < len - 1; i++) {
  2213. if (zlevelList[i] < zlevel && zlevelList[i + 1] > zlevel) {
  2214. break;
  2215. }
  2216. }
  2217. prevLayer = layersMap[zlevelList[i]];
  2218. }
  2219. zlevelList.splice(i + 1, 0, zlevel);
  2220. layersMap[zlevel] = layer;
  2221. if (!layer.virtual) {
  2222. if (prevLayer) {
  2223. var prevDom = prevLayer.dom;
  2224. if (prevDom.nextSibling) {
  2225. domRoot.insertBefore(layer.dom, prevDom.nextSibling);
  2226. } else {
  2227. domRoot.appendChild(layer.dom);
  2228. }
  2229. } else {
  2230. if (domRoot.firstChild) {
  2231. domRoot.insertBefore(layer.dom, domRoot.firstChild);
  2232. } else {
  2233. domRoot.appendChild(layer.dom);
  2234. }
  2235. }
  2236. }
  2237. layer.painter || (layer.painter = this);
  2238. };
  2239. CanvasPainter2.prototype.eachLayer = function(cb, context) {
  2240. var zlevelList = this._zlevelList;
  2241. for (var i = 0; i < zlevelList.length; i++) {
  2242. var z = zlevelList[i];
  2243. cb.call(context, this._layers[z], z);
  2244. }
  2245. };
  2246. CanvasPainter2.prototype.eachBuiltinLayer = function(cb, context) {
  2247. var zlevelList = this._zlevelList;
  2248. for (var i = 0; i < zlevelList.length; i++) {
  2249. var z = zlevelList[i];
  2250. var layer = this._layers[z];
  2251. if (layer.__builtin__) {
  2252. cb.call(context, layer, z);
  2253. }
  2254. }
  2255. };
  2256. CanvasPainter2.prototype.eachOtherLayer = function(cb, context) {
  2257. var zlevelList = this._zlevelList;
  2258. for (var i = 0; i < zlevelList.length; i++) {
  2259. var z = zlevelList[i];
  2260. var layer = this._layers[z];
  2261. if (!layer.__builtin__) {
  2262. cb.call(context, layer, z);
  2263. }
  2264. }
  2265. };
  2266. CanvasPainter2.prototype.getLayers = function() {
  2267. return this._layers;
  2268. };
  2269. CanvasPainter2.prototype._updateLayerStatus = function(list) {
  2270. this.eachBuiltinLayer(function(layer2, z) {
  2271. layer2.__dirty = layer2.__used = false;
  2272. });
  2273. function updatePrevLayer(idx) {
  2274. if (prevLayer) {
  2275. if (prevLayer.__endIndex !== idx) {
  2276. prevLayer.__dirty = true;
  2277. }
  2278. prevLayer.__endIndex = idx;
  2279. }
  2280. }
  2281. if (this._singleCanvas) {
  2282. for (var i_1 = 1; i_1 < list.length; i_1++) {
  2283. var el = list[i_1];
  2284. if (el.zlevel !== list[i_1 - 1].zlevel || el.incremental) {
  2285. this._needsManuallyCompositing = true;
  2286. break;
  2287. }
  2288. }
  2289. }
  2290. var prevLayer = null;
  2291. var incrementalLayerCount = 0;
  2292. var prevZlevel;
  2293. var i;
  2294. for (i = 0; i < list.length; i++) {
  2295. var el = list[i];
  2296. var zlevel = el.zlevel;
  2297. var layer = void 0;
  2298. if (prevZlevel !== zlevel) {
  2299. prevZlevel = zlevel;
  2300. incrementalLayerCount = 0;
  2301. }
  2302. if (el.incremental) {
  2303. layer = this.getLayer(zlevel + INCREMENTAL_INC, this._needsManuallyCompositing);
  2304. layer.incremental = true;
  2305. incrementalLayerCount = 1;
  2306. } else {
  2307. layer = this.getLayer(zlevel + (incrementalLayerCount > 0 ? EL_AFTER_INCREMENTAL_INC : 0), this._needsManuallyCompositing);
  2308. }
  2309. if (!layer.__builtin__) {
  2310. logError("ZLevel " + zlevel + " has been used by unkown layer " + layer.id);
  2311. }
  2312. if (layer !== prevLayer) {
  2313. layer.__used = true;
  2314. if (layer.__startIndex !== i) {
  2315. layer.__dirty = true;
  2316. }
  2317. layer.__startIndex = i;
  2318. if (!layer.incremental) {
  2319. layer.__drawIndex = i;
  2320. } else {
  2321. layer.__drawIndex = -1;
  2322. }
  2323. updatePrevLayer(i);
  2324. prevLayer = layer;
  2325. }
  2326. if (el.__dirty & REDRAW_BIT && !el.__inHover) {
  2327. layer.__dirty = true;
  2328. if (layer.incremental && layer.__drawIndex < 0) {
  2329. layer.__drawIndex = i;
  2330. }
  2331. }
  2332. }
  2333. updatePrevLayer(i);
  2334. this.eachBuiltinLayer(function(layer2, z) {
  2335. if (!layer2.__used && layer2.getElementCount() > 0) {
  2336. layer2.__dirty = true;
  2337. layer2.__startIndex = layer2.__endIndex = layer2.__drawIndex = 0;
  2338. }
  2339. if (layer2.__dirty && layer2.__drawIndex < 0) {
  2340. layer2.__drawIndex = layer2.__startIndex;
  2341. }
  2342. });
  2343. };
  2344. CanvasPainter2.prototype.clear = function() {
  2345. this.eachBuiltinLayer(this._clearLayer);
  2346. return this;
  2347. };
  2348. CanvasPainter2.prototype._clearLayer = function(layer) {
  2349. layer.clear();
  2350. };
  2351. CanvasPainter2.prototype.setBackgroundColor = function(backgroundColor) {
  2352. this._backgroundColor = backgroundColor;
  2353. each(this._layers, function(layer) {
  2354. layer.setUnpainted();
  2355. });
  2356. };
  2357. CanvasPainter2.prototype.configLayer = function(zlevel, config) {
  2358. if (config) {
  2359. var layerConfig = this._layerConfig;
  2360. if (!layerConfig[zlevel]) {
  2361. layerConfig[zlevel] = config;
  2362. } else {
  2363. merge(layerConfig[zlevel], config, true);
  2364. }
  2365. for (var i = 0; i < this._zlevelList.length; i++) {
  2366. var _zlevel = this._zlevelList[i];
  2367. if (_zlevel === zlevel || _zlevel === zlevel + EL_AFTER_INCREMENTAL_INC) {
  2368. var layer = this._layers[_zlevel];
  2369. merge(layer, layerConfig[zlevel], true);
  2370. }
  2371. }
  2372. }
  2373. };
  2374. CanvasPainter2.prototype.delLayer = function(zlevel) {
  2375. var layers = this._layers;
  2376. var zlevelList = this._zlevelList;
  2377. var layer = layers[zlevel];
  2378. if (!layer) {
  2379. return;
  2380. }
  2381. layer.dom.parentNode.removeChild(layer.dom);
  2382. delete layers[zlevel];
  2383. zlevelList.splice(indexOf(zlevelList, zlevel), 1);
  2384. };
  2385. CanvasPainter2.prototype.resize = function(width, height) {
  2386. if (!this._domRoot.style) {
  2387. if (width == null || height == null) {
  2388. return;
  2389. }
  2390. this._width = width;
  2391. this._height = height;
  2392. this.getLayer(CANVAS_ZLEVEL).resize(width, height);
  2393. } else {
  2394. var domRoot = this._domRoot;
  2395. domRoot.style.display = "none";
  2396. var opts = this._opts;
  2397. var root = this.root;
  2398. width != null && (opts.width = width);
  2399. height != null && (opts.height = height);
  2400. width = getSize(root, 0, opts);
  2401. height = getSize(root, 1, opts);
  2402. domRoot.style.display = "";
  2403. if (this._width !== width || height !== this._height) {
  2404. domRoot.style.width = width + "px";
  2405. domRoot.style.height = height + "px";
  2406. for (var id in this._layers) {
  2407. if (this._layers.hasOwnProperty(id)) {
  2408. this._layers[id].resize(width, height);
  2409. }
  2410. }
  2411. this.refresh(true);
  2412. }
  2413. this._width = width;
  2414. this._height = height;
  2415. }
  2416. return this;
  2417. };
  2418. CanvasPainter2.prototype.clearLayer = function(zlevel) {
  2419. var layer = this._layers[zlevel];
  2420. if (layer) {
  2421. layer.clear();
  2422. }
  2423. };
  2424. CanvasPainter2.prototype.dispose = function() {
  2425. this.root.innerHTML = "";
  2426. this.root = this.storage = this._domRoot = this._layers = null;
  2427. };
  2428. CanvasPainter2.prototype.getRenderedCanvas = function(opts) {
  2429. opts = opts || {};
  2430. if (this._singleCanvas && !this._compositeManually) {
  2431. return this._layers[CANVAS_ZLEVEL].dom;
  2432. }
  2433. var imageLayer = new Layer_default("image", this, opts.pixelRatio || this.dpr);
  2434. imageLayer.initContext();
  2435. imageLayer.clear(false, opts.backgroundColor || this._backgroundColor);
  2436. var ctx = imageLayer.ctx;
  2437. if (opts.pixelRatio <= this.dpr) {
  2438. this.refresh();
  2439. var width_1 = imageLayer.dom.width;
  2440. var height_1 = imageLayer.dom.height;
  2441. this.eachLayer(function(layer) {
  2442. if (layer.__builtin__) {
  2443. ctx.drawImage(layer.dom, 0, 0, width_1, height_1);
  2444. } else if (layer.renderToCanvas) {
  2445. ctx.save();
  2446. layer.renderToCanvas(ctx);
  2447. ctx.restore();
  2448. }
  2449. });
  2450. } else {
  2451. var scope = {
  2452. inHover: false,
  2453. viewWidth: this._width,
  2454. viewHeight: this._height
  2455. };
  2456. var displayList = this.storage.getDisplayList(true);
  2457. for (var i = 0, len = displayList.length; i < len; i++) {
  2458. var el = displayList[i];
  2459. brush(ctx, el, scope, i === len - 1);
  2460. }
  2461. }
  2462. return imageLayer.dom;
  2463. };
  2464. CanvasPainter2.prototype.getWidth = function() {
  2465. return this._width;
  2466. };
  2467. CanvasPainter2.prototype.getHeight = function() {
  2468. return this._height;
  2469. };
  2470. return CanvasPainter2;
  2471. }();
  2472. var Painter_default2 = CanvasPainter;
  2473. // node_modules/echarts/lib/renderer/installCanvasRenderer.js
  2474. function install2(registers) {
  2475. registers.registerPainter("canvas", Painter_default2);
  2476. }
  2477. export {
  2478. install2 as CanvasRenderer,
  2479. install as SVGRenderer
  2480. };
  2481. //# sourceMappingURL=echarts_renderers.js.map