RadarView.js 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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 * as graphic from '../../util/graphic.js';
  42. import { setStatesStylesFromModel, toggleHoverEmphasis } from '../../util/states.js';
  43. import * as zrUtil from 'zrender/lib/core/util.js';
  44. import * as symbolUtil from '../../util/symbol.js';
  45. import ChartView from '../../view/Chart.js';
  46. import { SERIES_TYPE_RADAR } from './RadarSeries.js';
  47. import { setLabelStyle, getLabelStatesModels } from '../../label/labelStyle.js';
  48. import ZRImage from 'zrender/lib/graphic/Image.js';
  49. import { saveOldStyle } from '../../animation/basicTransition.js';
  50. var RadarView = /** @class */function (_super) {
  51. __extends(RadarView, _super);
  52. function RadarView() {
  53. var _this = _super !== null && _super.apply(this, arguments) || this;
  54. _this.type = SERIES_TYPE_RADAR;
  55. return _this;
  56. }
  57. RadarView.prototype.render = function (seriesModel, ecModel, api) {
  58. var polar = seriesModel.coordinateSystem;
  59. var group = this.group;
  60. var data = seriesModel.getData();
  61. var oldData = this._data;
  62. function createSymbol(data, idx) {
  63. var symbolType = data.getItemVisual(idx, 'symbol') || 'circle';
  64. if (symbolType === 'none') {
  65. return;
  66. }
  67. var symbolSize = symbolUtil.normalizeSymbolSize(data.getItemVisual(idx, 'symbolSize'));
  68. var symbolPath = symbolUtil.createSymbol(symbolType, -1, -1, 2, 2);
  69. var symbolRotate = data.getItemVisual(idx, 'symbolRotate') || 0;
  70. symbolPath.attr({
  71. style: {
  72. strokeNoScale: true
  73. },
  74. z2: 100,
  75. scaleX: symbolSize[0] / 2,
  76. scaleY: symbolSize[1] / 2,
  77. rotation: symbolRotate * Math.PI / 180 || 0
  78. });
  79. return symbolPath;
  80. }
  81. function updateSymbols(oldPoints, newPoints, symbolGroup, data, idx, isInit) {
  82. // Simply rerender all
  83. symbolGroup.removeAll();
  84. for (var i = 0; i < newPoints.length - 1; i++) {
  85. var symbolPath = createSymbol(data, idx);
  86. if (symbolPath) {
  87. symbolPath.__dimIdx = i;
  88. if (oldPoints[i]) {
  89. symbolPath.setPosition(oldPoints[i]);
  90. graphic[isInit ? 'initProps' : 'updateProps'](symbolPath, {
  91. x: newPoints[i][0],
  92. y: newPoints[i][1]
  93. }, seriesModel, idx);
  94. } else {
  95. symbolPath.setPosition(newPoints[i]);
  96. }
  97. symbolGroup.add(symbolPath);
  98. }
  99. }
  100. }
  101. function getInitialPoints(points) {
  102. return zrUtil.map(points, function (pt) {
  103. return [polar.cx, polar.cy];
  104. });
  105. }
  106. data.diff(oldData).add(function (idx) {
  107. var points = data.getItemLayout(idx);
  108. if (!points) {
  109. return;
  110. }
  111. var polygon = new graphic.Polygon();
  112. var polyline = new graphic.Polyline();
  113. var target = {
  114. shape: {
  115. points: points
  116. }
  117. };
  118. polygon.shape.points = getInitialPoints(points);
  119. polyline.shape.points = getInitialPoints(points);
  120. graphic.initProps(polygon, target, seriesModel, idx);
  121. graphic.initProps(polyline, target, seriesModel, idx);
  122. var itemGroup = new graphic.Group();
  123. var symbolGroup = new graphic.Group();
  124. itemGroup.add(polyline);
  125. itemGroup.add(polygon);
  126. itemGroup.add(symbolGroup);
  127. updateSymbols(polyline.shape.points, points, symbolGroup, data, idx, true);
  128. data.setItemGraphicEl(idx, itemGroup);
  129. }).update(function (newIdx, oldIdx) {
  130. var itemGroup = oldData.getItemGraphicEl(oldIdx);
  131. var polyline = itemGroup.childAt(0);
  132. var polygon = itemGroup.childAt(1);
  133. var symbolGroup = itemGroup.childAt(2);
  134. var target = {
  135. shape: {
  136. points: data.getItemLayout(newIdx)
  137. }
  138. };
  139. if (!target.shape.points) {
  140. return;
  141. }
  142. updateSymbols(polyline.shape.points, target.shape.points, symbolGroup, data, newIdx, false);
  143. saveOldStyle(polygon);
  144. saveOldStyle(polyline);
  145. graphic.updateProps(polyline, target, seriesModel);
  146. graphic.updateProps(polygon, target, seriesModel);
  147. data.setItemGraphicEl(newIdx, itemGroup);
  148. }).remove(function (idx) {
  149. group.remove(oldData.getItemGraphicEl(idx));
  150. }).execute();
  151. data.eachItemGraphicEl(function (itemGroup, idx) {
  152. var itemModel = data.getItemModel(idx);
  153. var polyline = itemGroup.childAt(0);
  154. var polygon = itemGroup.childAt(1);
  155. var symbolGroup = itemGroup.childAt(2);
  156. // Radar uses the visual encoded from itemStyle.
  157. var itemStyle = data.getItemVisual(idx, 'style');
  158. var color = itemStyle.fill;
  159. group.add(itemGroup);
  160. polyline.useStyle(zrUtil.defaults(itemModel.getModel('lineStyle').getLineStyle(), {
  161. fill: 'none',
  162. stroke: color
  163. }));
  164. setStatesStylesFromModel(polyline, itemModel, 'lineStyle');
  165. setStatesStylesFromModel(polygon, itemModel, 'areaStyle');
  166. var areaStyleModel = itemModel.getModel('areaStyle');
  167. var polygonIgnore = areaStyleModel.isEmpty() && areaStyleModel.parentModel.isEmpty();
  168. polygon.ignore = polygonIgnore;
  169. zrUtil.each(['emphasis', 'select', 'blur'], function (stateName) {
  170. var stateModel = itemModel.getModel([stateName, 'areaStyle']);
  171. var stateIgnore = stateModel.isEmpty() && stateModel.parentModel.isEmpty();
  172. // Won't be ignore if normal state is not ignore.
  173. polygon.ensureState(stateName).ignore = stateIgnore && polygonIgnore;
  174. var lineStyle = itemModel.getModel([stateName, 'lineStyle']).getLineStyle();
  175. polyline.ensureState(stateName).style = lineStyle;
  176. var areaStyle = stateModel.getAreaStyle();
  177. polygon.ensureState(stateName).style = areaStyle;
  178. var itemStateStyle = itemModel.getModel([stateName, 'itemStyle']).getItemStyle();
  179. symbolGroup.eachChild(function (symbolPath) {
  180. symbolPath.ensureState(stateName).style = zrUtil.clone(itemStateStyle);
  181. });
  182. });
  183. polygon.useStyle(zrUtil.defaults(itemModel.getModel('areaStyle').getAreaStyle(), {
  184. fill: color,
  185. opacity: 0.7,
  186. decal: itemStyle.decal
  187. }));
  188. var emphasisModel = itemModel.getModel('emphasis');
  189. symbolGroup.eachChild(function (symbolPath) {
  190. if (symbolPath instanceof ZRImage) {
  191. var pathStyle = symbolPath.style;
  192. symbolPath.useStyle(zrUtil.extend({
  193. // TODO other properties like x, y ?
  194. image: pathStyle.image,
  195. x: pathStyle.x,
  196. y: pathStyle.y,
  197. width: pathStyle.width,
  198. height: pathStyle.height
  199. }, itemStyle));
  200. } else {
  201. symbolPath.useStyle(itemStyle);
  202. symbolPath.setColor(color);
  203. symbolPath.style.strokeNoScale = true;
  204. }
  205. var defaultText = data.getStore().get(data.getDimensionIndex(symbolPath.__dimIdx), idx);
  206. (defaultText == null || isNaN(defaultText)) && (defaultText = '');
  207. setLabelStyle(symbolPath, getLabelStatesModels(itemModel), {
  208. labelFetcher: data.hostModel,
  209. labelDataIndex: idx,
  210. labelDimIndex: symbolPath.__dimIdx,
  211. defaultText: defaultText,
  212. inheritColor: color,
  213. defaultOpacity: itemStyle.opacity
  214. });
  215. });
  216. toggleHoverEmphasis(itemGroup, emphasisModel.get('focus'), emphasisModel.get('blurScope'), emphasisModel.get('disabled'));
  217. });
  218. this._data = data;
  219. };
  220. RadarView.prototype.remove = function () {
  221. this.group.removeAll();
  222. this._data = null;
  223. };
  224. RadarView.type = SERIES_TYPE_RADAR;
  225. return RadarView;
  226. }(ChartView);
  227. export default RadarView;