MarkPointView.js 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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 } 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. mpData.each(function (idx) {
  53. var itemModel = mpData.getItemModel(idx);
  54. var point;
  55. var xPx = numberUtil.parsePercent(itemModel.get('x'), api.getWidth());
  56. var yPx = numberUtil.parsePercent(itemModel.get('y'), api.getHeight());
  57. if (!isNaN(xPx) && !isNaN(yPx)) {
  58. point = [xPx, yPx];
  59. }
  60. // Chart like bar may have there own marker positioning logic
  61. else if (seriesModel.getMarkerPosition) {
  62. // Use the getMarkerPosition
  63. point = seriesModel.getMarkerPosition(mpData.getValues(mpData.dimensions, idx));
  64. } else if (coordSys) {
  65. var x = mpData.get(coordSys.dimensions[0], idx);
  66. var y = mpData.get(coordSys.dimensions[1], idx);
  67. point = coordSys.dataToPoint([x, y]);
  68. }
  69. // Use x, y if has any
  70. if (!isNaN(xPx)) {
  71. point[0] = xPx;
  72. }
  73. if (!isNaN(yPx)) {
  74. point[1] = yPx;
  75. }
  76. mpData.setItemLayout(idx, point);
  77. });
  78. }
  79. var MarkPointView = /** @class */function (_super) {
  80. __extends(MarkPointView, _super);
  81. function MarkPointView() {
  82. var _this = _super !== null && _super.apply(this, arguments) || this;
  83. _this.type = MarkPointView.type;
  84. return _this;
  85. }
  86. MarkPointView.prototype.updateTransform = function (markPointModel, ecModel, api) {
  87. ecModel.eachSeries(function (seriesModel) {
  88. var mpModel = MarkerModel.getMarkerModelFromSeries(seriesModel, 'markPoint');
  89. if (mpModel) {
  90. updateMarkerLayout(mpModel.getData(), seriesModel, api);
  91. this.markerGroupMap.get(seriesModel.id).updateLayout();
  92. }
  93. }, this);
  94. };
  95. MarkPointView.prototype.renderSeries = function (seriesModel, mpModel, ecModel, api) {
  96. var coordSys = seriesModel.coordinateSystem;
  97. var seriesId = seriesModel.id;
  98. var seriesData = seriesModel.getData();
  99. var symbolDrawMap = this.markerGroupMap;
  100. var symbolDraw = symbolDrawMap.get(seriesId) || symbolDrawMap.set(seriesId, new SymbolDraw());
  101. var mpData = createData(coordSys, seriesModel, mpModel);
  102. // FIXME
  103. mpModel.setData(mpData);
  104. updateMarkerLayout(mpModel.getData(), seriesModel, api);
  105. mpData.each(function (idx) {
  106. var itemModel = mpData.getItemModel(idx);
  107. var symbol = itemModel.getShallow('symbol');
  108. var symbolSize = itemModel.getShallow('symbolSize');
  109. var symbolRotate = itemModel.getShallow('symbolRotate');
  110. var symbolOffset = itemModel.getShallow('symbolOffset');
  111. var symbolKeepAspect = itemModel.getShallow('symbolKeepAspect');
  112. // TODO: refactor needed: single data item should not support callback function
  113. if (isFunction(symbol) || isFunction(symbolSize) || isFunction(symbolRotate) || isFunction(symbolOffset)) {
  114. var rawIdx = mpModel.getRawValue(idx);
  115. var dataParams = mpModel.getDataParams(idx);
  116. if (isFunction(symbol)) {
  117. symbol = symbol(rawIdx, dataParams);
  118. }
  119. if (isFunction(symbolSize)) {
  120. // FIXME 这里不兼容 ECharts 2.x,2.x 貌似参数是整个数据?
  121. symbolSize = symbolSize(rawIdx, dataParams);
  122. }
  123. if (isFunction(symbolRotate)) {
  124. symbolRotate = symbolRotate(rawIdx, dataParams);
  125. }
  126. if (isFunction(symbolOffset)) {
  127. symbolOffset = symbolOffset(rawIdx, dataParams);
  128. }
  129. }
  130. var style = itemModel.getModel('itemStyle').getItemStyle();
  131. var color = getVisualFromData(seriesData, 'color');
  132. if (!style.fill) {
  133. style.fill = color;
  134. }
  135. mpData.setItemVisual(idx, {
  136. symbol: symbol,
  137. symbolSize: symbolSize,
  138. symbolRotate: symbolRotate,
  139. symbolOffset: symbolOffset,
  140. symbolKeepAspect: symbolKeepAspect,
  141. style: style
  142. });
  143. });
  144. // TODO Text are wrong
  145. symbolDraw.updateData(mpData);
  146. this.group.add(symbolDraw.group);
  147. // Set host model for tooltip
  148. // FIXME
  149. mpData.eachItemGraphicEl(function (el) {
  150. el.traverse(function (child) {
  151. getECData(child).dataModel = mpModel;
  152. });
  153. });
  154. this.markKeep(symbolDraw);
  155. symbolDraw.group.silent = mpModel.get('silent') || seriesModel.get('silent');
  156. };
  157. MarkPointView.type = 'markPoint';
  158. return MarkPointView;
  159. }(MarkerView);
  160. function createData(coordSys, seriesModel, mpModel) {
  161. var coordDimsInfos;
  162. if (coordSys) {
  163. coordDimsInfos = map(coordSys && coordSys.dimensions, function (coordDim) {
  164. var info = seriesModel.getData().getDimensionInfo(seriesModel.getData().mapDimension(coordDim)) || {};
  165. // In map series data don't have lng and lat dimension. Fallback to same with coordSys
  166. return extend(extend({}, info), {
  167. name: coordDim,
  168. // DON'T use ordinalMeta to parse and collect ordinal.
  169. ordinalMeta: null
  170. });
  171. });
  172. } else {
  173. coordDimsInfos = [{
  174. name: 'value',
  175. type: 'float'
  176. }];
  177. }
  178. var mpData = new SeriesData(coordDimsInfos, mpModel);
  179. var dataOpt = map(mpModel.get('data'), curry(markerHelper.dataTransform, seriesModel));
  180. if (coordSys) {
  181. dataOpt = filter(dataOpt, curry(markerHelper.dataFilter, coordSys));
  182. }
  183. var dimValueGetter = markerHelper.createMarkerDimValueGetter(!!coordSys, coordDimsInfos);
  184. mpData.initData(dataOpt, null, dimValueGetter);
  185. return mpData;
  186. }
  187. export default MarkPointView;