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,4710 @@
1
+ import { proxyCustomElement, HTMLElement, h } from '@stencil/core/internal/client';
2
+ import { o as overrideFocus, l as loc } from './index13.js';
3
+ import { S as SINGLE_REFERRING, e as each, c as createHashMap, a as createSourceFromSeriesDataOption, i as isFunction, b as curry, m as makeSeriesEncodeForAxisCoordSys, p as prepareSeriesDataSchema, d as enableDataStack, f as SeriesData, C as CoordinateSystemManager, g as map, h as SOURCE_FORMAT_ORIGINAL, j as isArray, k as getDataItemValue, l as getDimensionTypeByAxis, n as makeInner, o as getOptionCategoryInterval, q as makeLabelFormatter, r as getBoundingRect, s as shouldShowAllLabels, t as getPixelPrecision, u as linearMap, v as round, _ as __extends, w as ComponentModel, x as mixin, y as merge, z as defaults, A as getLayoutParams, B as mergeLayoutParam, O as OrdinalMeta, D as fetchLayoutMode, E as filter, F as invert, G as BoundingRect, H as applyTransform, I as getScaleExtent, J as increaseInterval, K as IntervalScale, L as getLayoutRect, M as estimateLabelUnionRect, N as isObject, P as indexOf, Q as createScaleByModel, R as isCartesian2DSeries, T as findAxisModels, U as getDataDimensionsOnAxis, V as ifAxisCrossZero, W as keys, X as isIntervalOrLogScale, Y as niceScaleExtent, Z as Rect, $ as Group, a0 as layout, a1 as AxisBuilder, a2 as extend, a3 as groupTransition, a4 as AxisView, a5 as Line, a6 as subPixelOptimizeLine, a7 as ComponentView, a8 as use, a9 as install$4, aa as retrieve2, ab as ZRText, ac as createTextStyle, ad as windowOpen, ae as getECData, af as retrieveRawValue, ag as initProps, ah as Sector, ai as isString, aj as SeriesModel, ak as inheritDefaultOption, al as Path, am as calculateTextPosition, an as isNumber, ao as traverseElements, ap as updateProps, aq as saveOldStyle, ar as labelInner, as as removeElementWithFadeOut, at as ChartView, au as getLabelStatesModels, av as setLabelStyle, aw as setLabelValueAnimation, ax as toggleHoverEmphasis, ay as setStatesStylesFromModel, az as throttle, aA as createProgressiveLayout, aB as layout$1, aC as install$5, aD as install$6, aE as installLabelLayout, aF as init } from './installCanvasRenderer.js';
4
+
5
+ /**
6
+ * @class
7
+ * For example:
8
+ * {
9
+ * coordSysName: 'cartesian2d',
10
+ * coordSysDims: ['x', 'y', ...],
11
+ * axisMap: HashMap({
12
+ * x: xAxisModel,
13
+ * y: yAxisModel
14
+ * }),
15
+ * categoryAxisMap: HashMap({
16
+ * x: xAxisModel,
17
+ * y: undefined
18
+ * }),
19
+ * // The index of the first category axis in `coordSysDims`.
20
+ * // `null/undefined` means no category axis exists.
21
+ * firstCategoryDimIndex: 1,
22
+ * // To replace user specified encode.
23
+ * }
24
+ */
25
+
26
+ var CoordSysInfo =
27
+ /** @class */
28
+ function () {
29
+ function CoordSysInfo(coordSysName) {
30
+ this.coordSysDims = [];
31
+ this.axisMap = createHashMap();
32
+ this.categoryAxisMap = createHashMap();
33
+ this.coordSysName = coordSysName;
34
+ }
35
+
36
+ return CoordSysInfo;
37
+ }();
38
+
39
+ function getCoordSysInfoBySeries(seriesModel) {
40
+ var coordSysName = seriesModel.get('coordinateSystem');
41
+ var result = new CoordSysInfo(coordSysName);
42
+ var fetch = fetchers[coordSysName];
43
+
44
+ if (fetch) {
45
+ fetch(seriesModel, result, result.axisMap, result.categoryAxisMap);
46
+ return result;
47
+ }
48
+ }
49
+ var fetchers = {
50
+ cartesian2d: function (seriesModel, result, axisMap, categoryAxisMap) {
51
+ var xAxisModel = seriesModel.getReferringComponents('xAxis', SINGLE_REFERRING).models[0];
52
+ var yAxisModel = seriesModel.getReferringComponents('yAxis', SINGLE_REFERRING).models[0];
53
+
54
+ result.coordSysDims = ['x', 'y'];
55
+ axisMap.set('x', xAxisModel);
56
+ axisMap.set('y', yAxisModel);
57
+
58
+ if (isCategory(xAxisModel)) {
59
+ categoryAxisMap.set('x', xAxisModel);
60
+ result.firstCategoryDimIndex = 0;
61
+ }
62
+
63
+ if (isCategory(yAxisModel)) {
64
+ categoryAxisMap.set('y', yAxisModel);
65
+ result.firstCategoryDimIndex == null && (result.firstCategoryDimIndex = 1);
66
+ }
67
+ },
68
+ singleAxis: function (seriesModel, result, axisMap, categoryAxisMap) {
69
+ var singleAxisModel = seriesModel.getReferringComponents('singleAxis', SINGLE_REFERRING).models[0];
70
+
71
+ result.coordSysDims = ['single'];
72
+ axisMap.set('single', singleAxisModel);
73
+
74
+ if (isCategory(singleAxisModel)) {
75
+ categoryAxisMap.set('single', singleAxisModel);
76
+ result.firstCategoryDimIndex = 0;
77
+ }
78
+ },
79
+ polar: function (seriesModel, result, axisMap, categoryAxisMap) {
80
+ var polarModel = seriesModel.getReferringComponents('polar', SINGLE_REFERRING).models[0];
81
+ var radiusAxisModel = polarModel.findAxisModel('radiusAxis');
82
+ var angleAxisModel = polarModel.findAxisModel('angleAxis');
83
+
84
+ result.coordSysDims = ['radius', 'angle'];
85
+ axisMap.set('radius', radiusAxisModel);
86
+ axisMap.set('angle', angleAxisModel);
87
+
88
+ if (isCategory(radiusAxisModel)) {
89
+ categoryAxisMap.set('radius', radiusAxisModel);
90
+ result.firstCategoryDimIndex = 0;
91
+ }
92
+
93
+ if (isCategory(angleAxisModel)) {
94
+ categoryAxisMap.set('angle', angleAxisModel);
95
+ result.firstCategoryDimIndex == null && (result.firstCategoryDimIndex = 1);
96
+ }
97
+ },
98
+ geo: function (seriesModel, result, axisMap, categoryAxisMap) {
99
+ result.coordSysDims = ['lng', 'lat'];
100
+ },
101
+ parallel: function (seriesModel, result, axisMap, categoryAxisMap) {
102
+ var ecModel = seriesModel.ecModel;
103
+ var parallelModel = ecModel.getComponent('parallel', seriesModel.get('parallelIndex'));
104
+ var coordSysDims = result.coordSysDims = parallelModel.dimensions.slice();
105
+ each(parallelModel.parallelAxisIndex, function (axisIndex, index) {
106
+ var axisModel = ecModel.getComponent('parallelAxis', axisIndex);
107
+ var axisDim = coordSysDims[index];
108
+ axisMap.set(axisDim, axisModel);
109
+
110
+ if (isCategory(axisModel)) {
111
+ categoryAxisMap.set(axisDim, axisModel);
112
+
113
+ if (result.firstCategoryDimIndex == null) {
114
+ result.firstCategoryDimIndex = index;
115
+ }
116
+ }
117
+ });
118
+ }
119
+ };
120
+
121
+ function isCategory(axisModel) {
122
+ return axisModel.get('type') === 'category';
123
+ }
124
+
125
+ function getCoordSysDimDefs(seriesModel, coordSysInfo) {
126
+ var coordSysName = seriesModel.get('coordinateSystem');
127
+ var registeredCoordSys = CoordinateSystemManager.get(coordSysName);
128
+ var coordSysDimDefs;
129
+
130
+ if (coordSysInfo && coordSysInfo.coordSysDims) {
131
+ coordSysDimDefs = map(coordSysInfo.coordSysDims, function (dim) {
132
+ var dimInfo = {
133
+ name: dim
134
+ };
135
+ var axisModel = coordSysInfo.axisMap.get(dim);
136
+
137
+ if (axisModel) {
138
+ var axisType = axisModel.get('type');
139
+ dimInfo.type = getDimensionTypeByAxis(axisType);
140
+ }
141
+
142
+ return dimInfo;
143
+ });
144
+ }
145
+
146
+ if (!coordSysDimDefs) {
147
+ // Get dimensions from registered coordinate system
148
+ coordSysDimDefs = registeredCoordSys && (registeredCoordSys.getDimensionsInfo ? registeredCoordSys.getDimensionsInfo() : registeredCoordSys.dimensions.slice()) || ['x', 'y'];
149
+ }
150
+
151
+ return coordSysDimDefs;
152
+ }
153
+
154
+ function injectOrdinalMeta(dimInfoList, createInvertedIndices, coordSysInfo) {
155
+ var firstCategoryDimIndex;
156
+ var hasNameEncode;
157
+ coordSysInfo && each(dimInfoList, function (dimInfo, dimIndex) {
158
+ var coordDim = dimInfo.coordDim;
159
+ var categoryAxisModel = coordSysInfo.categoryAxisMap.get(coordDim);
160
+
161
+ if (categoryAxisModel) {
162
+ if (firstCategoryDimIndex == null) {
163
+ firstCategoryDimIndex = dimIndex;
164
+ }
165
+
166
+ dimInfo.ordinalMeta = categoryAxisModel.getOrdinalMeta();
167
+
168
+ if (createInvertedIndices) {
169
+ dimInfo.createInvertedIndices = true;
170
+ }
171
+ }
172
+
173
+ if (dimInfo.otherDims.itemName != null) {
174
+ hasNameEncode = true;
175
+ }
176
+ });
177
+
178
+ if (!hasNameEncode && firstCategoryDimIndex != null) {
179
+ dimInfoList[firstCategoryDimIndex].otherDims.itemName = 0;
180
+ }
181
+
182
+ return firstCategoryDimIndex;
183
+ }
184
+ /**
185
+ * Caution: there are side effects to `sourceManager` in this method.
186
+ * Should better only be called in `Series['getInitialData']`.
187
+ */
188
+
189
+
190
+ function createSeriesData(sourceRaw, seriesModel, opt) {
191
+ opt = opt || {};
192
+ var sourceManager = seriesModel.getSourceManager();
193
+ var source;
194
+ var isOriginalSource = false;
195
+
196
+ if (sourceRaw) {
197
+ isOriginalSource = true;
198
+ source = createSourceFromSeriesDataOption(sourceRaw);
199
+ } else {
200
+ source = sourceManager.getSource(); // Is series.data. not dataset.
201
+
202
+ isOriginalSource = source.sourceFormat === SOURCE_FORMAT_ORIGINAL;
203
+ }
204
+
205
+ var coordSysInfo = getCoordSysInfoBySeries(seriesModel);
206
+ var coordSysDimDefs = getCoordSysDimDefs(seriesModel, coordSysInfo);
207
+ var useEncodeDefaulter = opt.useEncodeDefaulter;
208
+ var encodeDefaulter = isFunction(useEncodeDefaulter) ? useEncodeDefaulter : useEncodeDefaulter ? curry(makeSeriesEncodeForAxisCoordSys, coordSysDimDefs, seriesModel) : null;
209
+ var createDimensionOptions = {
210
+ coordDimensions: coordSysDimDefs,
211
+ generateCoord: opt.generateCoord,
212
+ encodeDefine: seriesModel.getEncode(),
213
+ encodeDefaulter: encodeDefaulter,
214
+ canOmitUnusedDimensions: !isOriginalSource
215
+ };
216
+ var schema = prepareSeriesDataSchema(source, createDimensionOptions);
217
+ var firstCategoryDimIndex = injectOrdinalMeta(schema.dimensions, opt.createInvertedIndices, coordSysInfo);
218
+ var store = !isOriginalSource ? sourceManager.getSharedDataStore(schema) : null;
219
+ var stackCalculationInfo = enableDataStack(seriesModel, {
220
+ schema: schema,
221
+ store: store
222
+ });
223
+ var data = new SeriesData(schema, seriesModel);
224
+ data.setCalculationInfo(stackCalculationInfo);
225
+ var dimValueGetter = firstCategoryDimIndex != null && isNeedCompleteOrdinalData(source) ? function (itemOpt, dimName, dataIndex, dimIndex) {
226
+ // Use dataIndex as ordinal value in categoryAxis
227
+ return dimIndex === firstCategoryDimIndex ? dataIndex : this.defaultDimValueGetter(itemOpt, dimName, dataIndex, dimIndex);
228
+ } : null;
229
+ data.hasItemOption = false;
230
+ data.initData( // Try to reuse the data store in sourceManager if using dataset.
231
+ isOriginalSource ? source : store, null, dimValueGetter);
232
+ return data;
233
+ }
234
+
235
+ function isNeedCompleteOrdinalData(source) {
236
+ if (source.sourceFormat === SOURCE_FORMAT_ORIGINAL) {
237
+ var sampleItem = firstDataNotNull(source.data || []);
238
+ return !isArray(getDataItemValue(sampleItem));
239
+ }
240
+ }
241
+
242
+ function firstDataNotNull(arr) {
243
+ var i = 0;
244
+
245
+ while (i < arr.length && arr[i] == null) {
246
+ i++;
247
+ }
248
+
249
+ return arr[i];
250
+ }
251
+
252
+ /*
253
+ * Licensed to the Apache Software Foundation (ASF) under one
254
+ * or more contributor license agreements. See the NOTICE file
255
+ * distributed with this work for additional information
256
+ * regarding copyright ownership. The ASF licenses this file
257
+ * to you under the Apache License, Version 2.0 (the
258
+ * "License"); you may not use this file except in compliance
259
+ * with the License. You may obtain a copy of the License at
260
+ *
261
+ * http://www.apache.org/licenses/LICENSE-2.0
262
+ *
263
+ * Unless required by applicable law or agreed to in writing,
264
+ * software distributed under the License is distributed on an
265
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
266
+ * KIND, either express or implied. See the License for the
267
+ * specific language governing permissions and limitations
268
+ * under the License.
269
+ */
270
+
271
+
272
+ /**
273
+ * AUTO-GENERATED FILE. DO NOT MODIFY.
274
+ */
275
+
276
+ /*
277
+ * Licensed to the Apache Software Foundation (ASF) under one
278
+ * or more contributor license agreements. See the NOTICE file
279
+ * distributed with this work for additional information
280
+ * regarding copyright ownership. The ASF licenses this file
281
+ * to you under the Apache License, Version 2.0 (the
282
+ * "License"); you may not use this file except in compliance
283
+ * with the License. You may obtain a copy of the License at
284
+ *
285
+ * http://www.apache.org/licenses/LICENSE-2.0
286
+ *
287
+ * Unless required by applicable law or agreed to in writing,
288
+ * software distributed under the License is distributed on an
289
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
290
+ * KIND, either express or implied. See the License for the
291
+ * specific language governing permissions and limitations
292
+ * under the License.
293
+ */
294
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
295
+ var AxisModelCommonMixin =
296
+ /** @class */
297
+ function () {
298
+ function AxisModelCommonMixin() {}
299
+
300
+ AxisModelCommonMixin.prototype.getNeedCrossZero = function () {
301
+ var option = this.option;
302
+ return !option.scale;
303
+ };
304
+ /**
305
+ * Should be implemented by each axis model if necessary.
306
+ * @return coordinate system model
307
+ */
308
+
309
+
310
+ AxisModelCommonMixin.prototype.getCoordSysModel = function () {
311
+ return;
312
+ };
313
+
314
+ return AxisModelCommonMixin;
315
+ }();
316
+
317
+ var inner$1 = makeInner();
318
+ function createAxisLabels(axis) {
319
+ // Only ordinal scale support tick interval
320
+ return axis.type === 'category' ? makeCategoryLabels(axis) : makeRealNumberLabels(axis);
321
+ }
322
+ /**
323
+ * @param {module:echats/coord/Axis} axis
324
+ * @param {module:echarts/model/Model} tickModel For example, can be axisTick, splitLine, splitArea.
325
+ * @return {Object} {
326
+ * ticks: Array.<number>
327
+ * tickCategoryInterval: number
328
+ * }
329
+ */
330
+
331
+ function createAxisTicks(axis, tickModel) {
332
+ // Only ordinal scale support tick interval
333
+ return axis.type === 'category' ? makeCategoryTicks(axis, tickModel) : {
334
+ ticks: map(axis.scale.getTicks(), function (tick) {
335
+ return tick.value;
336
+ })
337
+ };
338
+ }
339
+
340
+ function makeCategoryLabels(axis) {
341
+ var labelModel = axis.getLabelModel();
342
+ var result = makeCategoryLabelsActually(axis, labelModel);
343
+ return !labelModel.get('show') || axis.scale.isBlank() ? {
344
+ labels: [],
345
+ labelCategoryInterval: result.labelCategoryInterval
346
+ } : result;
347
+ }
348
+
349
+ function makeCategoryLabelsActually(axis, labelModel) {
350
+ var labelsCache = getListCache(axis, 'labels');
351
+ var optionLabelInterval = getOptionCategoryInterval(labelModel);
352
+ var result = listCacheGet(labelsCache, optionLabelInterval);
353
+
354
+ if (result) {
355
+ return result;
356
+ }
357
+
358
+ var labels;
359
+ var numericLabelInterval;
360
+
361
+ if (isFunction(optionLabelInterval)) {
362
+ labels = makeLabelsByCustomizedCategoryInterval(axis, optionLabelInterval);
363
+ } else {
364
+ numericLabelInterval = optionLabelInterval === 'auto' ? makeAutoCategoryInterval(axis) : optionLabelInterval;
365
+ labels = makeLabelsByNumericCategoryInterval(axis, numericLabelInterval);
366
+ } // Cache to avoid calling interval function repeatedly.
367
+
368
+
369
+ return listCacheSet(labelsCache, optionLabelInterval, {
370
+ labels: labels,
371
+ labelCategoryInterval: numericLabelInterval
372
+ });
373
+ }
374
+
375
+ function makeCategoryTicks(axis, tickModel) {
376
+ var ticksCache = getListCache(axis, 'ticks');
377
+ var optionTickInterval = getOptionCategoryInterval(tickModel);
378
+ var result = listCacheGet(ticksCache, optionTickInterval);
379
+
380
+ if (result) {
381
+ return result;
382
+ }
383
+
384
+ var ticks;
385
+ var tickCategoryInterval; // Optimize for the case that large category data and no label displayed,
386
+ // we should not return all ticks.
387
+
388
+ if (!tickModel.get('show') || axis.scale.isBlank()) {
389
+ ticks = [];
390
+ }
391
+
392
+ if (isFunction(optionTickInterval)) {
393
+ ticks = makeLabelsByCustomizedCategoryInterval(axis, optionTickInterval, true);
394
+ } // Always use label interval by default despite label show. Consider this
395
+ // scenario, Use multiple grid with the xAxis sync, and only one xAxis shows
396
+ // labels. `splitLine` and `axisTick` should be consistent in this case.
397
+ else if (optionTickInterval === 'auto') {
398
+ var labelsResult = makeCategoryLabelsActually(axis, axis.getLabelModel());
399
+ tickCategoryInterval = labelsResult.labelCategoryInterval;
400
+ ticks = map(labelsResult.labels, function (labelItem) {
401
+ return labelItem.tickValue;
402
+ });
403
+ } else {
404
+ tickCategoryInterval = optionTickInterval;
405
+ ticks = makeLabelsByNumericCategoryInterval(axis, tickCategoryInterval, true);
406
+ } // Cache to avoid calling interval function repeatedly.
407
+
408
+
409
+ return listCacheSet(ticksCache, optionTickInterval, {
410
+ ticks: ticks,
411
+ tickCategoryInterval: tickCategoryInterval
412
+ });
413
+ }
414
+
415
+ function makeRealNumberLabels(axis) {
416
+ var ticks = axis.scale.getTicks();
417
+ var labelFormatter = makeLabelFormatter(axis);
418
+ return {
419
+ labels: map(ticks, function (tick, idx) {
420
+ return {
421
+ level: tick.level,
422
+ formattedLabel: labelFormatter(tick, idx),
423
+ rawLabel: axis.scale.getLabel(tick),
424
+ tickValue: tick.value
425
+ };
426
+ })
427
+ };
428
+ }
429
+
430
+ function getListCache(axis, prop) {
431
+ // Because key can be a function, and cache size always is small, we use array cache.
432
+ return inner$1(axis)[prop] || (inner$1(axis)[prop] = []);
433
+ }
434
+
435
+ function listCacheGet(cache, key) {
436
+ for (var i = 0; i < cache.length; i++) {
437
+ if (cache[i].key === key) {
438
+ return cache[i].value;
439
+ }
440
+ }
441
+ }
442
+
443
+ function listCacheSet(cache, key, value) {
444
+ cache.push({
445
+ key: key,
446
+ value: value
447
+ });
448
+ return value;
449
+ }
450
+
451
+ function makeAutoCategoryInterval(axis) {
452
+ var result = inner$1(axis).autoInterval;
453
+ return result != null ? result : inner$1(axis).autoInterval = axis.calculateCategoryInterval();
454
+ }
455
+ /**
456
+ * Calculate interval for category axis ticks and labels.
457
+ * To get precise result, at least one of `getRotate` and `isHorizontal`
458
+ * should be implemented in axis.
459
+ */
460
+
461
+
462
+ function calculateCategoryInterval(axis) {
463
+ var params = fetchAutoCategoryIntervalCalculationParams(axis);
464
+ var labelFormatter = makeLabelFormatter(axis);
465
+ var rotation = (params.axisRotate - params.labelRotate) / 180 * Math.PI;
466
+ var ordinalScale = axis.scale;
467
+ var ordinalExtent = ordinalScale.getExtent(); // Providing this method is for optimization:
468
+ // avoid generating a long array by `getTicks`
469
+ // in large category data case.
470
+
471
+ var tickCount = ordinalScale.count();
472
+
473
+ if (ordinalExtent[1] - ordinalExtent[0] < 1) {
474
+ return 0;
475
+ }
476
+
477
+ var step = 1; // Simple optimization. Empirical value: tick count should less than 40.
478
+
479
+ if (tickCount > 40) {
480
+ step = Math.max(1, Math.floor(tickCount / 40));
481
+ }
482
+
483
+ var tickValue = ordinalExtent[0];
484
+ var unitSpan = axis.dataToCoord(tickValue + 1) - axis.dataToCoord(tickValue);
485
+ var unitW = Math.abs(unitSpan * Math.cos(rotation));
486
+ var unitH = Math.abs(unitSpan * Math.sin(rotation));
487
+ var maxW = 0;
488
+ var maxH = 0; // Caution: Performance sensitive for large category data.
489
+ // Consider dataZoom, we should make appropriate step to avoid O(n) loop.
490
+
491
+ for (; tickValue <= ordinalExtent[1]; tickValue += step) {
492
+ var width = 0;
493
+ var height = 0; // Not precise, do not consider align and vertical align
494
+ // and each distance from axis line yet.
495
+
496
+ var rect = getBoundingRect(labelFormatter({
497
+ value: tickValue
498
+ }), params.font, 'center', 'top'); // Magic number
499
+
500
+ width = rect.width * 1.3;
501
+ height = rect.height * 1.3; // Min size, void long loop.
502
+
503
+ maxW = Math.max(maxW, width, 7);
504
+ maxH = Math.max(maxH, height, 7);
505
+ }
506
+
507
+ var dw = maxW / unitW;
508
+ var dh = maxH / unitH; // 0/0 is NaN, 1/0 is Infinity.
509
+
510
+ isNaN(dw) && (dw = Infinity);
511
+ isNaN(dh) && (dh = Infinity);
512
+ var interval = Math.max(0, Math.floor(Math.min(dw, dh)));
513
+ var cache = inner$1(axis.model);
514
+ var axisExtent = axis.getExtent();
515
+ var lastAutoInterval = cache.lastAutoInterval;
516
+ var lastTickCount = cache.lastTickCount; // Use cache to keep interval stable while moving zoom window,
517
+ // otherwise the calculated interval might jitter when the zoom
518
+ // window size is close to the interval-changing size.
519
+ // For example, if all of the axis labels are `a, b, c, d, e, f, g`.
520
+ // The jitter will cause that sometimes the displayed labels are
521
+ // `a, d, g` (interval: 2) sometimes `a, c, e`(interval: 1).
522
+
523
+ if (lastAutoInterval != null && lastTickCount != null && Math.abs(lastAutoInterval - interval) <= 1 && Math.abs(lastTickCount - tickCount) <= 1 // Always choose the bigger one, otherwise the critical
524
+ // point is not the same when zooming in or zooming out.
525
+ && lastAutoInterval > interval // If the axis change is caused by chart resize, the cache should not
526
+ // be used. Otherwise some hidden labels might not be shown again.
527
+ && cache.axisExtent0 === axisExtent[0] && cache.axisExtent1 === axisExtent[1]) {
528
+ interval = lastAutoInterval;
529
+ } // Only update cache if cache not used, otherwise the
530
+ // changing of interval is too insensitive.
531
+ else {
532
+ cache.lastTickCount = tickCount;
533
+ cache.lastAutoInterval = interval;
534
+ cache.axisExtent0 = axisExtent[0];
535
+ cache.axisExtent1 = axisExtent[1];
536
+ }
537
+
538
+ return interval;
539
+ }
540
+
541
+ function fetchAutoCategoryIntervalCalculationParams(axis) {
542
+ var labelModel = axis.getLabelModel();
543
+ return {
544
+ axisRotate: axis.getRotate ? axis.getRotate() : axis.isHorizontal && !axis.isHorizontal() ? 90 : 0,
545
+ labelRotate: labelModel.get('rotate') || 0,
546
+ font: labelModel.getFont()
547
+ };
548
+ }
549
+
550
+ function makeLabelsByNumericCategoryInterval(axis, categoryInterval, onlyTick) {
551
+ var labelFormatter = makeLabelFormatter(axis);
552
+ var ordinalScale = axis.scale;
553
+ var ordinalExtent = ordinalScale.getExtent();
554
+ var labelModel = axis.getLabelModel();
555
+ var result = []; // TODO: axisType: ordinalTime, pick the tick from each month/day/year/...
556
+
557
+ var step = Math.max((categoryInterval || 0) + 1, 1);
558
+ var startTick = ordinalExtent[0];
559
+ var tickCount = ordinalScale.count(); // Calculate start tick based on zero if possible to keep label consistent
560
+ // while zooming and moving while interval > 0. Otherwise the selection
561
+ // of displayable ticks and symbols probably keep changing.
562
+ // 3 is empirical value.
563
+
564
+ if (startTick !== 0 && step > 1 && tickCount / step > 2) {
565
+ startTick = Math.round(Math.ceil(startTick / step) * step);
566
+ } // (1) Only add min max label here but leave overlap checking
567
+ // to render stage, which also ensure the returned list
568
+ // suitable for splitLine and splitArea rendering.
569
+ // (2) Scales except category always contain min max label so
570
+ // do not need to perform this process.
571
+
572
+
573
+ var showAllLabel = shouldShowAllLabels(axis);
574
+ var includeMinLabel = labelModel.get('showMinLabel') || showAllLabel;
575
+ var includeMaxLabel = labelModel.get('showMaxLabel') || showAllLabel;
576
+
577
+ if (includeMinLabel && startTick !== ordinalExtent[0]) {
578
+ addItem(ordinalExtent[0]);
579
+ } // Optimize: avoid generating large array by `ordinalScale.getTicks()`.
580
+
581
+
582
+ var tickValue = startTick;
583
+
584
+ for (; tickValue <= ordinalExtent[1]; tickValue += step) {
585
+ addItem(tickValue);
586
+ }
587
+
588
+ if (includeMaxLabel && tickValue - step !== ordinalExtent[1]) {
589
+ addItem(ordinalExtent[1]);
590
+ }
591
+
592
+ function addItem(tickValue) {
593
+ var tickObj = {
594
+ value: tickValue
595
+ };
596
+ result.push(onlyTick ? tickValue : {
597
+ formattedLabel: labelFormatter(tickObj),
598
+ rawLabel: ordinalScale.getLabel(tickObj),
599
+ tickValue: tickValue
600
+ });
601
+ }
602
+
603
+ return result;
604
+ }
605
+
606
+ function makeLabelsByCustomizedCategoryInterval(axis, categoryInterval, onlyTick) {
607
+ var ordinalScale = axis.scale;
608
+ var labelFormatter = makeLabelFormatter(axis);
609
+ var result = [];
610
+ each(ordinalScale.getTicks(), function (tick) {
611
+ var rawLabel = ordinalScale.getLabel(tick);
612
+ var tickValue = tick.value;
613
+
614
+ if (categoryInterval(tick.value, rawLabel)) {
615
+ result.push(onlyTick ? tickValue : {
616
+ formattedLabel: labelFormatter(tick),
617
+ rawLabel: rawLabel,
618
+ tickValue: tickValue
619
+ });
620
+ }
621
+ });
622
+ return result;
623
+ }
624
+
625
+ var NORMALIZED_EXTENT = [0, 1];
626
+ /**
627
+ * Base class of Axis.
628
+ */
629
+
630
+ var Axis =
631
+ /** @class */
632
+ function () {
633
+ function Axis(dim, scale, extent) {
634
+ this.onBand = false;
635
+ this.inverse = false;
636
+ this.dim = dim;
637
+ this.scale = scale;
638
+ this._extent = extent || [0, 0];
639
+ }
640
+ /**
641
+ * If axis extent contain given coord
642
+ */
643
+
644
+
645
+ Axis.prototype.contain = function (coord) {
646
+ var extent = this._extent;
647
+ var min = Math.min(extent[0], extent[1]);
648
+ var max = Math.max(extent[0], extent[1]);
649
+ return coord >= min && coord <= max;
650
+ };
651
+ /**
652
+ * If axis extent contain given data
653
+ */
654
+
655
+
656
+ Axis.prototype.containData = function (data) {
657
+ return this.scale.contain(data);
658
+ };
659
+ /**
660
+ * Get coord extent.
661
+ */
662
+
663
+
664
+ Axis.prototype.getExtent = function () {
665
+ return this._extent.slice();
666
+ };
667
+ /**
668
+ * Get precision used for formatting
669
+ */
670
+
671
+
672
+ Axis.prototype.getPixelPrecision = function (dataExtent) {
673
+ return getPixelPrecision(dataExtent || this.scale.getExtent(), this._extent);
674
+ };
675
+ /**
676
+ * Set coord extent
677
+ */
678
+
679
+
680
+ Axis.prototype.setExtent = function (start, end) {
681
+ var extent = this._extent;
682
+ extent[0] = start;
683
+ extent[1] = end;
684
+ };
685
+ /**
686
+ * Convert data to coord. Data is the rank if it has an ordinal scale
687
+ */
688
+
689
+
690
+ Axis.prototype.dataToCoord = function (data, clamp) {
691
+ var extent = this._extent;
692
+ var scale = this.scale;
693
+ data = scale.normalize(data);
694
+
695
+ if (this.onBand && scale.type === 'ordinal') {
696
+ extent = extent.slice();
697
+ fixExtentWithBands(extent, scale.count());
698
+ }
699
+
700
+ return linearMap(data, NORMALIZED_EXTENT, extent, clamp);
701
+ };
702
+ /**
703
+ * Convert coord to data. Data is the rank if it has an ordinal scale
704
+ */
705
+
706
+
707
+ Axis.prototype.coordToData = function (coord, clamp) {
708
+ var extent = this._extent;
709
+ var scale = this.scale;
710
+
711
+ if (this.onBand && scale.type === 'ordinal') {
712
+ extent = extent.slice();
713
+ fixExtentWithBands(extent, scale.count());
714
+ }
715
+
716
+ var t = linearMap(coord, extent, NORMALIZED_EXTENT, clamp);
717
+ return this.scale.scale(t);
718
+ };
719
+ /**
720
+ * Convert pixel point to data in axis
721
+ */
722
+
723
+
724
+ Axis.prototype.pointToData = function (point, clamp) {
725
+ // Should be implemented in derived class if necessary.
726
+ return;
727
+ };
728
+ /**
729
+ * Different from `zrUtil.map(axis.getTicks(), axis.dataToCoord, axis)`,
730
+ * `axis.getTicksCoords` considers `onBand`, which is used by
731
+ * `boundaryGap:true` of category axis and splitLine and splitArea.
732
+ * @param opt.tickModel default: axis.model.getModel('axisTick')
733
+ * @param opt.clamp If `true`, the first and the last
734
+ * tick must be at the axis end points. Otherwise, clip ticks
735
+ * that outside the axis extent.
736
+ */
737
+
738
+
739
+ Axis.prototype.getTicksCoords = function (opt) {
740
+ opt = opt || {};
741
+ var tickModel = opt.tickModel || this.getTickModel();
742
+ var result = createAxisTicks(this, tickModel);
743
+ var ticks = result.ticks;
744
+ var ticksCoords = map(ticks, function (tickVal) {
745
+ return {
746
+ coord: this.dataToCoord(this.scale.type === 'ordinal' ? this.scale.getRawOrdinalNumber(tickVal) : tickVal),
747
+ tickValue: tickVal
748
+ };
749
+ }, this);
750
+ var alignWithLabel = tickModel.get('alignWithLabel');
751
+ fixOnBandTicksCoords(this, ticksCoords, alignWithLabel, opt.clamp);
752
+ return ticksCoords;
753
+ };
754
+
755
+ Axis.prototype.getMinorTicksCoords = function () {
756
+ if (this.scale.type === 'ordinal') {
757
+ // Category axis doesn't support minor ticks
758
+ return [];
759
+ }
760
+
761
+ var minorTickModel = this.model.getModel('minorTick');
762
+ var splitNumber = minorTickModel.get('splitNumber'); // Protection.
763
+
764
+ if (!(splitNumber > 0 && splitNumber < 100)) {
765
+ splitNumber = 5;
766
+ }
767
+
768
+ var minorTicks = this.scale.getMinorTicks(splitNumber);
769
+ var minorTicksCoords = map(minorTicks, function (minorTicksGroup) {
770
+ return map(minorTicksGroup, function (minorTick) {
771
+ return {
772
+ coord: this.dataToCoord(minorTick),
773
+ tickValue: minorTick
774
+ };
775
+ }, this);
776
+ }, this);
777
+ return minorTicksCoords;
778
+ };
779
+
780
+ Axis.prototype.getViewLabels = function () {
781
+ return createAxisLabels(this).labels;
782
+ };
783
+
784
+ Axis.prototype.getLabelModel = function () {
785
+ return this.model.getModel('axisLabel');
786
+ };
787
+ /**
788
+ * Notice here we only get the default tick model. For splitLine
789
+ * or splitArea, we should pass the splitLineModel or splitAreaModel
790
+ * manually when calling `getTicksCoords`.
791
+ * In GL, this method may be overridden to:
792
+ * `axisModel.getModel('axisTick', grid3DModel.getModel('axisTick'));`
793
+ */
794
+
795
+
796
+ Axis.prototype.getTickModel = function () {
797
+ return this.model.getModel('axisTick');
798
+ };
799
+ /**
800
+ * Get width of band
801
+ */
802
+
803
+
804
+ Axis.prototype.getBandWidth = function () {
805
+ var axisExtent = this._extent;
806
+ var dataExtent = this.scale.getExtent();
807
+ var len = dataExtent[1] - dataExtent[0] + (this.onBand ? 1 : 0); // Fix #2728, avoid NaN when only one data.
808
+
809
+ len === 0 && (len = 1);
810
+ var size = Math.abs(axisExtent[1] - axisExtent[0]);
811
+ return Math.abs(size) / len;
812
+ };
813
+ /**
814
+ * Only be called in category axis.
815
+ * Can be overridden, consider other axes like in 3D.
816
+ * @return Auto interval for cateogry axis tick and label
817
+ */
818
+
819
+
820
+ Axis.prototype.calculateCategoryInterval = function () {
821
+ return calculateCategoryInterval(this);
822
+ };
823
+
824
+ return Axis;
825
+ }();
826
+
827
+ function fixExtentWithBands(extent, nTick) {
828
+ var size = extent[1] - extent[0];
829
+ var len = nTick;
830
+ var margin = size / len / 2;
831
+ extent[0] += margin;
832
+ extent[1] -= margin;
833
+ } // If axis has labels [1, 2, 3, 4]. Bands on the axis are
834
+ // |---1---|---2---|---3---|---4---|.
835
+ // So the displayed ticks and splitLine/splitArea should between
836
+ // each data item, otherwise cause misleading (e.g., split tow bars
837
+ // of a single data item when there are two bar series).
838
+ // Also consider if tickCategoryInterval > 0 and onBand, ticks and
839
+ // splitLine/spliteArea should layout appropriately corresponding
840
+ // to displayed labels. (So we should not use `getBandWidth` in this
841
+ // case).
842
+
843
+
844
+ function fixOnBandTicksCoords(axis, ticksCoords, alignWithLabel, clamp) {
845
+ var ticksLen = ticksCoords.length;
846
+
847
+ if (!axis.onBand || alignWithLabel || !ticksLen) {
848
+ return;
849
+ }
850
+
851
+ var axisExtent = axis.getExtent();
852
+ var last;
853
+ var diffSize;
854
+
855
+ if (ticksLen === 1) {
856
+ ticksCoords[0].coord = axisExtent[0];
857
+ last = ticksCoords[1] = {
858
+ coord: axisExtent[0]
859
+ };
860
+ } else {
861
+ var crossLen = ticksCoords[ticksLen - 1].tickValue - ticksCoords[0].tickValue;
862
+ var shift_1 = (ticksCoords[ticksLen - 1].coord - ticksCoords[0].coord) / crossLen;
863
+ each(ticksCoords, function (ticksItem) {
864
+ ticksItem.coord -= shift_1 / 2;
865
+ });
866
+ var dataExtent = axis.scale.getExtent();
867
+ diffSize = 1 + dataExtent[1] - ticksCoords[ticksLen - 1].tickValue;
868
+ last = {
869
+ coord: ticksCoords[ticksLen - 1].coord + shift_1 * diffSize
870
+ };
871
+ ticksCoords.push(last);
872
+ }
873
+
874
+ var inverse = axisExtent[0] > axisExtent[1]; // Handling clamp.
875
+
876
+ if (littleThan(ticksCoords[0].coord, axisExtent[0])) {
877
+ clamp ? ticksCoords[0].coord = axisExtent[0] : ticksCoords.shift();
878
+ }
879
+
880
+ if (clamp && littleThan(axisExtent[0], ticksCoords[0].coord)) {
881
+ ticksCoords.unshift({
882
+ coord: axisExtent[0]
883
+ });
884
+ }
885
+
886
+ if (littleThan(axisExtent[1], last.coord)) {
887
+ clamp ? last.coord = axisExtent[1] : ticksCoords.pop();
888
+ }
889
+
890
+ if (clamp && littleThan(last.coord, axisExtent[1])) {
891
+ ticksCoords.push({
892
+ coord: axisExtent[1]
893
+ });
894
+ }
895
+
896
+ function littleThan(a, b) {
897
+ // Avoid rounding error cause calculated tick coord different with extent.
898
+ // It may cause an extra unnecessary tick added.
899
+ a = round(a);
900
+ b = round(b);
901
+ return inverse ? a > b : a < b;
902
+ }
903
+ }
904
+
905
+ var GridModel =
906
+ /** @class */
907
+ function (_super) {
908
+ __extends(GridModel, _super);
909
+
910
+ function GridModel() {
911
+ return _super !== null && _super.apply(this, arguments) || this;
912
+ }
913
+
914
+ GridModel.type = 'grid';
915
+ GridModel.dependencies = ['xAxis', 'yAxis'];
916
+ GridModel.layoutMode = 'box';
917
+ GridModel.defaultOption = {
918
+ show: false,
919
+ // zlevel: 0,
920
+ z: 0,
921
+ left: '10%',
922
+ top: 60,
923
+ right: '10%',
924
+ bottom: 70,
925
+ // If grid size contain label
926
+ containLabel: false,
927
+ // width: {totalWidth} - left - right,
928
+ // height: {totalHeight} - top - bottom,
929
+ backgroundColor: 'rgba(0,0,0,0)',
930
+ borderWidth: 1,
931
+ borderColor: '#ccc'
932
+ };
933
+ return GridModel;
934
+ }(ComponentModel);
935
+
936
+ var CartesianAxisModel =
937
+ /** @class */
938
+ function (_super) {
939
+ __extends(CartesianAxisModel, _super);
940
+
941
+ function CartesianAxisModel() {
942
+ return _super !== null && _super.apply(this, arguments) || this;
943
+ }
944
+
945
+ CartesianAxisModel.prototype.getCoordSysModel = function () {
946
+ return this.getReferringComponents('grid', SINGLE_REFERRING).models[0];
947
+ };
948
+
949
+ CartesianAxisModel.type = 'cartesian2dAxis';
950
+ return CartesianAxisModel;
951
+ }(ComponentModel);
952
+ mixin(CartesianAxisModel, AxisModelCommonMixin);
953
+
954
+ var defaultOption = {
955
+ show: true,
956
+ // zlevel: 0,
957
+ z: 0,
958
+ // Inverse the axis.
959
+ inverse: false,
960
+ // Axis name displayed.
961
+ name: '',
962
+ // 'start' | 'middle' | 'end'
963
+ nameLocation: 'end',
964
+ // By degree. By default auto rotate by nameLocation.
965
+ nameRotate: null,
966
+ nameTruncate: {
967
+ maxWidth: null,
968
+ ellipsis: '...',
969
+ placeholder: '.'
970
+ },
971
+ // Use global text style by default.
972
+ nameTextStyle: {},
973
+ // The gap between axisName and axisLine.
974
+ nameGap: 15,
975
+ // Default `false` to support tooltip.
976
+ silent: false,
977
+ // Default `false` to avoid legacy user event listener fail.
978
+ triggerEvent: false,
979
+ tooltip: {
980
+ show: false
981
+ },
982
+ axisPointer: {},
983
+ axisLine: {
984
+ show: true,
985
+ onZero: true,
986
+ onZeroAxisIndex: null,
987
+ lineStyle: {
988
+ color: '#6E7079',
989
+ width: 1,
990
+ type: 'solid'
991
+ },
992
+ // The arrow at both ends the the axis.
993
+ symbol: ['none', 'none'],
994
+ symbolSize: [10, 15]
995
+ },
996
+ axisTick: {
997
+ show: true,
998
+ // Whether axisTick is inside the grid or outside the grid.
999
+ inside: false,
1000
+ // The length of axisTick.
1001
+ length: 5,
1002
+ lineStyle: {
1003
+ width: 1
1004
+ }
1005
+ },
1006
+ axisLabel: {
1007
+ show: true,
1008
+ // Whether axisLabel is inside the grid or outside the grid.
1009
+ inside: false,
1010
+ rotate: 0,
1011
+ // true | false | null/undefined (auto)
1012
+ showMinLabel: null,
1013
+ // true | false | null/undefined (auto)
1014
+ showMaxLabel: null,
1015
+ margin: 8,
1016
+ // formatter: null,
1017
+ fontSize: 12
1018
+ },
1019
+ splitLine: {
1020
+ show: true,
1021
+ lineStyle: {
1022
+ color: ['#E0E6F1'],
1023
+ width: 1,
1024
+ type: 'solid'
1025
+ }
1026
+ },
1027
+ splitArea: {
1028
+ show: false,
1029
+ areaStyle: {
1030
+ color: ['rgba(250,250,250,0.2)', 'rgba(210,219,238,0.2)']
1031
+ }
1032
+ }
1033
+ };
1034
+ var categoryAxis = merge({
1035
+ // The gap at both ends of the axis. For categoryAxis, boolean.
1036
+ boundaryGap: true,
1037
+ // Set false to faster category collection.
1038
+ deduplication: null,
1039
+ // splitArea: {
1040
+ // show: false
1041
+ // },
1042
+ splitLine: {
1043
+ show: false
1044
+ },
1045
+ axisTick: {
1046
+ // If tick is align with label when boundaryGap is true
1047
+ alignWithLabel: false,
1048
+ interval: 'auto'
1049
+ },
1050
+ axisLabel: {
1051
+ interval: 'auto'
1052
+ }
1053
+ }, defaultOption);
1054
+ var valueAxis = merge({
1055
+ boundaryGap: [0, 0],
1056
+ axisLine: {
1057
+ // Not shown when other axis is categoryAxis in cartesian
1058
+ show: 'auto'
1059
+ },
1060
+ axisTick: {
1061
+ // Not shown when other axis is categoryAxis in cartesian
1062
+ show: 'auto'
1063
+ },
1064
+ // TODO
1065
+ // min/max: [30, datamin, 60] or [20, datamin] or [datamin, 60]
1066
+ splitNumber: 5,
1067
+ minorTick: {
1068
+ // Minor tick, not available for cateogry axis.
1069
+ show: false,
1070
+ // Split number of minor ticks. The value should be in range of (0, 100)
1071
+ splitNumber: 5,
1072
+ // Length of minor tick
1073
+ length: 3,
1074
+ // Line style
1075
+ lineStyle: {// Default to be same with axisTick
1076
+ }
1077
+ },
1078
+ minorSplitLine: {
1079
+ show: false,
1080
+ lineStyle: {
1081
+ color: '#F4F7FD',
1082
+ width: 1
1083
+ }
1084
+ }
1085
+ }, defaultOption);
1086
+ var timeAxis = merge({
1087
+ splitNumber: 6,
1088
+ axisLabel: {
1089
+ // To eliminate labels that are not nice
1090
+ showMinLabel: false,
1091
+ showMaxLabel: false,
1092
+ rich: {
1093
+ primary: {
1094
+ fontWeight: 'bold'
1095
+ }
1096
+ }
1097
+ },
1098
+ splitLine: {
1099
+ show: false
1100
+ }
1101
+ }, valueAxis);
1102
+ var logAxis = defaults({
1103
+ logBase: 10
1104
+ }, valueAxis);
1105
+ const axisDefault = {
1106
+ category: categoryAxis,
1107
+ value: valueAxis,
1108
+ time: timeAxis,
1109
+ log: logAxis
1110
+ };
1111
+
1112
+ /*
1113
+ * Licensed to the Apache Software Foundation (ASF) under one
1114
+ * or more contributor license agreements. See the NOTICE file
1115
+ * distributed with this work for additional information
1116
+ * regarding copyright ownership. The ASF licenses this file
1117
+ * to you under the Apache License, Version 2.0 (the
1118
+ * "License"); you may not use this file except in compliance
1119
+ * with the License. You may obtain a copy of the License at
1120
+ *
1121
+ * http://www.apache.org/licenses/LICENSE-2.0
1122
+ *
1123
+ * Unless required by applicable law or agreed to in writing,
1124
+ * software distributed under the License is distributed on an
1125
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
1126
+ * KIND, either express or implied. See the License for the
1127
+ * specific language governing permissions and limitations
1128
+ * under the License.
1129
+ */
1130
+
1131
+
1132
+ /**
1133
+ * AUTO-GENERATED FILE. DO NOT MODIFY.
1134
+ */
1135
+
1136
+ /*
1137
+ * Licensed to the Apache Software Foundation (ASF) under one
1138
+ * or more contributor license agreements. See the NOTICE file
1139
+ * distributed with this work for additional information
1140
+ * regarding copyright ownership. The ASF licenses this file
1141
+ * to you under the Apache License, Version 2.0 (the
1142
+ * "License"); you may not use this file except in compliance
1143
+ * with the License. You may obtain a copy of the License at
1144
+ *
1145
+ * http://www.apache.org/licenses/LICENSE-2.0
1146
+ *
1147
+ * Unless required by applicable law or agreed to in writing,
1148
+ * software distributed under the License is distributed on an
1149
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
1150
+ * KIND, either express or implied. See the License for the
1151
+ * specific language governing permissions and limitations
1152
+ * under the License.
1153
+ */
1154
+ var AXIS_TYPES = {
1155
+ value: 1,
1156
+ category: 1,
1157
+ time: 1,
1158
+ log: 1
1159
+ };
1160
+
1161
+ /**
1162
+ * Generate sub axis model class
1163
+ * @param axisName 'x' 'y' 'radius' 'angle' 'parallel' ...
1164
+ */
1165
+
1166
+ function axisModelCreator(registers, axisName, BaseAxisModelClass, extraDefaultOption) {
1167
+ each(AXIS_TYPES, function (v, axisType) {
1168
+ var defaultOption = merge(merge({}, axisDefault[axisType], true), extraDefaultOption, true);
1169
+
1170
+ var AxisModel =
1171
+ /** @class */
1172
+ function (_super) {
1173
+ __extends(AxisModel, _super);
1174
+
1175
+ function AxisModel() {
1176
+ var _this = _super !== null && _super.apply(this, arguments) || this;
1177
+
1178
+ _this.type = axisName + 'Axis.' + axisType;
1179
+ return _this;
1180
+ }
1181
+
1182
+ AxisModel.prototype.mergeDefaultAndTheme = function (option, ecModel) {
1183
+ var layoutMode = fetchLayoutMode(this);
1184
+ var inputPositionParams = layoutMode ? getLayoutParams(option) : {};
1185
+ var themeModel = ecModel.getTheme();
1186
+ merge(option, themeModel.get(axisType + 'Axis'));
1187
+ merge(option, this.getDefaultOption());
1188
+ option.type = getAxisType(option);
1189
+
1190
+ if (layoutMode) {
1191
+ mergeLayoutParam(option, inputPositionParams, layoutMode);
1192
+ }
1193
+ };
1194
+
1195
+ AxisModel.prototype.optionUpdated = function () {
1196
+ var thisOption = this.option;
1197
+
1198
+ if (thisOption.type === 'category') {
1199
+ this.__ordinalMeta = OrdinalMeta.createByAxisModel(this);
1200
+ }
1201
+ };
1202
+ /**
1203
+ * Should not be called before all of 'getInitailData' finished.
1204
+ * Because categories are collected during initializing data.
1205
+ */
1206
+
1207
+
1208
+ AxisModel.prototype.getCategories = function (rawData) {
1209
+ var option = this.option; // FIXME
1210
+ // warning if called before all of 'getInitailData' finished.
1211
+
1212
+ if (option.type === 'category') {
1213
+ if (rawData) {
1214
+ return option.data;
1215
+ }
1216
+
1217
+ return this.__ordinalMeta.categories;
1218
+ }
1219
+ };
1220
+
1221
+ AxisModel.prototype.getOrdinalMeta = function () {
1222
+ return this.__ordinalMeta;
1223
+ };
1224
+
1225
+ AxisModel.type = axisName + 'Axis.' + axisType;
1226
+ AxisModel.defaultOption = defaultOption;
1227
+ return AxisModel;
1228
+ }(BaseAxisModelClass);
1229
+
1230
+ registers.registerComponentModel(AxisModel);
1231
+ });
1232
+ registers.registerSubTypeDefaulter(axisName + 'Axis', getAxisType);
1233
+ }
1234
+
1235
+ function getAxisType(option) {
1236
+ // Default axis with data is category axis
1237
+ return option.type || (option.data ? 'category' : 'value');
1238
+ }
1239
+
1240
+ var Cartesian =
1241
+ /** @class */
1242
+ function () {
1243
+ function Cartesian(name) {
1244
+ this.type = 'cartesian';
1245
+ this._dimList = [];
1246
+ this._axes = {};
1247
+ this.name = name || '';
1248
+ }
1249
+
1250
+ Cartesian.prototype.getAxis = function (dim) {
1251
+ return this._axes[dim];
1252
+ };
1253
+
1254
+ Cartesian.prototype.getAxes = function () {
1255
+ return map(this._dimList, function (dim) {
1256
+ return this._axes[dim];
1257
+ }, this);
1258
+ };
1259
+
1260
+ Cartesian.prototype.getAxesByScale = function (scaleType) {
1261
+ scaleType = scaleType.toLowerCase();
1262
+ return filter(this.getAxes(), function (axis) {
1263
+ return axis.scale.type === scaleType;
1264
+ });
1265
+ };
1266
+
1267
+ Cartesian.prototype.addAxis = function (axis) {
1268
+ var dim = axis.dim;
1269
+ this._axes[dim] = axis;
1270
+
1271
+ this._dimList.push(dim);
1272
+ };
1273
+
1274
+ return Cartesian;
1275
+ }();
1276
+
1277
+ var cartesian2DDimensions = ['x', 'y'];
1278
+
1279
+ function canCalculateAffineTransform(scale) {
1280
+ return scale.type === 'interval' || scale.type === 'time';
1281
+ }
1282
+
1283
+ var Cartesian2D =
1284
+ /** @class */
1285
+ function (_super) {
1286
+ __extends(Cartesian2D, _super);
1287
+
1288
+ function Cartesian2D() {
1289
+ var _this = _super !== null && _super.apply(this, arguments) || this;
1290
+
1291
+ _this.type = 'cartesian2d';
1292
+ _this.dimensions = cartesian2DDimensions;
1293
+ return _this;
1294
+ }
1295
+ /**
1296
+ * Calculate an affine transform matrix if two axes are time or value.
1297
+ * It's mainly for accelartion on the large time series data.
1298
+ */
1299
+
1300
+
1301
+ Cartesian2D.prototype.calcAffineTransform = function () {
1302
+ this._transform = this._invTransform = null;
1303
+ var xAxisScale = this.getAxis('x').scale;
1304
+ var yAxisScale = this.getAxis('y').scale;
1305
+
1306
+ if (!canCalculateAffineTransform(xAxisScale) || !canCalculateAffineTransform(yAxisScale)) {
1307
+ return;
1308
+ }
1309
+
1310
+ var xScaleExtent = xAxisScale.getExtent();
1311
+ var yScaleExtent = yAxisScale.getExtent();
1312
+ var start = this.dataToPoint([xScaleExtent[0], yScaleExtent[0]]);
1313
+ var end = this.dataToPoint([xScaleExtent[1], yScaleExtent[1]]);
1314
+ var xScaleSpan = xScaleExtent[1] - xScaleExtent[0];
1315
+ var yScaleSpan = yScaleExtent[1] - yScaleExtent[0];
1316
+
1317
+ if (!xScaleSpan || !yScaleSpan) {
1318
+ return;
1319
+ } // Accelerate data to point calculation on the special large time series data.
1320
+
1321
+
1322
+ var scaleX = (end[0] - start[0]) / xScaleSpan;
1323
+ var scaleY = (end[1] - start[1]) / yScaleSpan;
1324
+ var translateX = start[0] - xScaleExtent[0] * scaleX;
1325
+ var translateY = start[1] - yScaleExtent[0] * scaleY;
1326
+ var m = this._transform = [scaleX, 0, 0, scaleY, translateX, translateY];
1327
+ this._invTransform = invert([], m);
1328
+ };
1329
+ /**
1330
+ * Base axis will be used on stacking.
1331
+ */
1332
+
1333
+
1334
+ Cartesian2D.prototype.getBaseAxis = function () {
1335
+ return this.getAxesByScale('ordinal')[0] || this.getAxesByScale('time')[0] || this.getAxis('x');
1336
+ };
1337
+
1338
+ Cartesian2D.prototype.containPoint = function (point) {
1339
+ var axisX = this.getAxis('x');
1340
+ var axisY = this.getAxis('y');
1341
+ return axisX.contain(axisX.toLocalCoord(point[0])) && axisY.contain(axisY.toLocalCoord(point[1]));
1342
+ };
1343
+
1344
+ Cartesian2D.prototype.containData = function (data) {
1345
+ return this.getAxis('x').containData(data[0]) && this.getAxis('y').containData(data[1]);
1346
+ };
1347
+
1348
+ Cartesian2D.prototype.containZone = function (data1, data2) {
1349
+ var zoneDiag1 = this.dataToPoint(data1);
1350
+ var zoneDiag2 = this.dataToPoint(data2);
1351
+ var area = this.getArea();
1352
+ var zone = new BoundingRect(zoneDiag1[0], zoneDiag1[1], zoneDiag2[0] - zoneDiag1[0], zoneDiag2[1] - zoneDiag1[1]);
1353
+ return area.intersect(zone);
1354
+ };
1355
+
1356
+ Cartesian2D.prototype.dataToPoint = function (data, clamp, out) {
1357
+ out = out || [];
1358
+ var xVal = data[0];
1359
+ var yVal = data[1]; // Fast path
1360
+
1361
+ if (this._transform // It's supported that if data is like `[Inifity, 123]`, where only Y pixel calculated.
1362
+ && xVal != null && isFinite(xVal) && yVal != null && isFinite(yVal)) {
1363
+ return applyTransform(out, data, this._transform);
1364
+ }
1365
+
1366
+ var xAxis = this.getAxis('x');
1367
+ var yAxis = this.getAxis('y');
1368
+ out[0] = xAxis.toGlobalCoord(xAxis.dataToCoord(xVal, clamp));
1369
+ out[1] = yAxis.toGlobalCoord(yAxis.dataToCoord(yVal, clamp));
1370
+ return out;
1371
+ };
1372
+
1373
+ Cartesian2D.prototype.clampData = function (data, out) {
1374
+ var xScale = this.getAxis('x').scale;
1375
+ var yScale = this.getAxis('y').scale;
1376
+ var xAxisExtent = xScale.getExtent();
1377
+ var yAxisExtent = yScale.getExtent();
1378
+ var x = xScale.parse(data[0]);
1379
+ var y = yScale.parse(data[1]);
1380
+ out = out || [];
1381
+ out[0] = Math.min(Math.max(Math.min(xAxisExtent[0], xAxisExtent[1]), x), Math.max(xAxisExtent[0], xAxisExtent[1]));
1382
+ out[1] = Math.min(Math.max(Math.min(yAxisExtent[0], yAxisExtent[1]), y), Math.max(yAxisExtent[0], yAxisExtent[1]));
1383
+ return out;
1384
+ };
1385
+
1386
+ Cartesian2D.prototype.pointToData = function (point, clamp) {
1387
+ var out = [];
1388
+
1389
+ if (this._invTransform) {
1390
+ return applyTransform(out, point, this._invTransform);
1391
+ }
1392
+
1393
+ var xAxis = this.getAxis('x');
1394
+ var yAxis = this.getAxis('y');
1395
+ out[0] = xAxis.coordToData(xAxis.toLocalCoord(point[0]), clamp);
1396
+ out[1] = yAxis.coordToData(yAxis.toLocalCoord(point[1]), clamp);
1397
+ return out;
1398
+ };
1399
+
1400
+ Cartesian2D.prototype.getOtherAxis = function (axis) {
1401
+ return this.getAxis(axis.dim === 'x' ? 'y' : 'x');
1402
+ };
1403
+ /**
1404
+ * Get rect area of cartesian.
1405
+ * Area will have a contain function to determine if a point is in the coordinate system.
1406
+ */
1407
+
1408
+
1409
+ Cartesian2D.prototype.getArea = function () {
1410
+ var xExtent = this.getAxis('x').getGlobalExtent();
1411
+ var yExtent = this.getAxis('y').getGlobalExtent();
1412
+ var x = Math.min(xExtent[0], xExtent[1]);
1413
+ var y = Math.min(yExtent[0], yExtent[1]);
1414
+ var width = Math.max(xExtent[0], xExtent[1]) - x;
1415
+ var height = Math.max(yExtent[0], yExtent[1]) - y;
1416
+ return new BoundingRect(x, y, width, height);
1417
+ };
1418
+
1419
+ return Cartesian2D;
1420
+ }(Cartesian);
1421
+
1422
+ var Axis2D =
1423
+ /** @class */
1424
+ function (_super) {
1425
+ __extends(Axis2D, _super);
1426
+
1427
+ function Axis2D(dim, scale, coordExtent, axisType, position) {
1428
+ var _this = _super.call(this, dim, scale, coordExtent) || this;
1429
+ /**
1430
+ * Index of axis, can be used as key
1431
+ * Injected outside.
1432
+ */
1433
+
1434
+
1435
+ _this.index = 0;
1436
+ _this.type = axisType || 'value';
1437
+ _this.position = position || 'bottom';
1438
+ return _this;
1439
+ }
1440
+
1441
+ Axis2D.prototype.isHorizontal = function () {
1442
+ var position = this.position;
1443
+ return position === 'top' || position === 'bottom';
1444
+ };
1445
+ /**
1446
+ * Each item cooresponds to this.getExtent(), which
1447
+ * means globalExtent[0] may greater than globalExtent[1],
1448
+ * unless `asc` is input.
1449
+ *
1450
+ * @param {boolean} [asc]
1451
+ * @return {Array.<number>}
1452
+ */
1453
+
1454
+
1455
+ Axis2D.prototype.getGlobalExtent = function (asc) {
1456
+ var ret = this.getExtent();
1457
+ ret[0] = this.toGlobalCoord(ret[0]);
1458
+ ret[1] = this.toGlobalCoord(ret[1]);
1459
+ asc && ret[0] > ret[1] && ret.reverse();
1460
+ return ret;
1461
+ };
1462
+
1463
+ Axis2D.prototype.pointToData = function (point, clamp) {
1464
+ return this.coordToData(this.toLocalCoord(point[this.dim === 'x' ? 0 : 1]), clamp);
1465
+ };
1466
+ /**
1467
+ * Set ordinalSortInfo
1468
+ * @param info new OrdinalSortInfo
1469
+ */
1470
+
1471
+
1472
+ Axis2D.prototype.setCategorySortInfo = function (info) {
1473
+ if (this.type !== 'category') {
1474
+ return false;
1475
+ }
1476
+
1477
+ this.model.option.categorySortInfo = info;
1478
+ this.scale.setSortInfo(info);
1479
+ };
1480
+
1481
+ return Axis2D;
1482
+ }(Axis);
1483
+
1484
+ var mathLog = Math.log;
1485
+ function alignScaleTicks(scale, axisModel, alignToScale) {
1486
+ var intervalScaleProto = IntervalScale.prototype; // NOTE: There is a precondition for log scale here:
1487
+ // In log scale we store _interval and _extent of exponent value.
1488
+ // So if we use the method of InternalScale to set/get these data.
1489
+ // It process the exponent value, which is linear and what we want here.
1490
+
1491
+ var alignToTicks = intervalScaleProto.getTicks.call(alignToScale);
1492
+ var alignToNicedTicks = intervalScaleProto.getTicks.call(alignToScale, true);
1493
+ var alignToSplitNumber = alignToTicks.length - 1;
1494
+ var alignToInterval = intervalScaleProto.getInterval.call(alignToScale);
1495
+ var scaleExtent = getScaleExtent(scale, axisModel);
1496
+ var rawExtent = scaleExtent.extent;
1497
+ var isMinFixed = scaleExtent.fixMin;
1498
+ var isMaxFixed = scaleExtent.fixMax;
1499
+
1500
+ if (scale.type === 'log') {
1501
+ var logBase = mathLog(scale.base);
1502
+ rawExtent = [mathLog(rawExtent[0]) / logBase, mathLog(rawExtent[1]) / logBase];
1503
+ }
1504
+
1505
+ scale.setExtent(rawExtent[0], rawExtent[1]);
1506
+ scale.calcNiceExtent({
1507
+ splitNumber: alignToSplitNumber,
1508
+ fixMin: isMinFixed,
1509
+ fixMax: isMaxFixed
1510
+ });
1511
+ var extent = intervalScaleProto.getExtent.call(scale); // Need to update the rawExtent.
1512
+ // Because value in rawExtent may be not parsed. e.g. 'dataMin', 'dataMax'
1513
+
1514
+ if (isMinFixed) {
1515
+ rawExtent[0] = extent[0];
1516
+ }
1517
+
1518
+ if (isMaxFixed) {
1519
+ rawExtent[1] = extent[1];
1520
+ }
1521
+
1522
+ var interval = intervalScaleProto.getInterval.call(scale);
1523
+ var min = rawExtent[0];
1524
+ var max = rawExtent[1];
1525
+
1526
+ if (isMinFixed && isMaxFixed) {
1527
+ // User set min, max, divide to get new interval
1528
+ interval = (max - min) / alignToSplitNumber;
1529
+ } else if (isMinFixed) {
1530
+ max = rawExtent[0] + interval * alignToSplitNumber; // User set min, expand extent on the other side
1531
+
1532
+ while (max < rawExtent[1] && isFinite(max) && isFinite(rawExtent[1])) {
1533
+ interval = increaseInterval(interval);
1534
+ max = rawExtent[0] + interval * alignToSplitNumber;
1535
+ }
1536
+ } else if (isMaxFixed) {
1537
+ // User set max, expand extent on the other side
1538
+ min = rawExtent[1] - interval * alignToSplitNumber;
1539
+
1540
+ while (min > rawExtent[0] && isFinite(min) && isFinite(rawExtent[0])) {
1541
+ interval = increaseInterval(interval);
1542
+ min = rawExtent[1] - interval * alignToSplitNumber;
1543
+ }
1544
+ } else {
1545
+ var nicedSplitNumber = scale.getTicks().length - 1;
1546
+
1547
+ if (nicedSplitNumber > alignToSplitNumber) {
1548
+ interval = increaseInterval(interval);
1549
+ }
1550
+
1551
+ var range = interval * alignToSplitNumber;
1552
+ max = Math.ceil(rawExtent[1] / interval) * interval;
1553
+ min = round(max - range); // Not change the result that crossing zero.
1554
+
1555
+ if (min < 0 && rawExtent[0] >= 0) {
1556
+ min = 0;
1557
+ max = round(range);
1558
+ } else if (max > 0 && rawExtent[1] <= 0) {
1559
+ max = 0;
1560
+ min = -round(range);
1561
+ }
1562
+ } // Adjust min, max based on the extent of alignTo. When min or max is set in alignTo scale
1563
+
1564
+
1565
+ var t0 = (alignToTicks[0].value - alignToNicedTicks[0].value) / alignToInterval;
1566
+ var t1 = (alignToTicks[alignToSplitNumber].value - alignToNicedTicks[alignToSplitNumber].value) / alignToInterval; // NOTE: Must in setExtent -> setInterval -> setNiceExtent order.
1567
+
1568
+ intervalScaleProto.setExtent.call(scale, min + interval * t0, max + interval * t1);
1569
+ intervalScaleProto.setInterval.call(scale, interval);
1570
+
1571
+ if (t0 || t1) {
1572
+ intervalScaleProto.setNiceExtent.call(scale, min + interval, max - interval);
1573
+ }
1574
+ }
1575
+
1576
+ var Grid =
1577
+ /** @class */
1578
+ function () {
1579
+ function Grid(gridModel, ecModel, api) {
1580
+ // FIXME:TS where used (different from registered type 'cartesian2d')?
1581
+ this.type = 'grid';
1582
+ this._coordsMap = {};
1583
+ this._coordsList = [];
1584
+ this._axesMap = {};
1585
+ this._axesList = [];
1586
+ this.axisPointerEnabled = true;
1587
+ this.dimensions = cartesian2DDimensions;
1588
+
1589
+ this._initCartesian(gridModel, ecModel, api);
1590
+
1591
+ this.model = gridModel;
1592
+ }
1593
+
1594
+ Grid.prototype.getRect = function () {
1595
+ return this._rect;
1596
+ };
1597
+
1598
+ Grid.prototype.update = function (ecModel, api) {
1599
+ var axesMap = this._axesMap;
1600
+
1601
+ this._updateScale(ecModel, this.model);
1602
+
1603
+ function updateAxisTicks(axes) {
1604
+ var alignTo; // Axis is added in order of axisIndex.
1605
+
1606
+ var axesIndices = keys(axes);
1607
+ var len = axesIndices.length;
1608
+
1609
+ if (!len) {
1610
+ return;
1611
+ }
1612
+
1613
+ var axisNeedsAlign = []; // Process once and calculate the ticks for those don't use alignTicks.
1614
+
1615
+ for (var i = len - 1; i >= 0; i--) {
1616
+ var idx = +axesIndices[i]; // Convert to number.
1617
+
1618
+ var axis = axes[idx];
1619
+ var model = axis.model;
1620
+ var scale = axis.scale;
1621
+
1622
+ if ( // Only value and log axis without interval support alignTicks.
1623
+ isIntervalOrLogScale(scale) && model.get('alignTicks') && model.get('interval') == null) {
1624
+ axisNeedsAlign.push(axis);
1625
+ } else {
1626
+ niceScaleExtent(scale, model);
1627
+
1628
+ if (isIntervalOrLogScale(scale)) {
1629
+ // Can only align to interval or log axis.
1630
+ alignTo = axis;
1631
+ }
1632
+ }
1633
+ }
1634
+ // PENDING. Should we find the axis that both set interval, min, max and align to this one?
1635
+
1636
+ if (axisNeedsAlign.length) {
1637
+ if (!alignTo) {
1638
+ alignTo = axisNeedsAlign.pop();
1639
+ niceScaleExtent(alignTo.scale, alignTo.model);
1640
+ }
1641
+
1642
+ each(axisNeedsAlign, function (axis) {
1643
+ alignScaleTicks(axis.scale, axis.model, alignTo.scale);
1644
+ });
1645
+ }
1646
+ }
1647
+
1648
+ updateAxisTicks(axesMap.x);
1649
+ updateAxisTicks(axesMap.y); // Key: axisDim_axisIndex, value: boolean, whether onZero target.
1650
+
1651
+ var onZeroRecords = {};
1652
+ each(axesMap.x, function (xAxis) {
1653
+ fixAxisOnZero(axesMap, 'y', xAxis, onZeroRecords);
1654
+ });
1655
+ each(axesMap.y, function (yAxis) {
1656
+ fixAxisOnZero(axesMap, 'x', yAxis, onZeroRecords);
1657
+ }); // Resize again if containLabel is enabled
1658
+ // FIXME It may cause getting wrong grid size in data processing stage
1659
+
1660
+ this.resize(this.model, api);
1661
+ };
1662
+ /**
1663
+ * Resize the grid
1664
+ */
1665
+
1666
+
1667
+ Grid.prototype.resize = function (gridModel, api, ignoreContainLabel) {
1668
+ var boxLayoutParams = gridModel.getBoxLayoutParams();
1669
+ var isContainLabel = !ignoreContainLabel && gridModel.get('containLabel');
1670
+ var gridRect = getLayoutRect(boxLayoutParams, {
1671
+ width: api.getWidth(),
1672
+ height: api.getHeight()
1673
+ });
1674
+ this._rect = gridRect;
1675
+ var axesList = this._axesList;
1676
+ adjustAxes(); // Minus label size
1677
+
1678
+ if (isContainLabel) {
1679
+ each(axesList, function (axis) {
1680
+ if (!axis.model.get(['axisLabel', 'inside'])) {
1681
+ var labelUnionRect = estimateLabelUnionRect(axis);
1682
+
1683
+ if (labelUnionRect) {
1684
+ var dim = axis.isHorizontal() ? 'height' : 'width';
1685
+ var margin = axis.model.get(['axisLabel', 'margin']);
1686
+ gridRect[dim] -= labelUnionRect[dim] + margin;
1687
+
1688
+ if (axis.position === 'top') {
1689
+ gridRect.y += labelUnionRect.height + margin;
1690
+ } else if (axis.position === 'left') {
1691
+ gridRect.x += labelUnionRect.width + margin;
1692
+ }
1693
+ }
1694
+ }
1695
+ });
1696
+ adjustAxes();
1697
+ }
1698
+
1699
+ each(this._coordsList, function (coord) {
1700
+ // Calculate affine matrix to accelerate the data to point transform.
1701
+ // If all the axes scales are time or value.
1702
+ coord.calcAffineTransform();
1703
+ });
1704
+
1705
+ function adjustAxes() {
1706
+ each(axesList, function (axis) {
1707
+ var isHorizontal = axis.isHorizontal();
1708
+ var extent = isHorizontal ? [0, gridRect.width] : [0, gridRect.height];
1709
+ var idx = axis.inverse ? 1 : 0;
1710
+ axis.setExtent(extent[idx], extent[1 - idx]);
1711
+ updateAxisTransform(axis, isHorizontal ? gridRect.x : gridRect.y);
1712
+ });
1713
+ }
1714
+ };
1715
+
1716
+ Grid.prototype.getAxis = function (dim, axisIndex) {
1717
+ var axesMapOnDim = this._axesMap[dim];
1718
+
1719
+ if (axesMapOnDim != null) {
1720
+ return axesMapOnDim[axisIndex || 0];
1721
+ }
1722
+ };
1723
+
1724
+ Grid.prototype.getAxes = function () {
1725
+ return this._axesList.slice();
1726
+ };
1727
+
1728
+ Grid.prototype.getCartesian = function (xAxisIndex, yAxisIndex) {
1729
+ if (xAxisIndex != null && yAxisIndex != null) {
1730
+ var key = 'x' + xAxisIndex + 'y' + yAxisIndex;
1731
+ return this._coordsMap[key];
1732
+ }
1733
+
1734
+ if (isObject(xAxisIndex)) {
1735
+ yAxisIndex = xAxisIndex.yAxisIndex;
1736
+ xAxisIndex = xAxisIndex.xAxisIndex;
1737
+ }
1738
+
1739
+ for (var i = 0, coordList = this._coordsList; i < coordList.length; i++) {
1740
+ if (coordList[i].getAxis('x').index === xAxisIndex || coordList[i].getAxis('y').index === yAxisIndex) {
1741
+ return coordList[i];
1742
+ }
1743
+ }
1744
+ };
1745
+
1746
+ Grid.prototype.getCartesians = function () {
1747
+ return this._coordsList.slice();
1748
+ };
1749
+ /**
1750
+ * @implements
1751
+ */
1752
+
1753
+
1754
+ Grid.prototype.convertToPixel = function (ecModel, finder, value) {
1755
+ var target = this._findConvertTarget(finder);
1756
+
1757
+ return target.cartesian ? target.cartesian.dataToPoint(value) : target.axis ? target.axis.toGlobalCoord(target.axis.dataToCoord(value)) : null;
1758
+ };
1759
+ /**
1760
+ * @implements
1761
+ */
1762
+
1763
+
1764
+ Grid.prototype.convertFromPixel = function (ecModel, finder, value) {
1765
+ var target = this._findConvertTarget(finder);
1766
+
1767
+ return target.cartesian ? target.cartesian.pointToData(value) : target.axis ? target.axis.coordToData(target.axis.toLocalCoord(value)) : null;
1768
+ };
1769
+
1770
+ Grid.prototype._findConvertTarget = function (finder) {
1771
+ var seriesModel = finder.seriesModel;
1772
+ var xAxisModel = finder.xAxisModel || seriesModel && seriesModel.getReferringComponents('xAxis', SINGLE_REFERRING).models[0];
1773
+ var yAxisModel = finder.yAxisModel || seriesModel && seriesModel.getReferringComponents('yAxis', SINGLE_REFERRING).models[0];
1774
+ var gridModel = finder.gridModel;
1775
+ var coordsList = this._coordsList;
1776
+ var cartesian;
1777
+ var axis;
1778
+
1779
+ if (seriesModel) {
1780
+ cartesian = seriesModel.coordinateSystem;
1781
+ indexOf(coordsList, cartesian) < 0 && (cartesian = null);
1782
+ } else if (xAxisModel && yAxisModel) {
1783
+ cartesian = this.getCartesian(xAxisModel.componentIndex, yAxisModel.componentIndex);
1784
+ } else if (xAxisModel) {
1785
+ axis = this.getAxis('x', xAxisModel.componentIndex);
1786
+ } else if (yAxisModel) {
1787
+ axis = this.getAxis('y', yAxisModel.componentIndex);
1788
+ } // Lowest priority.
1789
+ else if (gridModel) {
1790
+ var grid = gridModel.coordinateSystem;
1791
+
1792
+ if (grid === this) {
1793
+ cartesian = this._coordsList[0];
1794
+ }
1795
+ }
1796
+
1797
+ return {
1798
+ cartesian: cartesian,
1799
+ axis: axis
1800
+ };
1801
+ };
1802
+ /**
1803
+ * @implements
1804
+ */
1805
+
1806
+
1807
+ Grid.prototype.containPoint = function (point) {
1808
+ var coord = this._coordsList[0];
1809
+
1810
+ if (coord) {
1811
+ return coord.containPoint(point);
1812
+ }
1813
+ };
1814
+ /**
1815
+ * Initialize cartesian coordinate systems
1816
+ */
1817
+
1818
+
1819
+ Grid.prototype._initCartesian = function (gridModel, ecModel, api) {
1820
+ var _this = this;
1821
+
1822
+ var grid = this;
1823
+ var axisPositionUsed = {
1824
+ left: false,
1825
+ right: false,
1826
+ top: false,
1827
+ bottom: false
1828
+ };
1829
+ var axesMap = {
1830
+ x: {},
1831
+ y: {}
1832
+ };
1833
+ var axesCount = {
1834
+ x: 0,
1835
+ y: 0
1836
+ }; // Create axis
1837
+
1838
+ ecModel.eachComponent('xAxis', createAxisCreator('x'), this);
1839
+ ecModel.eachComponent('yAxis', createAxisCreator('y'), this);
1840
+
1841
+ if (!axesCount.x || !axesCount.y) {
1842
+ // Roll back when there no either x or y axis
1843
+ this._axesMap = {};
1844
+ this._axesList = [];
1845
+ return;
1846
+ }
1847
+
1848
+ this._axesMap = axesMap; // Create cartesian2d
1849
+
1850
+ each(axesMap.x, function (xAxis, xAxisIndex) {
1851
+ each(axesMap.y, function (yAxis, yAxisIndex) {
1852
+ var key = 'x' + xAxisIndex + 'y' + yAxisIndex;
1853
+ var cartesian = new Cartesian2D(key);
1854
+ cartesian.master = _this;
1855
+ cartesian.model = gridModel;
1856
+ _this._coordsMap[key] = cartesian;
1857
+
1858
+ _this._coordsList.push(cartesian);
1859
+
1860
+ cartesian.addAxis(xAxis);
1861
+ cartesian.addAxis(yAxis);
1862
+ });
1863
+ });
1864
+
1865
+ function createAxisCreator(dimName) {
1866
+ return function (axisModel, idx) {
1867
+ if (!isAxisUsedInTheGrid(axisModel, gridModel)) {
1868
+ return;
1869
+ }
1870
+
1871
+ var axisPosition = axisModel.get('position');
1872
+
1873
+ if (dimName === 'x') {
1874
+ // Fix position
1875
+ if (axisPosition !== 'top' && axisPosition !== 'bottom') {
1876
+ // Default bottom of X
1877
+ axisPosition = axisPositionUsed.bottom ? 'top' : 'bottom';
1878
+ }
1879
+ } else {
1880
+ // Fix position
1881
+ if (axisPosition !== 'left' && axisPosition !== 'right') {
1882
+ // Default left of Y
1883
+ axisPosition = axisPositionUsed.left ? 'right' : 'left';
1884
+ }
1885
+ }
1886
+
1887
+ axisPositionUsed[axisPosition] = true;
1888
+ var axis = new Axis2D(dimName, createScaleByModel(axisModel), [0, 0], axisModel.get('type'), axisPosition);
1889
+ var isCategory = axis.type === 'category';
1890
+ axis.onBand = isCategory && axisModel.get('boundaryGap');
1891
+ axis.inverse = axisModel.get('inverse'); // Inject axis into axisModel
1892
+
1893
+ axisModel.axis = axis; // Inject axisModel into axis
1894
+
1895
+ axis.model = axisModel; // Inject grid info axis
1896
+
1897
+ axis.grid = grid; // Index of axis, can be used as key
1898
+
1899
+ axis.index = idx;
1900
+
1901
+ grid._axesList.push(axis);
1902
+
1903
+ axesMap[dimName][idx] = axis;
1904
+ axesCount[dimName]++;
1905
+ };
1906
+ }
1907
+ };
1908
+ /**
1909
+ * Update cartesian properties from series.
1910
+ */
1911
+
1912
+
1913
+ Grid.prototype._updateScale = function (ecModel, gridModel) {
1914
+ // Reset scale
1915
+ each(this._axesList, function (axis) {
1916
+ axis.scale.setExtent(Infinity, -Infinity);
1917
+
1918
+ if (axis.type === 'category') {
1919
+ var categorySortInfo = axis.model.get('categorySortInfo');
1920
+ axis.scale.setSortInfo(categorySortInfo);
1921
+ }
1922
+ });
1923
+ ecModel.eachSeries(function (seriesModel) {
1924
+ if (isCartesian2DSeries(seriesModel)) {
1925
+ var axesModelMap = findAxisModels(seriesModel);
1926
+ var xAxisModel = axesModelMap.xAxisModel;
1927
+ var yAxisModel = axesModelMap.yAxisModel;
1928
+
1929
+ if (!isAxisUsedInTheGrid(xAxisModel, gridModel) || !isAxisUsedInTheGrid(yAxisModel, gridModel)) {
1930
+ return;
1931
+ }
1932
+
1933
+ var cartesian = this.getCartesian(xAxisModel.componentIndex, yAxisModel.componentIndex);
1934
+ var data = seriesModel.getData();
1935
+ var xAxis = cartesian.getAxis('x');
1936
+ var yAxis = cartesian.getAxis('y');
1937
+ unionExtent(data, xAxis);
1938
+ unionExtent(data, yAxis);
1939
+ }
1940
+ }, this);
1941
+
1942
+ function unionExtent(data, axis) {
1943
+ each(getDataDimensionsOnAxis(data, axis.dim), function (dim) {
1944
+ axis.scale.unionExtentFromData(data, dim);
1945
+ });
1946
+ }
1947
+ };
1948
+ /**
1949
+ * @param dim 'x' or 'y' or 'auto' or null/undefined
1950
+ */
1951
+
1952
+
1953
+ Grid.prototype.getTooltipAxes = function (dim) {
1954
+ var baseAxes = [];
1955
+ var otherAxes = [];
1956
+ each(this.getCartesians(), function (cartesian) {
1957
+ var baseAxis = dim != null && dim !== 'auto' ? cartesian.getAxis(dim) : cartesian.getBaseAxis();
1958
+ var otherAxis = cartesian.getOtherAxis(baseAxis);
1959
+ indexOf(baseAxes, baseAxis) < 0 && baseAxes.push(baseAxis);
1960
+ indexOf(otherAxes, otherAxis) < 0 && otherAxes.push(otherAxis);
1961
+ });
1962
+ return {
1963
+ baseAxes: baseAxes,
1964
+ otherAxes: otherAxes
1965
+ };
1966
+ };
1967
+
1968
+ Grid.create = function (ecModel, api) {
1969
+ var grids = [];
1970
+ ecModel.eachComponent('grid', function (gridModel, idx) {
1971
+ var grid = new Grid(gridModel, ecModel, api);
1972
+ grid.name = 'grid_' + idx; // dataSampling requires axis extent, so resize
1973
+ // should be performed in create stage.
1974
+
1975
+ grid.resize(gridModel, api, true);
1976
+ gridModel.coordinateSystem = grid;
1977
+ grids.push(grid);
1978
+ }); // Inject the coordinateSystems into seriesModel
1979
+
1980
+ ecModel.eachSeries(function (seriesModel) {
1981
+ if (!isCartesian2DSeries(seriesModel)) {
1982
+ return;
1983
+ }
1984
+
1985
+ var axesModelMap = findAxisModels(seriesModel);
1986
+ var xAxisModel = axesModelMap.xAxisModel;
1987
+ var yAxisModel = axesModelMap.yAxisModel;
1988
+ var gridModel = xAxisModel.getCoordSysModel();
1989
+
1990
+ var grid = gridModel.coordinateSystem;
1991
+ seriesModel.coordinateSystem = grid.getCartesian(xAxisModel.componentIndex, yAxisModel.componentIndex);
1992
+ });
1993
+ return grids;
1994
+ }; // For deciding which dimensions to use when creating list data
1995
+
1996
+
1997
+ Grid.dimensions = cartesian2DDimensions;
1998
+ return Grid;
1999
+ }();
2000
+ /**
2001
+ * Check if the axis is used in the specified grid.
2002
+ */
2003
+
2004
+
2005
+ function isAxisUsedInTheGrid(axisModel, gridModel) {
2006
+ return axisModel.getCoordSysModel() === gridModel;
2007
+ }
2008
+
2009
+ function fixAxisOnZero(axesMap, otherAxisDim, axis, // Key: see `getOnZeroRecordKey`
2010
+ onZeroRecords) {
2011
+ axis.getAxesOnZeroOf = function () {
2012
+ // TODO: onZero of multiple axes.
2013
+ return otherAxisOnZeroOf ? [otherAxisOnZeroOf] : [];
2014
+ }; // onZero can not be enabled in these two situations:
2015
+ // 1. When any other axis is a category axis.
2016
+ // 2. When no axis is cross 0 point.
2017
+
2018
+
2019
+ var otherAxes = axesMap[otherAxisDim];
2020
+ var otherAxisOnZeroOf;
2021
+ var axisModel = axis.model;
2022
+ var onZero = axisModel.get(['axisLine', 'onZero']);
2023
+ var onZeroAxisIndex = axisModel.get(['axisLine', 'onZeroAxisIndex']);
2024
+
2025
+ if (!onZero) {
2026
+ return;
2027
+ } // If target axis is specified.
2028
+
2029
+
2030
+ if (onZeroAxisIndex != null) {
2031
+ if (canOnZeroToAxis(otherAxes[onZeroAxisIndex])) {
2032
+ otherAxisOnZeroOf = otherAxes[onZeroAxisIndex];
2033
+ }
2034
+ } else {
2035
+ // Find the first available other axis.
2036
+ for (var idx in otherAxes) {
2037
+ if (otherAxes.hasOwnProperty(idx) && canOnZeroToAxis(otherAxes[idx]) // Consider that two Y axes on one value axis,
2038
+ // if both onZero, the two Y axes overlap.
2039
+ && !onZeroRecords[getOnZeroRecordKey(otherAxes[idx])]) {
2040
+ otherAxisOnZeroOf = otherAxes[idx];
2041
+ break;
2042
+ }
2043
+ }
2044
+ }
2045
+
2046
+ if (otherAxisOnZeroOf) {
2047
+ onZeroRecords[getOnZeroRecordKey(otherAxisOnZeroOf)] = true;
2048
+ }
2049
+
2050
+ function getOnZeroRecordKey(axis) {
2051
+ return axis.dim + '_' + axis.index;
2052
+ }
2053
+ }
2054
+
2055
+ function canOnZeroToAxis(axis) {
2056
+ return axis && axis.type !== 'category' && axis.type !== 'time' && ifAxisCrossZero(axis);
2057
+ }
2058
+
2059
+ function updateAxisTransform(axis, coordBase) {
2060
+ var axisExtent = axis.getExtent();
2061
+ var axisExtentSum = axisExtent[0] + axisExtent[1]; // Fast transform
2062
+
2063
+ axis.toGlobalCoord = axis.dim === 'x' ? function (coord) {
2064
+ return coord + coordBase;
2065
+ } : function (coord) {
2066
+ return axisExtentSum - coord + coordBase;
2067
+ };
2068
+ axis.toLocalCoord = axis.dim === 'x' ? function (coord) {
2069
+ return coord - coordBase;
2070
+ } : function (coord) {
2071
+ return axisExtentSum - coord + coordBase;
2072
+ };
2073
+ }
2074
+
2075
+ var inner = makeInner();
2076
+ function rectCoordAxisBuildSplitArea(axisView, axisGroup, axisModel, gridModel) {
2077
+ var axis = axisModel.axis;
2078
+
2079
+ if (axis.scale.isBlank()) {
2080
+ return;
2081
+ } // TODO: TYPE
2082
+
2083
+
2084
+ var splitAreaModel = axisModel.getModel('splitArea');
2085
+ var areaStyleModel = splitAreaModel.getModel('areaStyle');
2086
+ var areaColors = areaStyleModel.get('color');
2087
+ var gridRect = gridModel.coordinateSystem.getRect();
2088
+ var ticksCoords = axis.getTicksCoords({
2089
+ tickModel: splitAreaModel,
2090
+ clamp: true
2091
+ });
2092
+
2093
+ if (!ticksCoords.length) {
2094
+ return;
2095
+ } // For Making appropriate splitArea animation, the color and anid
2096
+ // should be corresponding to previous one if possible.
2097
+
2098
+
2099
+ var areaColorsLen = areaColors.length;
2100
+ var lastSplitAreaColors = inner(axisView).splitAreaColors;
2101
+ var newSplitAreaColors = createHashMap();
2102
+ var colorIndex = 0;
2103
+
2104
+ if (lastSplitAreaColors) {
2105
+ for (var i = 0; i < ticksCoords.length; i++) {
2106
+ var cIndex = lastSplitAreaColors.get(ticksCoords[i].tickValue);
2107
+
2108
+ if (cIndex != null) {
2109
+ colorIndex = (cIndex + (areaColorsLen - 1) * i) % areaColorsLen;
2110
+ break;
2111
+ }
2112
+ }
2113
+ }
2114
+
2115
+ var prev = axis.toGlobalCoord(ticksCoords[0].coord);
2116
+ var areaStyle = areaStyleModel.getAreaStyle();
2117
+ areaColors = isArray(areaColors) ? areaColors : [areaColors];
2118
+
2119
+ for (var i = 1; i < ticksCoords.length; i++) {
2120
+ var tickCoord = axis.toGlobalCoord(ticksCoords[i].coord);
2121
+ var x = void 0;
2122
+ var y = void 0;
2123
+ var width = void 0;
2124
+ var height = void 0;
2125
+
2126
+ if (axis.isHorizontal()) {
2127
+ x = prev;
2128
+ y = gridRect.y;
2129
+ width = tickCoord - x;
2130
+ height = gridRect.height;
2131
+ prev = x + width;
2132
+ } else {
2133
+ x = gridRect.x;
2134
+ y = prev;
2135
+ width = gridRect.width;
2136
+ height = tickCoord - y;
2137
+ prev = y + height;
2138
+ }
2139
+
2140
+ var tickValue = ticksCoords[i - 1].tickValue;
2141
+ tickValue != null && newSplitAreaColors.set(tickValue, colorIndex);
2142
+ axisGroup.add(new Rect({
2143
+ anid: tickValue != null ? 'area_' + tickValue : null,
2144
+ shape: {
2145
+ x: x,
2146
+ y: y,
2147
+ width: width,
2148
+ height: height
2149
+ },
2150
+ style: defaults({
2151
+ fill: areaColors[colorIndex]
2152
+ }, areaStyle),
2153
+ autoBatch: true,
2154
+ silent: true
2155
+ }));
2156
+ colorIndex = (colorIndex + 1) % areaColorsLen;
2157
+ }
2158
+
2159
+ inner(axisView).splitAreaColors = newSplitAreaColors;
2160
+ }
2161
+ function rectCoordAxisHandleRemove(axisView) {
2162
+ inner(axisView).splitAreaColors = null;
2163
+ }
2164
+
2165
+ var axisBuilderAttrs = ['axisLine', 'axisTickLabel', 'axisName'];
2166
+ var selfBuilderAttrs = ['splitArea', 'splitLine', 'minorSplitLine'];
2167
+
2168
+ var CartesianAxisView =
2169
+ /** @class */
2170
+ function (_super) {
2171
+ __extends(CartesianAxisView, _super);
2172
+
2173
+ function CartesianAxisView() {
2174
+ var _this = _super !== null && _super.apply(this, arguments) || this;
2175
+
2176
+ _this.type = CartesianAxisView.type;
2177
+ _this.axisPointerClass = 'CartesianAxisPointer';
2178
+ return _this;
2179
+ }
2180
+ /**
2181
+ * @override
2182
+ */
2183
+
2184
+
2185
+ CartesianAxisView.prototype.render = function (axisModel, ecModel, api, payload) {
2186
+ this.group.removeAll();
2187
+ var oldAxisGroup = this._axisGroup;
2188
+ this._axisGroup = new Group();
2189
+ this.group.add(this._axisGroup);
2190
+
2191
+ if (!axisModel.get('show')) {
2192
+ return;
2193
+ }
2194
+
2195
+ var gridModel = axisModel.getCoordSysModel();
2196
+ var layout$1 = layout(gridModel, axisModel);
2197
+ var axisBuilder = new AxisBuilder(axisModel, extend({
2198
+ handleAutoShown: function (elementType) {
2199
+ var cartesians = gridModel.coordinateSystem.getCartesians();
2200
+
2201
+ for (var i = 0; i < cartesians.length; i++) {
2202
+ if (isIntervalOrLogScale(cartesians[i].getOtherAxis(axisModel.axis).scale)) {
2203
+ // Still show axis tick or axisLine if other axis is value / log
2204
+ return true;
2205
+ }
2206
+ } // Not show axisTick or axisLine if other axis is category / time
2207
+
2208
+
2209
+ return false;
2210
+ }
2211
+ }, layout$1));
2212
+ each(axisBuilderAttrs, axisBuilder.add, axisBuilder);
2213
+
2214
+ this._axisGroup.add(axisBuilder.getGroup());
2215
+
2216
+ each(selfBuilderAttrs, function (name) {
2217
+ if (axisModel.get([name, 'show'])) {
2218
+ axisElementBuilders[name](this, this._axisGroup, axisModel, gridModel);
2219
+ }
2220
+ }, this); // THIS is a special case for bar racing chart.
2221
+ // Update the axis label from the natural initial layout to
2222
+ // sorted layout should has no animation.
2223
+
2224
+ var isInitialSortFromBarRacing = payload && payload.type === 'changeAxisOrder' && payload.isInitSort;
2225
+
2226
+ if (!isInitialSortFromBarRacing) {
2227
+ groupTransition(oldAxisGroup, this._axisGroup, axisModel);
2228
+ }
2229
+
2230
+ _super.prototype.render.call(this, axisModel, ecModel, api, payload);
2231
+ };
2232
+
2233
+ CartesianAxisView.prototype.remove = function () {
2234
+ rectCoordAxisHandleRemove(this);
2235
+ };
2236
+
2237
+ CartesianAxisView.type = 'cartesianAxis';
2238
+ return CartesianAxisView;
2239
+ }(AxisView);
2240
+
2241
+ var axisElementBuilders = {
2242
+ splitLine: function (axisView, axisGroup, axisModel, gridModel) {
2243
+ var axis = axisModel.axis;
2244
+
2245
+ if (axis.scale.isBlank()) {
2246
+ return;
2247
+ }
2248
+
2249
+ var splitLineModel = axisModel.getModel('splitLine');
2250
+ var lineStyleModel = splitLineModel.getModel('lineStyle');
2251
+ var lineColors = lineStyleModel.get('color');
2252
+ lineColors = isArray(lineColors) ? lineColors : [lineColors];
2253
+ var gridRect = gridModel.coordinateSystem.getRect();
2254
+ var isHorizontal = axis.isHorizontal();
2255
+ var lineCount = 0;
2256
+ var ticksCoords = axis.getTicksCoords({
2257
+ tickModel: splitLineModel
2258
+ });
2259
+ var p1 = [];
2260
+ var p2 = [];
2261
+ var lineStyle = lineStyleModel.getLineStyle();
2262
+
2263
+ for (var i = 0; i < ticksCoords.length; i++) {
2264
+ var tickCoord = axis.toGlobalCoord(ticksCoords[i].coord);
2265
+
2266
+ if (isHorizontal) {
2267
+ p1[0] = tickCoord;
2268
+ p1[1] = gridRect.y;
2269
+ p2[0] = tickCoord;
2270
+ p2[1] = gridRect.y + gridRect.height;
2271
+ } else {
2272
+ p1[0] = gridRect.x;
2273
+ p1[1] = tickCoord;
2274
+ p2[0] = gridRect.x + gridRect.width;
2275
+ p2[1] = tickCoord;
2276
+ }
2277
+
2278
+ var colorIndex = lineCount++ % lineColors.length;
2279
+ var tickValue = ticksCoords[i].tickValue;
2280
+ var line = new Line({
2281
+ anid: tickValue != null ? 'line_' + ticksCoords[i].tickValue : null,
2282
+ autoBatch: true,
2283
+ shape: {
2284
+ x1: p1[0],
2285
+ y1: p1[1],
2286
+ x2: p2[0],
2287
+ y2: p2[1]
2288
+ },
2289
+ style: defaults({
2290
+ stroke: lineColors[colorIndex]
2291
+ }, lineStyle),
2292
+ silent: true
2293
+ });
2294
+ subPixelOptimizeLine(line.shape, lineStyle.lineWidth);
2295
+ axisGroup.add(line);
2296
+ }
2297
+ },
2298
+ minorSplitLine: function (axisView, axisGroup, axisModel, gridModel) {
2299
+ var axis = axisModel.axis;
2300
+ var minorSplitLineModel = axisModel.getModel('minorSplitLine');
2301
+ var lineStyleModel = minorSplitLineModel.getModel('lineStyle');
2302
+ var gridRect = gridModel.coordinateSystem.getRect();
2303
+ var isHorizontal = axis.isHorizontal();
2304
+ var minorTicksCoords = axis.getMinorTicksCoords();
2305
+
2306
+ if (!minorTicksCoords.length) {
2307
+ return;
2308
+ }
2309
+
2310
+ var p1 = [];
2311
+ var p2 = [];
2312
+ var lineStyle = lineStyleModel.getLineStyle();
2313
+
2314
+ for (var i = 0; i < minorTicksCoords.length; i++) {
2315
+ for (var k = 0; k < minorTicksCoords[i].length; k++) {
2316
+ var tickCoord = axis.toGlobalCoord(minorTicksCoords[i][k].coord);
2317
+
2318
+ if (isHorizontal) {
2319
+ p1[0] = tickCoord;
2320
+ p1[1] = gridRect.y;
2321
+ p2[0] = tickCoord;
2322
+ p2[1] = gridRect.y + gridRect.height;
2323
+ } else {
2324
+ p1[0] = gridRect.x;
2325
+ p1[1] = tickCoord;
2326
+ p2[0] = gridRect.x + gridRect.width;
2327
+ p2[1] = tickCoord;
2328
+ }
2329
+
2330
+ var line = new Line({
2331
+ anid: 'minor_line_' + minorTicksCoords[i][k].tickValue,
2332
+ autoBatch: true,
2333
+ shape: {
2334
+ x1: p1[0],
2335
+ y1: p1[1],
2336
+ x2: p2[0],
2337
+ y2: p2[1]
2338
+ },
2339
+ style: lineStyle,
2340
+ silent: true
2341
+ });
2342
+ subPixelOptimizeLine(line.shape, lineStyle.lineWidth);
2343
+ axisGroup.add(line);
2344
+ }
2345
+ }
2346
+ },
2347
+ splitArea: function (axisView, axisGroup, axisModel, gridModel) {
2348
+ rectCoordAxisBuildSplitArea(axisView, axisGroup, axisModel, gridModel);
2349
+ }
2350
+ };
2351
+
2352
+ var CartesianXAxisView =
2353
+ /** @class */
2354
+ function (_super) {
2355
+ __extends(CartesianXAxisView, _super);
2356
+
2357
+ function CartesianXAxisView() {
2358
+ var _this = _super !== null && _super.apply(this, arguments) || this;
2359
+
2360
+ _this.type = CartesianXAxisView.type;
2361
+ return _this;
2362
+ }
2363
+
2364
+ CartesianXAxisView.type = 'xAxis';
2365
+ return CartesianXAxisView;
2366
+ }(CartesianAxisView);
2367
+
2368
+ var CartesianYAxisView =
2369
+ /** @class */
2370
+ function (_super) {
2371
+ __extends(CartesianYAxisView, _super);
2372
+
2373
+ function CartesianYAxisView() {
2374
+ var _this = _super !== null && _super.apply(this, arguments) || this;
2375
+
2376
+ _this.type = CartesianXAxisView.type;
2377
+ return _this;
2378
+ }
2379
+
2380
+ CartesianYAxisView.type = 'yAxis';
2381
+ return CartesianYAxisView;
2382
+ }(CartesianAxisView);
2383
+
2384
+ var GridView =
2385
+ /** @class */
2386
+ function (_super) {
2387
+ __extends(GridView, _super);
2388
+
2389
+ function GridView() {
2390
+ var _this = _super !== null && _super.apply(this, arguments) || this;
2391
+
2392
+ _this.type = 'grid';
2393
+ return _this;
2394
+ }
2395
+
2396
+ GridView.prototype.render = function (gridModel, ecModel) {
2397
+ this.group.removeAll();
2398
+
2399
+ if (gridModel.get('show')) {
2400
+ this.group.add(new Rect({
2401
+ shape: gridModel.coordinateSystem.getRect(),
2402
+ style: defaults({
2403
+ fill: gridModel.get('backgroundColor')
2404
+ }, gridModel.getItemStyle()),
2405
+ silent: true,
2406
+ z2: -1
2407
+ }));
2408
+ }
2409
+ };
2410
+
2411
+ GridView.type = 'grid';
2412
+ return GridView;
2413
+ }(ComponentView);
2414
+
2415
+ var extraOption = {
2416
+ // gridIndex: 0,
2417
+ // gridId: '',
2418
+ offset: 0
2419
+ };
2420
+ function install$3(registers) {
2421
+ registers.registerComponentView(GridView);
2422
+ registers.registerComponentModel(GridModel);
2423
+ registers.registerCoordinateSystem('cartesian2d', Grid);
2424
+ axisModelCreator(registers, 'x', CartesianAxisModel, extraOption);
2425
+ axisModelCreator(registers, 'y', CartesianAxisModel, extraOption);
2426
+ registers.registerComponentView(CartesianXAxisView);
2427
+ registers.registerComponentView(CartesianYAxisView);
2428
+ registers.registerPreprocessor(function (option) {
2429
+ // Only create grid when need
2430
+ if (option.xAxis && option.yAxis && !option.grid) {
2431
+ option.grid = {};
2432
+ }
2433
+ });
2434
+ }
2435
+
2436
+ function install$2(registers) {
2437
+ use(install$3);
2438
+ use(install$4);
2439
+ }
2440
+
2441
+ var TitleModel =
2442
+ /** @class */
2443
+ function (_super) {
2444
+ __extends(TitleModel, _super);
2445
+
2446
+ function TitleModel() {
2447
+ var _this = _super !== null && _super.apply(this, arguments) || this;
2448
+
2449
+ _this.type = TitleModel.type;
2450
+ _this.layoutMode = {
2451
+ type: 'box',
2452
+ ignoreSize: true
2453
+ };
2454
+ return _this;
2455
+ }
2456
+
2457
+ TitleModel.type = 'title';
2458
+ TitleModel.defaultOption = {
2459
+ // zlevel: 0,
2460
+ z: 6,
2461
+ show: true,
2462
+ text: '',
2463
+ target: 'blank',
2464
+ subtext: '',
2465
+ subtarget: 'blank',
2466
+ left: 0,
2467
+ top: 0,
2468
+ backgroundColor: 'rgba(0,0,0,0)',
2469
+ borderColor: '#ccc',
2470
+ borderWidth: 0,
2471
+ padding: 5,
2472
+ itemGap: 10,
2473
+ textStyle: {
2474
+ fontSize: 18,
2475
+ fontWeight: 'bold',
2476
+ color: '#464646'
2477
+ },
2478
+ subtextStyle: {
2479
+ fontSize: 12,
2480
+ color: '#6E7079'
2481
+ }
2482
+ };
2483
+ return TitleModel;
2484
+ }(ComponentModel); // View
2485
+
2486
+
2487
+ var TitleView =
2488
+ /** @class */
2489
+ function (_super) {
2490
+ __extends(TitleView, _super);
2491
+
2492
+ function TitleView() {
2493
+ var _this = _super !== null && _super.apply(this, arguments) || this;
2494
+
2495
+ _this.type = TitleView.type;
2496
+ return _this;
2497
+ }
2498
+
2499
+ TitleView.prototype.render = function (titleModel, ecModel, api) {
2500
+ this.group.removeAll();
2501
+
2502
+ if (!titleModel.get('show')) {
2503
+ return;
2504
+ }
2505
+
2506
+ var group = this.group;
2507
+ var textStyleModel = titleModel.getModel('textStyle');
2508
+ var subtextStyleModel = titleModel.getModel('subtextStyle');
2509
+ var textAlign = titleModel.get('textAlign');
2510
+ var textVerticalAlign = retrieve2(titleModel.get('textBaseline'), titleModel.get('textVerticalAlign'));
2511
+ var textEl = new ZRText({
2512
+ style: createTextStyle(textStyleModel, {
2513
+ text: titleModel.get('text'),
2514
+ fill: textStyleModel.getTextColor()
2515
+ }, {
2516
+ disableBox: true
2517
+ }),
2518
+ z2: 10
2519
+ });
2520
+ var textRect = textEl.getBoundingRect();
2521
+ var subText = titleModel.get('subtext');
2522
+ var subTextEl = new ZRText({
2523
+ style: createTextStyle(subtextStyleModel, {
2524
+ text: subText,
2525
+ fill: subtextStyleModel.getTextColor(),
2526
+ y: textRect.height + titleModel.get('itemGap'),
2527
+ verticalAlign: 'top'
2528
+ }, {
2529
+ disableBox: true
2530
+ }),
2531
+ z2: 10
2532
+ });
2533
+ var link = titleModel.get('link');
2534
+ var sublink = titleModel.get('sublink');
2535
+ var triggerEvent = titleModel.get('triggerEvent', true);
2536
+ textEl.silent = !link && !triggerEvent;
2537
+ subTextEl.silent = !sublink && !triggerEvent;
2538
+
2539
+ if (link) {
2540
+ textEl.on('click', function () {
2541
+ windowOpen(link, '_' + titleModel.get('target'));
2542
+ });
2543
+ }
2544
+
2545
+ if (sublink) {
2546
+ subTextEl.on('click', function () {
2547
+ windowOpen(sublink, '_' + titleModel.get('subtarget'));
2548
+ });
2549
+ }
2550
+
2551
+ getECData(textEl).eventData = getECData(subTextEl).eventData = triggerEvent ? {
2552
+ componentType: 'title',
2553
+ componentIndex: titleModel.componentIndex
2554
+ } : null;
2555
+ group.add(textEl);
2556
+ subText && group.add(subTextEl); // If no subText, but add subTextEl, there will be an empty line.
2557
+
2558
+ var groupRect = group.getBoundingRect();
2559
+ var layoutOption = titleModel.getBoxLayoutParams();
2560
+ layoutOption.width = groupRect.width;
2561
+ layoutOption.height = groupRect.height;
2562
+ var layoutRect = getLayoutRect(layoutOption, {
2563
+ width: api.getWidth(),
2564
+ height: api.getHeight()
2565
+ }, titleModel.get('padding')); // Adjust text align based on position
2566
+
2567
+ if (!textAlign) {
2568
+ // Align left if title is on the left. center and right is same
2569
+ textAlign = titleModel.get('left') || titleModel.get('right'); // @ts-ignore
2570
+
2571
+ if (textAlign === 'middle') {
2572
+ textAlign = 'center';
2573
+ } // Adjust layout by text align
2574
+
2575
+
2576
+ if (textAlign === 'right') {
2577
+ layoutRect.x += layoutRect.width;
2578
+ } else if (textAlign === 'center') {
2579
+ layoutRect.x += layoutRect.width / 2;
2580
+ }
2581
+ }
2582
+
2583
+ if (!textVerticalAlign) {
2584
+ textVerticalAlign = titleModel.get('top') || titleModel.get('bottom'); // @ts-ignore
2585
+
2586
+ if (textVerticalAlign === 'center') {
2587
+ textVerticalAlign = 'middle';
2588
+ }
2589
+
2590
+ if (textVerticalAlign === 'bottom') {
2591
+ layoutRect.y += layoutRect.height;
2592
+ } else if (textVerticalAlign === 'middle') {
2593
+ layoutRect.y += layoutRect.height / 2;
2594
+ }
2595
+
2596
+ textVerticalAlign = textVerticalAlign || 'top';
2597
+ }
2598
+
2599
+ group.x = layoutRect.x;
2600
+ group.y = layoutRect.y;
2601
+ group.markRedraw();
2602
+ var alignStyle = {
2603
+ align: textAlign,
2604
+ verticalAlign: textVerticalAlign
2605
+ };
2606
+ textEl.setStyle(alignStyle);
2607
+ subTextEl.setStyle(alignStyle); // Render background
2608
+ // Get groupRect again because textAlign has been changed
2609
+
2610
+ groupRect = group.getBoundingRect();
2611
+ var padding = layoutRect.margin;
2612
+ var style = titleModel.getItemStyle(['color', 'opacity']);
2613
+ style.fill = titleModel.get('backgroundColor');
2614
+ var rect = new Rect({
2615
+ shape: {
2616
+ x: groupRect.x - padding[3],
2617
+ y: groupRect.y - padding[0],
2618
+ width: groupRect.width + padding[1] + padding[3],
2619
+ height: groupRect.height + padding[0] + padding[2],
2620
+ r: titleModel.get('borderRadius')
2621
+ },
2622
+ style: style,
2623
+ subPixelOptimize: true,
2624
+ silent: true
2625
+ });
2626
+ group.add(rect);
2627
+ };
2628
+
2629
+ TitleView.type = 'title';
2630
+ return TitleView;
2631
+ }(ComponentView);
2632
+
2633
+ function install$1(registers) {
2634
+ registers.registerComponentModel(TitleModel);
2635
+ registers.registerComponentView(TitleView);
2636
+ }
2637
+
2638
+ /**
2639
+ * @return label string. Not null/undefined
2640
+ */
2641
+
2642
+ function getDefaultLabel(data, dataIndex) {
2643
+ var labelDims = data.mapDimensionsAll('defaultedLabel');
2644
+ var len = labelDims.length; // Simple optimization (in lots of cases, label dims length is 1)
2645
+
2646
+ if (len === 1) {
2647
+ var rawVal = retrieveRawValue(data, dataIndex, labelDims[0]);
2648
+ return rawVal != null ? rawVal + '' : null;
2649
+ } else if (len) {
2650
+ var vals = [];
2651
+
2652
+ for (var i = 0; i < labelDims.length; i++) {
2653
+ vals.push(retrieveRawValue(data, dataIndex, labelDims[i]));
2654
+ }
2655
+
2656
+ return vals.join(' ');
2657
+ }
2658
+ }
2659
+ function getDefaultInterpolatedLabel(data, interpolatedValue) {
2660
+ var labelDims = data.mapDimensionsAll('defaultedLabel');
2661
+
2662
+ if (!isArray(interpolatedValue)) {
2663
+ return interpolatedValue + '';
2664
+ }
2665
+
2666
+ var vals = [];
2667
+
2668
+ for (var i = 0; i < labelDims.length; i++) {
2669
+ var dimIndex = data.getDimensionIndex(labelDims[i]);
2670
+
2671
+ if (dimIndex >= 0) {
2672
+ vals.push(interpolatedValue[dimIndex]);
2673
+ }
2674
+ }
2675
+
2676
+ return vals.join(' ');
2677
+ }
2678
+
2679
+ /*
2680
+ * Licensed to the Apache Software Foundation (ASF) under one
2681
+ * or more contributor license agreements. See the NOTICE file
2682
+ * distributed with this work for additional information
2683
+ * regarding copyright ownership. The ASF licenses this file
2684
+ * to you under the Apache License, Version 2.0 (the
2685
+ * "License"); you may not use this file except in compliance
2686
+ * with the License. You may obtain a copy of the License at
2687
+ *
2688
+ * http://www.apache.org/licenses/LICENSE-2.0
2689
+ *
2690
+ * Unless required by applicable law or agreed to in writing,
2691
+ * software distributed under the License is distributed on an
2692
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
2693
+ * KIND, either express or implied. See the License for the
2694
+ * specific language governing permissions and limitations
2695
+ * under the License.
2696
+ */
2697
+
2698
+
2699
+ /**
2700
+ * AUTO-GENERATED FILE. DO NOT MODIFY.
2701
+ */
2702
+
2703
+ /*
2704
+ * Licensed to the Apache Software Foundation (ASF) under one
2705
+ * or more contributor license agreements. See the NOTICE file
2706
+ * distributed with this work for additional information
2707
+ * regarding copyright ownership. The ASF licenses this file
2708
+ * to you under the Apache License, Version 2.0 (the
2709
+ * "License"); you may not use this file except in compliance
2710
+ * with the License. You may obtain a copy of the License at
2711
+ *
2712
+ * http://www.apache.org/licenses/LICENSE-2.0
2713
+ *
2714
+ * Unless required by applicable law or agreed to in writing,
2715
+ * software distributed under the License is distributed on an
2716
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
2717
+ * KIND, either express or implied. See the License for the
2718
+ * specific language governing permissions and limitations
2719
+ * under the License.
2720
+ */
2721
+ function isCoordinateSystemType(coordSys, type) {
2722
+ return coordSys.type === type;
2723
+ }
2724
+
2725
+ function createGridClipPath(cartesian, hasAnimation, seriesModel, done, during) {
2726
+ var rect = cartesian.getArea();
2727
+ var x = rect.x;
2728
+ var y = rect.y;
2729
+ var width = rect.width;
2730
+ var height = rect.height;
2731
+ var lineWidth = seriesModel.get(['lineStyle', 'width']) || 2; // Expand the clip path a bit to avoid the border is clipped and looks thinner
2732
+
2733
+ x -= lineWidth / 2;
2734
+ y -= lineWidth / 2;
2735
+ width += lineWidth;
2736
+ height += lineWidth; // fix: https://github.com/apache/incubator-echarts/issues/11369
2737
+
2738
+ x = Math.floor(x);
2739
+ width = Math.round(width);
2740
+ var clipPath = new Rect({
2741
+ shape: {
2742
+ x: x,
2743
+ y: y,
2744
+ width: width,
2745
+ height: height
2746
+ }
2747
+ });
2748
+
2749
+ if (hasAnimation) {
2750
+ var baseAxis = cartesian.getBaseAxis();
2751
+ var isHorizontal = baseAxis.isHorizontal();
2752
+ var isAxisInversed = baseAxis.inverse;
2753
+
2754
+ if (isHorizontal) {
2755
+ if (isAxisInversed) {
2756
+ clipPath.shape.x += width;
2757
+ }
2758
+
2759
+ clipPath.shape.width = 0;
2760
+ } else {
2761
+ if (!isAxisInversed) {
2762
+ clipPath.shape.y += height;
2763
+ }
2764
+
2765
+ clipPath.shape.height = 0;
2766
+ }
2767
+
2768
+ var duringCb = isFunction(during) ? function (percent) {
2769
+ during(percent, clipPath);
2770
+ } : null;
2771
+ initProps(clipPath, {
2772
+ shape: {
2773
+ width: width,
2774
+ height: height,
2775
+ x: x,
2776
+ y: y
2777
+ }
2778
+ }, seriesModel, null, done, duringCb);
2779
+ }
2780
+
2781
+ return clipPath;
2782
+ }
2783
+
2784
+ function createPolarClipPath(polar, hasAnimation, seriesModel) {
2785
+ var sectorArea = polar.getArea(); // Avoid float number rounding error for symbol on the edge of axis extent.
2786
+
2787
+ var r0 = round(sectorArea.r0, 1);
2788
+ var r = round(sectorArea.r, 1);
2789
+ var clipPath = new Sector({
2790
+ shape: {
2791
+ cx: round(polar.cx, 1),
2792
+ cy: round(polar.cy, 1),
2793
+ r0: r0,
2794
+ r: r,
2795
+ startAngle: sectorArea.startAngle,
2796
+ endAngle: sectorArea.endAngle,
2797
+ clockwise: sectorArea.clockwise
2798
+ }
2799
+ });
2800
+
2801
+ if (hasAnimation) {
2802
+ var isRadial = polar.getBaseAxis().dim === 'angle';
2803
+
2804
+ if (isRadial) {
2805
+ clipPath.shape.endAngle = sectorArea.startAngle;
2806
+ } else {
2807
+ clipPath.shape.r = r0;
2808
+ }
2809
+
2810
+ initProps(clipPath, {
2811
+ shape: {
2812
+ endAngle: sectorArea.endAngle,
2813
+ r: r
2814
+ }
2815
+ }, seriesModel);
2816
+ }
2817
+
2818
+ return clipPath;
2819
+ }
2820
+
2821
+ function createClipPath(coordSys, hasAnimation, seriesModel, done, during) {
2822
+ if (!coordSys) {
2823
+ return null;
2824
+ } else if (coordSys.type === 'polar') {
2825
+ return createPolarClipPath(coordSys, hasAnimation, seriesModel);
2826
+ } else if (coordSys.type === 'cartesian2d') {
2827
+ return createGridClipPath(coordSys, hasAnimation, seriesModel, done, during);
2828
+ }
2829
+
2830
+ return null;
2831
+ }
2832
+
2833
+ var samplers = {
2834
+ average: function (frame) {
2835
+ var sum = 0;
2836
+ var count = 0;
2837
+
2838
+ for (var i = 0; i < frame.length; i++) {
2839
+ if (!isNaN(frame[i])) {
2840
+ sum += frame[i];
2841
+ count++;
2842
+ }
2843
+ } // Return NaN if count is 0
2844
+
2845
+
2846
+ return count === 0 ? NaN : sum / count;
2847
+ },
2848
+ sum: function (frame) {
2849
+ var sum = 0;
2850
+
2851
+ for (var i = 0; i < frame.length; i++) {
2852
+ // Ignore NaN
2853
+ sum += frame[i] || 0;
2854
+ }
2855
+
2856
+ return sum;
2857
+ },
2858
+ max: function (frame) {
2859
+ var max = -Infinity;
2860
+
2861
+ for (var i = 0; i < frame.length; i++) {
2862
+ frame[i] > max && (max = frame[i]);
2863
+ } // NaN will cause illegal axis extent.
2864
+
2865
+
2866
+ return isFinite(max) ? max : NaN;
2867
+ },
2868
+ min: function (frame) {
2869
+ var min = Infinity;
2870
+
2871
+ for (var i = 0; i < frame.length; i++) {
2872
+ frame[i] < min && (min = frame[i]);
2873
+ } // NaN will cause illegal axis extent.
2874
+
2875
+
2876
+ return isFinite(min) ? min : NaN;
2877
+ },
2878
+ // TODO
2879
+ // Median
2880
+ nearest: function (frame) {
2881
+ return frame[0];
2882
+ }
2883
+ };
2884
+
2885
+ var indexSampler = function (frame) {
2886
+ return Math.round(frame.length / 2);
2887
+ };
2888
+
2889
+ function dataSample(seriesType) {
2890
+ return {
2891
+ seriesType: seriesType,
2892
+ // FIXME:TS never used, so comment it
2893
+ // modifyOutputEnd: true,
2894
+ reset: function (seriesModel, ecModel, api) {
2895
+ var data = seriesModel.getData();
2896
+ var sampling = seriesModel.get('sampling');
2897
+ var coordSys = seriesModel.coordinateSystem;
2898
+ var count = data.count(); // Only cartesian2d support down sampling. Disable it when there is few data.
2899
+
2900
+ if (count > 10 && coordSys.type === 'cartesian2d' && sampling) {
2901
+ var baseAxis = coordSys.getBaseAxis();
2902
+ var valueAxis = coordSys.getOtherAxis(baseAxis);
2903
+ var extent = baseAxis.getExtent();
2904
+ var dpr = api.getDevicePixelRatio(); // Coordinste system has been resized
2905
+
2906
+ var size = Math.abs(extent[1] - extent[0]) * (dpr || 1);
2907
+ var rate = Math.round(count / size);
2908
+
2909
+ if (isFinite(rate) && rate > 1) {
2910
+ if (sampling === 'lttb') {
2911
+ seriesModel.setData(data.lttbDownSample(data.mapDimension(valueAxis.dim), 1 / rate));
2912
+ }
2913
+
2914
+ var sampler = void 0;
2915
+
2916
+ if (isString(sampling)) {
2917
+ sampler = samplers[sampling];
2918
+ } else if (isFunction(sampling)) {
2919
+ sampler = sampling;
2920
+ }
2921
+
2922
+ if (sampler) {
2923
+ // Only support sample the first dim mapped from value axis.
2924
+ seriesModel.setData(data.downSample(data.mapDimension(valueAxis.dim), 1 / rate, sampler, indexSampler));
2925
+ }
2926
+ }
2927
+ }
2928
+ }
2929
+ };
2930
+ }
2931
+
2932
+ var BaseBarSeriesModel =
2933
+ /** @class */
2934
+ function (_super) {
2935
+ __extends(BaseBarSeriesModel, _super);
2936
+
2937
+ function BaseBarSeriesModel() {
2938
+ var _this = _super !== null && _super.apply(this, arguments) || this;
2939
+
2940
+ _this.type = BaseBarSeriesModel.type;
2941
+ return _this;
2942
+ }
2943
+
2944
+ BaseBarSeriesModel.prototype.getInitialData = function (option, ecModel) {
2945
+ return createSeriesData(null, this, {
2946
+ useEncodeDefaulter: true
2947
+ });
2948
+ };
2949
+
2950
+ BaseBarSeriesModel.prototype.getMarkerPosition = function (value, dims, startingAtTick) {
2951
+ var coordSys = this.coordinateSystem;
2952
+
2953
+ if (coordSys && coordSys.clampData) {
2954
+ // PENDING if clamp ?
2955
+ var pt_1 = coordSys.dataToPoint(coordSys.clampData(value));
2956
+
2957
+ if (startingAtTick) {
2958
+ each(coordSys.getAxes(), function (axis, idx) {
2959
+ // If axis type is category, use tick coords instead
2960
+ if (axis.type === 'category') {
2961
+ var tickCoords = axis.getTicksCoords();
2962
+ var tickIdx = coordSys.clampData(value)[idx]; // The index of rightmost tick of markArea is 1 larger than x1/y1 index
2963
+
2964
+ if (dims && (dims[idx] === 'x1' || dims[idx] === 'y1')) {
2965
+ tickIdx += 1;
2966
+ }
2967
+
2968
+ tickIdx > tickCoords.length - 1 && (tickIdx = tickCoords.length - 1);
2969
+ tickIdx < 0 && (tickIdx = 0);
2970
+ tickCoords[tickIdx] && (pt_1[idx] = axis.toGlobalCoord(tickCoords[tickIdx].coord));
2971
+ }
2972
+ });
2973
+ } else {
2974
+ var data = this.getData();
2975
+ var offset = data.getLayout('offset');
2976
+ var size = data.getLayout('size');
2977
+ var offsetIndex = coordSys.getBaseAxis().isHorizontal() ? 0 : 1;
2978
+ pt_1[offsetIndex] += offset + size / 2;
2979
+ }
2980
+
2981
+ return pt_1;
2982
+ }
2983
+
2984
+ return [NaN, NaN];
2985
+ };
2986
+
2987
+ BaseBarSeriesModel.type = 'series.__base_bar__';
2988
+ BaseBarSeriesModel.defaultOption = {
2989
+ // zlevel: 0,
2990
+ z: 2,
2991
+ coordinateSystem: 'cartesian2d',
2992
+ legendHoverLink: true,
2993
+ // stack: null
2994
+ // Cartesian coordinate system
2995
+ // xAxisIndex: 0,
2996
+ // yAxisIndex: 0,
2997
+ barMinHeight: 0,
2998
+ barMinAngle: 0,
2999
+ // cursor: null,
3000
+ large: false,
3001
+ largeThreshold: 400,
3002
+ progressive: 3e3,
3003
+ progressiveChunkMode: 'mod'
3004
+ };
3005
+ return BaseBarSeriesModel;
3006
+ }(SeriesModel);
3007
+
3008
+ SeriesModel.registerClass(BaseBarSeriesModel);
3009
+
3010
+ var BarSeriesModel =
3011
+ /** @class */
3012
+ function (_super) {
3013
+ __extends(BarSeriesModel, _super);
3014
+
3015
+ function BarSeriesModel() {
3016
+ var _this = _super !== null && _super.apply(this, arguments) || this;
3017
+
3018
+ _this.type = BarSeriesModel.type;
3019
+ return _this;
3020
+ }
3021
+
3022
+ BarSeriesModel.prototype.getInitialData = function () {
3023
+ return createSeriesData(null, this, {
3024
+ useEncodeDefaulter: true,
3025
+ createInvertedIndices: !!this.get('realtimeSort', true) || null
3026
+ });
3027
+ };
3028
+ /**
3029
+ * @override
3030
+ */
3031
+
3032
+
3033
+ BarSeriesModel.prototype.getProgressive = function () {
3034
+ // Do not support progressive in normal mode.
3035
+ return this.get('large') ? this.get('progressive') : false;
3036
+ };
3037
+ /**
3038
+ * @override
3039
+ */
3040
+
3041
+
3042
+ BarSeriesModel.prototype.getProgressiveThreshold = function () {
3043
+ // Do not support progressive in normal mode.
3044
+ var progressiveThreshold = this.get('progressiveThreshold');
3045
+ var largeThreshold = this.get('largeThreshold');
3046
+
3047
+ if (largeThreshold > progressiveThreshold) {
3048
+ progressiveThreshold = largeThreshold;
3049
+ }
3050
+
3051
+ return progressiveThreshold;
3052
+ };
3053
+
3054
+ BarSeriesModel.prototype.brushSelector = function (dataIndex, data, selectors) {
3055
+ return selectors.rect(data.getItemLayout(dataIndex));
3056
+ };
3057
+
3058
+ BarSeriesModel.type = 'series.bar';
3059
+ BarSeriesModel.dependencies = ['grid', 'polar'];
3060
+ BarSeriesModel.defaultOption = inheritDefaultOption(BaseBarSeriesModel.defaultOption, {
3061
+ // If clipped
3062
+ // Only available on cartesian2d
3063
+ clip: true,
3064
+ roundCap: false,
3065
+ showBackground: false,
3066
+ backgroundStyle: {
3067
+ color: 'rgba(180, 180, 180, 0.2)',
3068
+ borderColor: null,
3069
+ borderWidth: 0,
3070
+ borderType: 'solid',
3071
+ borderRadius: 0,
3072
+ shadowBlur: 0,
3073
+ shadowColor: null,
3074
+ shadowOffsetX: 0,
3075
+ shadowOffsetY: 0,
3076
+ opacity: 1
3077
+ },
3078
+ select: {
3079
+ itemStyle: {
3080
+ borderColor: '#212121'
3081
+ }
3082
+ },
3083
+ realtimeSort: false
3084
+ });
3085
+ return BarSeriesModel;
3086
+ }(BaseBarSeriesModel);
3087
+
3088
+ /**
3089
+ * Sausage: similar to sector, but have half circle on both sides
3090
+ */
3091
+
3092
+ var SausageShape =
3093
+ /** @class */
3094
+ function () {
3095
+ function SausageShape() {
3096
+ this.cx = 0;
3097
+ this.cy = 0;
3098
+ this.r0 = 0;
3099
+ this.r = 0;
3100
+ this.startAngle = 0;
3101
+ this.endAngle = Math.PI * 2;
3102
+ this.clockwise = true;
3103
+ }
3104
+
3105
+ return SausageShape;
3106
+ }();
3107
+
3108
+ var SausagePath =
3109
+ /** @class */
3110
+ function (_super) {
3111
+ __extends(SausagePath, _super);
3112
+
3113
+ function SausagePath(opts) {
3114
+ var _this = _super.call(this, opts) || this;
3115
+
3116
+ _this.type = 'sausage';
3117
+ return _this;
3118
+ }
3119
+
3120
+ SausagePath.prototype.getDefaultShape = function () {
3121
+ return new SausageShape();
3122
+ };
3123
+
3124
+ SausagePath.prototype.buildPath = function (ctx, shape) {
3125
+ var cx = shape.cx;
3126
+ var cy = shape.cy;
3127
+ var r0 = Math.max(shape.r0 || 0, 0);
3128
+ var r = Math.max(shape.r, 0);
3129
+ var dr = (r - r0) * 0.5;
3130
+ var rCenter = r0 + dr;
3131
+ var startAngle = shape.startAngle;
3132
+ var endAngle = shape.endAngle;
3133
+ var clockwise = shape.clockwise;
3134
+ var PI2 = Math.PI * 2;
3135
+ var lessThanCircle = clockwise ? endAngle - startAngle < PI2 : startAngle - endAngle < PI2;
3136
+
3137
+ if (!lessThanCircle) {
3138
+ // Normalize angles
3139
+ startAngle = endAngle - (clockwise ? PI2 : -PI2);
3140
+ }
3141
+
3142
+ var unitStartX = Math.cos(startAngle);
3143
+ var unitStartY = Math.sin(startAngle);
3144
+ var unitEndX = Math.cos(endAngle);
3145
+ var unitEndY = Math.sin(endAngle);
3146
+
3147
+ if (lessThanCircle) {
3148
+ ctx.moveTo(unitStartX * r0 + cx, unitStartY * r0 + cy);
3149
+ ctx.arc(unitStartX * rCenter + cx, unitStartY * rCenter + cy, dr, -Math.PI + startAngle, startAngle, !clockwise);
3150
+ } else {
3151
+ ctx.moveTo(unitStartX * r + cx, unitStartY * r + cy);
3152
+ }
3153
+
3154
+ ctx.arc(cx, cy, r, startAngle, endAngle, !clockwise);
3155
+ ctx.arc(unitEndX * rCenter + cx, unitEndY * rCenter + cy, dr, endAngle - Math.PI * 2, endAngle - Math.PI, !clockwise);
3156
+
3157
+ if (r0 !== 0) {
3158
+ ctx.arc(cx, cy, r0, endAngle, startAngle, clockwise);
3159
+ } // ctx.closePath();
3160
+
3161
+ };
3162
+
3163
+ return SausagePath;
3164
+ }(Path);
3165
+
3166
+ function createSectorCalculateTextPosition(positionMapping, opts) {
3167
+ opts = opts || {};
3168
+ var isRoundCap = opts.isRoundCap;
3169
+ return function (out, opts, boundingRect) {
3170
+ var textPosition = opts.position;
3171
+
3172
+ if (!textPosition || textPosition instanceof Array) {
3173
+ return calculateTextPosition(out, opts, boundingRect);
3174
+ }
3175
+
3176
+ var mappedSectorPosition = positionMapping(textPosition);
3177
+ var distance = opts.distance != null ? opts.distance : 5;
3178
+ var sector = this.shape;
3179
+ var cx = sector.cx;
3180
+ var cy = sector.cy;
3181
+ var r = sector.r;
3182
+ var r0 = sector.r0;
3183
+ var middleR = (r + r0) / 2;
3184
+ var startAngle = sector.startAngle;
3185
+ var endAngle = sector.endAngle;
3186
+ var middleAngle = (startAngle + endAngle) / 2;
3187
+ var extraDist = isRoundCap ? Math.abs(r - r0) / 2 : 0;
3188
+ var mathCos = Math.cos;
3189
+ var mathSin = Math.sin; // base position: top-left
3190
+
3191
+ var x = cx + r * mathCos(startAngle);
3192
+ var y = cy + r * mathSin(startAngle);
3193
+ var textAlign = 'left';
3194
+ var textVerticalAlign = 'top';
3195
+
3196
+ switch (mappedSectorPosition) {
3197
+ case 'startArc':
3198
+ x = cx + (r0 - distance) * mathCos(middleAngle);
3199
+ y = cy + (r0 - distance) * mathSin(middleAngle);
3200
+ textAlign = 'center';
3201
+ textVerticalAlign = 'top';
3202
+ break;
3203
+
3204
+ case 'insideStartArc':
3205
+ x = cx + (r0 + distance) * mathCos(middleAngle);
3206
+ y = cy + (r0 + distance) * mathSin(middleAngle);
3207
+ textAlign = 'center';
3208
+ textVerticalAlign = 'bottom';
3209
+ break;
3210
+
3211
+ case 'startAngle':
3212
+ x = cx + middleR * mathCos(startAngle) + adjustAngleDistanceX(startAngle, distance + extraDist, false);
3213
+ y = cy + middleR * mathSin(startAngle) + adjustAngleDistanceY(startAngle, distance + extraDist, false);
3214
+ textAlign = 'right';
3215
+ textVerticalAlign = 'middle';
3216
+ break;
3217
+
3218
+ case 'insideStartAngle':
3219
+ x = cx + middleR * mathCos(startAngle) + adjustAngleDistanceX(startAngle, -distance + extraDist, false);
3220
+ y = cy + middleR * mathSin(startAngle) + adjustAngleDistanceY(startAngle, -distance + extraDist, false);
3221
+ textAlign = 'left';
3222
+ textVerticalAlign = 'middle';
3223
+ break;
3224
+
3225
+ case 'middle':
3226
+ x = cx + middleR * mathCos(middleAngle);
3227
+ y = cy + middleR * mathSin(middleAngle);
3228
+ textAlign = 'center';
3229
+ textVerticalAlign = 'middle';
3230
+ break;
3231
+
3232
+ case 'endArc':
3233
+ x = cx + (r + distance) * mathCos(middleAngle);
3234
+ y = cy + (r + distance) * mathSin(middleAngle);
3235
+ textAlign = 'center';
3236
+ textVerticalAlign = 'bottom';
3237
+ break;
3238
+
3239
+ case 'insideEndArc':
3240
+ x = cx + (r - distance) * mathCos(middleAngle);
3241
+ y = cy + (r - distance) * mathSin(middleAngle);
3242
+ textAlign = 'center';
3243
+ textVerticalAlign = 'top';
3244
+ break;
3245
+
3246
+ case 'endAngle':
3247
+ x = cx + middleR * mathCos(endAngle) + adjustAngleDistanceX(endAngle, distance + extraDist, true);
3248
+ y = cy + middleR * mathSin(endAngle) + adjustAngleDistanceY(endAngle, distance + extraDist, true);
3249
+ textAlign = 'left';
3250
+ textVerticalAlign = 'middle';
3251
+ break;
3252
+
3253
+ case 'insideEndAngle':
3254
+ x = cx + middleR * mathCos(endAngle) + adjustAngleDistanceX(endAngle, -distance + extraDist, true);
3255
+ y = cy + middleR * mathSin(endAngle) + adjustAngleDistanceY(endAngle, -distance + extraDist, true);
3256
+ textAlign = 'right';
3257
+ textVerticalAlign = 'middle';
3258
+ break;
3259
+
3260
+ default:
3261
+ return calculateTextPosition(out, opts, boundingRect);
3262
+ }
3263
+
3264
+ out = out || {};
3265
+ out.x = x;
3266
+ out.y = y;
3267
+ out.align = textAlign;
3268
+ out.verticalAlign = textVerticalAlign;
3269
+ return out;
3270
+ };
3271
+ }
3272
+ function setSectorTextRotation(sector, textPosition, positionMapping, rotateType) {
3273
+ if (isNumber(rotateType)) {
3274
+ // user-set rotation
3275
+ sector.setTextConfig({
3276
+ rotation: rotateType
3277
+ });
3278
+ return;
3279
+ } else if (isArray(textPosition)) {
3280
+ // user-set position, use 0 as auto rotation
3281
+ sector.setTextConfig({
3282
+ rotation: 0
3283
+ });
3284
+ return;
3285
+ }
3286
+
3287
+ var shape = sector.shape;
3288
+ var startAngle = shape.clockwise ? shape.startAngle : shape.endAngle;
3289
+ var endAngle = shape.clockwise ? shape.endAngle : shape.startAngle;
3290
+ var middleAngle = (startAngle + endAngle) / 2;
3291
+ var anchorAngle;
3292
+ var mappedSectorPosition = positionMapping(textPosition);
3293
+
3294
+ switch (mappedSectorPosition) {
3295
+ case 'startArc':
3296
+ case 'insideStartArc':
3297
+ case 'middle':
3298
+ case 'insideEndArc':
3299
+ case 'endArc':
3300
+ anchorAngle = middleAngle;
3301
+ break;
3302
+
3303
+ case 'startAngle':
3304
+ case 'insideStartAngle':
3305
+ anchorAngle = startAngle;
3306
+ break;
3307
+
3308
+ case 'endAngle':
3309
+ case 'insideEndAngle':
3310
+ anchorAngle = endAngle;
3311
+ break;
3312
+
3313
+ default:
3314
+ sector.setTextConfig({
3315
+ rotation: 0
3316
+ });
3317
+ return;
3318
+ }
3319
+
3320
+ var rotate = Math.PI * 1.5 - anchorAngle;
3321
+ /**
3322
+ * TODO: labels with rotate > Math.PI / 2 should be rotate another
3323
+ * half round flipped to increase readability. However, only middle
3324
+ * position supports this for now, because in other positions, the
3325
+ * anchor point is not at the center of the text, so the positions
3326
+ * after rotating is not as expected.
3327
+ */
3328
+
3329
+ if (mappedSectorPosition === 'middle' && rotate > Math.PI / 2 && rotate < Math.PI * 1.5) {
3330
+ rotate -= Math.PI;
3331
+ }
3332
+
3333
+ sector.setTextConfig({
3334
+ rotation: rotate
3335
+ });
3336
+ }
3337
+
3338
+ function adjustAngleDistanceX(angle, distance, isEnd) {
3339
+ return distance * Math.sin(angle) * (isEnd ? -1 : 1);
3340
+ }
3341
+
3342
+ function adjustAngleDistanceY(angle, distance, isEnd) {
3343
+ return distance * Math.cos(angle) * (isEnd ? 1 : -1);
3344
+ }
3345
+
3346
+ var mathMax = Math.max;
3347
+ var mathMin = Math.min;
3348
+
3349
+ function getClipArea(coord, data) {
3350
+ var coordSysClipArea = coord.getArea && coord.getArea();
3351
+
3352
+ if (isCoordinateSystemType(coord, 'cartesian2d')) {
3353
+ var baseAxis = coord.getBaseAxis(); // When boundaryGap is false or using time axis. bar may exceed the grid.
3354
+ // We should not clip this part.
3355
+ // See test/bar2.html
3356
+
3357
+ if (baseAxis.type !== 'category' || !baseAxis.onBand) {
3358
+ var expandWidth = data.getLayout('bandWidth');
3359
+
3360
+ if (baseAxis.isHorizontal()) {
3361
+ coordSysClipArea.x -= expandWidth;
3362
+ coordSysClipArea.width += expandWidth * 2;
3363
+ } else {
3364
+ coordSysClipArea.y -= expandWidth;
3365
+ coordSysClipArea.height += expandWidth * 2;
3366
+ }
3367
+ }
3368
+ }
3369
+
3370
+ return coordSysClipArea;
3371
+ }
3372
+
3373
+ var BarView =
3374
+ /** @class */
3375
+ function (_super) {
3376
+ __extends(BarView, _super);
3377
+
3378
+ function BarView() {
3379
+ var _this = _super.call(this) || this;
3380
+
3381
+ _this.type = BarView.type;
3382
+ _this._isFirstFrame = true;
3383
+ return _this;
3384
+ }
3385
+
3386
+ BarView.prototype.render = function (seriesModel, ecModel, api, payload) {
3387
+ this._model = seriesModel;
3388
+
3389
+ this._removeOnRenderedListener(api);
3390
+
3391
+ this._updateDrawMode(seriesModel);
3392
+
3393
+ var coordinateSystemType = seriesModel.get('coordinateSystem');
3394
+
3395
+ if (coordinateSystemType === 'cartesian2d' || coordinateSystemType === 'polar') {
3396
+ // Clear previously rendered progressive elements.
3397
+ this._progressiveEls = null;
3398
+ this._isLargeDraw ? this._renderLarge(seriesModel, ecModel, api) : this._renderNormal(seriesModel, ecModel, api, payload);
3399
+ }
3400
+ };
3401
+
3402
+ BarView.prototype.incrementalPrepareRender = function (seriesModel) {
3403
+ this._clear();
3404
+
3405
+ this._updateDrawMode(seriesModel); // incremental also need to clip, otherwise might be overlow.
3406
+ // But must not set clip in each frame, otherwise all of the children will be marked redraw.
3407
+
3408
+
3409
+ this._updateLargeClip(seriesModel);
3410
+ };
3411
+
3412
+ BarView.prototype.incrementalRender = function (params, seriesModel) {
3413
+ // Reset
3414
+ this._progressiveEls = []; // Do not support progressive in normal mode.
3415
+
3416
+ this._incrementalRenderLarge(params, seriesModel);
3417
+ };
3418
+
3419
+ BarView.prototype.eachRendered = function (cb) {
3420
+ traverseElements(this._progressiveEls || this.group, cb);
3421
+ };
3422
+
3423
+ BarView.prototype._updateDrawMode = function (seriesModel) {
3424
+ var isLargeDraw = seriesModel.pipelineContext.large;
3425
+
3426
+ if (this._isLargeDraw == null || isLargeDraw !== this._isLargeDraw) {
3427
+ this._isLargeDraw = isLargeDraw;
3428
+
3429
+ this._clear();
3430
+ }
3431
+ };
3432
+
3433
+ BarView.prototype._renderNormal = function (seriesModel, ecModel, api, payload) {
3434
+ var group = this.group;
3435
+ var data = seriesModel.getData();
3436
+ var oldData = this._data;
3437
+ var coord = seriesModel.coordinateSystem;
3438
+ var baseAxis = coord.getBaseAxis();
3439
+ var isHorizontalOrRadial;
3440
+
3441
+ if (coord.type === 'cartesian2d') {
3442
+ isHorizontalOrRadial = baseAxis.isHorizontal();
3443
+ } else if (coord.type === 'polar') {
3444
+ isHorizontalOrRadial = baseAxis.dim === 'angle';
3445
+ }
3446
+
3447
+ var animationModel = seriesModel.isAnimationEnabled() ? seriesModel : null;
3448
+ var realtimeSortCfg = shouldRealtimeSort(seriesModel, coord);
3449
+
3450
+ if (realtimeSortCfg) {
3451
+ this._enableRealtimeSort(realtimeSortCfg, data, api);
3452
+ }
3453
+
3454
+ var needsClip = seriesModel.get('clip', true) || realtimeSortCfg;
3455
+ var coordSysClipArea = getClipArea(coord, data); // If there is clipPath created in large mode. Remove it.
3456
+
3457
+ group.removeClipPath(); // We don't use clipPath in normal mode because we needs a perfect animation
3458
+ // And don't want the label are clipped.
3459
+
3460
+ var roundCap = seriesModel.get('roundCap', true);
3461
+ var drawBackground = seriesModel.get('showBackground', true);
3462
+ var backgroundModel = seriesModel.getModel('backgroundStyle');
3463
+ var barBorderRadius = backgroundModel.get('borderRadius') || 0;
3464
+ var bgEls = [];
3465
+ var oldBgEls = this._backgroundEls;
3466
+ var isInitSort = payload && payload.isInitSort;
3467
+ var isChangeOrder = payload && payload.type === 'changeAxisOrder';
3468
+
3469
+ function createBackground(dataIndex) {
3470
+ var bgLayout = getLayout[coord.type](data, dataIndex);
3471
+ var bgEl = createBackgroundEl(coord, isHorizontalOrRadial, bgLayout);
3472
+ bgEl.useStyle(backgroundModel.getItemStyle()); // Only cartesian2d support borderRadius.
3473
+
3474
+ if (coord.type === 'cartesian2d') {
3475
+ bgEl.setShape('r', barBorderRadius);
3476
+ }
3477
+
3478
+ bgEls[dataIndex] = bgEl;
3479
+ return bgEl;
3480
+ }
3481
+ data.diff(oldData).add(function (dataIndex) {
3482
+ var itemModel = data.getItemModel(dataIndex);
3483
+ var layout = getLayout[coord.type](data, dataIndex, itemModel);
3484
+
3485
+ if (drawBackground) {
3486
+ createBackground(dataIndex);
3487
+ } // If dataZoom in filteMode: 'empty', the baseValue can be set as NaN in "axisProxy".
3488
+
3489
+
3490
+ if (!data.hasValue(dataIndex) || !isValidLayout[coord.type](layout)) {
3491
+ return;
3492
+ }
3493
+
3494
+ var isClipped = false;
3495
+
3496
+ if (needsClip) {
3497
+ // Clip will modify the layout params.
3498
+ // And return a boolean to determine if the shape are fully clipped.
3499
+ isClipped = clip[coord.type](coordSysClipArea, layout);
3500
+ }
3501
+
3502
+ var el = elementCreator[coord.type](seriesModel, data, dataIndex, layout, isHorizontalOrRadial, animationModel, baseAxis.model, false, roundCap);
3503
+
3504
+ if (realtimeSortCfg) {
3505
+ /**
3506
+ * Force label animation because even if the element is
3507
+ * ignored because it's clipped, it may not be clipped after
3508
+ * changing order. Then, if not using forceLabelAnimation,
3509
+ * the label animation was never started, in which case,
3510
+ * the label will be the final value and doesn't have label
3511
+ * animation.
3512
+ */
3513
+ el.forceLabelAnimation = true;
3514
+ }
3515
+
3516
+ updateStyle(el, data, dataIndex, itemModel, layout, seriesModel, isHorizontalOrRadial, coord.type === 'polar');
3517
+
3518
+ if (isInitSort) {
3519
+ el.attr({
3520
+ shape: layout
3521
+ });
3522
+ } else if (realtimeSortCfg) {
3523
+ updateRealtimeAnimation(realtimeSortCfg, animationModel, el, layout, dataIndex, isHorizontalOrRadial, false, false);
3524
+ } else {
3525
+ initProps(el, {
3526
+ shape: layout
3527
+ }, seriesModel, dataIndex);
3528
+ }
3529
+
3530
+ data.setItemGraphicEl(dataIndex, el);
3531
+ group.add(el);
3532
+ el.ignore = isClipped;
3533
+ }).update(function (newIndex, oldIndex) {
3534
+ var itemModel = data.getItemModel(newIndex);
3535
+ var layout = getLayout[coord.type](data, newIndex, itemModel);
3536
+
3537
+ if (drawBackground) {
3538
+ var bgEl = void 0;
3539
+
3540
+ if (oldBgEls.length === 0) {
3541
+ bgEl = createBackground(oldIndex);
3542
+ } else {
3543
+ bgEl = oldBgEls[oldIndex];
3544
+ bgEl.useStyle(backgroundModel.getItemStyle()); // Only cartesian2d support borderRadius.
3545
+
3546
+ if (coord.type === 'cartesian2d') {
3547
+ bgEl.setShape('r', barBorderRadius);
3548
+ }
3549
+
3550
+ bgEls[newIndex] = bgEl;
3551
+ }
3552
+
3553
+ var bgLayout = getLayout[coord.type](data, newIndex);
3554
+ var shape = createBackgroundShape(isHorizontalOrRadial, bgLayout, coord);
3555
+ updateProps(bgEl, {
3556
+ shape: shape
3557
+ }, animationModel, newIndex);
3558
+ }
3559
+
3560
+ var el = oldData.getItemGraphicEl(oldIndex);
3561
+
3562
+ if (!data.hasValue(newIndex) || !isValidLayout[coord.type](layout)) {
3563
+ group.remove(el);
3564
+ return;
3565
+ }
3566
+
3567
+ var isClipped = false;
3568
+
3569
+ if (needsClip) {
3570
+ isClipped = clip[coord.type](coordSysClipArea, layout);
3571
+
3572
+ if (isClipped) {
3573
+ group.remove(el);
3574
+ }
3575
+ }
3576
+
3577
+ if (!el) {
3578
+ el = elementCreator[coord.type](seriesModel, data, newIndex, layout, isHorizontalOrRadial, animationModel, baseAxis.model, !!el, roundCap);
3579
+ } else {
3580
+ saveOldStyle(el);
3581
+ }
3582
+
3583
+ if (realtimeSortCfg) {
3584
+ el.forceLabelAnimation = true;
3585
+ }
3586
+
3587
+ if (isChangeOrder) {
3588
+ var textEl = el.getTextContent();
3589
+
3590
+ if (textEl) {
3591
+ var labelInnerStore = labelInner(textEl);
3592
+
3593
+ if (labelInnerStore.prevValue != null) {
3594
+ /**
3595
+ * Set preValue to be value so that no new label
3596
+ * should be started, otherwise, it will take a full
3597
+ * `animationDurationUpdate` time to finish the
3598
+ * animation, which is not expected.
3599
+ */
3600
+ labelInnerStore.prevValue = labelInnerStore.value;
3601
+ }
3602
+ }
3603
+ } // Not change anything if only order changed.
3604
+ // Especially not change label.
3605
+ else {
3606
+ updateStyle(el, data, newIndex, itemModel, layout, seriesModel, isHorizontalOrRadial, coord.type === 'polar');
3607
+ }
3608
+
3609
+ if (isInitSort) {
3610
+ el.attr({
3611
+ shape: layout
3612
+ });
3613
+ } else if (realtimeSortCfg) {
3614
+ updateRealtimeAnimation(realtimeSortCfg, animationModel, el, layout, newIndex, isHorizontalOrRadial, true, isChangeOrder);
3615
+ } else {
3616
+ updateProps(el, {
3617
+ shape: layout
3618
+ }, seriesModel, newIndex, null);
3619
+ }
3620
+
3621
+ data.setItemGraphicEl(newIndex, el);
3622
+ el.ignore = isClipped;
3623
+ group.add(el);
3624
+ }).remove(function (dataIndex) {
3625
+ var el = oldData.getItemGraphicEl(dataIndex);
3626
+ el && removeElementWithFadeOut(el, seriesModel, dataIndex);
3627
+ }).execute();
3628
+ var bgGroup = this._backgroundGroup || (this._backgroundGroup = new Group());
3629
+ bgGroup.removeAll();
3630
+
3631
+ for (var i = 0; i < bgEls.length; ++i) {
3632
+ bgGroup.add(bgEls[i]);
3633
+ }
3634
+
3635
+ group.add(bgGroup);
3636
+ this._backgroundEls = bgEls;
3637
+ this._data = data;
3638
+ };
3639
+
3640
+ BarView.prototype._renderLarge = function (seriesModel, ecModel, api) {
3641
+ this._clear();
3642
+
3643
+ createLarge(seriesModel, this.group);
3644
+
3645
+ this._updateLargeClip(seriesModel);
3646
+ };
3647
+
3648
+ BarView.prototype._incrementalRenderLarge = function (params, seriesModel) {
3649
+ this._removeBackground();
3650
+
3651
+ createLarge(seriesModel, this.group, this._progressiveEls, true);
3652
+ };
3653
+
3654
+ BarView.prototype._updateLargeClip = function (seriesModel) {
3655
+ // Use clipPath in large mode.
3656
+ var clipPath = seriesModel.get('clip', true) && createClipPath(seriesModel.coordinateSystem, false, seriesModel);
3657
+ var group = this.group;
3658
+
3659
+ if (clipPath) {
3660
+ group.setClipPath(clipPath);
3661
+ } else {
3662
+ group.removeClipPath();
3663
+ }
3664
+ };
3665
+
3666
+ BarView.prototype._enableRealtimeSort = function (realtimeSortCfg, data, api) {
3667
+ var _this = this; // If no data in the first frame, wait for data to initSort
3668
+
3669
+
3670
+ if (!data.count()) {
3671
+ return;
3672
+ }
3673
+
3674
+ var baseAxis = realtimeSortCfg.baseAxis;
3675
+
3676
+ if (this._isFirstFrame) {
3677
+ this._dispatchInitSort(data, realtimeSortCfg, api);
3678
+
3679
+ this._isFirstFrame = false;
3680
+ } else {
3681
+ var orderMapping_1 = function (idx) {
3682
+ var el = data.getItemGraphicEl(idx);
3683
+ var shape = el && el.shape;
3684
+ return shape && // The result should be consistent with the initial sort by data value.
3685
+ // Do not support the case that both positive and negative exist.
3686
+ Math.abs(baseAxis.isHorizontal() ? shape.height : shape.width) // If data is NaN, shape.xxx may be NaN, so use || 0 here in case
3687
+ || 0;
3688
+ };
3689
+
3690
+ this._onRendered = function () {
3691
+ _this._updateSortWithinSameData(data, orderMapping_1, baseAxis, api);
3692
+ };
3693
+
3694
+ api.getZr().on('rendered', this._onRendered);
3695
+ }
3696
+ };
3697
+
3698
+ BarView.prototype._dataSort = function (data, baseAxis, orderMapping) {
3699
+ var info = [];
3700
+ data.each(data.mapDimension(baseAxis.dim), function (ordinalNumber, dataIdx) {
3701
+ var mappedValue = orderMapping(dataIdx);
3702
+ mappedValue = mappedValue == null ? NaN : mappedValue;
3703
+ info.push({
3704
+ dataIndex: dataIdx,
3705
+ mappedValue: mappedValue,
3706
+ ordinalNumber: ordinalNumber
3707
+ });
3708
+ });
3709
+ info.sort(function (a, b) {
3710
+ // If NaN, it will be treated as min val.
3711
+ return b.mappedValue - a.mappedValue;
3712
+ });
3713
+ return {
3714
+ ordinalNumbers: map(info, function (item) {
3715
+ return item.ordinalNumber;
3716
+ })
3717
+ };
3718
+ };
3719
+
3720
+ BarView.prototype._isOrderChangedWithinSameData = function (data, orderMapping, baseAxis) {
3721
+ var scale = baseAxis.scale;
3722
+ var ordinalDataDim = data.mapDimension(baseAxis.dim);
3723
+ var lastValue = Number.MAX_VALUE;
3724
+
3725
+ for (var tickNum = 0, len = scale.getOrdinalMeta().categories.length; tickNum < len; ++tickNum) {
3726
+ var rawIdx = data.rawIndexOf(ordinalDataDim, scale.getRawOrdinalNumber(tickNum));
3727
+ var value = rawIdx < 0 // If some tick have no bar, the tick will be treated as min.
3728
+ ? Number.MIN_VALUE // PENDING: if dataZoom on baseAxis exits, is it a performance issue?
3729
+ : orderMapping(data.indexOfRawIndex(rawIdx));
3730
+
3731
+ if (value > lastValue) {
3732
+ return true;
3733
+ }
3734
+
3735
+ lastValue = value;
3736
+ }
3737
+
3738
+ return false;
3739
+ };
3740
+ /*
3741
+ * Consider the case when A and B changed order, whose representing
3742
+ * bars are both out of sight, we don't wish to trigger reorder action
3743
+ * as long as the order in the view doesn't change.
3744
+ */
3745
+
3746
+
3747
+ BarView.prototype._isOrderDifferentInView = function (orderInfo, baseAxis) {
3748
+ var scale = baseAxis.scale;
3749
+ var extent = scale.getExtent();
3750
+ var tickNum = Math.max(0, extent[0]);
3751
+ var tickMax = Math.min(extent[1], scale.getOrdinalMeta().categories.length - 1);
3752
+
3753
+ for (; tickNum <= tickMax; ++tickNum) {
3754
+ if (orderInfo.ordinalNumbers[tickNum] !== scale.getRawOrdinalNumber(tickNum)) {
3755
+ return true;
3756
+ }
3757
+ }
3758
+ };
3759
+
3760
+ BarView.prototype._updateSortWithinSameData = function (data, orderMapping, baseAxis, api) {
3761
+ if (!this._isOrderChangedWithinSameData(data, orderMapping, baseAxis)) {
3762
+ return;
3763
+ }
3764
+
3765
+ var sortInfo = this._dataSort(data, baseAxis, orderMapping);
3766
+
3767
+ if (this._isOrderDifferentInView(sortInfo, baseAxis)) {
3768
+ this._removeOnRenderedListener(api);
3769
+
3770
+ api.dispatchAction({
3771
+ type: 'changeAxisOrder',
3772
+ componentType: baseAxis.dim + 'Axis',
3773
+ axisId: baseAxis.index,
3774
+ sortInfo: sortInfo
3775
+ });
3776
+ }
3777
+ };
3778
+
3779
+ BarView.prototype._dispatchInitSort = function (data, realtimeSortCfg, api) {
3780
+ var baseAxis = realtimeSortCfg.baseAxis;
3781
+
3782
+ var sortResult = this._dataSort(data, baseAxis, function (dataIdx) {
3783
+ return data.get(data.mapDimension(realtimeSortCfg.otherAxis.dim), dataIdx);
3784
+ });
3785
+
3786
+ api.dispatchAction({
3787
+ type: 'changeAxisOrder',
3788
+ componentType: baseAxis.dim + 'Axis',
3789
+ isInitSort: true,
3790
+ axisId: baseAxis.index,
3791
+ sortInfo: sortResult
3792
+ });
3793
+ };
3794
+
3795
+ BarView.prototype.remove = function (ecModel, api) {
3796
+ this._clear(this._model);
3797
+
3798
+ this._removeOnRenderedListener(api);
3799
+ };
3800
+
3801
+ BarView.prototype.dispose = function (ecModel, api) {
3802
+ this._removeOnRenderedListener(api);
3803
+ };
3804
+
3805
+ BarView.prototype._removeOnRenderedListener = function (api) {
3806
+ if (this._onRendered) {
3807
+ api.getZr().off('rendered', this._onRendered);
3808
+ this._onRendered = null;
3809
+ }
3810
+ };
3811
+
3812
+ BarView.prototype._clear = function (model) {
3813
+ var group = this.group;
3814
+ var data = this._data;
3815
+
3816
+ if (model && model.isAnimationEnabled() && data && !this._isLargeDraw) {
3817
+ this._removeBackground();
3818
+
3819
+ this._backgroundEls = [];
3820
+ data.eachItemGraphicEl(function (el) {
3821
+ removeElementWithFadeOut(el, model, getECData(el).dataIndex);
3822
+ });
3823
+ } else {
3824
+ group.removeAll();
3825
+ }
3826
+
3827
+ this._data = null;
3828
+ this._isFirstFrame = true;
3829
+ };
3830
+
3831
+ BarView.prototype._removeBackground = function () {
3832
+ this.group.remove(this._backgroundGroup);
3833
+ this._backgroundGroup = null;
3834
+ };
3835
+
3836
+ BarView.type = 'bar';
3837
+ return BarView;
3838
+ }(ChartView);
3839
+
3840
+ var clip = {
3841
+ cartesian2d: function (coordSysBoundingRect, layout) {
3842
+ var signWidth = layout.width < 0 ? -1 : 1;
3843
+ var signHeight = layout.height < 0 ? -1 : 1; // Needs positive width and height
3844
+
3845
+ if (signWidth < 0) {
3846
+ layout.x += layout.width;
3847
+ layout.width = -layout.width;
3848
+ }
3849
+
3850
+ if (signHeight < 0) {
3851
+ layout.y += layout.height;
3852
+ layout.height = -layout.height;
3853
+ }
3854
+
3855
+ var coordSysX2 = coordSysBoundingRect.x + coordSysBoundingRect.width;
3856
+ var coordSysY2 = coordSysBoundingRect.y + coordSysBoundingRect.height;
3857
+ var x = mathMax(layout.x, coordSysBoundingRect.x);
3858
+ var x2 = mathMin(layout.x + layout.width, coordSysX2);
3859
+ var y = mathMax(layout.y, coordSysBoundingRect.y);
3860
+ var y2 = mathMin(layout.y + layout.height, coordSysY2);
3861
+ var xClipped = x2 < x;
3862
+ var yClipped = y2 < y; // When xClipped or yClipped, the element will be marked as `ignore`.
3863
+ // But we should also place the element at the edge of the coord sys bounding rect.
3864
+ // Because if data changed and the bar shows again, its transition animation
3865
+ // will begin at this place.
3866
+
3867
+ layout.x = xClipped && x > coordSysX2 ? x2 : x;
3868
+ layout.y = yClipped && y > coordSysY2 ? y2 : y;
3869
+ layout.width = xClipped ? 0 : x2 - x;
3870
+ layout.height = yClipped ? 0 : y2 - y; // Reverse back
3871
+
3872
+ if (signWidth < 0) {
3873
+ layout.x += layout.width;
3874
+ layout.width = -layout.width;
3875
+ }
3876
+
3877
+ if (signHeight < 0) {
3878
+ layout.y += layout.height;
3879
+ layout.height = -layout.height;
3880
+ }
3881
+
3882
+ return xClipped || yClipped;
3883
+ },
3884
+ polar: function (coordSysClipArea, layout) {
3885
+ var signR = layout.r0 <= layout.r ? 1 : -1; // Make sure r is larger than r0
3886
+
3887
+ if (signR < 0) {
3888
+ var tmp = layout.r;
3889
+ layout.r = layout.r0;
3890
+ layout.r0 = tmp;
3891
+ }
3892
+
3893
+ var r = mathMin(layout.r, coordSysClipArea.r);
3894
+ var r0 = mathMax(layout.r0, coordSysClipArea.r0);
3895
+ layout.r = r;
3896
+ layout.r0 = r0;
3897
+ var clipped = r - r0 < 0; // Reverse back
3898
+
3899
+ if (signR < 0) {
3900
+ var tmp = layout.r;
3901
+ layout.r = layout.r0;
3902
+ layout.r0 = tmp;
3903
+ }
3904
+
3905
+ return clipped;
3906
+ }
3907
+ };
3908
+ var elementCreator = {
3909
+ cartesian2d: function (seriesModel, data, newIndex, layout, isHorizontal, animationModel, axisModel, isUpdate, roundCap) {
3910
+ var rect = new Rect({
3911
+ shape: extend({}, layout),
3912
+ z2: 1
3913
+ });
3914
+ rect.__dataIndex = newIndex;
3915
+ rect.name = 'item';
3916
+
3917
+ if (animationModel) {
3918
+ var rectShape = rect.shape;
3919
+ var animateProperty = isHorizontal ? 'height' : 'width';
3920
+ rectShape[animateProperty] = 0;
3921
+ }
3922
+
3923
+ return rect;
3924
+ },
3925
+ polar: function (seriesModel, data, newIndex, layout, isRadial, animationModel, axisModel, isUpdate, roundCap) {
3926
+ var ShapeClass = !isRadial && roundCap ? SausagePath : Sector;
3927
+ var sector = new ShapeClass({
3928
+ shape: layout,
3929
+ z2: 1
3930
+ });
3931
+ sector.name = 'item';
3932
+ var positionMap = createPolarPositionMapping(isRadial);
3933
+ sector.calculateTextPosition = createSectorCalculateTextPosition(positionMap, {
3934
+ isRoundCap: ShapeClass === SausagePath
3935
+ }); // Animation
3936
+
3937
+ if (animationModel) {
3938
+ var sectorShape = sector.shape;
3939
+ var animateProperty = isRadial ? 'r' : 'endAngle';
3940
+ var animateTarget = {};
3941
+ sectorShape[animateProperty] = isRadial ? 0 : layout.startAngle;
3942
+ animateTarget[animateProperty] = layout[animateProperty];
3943
+ (isUpdate ? updateProps : initProps)(sector, {
3944
+ shape: animateTarget // __value: typeof dataValue === 'string' ? parseInt(dataValue, 10) : dataValue
3945
+
3946
+ }, animationModel);
3947
+ }
3948
+
3949
+ return sector;
3950
+ }
3951
+ };
3952
+
3953
+ function shouldRealtimeSort(seriesModel, coordSys) {
3954
+ var realtimeSortOption = seriesModel.get('realtimeSort', true);
3955
+ var baseAxis = coordSys.getBaseAxis();
3956
+
3957
+ if (realtimeSortOption && baseAxis.type === 'category' && coordSys.type === 'cartesian2d') {
3958
+ return {
3959
+ baseAxis: baseAxis,
3960
+ otherAxis: coordSys.getOtherAxis(baseAxis)
3961
+ };
3962
+ }
3963
+ }
3964
+
3965
+ function updateRealtimeAnimation(realtimeSortCfg, seriesAnimationModel, el, layout, newIndex, isHorizontal, isUpdate, isChangeOrder) {
3966
+ var seriesTarget;
3967
+ var axisTarget;
3968
+
3969
+ if (isHorizontal) {
3970
+ axisTarget = {
3971
+ x: layout.x,
3972
+ width: layout.width
3973
+ };
3974
+ seriesTarget = {
3975
+ y: layout.y,
3976
+ height: layout.height
3977
+ };
3978
+ } else {
3979
+ axisTarget = {
3980
+ y: layout.y,
3981
+ height: layout.height
3982
+ };
3983
+ seriesTarget = {
3984
+ x: layout.x,
3985
+ width: layout.width
3986
+ };
3987
+ }
3988
+
3989
+ if (!isChangeOrder) {
3990
+ // Keep the original growth animation if only axis order changed.
3991
+ // Not start a new animation.
3992
+ (isUpdate ? updateProps : initProps)(el, {
3993
+ shape: seriesTarget
3994
+ }, seriesAnimationModel, newIndex, null);
3995
+ }
3996
+
3997
+ var axisAnimationModel = seriesAnimationModel ? realtimeSortCfg.baseAxis.model : null;
3998
+ (isUpdate ? updateProps : initProps)(el, {
3999
+ shape: axisTarget
4000
+ }, axisAnimationModel, newIndex);
4001
+ }
4002
+
4003
+ function checkPropertiesNotValid(obj, props) {
4004
+ for (var i = 0; i < props.length; i++) {
4005
+ if (!isFinite(obj[props[i]])) {
4006
+ return true;
4007
+ }
4008
+ }
4009
+
4010
+ return false;
4011
+ }
4012
+
4013
+ var rectPropties = ['x', 'y', 'width', 'height'];
4014
+ var polarPropties = ['cx', 'cy', 'r', 'startAngle', 'endAngle'];
4015
+ var isValidLayout = {
4016
+ cartesian2d: function (layout) {
4017
+ return !checkPropertiesNotValid(layout, rectPropties);
4018
+ },
4019
+ polar: function (layout) {
4020
+ return !checkPropertiesNotValid(layout, polarPropties);
4021
+ }
4022
+ };
4023
+ var getLayout = {
4024
+ // itemModel is only used to get borderWidth, which is not needed
4025
+ // when calculating bar background layout.
4026
+ cartesian2d: function (data, dataIndex, itemModel) {
4027
+ var layout = data.getItemLayout(dataIndex);
4028
+ var fixedLineWidth = itemModel ? getLineWidth(itemModel, layout) : 0; // fix layout with lineWidth
4029
+
4030
+ var signX = layout.width > 0 ? 1 : -1;
4031
+ var signY = layout.height > 0 ? 1 : -1;
4032
+ return {
4033
+ x: layout.x + signX * fixedLineWidth / 2,
4034
+ y: layout.y + signY * fixedLineWidth / 2,
4035
+ width: layout.width - signX * fixedLineWidth,
4036
+ height: layout.height - signY * fixedLineWidth
4037
+ };
4038
+ },
4039
+ polar: function (data, dataIndex, itemModel) {
4040
+ var layout = data.getItemLayout(dataIndex);
4041
+ return {
4042
+ cx: layout.cx,
4043
+ cy: layout.cy,
4044
+ r0: layout.r0,
4045
+ r: layout.r,
4046
+ startAngle: layout.startAngle,
4047
+ endAngle: layout.endAngle,
4048
+ clockwise: layout.clockwise
4049
+ };
4050
+ }
4051
+ };
4052
+
4053
+ function isZeroOnPolar(layout) {
4054
+ return layout.startAngle != null && layout.endAngle != null && layout.startAngle === layout.endAngle;
4055
+ }
4056
+
4057
+ function createPolarPositionMapping(isRadial) {
4058
+ return function (isRadial) {
4059
+ var arcOrAngle = isRadial ? 'Arc' : 'Angle';
4060
+ return function (position) {
4061
+ switch (position) {
4062
+ case 'start':
4063
+ case 'insideStart':
4064
+ case 'end':
4065
+ case 'insideEnd':
4066
+ return position + arcOrAngle;
4067
+
4068
+ default:
4069
+ return position;
4070
+ }
4071
+ };
4072
+ }(isRadial);
4073
+ }
4074
+
4075
+ function updateStyle(el, data, dataIndex, itemModel, layout, seriesModel, isHorizontalOrRadial, isPolar) {
4076
+ var style = data.getItemVisual(dataIndex, 'style');
4077
+
4078
+ if (!isPolar) {
4079
+ el.setShape('r', itemModel.get(['itemStyle', 'borderRadius']) || 0);
4080
+ }
4081
+
4082
+ el.useStyle(style);
4083
+ var cursorStyle = itemModel.getShallow('cursor');
4084
+ cursorStyle && el.attr('cursor', cursorStyle);
4085
+ var labelPositionOutside = isPolar ? isHorizontalOrRadial ? layout.r >= layout.r0 ? 'endArc' : 'startArc' : layout.endAngle >= layout.startAngle ? 'endAngle' : 'startAngle' : isHorizontalOrRadial ? layout.height >= 0 ? 'bottom' : 'top' : layout.width >= 0 ? 'right' : 'left';
4086
+ var labelStatesModels = getLabelStatesModels(itemModel);
4087
+ setLabelStyle(el, labelStatesModels, {
4088
+ labelFetcher: seriesModel,
4089
+ labelDataIndex: dataIndex,
4090
+ defaultText: getDefaultLabel(seriesModel.getData(), dataIndex),
4091
+ inheritColor: style.fill,
4092
+ defaultOpacity: style.opacity,
4093
+ defaultOutsidePosition: labelPositionOutside
4094
+ });
4095
+ var label = el.getTextContent();
4096
+
4097
+ if (isPolar && label) {
4098
+ var position = itemModel.get(['label', 'position']);
4099
+ el.textConfig.inside = position === 'middle' ? true : null;
4100
+ setSectorTextRotation(el, position === 'outside' ? labelPositionOutside : position, createPolarPositionMapping(isHorizontalOrRadial), itemModel.get(['label', 'rotate']));
4101
+ }
4102
+
4103
+ setLabelValueAnimation(label, labelStatesModels, seriesModel.getRawValue(dataIndex), function (value) {
4104
+ return getDefaultInterpolatedLabel(data, value);
4105
+ });
4106
+ var emphasisModel = itemModel.getModel(['emphasis']);
4107
+ toggleHoverEmphasis(el, emphasisModel.get('focus'), emphasisModel.get('blurScope'), emphasisModel.get('disabled'));
4108
+ setStatesStylesFromModel(el, itemModel);
4109
+
4110
+ if (isZeroOnPolar(layout)) {
4111
+ el.style.fill = 'none';
4112
+ el.style.stroke = 'none';
4113
+ each(el.states, function (state) {
4114
+ if (state.style) {
4115
+ state.style.fill = state.style.stroke = 'none';
4116
+ }
4117
+ });
4118
+ }
4119
+ } // In case width or height are too small.
4120
+
4121
+
4122
+ function getLineWidth(itemModel, rawLayout) {
4123
+ // Has no border.
4124
+ var borderColor = itemModel.get(['itemStyle', 'borderColor']);
4125
+
4126
+ if (!borderColor || borderColor === 'none') {
4127
+ return 0;
4128
+ }
4129
+
4130
+ var lineWidth = itemModel.get(['itemStyle', 'borderWidth']) || 0; // width or height may be NaN for empty data
4131
+
4132
+ var width = isNaN(rawLayout.width) ? Number.MAX_VALUE : Math.abs(rawLayout.width);
4133
+ var height = isNaN(rawLayout.height) ? Number.MAX_VALUE : Math.abs(rawLayout.height);
4134
+ return Math.min(lineWidth, width, height);
4135
+ }
4136
+
4137
+ var LagePathShape =
4138
+ /** @class */
4139
+ function () {
4140
+ function LagePathShape() {}
4141
+
4142
+ return LagePathShape;
4143
+ }();
4144
+
4145
+ var LargePath =
4146
+ /** @class */
4147
+ function (_super) {
4148
+ __extends(LargePath, _super);
4149
+
4150
+ function LargePath(opts) {
4151
+ var _this = _super.call(this, opts) || this;
4152
+
4153
+ _this.type = 'largeBar';
4154
+ return _this;
4155
+ }
4156
+
4157
+ LargePath.prototype.getDefaultShape = function () {
4158
+ return new LagePathShape();
4159
+ };
4160
+
4161
+ LargePath.prototype.buildPath = function (ctx, shape) {
4162
+ // Drawing lines is more efficient than drawing
4163
+ // a whole line or drawing rects.
4164
+ var points = shape.points;
4165
+ var baseDimIdx = this.baseDimIdx;
4166
+ var valueDimIdx = 1 - this.baseDimIdx;
4167
+ var startPoint = [];
4168
+ var size = [];
4169
+ var barWidth = this.barWidth;
4170
+
4171
+ for (var i = 0; i < points.length; i += 3) {
4172
+ size[baseDimIdx] = barWidth;
4173
+ size[valueDimIdx] = points[i + 2];
4174
+ startPoint[baseDimIdx] = points[i + baseDimIdx];
4175
+ startPoint[valueDimIdx] = points[i + valueDimIdx];
4176
+ ctx.rect(startPoint[0], startPoint[1], size[0], size[1]);
4177
+ }
4178
+ };
4179
+
4180
+ return LargePath;
4181
+ }(Path);
4182
+
4183
+ function createLarge(seriesModel, group, progressiveEls, incremental) {
4184
+ // TODO support polar
4185
+ var data = seriesModel.getData();
4186
+ var baseDimIdx = data.getLayout('valueAxisHorizontal') ? 1 : 0;
4187
+ var largeDataIndices = data.getLayout('largeDataIndices');
4188
+ var barWidth = data.getLayout('size');
4189
+ var backgroundModel = seriesModel.getModel('backgroundStyle');
4190
+ var bgPoints = data.getLayout('largeBackgroundPoints');
4191
+
4192
+ if (bgPoints) {
4193
+ var bgEl = new LargePath({
4194
+ shape: {
4195
+ points: bgPoints
4196
+ },
4197
+ incremental: !!incremental,
4198
+ silent: true,
4199
+ z2: 0
4200
+ });
4201
+ bgEl.baseDimIdx = baseDimIdx;
4202
+ bgEl.largeDataIndices = largeDataIndices;
4203
+ bgEl.barWidth = barWidth;
4204
+ bgEl.useStyle(backgroundModel.getItemStyle());
4205
+ group.add(bgEl);
4206
+ progressiveEls && progressiveEls.push(bgEl);
4207
+ }
4208
+
4209
+ var el = new LargePath({
4210
+ shape: {
4211
+ points: data.getLayout('largePoints')
4212
+ },
4213
+ incremental: !!incremental,
4214
+ ignoreCoarsePointer: true,
4215
+ z2: 1
4216
+ });
4217
+ el.baseDimIdx = baseDimIdx;
4218
+ el.largeDataIndices = largeDataIndices;
4219
+ el.barWidth = barWidth;
4220
+ group.add(el);
4221
+ el.useStyle(data.getVisual('style')); // Enable tooltip and user mouse/touch event handlers.
4222
+
4223
+ getECData(el).seriesIndex = seriesModel.seriesIndex;
4224
+
4225
+ if (!seriesModel.get('silent')) {
4226
+ el.on('mousedown', largePathUpdateDataIndex);
4227
+ el.on('mousemove', largePathUpdateDataIndex);
4228
+ }
4229
+
4230
+ progressiveEls && progressiveEls.push(el);
4231
+ } // Use throttle to avoid frequently traverse to find dataIndex.
4232
+
4233
+
4234
+ var largePathUpdateDataIndex = throttle(function (event) {
4235
+ var largePath = this;
4236
+ var dataIndex = largePathFindDataIndex(largePath, event.offsetX, event.offsetY);
4237
+ getECData(largePath).dataIndex = dataIndex >= 0 ? dataIndex : null;
4238
+ }, 30, false);
4239
+
4240
+ function largePathFindDataIndex(largePath, x, y) {
4241
+ var baseDimIdx = largePath.baseDimIdx;
4242
+ var valueDimIdx = 1 - baseDimIdx;
4243
+ var points = largePath.shape.points;
4244
+ var largeDataIndices = largePath.largeDataIndices;
4245
+ var startPoint = [];
4246
+ var size = [];
4247
+ var barWidth = largePath.barWidth;
4248
+
4249
+ for (var i = 0, len = points.length / 3; i < len; i++) {
4250
+ var ii = i * 3;
4251
+ size[baseDimIdx] = barWidth;
4252
+ size[valueDimIdx] = points[ii + 2];
4253
+ startPoint[baseDimIdx] = points[ii + baseDimIdx];
4254
+ startPoint[valueDimIdx] = points[ii + valueDimIdx];
4255
+
4256
+ if (size[valueDimIdx] < 0) {
4257
+ startPoint[valueDimIdx] += size[valueDimIdx];
4258
+ size[valueDimIdx] = -size[valueDimIdx];
4259
+ }
4260
+
4261
+ if (x >= startPoint[0] && x <= startPoint[0] + size[0] && y >= startPoint[1] && y <= startPoint[1] + size[1]) {
4262
+ return largeDataIndices[i];
4263
+ }
4264
+ }
4265
+
4266
+ return -1;
4267
+ }
4268
+
4269
+ function createBackgroundShape(isHorizontalOrRadial, layout, coord) {
4270
+ if (isCoordinateSystemType(coord, 'cartesian2d')) {
4271
+ var rectShape = layout;
4272
+ var coordLayout = coord.getArea();
4273
+ return {
4274
+ x: isHorizontalOrRadial ? rectShape.x : coordLayout.x,
4275
+ y: isHorizontalOrRadial ? coordLayout.y : rectShape.y,
4276
+ width: isHorizontalOrRadial ? rectShape.width : coordLayout.width,
4277
+ height: isHorizontalOrRadial ? coordLayout.height : rectShape.height
4278
+ };
4279
+ } else {
4280
+ var coordLayout = coord.getArea();
4281
+ var sectorShape = layout;
4282
+ return {
4283
+ cx: coordLayout.cx,
4284
+ cy: coordLayout.cy,
4285
+ r0: isHorizontalOrRadial ? coordLayout.r0 : sectorShape.r0,
4286
+ r: isHorizontalOrRadial ? coordLayout.r : sectorShape.r,
4287
+ startAngle: isHorizontalOrRadial ? sectorShape.startAngle : 0,
4288
+ endAngle: isHorizontalOrRadial ? sectorShape.endAngle : Math.PI * 2
4289
+ };
4290
+ }
4291
+ }
4292
+
4293
+ function createBackgroundEl(coord, isHorizontalOrRadial, layout) {
4294
+ var ElementClz = coord.type === 'polar' ? Sector : Rect;
4295
+ return new ElementClz({
4296
+ shape: createBackgroundShape(isHorizontalOrRadial, layout, coord),
4297
+ silent: true,
4298
+ z2: 0
4299
+ });
4300
+ }
4301
+
4302
+ function install(registers) {
4303
+ registers.registerChartView(BarView);
4304
+ registers.registerSeriesModel(BarSeriesModel);
4305
+ registers.registerLayout(registers.PRIORITY.VISUAL.LAYOUT, curry(layout$1, 'bar')); // Do layout after other overall layout, which can prepare some information.
4306
+
4307
+ registers.registerLayout(registers.PRIORITY.VISUAL.PROGRESSIVE_LAYOUT, createProgressiveLayout('bar')); // Down sample after filter
4308
+
4309
+ registers.registerProcessor(registers.PRIORITY.PROCESSOR.STATISTIC, dataSample('bar'));
4310
+ /**
4311
+ * @payload
4312
+ * @property {string} [componentType=series]
4313
+ * @property {number} [dx]
4314
+ * @property {number} [dy]
4315
+ * @property {number} [zoom]
4316
+ * @property {number} [originX]
4317
+ * @property {number} [originY]
4318
+ */
4319
+
4320
+ registers.registerAction({
4321
+ type: 'changeAxisOrder',
4322
+ event: 'changeAxisOrder',
4323
+ update: 'update'
4324
+ }, function (payload, ecModel) {
4325
+ var componentType = payload.componentType || 'series';
4326
+ ecModel.eachComponent({
4327
+ mainType: componentType,
4328
+ query: payload
4329
+ }, function (componentModel) {
4330
+ if (payload.sortInfo) {
4331
+ componentModel.axis.setCategorySortInfo(payload.sortInfo);
4332
+ }
4333
+ });
4334
+ });
4335
+ }
4336
+
4337
+ var ValidColorNames;
4338
+ (function (ValidColorNames) {
4339
+ ValidColorNames[ValidColorNames["aliceblue"] = 0] = "aliceblue";
4340
+ ValidColorNames[ValidColorNames["antiquewhite"] = 1] = "antiquewhite";
4341
+ ValidColorNames[ValidColorNames["aqua"] = 2] = "aqua";
4342
+ ValidColorNames[ValidColorNames["aquamarine"] = 3] = "aquamarine";
4343
+ ValidColorNames[ValidColorNames["azure"] = 4] = "azure";
4344
+ ValidColorNames[ValidColorNames["beige"] = 5] = "beige";
4345
+ ValidColorNames[ValidColorNames["bisque"] = 6] = "bisque";
4346
+ ValidColorNames[ValidColorNames["black"] = 7] = "black";
4347
+ ValidColorNames[ValidColorNames["blanchedalmond"] = 8] = "blanchedalmond";
4348
+ ValidColorNames[ValidColorNames["blue"] = 9] = "blue";
4349
+ ValidColorNames[ValidColorNames["blueviolet"] = 10] = "blueviolet";
4350
+ ValidColorNames[ValidColorNames["brown"] = 11] = "brown";
4351
+ ValidColorNames[ValidColorNames["burlywood"] = 12] = "burlywood";
4352
+ ValidColorNames[ValidColorNames["cadetblue"] = 13] = "cadetblue";
4353
+ ValidColorNames[ValidColorNames["chartreuse"] = 14] = "chartreuse";
4354
+ ValidColorNames[ValidColorNames["chocolate"] = 15] = "chocolate";
4355
+ ValidColorNames[ValidColorNames["coral"] = 16] = "coral";
4356
+ ValidColorNames[ValidColorNames["cornflowerblue"] = 17] = "cornflowerblue";
4357
+ ValidColorNames[ValidColorNames["cornsilk"] = 18] = "cornsilk";
4358
+ ValidColorNames[ValidColorNames["crimson"] = 19] = "crimson";
4359
+ ValidColorNames[ValidColorNames["cyan"] = 20] = "cyan";
4360
+ ValidColorNames[ValidColorNames["darkblue"] = 21] = "darkblue";
4361
+ ValidColorNames[ValidColorNames["darkcyan"] = 22] = "darkcyan";
4362
+ ValidColorNames[ValidColorNames["darkgoldenrod"] = 23] = "darkgoldenrod";
4363
+ ValidColorNames[ValidColorNames["darkgray"] = 24] = "darkgray";
4364
+ ValidColorNames[ValidColorNames["darkgreen"] = 25] = "darkgreen";
4365
+ ValidColorNames[ValidColorNames["darkkhaki"] = 26] = "darkkhaki";
4366
+ ValidColorNames[ValidColorNames["darkmagenta"] = 27] = "darkmagenta";
4367
+ ValidColorNames[ValidColorNames["darkolivegreen"] = 28] = "darkolivegreen";
4368
+ ValidColorNames[ValidColorNames["darkorange"] = 29] = "darkorange";
4369
+ ValidColorNames[ValidColorNames["darkorchid"] = 30] = "darkorchid";
4370
+ ValidColorNames[ValidColorNames["darkred"] = 31] = "darkred";
4371
+ ValidColorNames[ValidColorNames["darksalmon"] = 32] = "darksalmon";
4372
+ ValidColorNames[ValidColorNames["darkseagreen"] = 33] = "darkseagreen";
4373
+ ValidColorNames[ValidColorNames["darkslateblue"] = 34] = "darkslateblue";
4374
+ ValidColorNames[ValidColorNames["darkslategray"] = 35] = "darkslategray";
4375
+ ValidColorNames[ValidColorNames["darkturquoise"] = 36] = "darkturquoise";
4376
+ ValidColorNames[ValidColorNames["darkviolet"] = 37] = "darkviolet";
4377
+ ValidColorNames[ValidColorNames["deeppink"] = 38] = "deeppink";
4378
+ ValidColorNames[ValidColorNames["deepskyblue"] = 39] = "deepskyblue";
4379
+ ValidColorNames[ValidColorNames["dimgray"] = 40] = "dimgray";
4380
+ ValidColorNames[ValidColorNames["dodgerblue"] = 41] = "dodgerblue";
4381
+ ValidColorNames[ValidColorNames["firebrick"] = 42] = "firebrick";
4382
+ ValidColorNames[ValidColorNames["floralwhite"] = 43] = "floralwhite";
4383
+ ValidColorNames[ValidColorNames["forestgreen"] = 44] = "forestgreen";
4384
+ ValidColorNames[ValidColorNames["fuchsia"] = 45] = "fuchsia";
4385
+ ValidColorNames[ValidColorNames["gainsboro"] = 46] = "gainsboro";
4386
+ ValidColorNames[ValidColorNames["ghostwhite"] = 47] = "ghostwhite";
4387
+ ValidColorNames[ValidColorNames["gold"] = 48] = "gold";
4388
+ ValidColorNames[ValidColorNames["goldenrod"] = 49] = "goldenrod";
4389
+ ValidColorNames[ValidColorNames["gray"] = 50] = "gray";
4390
+ ValidColorNames[ValidColorNames["green"] = 51] = "green";
4391
+ ValidColorNames[ValidColorNames["greenyellow"] = 52] = "greenyellow";
4392
+ ValidColorNames[ValidColorNames["honeydew"] = 53] = "honeydew";
4393
+ ValidColorNames[ValidColorNames["hotpink"] = 54] = "hotpink";
4394
+ ValidColorNames[ValidColorNames["indianred"] = 55] = "indianred";
4395
+ ValidColorNames[ValidColorNames["indigo"] = 56] = "indigo";
4396
+ ValidColorNames[ValidColorNames["ivory"] = 57] = "ivory";
4397
+ ValidColorNames[ValidColorNames["khaki"] = 58] = "khaki";
4398
+ ValidColorNames[ValidColorNames["lavender"] = 59] = "lavender";
4399
+ ValidColorNames[ValidColorNames["lavenderblush"] = 60] = "lavenderblush";
4400
+ ValidColorNames[ValidColorNames["lawngreen"] = 61] = "lawngreen";
4401
+ ValidColorNames[ValidColorNames["lemonchiffon"] = 62] = "lemonchiffon";
4402
+ ValidColorNames[ValidColorNames["lightblue"] = 63] = "lightblue";
4403
+ ValidColorNames[ValidColorNames["lightcoral"] = 64] = "lightcoral";
4404
+ ValidColorNames[ValidColorNames["lightcyan"] = 65] = "lightcyan";
4405
+ ValidColorNames[ValidColorNames["lightgoldenrodyellow"] = 66] = "lightgoldenrodyellow";
4406
+ ValidColorNames[ValidColorNames["lightgrey"] = 67] = "lightgrey";
4407
+ ValidColorNames[ValidColorNames["lightgreen"] = 68] = "lightgreen";
4408
+ ValidColorNames[ValidColorNames["lightpink"] = 69] = "lightpink";
4409
+ ValidColorNames[ValidColorNames["lightsalmon"] = 70] = "lightsalmon";
4410
+ ValidColorNames[ValidColorNames["lightseagreen"] = 71] = "lightseagreen";
4411
+ ValidColorNames[ValidColorNames["lightskyblue"] = 72] = "lightskyblue";
4412
+ ValidColorNames[ValidColorNames["lightslategray"] = 73] = "lightslategray";
4413
+ ValidColorNames[ValidColorNames["lightsteelblue"] = 74] = "lightsteelblue";
4414
+ ValidColorNames[ValidColorNames["lightyellow"] = 75] = "lightyellow";
4415
+ ValidColorNames[ValidColorNames["lime"] = 76] = "lime";
4416
+ ValidColorNames[ValidColorNames["limegreen"] = 77] = "limegreen";
4417
+ ValidColorNames[ValidColorNames["linen"] = 78] = "linen";
4418
+ ValidColorNames[ValidColorNames["magenta"] = 79] = "magenta";
4419
+ ValidColorNames[ValidColorNames["maroon"] = 80] = "maroon";
4420
+ ValidColorNames[ValidColorNames["mediumaquamarine"] = 81] = "mediumaquamarine";
4421
+ ValidColorNames[ValidColorNames["mediumblue"] = 82] = "mediumblue";
4422
+ ValidColorNames[ValidColorNames["mediumorchid"] = 83] = "mediumorchid";
4423
+ ValidColorNames[ValidColorNames["mediumpurple"] = 84] = "mediumpurple";
4424
+ ValidColorNames[ValidColorNames["mediumseagreen"] = 85] = "mediumseagreen";
4425
+ ValidColorNames[ValidColorNames["mediumslateblue"] = 86] = "mediumslateblue";
4426
+ ValidColorNames[ValidColorNames["mediumspringgreen"] = 87] = "mediumspringgreen";
4427
+ ValidColorNames[ValidColorNames["mediumturquoise"] = 88] = "mediumturquoise";
4428
+ ValidColorNames[ValidColorNames["mediumvioletred"] = 89] = "mediumvioletred";
4429
+ ValidColorNames[ValidColorNames["midnightblue"] = 90] = "midnightblue";
4430
+ ValidColorNames[ValidColorNames["mintcream"] = 91] = "mintcream";
4431
+ ValidColorNames[ValidColorNames["mistyrose"] = 92] = "mistyrose";
4432
+ ValidColorNames[ValidColorNames["moccasin"] = 93] = "moccasin";
4433
+ ValidColorNames[ValidColorNames["navajowhite"] = 94] = "navajowhite";
4434
+ ValidColorNames[ValidColorNames["navy"] = 95] = "navy";
4435
+ ValidColorNames[ValidColorNames["oldlace"] = 96] = "oldlace";
4436
+ ValidColorNames[ValidColorNames["olive"] = 97] = "olive";
4437
+ ValidColorNames[ValidColorNames["olivedrab"] = 98] = "olivedrab";
4438
+ ValidColorNames[ValidColorNames["orange"] = 99] = "orange";
4439
+ ValidColorNames[ValidColorNames["orangered"] = 100] = "orangered";
4440
+ ValidColorNames[ValidColorNames["orchid"] = 101] = "orchid";
4441
+ ValidColorNames[ValidColorNames["palegoldenrod"] = 102] = "palegoldenrod";
4442
+ ValidColorNames[ValidColorNames["palegreen"] = 103] = "palegreen";
4443
+ ValidColorNames[ValidColorNames["paleturquoise"] = 104] = "paleturquoise";
4444
+ ValidColorNames[ValidColorNames["palevioletred"] = 105] = "palevioletred";
4445
+ ValidColorNames[ValidColorNames["papayawhip"] = 106] = "papayawhip";
4446
+ ValidColorNames[ValidColorNames["peachpuff"] = 107] = "peachpuff";
4447
+ ValidColorNames[ValidColorNames["peru"] = 108] = "peru";
4448
+ ValidColorNames[ValidColorNames["pink"] = 109] = "pink";
4449
+ ValidColorNames[ValidColorNames["plum"] = 110] = "plum";
4450
+ ValidColorNames[ValidColorNames["powderblue"] = 111] = "powderblue";
4451
+ ValidColorNames[ValidColorNames["purple"] = 112] = "purple";
4452
+ ValidColorNames[ValidColorNames["red"] = 113] = "red";
4453
+ ValidColorNames[ValidColorNames["rosybrown"] = 114] = "rosybrown";
4454
+ ValidColorNames[ValidColorNames["royalblue"] = 115] = "royalblue";
4455
+ ValidColorNames[ValidColorNames["saddlebrown"] = 116] = "saddlebrown";
4456
+ ValidColorNames[ValidColorNames["salmon"] = 117] = "salmon";
4457
+ ValidColorNames[ValidColorNames["sandybrown"] = 118] = "sandybrown";
4458
+ ValidColorNames[ValidColorNames["seagreen"] = 119] = "seagreen";
4459
+ ValidColorNames[ValidColorNames["seashell"] = 120] = "seashell";
4460
+ ValidColorNames[ValidColorNames["sienna"] = 121] = "sienna";
4461
+ ValidColorNames[ValidColorNames["silver"] = 122] = "silver";
4462
+ ValidColorNames[ValidColorNames["skyblue"] = 123] = "skyblue";
4463
+ ValidColorNames[ValidColorNames["slateblue"] = 124] = "slateblue";
4464
+ ValidColorNames[ValidColorNames["slategray"] = 125] = "slategray";
4465
+ ValidColorNames[ValidColorNames["snow"] = 126] = "snow";
4466
+ ValidColorNames[ValidColorNames["springgreen"] = 127] = "springgreen";
4467
+ ValidColorNames[ValidColorNames["steelblue"] = 128] = "steelblue";
4468
+ ValidColorNames[ValidColorNames["tan"] = 129] = "tan";
4469
+ ValidColorNames[ValidColorNames["teal"] = 130] = "teal";
4470
+ ValidColorNames[ValidColorNames["thistle"] = 131] = "thistle";
4471
+ ValidColorNames[ValidColorNames["tomato"] = 132] = "tomato";
4472
+ ValidColorNames[ValidColorNames["turquoise"] = 133] = "turquoise";
4473
+ ValidColorNames[ValidColorNames["violet"] = 134] = "violet";
4474
+ ValidColorNames[ValidColorNames["wheat"] = 135] = "wheat";
4475
+ ValidColorNames[ValidColorNames["white"] = 136] = "white";
4476
+ ValidColorNames[ValidColorNames["whitesmoke"] = 137] = "whitesmoke";
4477
+ ValidColorNames[ValidColorNames["yellow"] = 138] = "yellow";
4478
+ ValidColorNames[ValidColorNames["yellowgreen"] = 139] = "yellowgreen";
4479
+ })(ValidColorNames || (ValidColorNames = {}));
4480
+ function isValidColor(color) {
4481
+ const hexRegex = new RegExp('^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$');
4482
+ const isValidHex = hexRegex.test(color);
4483
+ const isValidCSSColorName = !!ValidColorNames[color];
4484
+ return isValidHex || isValidCSSColorName;
4485
+ }
4486
+ function getCSSProperty(name, containerStyles, hostElementStyles) {
4487
+ if (!name)
4488
+ return;
4489
+ let fallback;
4490
+ if (name.startsWith('var(') && name.endsWith(')')) {
4491
+ const regExp = /var\((.*)\)/g;
4492
+ const result = regExp.exec(name);
4493
+ const split = result.length >= 2 ? result[1].split(',') : [];
4494
+ name = split[0];
4495
+ fallback = split[1];
4496
+ }
4497
+ let result = containerStyles.getPropertyValue(name).trim();
4498
+ if (!result)
4499
+ result = hostElementStyles.getPropertyValue(name).trim();
4500
+ return result || fallback;
4501
+ }
4502
+ function formatValue(value, format) {
4503
+ const valueAsFloat = parseFloat(value.toString());
4504
+ if (isNaN(valueAsFloat))
4505
+ return;
4506
+ const decimals = isNaN(+format.decimals) ? 0 : +format.decimals;
4507
+ if (format.type === 'currency') {
4508
+ return Intl.NumberFormat('en-US', {
4509
+ style: 'currency',
4510
+ currency: 'USD',
4511
+ maximumFractionDigits: decimals,
4512
+ minimumFractionDigits: decimals,
4513
+ }).format(valueAsFloat);
4514
+ }
4515
+ else {
4516
+ return Intl.NumberFormat('en-US').format(valueAsFloat);
4517
+ }
4518
+ }
4519
+
4520
+ 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%}";
4521
+
4522
+ use([install$5, install, install$6, installLabelLayout, install$2, install$1]);
4523
+ const Q2ChartBar$1 = /*@__PURE__*/ proxyCustomElement(class extends HTMLElement {
4524
+ constructor() {
4525
+ super();
4526
+ this.__registerHost();
4527
+ this.__attachShadow();
4528
+ this.data = [];
4529
+ this.alignChartName = undefined;
4530
+ this.chartName = undefined;
4531
+ this.color = undefined;
4532
+ this.dataNamesOverflow = undefined;
4533
+ this.dataNamesWidth = undefined;
4534
+ this.format = undefined;
4535
+ this.formatModifier = undefined;
4536
+ this.hideBarLabels = false;
4537
+ this.hideValueAxisLabels = false;
4538
+ this.offsetDataNames = false;
4539
+ this.offsetDataValues = false;
4540
+ this.orientation = undefined;
4541
+ this.showChartName = false;
4542
+ this.sort = false;
4543
+ }
4544
+ componentDidLoad() {
4545
+ const chart = init(this.chartContainer);
4546
+ this.chart = chart;
4547
+ this.resizeObserver = new ResizeObserver(() => this.resizeChart());
4548
+ this.resizeObserver.observe(this.hostElement);
4549
+ this.cacheComputedStyles();
4550
+ this.updateChart(chart);
4551
+ overrideFocus(this.hostElement);
4552
+ }
4553
+ willDestroyElement() {
4554
+ this.resizeObserver = null;
4555
+ }
4556
+ cacheComputedStyles() {
4557
+ this.chartContainerStyles = getComputedStyle(this.chartContainer);
4558
+ this.hostElementStyles = getComputedStyle(this.hostElement);
4559
+ }
4560
+ getColor(color) {
4561
+ const primaryColor = getCSSProperty('var(--t-primary)', this.chartContainerStyles, this.hostElementStyles);
4562
+ const seriesColor = getCSSProperty(this.color, this.chartContainerStyles, this.hostElementStyles);
4563
+ const cssColorProp = getCSSProperty(color, this.chartContainerStyles, this.hostElementStyles);
4564
+ if (cssColorProp)
4565
+ return cssColorProp;
4566
+ if (isValidColor(color))
4567
+ return color;
4568
+ if (seriesColor)
4569
+ return seriesColor;
4570
+ if (isValidColor(this.color))
4571
+ return this.color;
4572
+ return primaryColor;
4573
+ }
4574
+ processData(data) {
4575
+ return data.map(datum => {
4576
+ return {
4577
+ value: datum.value || 0,
4578
+ itemStyle: {
4579
+ color: this.getColor(datum.color),
4580
+ },
4581
+ };
4582
+ });
4583
+ }
4584
+ updateChart(chart) {
4585
+ var _a;
4586
+ const decimals = ((_a = this.formatModifier) === null || _a === void 0 ? void 0 : _a.includes('dec')) ? this.formatModifier.replace('dec', '') : 0;
4587
+ const valueAxis = {
4588
+ type: 'value',
4589
+ axisLabel: {
4590
+ formatter: (value) => formatValue(value, {
4591
+ type: this.format,
4592
+ decimals,
4593
+ }),
4594
+ rotate: this.offsetDataValues ? 45 : 0,
4595
+ margin: this.offsetDataValues ? 15 : 8,
4596
+ show: !this.hideValueAxisLabels,
4597
+ },
4598
+ };
4599
+ const categoryAxis = {
4600
+ type: 'category',
4601
+ data: this.data.map(datum => loc(datum.name) || ''),
4602
+ axisLabel: {
4603
+ rotate: this.offsetDataNames ? 45 : 0,
4604
+ margin: this.offsetDataNames ? 15 : 8,
4605
+ interval: 0,
4606
+ width: this.dataNamesWidth || 50,
4607
+ overflow: this.dataNamesOverflow || 'none',
4608
+ truncate: 'ellipsis',
4609
+ },
4610
+ axisTick: {
4611
+ alignWithLabel: this.offsetDataNames,
4612
+ },
4613
+ };
4614
+ return chart.setOption({
4615
+ aria: {
4616
+ enabled: true,
4617
+ },
4618
+ title: {
4619
+ text: this.chartName,
4620
+ show: this.showChartName,
4621
+ left: this.alignChartName,
4622
+ },
4623
+ grid: {
4624
+ containLabel: true,
4625
+ },
4626
+ xAxis: this.orientation === 'horizontal' ? valueAxis : categoryAxis,
4627
+ yAxis: this.orientation === 'horizontal' ? categoryAxis : valueAxis,
4628
+ series: [
4629
+ {
4630
+ data: this.processData(this.data),
4631
+ id: 'bar',
4632
+ type: 'bar',
4633
+ label: {
4634
+ show: !this.hideBarLabels,
4635
+ position: 'top',
4636
+ fontWeight: 'bold',
4637
+ formatter: (params) => {
4638
+ return formatValue(params.value, {
4639
+ type: this.format,
4640
+ decimals,
4641
+ });
4642
+ },
4643
+ },
4644
+ realtimeSort: this.sort,
4645
+ },
4646
+ ],
4647
+ });
4648
+ }
4649
+ resizeChart() {
4650
+ this.chart.resize();
4651
+ }
4652
+ propsUpdates() {
4653
+ this.updateChart(this.chart);
4654
+ }
4655
+ render() {
4656
+ return (h("div", { class: "container" }, h("div", { ref: el => (this.chartContainer = el), class: "chart-container", "test-id": "barChartContainer" })));
4657
+ }
4658
+ get hostElement() { return this; }
4659
+ static get watchers() { return {
4660
+ "chartName": ["propsUpdates"],
4661
+ "color": ["propsUpdates"],
4662
+ "hideBarLabels": ["propsUpdates"],
4663
+ "showChartName": ["propsUpdates"],
4664
+ "alignChartName": ["propsUpdates"],
4665
+ "orientation": ["propsUpdates"],
4666
+ "format": ["propsUpdates"],
4667
+ "sort": ["propsUpdates"],
4668
+ "data": ["propsUpdates"],
4669
+ "offsetDataNames": ["propsUpdates"],
4670
+ "hideValueAxisLabels": ["propsUpdates"],
4671
+ "formatModifier": ["propsUpdates"],
4672
+ "dataNamesOverflow": ["propsUpdates"]
4673
+ }; }
4674
+ static get style() { return stylesCss; }
4675
+ }, [1, "q2-chart-bar", {
4676
+ "data": [16],
4677
+ "alignChartName": [513, "align-chart-name"],
4678
+ "chartName": [513, "chart-name"],
4679
+ "color": [513],
4680
+ "dataNamesOverflow": [513, "data-names-overflow"],
4681
+ "dataNamesWidth": [514, "data-names-width"],
4682
+ "format": [513],
4683
+ "formatModifier": [513, "format-modifier"],
4684
+ "hideBarLabels": [516, "hide-bar-labels"],
4685
+ "hideValueAxisLabels": [516, "hide-value-axis-labels"],
4686
+ "offsetDataNames": [516, "offset-data-names"],
4687
+ "offsetDataValues": [516, "offset-data-values"],
4688
+ "orientation": [513],
4689
+ "showChartName": [516, "show-chart-name"],
4690
+ "sort": [516]
4691
+ }]);
4692
+ function defineCustomElement$1() {
4693
+ if (typeof customElements === "undefined") {
4694
+ return;
4695
+ }
4696
+ const components = ["q2-chart-bar"];
4697
+ components.forEach(tagName => { switch (tagName) {
4698
+ case "q2-chart-bar":
4699
+ if (!customElements.get(tagName)) {
4700
+ customElements.define(tagName, Q2ChartBar$1);
4701
+ }
4702
+ break;
4703
+ } });
4704
+ }
4705
+ defineCustomElement$1();
4706
+
4707
+ const Q2ChartBar = Q2ChartBar$1;
4708
+ const defineCustomElement = defineCustomElement$1;
4709
+
4710
+ export { Q2ChartBar, defineCustomElement };