q2-tecton-elements 1.21.1 → 1.22.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (152) hide show
  1. package/dist/cjs/installCanvasRenderer-b4d10c92.js +38433 -0
  2. package/dist/cjs/loader.cjs.js +1 -1
  3. package/dist/cjs/q2-badge_2.cjs.entry.js +6 -4
  4. package/dist/cjs/q2-calendar.cjs.entry.js +75 -55
  5. package/dist/cjs/q2-carousel.cjs.entry.js +3 -3
  6. package/dist/cjs/q2-chart-bar.cjs.entry.js +4679 -0
  7. package/dist/cjs/q2-chart-donut.cjs.entry.js +357 -35592
  8. package/dist/cjs/q2-checkbox.cjs.entry.js +1 -1
  9. package/dist/cjs/q2-editable-field.cjs.entry.js +1 -1
  10. package/dist/cjs/q2-radio.cjs.entry.js +1 -1
  11. package/dist/cjs/q2-tecton-elements.cjs.js +1 -1
  12. package/dist/collection/collection-manifest.json +1 -0
  13. package/dist/collection/components/q2-calendar/index.js +43 -2
  14. package/dist/collection/components/q2-chart-bar/index.js +466 -0
  15. package/dist/collection/components/q2-chart-bar/styles.css +85 -0
  16. package/dist/collection/components/q2-chart-donut/index.js +3 -3
  17. package/dist/collection/components/q2-checkbox/styles.css +5 -1
  18. package/dist/collection/components/q2-editable-field/styles.css +1 -1
  19. package/dist/collection/components/q2-input/formatting/phone.js +3 -3
  20. package/dist/collection/components/q2-input/index.js +21 -0
  21. package/dist/collection/components/q2-input/styles.css +2 -2
  22. package/dist/collection/components/q2-radio/styles.css +1 -1
  23. package/dist/collection/utils/charting.js +182 -0
  24. package/dist/components/click-elsewhere.d.ts +11 -0
  25. package/dist/components/click-elsewhere.js +6 -0
  26. package/dist/components/index.d.ts +62 -0
  27. package/dist/components/index.js +42 -0
  28. package/dist/components/index10.js +84 -0
  29. package/dist/components/index11.js +383 -0
  30. package/dist/components/index12.js +125 -0
  31. package/dist/components/index13.js +602 -0
  32. package/dist/components/index2.js +100 -0
  33. package/dist/components/index3.js +90 -0
  34. package/dist/components/index4.js +62 -0
  35. package/dist/components/index5.js +146 -0
  36. package/dist/components/index6.js +145 -0
  37. package/dist/components/index7.js +2960 -0
  38. package/dist/components/index8.js +3356 -0
  39. package/dist/components/index9.js +101 -0
  40. package/dist/components/installCanvasRenderer.js +38282 -0
  41. package/dist/components/q2-avatar.d.ts +11 -0
  42. package/dist/components/q2-avatar.js +6 -0
  43. package/dist/components/q2-badge.d.ts +11 -0
  44. package/dist/components/q2-badge.js +6 -0
  45. package/dist/components/q2-btn.d.ts +11 -0
  46. package/dist/components/q2-btn.js +6 -0
  47. package/dist/components/q2-calendar.d.ts +11 -0
  48. package/dist/components/q2-calendar.js +3755 -0
  49. package/dist/components/q2-card.d.ts +11 -0
  50. package/dist/components/q2-card.js +187 -0
  51. package/dist/components/q2-carousel-pane.d.ts +11 -0
  52. package/dist/components/q2-carousel-pane.js +97 -0
  53. package/dist/components/q2-carousel.d.ts +11 -0
  54. package/dist/components/q2-carousel.js +5379 -0
  55. package/dist/components/q2-chart-bar.d.ts +11 -0
  56. package/dist/components/q2-chart-bar.js +4710 -0
  57. package/dist/components/q2-chart-donut.d.ts +11 -0
  58. package/dist/components/q2-chart-donut.js +4887 -0
  59. package/dist/components/q2-checkbox-group.d.ts +11 -0
  60. package/dist/components/q2-checkbox-group.js +114 -0
  61. package/dist/components/q2-checkbox.d.ts +11 -0
  62. package/dist/components/q2-checkbox.js +138 -0
  63. package/dist/components/q2-dropdown-item.d.ts +11 -0
  64. package/dist/components/q2-dropdown-item.js +6 -0
  65. package/dist/components/q2-dropdown.d.ts +11 -0
  66. package/dist/components/q2-dropdown.js +345 -0
  67. package/dist/components/q2-editable-field.d.ts +11 -0
  68. package/dist/components/q2-editable-field.js +220 -0
  69. package/dist/components/q2-icon.d.ts +11 -0
  70. package/dist/components/q2-icon.js +6 -0
  71. package/dist/components/q2-input.d.ts +11 -0
  72. package/dist/components/q2-input.js +6 -0
  73. package/dist/components/q2-loading-element.d.ts +11 -0
  74. package/dist/components/q2-loading-element.js +52 -0
  75. package/dist/components/q2-loading.d.ts +11 -0
  76. package/dist/components/q2-loading.js +6 -0
  77. package/dist/components/q2-loc.d.ts +11 -0
  78. package/dist/components/q2-loc.js +40 -0
  79. package/dist/components/q2-message.d.ts +11 -0
  80. package/dist/components/q2-message.js +6 -0
  81. package/dist/components/q2-month-picker.d.ts +11 -0
  82. package/dist/components/q2-month-picker.js +189 -0
  83. package/dist/components/q2-optgroup.d.ts +11 -0
  84. package/dist/components/q2-optgroup.js +75 -0
  85. package/dist/components/q2-option-list.d.ts +11 -0
  86. package/dist/components/q2-option-list.js +6 -0
  87. package/dist/components/q2-option.d.ts +11 -0
  88. package/dist/components/q2-option.js +81 -0
  89. package/dist/components/q2-pagination.d.ts +11 -0
  90. package/dist/components/q2-pagination.js +184 -0
  91. package/dist/components/q2-pill.d.ts +11 -0
  92. package/dist/components/q2-pill.js +216 -0
  93. package/dist/components/q2-popover.d.ts +11 -0
  94. package/dist/components/q2-popover.js +6 -0
  95. package/dist/components/q2-radio-group.d.ts +11 -0
  96. package/dist/components/q2-radio-group.js +191 -0
  97. package/dist/components/q2-radio.d.ts +11 -0
  98. package/dist/components/q2-radio.js +105 -0
  99. package/dist/components/q2-section.d.ts +11 -0
  100. package/dist/components/q2-section.js +218 -0
  101. package/dist/components/q2-select.d.ts +11 -0
  102. package/dist/components/q2-select.js +817 -0
  103. package/dist/components/q2-stepper-pane.d.ts +11 -0
  104. package/dist/components/q2-stepper-pane.js +92 -0
  105. package/dist/components/q2-stepper-vertical.d.ts +11 -0
  106. package/dist/components/q2-stepper-vertical.js +311 -0
  107. package/dist/components/q2-stepper.d.ts +11 -0
  108. package/dist/components/q2-stepper.js +252 -0
  109. package/dist/components/q2-tab-container.d.ts +11 -0
  110. package/dist/components/q2-tab-container.js +288 -0
  111. package/dist/components/q2-tab-pane.d.ts +11 -0
  112. package/dist/components/q2-tab-pane.js +58 -0
  113. package/dist/components/q2-tag.d.ts +11 -0
  114. package/dist/components/q2-tag.js +156 -0
  115. package/dist/components/q2-textarea.d.ts +11 -0
  116. package/dist/components/q2-textarea.js +265 -0
  117. package/dist/components/q2-tooltip.d.ts +11 -0
  118. package/dist/components/q2-tooltip.js +112 -0
  119. package/dist/components/shapes.js +91 -0
  120. package/dist/components/tecton-tab-pane.d.ts +11 -0
  121. package/dist/components/tecton-tab-pane.js +111 -0
  122. package/dist/esm/installCanvasRenderer-0143b52d.js +38282 -0
  123. package/dist/esm/loader.js +1 -1
  124. package/dist/esm/q2-badge_2.entry.js +6 -4
  125. package/dist/esm/q2-calendar.entry.js +75 -55
  126. package/dist/esm/q2-carousel.entry.js +3 -3
  127. package/dist/esm/q2-chart-bar.entry.js +4675 -0
  128. package/dist/esm/q2-chart-donut.entry.js +171 -35406
  129. package/dist/esm/q2-checkbox.entry.js +1 -1
  130. package/dist/esm/q2-editable-field.entry.js +1 -1
  131. package/dist/esm/q2-radio.entry.js +1 -1
  132. package/dist/esm/q2-tecton-elements.js +1 -1
  133. package/dist/q2-tecton-elements/p-1f85cced.js +39 -0
  134. package/dist/q2-tecton-elements/{p-89608314.entry.js → p-4625184b.entry.js} +1 -1
  135. package/dist/q2-tecton-elements/{p-9772b15f.entry.js → p-520c40f6.entry.js} +1 -1
  136. package/dist/q2-tecton-elements/p-6b52a262.entry.js +1 -0
  137. package/dist/q2-tecton-elements/p-c4640b55.entry.js +1 -0
  138. package/dist/q2-tecton-elements/{p-7e8f43d1.entry.js → p-cf41970f.entry.js} +1 -1
  139. package/dist/q2-tecton-elements/p-e4dc9ac0.entry.js +1 -0
  140. package/dist/q2-tecton-elements/p-f35bf6a3.entry.js +1 -0
  141. package/dist/q2-tecton-elements/q2-tecton-elements.esm.js +1 -1
  142. package/dist/types/components/q2-calendar/index.d.ts +3 -0
  143. package/dist/types/components/q2-chart-bar/index.d.ts +40 -0
  144. package/dist/types/components/q2-chart-donut/index.d.ts +7 -10
  145. package/dist/types/components/q2-input/index.d.ts +1 -0
  146. package/dist/types/components.d.ts +50 -3
  147. package/dist/types/utils/charting.d.ts +14 -0
  148. package/package.json +5 -2
  149. package/dist/q2-tecton-elements/p-0766a694.entry.js +0 -1
  150. package/dist/q2-tecton-elements/p-35177f6c.entry.js +0 -1
  151. package/dist/q2-tecton-elements/p-5f064e1e.entry.js +0 -39
  152. /package/dist/types/workspace/workspace/{tecton-production_release_1.21.x → Tecton_tecton-production_master}/packages/q2-tecton-elements/.stencil/test/helpers.d.ts +0 -0
