RadarView.js 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  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 =
  50. /** @class */
  51. function (_super) {
  52. __extends(RadarView, _super);
  53. function RadarView() {
  54. var _this = _super !== null && _super.apply(this, arguments) || this;
  55. _this.type = RadarView.type;
  56. return _this;
  57. }
  58. RadarView.prototype.render = function (seriesModel, ecModel, api) {
  59. var polar = seriesModel.coordinateSystem;
  60. var group = this.group;
  61. var data = seriesModel.getData();
  62. var oldData = this._data;
  63. function createSymbol(data, idx) {
  64. var symbolType = data.getItemVisual(idx, 'symbol') || 'circle';
  65. if (symbolType === 'none') {
  66. return;
  67. }
  68. var symbolSize = symbolUtil.normalizeSymbolSize(data.getItemVisual(idx, 'symbolSize'));
  69. var symbolPath = symbolUtil.createSymbol(symbolType, -1, -1, 2, 2);
  70. var symbolRotate = data.getItemVisual(idx, 'symbolRotate') || 0;
  71. symbolPath.attr({
  72. style: {
  73. strokeNoScale: true
  74. },
  75. z2: 100,
  76. scaleX: symbolSize[0] / 2,
  77. scaleY: symbolSize[1] / 2,
  78. rotation: symbolRotate * Math.PI / 180 || 0
  79. });
  80. return symbolPath;
  81. }
  82. function updateSymbols(oldPoints, newPoints, symbolGroup, data, idx, isInit) {
  83. // Simply rerender all
  84. symbolGroup.removeAll();
  85. for (var i = 0; i < newPoints.length - 1; i++) {
  86. var symbolPath = createSymbol(data, idx);
  87. if (symbolPath) {
  88. symbolPath.__dimIdx = i;
  89. if (oldPoints[i]) {
  90. symbolPath.setPosition(oldPoints[i]);
  91. graphic[isInit ? 'initProps' : 'updateProps'](symbolPath, {
  92. x: newPoints[i][0],
  93. y: newPoints[i][1]
  94. }, seriesModel, idx);
  95. } else {
  96. symbolPath.setPosition(newPoints[i]);
  97. }
  98. symbolGroup.add(symbolPath);
  99. }
  100. }
  101. }
  102. function getInitialPoints(points) {
  103. return zrUtil.map(points, function (pt) {
  104. return [polar.cx, polar.cy];
  105. });
  106. }
  107. data.diff(oldData).add(function (idx) {
  108. var points = data.getItemLayout(idx);
  109. if (!points) {
  110. return;
  111. }
  112. var polygon = new graphic.Polygon();
  113. var polyline = new graphic.Polyline();
  114. var target = {
  115. shape: {
  116. points: points
  117. }
  118. };
  119. polygon.shape.points = getInitialPoints(points);
  120. polyline.shape.points = getInitialPoints(points);
  121. graphic.initProps(polygon, target, seriesModel, idx);
  122. graphic.initProps(polyline, target, seriesModel, idx);
  123. var itemGroup = new graphic.Group();
  124. var symbolGroup = new graphic.Group();
  125. itemGroup.add(polyline);
  126. itemGroup.add(polygon);
  127. itemGroup.add(symbolGroup);
  128. updateSymbols(polyline.shape.points, points, symbolGroup, data, idx, true);
  129. data.setItemGraphicEl(idx, itemGroup);
  130. }).update(function (newIdx, oldIdx) {
  131. var itemGroup = oldData.getItemGraphicEl(oldIdx);
  132. var polyline = itemGroup.childAt(0);
  133. var polygon = itemGroup.childAt(1);
  134. var symbolGroup = itemGroup.childAt(2);
  135. var target = {
  136. shape: {
  137. points: data.getItemLayout(newIdx)
  138. }
  139. };
  140. if (!target.shape.points) {
  141. return;
  142. }
  143. updateSymbols(polyline.shape.points, target.shape.points, symbolGroup, data, newIdx, false);
  144. saveOldStyle(polygon);
  145. saveOldStyle(polyline);
  146. graphic.updateProps(polyline, target, seriesModel);
  147. graphic.updateProps(polygon, target, seriesModel);
  148. data.setItemGraphicEl(newIdx, itemGroup);
  149. }).remove(function (idx) {
  150. group.remove(oldData.getItemGraphicEl(idx));
  151. }).execute();
  152. data.eachItemGraphicEl(function (itemGroup, idx) {
  153. var itemModel = data.getItemModel(idx);
  154. var polyline = itemGroup.childAt(0);
  155. var polygon = itemGroup.childAt(1);
  156. var symbolGroup = itemGroup.childAt(2); // 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(); // 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;