ParallelAxisView.js 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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. var echarts = require("../../echarts");
  20. var zrUtil = require("zrender/lib/core/util");
  21. var AxisBuilder = require("./AxisBuilder");
  22. var BrushController = require("../helper/BrushController");
  23. var brushHelper = require("../helper/brushHelper");
  24. var graphic = require("../../util/graphic");
  25. /*
  26. * Licensed to the Apache Software Foundation (ASF) under one
  27. * or more contributor license agreements. See the NOTICE file
  28. * distributed with this work for additional information
  29. * regarding copyright ownership. The ASF licenses this file
  30. * to you under the Apache License, Version 2.0 (the
  31. * "License"); you may not use this file except in compliance
  32. * with the License. You may obtain a copy of the License at
  33. *
  34. * http://www.apache.org/licenses/LICENSE-2.0
  35. *
  36. * Unless required by applicable law or agreed to in writing,
  37. * software distributed under the License is distributed on an
  38. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  39. * KIND, either express or implied. See the License for the
  40. * specific language governing permissions and limitations
  41. * under the License.
  42. */
  43. var elementList = ['axisLine', 'axisTickLabel', 'axisName'];
  44. var AxisView = echarts.extendComponentView({
  45. type: 'parallelAxis',
  46. /**
  47. * @override
  48. */
  49. init: function (ecModel, api) {
  50. AxisView.superApply(this, 'init', arguments);
  51. /**
  52. * @type {module:echarts/component/helper/BrushController}
  53. */
  54. (this._brushController = new BrushController(api.getZr())).on('brush', zrUtil.bind(this._onBrush, this));
  55. },
  56. /**
  57. * @override
  58. */
  59. 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. var animationModel = payload && payload.animation === false ? null : axisModel;
  86. graphic.groupTransition(oldAxisGroup, this._axisGroup, animationModel);
  87. },
  88. // /**
  89. // * @override
  90. // */
  91. // updateVisual: function (axisModel, ecModel, api, payload) {
  92. // this._brushController && this._brushController
  93. // .updateCovers(getCoverInfoList(axisModel));
  94. // },
  95. _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. position: builderOpt.position
  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. _onBrush: function (coverInfoList, opt) {
  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. }); // If realtime is true, action is not dispatched on drag end, because
  132. // the drag end emits the same params with the last drag move event,
  133. // and may have some delay when using touch pad.
  134. if (!axisModel.option.realtime === opt.isEnd || opt.removeOnClick) {
  135. // jshint ignore:line
  136. this.api.dispatchAction({
  137. type: 'axisAreaSelect',
  138. parallelAxisId: axisModel.id,
  139. intervals: intervals
  140. });
  141. }
  142. },
  143. /**
  144. * @override
  145. */
  146. dispose: function () {
  147. this._brushController.dispose();
  148. }
  149. });
  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. var _default = AxisView;
  170. module.exports = _default;