PiecewiseView.js 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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 zrUtil from 'zrender/lib/core/util.js';
  42. import VisualMapView from './VisualMapView.js';
  43. import * as graphic from '../../util/graphic.js';
  44. import { createSymbol } from '../../util/symbol.js';
  45. import * as layout from '../../util/layout.js';
  46. import * as helper from './helper.js';
  47. import { createTextStyle } from '../../label/labelStyle.js';
  48. var PiecewiseVisualMapView = /** @class */function (_super) {
  49. __extends(PiecewiseVisualMapView, _super);
  50. function PiecewiseVisualMapView() {
  51. var _this = _super !== null && _super.apply(this, arguments) || this;
  52. _this.type = PiecewiseVisualMapView.type;
  53. return _this;
  54. }
  55. PiecewiseVisualMapView.prototype.doRender = function () {
  56. var thisGroup = this.group;
  57. thisGroup.removeAll();
  58. var visualMapModel = this.visualMapModel;
  59. var textGap = visualMapModel.get('textGap');
  60. var textStyleModel = visualMapModel.textStyleModel;
  61. var textFont = textStyleModel.getFont();
  62. var textFill = textStyleModel.getTextColor();
  63. var itemAlign = this._getItemAlign();
  64. var itemSize = visualMapModel.itemSize;
  65. var viewData = this._getViewData();
  66. var endsText = viewData.endsText;
  67. var showLabel = zrUtil.retrieve(visualMapModel.get('showLabel', true), !endsText);
  68. var silent = !visualMapModel.get('selectedMode');
  69. endsText && this._renderEndsText(thisGroup, endsText[0], itemSize, showLabel, itemAlign);
  70. zrUtil.each(viewData.viewPieceList, function (item) {
  71. var piece = item.piece;
  72. var itemGroup = new graphic.Group();
  73. itemGroup.onclick = zrUtil.bind(this._onItemClick, this, piece);
  74. this._enableHoverLink(itemGroup, item.indexInModelPieceList);
  75. // TODO Category
  76. var representValue = visualMapModel.getRepresentValue(piece);
  77. this._createItemSymbol(itemGroup, representValue, [0, 0, itemSize[0], itemSize[1]], silent);
  78. if (showLabel) {
  79. var visualState = this.visualMapModel.getValueState(representValue);
  80. itemGroup.add(new graphic.Text({
  81. style: {
  82. x: itemAlign === 'right' ? -textGap : itemSize[0] + textGap,
  83. y: itemSize[1] / 2,
  84. text: piece.text,
  85. verticalAlign: 'middle',
  86. align: itemAlign,
  87. font: textFont,
  88. fill: textFill,
  89. opacity: visualState === 'outOfRange' ? 0.5 : 1
  90. },
  91. silent: silent
  92. }));
  93. }
  94. thisGroup.add(itemGroup);
  95. }, this);
  96. endsText && this._renderEndsText(thisGroup, endsText[1], itemSize, showLabel, itemAlign);
  97. layout.box(visualMapModel.get('orient'), thisGroup, visualMapModel.get('itemGap'));
  98. this.renderBackground(thisGroup);
  99. this.positionGroup(thisGroup);
  100. };
  101. PiecewiseVisualMapView.prototype._enableHoverLink = function (itemGroup, pieceIndex) {
  102. var _this = this;
  103. itemGroup.on('mouseover', function () {
  104. return onHoverLink('highlight');
  105. }).on('mouseout', function () {
  106. return onHoverLink('downplay');
  107. });
  108. var onHoverLink = function (method) {
  109. var visualMapModel = _this.visualMapModel;
  110. // TODO: TYPE More detailed action types
  111. visualMapModel.option.hoverLink && _this.api.dispatchAction({
  112. type: method,
  113. batch: helper.makeHighDownBatch(visualMapModel.findTargetDataIndices(pieceIndex), visualMapModel)
  114. });
  115. };
  116. };
  117. PiecewiseVisualMapView.prototype._getItemAlign = function () {
  118. var visualMapModel = this.visualMapModel;
  119. var modelOption = visualMapModel.option;
  120. if (modelOption.orient === 'vertical') {
  121. return helper.getItemAlign(visualMapModel, this.api, visualMapModel.itemSize);
  122. } else {
  123. // horizontal, most case left unless specifying right.
  124. var align = modelOption.align;
  125. if (!align || align === 'auto') {
  126. align = 'left';
  127. }
  128. return align;
  129. }
  130. };
  131. PiecewiseVisualMapView.prototype._renderEndsText = function (group, text, itemSize, showLabel, itemAlign) {
  132. if (!text) {
  133. return;
  134. }
  135. var itemGroup = new graphic.Group();
  136. var textStyleModel = this.visualMapModel.textStyleModel;
  137. itemGroup.add(new graphic.Text({
  138. style: createTextStyle(textStyleModel, {
  139. x: showLabel ? itemAlign === 'right' ? itemSize[0] : 0 : itemSize[0] / 2,
  140. y: itemSize[1] / 2,
  141. verticalAlign: 'middle',
  142. align: showLabel ? itemAlign : 'center',
  143. text: text
  144. })
  145. }));
  146. group.add(itemGroup);
  147. };
  148. /**
  149. * @private
  150. * @return {Object} {peiceList, endsText} The order is the same as screen pixel order.
  151. */
  152. PiecewiseVisualMapView.prototype._getViewData = function () {
  153. var visualMapModel = this.visualMapModel;
  154. var viewPieceList = zrUtil.map(visualMapModel.getPieceList(), function (piece, index) {
  155. return {
  156. piece: piece,
  157. indexInModelPieceList: index
  158. };
  159. });
  160. var endsText = visualMapModel.get('text');
  161. // Consider orient and inverse.
  162. var orient = visualMapModel.get('orient');
  163. var inverse = visualMapModel.get('inverse');
  164. // Order of model pieceList is always [low, ..., high]
  165. if (orient === 'horizontal' ? inverse : !inverse) {
  166. viewPieceList.reverse();
  167. }
  168. // Origin order of endsText is [high, low]
  169. else if (endsText) {
  170. endsText = endsText.slice().reverse();
  171. }
  172. return {
  173. viewPieceList: viewPieceList,
  174. endsText: endsText
  175. };
  176. };
  177. PiecewiseVisualMapView.prototype._createItemSymbol = function (group, representValue, shapeParam, silent) {
  178. var itemSymbol = createSymbol(
  179. // symbol will be string
  180. this.getControllerVisual(representValue, 'symbol'), shapeParam[0], shapeParam[1], shapeParam[2], shapeParam[3],
  181. // color will be string
  182. this.getControllerVisual(representValue, 'color'));
  183. itemSymbol.silent = silent;
  184. group.add(itemSymbol);
  185. };
  186. PiecewiseVisualMapView.prototype._onItemClick = function (piece) {
  187. var visualMapModel = this.visualMapModel;
  188. var option = visualMapModel.option;
  189. var selectedMode = option.selectedMode;
  190. if (!selectedMode) {
  191. return;
  192. }
  193. var selected = zrUtil.clone(option.selected);
  194. var newKey = visualMapModel.getSelectedMapKey(piece);
  195. if (selectedMode === 'single' || selectedMode === true) {
  196. selected[newKey] = true;
  197. zrUtil.each(selected, function (o, key) {
  198. selected[key] = key === newKey;
  199. });
  200. } else {
  201. selected[newKey] = !selected[newKey];
  202. }
  203. this.api.dispatchAction({
  204. type: 'selectDataRange',
  205. from: this.uid,
  206. visualMapId: this.visualMapModel.id,
  207. selected: selected
  208. });
  209. };
  210. PiecewiseVisualMapView.type = 'visualMap.piecewise';
  211. return PiecewiseVisualMapView;
  212. }(VisualMapView);
  213. export default PiecewiseVisualMapView;