MarkPointView.js 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing,
  13. * software distributed under the License is distributed on an
  14. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  15. * KIND, either express or implied. See the License for the
  16. * specific language governing permissions and limitations
  17. * under the License.
  18. */
  19. /**
  20. * AUTO-GENERATED FILE. DO NOT MODIFY.
  21. */
  22. /*
  23. * Licensed to the Apache Software Foundation (ASF) under one
  24. * or more contributor license agreements. See the NOTICE file
  25. * distributed with this work for additional information
  26. * regarding copyright ownership. The ASF licenses this file
  27. * to you under the Apache License, Version 2.0 (the
  28. * "License"); you may not use this file except in compliance
  29. * with the License. You may obtain a copy of the License at
  30. *
  31. * http://www.apache.org/licenses/LICENSE-2.0
  32. *
  33. * Unless required by applicable law or agreed to in writing,
  34. * software distributed under the License is distributed on an
  35. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  36. * KIND, either express or implied. See the License for the
  37. * specific language governing permissions and limitations
  38. * under the License.
  39. */
  40. import { __extends } from "tslib";
  41. import SymbolDraw from '../../chart/helper/SymbolDraw.js';
  42. import * as numberUtil from '../../util/number.js';
  43. import SeriesData from '../../data/SeriesData.js';
  44. import * as markerHelper from './markerHelper.js';
  45. import MarkerView from './MarkerView.js';
  46. import MarkerModel from './MarkerModel.js';
  47. import { isFunction, map, filter, curry, extend, retrieve2 } from 'zrender/lib/core/util.js';
  48. import { getECData } from '../../util/innerStore.js';
  49. import { getVisualFromData } from '../../visual/helper.js';
  50. function updateMarkerLayout(mpData, seriesModel, api) {
  51. var coordSys = seriesModel.coordinateSystem;
  52. var apiWidth = api.getWidth();
  53. var apiHeight = api.getHeight();
  54. var coordRect = coordSys && coordSys.getArea && coordSys.getArea();
  55. mpData.each(function (idx) {
  56. var itemModel = mpData.getItemModel(idx);
  57. var isRelativeToCoordinate = itemModel.get('relativeTo') === 'coordinate';
  58. var width = isRelativeToCoordinate ? coordRect ? coordRect.width : 0 : apiWidth;
  59. var height = isRelativeToCoordinate ? coordRect ? coordRect.height : 0 : apiHeight;
  60. var left = isRelativeToCoordinate && coordRect ? coordRect.x : 0;
  61. var top = isRelativeToCoordinate && coordRect ? coordRect.y : 0;
  62. var point;
  63. var xPx = numberUtil.parsePercent(itemModel.get('x'), width) + left;
  64. var yPx = numberUtil.parsePercent(itemModel.get('y'), height) + top;
  65. if (!isNaN(xPx) && !isNaN(yPx)) {
  66. point = [xPx, yPx];
  67. }
  68. // Chart like bar may have there own marker positioning logic
  69. else if (seriesModel.getMarkerPosition) {
  70. // Use the getMarkerPosition
  71. point = seriesModel.getMarkerPosition(mpData.getValues(mpData.dimensions, idx));
  72. } else if (coordSys) {
  73. var x = mpData.get(coordSys.dimensions[0], idx);
  74. var y = mpData.get(coordSys.dimensions[1], idx);
  75. point = coordSys.dataToPoint([x, y]);
  76. }
  77. // Use x, y if has any
  78. if (!isNaN(xPx)) {
  79. point[0] = xPx;
  80. }
  81. if (!isNaN(yPx)) {
  82. point[1] = yPx;
  83. }
  84. mpData.setItemLayout(idx, point);
  85. });
  86. }
  87. var MarkPointView = /** @class */function (_super) {
  88. __extends(MarkPointView, _super);
  89. function MarkPointView() {
  90. var _this = _super !== null && _super.apply(this, arguments) || this;
  91. _this.type = MarkPointView.type;
  92. return _this;
  93. }
  94. MarkPointView.prototype.updateTransform = function (markPointModel, ecModel, api) {
  95. ecModel.eachSeries(function (seriesModel) {
  96. var mpModel = MarkerModel.getMarkerModelFromSeries(seriesModel, 'markPoint');
  97. if (mpModel) {
  98. updateMarkerLayout(mpModel.getData(), seriesModel, api);
  99. this.markerGroupMap.get(seriesModel.id).updateLayout();
  100. }
  101. }, this);
  102. };
  103. MarkPointView.prototype.renderSeries = function (seriesModel, mpModel, ecModel, api) {
  104. var coordSys = seriesModel.coordinateSystem;
  105. var seriesId = seriesModel.id;
  106. var seriesData = seriesModel.getData();
  107. var symbolDrawMap = this.markerGroupMap;
  108. var symbolDraw = symbolDrawMap.get(seriesId) || symbolDrawMap.set(seriesId, new SymbolDraw());
  109. var mpData = createData(coordSys, seriesModel, mpModel);
  110. // FIXME
  111. mpModel.setData(mpData);
  112. updateMarkerLayout(mpModel.getData(), seriesModel, api);
  113. mpData.each(function (idx) {
  114. var itemModel = mpData.getItemModel(idx);
  115. var symbol = itemModel.getShallow('symbol');
  116. var symbolSize = itemModel.getShallow('symbolSize');
  117. var symbolRotate = itemModel.getShallow('symbolRotate');
  118. var symbolOffset = itemModel.getShallow('symbolOffset');
  119. var symbolKeepAspect = itemModel.getShallow('symbolKeepAspect');
  120. // TODO: refactor needed: single data item should not support callback function
  121. if (isFunction(symbol) || isFunction(symbolSize) || isFunction(symbolRotate) || isFunction(symbolOffset)) {
  122. var rawIdx = mpModel.getRawValue(idx);
  123. var dataParams = mpModel.getDataParams(idx);
  124. if (isFunction(symbol)) {
  125. symbol = symbol(rawIdx, dataParams);
  126. }
  127. if (isFunction(symbolSize)) {
  128. // FIXME 这里不兼容 ECharts 2.x,2.x 貌似参数是整个数据?
  129. symbolSize = symbolSize(rawIdx, dataParams);
  130. }
  131. if (isFunction(symbolRotate)) {
  132. symbolRotate = symbolRotate(rawIdx, dataParams);
  133. }
  134. if (isFunction(symbolOffset)) {
  135. symbolOffset = symbolOffset(rawIdx, dataParams);
  136. }
  137. }
  138. var style = itemModel.getModel('itemStyle').getItemStyle();
  139. var z2 = itemModel.get('z2');
  140. var color = getVisualFromData(seriesData, 'color');
  141. if (!style.fill) {
  142. style.fill = color;
  143. }
  144. mpData.setItemVisual(idx, {
  145. z2: retrieve2(z2, 0),
  146. symbol: symbol,
  147. symbolSize: symbolSize,
  148. symbolRotate: symbolRotate,
  149. symbolOffset: symbolOffset,
  150. symbolKeepAspect: symbolKeepAspect,
  151. style: style
  152. });
  153. });
  154. // TODO Text are wrong
  155. symbolDraw.updateData(mpData);
  156. this.group.add(symbolDraw.group);
  157. // Set host model for tooltip
  158. // FIXME
  159. mpData.eachItemGraphicEl(function (el) {
  160. el.traverse(function (child) {
  161. getECData(child).dataModel = mpModel;
  162. });
  163. });
  164. this.markKeep(symbolDraw);
  165. symbolDraw.group.silent = mpModel.get('silent') || seriesModel.get('silent');
  166. };
  167. MarkPointView.type = 'markPoint';
  168. return MarkPointView;
  169. }(MarkerView);
  170. function createData(coordSys, seriesModel, mpModel) {
  171. var coordDimsInfos;
  172. if (coordSys) {
  173. coordDimsInfos = map(coordSys && coordSys.dimensions, function (coordDim) {
  174. var info = seriesModel.getData().getDimensionInfo(seriesModel.getData().mapDimension(coordDim)) || {};
  175. // In map series data don't have lng and lat dimension. Fallback to same with coordSys
  176. return extend(extend({}, info), {
  177. name: coordDim,
  178. // DON'T use ordinalMeta to parse and collect ordinal.
  179. ordinalMeta: null
  180. });
  181. });
  182. } else {
  183. coordDimsInfos = [{
  184. name: 'value',
  185. type: 'float'
  186. }];
  187. }
  188. var mpData = new SeriesData(coordDimsInfos, mpModel);
  189. var dataOpt = map(mpModel.get('data'), curry(markerHelper.dataTransform, seriesModel));
  190. if (coordSys) {
  191. dataOpt = filter(dataOpt, curry(markerHelper.dataFilter, coordSys));
  192. }
  193. var dimValueGetter = markerHelper.createMarkerDimValueGetter(!!coordSys, coordDimsInfos);
  194. mpData.initData(dataOpt, null, dimValueGetter);
  195. return mpData;
  196. }
  197. export default MarkPointView;