ParallelAxisView.js 6.6 KB

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