RadarView.js 8.7 KB

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