@@ -0,0 +1,4887 @@
1
+ import { proxyCustomElement, HTMLElement, createEvent, h } from '@stencil/core/internal/client';
2
+ import { o as overrideFocus, l as loc, i as isEventFromElement } from './index13.js';
3
+ import { d as defineCustomElement$3 } from './index2.js';
4
+ import { d as defineCustomElement$2 } from './index7.js';
5
+ import { aG as normalizeCssArray, Z as Rect, _ as __extends, w as ComponentModel, aH as toCamelCase, aI as env, aJ as normalizeEvent, aK as convertToColorString, ai as isString, j as isArray, aL as isDom, e as each$1, aM as bind, P as indexOf, aN as getPaddingFromTooltipModel, aO as transformLocalCoord, N as isObject, aP as throwError, ab as ZRText, aQ as getTooltipRenderMode, aR as createOrUpdate, aS as clear, aT as register, ae as getECData, aU as findPointFromSeries, aV as findEventDispatcher, aW as createTooltipMarkup, aX as getValueLabel, aY as trim, aZ as getAxisRawValue, a_ as normalizeTooltipFormatResult, a$ as buildTooltipMarkup, b0 as clone, b1 as format, b2 as formatTpl, i as isFunction, b3 as parsePercent, L as getLayoutRect, b4 as unregister, a7 as ComponentView, b5 as Model, b6 as preParseFinder, b7 as queryReferringComponents, b8 as TooltipMarkupStyleCreator, a2 as extend, a8 as use, a9 as install$5, b9 as noop, y as merge, ba as isNameSpecified, c as createHashMap, g as map, E as filter, an as isNumber, z as defaults, bb as parse, bc as stringify, av as setLabelStyle, bd as enableHoverEmphasis, ac as createTextStyle, be as setTooltipConfig, bf as box, bg as createOrUpdatePatternFromDecal, bh as createSymbol, b as curry$1, $ as Group$2, A as getLayoutParams, ak as inheritDefaultOption, B as mergeLayoutParam, bi as createIcon, aa as retrieve2, ap as updateProps, u as linearMap, bj as Point, bk as limitTurnAngle, bl as limitSurfaceAngle, bm as shiftLayoutOnY, bn as parsePercent$1, ag as initProps, aq as saveOldStyle, ay as setStatesStylesFromModel, ax as toggleHoverEmphasis, au as getLabelStatesModels, bo as Polyline, bp as setLabelLineStyle, bq as retrieve3, br as getLabelLineStatesModels, ah as Sector, as as removeElementWithFadeOut, at as ChartView, p as prepareSeriesDataSchema, f as SeriesData, n as makeInner, bs as makeSeriesEncodeForNameBased, bt as getPercentSeats, bu as defaultEmphasis, aj as SeriesModel, bv as createLegacyDataSelectAction, aD as install$6, aC as install$7, aE as installLabelLayout, aF as init } from './installCanvasRenderer.js';
6
+
7
+ function makeBackground(rect, componentModel) {
8
+ var padding = normalizeCssArray(componentModel.get('padding'));
9
+ var style = componentModel.getItemStyle(['color', 'opacity']);
10
+ style.fill = componentModel.get('backgroundColor');
11
+ rect = new Rect({
12
+ shape: {
13
+ x: rect.x - padding[3],
14
+ y: rect.y - padding[0],
15
+ width: rect.width + padding[1] + padding[3],
16
+ height: rect.height + padding[0] + padding[2],
17
+ r: componentModel.get('borderRadius')
18
+ },
19
+ style: style,
20
+ silent: true,
21
+ z2: -1
22
+ }); // FIXME
23
+ // `subPixelOptimizeRect` may bring some gap between edge of viewpart
24
+ // and background rect when setting like `left: 0`, `top: 0`.
25
+ // graphic.subPixelOptimizeRect(rect);
26
+
27
+ return rect;
28
+ }
29
+
30
+ var TooltipModel =
31
+ /** @class */
32
+ function (_super) {
33
+ __extends(TooltipModel, _super);
34
+
35
+ function TooltipModel() {
36
+ var _this = _super !== null && _super.apply(this, arguments) || this;
37
+
38
+ _this.type = TooltipModel.type;
39
+ return _this;
40
+ }
41
+
42
+ TooltipModel.type = 'tooltip';
43
+ TooltipModel.dependencies = ['axisPointer'];
44
+ TooltipModel.defaultOption = {
45
+ // zlevel: 0,
46
+ z: 60,
47
+ show: true,
48
+ // tooltip main content
49
+ showContent: true,
50
+ // 'trigger' only works on coordinate system.
51
+ // 'item' | 'axis' | 'none'
52
+ trigger: 'item',
53
+ // 'click' | 'mousemove' | 'none'
54
+ triggerOn: 'mousemove|click',
55
+ alwaysShowContent: false,
56
+ displayMode: 'single',
57
+ renderMode: 'auto',
58
+ // whether restraint content inside viewRect.
59
+ // If renderMode: 'richText', default true.
60
+ // If renderMode: 'html', defaut false (for backward compat).
61
+ confine: null,
62
+ showDelay: 0,
63
+ hideDelay: 100,
64
+ // Animation transition time, unit is second
65
+ transitionDuration: 0.4,
66
+ enterable: false,
67
+ backgroundColor: '#fff',
68
+ // box shadow
69
+ shadowBlur: 10,
70
+ shadowColor: 'rgba(0, 0, 0, .2)',
71
+ shadowOffsetX: 1,
72
+ shadowOffsetY: 2,
73
+ // tooltip border radius, unit is px, default is 4
74
+ borderRadius: 4,
75
+ // tooltip border width, unit is px, default is 0 (no border)
76
+ borderWidth: 1,
77
+ // Tooltip inside padding, default is 5 for all direction
78
+ // Array is allowed to set up, right, bottom, left, same with css
79
+ // The default value: See `tooltip/tooltipMarkup.ts#getPaddingFromTooltipModel`.
80
+ padding: null,
81
+ // Extra css text
82
+ extraCssText: '',
83
+ // axis indicator, trigger by axis
84
+ axisPointer: {
85
+ // default is line
86
+ // legal values: 'line' | 'shadow' | 'cross'
87
+ type: 'line',
88
+ // Valid when type is line, appoint tooltip line locate on which line. Optional
89
+ // legal values: 'x' | 'y' | 'angle' | 'radius' | 'auto'
90
+ // default is 'auto', chose the axis which type is category.
91
+ // for multiply y axis, cartesian coord chose x axis, polar chose angle axis
92
+ axis: 'auto',
93
+ animation: 'auto',
94
+ animationDurationUpdate: 200,
95
+ animationEasingUpdate: 'exponentialOut',
96
+ crossStyle: {
97
+ color: '#999',
98
+ width: 1,
99
+ type: 'dashed',
100
+ // TODO formatter
101
+ textStyle: {}
102
+ } // lineStyle and shadowStyle should not be specified here,
103
+ // otherwise it will always override those styles on option.axisPointer.
104
+
105
+ },
106
+ textStyle: {
107
+ color: '#666',
108
+ fontSize: 14
109
+ }
110
+ };
111
+ return TooltipModel;
112
+ }(ComponentModel);
113
+
114
+ /* global document */
115
+
116
+ function shouldTooltipConfine(tooltipModel) {
117
+ var confineOption = tooltipModel.get('confine');
118
+ return confineOption != null ? !!confineOption // In richText mode, the outside part can not be visible.
119
+ : tooltipModel.get('renderMode') === 'richText';
120
+ }
121
+
122
+ function testStyle(styleProps) {
123
+ if (!env.domSupported) {
124
+ return;
125
+ }
126
+
127
+ var style = document.documentElement.style;
128
+
129
+ for (var i = 0, len = styleProps.length; i < len; i++) {
130
+ if (styleProps[i] in style) {
131
+ return styleProps[i];
132
+ }
133
+ }
134
+ }
135
+
136
+ var TRANSFORM_VENDOR = testStyle(['transform', 'webkitTransform', 'OTransform', 'MozTransform', 'msTransform']);
137
+ var TRANSITION_VENDOR = testStyle(['webkitTransition', 'transition', 'OTransition', 'MozTransition', 'msTransition']);
138
+ function toCSSVendorPrefix(styleVendor, styleProp) {
139
+ if (!styleVendor) {
140
+ return styleProp;
141
+ }
142
+
143
+ styleProp = toCamelCase(styleProp, true);
144
+ var idx = styleVendor.indexOf(styleProp);
145
+ styleVendor = idx === -1 ? styleProp : "-" + styleVendor.slice(0, idx) + "-" + styleProp;
146
+ return styleVendor.toLowerCase();
147
+ }
148
+ function getComputedStyle$1(el, style) {
149
+ var stl = el.currentStyle || document.defaultView && document.defaultView.getComputedStyle(el);
150
+ return stl ? style ? stl[style] : stl : null;
151
+ }
152
+
153
+ /* global document, window */
154
+
155
+ var CSS_TRANSITION_VENDOR = toCSSVendorPrefix(TRANSITION_VENDOR, 'transition');
156
+ var CSS_TRANSFORM_VENDOR = toCSSVendorPrefix(TRANSFORM_VENDOR, 'transform'); // eslint-disable-next-line
157
+
158
+ var gCssText = "position:absolute;display:block;border-style:solid;white-space:nowrap;z-index:9999999;" + (env.transform3dSupported ? 'will-change:transform;' : '');
159
+
160
+ function mirrorPos(pos) {
161
+ pos = pos === 'left' ? 'right' : pos === 'right' ? 'left' : pos === 'top' ? 'bottom' : 'top';
162
+ return pos;
163
+ }
164
+
165
+ function assembleArrow(tooltipModel, borderColor, arrowPosition) {
166
+ if (!isString(arrowPosition) || arrowPosition === 'inside') {
167
+ return '';
168
+ }
169
+
170
+ var backgroundColor = tooltipModel.get('backgroundColor');
171
+ var borderWidth = tooltipModel.get('borderWidth');
172
+ borderColor = convertToColorString(borderColor);
173
+ var arrowPos = mirrorPos(arrowPosition);
174
+ var arrowSize = Math.max(Math.round(borderWidth) * 1.5, 6);
175
+ var positionStyle = '';
176
+ var transformStyle = CSS_TRANSFORM_VENDOR + ':';
177
+ var rotateDeg;
178
+
179
+ if (indexOf(['left', 'right'], arrowPos) > -1) {
180
+ positionStyle += 'top:50%';
181
+ transformStyle += "translateY(-50%) rotate(" + (rotateDeg = arrowPos === 'left' ? -225 : -45) + "deg)";
182
+ } else {
183
+ positionStyle += 'left:50%';
184
+ transformStyle += "translateX(-50%) rotate(" + (rotateDeg = arrowPos === 'top' ? 225 : 45) + "deg)";
185
+ }
186
+
187
+ var rotateRadian = rotateDeg * Math.PI / 180;
188
+ var arrowWH = arrowSize + borderWidth;
189
+ var rotatedWH = arrowWH * Math.abs(Math.cos(rotateRadian)) + arrowWH * Math.abs(Math.sin(rotateRadian));
190
+ var arrowOffset = Math.round(((rotatedWH - Math.SQRT2 * borderWidth) / 2 + Math.SQRT2 * borderWidth - (rotatedWH - arrowWH) / 2) * 100) / 100;
191
+ positionStyle += ";" + arrowPos + ":-" + arrowOffset + "px";
192
+ var borderStyle = borderColor + " solid " + borderWidth + "px;";
193
+ var styleCss = ["position:absolute;width:" + arrowSize + "px;height:" + arrowSize + "px;z-index:-1;", positionStyle + ";" + transformStyle + ";", "border-bottom:" + borderStyle, "border-right:" + borderStyle, "background-color:" + backgroundColor + ";"];
194
+ return "<div style=\"" + styleCss.join('') + "\"></div>";
195
+ }
196
+
197
+ function assembleTransition(duration, onlyFade) {
198
+ var transitionCurve = 'cubic-bezier(0.23,1,0.32,1)';
199
+ var transitionOption = " " + duration / 2 + "s " + transitionCurve;
200
+ var transitionText = "opacity" + transitionOption + ",visibility" + transitionOption;
201
+
202
+ if (!onlyFade) {
203
+ transitionOption = " " + duration + "s " + transitionCurve;
204
+ transitionText += env.transformSupported ? "," + CSS_TRANSFORM_VENDOR + transitionOption : ",left" + transitionOption + ",top" + transitionOption;
205
+ }
206
+
207
+ return CSS_TRANSITION_VENDOR + ':' + transitionText;
208
+ }
209
+
210
+ function assembleTransform(x, y, toString) {
211
+ // If using float on style, the final width of the dom might
212
+ // keep changing slightly while mouse move. So `toFixed(0)` them.
213
+ var x0 = x.toFixed(0) + 'px';
214
+ var y0 = y.toFixed(0) + 'px'; // not support transform, use `left` and `top` instead.
215
+
216
+ if (!env.transformSupported) {
217
+ return toString ? "top:" + y0 + ";left:" + x0 + ";" : [['top', y0], ['left', x0]];
218
+ } // support transform
219
+
220
+
221
+ var is3d = env.transform3dSupported;
222
+ var translate = "translate" + (is3d ? '3d' : '') + "(" + x0 + "," + y0 + (is3d ? ',0' : '') + ")";
223
+ return toString ? 'top:0;left:0;' + CSS_TRANSFORM_VENDOR + ':' + translate + ';' : [['top', 0], ['left', 0], [TRANSFORM_VENDOR, translate]];
224
+ }
225
+ /**
226
+ * @param {Object} textStyle
227
+ * @return {string}
228
+ * @inner
229
+ */
230
+
231
+
232
+ function assembleFont(textStyleModel) {
233
+ var cssText = [];
234
+ var fontSize = textStyleModel.get('fontSize');
235
+ var color = textStyleModel.getTextColor();
236
+ color && cssText.push('color:' + color);
237
+ cssText.push('font:' + textStyleModel.getFont());
238
+ fontSize // @ts-ignore, leave it to the tooltip refactor.
239
+ && cssText.push('line-height:' + Math.round(fontSize * 3 / 2) + 'px');
240
+ var shadowColor = textStyleModel.get('textShadowColor');
241
+ var shadowBlur = textStyleModel.get('textShadowBlur') || 0;
242
+ var shadowOffsetX = textStyleModel.get('textShadowOffsetX') || 0;
243
+ var shadowOffsetY = textStyleModel.get('textShadowOffsetY') || 0;
244
+ shadowColor && shadowBlur && cssText.push('text-shadow:' + shadowOffsetX + 'px ' + shadowOffsetY + 'px ' + shadowBlur + 'px ' + shadowColor);
245
+ each$1(['decoration', 'align'], function (name) {
246
+ var val = textStyleModel.get(name);
247
+ val && cssText.push('text-' + name + ':' + val);
248
+ });
249
+ return cssText.join(';');
250
+ }
251
+
252
+ function assembleCssText(tooltipModel, enableTransition, onlyFade) {
253
+ var cssText = [];
254
+ var transitionDuration = tooltipModel.get('transitionDuration');
255
+ var backgroundColor = tooltipModel.get('backgroundColor');
256
+ var shadowBlur = tooltipModel.get('shadowBlur');
257
+ var shadowColor = tooltipModel.get('shadowColor');
258
+ var shadowOffsetX = tooltipModel.get('shadowOffsetX');
259
+ var shadowOffsetY = tooltipModel.get('shadowOffsetY');
260
+ var textStyleModel = tooltipModel.getModel('textStyle');
261
+ var padding = getPaddingFromTooltipModel(tooltipModel, 'html');
262
+ var boxShadow = shadowOffsetX + "px " + shadowOffsetY + "px " + shadowBlur + "px " + shadowColor;
263
+ cssText.push('box-shadow:' + boxShadow); // Animation transition. Do not animate when transitionDuration is 0.
264
+
265
+ enableTransition && transitionDuration && cssText.push(assembleTransition(transitionDuration, onlyFade));
266
+
267
+ if (backgroundColor) {
268
+ cssText.push('background-color:' + backgroundColor);
269
+ } // Border style
270
+
271
+
272
+ each$1(['width', 'color', 'radius'], function (name) {
273
+ var borderName = 'border-' + name;
274
+ var camelCase = toCamelCase(borderName);
275
+ var val = tooltipModel.get(camelCase);
276
+ val != null && cssText.push(borderName + ':' + val + (name === 'color' ? '' : 'px'));
277
+ }); // Text style
278
+
279
+ cssText.push(assembleFont(textStyleModel)); // Padding
280
+
281
+ if (padding != null) {
282
+ cssText.push('padding:' + normalizeCssArray(padding).join('px ') + 'px');
283
+ }
284
+
285
+ return cssText.join(';') + ';';
286
+ } // If not able to make, do not modify the input `out`.
287
+
288
+
289
+ function makeStyleCoord$1(out, zr, appendToBody, zrX, zrY) {
290
+ var zrPainter = zr && zr.painter;
291
+
292
+ if (appendToBody) {
293
+ var zrViewportRoot = zrPainter && zrPainter.getViewportRoot();
294
+
295
+ if (zrViewportRoot) {
296
+ // Some APPs might use scale on body, so we support CSS transform here.
297
+ transformLocalCoord(out, zrViewportRoot, document.body, zrX, zrY);
298
+ }
299
+ } else {
300
+ out[0] = zrX;
301
+ out[1] = zrY; // xy should be based on canvas root. But tooltipContent is
302
+ // the sibling of canvas root. So padding of ec container
303
+ // should be considered here.
304
+
305
+ var viewportRootOffset = zrPainter && zrPainter.getViewportRootOffset();
306
+
307
+ if (viewportRootOffset) {
308
+ out[0] += viewportRootOffset.offsetLeft;
309
+ out[1] += viewportRootOffset.offsetTop;
310
+ }
311
+ }
312
+
313
+ out[2] = out[0] / zr.getWidth();
314
+ out[3] = out[1] / zr.getHeight();
315
+ }
316
+
317
+ var TooltipHTMLContent =
318
+ /** @class */
319
+ function () {
320
+ function TooltipHTMLContent(container, api, opt) {
321
+ this._show = false;
322
+ this._styleCoord = [0, 0, 0, 0];
323
+ this._enterable = true;
324
+ this._firstShow = true;
325
+ this._longHide = true;
326
+
327
+ if (env.wxa) {
328
+ return null;
329
+ }
330
+
331
+ var el = document.createElement('div'); // TODO: TYPE
332
+
333
+ el.domBelongToZr = true;
334
+ this.el = el;
335
+ var zr = this._zr = api.getZr();
336
+ var appendToBody = this._appendToBody = opt && opt.appendToBody;
337
+ makeStyleCoord$1(this._styleCoord, zr, appendToBody, api.getWidth() / 2, api.getHeight() / 2);
338
+
339
+ if (appendToBody) {
340
+ document.body.appendChild(el);
341
+ } else {
342
+ container.appendChild(el);
343
+ }
344
+
345
+ this._container = container; // FIXME
346
+ // Is it needed to trigger zr event manually if
347
+ // the browser do not support `pointer-events: none`.
348
+
349
+ var self = this;
350
+
351
+ el.onmouseenter = function () {
352
+ // clear the timeout in hideLater and keep showing tooltip
353
+ if (self._enterable) {
354
+ clearTimeout(self._hideTimeout);
355
+ self._show = true;
356
+ }
357
+
358
+ self._inContent = true;
359
+ };
360
+
361
+ el.onmousemove = function (e) {
362
+ e = e || window.event;
363
+
364
+ if (!self._enterable) {
365
+ // `pointer-events: none` is set to tooltip content div
366
+ // if `enterable` is set as `false`, and `el.onmousemove`
367
+ // can not be triggered. But in browser that do not
368
+ // support `pointer-events`, we need to do this:
369
+ // Try trigger zrender event to avoid mouse
370
+ // in and out shape too frequently
371
+ var handler = zr.handler;
372
+ var zrViewportRoot = zr.painter.getViewportRoot();
373
+ normalizeEvent(zrViewportRoot, e, true);
374
+ handler.dispatch('mousemove', e);
375
+ }
376
+ };
377
+
378
+ el.onmouseleave = function () {
379
+ // set `_inContent` to `false` before `hideLater`
380
+ self._inContent = false;
381
+
382
+ if (self._enterable) {
383
+ if (self._show) {
384
+ self.hideLater(self._hideDelay);
385
+ }
386
+ }
387
+ };
388
+ }
389
+ /**
390
+ * Update when tooltip is rendered
391
+ */
392
+
393
+
394
+ TooltipHTMLContent.prototype.update = function (tooltipModel) {
395
+ // FIXME
396
+ // Move this logic to ec main?
397
+ var container = this._container;
398
+ var position = getComputedStyle$1(container, 'position');
399
+ var domStyle = container.style;
400
+
401
+ if (domStyle.position !== 'absolute' && position !== 'absolute') {
402
+ domStyle.position = 'relative';
403
+ } // move tooltip if chart resized
404
+
405
+
406
+ var alwaysShowContent = tooltipModel.get('alwaysShowContent');
407
+ alwaysShowContent && this._moveIfResized(); // update className
408
+
409
+ this.el.className = tooltipModel.get('className') || ''; // Hide the tooltip
410
+ // PENDING
411
+ // this.hide();
412
+ };
413
+
414
+ TooltipHTMLContent.prototype.show = function (tooltipModel, nearPointColor) {
415
+ clearTimeout(this._hideTimeout);
416
+ clearTimeout(this._longHideTimeout);
417
+ var el = this.el;
418
+ var style = el.style;
419
+ var styleCoord = this._styleCoord;
420
+
421
+ if (!el.innerHTML) {
422
+ style.display = 'none';
423
+ } else {
424
+ style.cssText = gCssText + assembleCssText(tooltipModel, !this._firstShow, this._longHide) // initial transform
425
+ + assembleTransform(styleCoord[0], styleCoord[1], true) + ("border-color:" + convertToColorString(nearPointColor) + ";") + (tooltipModel.get('extraCssText') || '') // If mouse occasionally move over the tooltip, a mouseout event will be
426
+ // triggered by canvas, and cause some unexpectable result like dragging
427
+ // stop, "unfocusAdjacency". Here `pointer-events: none` is used to solve
428
+ // it. Although it is not supported by IE8~IE10, fortunately it is a rare
429
+ // scenario.
430
+ + (";pointer-events:" + (this._enterable ? 'auto' : 'none'));
431
+ }
432
+
433
+ this._show = true;
434
+ this._firstShow = false;
435
+ this._longHide = false;
436
+ };
437
+
438
+ TooltipHTMLContent.prototype.setContent = function (content, markers, tooltipModel, borderColor, arrowPosition) {
439
+ var el = this.el;
440
+
441
+ if (content == null) {
442
+ el.innerHTML = '';
443
+ return;
444
+ }
445
+
446
+ var arrow = '';
447
+
448
+ if (isString(arrowPosition) && tooltipModel.get('trigger') === 'item' && !shouldTooltipConfine(tooltipModel)) {
449
+ arrow = assembleArrow(tooltipModel, borderColor, arrowPosition);
450
+ }
451
+
452
+ if (isString(content)) {
453
+ el.innerHTML = content + arrow;
454
+ } else if (content) {
455
+ // Clear previous
456
+ el.innerHTML = '';
457
+
458
+ if (!isArray(content)) {
459
+ content = [content];
460
+ }
461
+
462
+ for (var i = 0; i < content.length; i++) {
463
+ if (isDom(content[i]) && content[i].parentNode !== el) {
464
+ el.appendChild(content[i]);
465
+ }
466
+ } // no arrow if empty
467
+
468
+
469
+ if (arrow && el.childNodes.length) {
470
+ // no need to create a new parent element, but it's not supported by IE 10 and older.
471
+ // const arrowEl = document.createRange().createContextualFragment(arrow);
472
+ var arrowEl = document.createElement('div');
473
+ arrowEl.innerHTML = arrow;
474
+ el.appendChild(arrowEl);
475
+ }
476
+ }
477
+ };
478
+
479
+ TooltipHTMLContent.prototype.setEnterable = function (enterable) {
480
+ this._enterable = enterable;
481
+ };
482
+
483
+ TooltipHTMLContent.prototype.getSize = function () {
484
+ var el = this.el;
485
+ return [el.offsetWidth, el.offsetHeight];
486
+ };
487
+
488
+ TooltipHTMLContent.prototype.moveTo = function (zrX, zrY) {
489
+ var styleCoord = this._styleCoord;
490
+ makeStyleCoord$1(styleCoord, this._zr, this._appendToBody, zrX, zrY);
491
+
492
+ if (styleCoord[0] != null && styleCoord[1] != null) {
493
+ var style_1 = this.el.style;
494
+ var transforms = assembleTransform(styleCoord[0], styleCoord[1]);
495
+ each$1(transforms, function (transform) {
496
+ style_1[transform[0]] = transform[1];
497
+ });
498
+ }
499
+ };
500
+ /**
501
+ * when `alwaysShowContent` is true,
502
+ * move the tooltip after chart resized
503
+ */
504
+
505
+
506
+ TooltipHTMLContent.prototype._moveIfResized = function () {
507
+ // The ratio of left to width
508
+ var ratioX = this._styleCoord[2]; // The ratio of top to height
509
+
510
+ var ratioY = this._styleCoord[3];
511
+ this.moveTo(ratioX * this._zr.getWidth(), ratioY * this._zr.getHeight());
512
+ };
513
+
514
+ TooltipHTMLContent.prototype.hide = function () {
515
+ var _this = this;
516
+
517
+ var style = this.el.style;
518
+ style.visibility = 'hidden';
519
+ style.opacity = '0';
520
+ env.transform3dSupported && (style.willChange = '');
521
+ this._show = false;
522
+ this._longHideTimeout = setTimeout(function () {
523
+ return _this._longHide = true;
524
+ }, 500);
525
+ };
526
+
527
+ TooltipHTMLContent.prototype.hideLater = function (time) {
528
+ if (this._show && !(this._inContent && this._enterable)) {
529
+ if (time) {
530
+ this._hideDelay = time; // Set show false to avoid invoke hideLater multiple times
531
+
532
+ this._show = false;
533
+ this._hideTimeout = setTimeout(bind(this.hide, this), time);
534
+ } else {
535
+ this.hide();
536
+ }
537
+ }
538
+ };
539
+
540
+ TooltipHTMLContent.prototype.isShow = function () {
541
+ return this._show;
542
+ };
543
+
544
+ TooltipHTMLContent.prototype.dispose = function () {
545
+ this.el.parentNode.removeChild(this.el);
546
+ };
547
+
548
+ return TooltipHTMLContent;
549
+ }();
550
+
551
+ var TooltipRichContent =
552
+ /** @class */
553
+ function () {
554
+ function TooltipRichContent(api) {
555
+ this._show = false;
556
+ this._styleCoord = [0, 0, 0, 0];
557
+ this._enterable = true;
558
+ this._zr = api.getZr();
559
+ makeStyleCoord(this._styleCoord, this._zr, api.getWidth() / 2, api.getHeight() / 2);
560
+ }
561
+ /**
562
+ * Update when tooltip is rendered
563
+ */
564
+
565
+
566
+ TooltipRichContent.prototype.update = function (tooltipModel) {
567
+ var alwaysShowContent = tooltipModel.get('alwaysShowContent');
568
+ alwaysShowContent && this._moveIfResized();
569
+ };
570
+
571
+ TooltipRichContent.prototype.show = function () {
572
+ if (this._hideTimeout) {
573
+ clearTimeout(this._hideTimeout);
574
+ }
575
+
576
+ this.el.show();
577
+ this._show = true;
578
+ };
579
+ /**
580
+ * Set tooltip content
581
+ */
582
+
583
+
584
+ TooltipRichContent.prototype.setContent = function (content, markupStyleCreator, tooltipModel, borderColor, arrowPosition) {
585
+ var _this = this;
586
+
587
+ if (isObject(content)) {
588
+ throwError('');
589
+ }
590
+
591
+ if (this.el) {
592
+ this._zr.remove(this.el);
593
+ }
594
+
595
+ var textStyleModel = tooltipModel.getModel('textStyle');
596
+ this.el = new ZRText({
597
+ style: {
598
+ rich: markupStyleCreator.richTextStyles,
599
+ text: content,
600
+ lineHeight: 22,
601
+ borderWidth: 1,
602
+ borderColor: borderColor,
603
+ textShadowColor: textStyleModel.get('textShadowColor'),
604
+ fill: tooltipModel.get(['textStyle', 'color']),
605
+ padding: getPaddingFromTooltipModel(tooltipModel, 'richText'),
606
+ verticalAlign: 'top',
607
+ align: 'left'
608
+ },
609
+ z: tooltipModel.get('z')
610
+ });
611
+ each$1(['backgroundColor', 'borderRadius', 'shadowColor', 'shadowBlur', 'shadowOffsetX', 'shadowOffsetY'], function (propName) {
612
+ _this.el.style[propName] = tooltipModel.get(propName);
613
+ });
614
+ each$1(['textShadowBlur', 'textShadowOffsetX', 'textShadowOffsetY'], function (propName) {
615
+ _this.el.style[propName] = textStyleModel.get(propName) || 0;
616
+ });
617
+
618
+ this._zr.add(this.el);
619
+
620
+ var self = this;
621
+ this.el.on('mouseover', function () {
622
+ // clear the timeout in hideLater and keep showing tooltip
623
+ if (self._enterable) {
624
+ clearTimeout(self._hideTimeout);
625
+ self._show = true;
626
+ }
627
+
628
+ self._inContent = true;
629
+ });
630
+ this.el.on('mouseout', function () {
631
+ if (self._enterable) {
632
+ if (self._show) {
633
+ self.hideLater(self._hideDelay);
634
+ }
635
+ }
636
+
637
+ self._inContent = false;
638
+ });
639
+ };
640
+
641
+ TooltipRichContent.prototype.setEnterable = function (enterable) {
642
+ this._enterable = enterable;
643
+ };
644
+
645
+ TooltipRichContent.prototype.getSize = function () {
646
+ var el = this.el;
647
+ var bounding = this.el.getBoundingRect(); // bounding rect does not include shadow. For renderMode richText,
648
+ // if overflow, it will be cut. So calculate them accurately.
649
+
650
+ var shadowOuterSize = calcShadowOuterSize(el.style);
651
+ return [bounding.width + shadowOuterSize.left + shadowOuterSize.right, bounding.height + shadowOuterSize.top + shadowOuterSize.bottom];
652
+ };
653
+
654
+ TooltipRichContent.prototype.moveTo = function (x, y) {
655
+ var el = this.el;
656
+
657
+ if (el) {
658
+ var styleCoord = this._styleCoord;
659
+ makeStyleCoord(styleCoord, this._zr, x, y);
660
+ x = styleCoord[0];
661
+ y = styleCoord[1];
662
+ var style = el.style;
663
+ var borderWidth = mathMaxWith0(style.borderWidth || 0);
664
+ var shadowOuterSize = calcShadowOuterSize(style); // rich text x, y do not include border.
665
+
666
+ el.x = x + borderWidth + shadowOuterSize.left;
667
+ el.y = y + borderWidth + shadowOuterSize.top;
668
+ el.markRedraw();
669
+ }
670
+ };
671
+ /**
672
+ * when `alwaysShowContent` is true,
673
+ * move the tooltip after chart resized
674
+ */
675
+
676
+
677
+ TooltipRichContent.prototype._moveIfResized = function () {
678
+ // The ratio of left to width
679
+ var ratioX = this._styleCoord[2]; // The ratio of top to height
680
+
681
+ var ratioY = this._styleCoord[3];
682
+ this.moveTo(ratioX * this._zr.getWidth(), ratioY * this._zr.getHeight());
683
+ };
684
+
685
+ TooltipRichContent.prototype.hide = function () {
686
+ if (this.el) {
687
+ this.el.hide();
688
+ }
689
+
690
+ this._show = false;
691
+ };
692
+
693
+ TooltipRichContent.prototype.hideLater = function (time) {
694
+ if (this._show && !(this._inContent && this._enterable)) {
695
+ if (time) {
696
+ this._hideDelay = time; // Set show false to avoid invoke hideLater multiple times
697
+
698
+ this._show = false;
699
+ this._hideTimeout = setTimeout(bind(this.hide, this), time);
700
+ } else {
701
+ this.hide();
702
+ }
703
+ }
704
+ };
705
+
706
+ TooltipRichContent.prototype.isShow = function () {
707
+ return this._show;
708
+ };
709
+
710
+ TooltipRichContent.prototype.dispose = function () {
711
+ this._zr.remove(this.el);
712
+ };
713
+
714
+ return TooltipRichContent;
715
+ }();
716
+
717
+ function mathMaxWith0(val) {
718
+ return Math.max(0, val);
719
+ }
720
+
721
+ function calcShadowOuterSize(style) {
722
+ var shadowBlur = mathMaxWith0(style.shadowBlur || 0);
723
+ var shadowOffsetX = mathMaxWith0(style.shadowOffsetX || 0);
724
+ var shadowOffsetY = mathMaxWith0(style.shadowOffsetY || 0);
725
+ return {
726
+ left: mathMaxWith0(shadowBlur - shadowOffsetX),
727
+ right: mathMaxWith0(shadowBlur + shadowOffsetX),
728
+ top: mathMaxWith0(shadowBlur - shadowOffsetY),
729
+ bottom: mathMaxWith0(shadowBlur + shadowOffsetY)
730
+ };
731
+ }
732
+
733
+ function makeStyleCoord(out, zr, zrX, zrY) {
734
+ out[0] = zrX;
735
+ out[1] = zrY;
736
+ out[2] = out[0] / zr.getWidth();
737
+ out[3] = out[1] / zr.getHeight();
738
+ }
739
+
740
+ var proxyRect = new Rect({
741
+ shape: {
742
+ x: -1,
743
+ y: -1,
744
+ width: 2,
745
+ height: 2
746
+ }
747
+ });
748
+
749
+ var TooltipView =
750
+ /** @class */
751
+ function (_super) {
752
+ __extends(TooltipView, _super);
753
+
754
+ function TooltipView() {
755
+ var _this = _super !== null && _super.apply(this, arguments) || this;
756
+
757
+ _this.type = TooltipView.type;
758
+ return _this;
759
+ }
760
+
761
+ TooltipView.prototype.init = function (ecModel, api) {
762
+ if (env.node || !api.getDom()) {
763
+ return;
764
+ }
765
+
766
+ var tooltipModel = ecModel.getComponent('tooltip');
767
+ var renderMode = this._renderMode = getTooltipRenderMode(tooltipModel.get('renderMode'));
768
+ this._tooltipContent = renderMode === 'richText' ? new TooltipRichContent(api) : new TooltipHTMLContent(api.getDom(), api, {
769
+ appendToBody: tooltipModel.get('appendToBody', true)
770
+ });
771
+ };
772
+
773
+ TooltipView.prototype.render = function (tooltipModel, ecModel, api) {
774
+ if (env.node || !api.getDom()) {
775
+ return;
776
+ } // Reset
777
+
778
+
779
+ this.group.removeAll();
780
+ this._tooltipModel = tooltipModel;
781
+ this._ecModel = ecModel;
782
+ this._api = api;
783
+ /**
784
+ * @private
785
+ * @type {boolean}
786
+ */
787
+
788
+ this._alwaysShowContent = tooltipModel.get('alwaysShowContent');
789
+ var tooltipContent = this._tooltipContent;
790
+ tooltipContent.update(tooltipModel);
791
+ tooltipContent.setEnterable(tooltipModel.get('enterable'));
792
+
793
+ this._initGlobalListener();
794
+
795
+ this._keepShow(); // PENDING
796
+ // `mousemove` event will be triggered very frequently when the mouse moves fast,
797
+ // which causes that the `updatePosition` function was also called frequently.
798
+ // In Chrome with devtools open and Firefox, tooltip looks laggy and shakes. See #14695 #16101
799
+ // To avoid frequent triggering,
800
+ // consider throttling it in 50ms when transition is enabled
801
+
802
+
803
+ if (this._renderMode !== 'richText' && tooltipModel.get('transitionDuration')) {
804
+ createOrUpdate(this, '_updatePosition', 50, 'fixRate');
805
+ } else {
806
+ clear(this, '_updatePosition');
807
+ }
808
+ };
809
+
810
+ TooltipView.prototype._initGlobalListener = function () {
811
+ var tooltipModel = this._tooltipModel;
812
+ var triggerOn = tooltipModel.get('triggerOn');
813
+ register('itemTooltip', this._api, bind(function (currTrigger, e, dispatchAction) {
814
+ // If 'none', it is not controlled by mouse totally.
815
+ if (triggerOn !== 'none') {
816
+ if (triggerOn.indexOf(currTrigger) >= 0) {
817
+ this._tryShow(e, dispatchAction);
818
+ } else if (currTrigger === 'leave') {
819
+ this._hide(dispatchAction);
820
+ }
821
+ }
822
+ }, this));
823
+ };
824
+
825
+ TooltipView.prototype._keepShow = function () {
826
+ var tooltipModel = this._tooltipModel;
827
+ var ecModel = this._ecModel;
828
+ var api = this._api;
829
+ var triggerOn = tooltipModel.get('triggerOn'); // Try to keep the tooltip show when refreshing
830
+
831
+ if (this._lastX != null && this._lastY != null // When user is willing to control tooltip totally using API,
832
+ // self.manuallyShowTip({x, y}) might cause tooltip hide,
833
+ // which is not expected.
834
+ && triggerOn !== 'none' && triggerOn !== 'click') {
835
+ var self_1 = this;
836
+ clearTimeout(this._refreshUpdateTimeout);
837
+ this._refreshUpdateTimeout = setTimeout(function () {
838
+ // Show tip next tick after other charts are rendered
839
+ // In case highlight action has wrong result
840
+ // FIXME
841
+ !api.isDisposed() && self_1.manuallyShowTip(tooltipModel, ecModel, api, {
842
+ x: self_1._lastX,
843
+ y: self_1._lastY,
844
+ dataByCoordSys: self_1._lastDataByCoordSys
845
+ });
846
+ });
847
+ }
848
+ };
849
+ /**
850
+ * Show tip manually by
851
+ * dispatchAction({
852
+ * type: 'showTip',
853
+ * x: 10,
854
+ * y: 10
855
+ * });
856
+ * Or
857
+ * dispatchAction({
858
+ * type: 'showTip',
859
+ * seriesIndex: 0,
860
+ * dataIndex or dataIndexInside or name
861
+ * });
862
+ *
863
+ * TODO Batch
864
+ */
865
+
866
+
867
+ TooltipView.prototype.manuallyShowTip = function (tooltipModel, ecModel, api, payload) {
868
+ if (payload.from === this.uid || env.node || !api.getDom()) {
869
+ return;
870
+ }
871
+
872
+ var dispatchAction = makeDispatchAction(payload, api); // Reset ticket
873
+
874
+ this._ticket = ''; // When triggered from axisPointer.
875
+
876
+ var dataByCoordSys = payload.dataByCoordSys;
877
+ var cmptRef = findComponentReference(payload, ecModel, api);
878
+
879
+ if (cmptRef) {
880
+ var rect = cmptRef.el.getBoundingRect().clone();
881
+ rect.applyTransform(cmptRef.el.transform);
882
+
883
+ this._tryShow({
884
+ offsetX: rect.x + rect.width / 2,
885
+ offsetY: rect.y + rect.height / 2,
886
+ target: cmptRef.el,
887
+ position: payload.position,
888
+ // When manully trigger, the mouse is not on the el, so we'd better to
889
+ // position tooltip on the bottom of the el and display arrow is possible.
890
+ positionDefault: 'bottom'
891
+ }, dispatchAction);
892
+ } else if (payload.tooltip && payload.x != null && payload.y != null) {
893
+ var el = proxyRect;
894
+ el.x = payload.x;
895
+ el.y = payload.y;
896
+ el.update();
897
+ getECData(el).tooltipConfig = {
898
+ name: null,
899
+ option: payload.tooltip
900
+ }; // Manually show tooltip while view is not using zrender elements.
901
+
902
+ this._tryShow({
903
+ offsetX: payload.x,
904
+ offsetY: payload.y,
905
+ target: el
906
+ }, dispatchAction);
907
+ } else if (dataByCoordSys) {
908
+ this._tryShow({
909
+ offsetX: payload.x,
910
+ offsetY: payload.y,
911
+ position: payload.position,
912
+ dataByCoordSys: dataByCoordSys,
913
+ tooltipOption: payload.tooltipOption
914
+ }, dispatchAction);
915
+ } else if (payload.seriesIndex != null) {
916
+ if (this._manuallyAxisShowTip(tooltipModel, ecModel, api, payload)) {
917
+ return;
918
+ }
919
+
920
+ var pointInfo = findPointFromSeries(payload, ecModel);
921
+ var cx = pointInfo.point[0];
922
+ var cy = pointInfo.point[1];
923
+
924
+ if (cx != null && cy != null) {
925
+ this._tryShow({
926
+ offsetX: cx,
927
+ offsetY: cy,
928
+ target: pointInfo.el,
929
+ position: payload.position,
930
+ // When manully trigger, the mouse is not on the el, so we'd better to
931
+ // position tooltip on the bottom of the el and display arrow is possible.
932
+ positionDefault: 'bottom'
933
+ }, dispatchAction);
934
+ }
935
+ } else if (payload.x != null && payload.y != null) {
936
+ // FIXME
937
+ // should wrap dispatchAction like `axisPointer/globalListener` ?
938
+ api.dispatchAction({
939
+ type: 'updateAxisPointer',
940
+ x: payload.x,
941
+ y: payload.y
942
+ });
943
+
944
+ this._tryShow({
945
+ offsetX: payload.x,
946
+ offsetY: payload.y,
947
+ position: payload.position,
948
+ target: api.getZr().findHover(payload.x, payload.y).target
949
+ }, dispatchAction);
950
+ }
951
+ };
952
+
953
+ TooltipView.prototype.manuallyHideTip = function (tooltipModel, ecModel, api, payload) {
954
+ var tooltipContent = this._tooltipContent;
955
+
956
+ if (!this._alwaysShowContent && this._tooltipModel) {
957
+ tooltipContent.hideLater(this._tooltipModel.get('hideDelay'));
958
+ }
959
+
960
+ this._lastX = this._lastY = this._lastDataByCoordSys = null;
961
+
962
+ if (payload.from !== this.uid) {
963
+ this._hide(makeDispatchAction(payload, api));
964
+ }
965
+ }; // Be compatible with previous design, that is, when tooltip.type is 'axis' and
966
+ // dispatchAction 'showTip' with seriesIndex and dataIndex will trigger axis pointer
967
+ // and tooltip.
968
+
969
+
970
+ TooltipView.prototype._manuallyAxisShowTip = function (tooltipModel, ecModel, api, payload) {
971
+ var seriesIndex = payload.seriesIndex;
972
+ var dataIndex = payload.dataIndex; // @ts-ignore
973
+
974
+ var coordSysAxesInfo = ecModel.getComponent('axisPointer').coordSysAxesInfo;
975
+
976
+ if (seriesIndex == null || dataIndex == null || coordSysAxesInfo == null) {
977
+ return;
978
+ }
979
+
980
+ var seriesModel = ecModel.getSeriesByIndex(seriesIndex);
981
+
982
+ if (!seriesModel) {
983
+ return;
984
+ }
985
+
986
+ var data = seriesModel.getData();
987
+ var tooltipCascadedModel = buildTooltipModel([data.getItemModel(dataIndex), seriesModel, (seriesModel.coordinateSystem || {}).model], this._tooltipModel);
988
+
989
+ if (tooltipCascadedModel.get('trigger') !== 'axis') {
990
+ return;
991
+ }
992
+
993
+ api.dispatchAction({
994
+ type: 'updateAxisPointer',
995
+ seriesIndex: seriesIndex,
996
+ dataIndex: dataIndex,
997
+ position: payload.position
998
+ });
999
+ return true;
1000
+ };
1001
+
1002
+ TooltipView.prototype._tryShow = function (e, dispatchAction) {
1003
+ var el = e.target;
1004
+ var tooltipModel = this._tooltipModel;
1005
+
1006
+ if (!tooltipModel) {
1007
+ return;
1008
+ } // Save mouse x, mouse y. So we can try to keep showing the tip if chart is refreshed
1009
+
1010
+
1011
+ this._lastX = e.offsetX;
1012
+ this._lastY = e.offsetY;
1013
+ var dataByCoordSys = e.dataByCoordSys;
1014
+
1015
+ if (dataByCoordSys && dataByCoordSys.length) {
1016
+ this._showAxisTooltip(dataByCoordSys, e);
1017
+ } else if (el) {
1018
+ this._lastDataByCoordSys = null;
1019
+ var seriesDispatcher_1;
1020
+ var cmptDispatcher_1;
1021
+ findEventDispatcher(el, function (target) {
1022
+ // Always show item tooltip if mouse is on the element with dataIndex
1023
+ if (getECData(target).dataIndex != null) {
1024
+ seriesDispatcher_1 = target;
1025
+ return true;
1026
+ } // Tooltip provided directly. Like legend.
1027
+
1028
+
1029
+ if (getECData(target).tooltipConfig != null) {
1030
+ cmptDispatcher_1 = target;
1031
+ return true;
1032
+ }
1033
+ }, true);
1034
+
1035
+ if (seriesDispatcher_1) {
1036
+ this._showSeriesItemTooltip(e, seriesDispatcher_1, dispatchAction);
1037
+ } else if (cmptDispatcher_1) {
1038
+ this._showComponentItemTooltip(e, cmptDispatcher_1, dispatchAction);
1039
+ } else {
1040
+ this._hide(dispatchAction);
1041
+ }
1042
+ } else {
1043
+ this._lastDataByCoordSys = null;
1044
+
1045
+ this._hide(dispatchAction);
1046
+ }
1047
+ };
1048
+
1049
+ TooltipView.prototype._showOrMove = function (tooltipModel, cb) {
1050
+ // showDelay is used in this case: tooltip.enterable is set
1051
+ // as true. User intent to move mouse into tooltip and click
1052
+ // something. `showDelay` makes it easier to enter the content
1053
+ // but tooltip do not move immediately.
1054
+ var delay = tooltipModel.get('showDelay');
1055
+ cb = bind(cb, this);
1056
+ clearTimeout(this._showTimout);
1057
+ delay > 0 ? this._showTimout = setTimeout(cb, delay) : cb();
1058
+ };
1059
+
1060
+ TooltipView.prototype._showAxisTooltip = function (dataByCoordSys, e) {
1061
+ var ecModel = this._ecModel;
1062
+ var globalTooltipModel = this._tooltipModel;
1063
+ var point = [e.offsetX, e.offsetY];
1064
+ var singleTooltipModel = buildTooltipModel([e.tooltipOption], globalTooltipModel);
1065
+ var renderMode = this._renderMode;
1066
+ var cbParamsList = [];
1067
+ var articleMarkup = createTooltipMarkup('section', {
1068
+ blocks: [],
1069
+ noHeader: true
1070
+ }); // Only for legacy: `Serise['formatTooltip']` returns a string.
1071
+
1072
+ var markupTextArrLegacy = [];
1073
+ var markupStyleCreator = new TooltipMarkupStyleCreator();
1074
+ each$1(dataByCoordSys, function (itemCoordSys) {
1075
+ each$1(itemCoordSys.dataByAxis, function (axisItem) {
1076
+ var axisModel = ecModel.getComponent(axisItem.axisDim + 'Axis', axisItem.axisIndex);
1077
+ var axisValue = axisItem.value;
1078
+
1079
+ if (!axisModel || axisValue == null) {
1080
+ return;
1081
+ }
1082
+
1083
+ var axisValueLabel = getValueLabel(axisValue, axisModel.axis, ecModel, axisItem.seriesDataIndices, axisItem.valueLabelOpt);
1084
+ var axisSectionMarkup = createTooltipMarkup('section', {
1085
+ header: axisValueLabel,
1086
+ noHeader: !trim(axisValueLabel),
1087
+ sortBlocks: true,
1088
+ blocks: []
1089
+ });
1090
+ articleMarkup.blocks.push(axisSectionMarkup);
1091
+ each$1(axisItem.seriesDataIndices, function (idxItem) {
1092
+ var series = ecModel.getSeriesByIndex(idxItem.seriesIndex);
1093
+ var dataIndex = idxItem.dataIndexInside;
1094
+ var cbParams = series.getDataParams(dataIndex); // Can't find data.
1095
+
1096
+ if (cbParams.dataIndex < 0) {
1097
+ return;
1098
+ }
1099
+
1100
+ cbParams.axisDim = axisItem.axisDim;
1101
+ cbParams.axisIndex = axisItem.axisIndex;
1102
+ cbParams.axisType = axisItem.axisType;
1103
+ cbParams.axisId = axisItem.axisId;
1104
+ cbParams.axisValue = getAxisRawValue(axisModel.axis, {
1105
+ value: axisValue
1106
+ });
1107
+ cbParams.axisValueLabel = axisValueLabel; // Pre-create marker style for makers. Users can assemble richText
1108
+ // text in `formatter` callback and use those markers style.
1109
+
1110
+ cbParams.marker = markupStyleCreator.makeTooltipMarker('item', convertToColorString(cbParams.color), renderMode);
1111
+ var seriesTooltipResult = normalizeTooltipFormatResult(series.formatTooltip(dataIndex, true, null));
1112
+ var frag = seriesTooltipResult.frag;
1113
+
1114
+ if (frag) {
1115
+ var valueFormatter = buildTooltipModel([series], globalTooltipModel).get('valueFormatter');
1116
+ axisSectionMarkup.blocks.push(valueFormatter ? extend({
1117
+ valueFormatter: valueFormatter
1118
+ }, frag) : frag);
1119
+ }
1120
+
1121
+ if (seriesTooltipResult.text) {
1122
+ markupTextArrLegacy.push(seriesTooltipResult.text);
1123
+ }
1124
+
1125
+ cbParamsList.push(cbParams);
1126
+ });
1127
+ });
1128
+ }); // In most cases, the second axis is displays upper on the first one.
1129
+ // So we reverse it to look better.
1130
+
1131
+ articleMarkup.blocks.reverse();
1132
+ markupTextArrLegacy.reverse();
1133
+ var positionExpr = e.position;
1134
+ var orderMode = singleTooltipModel.get('order');
1135
+ var builtMarkupText = buildTooltipMarkup(articleMarkup, markupStyleCreator, renderMode, orderMode, ecModel.get('useUTC'), singleTooltipModel.get('textStyle'));
1136
+ builtMarkupText && markupTextArrLegacy.unshift(builtMarkupText);
1137
+ var blockBreak = renderMode === 'richText' ? '\n\n' : '<br/>';
1138
+ var allMarkupText = markupTextArrLegacy.join(blockBreak);
1139
+
1140
+ this._showOrMove(singleTooltipModel, function () {
1141
+ if (this._updateContentNotChangedOnAxis(dataByCoordSys, cbParamsList)) {
1142
+ this._updatePosition(singleTooltipModel, positionExpr, point[0], point[1], this._tooltipContent, cbParamsList);
1143
+ } else {
1144
+ this._showTooltipContent(singleTooltipModel, allMarkupText, cbParamsList, Math.random() + '', point[0], point[1], positionExpr, null, markupStyleCreator);
1145
+ }
1146
+ }); // Do not trigger events here, because this branch only be entered
1147
+ // from dispatchAction.
1148
+
1149
+ };
1150
+
1151
+ TooltipView.prototype._showSeriesItemTooltip = function (e, dispatcher, dispatchAction) {
1152
+ var ecModel = this._ecModel;
1153
+ var ecData = getECData(dispatcher); // Use dataModel in element if possible
1154
+ // Used when mouseover on a element like markPoint or edge
1155
+ // In which case, the data is not main data in series.
1156
+
1157
+ var seriesIndex = ecData.seriesIndex;
1158
+ var seriesModel = ecModel.getSeriesByIndex(seriesIndex); // For example, graph link.
1159
+
1160
+ var dataModel = ecData.dataModel || seriesModel;
1161
+ var dataIndex = ecData.dataIndex;
1162
+ var dataType = ecData.dataType;
1163
+ var data = dataModel.getData(dataType);
1164
+ var renderMode = this._renderMode;
1165
+ var positionDefault = e.positionDefault;
1166
+ var tooltipModel = buildTooltipModel([data.getItemModel(dataIndex), dataModel, seriesModel && (seriesModel.coordinateSystem || {}).model], this._tooltipModel, positionDefault ? {
1167
+ position: positionDefault
1168
+ } : null);
1169
+ var tooltipTrigger = tooltipModel.get('trigger');
1170
+
1171
+ if (tooltipTrigger != null && tooltipTrigger !== 'item') {
1172
+ return;
1173
+ }
1174
+
1175
+ var params = dataModel.getDataParams(dataIndex, dataType);
1176
+ var markupStyleCreator = new TooltipMarkupStyleCreator(); // Pre-create marker style for makers. Users can assemble richText
1177
+ // text in `formatter` callback and use those markers style.
1178
+
1179
+ params.marker = markupStyleCreator.makeTooltipMarker('item', convertToColorString(params.color), renderMode);
1180
+ var seriesTooltipResult = normalizeTooltipFormatResult(dataModel.formatTooltip(dataIndex, false, dataType));
1181
+ var orderMode = tooltipModel.get('order');
1182
+ var valueFormatter = tooltipModel.get('valueFormatter');
1183
+ var frag = seriesTooltipResult.frag;
1184
+ var markupText = frag ? buildTooltipMarkup(valueFormatter ? extend({
1185
+ valueFormatter: valueFormatter
1186
+ }, frag) : frag, markupStyleCreator, renderMode, orderMode, ecModel.get('useUTC'), tooltipModel.get('textStyle')) : seriesTooltipResult.text;
1187
+ var asyncTicket = 'item_' + dataModel.name + '_' + dataIndex;
1188
+
1189
+ this._showOrMove(tooltipModel, function () {
1190
+ this._showTooltipContent(tooltipModel, markupText, params, asyncTicket, e.offsetX, e.offsetY, e.position, e.target, markupStyleCreator);
1191
+ }); // FIXME
1192
+ // duplicated showtip if manuallyShowTip is called from dispatchAction.
1193
+
1194
+
1195
+ dispatchAction({
1196
+ type: 'showTip',
1197
+ dataIndexInside: dataIndex,
1198
+ dataIndex: data.getRawIndex(dataIndex),
1199
+ seriesIndex: seriesIndex,
1200
+ from: this.uid
1201
+ });
1202
+ };
1203
+
1204
+ TooltipView.prototype._showComponentItemTooltip = function (e, el, dispatchAction) {
1205
+ var ecData = getECData(el);
1206
+ var tooltipConfig = ecData.tooltipConfig;
1207
+ var tooltipOpt = tooltipConfig.option || {};
1208
+
1209
+ if (isString(tooltipOpt)) {
1210
+ var content = tooltipOpt;
1211
+ tooltipOpt = {
1212
+ content: content,
1213
+ // Fixed formatter
1214
+ formatter: content
1215
+ };
1216
+ }
1217
+
1218
+ var tooltipModelCascade = [tooltipOpt];
1219
+
1220
+ var cmpt = this._ecModel.getComponent(ecData.componentMainType, ecData.componentIndex);
1221
+
1222
+ if (cmpt) {
1223
+ tooltipModelCascade.push(cmpt);
1224
+ } // In most cases, component tooltip formatter has different params with series tooltip formatter,
1225
+ // so that they can not share the same formatter. Since the global tooltip formatter is used for series
1226
+ // by convension, we do not use it as the default formatter for component.
1227
+
1228
+
1229
+ tooltipModelCascade.push({
1230
+ formatter: tooltipOpt.content
1231
+ });
1232
+ var positionDefault = e.positionDefault;
1233
+ var subTooltipModel = buildTooltipModel(tooltipModelCascade, this._tooltipModel, positionDefault ? {
1234
+ position: positionDefault
1235
+ } : null);
1236
+ var defaultHtml = subTooltipModel.get('content');
1237
+ var asyncTicket = Math.random() + ''; // PENDING: this case do not support richText style yet.
1238
+
1239
+ var markupStyleCreator = new TooltipMarkupStyleCreator(); // Do not check whether `trigger` is 'none' here, because `trigger`
1240
+ // only works on coordinate system. In fact, we have not found case
1241
+ // that requires setting `trigger` nothing on component yet.
1242
+
1243
+ this._showOrMove(subTooltipModel, function () {
1244
+ // Use formatterParams from element defined in component
1245
+ // Avoid users modify it.
1246
+ var formatterParams = clone(subTooltipModel.get('formatterParams') || {});
1247
+
1248
+ this._showTooltipContent(subTooltipModel, defaultHtml, formatterParams, asyncTicket, e.offsetX, e.offsetY, e.position, el, markupStyleCreator);
1249
+ }); // If not dispatch showTip, tip may be hide triggered by axis.
1250
+
1251
+
1252
+ dispatchAction({
1253
+ type: 'showTip',
1254
+ from: this.uid
1255
+ });
1256
+ };
1257
+
1258
+ TooltipView.prototype._showTooltipContent = function ( // Use Model<TooltipOption> insteadof TooltipModel because this model may be from series or other options.
1259
+ // Instead of top level tooltip.
1260
+ tooltipModel, defaultHtml, params, asyncTicket, x, y, positionExpr, el, markupStyleCreator) {
1261
+ // Reset ticket
1262
+ this._ticket = '';
1263
+
1264
+ if (!tooltipModel.get('showContent') || !tooltipModel.get('show')) {
1265
+ return;
1266
+ }
1267
+
1268
+ var tooltipContent = this._tooltipContent;
1269
+ tooltipContent.setEnterable(tooltipModel.get('enterable'));
1270
+ var formatter = tooltipModel.get('formatter');
1271
+ positionExpr = positionExpr || tooltipModel.get('position');
1272
+ var html = defaultHtml;
1273
+
1274
+ var nearPoint = this._getNearestPoint([x, y], params, tooltipModel.get('trigger'), tooltipModel.get('borderColor'));
1275
+
1276
+ var nearPointColor = nearPoint.color;
1277
+
1278
+ if (formatter) {
1279
+ if (isString(formatter)) {
1280
+ var useUTC = tooltipModel.ecModel.get('useUTC');
1281
+ var params0 = isArray(params) ? params[0] : params;
1282
+ var isTimeAxis = params0 && params0.axisType && params0.axisType.indexOf('time') >= 0;
1283
+ html = formatter;
1284
+
1285
+ if (isTimeAxis) {
1286
+ html = format(params0.axisValue, html, useUTC);
1287
+ }
1288
+
1289
+ html = formatTpl(html, params, true);
1290
+ } else if (isFunction(formatter)) {
1291
+ var callback = bind(function (cbTicket, html) {
1292
+ if (cbTicket === this._ticket) {
1293
+ tooltipContent.setContent(html, markupStyleCreator, tooltipModel, nearPointColor, positionExpr);
1294
+
1295
+ this._updatePosition(tooltipModel, positionExpr, x, y, tooltipContent, params, el);
1296
+ }
1297
+ }, this);
1298
+ this._ticket = asyncTicket;
1299
+ html = formatter(params, asyncTicket, callback);
1300
+ } else {
1301
+ html = formatter;
1302
+ }
1303
+ }
1304
+
1305
+ tooltipContent.setContent(html, markupStyleCreator, tooltipModel, nearPointColor, positionExpr);
1306
+ tooltipContent.show(tooltipModel, nearPointColor);
1307
+
1308
+ this._updatePosition(tooltipModel, positionExpr, x, y, tooltipContent, params, el);
1309
+ };
1310
+
1311
+ TooltipView.prototype._getNearestPoint = function (point, tooltipDataParams, trigger, borderColor) {
1312
+ if (trigger === 'axis' || isArray(tooltipDataParams)) {
1313
+ return {
1314
+ color: borderColor || (this._renderMode === 'html' ? '#fff' : 'none')
1315
+ };
1316
+ }
1317
+
1318
+ if (!isArray(tooltipDataParams)) {
1319
+ return {
1320
+ color: borderColor || tooltipDataParams.color || tooltipDataParams.borderColor
1321
+ };
1322
+ }
1323
+ };
1324
+
1325
+ TooltipView.prototype._updatePosition = function (tooltipModel, positionExpr, x, // Mouse x
1326
+ y, // Mouse y
1327
+ content, params, el) {
1328
+ var viewWidth = this._api.getWidth();
1329
+
1330
+ var viewHeight = this._api.getHeight();
1331
+
1332
+ positionExpr = positionExpr || tooltipModel.get('position');
1333
+ var contentSize = content.getSize();
1334
+ var align = tooltipModel.get('align');
1335
+ var vAlign = tooltipModel.get('verticalAlign');
1336
+ var rect = el && el.getBoundingRect().clone();
1337
+ el && rect.applyTransform(el.transform);
1338
+
1339
+ if (isFunction(positionExpr)) {
1340
+ // Callback of position can be an array or a string specify the position
1341
+ positionExpr = positionExpr([x, y], params, content.el, rect, {
1342
+ viewSize: [viewWidth, viewHeight],
1343
+ contentSize: contentSize.slice()
1344
+ });
1345
+ }
1346
+
1347
+ if (isArray(positionExpr)) {
1348
+ x = parsePercent(positionExpr[0], viewWidth);
1349
+ y = parsePercent(positionExpr[1], viewHeight);
1350
+ } else if (isObject(positionExpr)) {
1351
+ var boxLayoutPosition = positionExpr;
1352
+ boxLayoutPosition.width = contentSize[0];
1353
+ boxLayoutPosition.height = contentSize[1];
1354
+ var layoutRect = getLayoutRect(boxLayoutPosition, {
1355
+ width: viewWidth,
1356
+ height: viewHeight
1357
+ });
1358
+ x = layoutRect.x;
1359
+ y = layoutRect.y;
1360
+ align = null; // When positionExpr is left/top/right/bottom,
1361
+ // align and verticalAlign will not work.
1362
+
1363
+ vAlign = null;
1364
+ } // Specify tooltip position by string 'top' 'bottom' 'left' 'right' around graphic element
1365
+ else if (isString(positionExpr) && el) {
1366
+ var pos = calcTooltipPosition(positionExpr, rect, contentSize, tooltipModel.get('borderWidth'));
1367
+ x = pos[0];
1368
+ y = pos[1];
1369
+ } else {
1370
+ var pos = refixTooltipPosition(x, y, content, viewWidth, viewHeight, align ? null : 20, vAlign ? null : 20);
1371
+ x = pos[0];
1372
+ y = pos[1];
1373
+ }
1374
+
1375
+ align && (x -= isCenterAlign(align) ? contentSize[0] / 2 : align === 'right' ? contentSize[0] : 0);
1376
+ vAlign && (y -= isCenterAlign(vAlign) ? contentSize[1] / 2 : vAlign === 'bottom' ? contentSize[1] : 0);
1377
+
1378
+ if (shouldTooltipConfine(tooltipModel)) {
1379
+ var pos = confineTooltipPosition(x, y, content, viewWidth, viewHeight);
1380
+ x = pos[0];
1381
+ y = pos[1];
1382
+ }
1383
+
1384
+ content.moveTo(x, y);
1385
+ }; // FIXME
1386
+ // Should we remove this but leave this to user?
1387
+
1388
+
1389
+ TooltipView.prototype._updateContentNotChangedOnAxis = function (dataByCoordSys, cbParamsList) {
1390
+ var lastCoordSys = this._lastDataByCoordSys;
1391
+ var lastCbParamsList = this._cbParamsList;
1392
+ var contentNotChanged = !!lastCoordSys && lastCoordSys.length === dataByCoordSys.length;
1393
+ contentNotChanged && each$1(lastCoordSys, function (lastItemCoordSys, indexCoordSys) {
1394
+ var lastDataByAxis = lastItemCoordSys.dataByAxis || [];
1395
+ var thisItemCoordSys = dataByCoordSys[indexCoordSys] || {};
1396
+ var thisDataByAxis = thisItemCoordSys.dataByAxis || [];
1397
+ contentNotChanged = contentNotChanged && lastDataByAxis.length === thisDataByAxis.length;
1398
+ contentNotChanged && each$1(lastDataByAxis, function (lastItem, indexAxis) {
1399
+ var thisItem = thisDataByAxis[indexAxis] || {};
1400
+ var lastIndices = lastItem.seriesDataIndices || [];
1401
+ var newIndices = thisItem.seriesDataIndices || [];
1402
+ contentNotChanged = contentNotChanged && lastItem.value === thisItem.value && lastItem.axisType === thisItem.axisType && lastItem.axisId === thisItem.axisId && lastIndices.length === newIndices.length;
1403
+ contentNotChanged && each$1(lastIndices, function (lastIdxItem, j) {
1404
+ var newIdxItem = newIndices[j];
1405
+ contentNotChanged = contentNotChanged && lastIdxItem.seriesIndex === newIdxItem.seriesIndex && lastIdxItem.dataIndex === newIdxItem.dataIndex;
1406
+ }); // check is cbParams data value changed
1407
+
1408
+ lastCbParamsList && each$1(lastItem.seriesDataIndices, function (idxItem) {
1409
+ var seriesIdx = idxItem.seriesIndex;
1410
+ var cbParams = cbParamsList[seriesIdx];
1411
+ var lastCbParams = lastCbParamsList[seriesIdx];
1412
+
1413
+ if (cbParams && lastCbParams && lastCbParams.data !== cbParams.data) {
1414
+ contentNotChanged = false;
1415
+ }
1416
+ });
1417
+ });
1418
+ });
1419
+ this._lastDataByCoordSys = dataByCoordSys;
1420
+ this._cbParamsList = cbParamsList;
1421
+ return !!contentNotChanged;
1422
+ };
1423
+
1424
+ TooltipView.prototype._hide = function (dispatchAction) {
1425
+ // Do not directly hideLater here, because this behavior may be prevented
1426
+ // in dispatchAction when showTip is dispatched.
1427
+ // FIXME
1428
+ // duplicated hideTip if manuallyHideTip is called from dispatchAction.
1429
+ this._lastDataByCoordSys = null;
1430
+ dispatchAction({
1431
+ type: 'hideTip',
1432
+ from: this.uid
1433
+ });
1434
+ };
1435
+
1436
+ TooltipView.prototype.dispose = function (ecModel, api) {
1437
+ if (env.node || !api.getDom()) {
1438
+ return;
1439
+ }
1440
+
1441
+ clear(this, '_updatePosition');
1442
+
1443
+ this._tooltipContent.dispose();
1444
+
1445
+ unregister('itemTooltip', api);
1446
+ };
1447
+
1448
+ TooltipView.type = 'tooltip';
1449
+ return TooltipView;
1450
+ }(ComponentView);
1451
+ /**
1452
+ * From top to bottom. (the last one should be globalTooltipModel);
1453
+ */
1454
+
1455
+
1456
+ function buildTooltipModel(modelCascade, globalTooltipModel, defaultTooltipOption) {
1457
+ // Last is always tooltip model.
1458
+ var ecModel = globalTooltipModel.ecModel;
1459
+ var resultModel;
1460
+
1461
+ if (defaultTooltipOption) {
1462
+ resultModel = new Model(defaultTooltipOption, ecModel, ecModel);
1463
+ resultModel = new Model(globalTooltipModel.option, resultModel, ecModel);
1464
+ } else {
1465
+ resultModel = globalTooltipModel;
1466
+ }
1467
+
1468
+ for (var i = modelCascade.length - 1; i >= 0; i--) {
1469
+ var tooltipOpt = modelCascade[i];
1470
+
1471
+ if (tooltipOpt) {
1472
+ if (tooltipOpt instanceof Model) {
1473
+ tooltipOpt = tooltipOpt.get('tooltip', true);
1474
+ } // In each data item tooltip can be simply write:
1475
+ // {
1476
+ // value: 10,
1477
+ // tooltip: 'Something you need to know'
1478
+ // }
1479
+
1480
+
1481
+ if (isString(tooltipOpt)) {
1482
+ tooltipOpt = {
1483
+ formatter: tooltipOpt
1484
+ };
1485
+ }
1486
+
1487
+ if (tooltipOpt) {
1488
+ resultModel = new Model(tooltipOpt, resultModel, ecModel);
1489
+ }
1490
+ }
1491
+ }
1492
+
1493
+ return resultModel;
1494
+ }
1495
+
1496
+ function makeDispatchAction(payload, api) {
1497
+ return payload.dispatchAction || bind(api.dispatchAction, api);
1498
+ }
1499
+
1500
+ function refixTooltipPosition(x, y, content, viewWidth, viewHeight, gapH, gapV) {
1501
+ var size = content.getSize();
1502
+ var width = size[0];
1503
+ var height = size[1];
1504
+
1505
+ if (gapH != null) {
1506
+ // Add extra 2 pixels for this case:
1507
+ // At present the "values" in defaut tooltip are using CSS `float: right`.
1508
+ // When the right edge of the tooltip box is on the right side of the
1509
+ // viewport, the `float` layout might push the "values" to the second line.
1510
+ if (x + width + gapH + 2 > viewWidth) {
1511
+ x -= width + gapH;
1512
+ } else {
1513
+ x += gapH;
1514
+ }
1515
+ }
1516
+
1517
+ if (gapV != null) {
1518
+ if (y + height + gapV > viewHeight) {
1519
+ y -= height + gapV;
1520
+ } else {
1521
+ y += gapV;
1522
+ }
1523
+ }
1524
+
1525
+ return [x, y];
1526
+ }
1527
+
1528
+ function confineTooltipPosition(x, y, content, viewWidth, viewHeight) {
1529
+ var size = content.getSize();
1530
+ var width = size[0];
1531
+ var height = size[1];
1532
+ x = Math.min(x + width, viewWidth) - width;
1533
+ y = Math.min(y + height, viewHeight) - height;
1534
+ x = Math.max(x, 0);
1535
+ y = Math.max(y, 0);
1536
+ return [x, y];
1537
+ }
1538
+
1539
+ function calcTooltipPosition(position, rect, contentSize, borderWidth) {
1540
+ var domWidth = contentSize[0];
1541
+ var domHeight = contentSize[1];
1542
+ var offset = Math.ceil(Math.SQRT2 * borderWidth) + 8;
1543
+ var x = 0;
1544
+ var y = 0;
1545
+ var rectWidth = rect.width;
1546
+ var rectHeight = rect.height;
1547
+
1548
+ switch (position) {
1549
+ case 'inside':
1550
+ x = rect.x + rectWidth / 2 - domWidth / 2;
1551
+ y = rect.y + rectHeight / 2 - domHeight / 2;
1552
+ break;
1553
+
1554
+ case 'top':
1555
+ x = rect.x + rectWidth / 2 - domWidth / 2;
1556
+ y = rect.y - domHeight - offset;
1557
+ break;
1558
+
1559
+ case 'bottom':
1560
+ x = rect.x + rectWidth / 2 - domWidth / 2;
1561
+ y = rect.y + rectHeight + offset;
1562
+ break;
1563
+
1564
+ case 'left':
1565
+ x = rect.x - domWidth - offset;
1566
+ y = rect.y + rectHeight / 2 - domHeight / 2;
1567
+ break;
1568
+
1569
+ case 'right':
1570
+ x = rect.x + rectWidth + offset;
1571
+ y = rect.y + rectHeight / 2 - domHeight / 2;
1572
+ }
1573
+
1574
+ return [x, y];
1575
+ }
1576
+
1577
+ function isCenterAlign(align) {
1578
+ return align === 'center' || align === 'middle';
1579
+ }
1580
+ /**
1581
+ * Find target component by payload like:
1582
+ * ```js
1583
+ * { legendId: 'some_id', name: 'xxx' }
1584
+ * { toolboxIndex: 1, name: 'xxx' }
1585
+ * { geoName: 'some_name', name: 'xxx' }
1586
+ * ```
1587
+ * PENDING: at present only
1588
+ *
1589
+ * If not found, return null/undefined.
1590
+ */
1591
+
1592
+
1593
+ function findComponentReference(payload, ecModel, api) {
1594
+ var queryOptionMap = preParseFinder(payload).queryOptionMap;
1595
+ var componentMainType = queryOptionMap.keys()[0];
1596
+
1597
+ if (!componentMainType || componentMainType === 'series') {
1598
+ return;
1599
+ }
1600
+
1601
+ var queryResult = queryReferringComponents(ecModel, componentMainType, queryOptionMap.get(componentMainType), {
1602
+ useDefault: false,
1603
+ enableAll: false,
1604
+ enableNone: false
1605
+ });
1606
+ var model = queryResult.models[0];
1607
+
1608
+ if (!model) {
1609
+ return;
1610
+ }
1611
+
1612
+ var view = api.getViewOfComponentModel(model);
1613
+ var el;
1614
+ view.group.traverse(function (subEl) {
1615
+ var tooltipConfig = getECData(subEl).tooltipConfig;
1616
+
1617
+ if (tooltipConfig && tooltipConfig.name === payload.name) {
1618
+ el = subEl;
1619
+ return true; // stop
1620
+ }
1621
+ });
1622
+
1623
+ if (el) {
1624
+ return {
1625
+ componentMainType: componentMainType,
1626
+ componentIndex: model.componentIndex,
1627
+ el: el
1628
+ };
1629
+ }
1630
+ }
1631
+
1632
+ function install$4(registers) {
1633
+ use(install$5);
1634
+ registers.registerComponentModel(TooltipModel);
1635
+ registers.registerComponentView(TooltipView);
1636
+ /**
1637
+ * @action
1638
+ * @property {string} type
1639
+ * @property {number} seriesIndex
1640
+ * @property {number} dataIndex
1641
+ * @property {number} [x]
1642
+ * @property {number} [y]
1643
+ */
1644
+
1645
+ registers.registerAction({
1646
+ type: 'showTip',
1647
+ event: 'showTip',
1648
+ update: 'tooltip:manuallyShowTip'
1649
+ }, noop);
1650
+ registers.registerAction({
1651
+ type: 'hideTip',
1652
+ event: 'hideTip',
1653
+ update: 'tooltip:manuallyHideTip'
1654
+ }, noop);
1655
+ }
1656
+
1657
+ var getDefaultSelectorOptions = function (ecModel, type) {
1658
+ if (type === 'all') {
1659
+ return {
1660
+ type: 'all',
1661
+ title: ecModel.getLocaleModel().get(['legend', 'selector', 'all'])
1662
+ };
1663
+ } else if (type === 'inverse') {
1664
+ return {
1665
+ type: 'inverse',
1666
+ title: ecModel.getLocaleModel().get(['legend', 'selector', 'inverse'])
1667
+ };
1668
+ }
1669
+ };
1670
+
1671
+ var LegendModel =
1672
+ /** @class */
1673
+ function (_super) {
1674
+ __extends(LegendModel, _super);
1675
+
1676
+ function LegendModel() {
1677
+ var _this = _super !== null && _super.apply(this, arguments) || this;
1678
+
1679
+ _this.type = LegendModel.type;
1680
+ _this.layoutMode = {
1681
+ type: 'box',
1682
+ // legend.width/height are maxWidth/maxHeight actually,
1683
+ // whereas real width/height is calculated by its content.
1684
+ // (Setting {left: 10, right: 10} does not make sense).
1685
+ // So consider the case:
1686
+ // `setOption({legend: {left: 10});`
1687
+ // then `setOption({legend: {right: 10});`
1688
+ // The previous `left` should be cleared by setting `ignoreSize`.
1689
+ ignoreSize: true
1690
+ };
1691
+ return _this;
1692
+ }
1693
+
1694
+ LegendModel.prototype.init = function (option, parentModel, ecModel) {
1695
+ this.mergeDefaultAndTheme(option, ecModel);
1696
+ option.selected = option.selected || {};
1697
+
1698
+ this._updateSelector(option);
1699
+ };
1700
+
1701
+ LegendModel.prototype.mergeOption = function (option, ecModel) {
1702
+ _super.prototype.mergeOption.call(this, option, ecModel);
1703
+
1704
+ this._updateSelector(option);
1705
+ };
1706
+
1707
+ LegendModel.prototype._updateSelector = function (option) {
1708
+ var selector = option.selector;
1709
+ var ecModel = this.ecModel;
1710
+
1711
+ if (selector === true) {
1712
+ selector = option.selector = ['all', 'inverse'];
1713
+ }
1714
+
1715
+ if (isArray(selector)) {
1716
+ each$1(selector, function (item, index) {
1717
+ isString(item) && (item = {
1718
+ type: item
1719
+ });
1720
+ selector[index] = merge(item, getDefaultSelectorOptions(ecModel, item.type));
1721
+ });
1722
+ }
1723
+ };
1724
+
1725
+ LegendModel.prototype.optionUpdated = function () {
1726
+ this._updateData(this.ecModel);
1727
+
1728
+ var legendData = this._data; // If selectedMode is single, try to select one
1729
+
1730
+ if (legendData[0] && this.get('selectedMode') === 'single') {
1731
+ var hasSelected = false; // If has any selected in option.selected
1732
+
1733
+ for (var i = 0; i < legendData.length; i++) {
1734
+ var name_1 = legendData[i].get('name');
1735
+
1736
+ if (this.isSelected(name_1)) {
1737
+ // Force to unselect others
1738
+ this.select(name_1);
1739
+ hasSelected = true;
1740
+ break;
1741
+ }
1742
+ } // Try select the first if selectedMode is single
1743
+
1744
+
1745
+ !hasSelected && this.select(legendData[0].get('name'));
1746
+ }
1747
+ };
1748
+
1749
+ LegendModel.prototype._updateData = function (ecModel) {
1750
+ var potentialData = [];
1751
+ var availableNames = [];
1752
+ ecModel.eachRawSeries(function (seriesModel) {
1753
+ var seriesName = seriesModel.name;
1754
+ availableNames.push(seriesName);
1755
+ var isPotential;
1756
+
1757
+ if (seriesModel.legendVisualProvider) {
1758
+ var provider = seriesModel.legendVisualProvider;
1759
+ var names = provider.getAllNames();
1760
+
1761
+ if (!ecModel.isSeriesFiltered(seriesModel)) {
1762
+ availableNames = availableNames.concat(names);
1763
+ }
1764
+
1765
+ if (names.length) {
1766
+ potentialData = potentialData.concat(names);
1767
+ } else {
1768
+ isPotential = true;
1769
+ }
1770
+ } else {
1771
+ isPotential = true;
1772
+ }
1773
+
1774
+ if (isPotential && isNameSpecified(seriesModel)) {
1775
+ potentialData.push(seriesModel.name);
1776
+ }
1777
+ });
1778
+ /**
1779
+ * @type {Array.<string>}
1780
+ * @private
1781
+ */
1782
+
1783
+ this._availableNames = availableNames; // If legend.data is not specified in option, use availableNames as data,
1784
+ // which is convenient for user preparing option.
1785
+
1786
+ var rawData = this.get('data') || potentialData;
1787
+ var legendNameMap = createHashMap();
1788
+ var legendData = map(rawData, function (dataItem) {
1789
+ // Can be string or number
1790
+ if (isString(dataItem) || isNumber(dataItem)) {
1791
+ dataItem = {
1792
+ name: dataItem
1793
+ };
1794
+ }
1795
+
1796
+ if (legendNameMap.get(dataItem.name)) {
1797
+ // remove legend name duplicate
1798
+ return null;
1799
+ }
1800
+
1801
+ legendNameMap.set(dataItem.name, true);
1802
+ return new Model(dataItem, this, this.ecModel);
1803
+ }, this);
1804
+ /**
1805
+ * @type {Array.<module:echarts/model/Model>}
1806
+ * @private
1807
+ */
1808
+
1809
+ this._data = filter(legendData, function (item) {
1810
+ return !!item;
1811
+ });
1812
+ };
1813
+
1814
+ LegendModel.prototype.getData = function () {
1815
+ return this._data;
1816
+ };
1817
+
1818
+ LegendModel.prototype.select = function (name) {
1819
+ var selected = this.option.selected;
1820
+ var selectedMode = this.get('selectedMode');
1821
+
1822
+ if (selectedMode === 'single') {
1823
+ var data = this._data;
1824
+ each$1(data, function (dataItem) {
1825
+ selected[dataItem.get('name')] = false;
1826
+ });
1827
+ }
1828
+
1829
+ selected[name] = true;
1830
+ };
1831
+
1832
+ LegendModel.prototype.unSelect = function (name) {
1833
+ if (this.get('selectedMode') !== 'single') {
1834
+ this.option.selected[name] = false;
1835
+ }
1836
+ };
1837
+
1838
+ LegendModel.prototype.toggleSelected = function (name) {
1839
+ var selected = this.option.selected; // Default is true
1840
+
1841
+ if (!selected.hasOwnProperty(name)) {
1842
+ selected[name] = true;
1843
+ }
1844
+
1845
+ this[selected[name] ? 'unSelect' : 'select'](name);
1846
+ };
1847
+
1848
+ LegendModel.prototype.allSelect = function () {
1849
+ var data = this._data;
1850
+ var selected = this.option.selected;
1851
+ each$1(data, function (dataItem) {
1852
+ selected[dataItem.get('name', true)] = true;
1853
+ });
1854
+ };
1855
+
1856
+ LegendModel.prototype.inverseSelect = function () {
1857
+ var data = this._data;
1858
+ var selected = this.option.selected;
1859
+ each$1(data, function (dataItem) {
1860
+ var name = dataItem.get('name', true); // Initially, default value is true
1861
+
1862
+ if (!selected.hasOwnProperty(name)) {
1863
+ selected[name] = true;
1864
+ }
1865
+
1866
+ selected[name] = !selected[name];
1867
+ });
1868
+ };
1869
+
1870
+ LegendModel.prototype.isSelected = function (name) {
1871
+ var selected = this.option.selected;
1872
+ return !(selected.hasOwnProperty(name) && !selected[name]) && indexOf(this._availableNames, name) >= 0;
1873
+ };
1874
+
1875
+ LegendModel.prototype.getOrient = function () {
1876
+ return this.get('orient') === 'vertical' ? {
1877
+ index: 1,
1878
+ name: 'vertical'
1879
+ } : {
1880
+ index: 0,
1881
+ name: 'horizontal'
1882
+ };
1883
+ };
1884
+
1885
+ LegendModel.type = 'legend.plain';
1886
+ LegendModel.dependencies = ['series'];
1887
+ LegendModel.defaultOption = {
1888
+ // zlevel: 0,
1889
+ z: 4,
1890
+ show: true,
1891
+ orient: 'horizontal',
1892
+ left: 'center',
1893
+ // right: 'center',
1894
+ top: 0,
1895
+ // bottom: null,
1896
+ align: 'auto',
1897
+ backgroundColor: 'rgba(0,0,0,0)',
1898
+ borderColor: '#ccc',
1899
+ borderRadius: 0,
1900
+ borderWidth: 0,
1901
+ padding: 5,
1902
+ itemGap: 10,
1903
+ itemWidth: 25,
1904
+ itemHeight: 14,
1905
+ symbolRotate: 'inherit',
1906
+ symbolKeepAspect: true,
1907
+ inactiveColor: '#ccc',
1908
+ inactiveBorderColor: '#ccc',
1909
+ inactiveBorderWidth: 'auto',
1910
+ itemStyle: {
1911
+ color: 'inherit',
1912
+ opacity: 'inherit',
1913
+ borderColor: 'inherit',
1914
+ borderWidth: 'auto',
1915
+ borderCap: 'inherit',
1916
+ borderJoin: 'inherit',
1917
+ borderDashOffset: 'inherit',
1918
+ borderMiterLimit: 'inherit'
1919
+ },
1920
+ lineStyle: {
1921
+ width: 'auto',
1922
+ color: 'inherit',
1923
+ inactiveColor: '#ccc',
1924
+ inactiveWidth: 2,
1925
+ opacity: 'inherit',
1926
+ type: 'inherit',
1927
+ cap: 'inherit',
1928
+ join: 'inherit',
1929
+ dashOffset: 'inherit',
1930
+ miterLimit: 'inherit'
1931
+ },
1932
+ textStyle: {
1933
+ color: '#333'
1934
+ },
1935
+ selectedMode: true,
1936
+ selector: false,
1937
+ selectorLabel: {
1938
+ show: true,
1939
+ borderRadius: 10,
1940
+ padding: [3, 5, 3, 5],
1941
+ fontSize: 12,
1942
+ fontFamily: 'sans-serif',
1943
+ color: '#666',
1944
+ borderWidth: 1,
1945
+ borderColor: '#666'
1946
+ },
1947
+ emphasis: {
1948
+ selectorLabel: {
1949
+ show: true,
1950
+ color: '#eee',
1951
+ backgroundColor: '#666'
1952
+ }
1953
+ },
1954
+ selectorPosition: 'auto',
1955
+ selectorItemGap: 7,
1956
+ selectorButtonGap: 10,
1957
+ tooltip: {
1958
+ show: false
1959
+ }
1960
+ };
1961
+ return LegendModel;
1962
+ }(ComponentModel);
1963
+
1964
+ var curry = curry$1;
1965
+ var each = each$1;
1966
+ var Group$1 = Group$2;
1967
+
1968
+ var LegendView =
1969
+ /** @class */
1970
+ function (_super) {
1971
+ __extends(LegendView, _super);
1972
+
1973
+ function LegendView() {
1974
+ var _this = _super !== null && _super.apply(this, arguments) || this;
1975
+
1976
+ _this.type = LegendView.type;
1977
+ _this.newlineDisabled = false;
1978
+ return _this;
1979
+ }
1980
+
1981
+ LegendView.prototype.init = function () {
1982
+ this.group.add(this._contentGroup = new Group$1());
1983
+ this.group.add(this._selectorGroup = new Group$1());
1984
+ this._isFirstRender = true;
1985
+ };
1986
+ /**
1987
+ * @protected
1988
+ */
1989
+
1990
+
1991
+ LegendView.prototype.getContentGroup = function () {
1992
+ return this._contentGroup;
1993
+ };
1994
+ /**
1995
+ * @protected
1996
+ */
1997
+
1998
+
1999
+ LegendView.prototype.getSelectorGroup = function () {
2000
+ return this._selectorGroup;
2001
+ };
2002
+ /**
2003
+ * @override
2004
+ */
2005
+
2006
+
2007
+ LegendView.prototype.render = function (legendModel, ecModel, api) {
2008
+ var isFirstRender = this._isFirstRender;
2009
+ this._isFirstRender = false;
2010
+ this.resetInner();
2011
+
2012
+ if (!legendModel.get('show', true)) {
2013
+ return;
2014
+ }
2015
+
2016
+ var itemAlign = legendModel.get('align');
2017
+ var orient = legendModel.get('orient');
2018
+
2019
+ if (!itemAlign || itemAlign === 'auto') {
2020
+ itemAlign = legendModel.get('left') === 'right' && orient === 'vertical' ? 'right' : 'left';
2021
+ } // selector has been normalized to an array in model
2022
+
2023
+
2024
+ var selector = legendModel.get('selector', true);
2025
+ var selectorPosition = legendModel.get('selectorPosition', true);
2026
+
2027
+ if (selector && (!selectorPosition || selectorPosition === 'auto')) {
2028
+ selectorPosition = orient === 'horizontal' ? 'end' : 'start';
2029
+ }
2030
+
2031
+ this.renderInner(itemAlign, legendModel, ecModel, api, selector, orient, selectorPosition); // Perform layout.
2032
+
2033
+ var positionInfo = legendModel.getBoxLayoutParams();
2034
+ var viewportSize = {
2035
+ width: api.getWidth(),
2036
+ height: api.getHeight()
2037
+ };
2038
+ var padding = legendModel.get('padding');
2039
+ var maxSize = getLayoutRect(positionInfo, viewportSize, padding);
2040
+ var mainRect = this.layoutInner(legendModel, itemAlign, maxSize, isFirstRender, selector, selectorPosition); // Place mainGroup, based on the calculated `mainRect`.
2041
+
2042
+ var layoutRect = getLayoutRect(defaults({
2043
+ width: mainRect.width,
2044
+ height: mainRect.height
2045
+ }, positionInfo), viewportSize, padding);
2046
+ this.group.x = layoutRect.x - mainRect.x;
2047
+ this.group.y = layoutRect.y - mainRect.y;
2048
+ this.group.markRedraw(); // Render background after group is layout.
2049
+
2050
+ this.group.add(this._backgroundEl = makeBackground(mainRect, legendModel));
2051
+ };
2052
+
2053
+ LegendView.prototype.resetInner = function () {
2054
+ this.getContentGroup().removeAll();
2055
+ this._backgroundEl && this.group.remove(this._backgroundEl);
2056
+ this.getSelectorGroup().removeAll();
2057
+ };
2058
+
2059
+ LegendView.prototype.renderInner = function (itemAlign, legendModel, ecModel, api, selector, orient, selectorPosition) {
2060
+ var contentGroup = this.getContentGroup();
2061
+ var legendDrawnMap = createHashMap();
2062
+ var selectMode = legendModel.get('selectedMode');
2063
+ var excludeSeriesId = [];
2064
+ ecModel.eachRawSeries(function (seriesModel) {
2065
+ !seriesModel.get('legendHoverLink') && excludeSeriesId.push(seriesModel.id);
2066
+ });
2067
+ each(legendModel.getData(), function (legendItemModel, dataIndex) {
2068
+ var name = legendItemModel.get('name'); // Use empty string or \n as a newline string
2069
+
2070
+ if (!this.newlineDisabled && (name === '' || name === '\n')) {
2071
+ var g = new Group$1(); // @ts-ignore
2072
+
2073
+ g.newline = true;
2074
+ contentGroup.add(g);
2075
+ return;
2076
+ } // Representitive series.
2077
+
2078
+
2079
+ var seriesModel = ecModel.getSeriesByName(name)[0];
2080
+
2081
+ if (legendDrawnMap.get(name)) {
2082
+ // Have been drawn
2083
+ return;
2084
+ } // Legend to control series.
2085
+
2086
+
2087
+ if (seriesModel) {
2088
+ var data = seriesModel.getData();
2089
+ var lineVisualStyle = data.getVisual('legendLineStyle') || {};
2090
+ var legendIcon = data.getVisual('legendIcon');
2091
+ /**
2092
+ * `data.getVisual('style')` may be the color from the register
2093
+ * in series. For example, for line series,
2094
+ */
2095
+
2096
+ var style = data.getVisual('style');
2097
+
2098
+ var itemGroup = this._createItem(seriesModel, name, dataIndex, legendItemModel, legendModel, itemAlign, lineVisualStyle, style, legendIcon, selectMode, api);
2099
+
2100
+ itemGroup.on('click', curry(dispatchSelectAction, name, null, api, excludeSeriesId)).on('mouseover', curry(dispatchHighlightAction, seriesModel.name, null, api, excludeSeriesId)).on('mouseout', curry(dispatchDownplayAction, seriesModel.name, null, api, excludeSeriesId));
2101
+ legendDrawnMap.set(name, true);
2102
+ } else {
2103
+ // Legend to control data. In pie and funnel.
2104
+ ecModel.eachRawSeries(function (seriesModel) {
2105
+ // In case multiple series has same data name
2106
+ if (legendDrawnMap.get(name)) {
2107
+ return;
2108
+ }
2109
+
2110
+ if (seriesModel.legendVisualProvider) {
2111
+ var provider = seriesModel.legendVisualProvider;
2112
+
2113
+ if (!provider.containName(name)) {
2114
+ return;
2115
+ }
2116
+
2117
+ var idx = provider.indexOfName(name);
2118
+ var style = provider.getItemVisual(idx, 'style');
2119
+ var legendIcon = provider.getItemVisual(idx, 'legendIcon');
2120
+ var colorArr = parse(style.fill); // Color may be set to transparent in visualMap when data is out of range.
2121
+ // Do not show nothing.
2122
+
2123
+ if (colorArr && colorArr[3] === 0) {
2124
+ colorArr[3] = 0.2; // TODO color is set to 0, 0, 0, 0. Should show correct RGBA
2125
+
2126
+ style = extend(extend({}, style), {
2127
+ fill: stringify(colorArr, 'rgba')
2128
+ });
2129
+ }
2130
+
2131
+ var itemGroup = this._createItem(seriesModel, name, dataIndex, legendItemModel, legendModel, itemAlign, {}, style, legendIcon, selectMode, api); // FIXME: consider different series has items with the same name.
2132
+
2133
+
2134
+ itemGroup.on('click', curry(dispatchSelectAction, null, name, api, excludeSeriesId)) // Should not specify the series name, consider legend controls
2135
+ // more than one pie series.
2136
+ .on('mouseover', curry(dispatchHighlightAction, null, name, api, excludeSeriesId)).on('mouseout', curry(dispatchDownplayAction, null, name, api, excludeSeriesId));
2137
+ legendDrawnMap.set(name, true);
2138
+ }
2139
+ }, this);
2140
+ }
2141
+ }, this);
2142
+
2143
+ if (selector) {
2144
+ this._createSelector(selector, legendModel, api, orient, selectorPosition);
2145
+ }
2146
+ };
2147
+
2148
+ LegendView.prototype._createSelector = function (selector, legendModel, api, orient, selectorPosition) {
2149
+ var selectorGroup = this.getSelectorGroup();
2150
+ each(selector, function createSelectorButton(selectorItem) {
2151
+ var type = selectorItem.type;
2152
+ var labelText = new ZRText({
2153
+ style: {
2154
+ x: 0,
2155
+ y: 0,
2156
+ align: 'center',
2157
+ verticalAlign: 'middle'
2158
+ },
2159
+ onclick: function () {
2160
+ api.dispatchAction({
2161
+ type: type === 'all' ? 'legendAllSelect' : 'legendInverseSelect'
2162
+ });
2163
+ }
2164
+ });
2165
+ selectorGroup.add(labelText);
2166
+ var labelModel = legendModel.getModel('selectorLabel');
2167
+ var emphasisLabelModel = legendModel.getModel(['emphasis', 'selectorLabel']);
2168
+ setLabelStyle(labelText, {
2169
+ normal: labelModel,
2170
+ emphasis: emphasisLabelModel
2171
+ }, {
2172
+ defaultText: selectorItem.title
2173
+ });
2174
+ enableHoverEmphasis(labelText);
2175
+ });
2176
+ };
2177
+
2178
+ LegendView.prototype._createItem = function (seriesModel, name, dataIndex, legendItemModel, legendModel, itemAlign, lineVisualStyle, itemVisualStyle, legendIcon, selectMode, api) {
2179
+ var drawType = seriesModel.visualDrawType;
2180
+ var itemWidth = legendModel.get('itemWidth');
2181
+ var itemHeight = legendModel.get('itemHeight');
2182
+ var isSelected = legendModel.isSelected(name);
2183
+ var iconRotate = legendItemModel.get('symbolRotate');
2184
+ var symbolKeepAspect = legendItemModel.get('symbolKeepAspect');
2185
+ var legendIconType = legendItemModel.get('icon');
2186
+ legendIcon = legendIconType || legendIcon || 'roundRect';
2187
+ var style = getLegendStyle(legendIcon, legendItemModel, lineVisualStyle, itemVisualStyle, drawType, isSelected, api);
2188
+ var itemGroup = new Group$1();
2189
+ var textStyleModel = legendItemModel.getModel('textStyle');
2190
+
2191
+ if (isFunction(seriesModel.getLegendIcon) && (!legendIconType || legendIconType === 'inherit')) {
2192
+ // Series has specific way to define legend icon
2193
+ itemGroup.add(seriesModel.getLegendIcon({
2194
+ itemWidth: itemWidth,
2195
+ itemHeight: itemHeight,
2196
+ icon: legendIcon,
2197
+ iconRotate: iconRotate,
2198
+ itemStyle: style.itemStyle,
2199
+ lineStyle: style.lineStyle,
2200
+ symbolKeepAspect: symbolKeepAspect
2201
+ }));
2202
+ } else {
2203
+ // Use default legend icon policy for most series
2204
+ var rotate = legendIconType === 'inherit' && seriesModel.getData().getVisual('symbol') ? iconRotate === 'inherit' ? seriesModel.getData().getVisual('symbolRotate') : iconRotate : 0; // No rotation for no icon
2205
+
2206
+ itemGroup.add(getDefaultLegendIcon({
2207
+ itemWidth: itemWidth,
2208
+ itemHeight: itemHeight,
2209
+ icon: legendIcon,
2210
+ iconRotate: rotate,
2211
+ itemStyle: style.itemStyle,
2212
+ lineStyle: style.lineStyle,
2213
+ symbolKeepAspect: symbolKeepAspect
2214
+ }));
2215
+ }
2216
+
2217
+ var textX = itemAlign === 'left' ? itemWidth + 5 : -5;
2218
+ var textAlign = itemAlign;
2219
+ var formatter = legendModel.get('formatter');
2220
+ var content = name;
2221
+
2222
+ if (isString(formatter) && formatter) {
2223
+ content = formatter.replace('{name}', name != null ? name : '');
2224
+ } else if (isFunction(formatter)) {
2225
+ content = formatter(name);
2226
+ }
2227
+
2228
+ var inactiveColor = legendItemModel.get('inactiveColor');
2229
+ itemGroup.add(new ZRText({
2230
+ style: createTextStyle(textStyleModel, {
2231
+ text: content,
2232
+ x: textX,
2233
+ y: itemHeight / 2,
2234
+ fill: isSelected ? textStyleModel.getTextColor() : inactiveColor,
2235
+ align: textAlign,
2236
+ verticalAlign: 'middle'
2237
+ })
2238
+ })); // Add a invisible rect to increase the area of mouse hover
2239
+
2240
+ var hitRect = new Rect({
2241
+ shape: itemGroup.getBoundingRect(),
2242
+ invisible: true
2243
+ });
2244
+ var tooltipModel = legendItemModel.getModel('tooltip');
2245
+
2246
+ if (tooltipModel.get('show')) {
2247
+ setTooltipConfig({
2248
+ el: hitRect,
2249
+ componentModel: legendModel,
2250
+ itemName: name,
2251
+ itemTooltipOption: tooltipModel.option
2252
+ });
2253
+ }
2254
+
2255
+ itemGroup.add(hitRect);
2256
+ itemGroup.eachChild(function (child) {
2257
+ child.silent = true;
2258
+ });
2259
+ hitRect.silent = !selectMode;
2260
+ this.getContentGroup().add(itemGroup);
2261
+ enableHoverEmphasis(itemGroup); // @ts-ignore
2262
+
2263
+ itemGroup.__legendDataIndex = dataIndex;
2264
+ return itemGroup;
2265
+ };
2266
+
2267
+ LegendView.prototype.layoutInner = function (legendModel, itemAlign, maxSize, isFirstRender, selector, selectorPosition) {
2268
+ var contentGroup = this.getContentGroup();
2269
+ var selectorGroup = this.getSelectorGroup(); // Place items in contentGroup.
2270
+
2271
+ box(legendModel.get('orient'), contentGroup, legendModel.get('itemGap'), maxSize.width, maxSize.height);
2272
+ var contentRect = contentGroup.getBoundingRect();
2273
+ var contentPos = [-contentRect.x, -contentRect.y];
2274
+ selectorGroup.markRedraw();
2275
+ contentGroup.markRedraw();
2276
+
2277
+ if (selector) {
2278
+ // Place buttons in selectorGroup
2279
+ box( // Buttons in selectorGroup always layout horizontally
2280
+ 'horizontal', selectorGroup, legendModel.get('selectorItemGap', true));
2281
+ var selectorRect = selectorGroup.getBoundingRect();
2282
+ var selectorPos = [-selectorRect.x, -selectorRect.y];
2283
+ var selectorButtonGap = legendModel.get('selectorButtonGap', true);
2284
+ var orientIdx = legendModel.getOrient().index;
2285
+ var wh = orientIdx === 0 ? 'width' : 'height';
2286
+ var hw = orientIdx === 0 ? 'height' : 'width';
2287
+ var yx = orientIdx === 0 ? 'y' : 'x';
2288
+
2289
+ if (selectorPosition === 'end') {
2290
+ selectorPos[orientIdx] += contentRect[wh] + selectorButtonGap;
2291
+ } else {
2292
+ contentPos[orientIdx] += selectorRect[wh] + selectorButtonGap;
2293
+ } // Always align selector to content as 'middle'
2294
+
2295
+
2296
+ selectorPos[1 - orientIdx] += contentRect[hw] / 2 - selectorRect[hw] / 2;
2297
+ selectorGroup.x = selectorPos[0];
2298
+ selectorGroup.y = selectorPos[1];
2299
+ contentGroup.x = contentPos[0];
2300
+ contentGroup.y = contentPos[1];
2301
+ var mainRect = {
2302
+ x: 0,
2303
+ y: 0
2304
+ };
2305
+ mainRect[wh] = contentRect[wh] + selectorButtonGap + selectorRect[wh];
2306
+ mainRect[hw] = Math.max(contentRect[hw], selectorRect[hw]);
2307
+ mainRect[yx] = Math.min(0, selectorRect[yx] + selectorPos[1 - orientIdx]);
2308
+ return mainRect;
2309
+ } else {
2310
+ contentGroup.x = contentPos[0];
2311
+ contentGroup.y = contentPos[1];
2312
+ return this.group.getBoundingRect();
2313
+ }
2314
+ };
2315
+ /**
2316
+ * @protected
2317
+ */
2318
+
2319
+
2320
+ LegendView.prototype.remove = function () {
2321
+ this.getContentGroup().removeAll();
2322
+ this._isFirstRender = true;
2323
+ };
2324
+
2325
+ LegendView.type = 'legend.plain';
2326
+ return LegendView;
2327
+ }(ComponentView);
2328
+
2329
+ function getLegendStyle(iconType, legendItemModel, lineVisualStyle, itemVisualStyle, drawType, isSelected, api) {
2330
+ /**
2331
+ * Use series style if is inherit;
2332
+ * elsewise, use legend style
2333
+ */
2334
+ function handleCommonProps(style, visualStyle) {
2335
+ // If lineStyle.width is 'auto', it is set to be 2 if series has border
2336
+ if (style.lineWidth === 'auto') {
2337
+ style.lineWidth = visualStyle.lineWidth > 0 ? 2 : 0;
2338
+ }
2339
+
2340
+ each(style, function (propVal, propName) {
2341
+ style[propName] === 'inherit' && (style[propName] = visualStyle[propName]);
2342
+ });
2343
+ } // itemStyle
2344
+
2345
+
2346
+ var itemStyleModel = legendItemModel.getModel('itemStyle');
2347
+ var itemStyle = itemStyleModel.getItemStyle();
2348
+ var iconBrushType = iconType.lastIndexOf('empty', 0) === 0 ? 'fill' : 'stroke';
2349
+ var decalStyle = itemStyleModel.getShallow('decal');
2350
+ itemStyle.decal = !decalStyle || decalStyle === 'inherit' ? itemVisualStyle.decal : createOrUpdatePatternFromDecal(decalStyle, api);
2351
+
2352
+ if (itemStyle.fill === 'inherit') {
2353
+ /**
2354
+ * Series with visualDrawType as 'stroke' should have
2355
+ * series stroke as legend fill
2356
+ */
2357
+ itemStyle.fill = itemVisualStyle[drawType];
2358
+ }
2359
+
2360
+ if (itemStyle.stroke === 'inherit') {
2361
+ /**
2362
+ * icon type with "emptyXXX" should use fill color
2363
+ * in visual style
2364
+ */
2365
+ itemStyle.stroke = itemVisualStyle[iconBrushType];
2366
+ }
2367
+
2368
+ if (itemStyle.opacity === 'inherit') {
2369
+ /**
2370
+ * Use lineStyle.opacity if drawType is stroke
2371
+ */
2372
+ itemStyle.opacity = (drawType === 'fill' ? itemVisualStyle : lineVisualStyle).opacity;
2373
+ }
2374
+
2375
+ handleCommonProps(itemStyle, itemVisualStyle); // lineStyle
2376
+
2377
+ var legendLineModel = legendItemModel.getModel('lineStyle');
2378
+ var lineStyle = legendLineModel.getLineStyle();
2379
+ handleCommonProps(lineStyle, lineVisualStyle); // Fix auto color to real color
2380
+
2381
+ itemStyle.fill === 'auto' && (itemStyle.fill = itemVisualStyle.fill);
2382
+ itemStyle.stroke === 'auto' && (itemStyle.stroke = itemVisualStyle.fill);
2383
+ lineStyle.stroke === 'auto' && (lineStyle.stroke = itemVisualStyle.fill);
2384
+
2385
+ if (!isSelected) {
2386
+ var borderWidth = legendItemModel.get('inactiveBorderWidth');
2387
+ /**
2388
+ * Since stroke is set to be inactiveBorderColor, it may occur that
2389
+ * there is no border in series but border in legend, so we need to
2390
+ * use border only when series has border if is set to be auto
2391
+ */
2392
+
2393
+ var visualHasBorder = itemStyle[iconBrushType];
2394
+ itemStyle.lineWidth = borderWidth === 'auto' ? itemVisualStyle.lineWidth > 0 && visualHasBorder ? 2 : 0 : itemStyle.lineWidth;
2395
+ itemStyle.fill = legendItemModel.get('inactiveColor');
2396
+ itemStyle.stroke = legendItemModel.get('inactiveBorderColor');
2397
+ lineStyle.stroke = legendLineModel.get('inactiveColor');
2398
+ lineStyle.lineWidth = legendLineModel.get('inactiveWidth');
2399
+ }
2400
+
2401
+ return {
2402
+ itemStyle: itemStyle,
2403
+ lineStyle: lineStyle
2404
+ };
2405
+ }
2406
+
2407
+ function getDefaultLegendIcon(opt) {
2408
+ var symboType = opt.icon || 'roundRect';
2409
+ var icon = createSymbol(symboType, 0, 0, opt.itemWidth, opt.itemHeight, opt.itemStyle.fill, opt.symbolKeepAspect);
2410
+ icon.setStyle(opt.itemStyle);
2411
+ icon.rotation = (opt.iconRotate || 0) * Math.PI / 180;
2412
+ icon.setOrigin([opt.itemWidth / 2, opt.itemHeight / 2]);
2413
+
2414
+ if (symboType.indexOf('empty') > -1) {
2415
+ icon.style.stroke = icon.style.fill;
2416
+ icon.style.fill = '#fff';
2417
+ icon.style.lineWidth = 2;
2418
+ }
2419
+
2420
+ return icon;
2421
+ }
2422
+
2423
+ function dispatchSelectAction(seriesName, dataName, api, excludeSeriesId) {
2424
+ // downplay before unselect
2425
+ dispatchDownplayAction(seriesName, dataName, api, excludeSeriesId);
2426
+ api.dispatchAction({
2427
+ type: 'legendToggleSelect',
2428
+ name: seriesName != null ? seriesName : dataName
2429
+ }); // highlight after select
2430
+ // TODO highlight immediately may cause animation loss.
2431
+
2432
+ dispatchHighlightAction(seriesName, dataName, api, excludeSeriesId);
2433
+ }
2434
+
2435
+ function isUseHoverLayer(api) {
2436
+ var list = api.getZr().storage.getDisplayList();
2437
+ var emphasisState;
2438
+ var i = 0;
2439
+ var len = list.length;
2440
+
2441
+ while (i < len && !(emphasisState = list[i].states.emphasis)) {
2442
+ i++;
2443
+ }
2444
+
2445
+ return emphasisState && emphasisState.hoverLayer;
2446
+ }
2447
+
2448
+ function dispatchHighlightAction(seriesName, dataName, api, excludeSeriesId) {
2449
+ // If element hover will move to a hoverLayer.
2450
+ if (!isUseHoverLayer(api)) {
2451
+ api.dispatchAction({
2452
+ type: 'highlight',
2453
+ seriesName: seriesName,
2454
+ name: dataName,
2455
+ excludeSeriesId: excludeSeriesId
2456
+ });
2457
+ }
2458
+ }
2459
+
2460
+ function dispatchDownplayAction(seriesName, dataName, api, excludeSeriesId) {
2461
+ // If element hover will move to a hoverLayer.
2462
+ if (!isUseHoverLayer(api)) {
2463
+ api.dispatchAction({
2464
+ type: 'downplay',
2465
+ seriesName: seriesName,
2466
+ name: dataName,
2467
+ excludeSeriesId: excludeSeriesId
2468
+ });
2469
+ }
2470
+ }
2471
+
2472
+ /*
2473
+ * Licensed to the Apache Software Foundation (ASF) under one
2474
+ * or more contributor license agreements. See the NOTICE file
2475
+ * distributed with this work for additional information
2476
+ * regarding copyright ownership. The ASF licenses this file
2477
+ * to you under the Apache License, Version 2.0 (the
2478
+ * "License"); you may not use this file except in compliance
2479
+ * with the License. You may obtain a copy of the License at
2480
+ *
2481
+ * http://www.apache.org/licenses/LICENSE-2.0
2482
+ *
2483
+ * Unless required by applicable law or agreed to in writing,
2484
+ * software distributed under the License is distributed on an
2485
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
2486
+ * KIND, either express or implied. See the License for the
2487
+ * specific language governing permissions and limitations
2488
+ * under the License.
2489
+ */
2490
+
2491
+
2492
+ /**
2493
+ * AUTO-GENERATED FILE. DO NOT MODIFY.
2494
+ */
2495
+
2496
+ /*
2497
+ * Licensed to the Apache Software Foundation (ASF) under one
2498
+ * or more contributor license agreements. See the NOTICE file
2499
+ * distributed with this work for additional information
2500
+ * regarding copyright ownership. The ASF licenses this file
2501
+ * to you under the Apache License, Version 2.0 (the
2502
+ * "License"); you may not use this file except in compliance
2503
+ * with the License. You may obtain a copy of the License at
2504
+ *
2505
+ * http://www.apache.org/licenses/LICENSE-2.0
2506
+ *
2507
+ * Unless required by applicable law or agreed to in writing,
2508
+ * software distributed under the License is distributed on an
2509
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
2510
+ * KIND, either express or implied. See the License for the
2511
+ * specific language governing permissions and limitations
2512
+ * under the License.
2513
+ */
2514
+ function legendFilter(ecModel) {
2515
+ var legendModels = ecModel.findComponents({
2516
+ mainType: 'legend'
2517
+ });
2518
+
2519
+ if (legendModels && legendModels.length) {
2520
+ ecModel.filterSeries(function (series) {
2521
+ // If in any legend component the status is not selected.
2522
+ // Because in legend series is assumed selected when it is not in the legend data.
2523
+ for (var i = 0; i < legendModels.length; i++) {
2524
+ if (!legendModels[i].isSelected(series.name)) {
2525
+ return false;
2526
+ }
2527
+ }
2528
+
2529
+ return true;
2530
+ });
2531
+ }
2532
+ }
2533
+
2534
+ function legendSelectActionHandler(methodName, payload, ecModel) {
2535
+ var selectedMap = {};
2536
+ var isToggleSelect = methodName === 'toggleSelected';
2537
+ var isSelected; // Update all legend components
2538
+
2539
+ ecModel.eachComponent('legend', function (legendModel) {
2540
+ if (isToggleSelect && isSelected != null) {
2541
+ // Force other legend has same selected status
2542
+ // Or the first is toggled to true and other are toggled to false
2543
+ // In the case one legend has some item unSelected in option. And if other legend
2544
+ // doesn't has the item, they will assume it is selected.
2545
+ legendModel[isSelected ? 'select' : 'unSelect'](payload.name);
2546
+ } else if (methodName === 'allSelect' || methodName === 'inverseSelect') {
2547
+ legendModel[methodName]();
2548
+ } else {
2549
+ legendModel[methodName](payload.name);
2550
+ isSelected = legendModel.isSelected(payload.name);
2551
+ }
2552
+
2553
+ var legendData = legendModel.getData();
2554
+ each$1(legendData, function (model) {
2555
+ var name = model.get('name'); // Wrap element
2556
+
2557
+ if (name === '\n' || name === '') {
2558
+ return;
2559
+ }
2560
+
2561
+ var isItemSelected = legendModel.isSelected(name);
2562
+
2563
+ if (selectedMap.hasOwnProperty(name)) {
2564
+ // Unselected if any legend is unselected
2565
+ selectedMap[name] = selectedMap[name] && isItemSelected;
2566
+ } else {
2567
+ selectedMap[name] = isItemSelected;
2568
+ }
2569
+ });
2570
+ }); // Return the event explicitly
2571
+
2572
+ return methodName === 'allSelect' || methodName === 'inverseSelect' ? {
2573
+ selected: selectedMap
2574
+ } : {
2575
+ name: payload.name,
2576
+ selected: selectedMap
2577
+ };
2578
+ }
2579
+
2580
+ function installLegendAction(registers) {
2581
+ /**
2582
+ * @event legendToggleSelect
2583
+ * @type {Object}
2584
+ * @property {string} type 'legendToggleSelect'
2585
+ * @property {string} [from]
2586
+ * @property {string} name Series name or data item name
2587
+ */
2588
+ registers.registerAction('legendToggleSelect', 'legendselectchanged', curry$1(legendSelectActionHandler, 'toggleSelected'));
2589
+ registers.registerAction('legendAllSelect', 'legendselectall', curry$1(legendSelectActionHandler, 'allSelect'));
2590
+ registers.registerAction('legendInverseSelect', 'legendinverseselect', curry$1(legendSelectActionHandler, 'inverseSelect'));
2591
+ /**
2592
+ * @event legendSelect
2593
+ * @type {Object}
2594
+ * @property {string} type 'legendSelect'
2595
+ * @property {string} name Series name or data item name
2596
+ */
2597
+
2598
+ registers.registerAction('legendSelect', 'legendselected', curry$1(legendSelectActionHandler, 'select'));
2599
+ /**
2600
+ * @event legendUnSelect
2601
+ * @type {Object}
2602
+ * @property {string} type 'legendUnSelect'
2603
+ * @property {string} name Series name or data item name
2604
+ */
2605
+
2606
+ registers.registerAction('legendUnSelect', 'legendunselected', curry$1(legendSelectActionHandler, 'unSelect'));
2607
+ }
2608
+
2609
+ function install$3(registers) {
2610
+ registers.registerComponentModel(LegendModel);
2611
+ registers.registerComponentView(LegendView);
2612
+ registers.registerProcessor(registers.PRIORITY.PROCESSOR.SERIES_FILTER, legendFilter);
2613
+ registers.registerSubTypeDefaulter('legend', function () {
2614
+ return 'plain';
2615
+ });
2616
+ installLegendAction(registers);
2617
+ }
2618
+
2619
+ var ScrollableLegendModel =
2620
+ /** @class */
2621
+ function (_super) {
2622
+ __extends(ScrollableLegendModel, _super);
2623
+
2624
+ function ScrollableLegendModel() {
2625
+ var _this = _super !== null && _super.apply(this, arguments) || this;
2626
+
2627
+ _this.type = ScrollableLegendModel.type;
2628
+ return _this;
2629
+ }
2630
+ /**
2631
+ * @param {number} scrollDataIndex
2632
+ */
2633
+
2634
+
2635
+ ScrollableLegendModel.prototype.setScrollDataIndex = function (scrollDataIndex) {
2636
+ this.option.scrollDataIndex = scrollDataIndex;
2637
+ };
2638
+
2639
+ ScrollableLegendModel.prototype.init = function (option, parentModel, ecModel) {
2640
+ var inputPositionParams = getLayoutParams(option);
2641
+
2642
+ _super.prototype.init.call(this, option, parentModel, ecModel);
2643
+
2644
+ mergeAndNormalizeLayoutParams(this, option, inputPositionParams);
2645
+ };
2646
+ /**
2647
+ * @override
2648
+ */
2649
+
2650
+
2651
+ ScrollableLegendModel.prototype.mergeOption = function (option, ecModel) {
2652
+ _super.prototype.mergeOption.call(this, option, ecModel);
2653
+
2654
+ mergeAndNormalizeLayoutParams(this, this.option, option);
2655
+ };
2656
+
2657
+ ScrollableLegendModel.type = 'legend.scroll';
2658
+ ScrollableLegendModel.defaultOption = inheritDefaultOption(LegendModel.defaultOption, {
2659
+ scrollDataIndex: 0,
2660
+ pageButtonItemGap: 5,
2661
+ pageButtonGap: null,
2662
+ pageButtonPosition: 'end',
2663
+ pageFormatter: '{current}/{total}',
2664
+ pageIcons: {
2665
+ horizontal: ['M0,0L12,-10L12,10z', 'M0,0L-12,-10L-12,10z'],
2666
+ vertical: ['M0,0L20,0L10,-20z', 'M0,0L20,0L10,20z']
2667
+ },
2668
+ pageIconColor: '#2f4554',
2669
+ pageIconInactiveColor: '#aaa',
2670
+ pageIconSize: 15,
2671
+ pageTextStyle: {
2672
+ color: '#333'
2673
+ },
2674
+ animationDurationUpdate: 800
2675
+ });
2676
+ return ScrollableLegendModel;
2677
+ }(LegendModel);
2678
+
2679
+ function mergeAndNormalizeLayoutParams(legendModel, target, raw) {
2680
+ var orient = legendModel.getOrient();
2681
+ var ignoreSize = [1, 1];
2682
+ ignoreSize[orient.index] = 0;
2683
+ mergeLayoutParam(target, raw, {
2684
+ type: 'box',
2685
+ ignoreSize: !!ignoreSize
2686
+ });
2687
+ }
2688
+
2689
+ var Group = Group$2;
2690
+ var WH = ['width', 'height'];
2691
+ var XY = ['x', 'y'];
2692
+
2693
+ var ScrollableLegendView =
2694
+ /** @class */
2695
+ function (_super) {
2696
+ __extends(ScrollableLegendView, _super);
2697
+
2698
+ function ScrollableLegendView() {
2699
+ var _this = _super !== null && _super.apply(this, arguments) || this;
2700
+
2701
+ _this.type = ScrollableLegendView.type;
2702
+ _this.newlineDisabled = true;
2703
+ _this._currentIndex = 0;
2704
+ return _this;
2705
+ }
2706
+
2707
+ ScrollableLegendView.prototype.init = function () {
2708
+ _super.prototype.init.call(this);
2709
+
2710
+ this.group.add(this._containerGroup = new Group());
2711
+
2712
+ this._containerGroup.add(this.getContentGroup());
2713
+
2714
+ this.group.add(this._controllerGroup = new Group());
2715
+ };
2716
+ /**
2717
+ * @override
2718
+ */
2719
+
2720
+
2721
+ ScrollableLegendView.prototype.resetInner = function () {
2722
+ _super.prototype.resetInner.call(this);
2723
+
2724
+ this._controllerGroup.removeAll();
2725
+
2726
+ this._containerGroup.removeClipPath();
2727
+
2728
+ this._containerGroup.__rectSize = null;
2729
+ };
2730
+ /**
2731
+ * @override
2732
+ */
2733
+
2734
+
2735
+ ScrollableLegendView.prototype.renderInner = function (itemAlign, legendModel, ecModel, api, selector, orient, selectorPosition) {
2736
+ var self = this; // Render content items.
2737
+
2738
+ _super.prototype.renderInner.call(this, itemAlign, legendModel, ecModel, api, selector, orient, selectorPosition);
2739
+
2740
+ var controllerGroup = this._controllerGroup; // FIXME: support be 'auto' adapt to size number text length,
2741
+ // e.g., '3/12345' should not overlap with the control arrow button.
2742
+
2743
+ var pageIconSize = legendModel.get('pageIconSize', true);
2744
+ var pageIconSizeArr = isArray(pageIconSize) ? pageIconSize : [pageIconSize, pageIconSize];
2745
+ createPageButton('pagePrev', 0);
2746
+ var pageTextStyleModel = legendModel.getModel('pageTextStyle');
2747
+ controllerGroup.add(new ZRText({
2748
+ name: 'pageText',
2749
+ style: {
2750
+ // Placeholder to calculate a proper layout.
2751
+ text: 'xx/xx',
2752
+ fill: pageTextStyleModel.getTextColor(),
2753
+ font: pageTextStyleModel.getFont(),
2754
+ verticalAlign: 'middle',
2755
+ align: 'center'
2756
+ },
2757
+ silent: true
2758
+ }));
2759
+ createPageButton('pageNext', 1);
2760
+
2761
+ function createPageButton(name, iconIdx) {
2762
+ var pageDataIndexName = name + 'DataIndex';
2763
+ var icon = createIcon(legendModel.get('pageIcons', true)[legendModel.getOrient().name][iconIdx], {
2764
+ // Buttons will be created in each render, so we do not need
2765
+ // to worry about avoiding using legendModel kept in scope.
2766
+ onclick: bind(self._pageGo, self, pageDataIndexName, legendModel, api)
2767
+ }, {
2768
+ x: -pageIconSizeArr[0] / 2,
2769
+ y: -pageIconSizeArr[1] / 2,
2770
+ width: pageIconSizeArr[0],
2771
+ height: pageIconSizeArr[1]
2772
+ });
2773
+ icon.name = name;
2774
+ controllerGroup.add(icon);
2775
+ }
2776
+ };
2777
+ /**
2778
+ * @override
2779
+ */
2780
+
2781
+
2782
+ ScrollableLegendView.prototype.layoutInner = function (legendModel, itemAlign, maxSize, isFirstRender, selector, selectorPosition) {
2783
+ var selectorGroup = this.getSelectorGroup();
2784
+ var orientIdx = legendModel.getOrient().index;
2785
+ var wh = WH[orientIdx];
2786
+ var xy = XY[orientIdx];
2787
+ var hw = WH[1 - orientIdx];
2788
+ var yx = XY[1 - orientIdx];
2789
+ selector && box( // Buttons in selectorGroup always layout horizontally
2790
+ 'horizontal', selectorGroup, legendModel.get('selectorItemGap', true));
2791
+ var selectorButtonGap = legendModel.get('selectorButtonGap', true);
2792
+ var selectorRect = selectorGroup.getBoundingRect();
2793
+ var selectorPos = [-selectorRect.x, -selectorRect.y];
2794
+ var processMaxSize = clone(maxSize);
2795
+ selector && (processMaxSize[wh] = maxSize[wh] - selectorRect[wh] - selectorButtonGap);
2796
+
2797
+ var mainRect = this._layoutContentAndController(legendModel, isFirstRender, processMaxSize, orientIdx, wh, hw, yx, xy);
2798
+
2799
+ if (selector) {
2800
+ if (selectorPosition === 'end') {
2801
+ selectorPos[orientIdx] += mainRect[wh] + selectorButtonGap;
2802
+ } else {
2803
+ var offset = selectorRect[wh] + selectorButtonGap;
2804
+ selectorPos[orientIdx] -= offset;
2805
+ mainRect[xy] -= offset;
2806
+ }
2807
+
2808
+ mainRect[wh] += selectorRect[wh] + selectorButtonGap;
2809
+ selectorPos[1 - orientIdx] += mainRect[yx] + mainRect[hw] / 2 - selectorRect[hw] / 2;
2810
+ mainRect[hw] = Math.max(mainRect[hw], selectorRect[hw]);
2811
+ mainRect[yx] = Math.min(mainRect[yx], selectorRect[yx] + selectorPos[1 - orientIdx]);
2812
+ selectorGroup.x = selectorPos[0];
2813
+ selectorGroup.y = selectorPos[1];
2814
+ selectorGroup.markRedraw();
2815
+ }
2816
+
2817
+ return mainRect;
2818
+ };
2819
+
2820
+ ScrollableLegendView.prototype._layoutContentAndController = function (legendModel, isFirstRender, maxSize, orientIdx, wh, hw, yx, xy) {
2821
+ var contentGroup = this.getContentGroup();
2822
+ var containerGroup = this._containerGroup;
2823
+ var controllerGroup = this._controllerGroup; // Place items in contentGroup.
2824
+
2825
+ box(legendModel.get('orient'), contentGroup, legendModel.get('itemGap'), !orientIdx ? null : maxSize.width, orientIdx ? null : maxSize.height);
2826
+ box( // Buttons in controller are layout always horizontally.
2827
+ 'horizontal', controllerGroup, legendModel.get('pageButtonItemGap', true));
2828
+ var contentRect = contentGroup.getBoundingRect();
2829
+ var controllerRect = controllerGroup.getBoundingRect();
2830
+ var showController = this._showController = contentRect[wh] > maxSize[wh]; // In case that the inner elements of contentGroup layout do not based on [0, 0]
2831
+
2832
+ var contentPos = [-contentRect.x, -contentRect.y]; // Remain contentPos when scroll animation perfroming.
2833
+ // If first rendering, `contentGroup.position` is [0, 0], which
2834
+ // does not make sense and may cause unexepcted animation if adopted.
2835
+
2836
+ if (!isFirstRender) {
2837
+ contentPos[orientIdx] = contentGroup[xy];
2838
+ } // Layout container group based on 0.
2839
+
2840
+
2841
+ var containerPos = [0, 0];
2842
+ var controllerPos = [-controllerRect.x, -controllerRect.y];
2843
+ var pageButtonGap = retrieve2(legendModel.get('pageButtonGap', true), legendModel.get('itemGap', true)); // Place containerGroup and controllerGroup and contentGroup.
2844
+
2845
+ if (showController) {
2846
+ var pageButtonPosition = legendModel.get('pageButtonPosition', true); // controller is on the right / bottom.
2847
+
2848
+ if (pageButtonPosition === 'end') {
2849
+ controllerPos[orientIdx] += maxSize[wh] - controllerRect[wh];
2850
+ } // controller is on the left / top.
2851
+ else {
2852
+ containerPos[orientIdx] += controllerRect[wh] + pageButtonGap;
2853
+ }
2854
+ } // Always align controller to content as 'middle'.
2855
+
2856
+
2857
+ controllerPos[1 - orientIdx] += contentRect[hw] / 2 - controllerRect[hw] / 2;
2858
+ contentGroup.setPosition(contentPos);
2859
+ containerGroup.setPosition(containerPos);
2860
+ controllerGroup.setPosition(controllerPos); // Calculate `mainRect` and set `clipPath`.
2861
+ // mainRect should not be calculated by `this.group.getBoundingRect()`
2862
+ // for sake of the overflow.
2863
+
2864
+ var mainRect = {
2865
+ x: 0,
2866
+ y: 0
2867
+ }; // Consider content may be overflow (should be clipped).
2868
+
2869
+ mainRect[wh] = showController ? maxSize[wh] : contentRect[wh];
2870
+ mainRect[hw] = Math.max(contentRect[hw], controllerRect[hw]); // `containerRect[yx] + containerPos[1 - orientIdx]` is 0.
2871
+
2872
+ mainRect[yx] = Math.min(0, controllerRect[yx] + controllerPos[1 - orientIdx]);
2873
+ containerGroup.__rectSize = maxSize[wh];
2874
+
2875
+ if (showController) {
2876
+ var clipShape = {
2877
+ x: 0,
2878
+ y: 0
2879
+ };
2880
+ clipShape[wh] = Math.max(maxSize[wh] - controllerRect[wh] - pageButtonGap, 0);
2881
+ clipShape[hw] = mainRect[hw];
2882
+ containerGroup.setClipPath(new Rect({
2883
+ shape: clipShape
2884
+ })); // Consider content may be larger than container, container rect
2885
+ // can not be obtained from `containerGroup.getBoundingRect()`.
2886
+
2887
+ containerGroup.__rectSize = clipShape[wh];
2888
+ } else {
2889
+ // Do not remove or ignore controller. Keep them set as placeholders.
2890
+ controllerGroup.eachChild(function (child) {
2891
+ child.attr({
2892
+ invisible: true,
2893
+ silent: true
2894
+ });
2895
+ });
2896
+ } // Content translate animation.
2897
+
2898
+
2899
+ var pageInfo = this._getPageInfo(legendModel);
2900
+
2901
+ pageInfo.pageIndex != null && updateProps(contentGroup, {
2902
+ x: pageInfo.contentPosition[0],
2903
+ y: pageInfo.contentPosition[1]
2904
+ }, // When switch from "show controller" to "not show controller", view should be
2905
+ // updated immediately without animation, otherwise causes weird effect.
2906
+ showController ? legendModel : null);
2907
+
2908
+ this._updatePageInfoView(legendModel, pageInfo);
2909
+
2910
+ return mainRect;
2911
+ };
2912
+
2913
+ ScrollableLegendView.prototype._pageGo = function (to, legendModel, api) {
2914
+ var scrollDataIndex = this._getPageInfo(legendModel)[to];
2915
+
2916
+ scrollDataIndex != null && api.dispatchAction({
2917
+ type: 'legendScroll',
2918
+ scrollDataIndex: scrollDataIndex,
2919
+ legendId: legendModel.id
2920
+ });
2921
+ };
2922
+
2923
+ ScrollableLegendView.prototype._updatePageInfoView = function (legendModel, pageInfo) {
2924
+ var controllerGroup = this._controllerGroup;
2925
+ each$1(['pagePrev', 'pageNext'], function (name) {
2926
+ var key = name + 'DataIndex';
2927
+ var canJump = pageInfo[key] != null;
2928
+ var icon = controllerGroup.childOfName(name);
2929
+
2930
+ if (icon) {
2931
+ icon.setStyle('fill', canJump ? legendModel.get('pageIconColor', true) : legendModel.get('pageIconInactiveColor', true));
2932
+ icon.cursor = canJump ? 'pointer' : 'default';
2933
+ }
2934
+ });
2935
+ var pageText = controllerGroup.childOfName('pageText');
2936
+ var pageFormatter = legendModel.get('pageFormatter');
2937
+ var pageIndex = pageInfo.pageIndex;
2938
+ var current = pageIndex != null ? pageIndex + 1 : 0;
2939
+ var total = pageInfo.pageCount;
2940
+ pageText && pageFormatter && pageText.setStyle('text', isString(pageFormatter) ? pageFormatter.replace('{current}', current == null ? '' : current + '').replace('{total}', total == null ? '' : total + '') : pageFormatter({
2941
+ current: current,
2942
+ total: total
2943
+ }));
2944
+ };
2945
+ /**
2946
+ * contentPosition: Array.<number>, null when data item not found.
2947
+ * pageIndex: number, null when data item not found.
2948
+ * pageCount: number, always be a number, can be 0.
2949
+ * pagePrevDataIndex: number, null when no previous page.
2950
+ * pageNextDataIndex: number, null when no next page.
2951
+ * }
2952
+ */
2953
+
2954
+
2955
+ ScrollableLegendView.prototype._getPageInfo = function (legendModel) {
2956
+ var scrollDataIndex = legendModel.get('scrollDataIndex', true);
2957
+ var contentGroup = this.getContentGroup();
2958
+ var containerRectSize = this._containerGroup.__rectSize;
2959
+ var orientIdx = legendModel.getOrient().index;
2960
+ var wh = WH[orientIdx];
2961
+ var xy = XY[orientIdx];
2962
+
2963
+ var targetItemIndex = this._findTargetItemIndex(scrollDataIndex);
2964
+
2965
+ var children = contentGroup.children();
2966
+ var targetItem = children[targetItemIndex];
2967
+ var itemCount = children.length;
2968
+ var pCount = !itemCount ? 0 : 1;
2969
+ var result = {
2970
+ contentPosition: [contentGroup.x, contentGroup.y],
2971
+ pageCount: pCount,
2972
+ pageIndex: pCount - 1,
2973
+ pagePrevDataIndex: null,
2974
+ pageNextDataIndex: null
2975
+ };
2976
+
2977
+ if (!targetItem) {
2978
+ return result;
2979
+ }
2980
+
2981
+ var targetItemInfo = getItemInfo(targetItem);
2982
+ result.contentPosition[orientIdx] = -targetItemInfo.s; // Strategy:
2983
+ // (1) Always align based on the left/top most item.
2984
+ // (2) It is user-friendly that the last item shown in the
2985
+ // current window is shown at the begining of next window.
2986
+ // Otherwise if half of the last item is cut by the window,
2987
+ // it will have no chance to display entirely.
2988
+ // (3) Consider that item size probably be different, we
2989
+ // have calculate pageIndex by size rather than item index,
2990
+ // and we can not get page index directly by division.
2991
+ // (4) The window is to narrow to contain more than
2992
+ // one item, we should make sure that the page can be fliped.
2993
+
2994
+ for (var i = targetItemIndex + 1, winStartItemInfo = targetItemInfo, winEndItemInfo = targetItemInfo, currItemInfo = null; i <= itemCount; ++i) {
2995
+ currItemInfo = getItemInfo(children[i]);
2996
+
2997
+ if ( // Half of the last item is out of the window.
2998
+ !currItemInfo && winEndItemInfo.e > winStartItemInfo.s + containerRectSize || // If the current item does not intersect with the window, the new page
2999
+ // can be started at the current item or the last item.
3000
+ currItemInfo && !intersect(currItemInfo, winStartItemInfo.s)) {
3001
+ if (winEndItemInfo.i > winStartItemInfo.i) {
3002
+ winStartItemInfo = winEndItemInfo;
3003
+ } else {
3004
+ // e.g., when page size is smaller than item size.
3005
+ winStartItemInfo = currItemInfo;
3006
+ }
3007
+
3008
+ if (winStartItemInfo) {
3009
+ if (result.pageNextDataIndex == null) {
3010
+ result.pageNextDataIndex = winStartItemInfo.i;
3011
+ }
3012
+
3013
+ ++result.pageCount;
3014
+ }
3015
+ }
3016
+
3017
+ winEndItemInfo = currItemInfo;
3018
+ }
3019
+
3020
+ for (var i = targetItemIndex - 1, winStartItemInfo = targetItemInfo, winEndItemInfo = targetItemInfo, currItemInfo = null; i >= -1; --i) {
3021
+ currItemInfo = getItemInfo(children[i]);
3022
+
3023
+ if ( // If the the end item does not intersect with the window started
3024
+ // from the current item, a page can be settled.
3025
+ (!currItemInfo || !intersect(winEndItemInfo, currItemInfo.s)) && // e.g., when page size is smaller than item size.
3026
+ winStartItemInfo.i < winEndItemInfo.i) {
3027
+ winEndItemInfo = winStartItemInfo;
3028
+
3029
+ if (result.pagePrevDataIndex == null) {
3030
+ result.pagePrevDataIndex = winStartItemInfo.i;
3031
+ }
3032
+
3033
+ ++result.pageCount;
3034
+ ++result.pageIndex;
3035
+ }
3036
+
3037
+ winStartItemInfo = currItemInfo;
3038
+ }
3039
+
3040
+ return result;
3041
+
3042
+ function getItemInfo(el) {
3043
+ if (el) {
3044
+ var itemRect = el.getBoundingRect();
3045
+ var start = itemRect[xy] + el[xy];
3046
+ return {
3047
+ s: start,
3048
+ e: start + itemRect[wh],
3049
+ i: el.__legendDataIndex
3050
+ };
3051
+ }
3052
+ }
3053
+
3054
+ function intersect(itemInfo, winStart) {
3055
+ return itemInfo.e >= winStart && itemInfo.s <= winStart + containerRectSize;
3056
+ }
3057
+ };
3058
+
3059
+ ScrollableLegendView.prototype._findTargetItemIndex = function (targetDataIndex) {
3060
+ if (!this._showController) {
3061
+ return 0;
3062
+ }
3063
+
3064
+ var index;
3065
+ var contentGroup = this.getContentGroup();
3066
+ var defaultIndex;
3067
+ contentGroup.eachChild(function (child, idx) {
3068
+ var legendDataIdx = child.__legendDataIndex; // FIXME
3069
+ // If the given targetDataIndex (from model) is illegal,
3070
+ // we use defaultIndex. But the index on the legend model and
3071
+ // action payload is still illegal. That case will not be
3072
+ // changed until some scenario requires.
3073
+
3074
+ if (defaultIndex == null && legendDataIdx != null) {
3075
+ defaultIndex = idx;
3076
+ }
3077
+
3078
+ if (legendDataIdx === targetDataIndex) {
3079
+ index = idx;
3080
+ }
3081
+ });
3082
+ return index != null ? index : defaultIndex;
3083
+ };
3084
+
3085
+ ScrollableLegendView.type = 'legend.scroll';
3086
+ return ScrollableLegendView;
3087
+ }(LegendView);
3088
+
3089
+ /*
3090
+ * Licensed to the Apache Software Foundation (ASF) under one
3091
+ * or more contributor license agreements. See the NOTICE file
3092
+ * distributed with this work for additional information
3093
+ * regarding copyright ownership. The ASF licenses this file
3094
+ * to you under the Apache License, Version 2.0 (the
3095
+ * "License"); you may not use this file except in compliance
3096
+ * with the License. You may obtain a copy of the License at
3097
+ *
3098
+ * http://www.apache.org/licenses/LICENSE-2.0
3099
+ *
3100
+ * Unless required by applicable law or agreed to in writing,
3101
+ * software distributed under the License is distributed on an
3102
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
3103
+ * KIND, either express or implied. See the License for the
3104
+ * specific language governing permissions and limitations
3105
+ * under the License.
3106
+ */
3107
+
3108
+
3109
+ /**
3110
+ * AUTO-GENERATED FILE. DO NOT MODIFY.
3111
+ */
3112
+
3113
+ /*
3114
+ * Licensed to the Apache Software Foundation (ASF) under one
3115
+ * or more contributor license agreements. See the NOTICE file
3116
+ * distributed with this work for additional information
3117
+ * regarding copyright ownership. The ASF licenses this file
3118
+ * to you under the Apache License, Version 2.0 (the
3119
+ * "License"); you may not use this file except in compliance
3120
+ * with the License. You may obtain a copy of the License at
3121
+ *
3122
+ * http://www.apache.org/licenses/LICENSE-2.0
3123
+ *
3124
+ * Unless required by applicable law or agreed to in writing,
3125
+ * software distributed under the License is distributed on an
3126
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
3127
+ * KIND, either express or implied. See the License for the
3128
+ * specific language governing permissions and limitations
3129
+ * under the License.
3130
+ */
3131
+ function installScrollableLegendAction(registers) {
3132
+ /**
3133
+ * @event legendScroll
3134
+ * @type {Object}
3135
+ * @property {string} type 'legendScroll'
3136
+ * @property {string} scrollDataIndex
3137
+ */
3138
+ registers.registerAction('legendScroll', 'legendscroll', function (payload, ecModel) {
3139
+ var scrollDataIndex = payload.scrollDataIndex;
3140
+ scrollDataIndex != null && ecModel.eachComponent({
3141
+ mainType: 'legend',
3142
+ subType: 'scroll',
3143
+ query: payload
3144
+ }, function (legendModel) {
3145
+ legendModel.setScrollDataIndex(scrollDataIndex);
3146
+ });
3147
+ });
3148
+ }
3149
+
3150
+ function install$2(registers) {
3151
+ use(install$3);
3152
+ registers.registerComponentModel(ScrollableLegendModel);
3153
+ registers.registerComponentView(ScrollableLegendView);
3154
+ installScrollableLegendAction(registers);
3155
+ }
3156
+
3157
+ function install$1(registers) {
3158
+ use(install$3);
3159
+ use(install$2);
3160
+ }
3161
+
3162
+ var PI2 = Math.PI * 2;
3163
+ var RADIAN$1 = Math.PI / 180;
3164
+
3165
+ function getViewRect(seriesModel, api) {
3166
+ return getLayoutRect(seriesModel.getBoxLayoutParams(), {
3167
+ width: api.getWidth(),
3168
+ height: api.getHeight()
3169
+ });
3170
+ }
3171
+
3172
+ function getBasicPieLayout(seriesModel, api) {
3173
+ var viewRect = getViewRect(seriesModel, api); // center can be string or number when coordinateSystem is specified
3174
+
3175
+ var center = seriesModel.get('center');
3176
+ var radius = seriesModel.get('radius');
3177
+
3178
+ if (!isArray(radius)) {
3179
+ radius = [0, radius];
3180
+ }
3181
+
3182
+ var width = parsePercent(viewRect.width, api.getWidth());
3183
+ var height = parsePercent(viewRect.height, api.getHeight());
3184
+ var size = Math.min(width, height);
3185
+ var r0 = parsePercent(radius[0], size / 2);
3186
+ var r = parsePercent(radius[1], size / 2);
3187
+ var cx;
3188
+ var cy;
3189
+ var coordSys = seriesModel.coordinateSystem;
3190
+
3191
+ if (coordSys) {
3192
+ // percentage is not allowed when coordinate system is specified
3193
+ var point = coordSys.dataToPoint(center);
3194
+ cx = point[0] || 0;
3195
+ cy = point[1] || 0;
3196
+ } else {
3197
+ if (!isArray(center)) {
3198
+ center = [center, center];
3199
+ }
3200
+
3201
+ cx = parsePercent(center[0], width) + viewRect.x;
3202
+ cy = parsePercent(center[1], height) + viewRect.y;
3203
+ }
3204
+
3205
+ return {
3206
+ cx: cx,
3207
+ cy: cy,
3208
+ r0: r0,
3209
+ r: r
3210
+ };
3211
+ }
3212
+ function pieLayout(seriesType, ecModel, api) {
3213
+ ecModel.eachSeriesByType(seriesType, function (seriesModel) {
3214
+ var data = seriesModel.getData();
3215
+ var valueDim = data.mapDimension('value');
3216
+ var viewRect = getViewRect(seriesModel, api);
3217
+
3218
+ var _a = getBasicPieLayout(seriesModel, api),
3219
+ cx = _a.cx,
3220
+ cy = _a.cy,
3221
+ r = _a.r,
3222
+ r0 = _a.r0;
3223
+
3224
+ var startAngle = -seriesModel.get('startAngle') * RADIAN$1;
3225
+ var minAngle = seriesModel.get('minAngle') * RADIAN$1;
3226
+ var validDataCount = 0;
3227
+ data.each(valueDim, function (value) {
3228
+ !isNaN(value) && validDataCount++;
3229
+ });
3230
+ var sum = data.getSum(valueDim); // Sum may be 0
3231
+
3232
+ var unitRadian = Math.PI / (sum || validDataCount) * 2;
3233
+ var clockwise = seriesModel.get('clockwise');
3234
+ var roseType = seriesModel.get('roseType');
3235
+ var stillShowZeroSum = seriesModel.get('stillShowZeroSum'); // [0...max]
3236
+
3237
+ var extent = data.getDataExtent(valueDim);
3238
+ extent[0] = 0; // In the case some sector angle is smaller than minAngle
3239
+
3240
+ var restAngle = PI2;
3241
+ var valueSumLargerThanMinAngle = 0;
3242
+ var currentAngle = startAngle;
3243
+ var dir = clockwise ? 1 : -1;
3244
+ data.setLayout({
3245
+ viewRect: viewRect,
3246
+ r: r
3247
+ });
3248
+ data.each(valueDim, function (value, idx) {
3249
+ var angle;
3250
+
3251
+ if (isNaN(value)) {
3252
+ data.setItemLayout(idx, {
3253
+ angle: NaN,
3254
+ startAngle: NaN,
3255
+ endAngle: NaN,
3256
+ clockwise: clockwise,
3257
+ cx: cx,
3258
+ cy: cy,
3259
+ r0: r0,
3260
+ r: roseType ? NaN : r
3261
+ });
3262
+ return;
3263
+ } // FIXME 兼容 2.0 但是 roseType 是 area 的时候才是这样?
3264
+
3265
+
3266
+ if (roseType !== 'area') {
3267
+ angle = sum === 0 && stillShowZeroSum ? unitRadian : value * unitRadian;
3268
+ } else {
3269
+ angle = PI2 / validDataCount;
3270
+ }
3271
+
3272
+ if (angle < minAngle) {
3273
+ angle = minAngle;
3274
+ restAngle -= minAngle;
3275
+ } else {
3276
+ valueSumLargerThanMinAngle += value;
3277
+ }
3278
+
3279
+ var endAngle = currentAngle + dir * angle;
3280
+ data.setItemLayout(idx, {
3281
+ angle: angle,
3282
+ startAngle: currentAngle,
3283
+ endAngle: endAngle,
3284
+ clockwise: clockwise,
3285
+ cx: cx,
3286
+ cy: cy,
3287
+ r0: r0,
3288
+ r: roseType ? linearMap(value, extent, [r0, r]) : r
3289
+ });
3290
+ currentAngle = endAngle;
3291
+ }); // Some sector is constrained by minAngle
3292
+ // Rest sectors needs recalculate angle
3293
+
3294
+ if (restAngle < PI2 && validDataCount) {
3295
+ // Average the angle if rest angle is not enough after all angles is
3296
+ // Constrained by minAngle
3297
+ if (restAngle <= 1e-3) {
3298
+ var angle_1 = PI2 / validDataCount;
3299
+ data.each(valueDim, function (value, idx) {
3300
+ if (!isNaN(value)) {
3301
+ var layout_1 = data.getItemLayout(idx);
3302
+ layout_1.angle = angle_1;
3303
+ layout_1.startAngle = startAngle + dir * idx * angle_1;
3304
+ layout_1.endAngle = startAngle + dir * (idx + 1) * angle_1;
3305
+ }
3306
+ });
3307
+ } else {
3308
+ unitRadian = restAngle / valueSumLargerThanMinAngle;
3309
+ currentAngle = startAngle;
3310
+ data.each(valueDim, function (value, idx) {
3311
+ if (!isNaN(value)) {
3312
+ var layout_2 = data.getItemLayout(idx);
3313
+ var angle = layout_2.angle === minAngle ? minAngle : value * unitRadian;
3314
+ layout_2.startAngle = currentAngle;
3315
+ layout_2.endAngle = currentAngle + dir * angle;
3316
+ currentAngle += dir * angle;
3317
+ }
3318
+ });
3319
+ }
3320
+ }
3321
+ });
3322
+ }
3323
+
3324
+ /*
3325
+ * Licensed to the Apache Software Foundation (ASF) under one
3326
+ * or more contributor license agreements. See the NOTICE file
3327
+ * distributed with this work for additional information
3328
+ * regarding copyright ownership. The ASF licenses this file
3329
+ * to you under the Apache License, Version 2.0 (the
3330
+ * "License"); you may not use this file except in compliance
3331
+ * with the License. You may obtain a copy of the License at
3332
+ *
3333
+ * http://www.apache.org/licenses/LICENSE-2.0
3334
+ *
3335
+ * Unless required by applicable law or agreed to in writing,
3336
+ * software distributed under the License is distributed on an
3337
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
3338
+ * KIND, either express or implied. See the License for the
3339
+ * specific language governing permissions and limitations
3340
+ * under the License.
3341
+ */
3342
+
3343
+
3344
+ /**
3345
+ * AUTO-GENERATED FILE. DO NOT MODIFY.
3346
+ */
3347
+
3348
+ /*
3349
+ * Licensed to the Apache Software Foundation (ASF) under one
3350
+ * or more contributor license agreements. See the NOTICE file
3351
+ * distributed with this work for additional information
3352
+ * regarding copyright ownership. The ASF licenses this file
3353
+ * to you under the Apache License, Version 2.0 (the
3354
+ * "License"); you may not use this file except in compliance
3355
+ * with the License. You may obtain a copy of the License at
3356
+ *
3357
+ * http://www.apache.org/licenses/LICENSE-2.0
3358
+ *
3359
+ * Unless required by applicable law or agreed to in writing,
3360
+ * software distributed under the License is distributed on an
3361
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
3362
+ * KIND, either express or implied. See the License for the
3363
+ * specific language governing permissions and limitations
3364
+ * under the License.
3365
+ */
3366
+ function dataFilter(seriesType) {
3367
+ return {
3368
+ seriesType: seriesType,
3369
+ reset: function (seriesModel, ecModel) {
3370
+ var legendModels = ecModel.findComponents({
3371
+ mainType: 'legend'
3372
+ });
3373
+
3374
+ if (!legendModels || !legendModels.length) {
3375
+ return;
3376
+ }
3377
+
3378
+ var data = seriesModel.getData();
3379
+ data.filterSelf(function (idx) {
3380
+ var name = data.getName(idx); // If in any legend component the status is not selected.
3381
+
3382
+ for (var i = 0; i < legendModels.length; i++) {
3383
+ // @ts-ignore FIXME: LegendModel
3384
+ if (!legendModels[i].isSelected(name)) {
3385
+ return false;
3386
+ }
3387
+ }
3388
+
3389
+ return true;
3390
+ });
3391
+ }
3392
+ };
3393
+ }
3394
+
3395
+ var RADIAN = Math.PI / 180;
3396
+
3397
+ function adjustSingleSide(list, cx, cy, r, dir, viewWidth, viewHeight, viewLeft, viewTop, farthestX) {
3398
+ if (list.length < 2) {
3399
+ return;
3400
+ }
3401
+
3402
+ function recalculateXOnSemiToAlignOnEllipseCurve(semi) {
3403
+ var rB = semi.rB;
3404
+ var rB2 = rB * rB;
3405
+
3406
+ for (var i = 0; i < semi.list.length; i++) {
3407
+ var item = semi.list[i];
3408
+ var dy = Math.abs(item.label.y - cy); // horizontal r is always same with original r because x is not changed.
3409
+
3410
+ var rA = r + item.len;
3411
+ var rA2 = rA * rA; // Use ellipse implicit function to calculate x
3412
+
3413
+ var dx = Math.sqrt((1 - Math.abs(dy * dy / rB2)) * rA2);
3414
+ var newX = cx + (dx + item.len2) * dir;
3415
+ var deltaX = newX - item.label.x;
3416
+ var newTargetWidth = item.targetTextWidth - deltaX * dir; // text x is changed, so need to recalculate width.
3417
+
3418
+ constrainTextWidth(item, newTargetWidth, true);
3419
+ item.label.x = newX;
3420
+ }
3421
+ } // Adjust X based on the shifted y. Make tight labels aligned on an ellipse curve.
3422
+
3423
+
3424
+ function recalculateX(items) {
3425
+ // Extremes of
3426
+ var topSemi = {
3427
+ list: [],
3428
+ maxY: 0
3429
+ };
3430
+ var bottomSemi = {
3431
+ list: [],
3432
+ maxY: 0
3433
+ };
3434
+
3435
+ for (var i = 0; i < items.length; i++) {
3436
+ if (items[i].labelAlignTo !== 'none') {
3437
+ continue;
3438
+ }
3439
+
3440
+ var item = items[i];
3441
+ var semi = item.label.y > cy ? bottomSemi : topSemi;
3442
+ var dy = Math.abs(item.label.y - cy);
3443
+
3444
+ if (dy >= semi.maxY) {
3445
+ var dx = item.label.x - cx - item.len2 * dir; // horizontal r is always same with original r because x is not changed.
3446
+
3447
+ var rA = r + item.len; // Canculate rB based on the topest / bottemest label.
3448
+
3449
+ var rB = Math.abs(dx) < rA ? Math.sqrt(dy * dy / (1 - dx * dx / rA / rA)) : rA;
3450
+ semi.rB = rB;
3451
+ semi.maxY = dy;
3452
+ }
3453
+
3454
+ semi.list.push(item);
3455
+ }
3456
+
3457
+ recalculateXOnSemiToAlignOnEllipseCurve(topSemi);
3458
+ recalculateXOnSemiToAlignOnEllipseCurve(bottomSemi);
3459
+ }
3460
+
3461
+ var len = list.length;
3462
+
3463
+ for (var i = 0; i < len; i++) {
3464
+ if (list[i].position === 'outer' && list[i].labelAlignTo === 'labelLine') {
3465
+ var dx = list[i].label.x - farthestX;
3466
+ list[i].linePoints[1][0] += dx;
3467
+ list[i].label.x = farthestX;
3468
+ }
3469
+ }
3470
+
3471
+ if (shiftLayoutOnY(list, viewTop, viewTop + viewHeight)) {
3472
+ recalculateX(list);
3473
+ }
3474
+ }
3475
+
3476
+ function avoidOverlap(labelLayoutList, cx, cy, r, viewWidth, viewHeight, viewLeft, viewTop) {
3477
+ var leftList = [];
3478
+ var rightList = [];
3479
+ var leftmostX = Number.MAX_VALUE;
3480
+ var rightmostX = -Number.MAX_VALUE;
3481
+
3482
+ for (var i = 0; i < labelLayoutList.length; i++) {
3483
+ var label = labelLayoutList[i].label;
3484
+
3485
+ if (isPositionCenter(labelLayoutList[i])) {
3486
+ continue;
3487
+ }
3488
+
3489
+ if (label.x < cx) {
3490
+ leftmostX = Math.min(leftmostX, label.x);
3491
+ leftList.push(labelLayoutList[i]);
3492
+ } else {
3493
+ rightmostX = Math.max(rightmostX, label.x);
3494
+ rightList.push(labelLayoutList[i]);
3495
+ }
3496
+ }
3497
+
3498
+ for (var i = 0; i < labelLayoutList.length; i++) {
3499
+ var layout = labelLayoutList[i];
3500
+
3501
+ if (!isPositionCenter(layout) && layout.linePoints) {
3502
+ if (layout.labelStyleWidth != null) {
3503
+ continue;
3504
+ }
3505
+
3506
+ var label = layout.label;
3507
+ var linePoints = layout.linePoints;
3508
+ var targetTextWidth = void 0;
3509
+
3510
+ if (layout.labelAlignTo === 'edge') {
3511
+ if (label.x < cx) {
3512
+ targetTextWidth = linePoints[2][0] - layout.labelDistance - viewLeft - layout.edgeDistance;
3513
+ } else {
3514
+ targetTextWidth = viewLeft + viewWidth - layout.edgeDistance - linePoints[2][0] - layout.labelDistance;
3515
+ }
3516
+ } else if (layout.labelAlignTo === 'labelLine') {
3517
+ if (label.x < cx) {
3518
+ targetTextWidth = leftmostX - viewLeft - layout.bleedMargin;
3519
+ } else {
3520
+ targetTextWidth = viewLeft + viewWidth - rightmostX - layout.bleedMargin;
3521
+ }
3522
+ } else {
3523
+ if (label.x < cx) {
3524
+ targetTextWidth = label.x - viewLeft - layout.bleedMargin;
3525
+ } else {
3526
+ targetTextWidth = viewLeft + viewWidth - label.x - layout.bleedMargin;
3527
+ }
3528
+ }
3529
+
3530
+ layout.targetTextWidth = targetTextWidth;
3531
+ constrainTextWidth(layout, targetTextWidth);
3532
+ }
3533
+ }
3534
+
3535
+ adjustSingleSide(rightList, cx, cy, r, 1, viewWidth, viewHeight, viewLeft, viewTop, rightmostX);
3536
+ adjustSingleSide(leftList, cx, cy, r, -1, viewWidth, viewHeight, viewLeft, viewTop, leftmostX);
3537
+
3538
+ for (var i = 0; i < labelLayoutList.length; i++) {
3539
+ var layout = labelLayoutList[i];
3540
+
3541
+ if (!isPositionCenter(layout) && layout.linePoints) {
3542
+ var label = layout.label;
3543
+ var linePoints = layout.linePoints;
3544
+ var isAlignToEdge = layout.labelAlignTo === 'edge';
3545
+ var padding = label.style.padding;
3546
+ var paddingH = padding ? padding[1] + padding[3] : 0; // textRect.width already contains paddingH if bgColor is set
3547
+
3548
+ var extraPaddingH = label.style.backgroundColor ? 0 : paddingH;
3549
+ var realTextWidth = layout.rect.width + extraPaddingH;
3550
+ var dist = linePoints[1][0] - linePoints[2][0];
3551
+
3552
+ if (isAlignToEdge) {
3553
+ if (label.x < cx) {
3554
+ linePoints[2][0] = viewLeft + layout.edgeDistance + realTextWidth + layout.labelDistance;
3555
+ } else {
3556
+ linePoints[2][0] = viewLeft + viewWidth - layout.edgeDistance - realTextWidth - layout.labelDistance;
3557
+ }
3558
+ } else {
3559
+ if (label.x < cx) {
3560
+ linePoints[2][0] = label.x + layout.labelDistance;
3561
+ } else {
3562
+ linePoints[2][0] = label.x - layout.labelDistance;
3563
+ }
3564
+
3565
+ linePoints[1][0] = linePoints[2][0] + dist;
3566
+ }
3567
+
3568
+ linePoints[1][1] = linePoints[2][1] = label.y;
3569
+ }
3570
+ }
3571
+ }
3572
+ /**
3573
+ * Set max width of each label, and then wrap each label to the max width.
3574
+ *
3575
+ * @param layout label layout
3576
+ * @param availableWidth max width for the label to display
3577
+ * @param forceRecalculate recaculate the text layout even if the current width
3578
+ * is smaller than `availableWidth`. This is useful when the text was previously
3579
+ * wrapped by calling `constrainTextWidth` but now `availableWidth` changed, in
3580
+ * which case, previous wrapping should be redo.
3581
+ */
3582
+
3583
+
3584
+ function constrainTextWidth(layout, availableWidth, forceRecalculate) {
3585
+ if (forceRecalculate === void 0) {
3586
+ forceRecalculate = false;
3587
+ }
3588
+
3589
+ if (layout.labelStyleWidth != null) {
3590
+ // User-defined style.width has the highest priority.
3591
+ return;
3592
+ }
3593
+
3594
+ var label = layout.label;
3595
+ var style = label.style;
3596
+ var textRect = layout.rect;
3597
+ var bgColor = style.backgroundColor;
3598
+ var padding = style.padding;
3599
+ var paddingH = padding ? padding[1] + padding[3] : 0;
3600
+ var overflow = style.overflow; // textRect.width already contains paddingH if bgColor is set
3601
+
3602
+ var oldOuterWidth = textRect.width + (bgColor ? 0 : paddingH);
3603
+
3604
+ if (availableWidth < oldOuterWidth || forceRecalculate) {
3605
+ var oldHeight = textRect.height;
3606
+
3607
+ if (overflow && overflow.match('break')) {
3608
+ // Temporarily set background to be null to calculate
3609
+ // the bounding box without background.
3610
+ label.setStyle('backgroundColor', null); // Set constraining width
3611
+
3612
+ label.setStyle('width', availableWidth - paddingH); // This is the real bounding box of the text without padding.
3613
+
3614
+ var innerRect = label.getBoundingRect();
3615
+ label.setStyle('width', Math.ceil(innerRect.width));
3616
+ label.setStyle('backgroundColor', bgColor);
3617
+ } else {
3618
+ var availableInnerWidth = availableWidth - paddingH;
3619
+ var newWidth = availableWidth < oldOuterWidth // Current text is too wide, use `availableWidth` as max width.
3620
+ ? availableInnerWidth : // Current available width is enough, but the text may have
3621
+ // already been wrapped with a smaller available width.
3622
+ forceRecalculate ? availableInnerWidth > layout.unconstrainedWidth // Current available is larger than text width,
3623
+ // so don't constrain width (otherwise it may have
3624
+ // empty space in the background).
3625
+ ? null // Current available is smaller than text width, so
3626
+ // use the current available width as constraining
3627
+ // width.
3628
+ : availableInnerWidth : // Current available width is enough, so no need to
3629
+ // constrain.
3630
+ null;
3631
+ label.setStyle('width', newWidth);
3632
+ }
3633
+
3634
+ var newRect = label.getBoundingRect();
3635
+ textRect.width = newRect.width;
3636
+ var margin = (label.style.margin || 0) + 2.1;
3637
+ textRect.height = newRect.height + margin;
3638
+ textRect.y -= (textRect.height - oldHeight) / 2;
3639
+ }
3640
+ }
3641
+
3642
+ function isPositionCenter(sectorShape) {
3643
+ // Not change x for center label
3644
+ return sectorShape.position === 'center';
3645
+ }
3646
+
3647
+ function pieLabelLayout(seriesModel) {
3648
+ var data = seriesModel.getData();
3649
+ var labelLayoutList = [];
3650
+ var cx;
3651
+ var cy;
3652
+ var hasLabelRotate = false;
3653
+ var minShowLabelRadian = (seriesModel.get('minShowLabelAngle') || 0) * RADIAN;
3654
+ var viewRect = data.getLayout('viewRect');
3655
+ var r = data.getLayout('r');
3656
+ var viewWidth = viewRect.width;
3657
+ var viewLeft = viewRect.x;
3658
+ var viewTop = viewRect.y;
3659
+ var viewHeight = viewRect.height;
3660
+
3661
+ function setNotShow(el) {
3662
+ el.ignore = true;
3663
+ }
3664
+
3665
+ function isLabelShown(label) {
3666
+ if (!label.ignore) {
3667
+ return true;
3668
+ }
3669
+
3670
+ for (var key in label.states) {
3671
+ if (label.states[key].ignore === false) {
3672
+ return true;
3673
+ }
3674
+ }
3675
+
3676
+ return false;
3677
+ }
3678
+
3679
+ data.each(function (idx) {
3680
+ var sector = data.getItemGraphicEl(idx);
3681
+ var sectorShape = sector.shape;
3682
+ var label = sector.getTextContent();
3683
+ var labelLine = sector.getTextGuideLine();
3684
+ var itemModel = data.getItemModel(idx);
3685
+ var labelModel = itemModel.getModel('label'); // Use position in normal or emphasis
3686
+
3687
+ var labelPosition = labelModel.get('position') || itemModel.get(['emphasis', 'label', 'position']);
3688
+ var labelDistance = labelModel.get('distanceToLabelLine');
3689
+ var labelAlignTo = labelModel.get('alignTo');
3690
+ var edgeDistance = parsePercent(labelModel.get('edgeDistance'), viewWidth);
3691
+ var bleedMargin = labelModel.get('bleedMargin');
3692
+ var labelLineModel = itemModel.getModel('labelLine');
3693
+ var labelLineLen = labelLineModel.get('length');
3694
+ labelLineLen = parsePercent(labelLineLen, viewWidth);
3695
+ var labelLineLen2 = labelLineModel.get('length2');
3696
+ labelLineLen2 = parsePercent(labelLineLen2, viewWidth);
3697
+
3698
+ if (Math.abs(sectorShape.endAngle - sectorShape.startAngle) < minShowLabelRadian) {
3699
+ each$1(label.states, setNotShow);
3700
+ label.ignore = true;
3701
+
3702
+ if (labelLine) {
3703
+ each$1(labelLine.states, setNotShow);
3704
+ labelLine.ignore = true;
3705
+ }
3706
+
3707
+ return;
3708
+ }
3709
+
3710
+ if (!isLabelShown(label)) {
3711
+ return;
3712
+ }
3713
+
3714
+ var midAngle = (sectorShape.startAngle + sectorShape.endAngle) / 2;
3715
+ var nx = Math.cos(midAngle);
3716
+ var ny = Math.sin(midAngle);
3717
+ var textX;
3718
+ var textY;
3719
+ var linePoints;
3720
+ var textAlign;
3721
+ cx = sectorShape.cx;
3722
+ cy = sectorShape.cy;
3723
+ var isLabelInside = labelPosition === 'inside' || labelPosition === 'inner';
3724
+
3725
+ if (labelPosition === 'center') {
3726
+ textX = sectorShape.cx;
3727
+ textY = sectorShape.cy;
3728
+ textAlign = 'center';
3729
+ } else {
3730
+ var x1 = (isLabelInside ? (sectorShape.r + sectorShape.r0) / 2 * nx : sectorShape.r * nx) + cx;
3731
+ var y1 = (isLabelInside ? (sectorShape.r + sectorShape.r0) / 2 * ny : sectorShape.r * ny) + cy;
3732
+ textX = x1 + nx * 3;
3733
+ textY = y1 + ny * 3;
3734
+
3735
+ if (!isLabelInside) {
3736
+ // For roseType
3737
+ var x2 = x1 + nx * (labelLineLen + r - sectorShape.r);
3738
+ var y2 = y1 + ny * (labelLineLen + r - sectorShape.r);
3739
+ var x3 = x2 + (nx < 0 ? -1 : 1) * labelLineLen2;
3740
+ var y3 = y2;
3741
+
3742
+ if (labelAlignTo === 'edge') {
3743
+ // Adjust textX because text align of edge is opposite
3744
+ textX = nx < 0 ? viewLeft + edgeDistance : viewLeft + viewWidth - edgeDistance;
3745
+ } else {
3746
+ textX = x3 + (nx < 0 ? -labelDistance : labelDistance);
3747
+ }
3748
+
3749
+ textY = y3;
3750
+ linePoints = [[x1, y1], [x2, y2], [x3, y3]];
3751
+ }
3752
+
3753
+ textAlign = isLabelInside ? 'center' : labelAlignTo === 'edge' ? nx > 0 ? 'right' : 'left' : nx > 0 ? 'left' : 'right';
3754
+ }
3755
+
3756
+ var PI = Math.PI;
3757
+ var labelRotate = 0;
3758
+ var rotate = labelModel.get('rotate');
3759
+
3760
+ if (isNumber(rotate)) {
3761
+ labelRotate = rotate * (PI / 180);
3762
+ } else if (labelPosition === 'center') {
3763
+ labelRotate = 0;
3764
+ } else if (rotate === 'radial' || rotate === true) {
3765
+ var radialAngle = nx < 0 ? -midAngle + PI : -midAngle;
3766
+ labelRotate = radialAngle;
3767
+ } else if (rotate === 'tangential' && labelPosition !== 'outside' && labelPosition !== 'outer') {
3768
+ var rad = Math.atan2(nx, ny);
3769
+
3770
+ if (rad < 0) {
3771
+ rad = PI * 2 + rad;
3772
+ }
3773
+
3774
+ var isDown = ny > 0;
3775
+
3776
+ if (isDown) {
3777
+ rad = PI + rad;
3778
+ }
3779
+
3780
+ labelRotate = rad - PI;
3781
+ }
3782
+
3783
+ hasLabelRotate = !!labelRotate;
3784
+ label.x = textX;
3785
+ label.y = textY;
3786
+ label.rotation = labelRotate;
3787
+ label.setStyle({
3788
+ verticalAlign: 'middle'
3789
+ }); // Not sectorShape the inside label
3790
+
3791
+ if (!isLabelInside) {
3792
+ var textRect = label.getBoundingRect().clone();
3793
+ textRect.applyTransform(label.getComputedTransform()); // Text has a default 1px stroke. Exclude this.
3794
+
3795
+ var margin = (label.style.margin || 0) + 2.1;
3796
+ textRect.y -= margin / 2;
3797
+ textRect.height += margin;
3798
+ labelLayoutList.push({
3799
+ label: label,
3800
+ labelLine: labelLine,
3801
+ position: labelPosition,
3802
+ len: labelLineLen,
3803
+ len2: labelLineLen2,
3804
+ minTurnAngle: labelLineModel.get('minTurnAngle'),
3805
+ maxSurfaceAngle: labelLineModel.get('maxSurfaceAngle'),
3806
+ surfaceNormal: new Point(nx, ny),
3807
+ linePoints: linePoints,
3808
+ textAlign: textAlign,
3809
+ labelDistance: labelDistance,
3810
+ labelAlignTo: labelAlignTo,
3811
+ edgeDistance: edgeDistance,
3812
+ bleedMargin: bleedMargin,
3813
+ rect: textRect,
3814
+ unconstrainedWidth: textRect.width,
3815
+ labelStyleWidth: label.style.width
3816
+ });
3817
+ } else {
3818
+ label.setStyle({
3819
+ align: textAlign
3820
+ });
3821
+ var selectState = label.states.select;
3822
+
3823
+ if (selectState) {
3824
+ selectState.x += label.x;
3825
+ selectState.y += label.y;
3826
+ }
3827
+ }
3828
+
3829
+ sector.setTextConfig({
3830
+ inside: isLabelInside
3831
+ });
3832
+ });
3833
+
3834
+ if (!hasLabelRotate && seriesModel.get('avoidLabelOverlap')) {
3835
+ avoidOverlap(labelLayoutList, cx, cy, r, viewWidth, viewHeight, viewLeft, viewTop);
3836
+ }
3837
+
3838
+ for (var i = 0; i < labelLayoutList.length; i++) {
3839
+ var layout = labelLayoutList[i];
3840
+ var label = layout.label;
3841
+ var labelLine = layout.labelLine;
3842
+ var notShowLabel = isNaN(label.x) || isNaN(label.y);
3843
+
3844
+ if (label) {
3845
+ label.setStyle({
3846
+ align: layout.textAlign
3847
+ });
3848
+
3849
+ if (notShowLabel) {
3850
+ each$1(label.states, setNotShow);
3851
+ label.ignore = true;
3852
+ }
3853
+
3854
+ var selectState = label.states.select;
3855
+
3856
+ if (selectState) {
3857
+ selectState.x += label.x;
3858
+ selectState.y += label.y;
3859
+ }
3860
+ }
3861
+
3862
+ if (labelLine) {
3863
+ var linePoints = layout.linePoints;
3864
+
3865
+ if (notShowLabel || !linePoints) {
3866
+ each$1(labelLine.states, setNotShow);
3867
+ labelLine.ignore = true;
3868
+ } else {
3869
+ limitTurnAngle(linePoints, layout.minTurnAngle);
3870
+ limitSurfaceAngle(linePoints, layout.surfaceNormal, layout.maxSurfaceAngle);
3871
+ labelLine.setShape({
3872
+ points: linePoints
3873
+ }); // Set the anchor to the midpoint of sector
3874
+
3875
+ label.__hostTarget.textGuideLineConfig = {
3876
+ anchor: new Point(linePoints[0][0], linePoints[0][1])
3877
+ };
3878
+ }
3879
+ }
3880
+ }
3881
+ }
3882
+
3883
+ function getSectorCornerRadius(model, shape, zeroIfNull) {
3884
+ var cornerRadius = model.get('borderRadius');
3885
+
3886
+ if (cornerRadius == null) {
3887
+ return zeroIfNull ? {
3888
+ cornerRadius: 0
3889
+ } : null;
3890
+ }
3891
+
3892
+ if (!isArray(cornerRadius)) {
3893
+ cornerRadius = [cornerRadius, cornerRadius, cornerRadius, cornerRadius];
3894
+ }
3895
+
3896
+ var dr = Math.abs(shape.r || 0 - shape.r0 || 0);
3897
+ return {
3898
+ cornerRadius: map(cornerRadius, function (cr) {
3899
+ return parsePercent$1(cr, dr);
3900
+ })
3901
+ };
3902
+ }
3903
+
3904
+ /**
3905
+ * Piece of pie including Sector, Label, LabelLine
3906
+ */
3907
+
3908
+ var PiePiece =
3909
+ /** @class */
3910
+ function (_super) {
3911
+ __extends(PiePiece, _super);
3912
+
3913
+ function PiePiece(data, idx, startAngle) {
3914
+ var _this = _super.call(this) || this;
3915
+
3916
+ _this.z2 = 2;
3917
+ var text = new ZRText();
3918
+
3919
+ _this.setTextContent(text);
3920
+
3921
+ _this.updateData(data, idx, startAngle, true);
3922
+
3923
+ return _this;
3924
+ }
3925
+
3926
+ PiePiece.prototype.updateData = function (data, idx, startAngle, firstCreate) {
3927
+ var sector = this;
3928
+ var seriesModel = data.hostModel;
3929
+ var itemModel = data.getItemModel(idx);
3930
+ var emphasisModel = itemModel.getModel('emphasis');
3931
+ var layout = data.getItemLayout(idx); // cornerRadius & innerCornerRadius doesn't exist in the item layout. Use `0` if null value is specified.
3932
+ // see `setItemLayout` in `pieLayout.ts`.
3933
+
3934
+ var sectorShape = extend(getSectorCornerRadius(itemModel.getModel('itemStyle'), layout, true), layout); // Ignore NaN data.
3935
+
3936
+ if (isNaN(sectorShape.startAngle)) {
3937
+ // Use NaN shape to avoid drawing shape.
3938
+ sector.setShape(sectorShape);
3939
+ return;
3940
+ }
3941
+
3942
+ if (firstCreate) {
3943
+ sector.setShape(sectorShape);
3944
+ var animationType = seriesModel.getShallow('animationType');
3945
+
3946
+ if (seriesModel.ecModel.ssr) {
3947
+ // Use scale animation in SSR mode(opacity?)
3948
+ // Because CSS SVG animation doesn't support very customized shape animation.
3949
+ initProps(sector, {
3950
+ scaleX: 0,
3951
+ scaleY: 0
3952
+ }, seriesModel, {
3953
+ dataIndex: idx,
3954
+ isFrom: true
3955
+ });
3956
+ sector.originX = sectorShape.cx;
3957
+ sector.originY = sectorShape.cy;
3958
+ } else if (animationType === 'scale') {
3959
+ sector.shape.r = layout.r0;
3960
+ initProps(sector, {
3961
+ shape: {
3962
+ r: layout.r
3963
+ }
3964
+ }, seriesModel, idx);
3965
+ } // Expansion
3966
+ else {
3967
+ if (startAngle != null) {
3968
+ sector.setShape({
3969
+ startAngle: startAngle,
3970
+ endAngle: startAngle
3971
+ });
3972
+ initProps(sector, {
3973
+ shape: {
3974
+ startAngle: layout.startAngle,
3975
+ endAngle: layout.endAngle
3976
+ }
3977
+ }, seriesModel, idx);
3978
+ } else {
3979
+ sector.shape.endAngle = layout.startAngle;
3980
+ updateProps(sector, {
3981
+ shape: {
3982
+ endAngle: layout.endAngle
3983
+ }
3984
+ }, seriesModel, idx);
3985
+ }
3986
+ }
3987
+ } else {
3988
+ saveOldStyle(sector); // Transition animation from the old shape
3989
+
3990
+ updateProps(sector, {
3991
+ shape: sectorShape
3992
+ }, seriesModel, idx);
3993
+ }
3994
+
3995
+ sector.useStyle(data.getItemVisual(idx, 'style'));
3996
+ setStatesStylesFromModel(sector, itemModel);
3997
+ var midAngle = (layout.startAngle + layout.endAngle) / 2;
3998
+ var offset = seriesModel.get('selectedOffset');
3999
+ var dx = Math.cos(midAngle) * offset;
4000
+ var dy = Math.sin(midAngle) * offset;
4001
+ var cursorStyle = itemModel.getShallow('cursor');
4002
+ cursorStyle && sector.attr('cursor', cursorStyle);
4003
+
4004
+ this._updateLabel(seriesModel, data, idx);
4005
+
4006
+ sector.ensureState('emphasis').shape = extend({
4007
+ r: layout.r + (emphasisModel.get('scale') ? emphasisModel.get('scaleSize') || 0 : 0)
4008
+ }, getSectorCornerRadius(emphasisModel.getModel('itemStyle'), layout));
4009
+ extend(sector.ensureState('select'), {
4010
+ x: dx,
4011
+ y: dy,
4012
+ shape: getSectorCornerRadius(itemModel.getModel(['select', 'itemStyle']), layout)
4013
+ });
4014
+ extend(sector.ensureState('blur'), {
4015
+ shape: getSectorCornerRadius(itemModel.getModel(['blur', 'itemStyle']), layout)
4016
+ });
4017
+ var labelLine = sector.getTextGuideLine();
4018
+ var labelText = sector.getTextContent();
4019
+ labelLine && extend(labelLine.ensureState('select'), {
4020
+ x: dx,
4021
+ y: dy
4022
+ }); // TODO: needs dx, dy in zrender?
4023
+
4024
+ extend(labelText.ensureState('select'), {
4025
+ x: dx,
4026
+ y: dy
4027
+ });
4028
+ toggleHoverEmphasis(this, emphasisModel.get('focus'), emphasisModel.get('blurScope'), emphasisModel.get('disabled'));
4029
+ };
4030
+
4031
+ PiePiece.prototype._updateLabel = function (seriesModel, data, idx) {
4032
+ var sector = this;
4033
+ var itemModel = data.getItemModel(idx);
4034
+ var labelLineModel = itemModel.getModel('labelLine');
4035
+ var style = data.getItemVisual(idx, 'style');
4036
+ var visualColor = style && style.fill;
4037
+ var visualOpacity = style && style.opacity;
4038
+ setLabelStyle(sector, getLabelStatesModels(itemModel), {
4039
+ labelFetcher: data.hostModel,
4040
+ labelDataIndex: idx,
4041
+ inheritColor: visualColor,
4042
+ defaultOpacity: visualOpacity,
4043
+ defaultText: seriesModel.getFormattedLabel(idx, 'normal') || data.getName(idx)
4044
+ });
4045
+ var labelText = sector.getTextContent(); // Set textConfig on sector.
4046
+
4047
+ sector.setTextConfig({
4048
+ // reset position, rotation
4049
+ position: null,
4050
+ rotation: null
4051
+ }); // Make sure update style on labelText after setLabelStyle.
4052
+ // Because setLabelStyle will replace a new style on it.
4053
+
4054
+ labelText.attr({
4055
+ z2: 10
4056
+ });
4057
+ var labelPosition = seriesModel.get(['label', 'position']);
4058
+
4059
+ if (labelPosition !== 'outside' && labelPosition !== 'outer') {
4060
+ sector.removeTextGuideLine();
4061
+ } else {
4062
+ var polyline = this.getTextGuideLine();
4063
+
4064
+ if (!polyline) {
4065
+ polyline = new Polyline();
4066
+ this.setTextGuideLine(polyline);
4067
+ } // Default use item visual color
4068
+
4069
+
4070
+ setLabelLineStyle(this, getLabelLineStatesModels(itemModel), {
4071
+ stroke: visualColor,
4072
+ opacity: retrieve3(labelLineModel.get(['lineStyle', 'opacity']), visualOpacity, 1)
4073
+ });
4074
+ }
4075
+ };
4076
+
4077
+ return PiePiece;
4078
+ }(Sector); // Pie view
4079
+
4080
+
4081
+ var PieView =
4082
+ /** @class */
4083
+ function (_super) {
4084
+ __extends(PieView, _super);
4085
+
4086
+ function PieView() {
4087
+ var _this = _super !== null && _super.apply(this, arguments) || this;
4088
+
4089
+ _this.ignoreLabelLineUpdate = true;
4090
+ return _this;
4091
+ }
4092
+
4093
+ PieView.prototype.render = function (seriesModel, ecModel, api, payload) {
4094
+ var data = seriesModel.getData();
4095
+ var oldData = this._data;
4096
+ var group = this.group;
4097
+ var startAngle; // First render
4098
+
4099
+ if (!oldData && data.count() > 0) {
4100
+ var shape = data.getItemLayout(0);
4101
+
4102
+ for (var s = 1; isNaN(shape && shape.startAngle) && s < data.count(); ++s) {
4103
+ shape = data.getItemLayout(s);
4104
+ }
4105
+
4106
+ if (shape) {
4107
+ startAngle = shape.startAngle;
4108
+ }
4109
+ } // remove empty-circle if it exists
4110
+
4111
+
4112
+ if (this._emptyCircleSector) {
4113
+ group.remove(this._emptyCircleSector);
4114
+ } // when all data are filtered, show lightgray empty circle
4115
+
4116
+
4117
+ if (data.count() === 0 && seriesModel.get('showEmptyCircle')) {
4118
+ var sector = new Sector({
4119
+ shape: getBasicPieLayout(seriesModel, api)
4120
+ });
4121
+ sector.useStyle(seriesModel.getModel('emptyCircleStyle').getItemStyle());
4122
+ this._emptyCircleSector = sector;
4123
+ group.add(sector);
4124
+ }
4125
+
4126
+ data.diff(oldData).add(function (idx) {
4127
+ var piePiece = new PiePiece(data, idx, startAngle);
4128
+ data.setItemGraphicEl(idx, piePiece);
4129
+ group.add(piePiece);
4130
+ }).update(function (newIdx, oldIdx) {
4131
+ var piePiece = oldData.getItemGraphicEl(oldIdx);
4132
+ piePiece.updateData(data, newIdx, startAngle);
4133
+ piePiece.off('click');
4134
+ group.add(piePiece);
4135
+ data.setItemGraphicEl(newIdx, piePiece);
4136
+ }).remove(function (idx) {
4137
+ var piePiece = oldData.getItemGraphicEl(idx);
4138
+ removeElementWithFadeOut(piePiece, seriesModel, idx);
4139
+ }).execute();
4140
+ pieLabelLayout(seriesModel); // Always use initial animation.
4141
+
4142
+ if (seriesModel.get('animationTypeUpdate') !== 'expansion') {
4143
+ this._data = data;
4144
+ }
4145
+ };
4146
+
4147
+ PieView.prototype.dispose = function () {};
4148
+
4149
+ PieView.prototype.containPoint = function (point, seriesModel) {
4150
+ var data = seriesModel.getData();
4151
+ var itemLayout = data.getItemLayout(0);
4152
+
4153
+ if (itemLayout) {
4154
+ var dx = point[0] - itemLayout.cx;
4155
+ var dy = point[1] - itemLayout.cy;
4156
+ var radius = Math.sqrt(dx * dx + dy * dy);
4157
+ return radius <= itemLayout.r && radius >= itemLayout.r0;
4158
+ }
4159
+ };
4160
+
4161
+ PieView.type = 'pie';
4162
+ return PieView;
4163
+ }(ChartView);
4164
+
4165
+ /**
4166
+ * [Usage]:
4167
+ * (1)
4168
+ * createListSimply(seriesModel, ['value']);
4169
+ * (2)
4170
+ * createListSimply(seriesModel, {
4171
+ * coordDimensions: ['value'],
4172
+ * dimensionsCount: 5
4173
+ * });
4174
+ */
4175
+
4176
+ function createSeriesDataSimply(seriesModel, opt, nameList) {
4177
+ opt = isArray(opt) && {
4178
+ coordDimensions: opt
4179
+ } || extend({
4180
+ encodeDefine: seriesModel.getEncode()
4181
+ }, opt);
4182
+ var source = seriesModel.getSource();
4183
+ var dimensions = prepareSeriesDataSchema(source, opt).dimensions;
4184
+ var list = new SeriesData(dimensions, seriesModel);
4185
+ list.initData(source, nameList);
4186
+ return list;
4187
+ }
4188
+
4189
+ /*
4190
+ * Licensed to the Apache Software Foundation (ASF) under one
4191
+ * or more contributor license agreements. See the NOTICE file
4192
+ * distributed with this work for additional information
4193
+ * regarding copyright ownership. The ASF licenses this file
4194
+ * to you under the Apache License, Version 2.0 (the
4195
+ * "License"); you may not use this file except in compliance
4196
+ * with the License. You may obtain a copy of the License at
4197
+ *
4198
+ * http://www.apache.org/licenses/LICENSE-2.0
4199
+ *
4200
+ * Unless required by applicable law or agreed to in writing,
4201
+ * software distributed under the License is distributed on an
4202
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
4203
+ * KIND, either express or implied. See the License for the
4204
+ * specific language governing permissions and limitations
4205
+ * under the License.
4206
+ */
4207
+
4208
+
4209
+ /**
4210
+ * AUTO-GENERATED FILE. DO NOT MODIFY.
4211
+ */
4212
+
4213
+ /*
4214
+ * Licensed to the Apache Software Foundation (ASF) under one
4215
+ * or more contributor license agreements. See the NOTICE file
4216
+ * distributed with this work for additional information
4217
+ * regarding copyright ownership. The ASF licenses this file
4218
+ * to you under the Apache License, Version 2.0 (the
4219
+ * "License"); you may not use this file except in compliance
4220
+ * with the License. You may obtain a copy of the License at
4221
+ *
4222
+ * http://www.apache.org/licenses/LICENSE-2.0
4223
+ *
4224
+ * Unless required by applicable law or agreed to in writing,
4225
+ * software distributed under the License is distributed on an
4226
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
4227
+ * KIND, either express or implied. See the License for the
4228
+ * specific language governing permissions and limitations
4229
+ * under the License.
4230
+ */
4231
+
4232
+ /**
4233
+ * LegendVisualProvider is an bridge that pick encoded color from data and
4234
+ * provide to the legend component.
4235
+ */
4236
+ var LegendVisualProvider =
4237
+ /** @class */
4238
+ function () {
4239
+ function LegendVisualProvider( // Function to get data after filtered. It stores all the encoding info
4240
+ getDataWithEncodedVisual, // Function to get raw data before filtered.
4241
+ getRawData) {
4242
+ this._getDataWithEncodedVisual = getDataWithEncodedVisual;
4243
+ this._getRawData = getRawData;
4244
+ }
4245
+
4246
+ LegendVisualProvider.prototype.getAllNames = function () {
4247
+ var rawData = this._getRawData(); // We find the name from the raw data. In case it's filtered by the legend component.
4248
+ // Normally, the name can be found in rawData, but can't be found in filtered data will display as gray.
4249
+
4250
+
4251
+ return rawData.mapArray(rawData.getName);
4252
+ };
4253
+
4254
+ LegendVisualProvider.prototype.containName = function (name) {
4255
+ var rawData = this._getRawData();
4256
+
4257
+ return rawData.indexOfName(name) >= 0;
4258
+ };
4259
+
4260
+ LegendVisualProvider.prototype.indexOfName = function (name) {
4261
+ // Only get data when necessary.
4262
+ // Because LegendVisualProvider constructor may be new in the stage that data is not prepared yet.
4263
+ // Invoking Series#getData immediately will throw an error.
4264
+ var dataWithEncodedVisual = this._getDataWithEncodedVisual();
4265
+
4266
+ return dataWithEncodedVisual.indexOfName(name);
4267
+ };
4268
+
4269
+ LegendVisualProvider.prototype.getItemVisual = function (dataIndex, key) {
4270
+ // Get encoded visual properties from final filtered data.
4271
+ var dataWithEncodedVisual = this._getDataWithEncodedVisual();
4272
+
4273
+ return dataWithEncodedVisual.getItemVisual(dataIndex, key);
4274
+ };
4275
+
4276
+ return LegendVisualProvider;
4277
+ }();
4278
+
4279
+ var innerData = makeInner();
4280
+
4281
+ var PieSeriesModel =
4282
+ /** @class */
4283
+ function (_super) {
4284
+ __extends(PieSeriesModel, _super);
4285
+
4286
+ function PieSeriesModel() {
4287
+ return _super !== null && _super.apply(this, arguments) || this;
4288
+ }
4289
+ /**
4290
+ * @overwrite
4291
+ */
4292
+
4293
+
4294
+ PieSeriesModel.prototype.init = function (option) {
4295
+ _super.prototype.init.apply(this, arguments); // Enable legend selection for each data item
4296
+ // Use a function instead of direct access because data reference may changed
4297
+
4298
+
4299
+ this.legendVisualProvider = new LegendVisualProvider(bind(this.getData, this), bind(this.getRawData, this));
4300
+
4301
+ this._defaultLabelLine(option);
4302
+ };
4303
+ /**
4304
+ * @overwrite
4305
+ */
4306
+
4307
+
4308
+ PieSeriesModel.prototype.mergeOption = function () {
4309
+ _super.prototype.mergeOption.apply(this, arguments);
4310
+ };
4311
+ /**
4312
+ * @overwrite
4313
+ */
4314
+
4315
+
4316
+ PieSeriesModel.prototype.getInitialData = function () {
4317
+ return createSeriesDataSimply(this, {
4318
+ coordDimensions: ['value'],
4319
+ encodeDefaulter: curry$1(makeSeriesEncodeForNameBased, this)
4320
+ });
4321
+ };
4322
+ /**
4323
+ * @overwrite
4324
+ */
4325
+
4326
+
4327
+ PieSeriesModel.prototype.getDataParams = function (dataIndex) {
4328
+ var data = this.getData(); // update seats when data is changed
4329
+
4330
+ var dataInner = innerData(data);
4331
+ var seats = dataInner.seats;
4332
+
4333
+ if (!seats) {
4334
+ var valueList_1 = [];
4335
+ data.each(data.mapDimension('value'), function (value) {
4336
+ valueList_1.push(value);
4337
+ });
4338
+ seats = dataInner.seats = getPercentSeats(valueList_1, data.hostModel.get('percentPrecision'));
4339
+ }
4340
+
4341
+ var params = _super.prototype.getDataParams.call(this, dataIndex); // seats may be empty when sum is 0
4342
+
4343
+
4344
+ params.percent = seats[dataIndex] || 0;
4345
+ params.$vars.push('percent');
4346
+ return params;
4347
+ };
4348
+
4349
+ PieSeriesModel.prototype._defaultLabelLine = function (option) {
4350
+ // Extend labelLine emphasis
4351
+ defaultEmphasis(option, 'labelLine', ['show']);
4352
+ var labelLineNormalOpt = option.labelLine;
4353
+ var labelLineEmphasisOpt = option.emphasis.labelLine; // Not show label line if `label.normal.show = false`
4354
+
4355
+ labelLineNormalOpt.show = labelLineNormalOpt.show && option.label.show;
4356
+ labelLineEmphasisOpt.show = labelLineEmphasisOpt.show && option.emphasis.label.show;
4357
+ };
4358
+
4359
+ PieSeriesModel.type = 'series.pie';
4360
+ PieSeriesModel.defaultOption = {
4361
+ // zlevel: 0,
4362
+ z: 2,
4363
+ legendHoverLink: true,
4364
+ colorBy: 'data',
4365
+ // 默认全局居中
4366
+ center: ['50%', '50%'],
4367
+ radius: [0, '75%'],
4368
+ // 默认顺时针
4369
+ clockwise: true,
4370
+ startAngle: 90,
4371
+ // 最小角度改为0
4372
+ minAngle: 0,
4373
+ // If the angle of a sector less than `minShowLabelAngle`,
4374
+ // the label will not be displayed.
4375
+ minShowLabelAngle: 0,
4376
+ // 选中时扇区偏移量
4377
+ selectedOffset: 10,
4378
+ // 选择模式,默认关闭,可选single,multiple
4379
+ // selectedMode: false,
4380
+ // 南丁格尔玫瑰图模式,'radius'(半径) | 'area'(面积)
4381
+ // roseType: null,
4382
+ percentPrecision: 2,
4383
+ // If still show when all data zero.
4384
+ stillShowZeroSum: true,
4385
+ // cursor: null,
4386
+ left: 0,
4387
+ top: 0,
4388
+ right: 0,
4389
+ bottom: 0,
4390
+ width: null,
4391
+ height: null,
4392
+ label: {
4393
+ // color: 'inherit',
4394
+ // If rotate around circle
4395
+ rotate: 0,
4396
+ show: true,
4397
+ overflow: 'truncate',
4398
+ // 'outer', 'inside', 'center'
4399
+ position: 'outer',
4400
+ // 'none', 'labelLine', 'edge'. Works only when position is 'outer'
4401
+ alignTo: 'none',
4402
+ // Closest distance between label and chart edge.
4403
+ // Works only position is 'outer' and alignTo is 'edge'.
4404
+ edgeDistance: '25%',
4405
+ // Works only position is 'outer' and alignTo is not 'edge'.
4406
+ bleedMargin: 10,
4407
+ // Distance between text and label line.
4408
+ distanceToLabelLine: 5 // formatter: 标签文本格式器,同 tooltip.formatter,不支持异步回调
4409
+ // 默认使用全局文本样式,详见 textStyle
4410
+ // distance: 当position为inner时有效,为label位置到圆心的距离与圆半径(环状图为内外半径和)的比例系数
4411
+
4412
+ },
4413
+ // Enabled when label.normal.position is 'outer'
4414
+ labelLine: {
4415
+ show: true,
4416
+ // 引导线两段中的第一段长度
4417
+ length: 15,
4418
+ // 引导线两段中的第二段长度
4419
+ length2: 15,
4420
+ smooth: false,
4421
+ minTurnAngle: 90,
4422
+ maxSurfaceAngle: 90,
4423
+ lineStyle: {
4424
+ // color: 各异,
4425
+ width: 1,
4426
+ type: 'solid'
4427
+ }
4428
+ },
4429
+ itemStyle: {
4430
+ borderWidth: 1,
4431
+ borderJoin: 'round'
4432
+ },
4433
+ showEmptyCircle: true,
4434
+ emptyCircleStyle: {
4435
+ color: 'lightgray',
4436
+ opacity: 1
4437
+ },
4438
+ labelLayout: {
4439
+ // Hide the overlapped label.
4440
+ hideOverlap: true
4441
+ },
4442
+ emphasis: {
4443
+ scale: true,
4444
+ scaleSize: 5
4445
+ },
4446
+ // If use strategy to avoid label overlapping
4447
+ avoidLabelOverlap: true,
4448
+ // Animation type. Valid values: expansion, scale
4449
+ animationType: 'expansion',
4450
+ animationDuration: 1000,
4451
+ // Animation type when update. Valid values: transition, expansion
4452
+ animationTypeUpdate: 'transition',
4453
+ animationEasingUpdate: 'cubicInOut',
4454
+ animationDurationUpdate: 500,
4455
+ animationEasing: 'cubicInOut'
4456
+ };
4457
+ return PieSeriesModel;
4458
+ }(SeriesModel);
4459
+
4460
+ function negativeDataFilter(seriesType) {
4461
+ return {
4462
+ seriesType: seriesType,
4463
+ reset: function (seriesModel, ecModel) {
4464
+ var data = seriesModel.getData();
4465
+ data.filterSelf(function (idx) {
4466
+ // handle negative value condition
4467
+ var valueDim = data.mapDimension('value');
4468
+ var curValue = data.get(valueDim, idx);
4469
+
4470
+ if (isNumber(curValue) && !isNaN(curValue) && curValue < 0) {
4471
+ return false;
4472
+ }
4473
+
4474
+ return true;
4475
+ });
4476
+ }
4477
+ };
4478
+ }
4479
+
4480
+ function install(registers) {
4481
+ registers.registerChartView(PieView);
4482
+ registers.registerSeriesModel(PieSeriesModel);
4483
+ createLegacyDataSelectAction('pie', registers.registerAction);
4484
+ registers.registerLayout(curry$1(pieLayout, 'pie'));
4485
+ registers.registerProcessor(dataFilter('pie'));
4486
+ registers.registerProcessor(negativeDataFilter('pie'));
4487
+ }
4488
+
4489
+ const stylesCss = "*{box-sizing:border-box}*:active{outline:none}*:focus{outline:none;box-shadow:var(--const-double-focus-ring, 0 0 0 2px #ffffff, 0 0 0 4px #33b4ff #06C)}:host{box-shadow:none !important}::-moz-focus-inner{border:none}input,textarea,button{font-family:inherit;font-size:inherit;font-stretch:inherit}:host(.sr),:host(.sr) button{border:0;clip:rect(0 0 0 0);height:1px;margin:-1px;overflow:hidden;padding:0;position:absolute;width:1px;white-space:nowrap}.sr,.sr button{border:0;clip:rect(0 0 0 0);height:1px;margin:-1px;overflow:hidden;padding:0;position:absolute;width:1px;white-space:nowrap}.hidden{display:none}:host([hidden]){display:none}.invisible{visibility:hidden}:host{position:relative;width:100%;display:block}.container{aspect-ratio:1/1;width:100%;display:flex;justify-content:center;align-items:center}.chart-container{width:100%;height:100%;--comp-color-1:var(--tct-chart-donut-color-1, var(--t-chart-donut-color-1, var(--t-accent-1, #e05252)));--comp-color-2:var(--tct-chart-donut-color-2, var(--t-chart-donut-color-2, var(--t-accent-2, #e09952)));--comp-color-3:var(--tct-chart-donut-color-3, var(--t-chart-donut-color-3, var(--t-accent-3, #e0e052)));--comp-color-4:var(--tct-chart-donut-color-4, var(--t-chart-donut-color-4, var(--t-accent-4, #99e052)));--comp-color-5:var(--tct-chart-donut-color-5, var(--t-chart-donut-color-5, var(--t-accent-5, #52e052)));--comp-color-6:var(--tct-chart-donut-color-6, var(--t-chart-donut-color-6, var(--t-accent-6, #52e099)));--comp-color-7:var(--tct-chart-donut-color-7, var(--t-chart-donut-color-7, var(--t-accent-7, #52e0e0)));--comp-color-8:var(--tct-chart-donut-color-8, var(--t-chart-donut-color-8, var(--t-accent-8, #5299e0)));--comp-color-9:var(--tct-chart-donut-color-9, var(--t-chart-donut-color-9, var(--t-accent-9, #5252e0)));--comp-color-10:var(--tct-chart-donut-color-10, var(--t-chart-donut-color-10, var(--t-accent-10, #9952e0)));--comp-color-11:var(--tct-chart-donut-color-11, var(--t-chart-donut-color-11, var(--t-accent-11, #e052e0)));--comp-color-12:var(--tct-chart-donut-color-12, var(--t-chart-donut-color-12, var(--t-accent-12, #e05299)))}.chart-container,.center-card{--comp-background-color:var(--tct-chart-donut-border-color, var(--t-chart-donut-border-color, var(--t-base, #ffffff)))}button{--comp-button-vertical-padding:var(--tct-chart-donut-button-vertical-padding, var(--t-chart-donut-button-vertical-padding, var(--app-scale-1x, 5px)));transition:box-shadow var(--tct-chart-donut-button-tween, var(--t-chart-donut-button-tween, var(--app-tween-1, 0.2s ease)));padding:var(--comp-button-vertical-padding) 0}button:active{box-shadow:var(--const-double-focus-ring), var(--tct-chart-donut-button-hover-box-shadow, var(--t-chart-donut-button-hover-box-shadow, var(--app-shadow-1, 0 2px 4px rgba(0, 0, 0, 0.3))))}button:hover{box-shadow:var(--tct-chart-donut-button-hover-box-shadow, var(--t-chart-donut-button-hover-box-shadow, var(--app-shadow-1, 0 2px 4px rgba(0, 0, 0, 0.3))))}button:focus{box-shadow:var(--const-double-focus-ring), var(--tct-chart-donut-button-hover-box-shadow, var(--t-chart-donut-button-hover-box-shadow, var(--app-shadow-1, 0 2px 4px rgba(0, 0, 0, 0.3))))}.center-card-container{position:absolute;top:50%;transform:translateY(-50%);padding:var(--tct-chart-donut-button-container-padding, var(--t-chart-donut-button-container-padding, var(--app-scale-1x, 5px)))}.center-card{width:100%;text-align:center;color:var(--tct-chart-donut-text-color, var(--t-chart-donut-text-color, var(--t-text, #4d4d4d)));margin-inline:auto;display:block}.center-card:is(button){cursor:pointer;background:var(--comp-background-color);border:0;border-radius:var(--tct-chart-donut-button-border-radius, var(--t-chart-donut-button-border-radius, var(--app-border-radius-1, 3px)))}q2-icon{--tct-icon-size:var(--tct-chart-donut-icon-size, var(--t-chart-donut-icon-size, 26px));margin-bottom:var(--tct-chart-donut-icon-margin-bottom, var(--t-chart-donut-icon-margin-bottom, var(--app-scale-1x, 5px)))}.name{font-size:var(--tct-chart-donut-name-font-size, var(--t-chart-donut-name-font-size, 14px))}.value{font-size:var(--tct-chart-donut-value-font-size, var(--t-chart-donut-value-font-size, 21px))}";
4490
+
4491
+ use([install$4, install$1, install, install$6, install$7, installLabelLayout]);
4492
+ const Q2ChartDonut$1 = /*@__PURE__*/ proxyCustomElement(class extends HTMLElement {
4493
+ constructor() {
4494
+ super();
4495
+ this.__registerHost();
4496
+ this.__attachShadow();
4497
+ this.change = createEvent(this, "change", 7);
4498
+ this.click = createEvent(this, "click", 7);
4499
+ this.defaultRecord = { id: null, value: null, name: null };
4500
+ /// Event Handlers ///
4501
+ this.onClickElsewhere = (event) => {
4502
+ event.stopPropagation();
4503
+ this.clearSelection();
4504
+ };
4505
+ this.onButtonKeyUp = (event) => {
4506
+ const { selectedId, data } = this;
4507
+ let selectedIndex = this.getIndexById(selectedId) || 0;
4508
+ switch (event.key) {
4509
+ case 'ArrowLeft':
4510
+ case 'ArrowUp':
4511
+ selectedIndex--;
4512
+ if (selectedIndex < 0)
4513
+ selectedIndex = data.length - 1;
4514
+ this.chart.dispatchAction({
4515
+ type: 'select',
4516
+ seriesId: 'pie',
4517
+ dataIndex: selectedIndex,
4518
+ });
4519
+ break;
4520
+ case 'ArrowRight':
4521
+ case 'ArrowDown':
4522
+ selectedIndex++;
4523
+ if (selectedIndex > data.length - 1)
4524
+ selectedIndex = 0;
4525
+ this.chart.dispatchAction({
4526
+ type: 'select',
4527
+ seriesId: 'pie',
4528
+ dataIndex: selectedIndex,
4529
+ });
4530
+ break;
4531
+ case 'Escape':
4532
+ this.clearSelection();
4533
+ break;
4534
+ default:
4535
+ return;
4536
+ }
4537
+ };
4538
+ this.onButtonClick = (event) => {
4539
+ event.stopPropagation();
4540
+ const { selectedId } = this;
4541
+ const data = selectedId ? this.getDataById(selectedId) : Object.assign({}, this.defaultRecord);
4542
+ this.click.emit(data);
4543
+ };
4544
+ this.onContainerClick = (event) => {
4545
+ if (this.isInChangeEvent)
4546
+ return;
4547
+ if (!(event.target instanceof HTMLElement))
4548
+ return;
4549
+ this.clearSelection();
4550
+ event.stopPropagation();
4551
+ };
4552
+ this.chartName = undefined;
4553
+ this.summaryIcon = undefined;
4554
+ this.summaryName = undefined;
4555
+ this.innerRadius = '70%';
4556
+ this.outerRadius = '85%';
4557
+ this.minSliceSize = '2.5%';
4558
+ this.selectedOffset = 10;
4559
+ this.hoverScaleSize = 5;
4560
+ this.format = undefined;
4561
+ this.isClickable = undefined;
4562
+ this.data = [];
4563
+ this.selectedId = undefined;
4564
+ this.hoveredId = undefined;
4565
+ }
4566
+ /// LifeCycle Hooks ///
4567
+ componentDidLoad() {
4568
+ const chart = init(this.chartContainer);
4569
+ this.cacheComputedStyles();
4570
+ this.colors = this.getColors();
4571
+ this.resizeObserver = new ResizeObserver(() => this.resizeChart());
4572
+ this.resizeObserver.observe(this.hostElement);
4573
+ this.updateChart(chart);
4574
+ this.setupChartEvents(chart);
4575
+ this.chart = chart;
4576
+ overrideFocus(this.hostElement);
4577
+ }
4578
+ willDestroyElement() {
4579
+ this.resizeObserver = null;
4580
+ }
4581
+ /// Getters ///
4582
+ get centerData() {
4583
+ const { selectedId, hoveredId, data } = this;
4584
+ const idToDisplay = hoveredId || selectedId;
4585
+ const index = this.getIndexById(idToDisplay);
4586
+ return idToDisplay
4587
+ ? Object.assign(Object.assign({}, this.getDataById(idToDisplay)), { color: this.colors[index] }) : {
4588
+ name: loc(this.summaryName || 'tecton.element.chartDonut.button.summaryName'),
4589
+ icon: this.summaryIcon,
4590
+ value: data.reduce((acc, cur) => acc + cur.value, 0),
4591
+ color: null,
4592
+ };
4593
+ }
4594
+ /// Helpers
4595
+ cacheComputedStyles() {
4596
+ this.chartContainerStyles = getComputedStyle(this.chartContainer);
4597
+ this.hostElementStyles = getComputedStyle(this.hostElement);
4598
+ }
4599
+ displayValue(value) {
4600
+ const valueAsFloat = parseFloat(value.toString());
4601
+ if (isNaN(valueAsFloat))
4602
+ return;
4603
+ if (this.format === 'currency') {
4604
+ return Intl.NumberFormat('en-US', {
4605
+ style: 'currency',
4606
+ currency: 'USD',
4607
+ }).format(valueAsFloat);
4608
+ }
4609
+ else {
4610
+ return Intl.NumberFormat('en-US').format(valueAsFloat);
4611
+ }
4612
+ }
4613
+ getCSSProperty(name) {
4614
+ let fallback;
4615
+ if (name.startsWith('var(') && name.endsWith(')')) {
4616
+ const regExp = /var\((.*)\)/g;
4617
+ const result = regExp.exec(name);
4618
+ const split = result.length >= 2 ? result[1].split(',') : [];
4619
+ name = split[0];
4620
+ fallback = split[1];
4621
+ }
4622
+ let result = this.chartContainerStyles.getPropertyValue(name).trim();
4623
+ if (!result)
4624
+ result = this.hostElementStyles.getPropertyValue(name).trim();
4625
+ return result || fallback;
4626
+ }
4627
+ getIndexById(id) {
4628
+ return this.data.findIndex(item => item.id === id);
4629
+ }
4630
+ getDataByIndex(index) {
4631
+ if (typeof index !== 'number')
4632
+ return;
4633
+ return this.data[index];
4634
+ }
4635
+ getDataById(id) {
4636
+ if (!id)
4637
+ return;
4638
+ return this.data.find(item => item.id === id);
4639
+ }
4640
+ getColors() {
4641
+ const defaultColors = [
4642
+ '--comp-color-1',
4643
+ '--comp-color-2',
4644
+ '--comp-color-3',
4645
+ '--comp-color-4',
4646
+ '--comp-color-5',
4647
+ '--comp-color-6',
4648
+ '--comp-color-7',
4649
+ '--comp-color-8',
4650
+ '--comp-color-9',
4651
+ '--comp-color-10',
4652
+ '--comp-color-11',
4653
+ '--comp-color-12',
4654
+ ];
4655
+ return this.data.reduce((acc, cur) => {
4656
+ let color = defaultColors.shift();
4657
+ if (cur.color)
4658
+ color = cur.color;
4659
+ acc.push(this.getCSSProperty(color) || color);
4660
+ return acc;
4661
+ }, []);
4662
+ }
4663
+ setupChartEvents(chart) {
4664
+ chart.on('mouseover', (params) => {
4665
+ this.hoveredId = params.data.id;
4666
+ });
4667
+ chart.on('click', params => {
4668
+ // Don't emit click event when clicking a chart slice
4669
+ params.event.event.stopPropagation();
4670
+ });
4671
+ chart.on('mouseout', () => {
4672
+ this.hoveredId = null;
4673
+ });
4674
+ chart.on('selectchanged', (params) => {
4675
+ var _a, _b, _c, _d;
4676
+ const selectedIndex = (_d = (_c = (_b = (_a = params.selected) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.dataIndex) === null || _c === void 0 ? void 0 : _c[0]) !== null && _d !== void 0 ? _d : null;
4677
+ const data = typeof selectedIndex === 'number' ? this.getDataByIndex(selectedIndex) : Object.assign({}, this.defaultRecord);
4678
+ this.selectedId = data.id;
4679
+ this.isInChangeEvent = true;
4680
+ this.change.emit(data);
4681
+ setTimeout(() => {
4682
+ this.isInChangeEvent = false;
4683
+ }, 0);
4684
+ });
4685
+ }
4686
+ cleanData(data) {
4687
+ const { minSliceSize } = this;
4688
+ const minSize = parseFloat(minSliceSize || '2.5%') / 100;
4689
+ const total = data.reduce((acc, cur) => acc + cur.value, 0);
4690
+ const minValue = total * minSize;
4691
+ const newData = data.map(item => {
4692
+ if (item.value < minValue)
4693
+ return Object.assign(Object.assign({}, item), { value: minValue });
4694
+ return item;
4695
+ });
4696
+ return newData;
4697
+ }
4698
+ updateChart(chart) {
4699
+ return chart.setOption({
4700
+ tooltip: {
4701
+ show: false,
4702
+ },
4703
+ legend: {
4704
+ show: false,
4705
+ },
4706
+ aria: {
4707
+ enabled: true,
4708
+ },
4709
+ series: [
4710
+ {
4711
+ name: this.chartName,
4712
+ animationType: 'scale',
4713
+ color: this.colors,
4714
+ id: 'pie',
4715
+ type: 'pie',
4716
+ selectedOffset: this.selectedOffset,
4717
+ selectedMode: 'single',
4718
+ radius: [this.innerRadius, this.outerRadius],
4719
+ label: {
4720
+ show: false,
4721
+ },
4722
+ labelLine: {
4723
+ show: false,
4724
+ },
4725
+ itemStyle: {
4726
+ borderWidth: 5,
4727
+ borderColor: this.getCSSProperty('--comp-background-color'),
4728
+ },
4729
+ emphasis: {
4730
+ scaleSize: this.hoverScaleSize,
4731
+ itemStyle: {
4732
+ color: 'inherit',
4733
+ },
4734
+ },
4735
+ data: this.cleanData(this.data),
4736
+ },
4737
+ ],
4738
+ });
4739
+ }
4740
+ resizeChart() {
4741
+ this.chart.resize();
4742
+ }
4743
+ /// Watchers ///
4744
+ propsUpdates() {
4745
+ this.updateChart(this.chart);
4746
+ }
4747
+ dataUpdated() {
4748
+ this.colors = this.getColors();
4749
+ }
4750
+ innerRadiusUpdated() {
4751
+ const { innerRadius, outerRadius } = this;
4752
+ const innerRadiusInt = parseFloat(innerRadius);
4753
+ const outerRadiusInt = parseFloat(outerRadius);
4754
+ if (innerRadiusInt >= outerRadiusInt) {
4755
+ this.innerRadius = `${outerRadiusInt - 15}%`;
4756
+ }
4757
+ }
4758
+ outerRadiusUpdated() {
4759
+ const { innerRadius, outerRadius } = this;
4760
+ const innerRadiusInt = parseFloat(innerRadius);
4761
+ const outerRadiusInt = parseFloat(outerRadius);
4762
+ if (outerRadiusInt <= innerRadiusInt) {
4763
+ this.outerRadius = `${innerRadiusInt + 15}%`;
4764
+ }
4765
+ }
4766
+ /// Listeners ///
4767
+ delegateFocus(event) {
4768
+ var _a;
4769
+ if (!isEventFromElement(event, this.hostElement))
4770
+ return;
4771
+ if (!this.isClickable)
4772
+ return;
4773
+ (_a = this.centerButtonElement) === null || _a === void 0 ? void 0 : _a.focus();
4774
+ }
4775
+ /// Methods ///
4776
+ async selectById(id) {
4777
+ const dataIndex = this.getIndexById(id);
4778
+ if (dataIndex === -1)
4779
+ return;
4780
+ this.chart.dispatchAction({
4781
+ type: 'select',
4782
+ seriesId: 'pie',
4783
+ dataIndex,
4784
+ });
4785
+ }
4786
+ async selectByIndex(index) {
4787
+ const dataIndex = this.data[index] ? index : null;
4788
+ if (!dataIndex)
4789
+ return;
4790
+ this.chart.dispatchAction({
4791
+ type: 'select',
4792
+ seriesId: 'pie',
4793
+ dataIndex,
4794
+ });
4795
+ }
4796
+ async clearSelection() {
4797
+ const { selectedId } = this;
4798
+ if (!selectedId)
4799
+ return;
4800
+ this.chart.dispatchAction({
4801
+ type: 'unselect',
4802
+ seriesId: 'pie',
4803
+ dataIndex: this.getIndexById(selectedId),
4804
+ });
4805
+ }
4806
+ /// DOM ///
4807
+ renderCenterBlock() {
4808
+ const { icon, name, value, color } = this.centerData;
4809
+ const { isClickable } = this;
4810
+ const TagName = isClickable ? 'button' : 'div';
4811
+ const displayValue = this.displayValue(value);
4812
+ const props = isClickable
4813
+ ? {
4814
+ onKeyUp: this.onButtonKeyUp,
4815
+ onClick: this.onButtonClick,
4816
+ ref: el => (this.centerButtonElement = el),
4817
+ 'aria-description': loc('tecton.element.chartDonut.button.description'),
4818
+ 'aria-roledescription': loc('tecton.element.chartDonut.button.roleDescription'),
4819
+ }
4820
+ : null;
4821
+ return (h("div", { class: "center-card-container", style: { width: `calc(${this.innerRadius} - 10%)` } }, h(TagName, Object.assign({ class: "center-card", "test-id": "centerCard" }, props), icon && (h("q2-icon", { type: icon, style: color && {
4822
+ '--tct-icon-stroke-primary': color,
4823
+ '--tct-icon-stroke-secondary': color,
4824
+ color,
4825
+ } })), name && h("div", { class: "name" }, name), value && h("div", { class: "value" }, displayValue))));
4826
+ }
4827
+ render() {
4828
+ return (h("click-elsewhere", { onChange: this.onClickElsewhere }, h("div", { class: "container" }, h("div", { ref: el => (this.chartContainer = el), class: "chart-container", "test-id": "chartContainer", onClick: this.onContainerClick }), this.renderCenterBlock())));
4829
+ }
4830
+ get hostElement() { return this; }
4831
+ static get watchers() { return {
4832
+ "chartName": ["propsUpdates"],
4833
+ "innerRadius": ["propsUpdates", "innerRadiusUpdated"],
4834
+ "outerRadius": ["propsUpdates", "outerRadiusUpdated"],
4835
+ "minSliceSize": ["propsUpdates"],
4836
+ "hoverScaleSize": ["propsUpdates"],
4837
+ "selectedOffset": ["propsUpdates"],
4838
+ "data": ["propsUpdates", "dataUpdated"]
4839
+ }; }
4840
+ static get style() { return stylesCss; }
4841
+ }, [1, "q2-chart-donut", {
4842
+ "chartName": [513, "chart-name"],
4843
+ "summaryIcon": [513, "summary-icon"],
4844
+ "summaryName": [513, "summary-name"],
4845
+ "innerRadius": [1025, "inner-radius"],
4846
+ "outerRadius": [1025, "outer-radius"],
4847
+ "minSliceSize": [1, "min-slice-size"],
4848
+ "selectedOffset": [2, "selected-offset"],
4849
+ "hoverScaleSize": [2, "hover-scale-size"],
4850
+ "format": [513],
4851
+ "isClickable": [516, "is-clickable"],
4852
+ "data": [16],
4853
+ "selectedId": [32],
4854
+ "hoveredId": [32],
4855
+ "selectById": [64],
4856
+ "selectByIndex": [64],
4857
+ "clearSelection": [64]
4858
+ }, [[0, "focus", "delegateFocus"]]]);
4859
+ function defineCustomElement$1() {
4860
+ if (typeof customElements === "undefined") {
4861
+ return;
4862
+ }
4863
+ const components = ["q2-chart-donut", "click-elsewhere", "q2-icon"];
4864
+ components.forEach(tagName => { switch (tagName) {
4865
+ case "q2-chart-donut":
4866
+ if (!customElements.get(tagName)) {
4867
+ customElements.define(tagName, Q2ChartDonut$1);
4868
+ }
4869
+ break;
4870
+ case "click-elsewhere":
4871
+ if (!customElements.get(tagName)) {
4872
+ defineCustomElement$3();
4873
+ }
4874
+ break;
4875
+ case "q2-icon":
4876
+ if (!customElements.get(tagName)) {
4877
+ defineCustomElement$2();
4878
+ }
4879
+ break;
4880
+ } });
4881
+ }
4882
+ defineCustomElement$1();
4883
+
4884
+ const Q2ChartDonut = Q2ChartDonut$1;
4885
+ const defineCustomElement = defineCustomElement$1;
4886
+
4887
+ export { Q2ChartDonut, defineCustomElement };