q2-tecton-elements 1.21.2 → 1.22.1

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