roamHelper.js 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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 View, { getOwnRoamViewCoordSys, ownRoamModelCoordSysUpdateInAction, ownRoamViewUpdateDirectlyInAction, viewCoordSysSetBoundingRect, viewCoordSysSetViewRect, useLegacyViewCoordSysCenterBase, viewCoordSysSetRoamOptionFromModel } from '../../coord/View.js';
  41. import { COMPONENT_MAIN_TYPE_SERIES, ROAM_ACTION_TYPE_SUFFIX } from '../../util/types.js';
  42. import { BoundingRect, payloadDisableAnimation } from '../../util/graphic.js';
  43. import { makeQueryConditionKindA } from '../../util/model.js';
  44. import { defaults, retrieve2 } from 'zrender/lib/core/util.js';
  45. /**
  46. * An abstraction for some similar impl in roaming.
  47. *
  48. * Require action like `registerRoamActionSimply`.
  49. */
  50. export function updateRoamControllerSimply(componentOrSeries, api, controller,
  51. // Can use `createIsInSelfByPointerCheckerEl`
  52. isInSelf, clipRect, extraOnRoam, roamTypeDefault, geoBackwardCompat) {
  53. var coordSys = getOwnRoamViewCoordSys(componentOrSeries);
  54. if (!coordSys) {
  55. controller.disable();
  56. return;
  57. }
  58. controller.enable(
  59. // NOTE:
  60. // If roamTypeDefault is null/undefined, roamType will be set as true.
  61. // PENDING:
  62. // In MapSeries case, it has long been retrieving `roam` option from the first MapSeries
  63. // that are not filtered out by a legend. But that requires `roam: true` to be set in all
  64. // MapSeries option, otherwise if a legend hides the `roam: true` MapSeries, the map can
  65. // not be roamed unexpectedly.
  66. retrieve2(componentOrSeries.get('roam'), roamTypeDefault), {
  67. api: api,
  68. zInfo: {
  69. component: componentOrSeries
  70. },
  71. triggerInfo: {
  72. roamTrigger: componentOrSeries.get('roamTrigger'),
  73. isInSelf: isInSelf,
  74. isInClip: function (e, x, y) {
  75. return !clipRect || clipRect.contain(x, y);
  76. }
  77. }
  78. });
  79. function dispatchAction(extra) {
  80. var mainType = componentOrSeries.mainType;
  81. var payload = payloadDisableAnimation(defaults({
  82. type: makeViewCoordSysActionType(mainType, componentOrSeries.subType, ROAM_ACTION_TYPE_SUFFIX)
  83. }, extra));
  84. if (geoBackwardCompat) {
  85. payload.componentType = mainType;
  86. }
  87. // Like `seriesId`, `geoId`.
  88. payload[mainType + "Id"] = componentOrSeries.id;
  89. api.dispatchAction(payload);
  90. }
  91. controller.off('pan').off('zoom')
  92. // NOTICE: 'pan' and 'zoom' listener should do nothing except `api.dispatchAction`,
  93. // the rest logic should be performed in the action handler and `updateTransform`;
  94. // otherwise, it can cause inconsistency if users trigger this action explicitly.
  95. .on('pan', function (event) {
  96. extraOnRoam && extraOnRoam('pan');
  97. dispatchAction({
  98. dx: event.dx,
  99. dy: event.dy
  100. });
  101. }).on('zoom', function (event) {
  102. extraOnRoam && extraOnRoam('zoom');
  103. dispatchAction({
  104. zoom: event.scale,
  105. originX: event.originX,
  106. originY: event.originY
  107. });
  108. });
  109. }
  110. export function createIsInSelfByPointerCheckerEl(pointerCheckerEl) {
  111. return function (e, x, y) {
  112. tmpRectCII.copy(pointerCheckerEl.getBoundingRect());
  113. tmpRectCII.applyTransform(pointerCheckerEl.getComputedTransform());
  114. return tmpRectCII.contain(x, y);
  115. };
  116. }
  117. var tmpRectCII = new BoundingRect(0, 0, 0, 0);
  118. export function registerRoamActionSimply(registers, mainType, subType) {
  119. var actionType = makeViewCoordSysActionType(mainType, subType, ROAM_ACTION_TYPE_SUFFIX);
  120. registers.registerAction({
  121. type: actionType,
  122. event: actionType,
  123. // If `mainType` is a coord sys, 'update:' should be 'updateTransform' to
  124. // broadcast the update. But currently there is no such case required.
  125. // If 'updateTransform' is used, the owner of VIEW_COORD_SYS update firstly
  126. // in the action handler as follows, and then series and components laid
  127. // out on this VIEW_COORD_SYS update in `View['updateTransform']`.
  128. update: 'none'
  129. }, function (payload, ecModel, api) {
  130. ecModel.eachComponent(makeQueryConditionKindA(payload, mainType, subType), function (componentOrSeries) {
  131. ownRoamModelCoordSysUpdateInAction(payload, componentOrSeries);
  132. ownRoamViewUpdateDirectlyInAction(payload, componentOrSeries, ecModel, api);
  133. });
  134. });
  135. }
  136. function makeViewCoordSysActionType(mainType, subType, suffix) {
  137. // e.g. 'treeRoam', 'sankeyRoam', 'geoRoam'
  138. return (mainType !== COMPONENT_MAIN_TYPE_SERIES ? mainType : subType === 'map' ? 'geo' // Historical setting.
  139. : subType) + suffix;
  140. }
  141. export function isRoamPayloadHasZoom(payload) {
  142. return payload.zoom != null;
  143. }
  144. export function createViewCoordSysSimply(componentOrSeries, api,
  145. // VIEW_COORD_SYS DataRect init:
  146. x, y, width, height,
  147. // VIEW_COORD_SYS ViewRect init:
  148. // Use DataRect by default, which means DataRect is in pixel space.
  149. viewRect) {
  150. var viewCoordSys = new View(null, useLegacyViewCoordSysCenterBase(componentOrSeries.ecModel, api));
  151. viewCoordSysSetBoundingRect(viewCoordSys, x, y, width, height);
  152. viewRect ? viewCoordSysSetViewRect(viewCoordSys, viewRect.x, viewRect.y, viewRect.width, viewRect.height) : viewCoordSysSetViewRect(viewCoordSys, x, y, width, height);
  153. viewCoordSysSetRoamOptionFromModel(viewCoordSys, componentOrSeries);
  154. return viewCoordSys;
  155. }