ParallelAxisView.js 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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 AxisBuilder from './AxisBuilder.js';
  43. import BrushController from '../helper/BrushController.js';
  44. import * as brushHelper from '../helper/brushHelper.js';
  45. import * as graphic from '../../util/graphic.js';
  46. import ComponentView from '../../view/Component.js';
  47. var elementList = ['axisLine', 'axisTickLabel', 'axisName'];
  48. var ParallelAxisView = /** @class */function (_super) {
  49. __extends(ParallelAxisView, _super);
  50. function ParallelAxisView() {
  51. var _this = _super !== null && _super.apply(this, arguments) || this;
  52. _this.type = ParallelAxisView.type;
  53. return _this;
  54. }
  55. ParallelAxisView.prototype.init = function (ecModel, api) {
  56. _super.prototype.init.apply(this, arguments);
  57. (this._brushController = new BrushController(api.getZr())).on('brush', zrUtil.bind(this._onBrush, this));
  58. };
  59. ParallelAxisView.prototype.render = function (axisModel, ecModel, api, payload) {
  60. if (fromAxisAreaSelect(axisModel, ecModel, payload)) {
  61. return;
  62. }
  63. this.axisModel = axisModel;
  64. this.api = api;
  65. this.group.removeAll();
  66. var oldAxisGroup = this._axisGroup;
  67. this._axisGroup = new graphic.Group();
  68. this.group.add(this._axisGroup);
  69. if (!axisModel.get('show')) {
  70. return;
  71. }
  72. var coordSysModel = getCoordSysModel(axisModel, ecModel);
  73. var coordSys = coordSysModel.coordinateSystem;
  74. var areaSelectStyle = axisModel.getAreaSelectStyle();
  75. var areaWidth = areaSelectStyle.width;
  76. var dim = axisModel.axis.dim;
  77. var axisLayout = coordSys.getAxisLayout(dim);
  78. var builderOpt = zrUtil.extend({
  79. strokeContainThreshold: areaWidth
  80. }, axisLayout);
  81. var axisBuilder = new AxisBuilder(axisModel, builderOpt);
  82. zrUtil.each(elementList, axisBuilder.add, axisBuilder);
  83. this._axisGroup.add(axisBuilder.getGroup());
  84. this._refreshBrushController(builderOpt, areaSelectStyle, axisModel, coordSysModel, areaWidth, api);
  85. graphic.groupTransition(oldAxisGroup, this._axisGroup, axisModel);
  86. };
  87. // /**
  88. // * @override
  89. // */
  90. // updateVisual(axisModel, ecModel, api, payload) {
  91. // this._brushController && this._brushController
  92. // .updateCovers(getCoverInfoList(axisModel));
  93. // }
  94. ParallelAxisView.prototype._refreshBrushController = function (builderOpt, areaSelectStyle, axisModel, coordSysModel, areaWidth, api) {
  95. // After filtering, axis may change, select area needs to be update.
  96. var extent = axisModel.axis.getExtent();
  97. var extentLen = extent[1] - extent[0];
  98. var extra = Math.min(30, Math.abs(extentLen) * 0.1); // Arbitrary value.
  99. // width/height might be negative, which will be
  100. // normalized in BoundingRect.
  101. var rect = graphic.BoundingRect.create({
  102. x: extent[0],
  103. y: -areaWidth / 2,
  104. width: extentLen,
  105. height: areaWidth
  106. });
  107. rect.x -= extra;
  108. rect.width += 2 * extra;
  109. this._brushController.mount({
  110. enableGlobalPan: true,
  111. rotation: builderOpt.rotation,
  112. x: builderOpt.position[0],
  113. y: builderOpt.position[1]
  114. }).setPanels([{
  115. panelId: 'pl',
  116. clipPath: brushHelper.makeRectPanelClipPath(rect),
  117. isTargetByCursor: brushHelper.makeRectIsTargetByCursor(rect, api, coordSysModel),
  118. getLinearBrushOtherExtent: brushHelper.makeLinearBrushOtherExtent(rect, 0)
  119. }]).enableBrush({
  120. brushType: 'lineX',
  121. brushStyle: areaSelectStyle,
  122. removeOnClick: true
  123. }).updateCovers(getCoverInfoList(axisModel));
  124. };
  125. ParallelAxisView.prototype._onBrush = function (eventParam) {
  126. var coverInfoList = eventParam.areas;
  127. // Do not cache these object, because the mey be changed.
  128. var axisModel = this.axisModel;
  129. var axis = axisModel.axis;
  130. var intervals = zrUtil.map(coverInfoList, function (coverInfo) {
  131. return [axis.coordToData(coverInfo.range[0], true), axis.coordToData(coverInfo.range[1], true)];
  132. });
  133. // If realtime is true, action is not dispatched on drag end, because
  134. // the drag end emits the same params with the last drag move event,
  135. // and may have some delay when using touch pad.
  136. if (!axisModel.option.realtime === eventParam.isEnd || eventParam.removeOnClick) {
  137. // jshint ignore:line
  138. this.api.dispatchAction({
  139. type: 'axisAreaSelect',
  140. parallelAxisId: axisModel.id,
  141. intervals: intervals
  142. });
  143. }
  144. };
  145. ParallelAxisView.prototype.dispose = function () {
  146. this._brushController.dispose();
  147. };
  148. ParallelAxisView.type = 'parallelAxis';
  149. return ParallelAxisView;
  150. }(ComponentView);
  151. function fromAxisAreaSelect(axisModel, ecModel, payload) {
  152. return payload && payload.type === 'axisAreaSelect' && ecModel.findComponents({
  153. mainType: 'parallelAxis',
  154. query: payload
  155. })[0] === axisModel;
  156. }
  157. function getCoverInfoList(axisModel) {
  158. var axis = axisModel.axis;
  159. return zrUtil.map(axisModel.activeIntervals, function (interval) {
  160. return {
  161. brushType: 'lineX',
  162. panelId: 'pl',
  163. range: [axis.dataToCoord(interval[0], true), axis.dataToCoord(interval[1], true)]
  164. };
  165. });
  166. }
  167. function getCoordSysModel(axisModel, ecModel) {
  168. return ecModel.getComponent('parallel', axisModel.get('parallelIndex'));
  169. }
  170. export default ParallelAxisView;