ParallelAxisView.js 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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 =
  49. /** @class */
  50. function (_super) {
  51. __extends(ParallelAxisView, _super);
  52. function ParallelAxisView() {
  53. var _this = _super !== null && _super.apply(this, arguments) || this;
  54. _this.type = ParallelAxisView.type;
  55. return _this;
  56. }
  57. ParallelAxisView.prototype.init = function (ecModel, api) {
  58. _super.prototype.init.apply(this, arguments);
  59. (this._brushController = new BrushController(api.getZr())).on('brush', zrUtil.bind(this._onBrush, this));
  60. };
  61. ParallelAxisView.prototype.render = function (axisModel, ecModel, api, payload) {
  62. if (fromAxisAreaSelect(axisModel, ecModel, payload)) {
  63. return;
  64. }
  65. this.axisModel = axisModel;
  66. this.api = api;
  67. this.group.removeAll();
  68. var oldAxisGroup = this._axisGroup;
  69. this._axisGroup = new graphic.Group();
  70. this.group.add(this._axisGroup);
  71. if (!axisModel.get('show')) {
  72. return;
  73. }
  74. var coordSysModel = getCoordSysModel(axisModel, ecModel);
  75. var coordSys = coordSysModel.coordinateSystem;
  76. var areaSelectStyle = axisModel.getAreaSelectStyle();
  77. var areaWidth = areaSelectStyle.width;
  78. var dim = axisModel.axis.dim;
  79. var axisLayout = coordSys.getAxisLayout(dim);
  80. var builderOpt = zrUtil.extend({
  81. strokeContainThreshold: areaWidth
  82. }, axisLayout);
  83. var axisBuilder = new AxisBuilder(axisModel, builderOpt);
  84. zrUtil.each(elementList, axisBuilder.add, axisBuilder);
  85. this._axisGroup.add(axisBuilder.getGroup());
  86. this._refreshBrushController(builderOpt, areaSelectStyle, axisModel, coordSysModel, areaWidth, api);
  87. graphic.groupTransition(oldAxisGroup, this._axisGroup, axisModel);
  88. }; // /**
  89. // * @override
  90. // */
  91. // updateVisual(axisModel, ecModel, api, payload) {
  92. // this._brushController && this._brushController
  93. // .updateCovers(getCoverInfoList(axisModel));
  94. // }
  95. ParallelAxisView.prototype._refreshBrushController = function (builderOpt, areaSelectStyle, axisModel, coordSysModel, areaWidth, api) {
  96. // After filtering, axis may change, select area needs to be update.
  97. var extent = axisModel.axis.getExtent();
  98. var extentLen = extent[1] - extent[0];
  99. var extra = Math.min(30, Math.abs(extentLen) * 0.1); // Arbitrary value.
  100. // width/height might be negative, which will be
  101. // normalized in BoundingRect.
  102. var rect = graphic.BoundingRect.create({
  103. x: extent[0],
  104. y: -areaWidth / 2,
  105. width: extentLen,
  106. height: areaWidth
  107. });
  108. rect.x -= extra;
  109. rect.width += 2 * extra;
  110. this._brushController.mount({
  111. enableGlobalPan: true,
  112. rotation: builderOpt.rotation,
  113. x: builderOpt.position[0],
  114. y: builderOpt.position[1]
  115. }).setPanels([{
  116. panelId: 'pl',
  117. clipPath: brushHelper.makeRectPanelClipPath(rect),
  118. isTargetByCursor: brushHelper.makeRectIsTargetByCursor(rect, api, coordSysModel),
  119. getLinearBrushOtherExtent: brushHelper.makeLinearBrushOtherExtent(rect, 0)
  120. }]).enableBrush({
  121. brushType: 'lineX',
  122. brushStyle: areaSelectStyle,
  123. removeOnClick: true
  124. }).updateCovers(getCoverInfoList(axisModel));
  125. };
  126. ParallelAxisView.prototype._onBrush = function (eventParam) {
  127. var coverInfoList = eventParam.areas; // 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. }); // 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;