6c76e2b12dd477431389e1baf48fef197e49cffe1016e3d6a6963b62635f18c7205f24d3a512e58e8133a7370586993ab47b6dc1a1679d92b55dbe7a0f8d36 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. import BoundingRect from 'zrender/lib/core/BoundingRect.js';
  2. import { BoxLayoutOptionMixin, ComponentLayoutMode } from './types.js';
  3. import Group from 'zrender/lib/graphic/Group.js';
  4. import Element from 'zrender/lib/Element.js';
  5. export interface LayoutRect extends BoundingRect {
  6. margin: number[];
  7. }
  8. export interface NewlineElement extends Element {
  9. newline: boolean;
  10. }
  11. /**
  12. * @public
  13. */
  14. export declare const LOCATION_PARAMS: readonly ["left", "right", "top", "bottom", "width", "height"];
  15. /**
  16. * @public
  17. */
  18. export declare const HV_NAMES: readonly [readonly ["width", "left", "right"], readonly ["height", "top", "bottom"]];
  19. declare function boxLayout(orient: 'horizontal' | 'vertical', group: Group, gap: number, maxWidth?: number, maxHeight?: number): void;
  20. /**
  21. * VBox or HBox layouting
  22. * @param {string} orient
  23. * @param {module:zrender/graphic/Group} group
  24. * @param {number} gap
  25. * @param {number} [width=Infinity]
  26. * @param {number} [height=Infinity]
  27. */
  28. export declare const box: typeof boxLayout;
  29. /**
  30. * VBox layouting
  31. * @param {module:zrender/graphic/Group} group
  32. * @param {number} gap
  33. * @param {number} [width=Infinity]
  34. * @param {number} [height=Infinity]
  35. */
  36. export declare const vbox: (group: Group, gap: number, maxWidth?: number, maxHeight?: number) => void;
  37. /**
  38. * HBox layouting
  39. * @param {module:zrender/graphic/Group} group
  40. * @param {number} gap
  41. * @param {number} [width=Infinity]
  42. * @param {number} [height=Infinity]
  43. */
  44. export declare const hbox: (group: Group, gap: number, maxWidth?: number, maxHeight?: number) => void;
  45. /**
  46. * If x or x2 is not specified or 'center' 'left' 'right',
  47. * the width would be as long as possible.
  48. * If y or y2 is not specified or 'middle' 'top' 'bottom',
  49. * the height would be as long as possible.
  50. */
  51. export declare function getAvailableSize(positionInfo: {
  52. left?: number | string;
  53. top?: number | string;
  54. right?: number | string;
  55. bottom?: number | string;
  56. }, containerRect: {
  57. width: number;
  58. height: number;
  59. }, margin?: number[] | number): {
  60. width: number;
  61. height: number;
  62. };
  63. /**
  64. * Parse position info.
  65. */
  66. export declare function getLayoutRect(positionInfo: BoxLayoutOptionMixin & {
  67. aspect?: number;
  68. }, containerRect: {
  69. width: number;
  70. height: number;
  71. }, margin?: number | number[]): LayoutRect;
  72. /**
  73. * Position a zr element in viewport
  74. * Group position is specified by either
  75. * {left, top}, {right, bottom}
  76. * If all properties exists, right and bottom will be igonred.
  77. *
  78. * Logic:
  79. * 1. Scale (against origin point in parent coord)
  80. * 2. Rotate (against origin point in parent coord)
  81. * 3. Traslate (with el.position by this method)
  82. * So this method only fixes the last step 'Traslate', which does not affect
  83. * scaling and rotating.
  84. *
  85. * If be called repeatly with the same input el, the same result will be gotten.
  86. *
  87. * Return true if the layout happend.
  88. *
  89. * @param el Should have `getBoundingRect` method.
  90. * @param positionInfo
  91. * @param positionInfo.left
  92. * @param positionInfo.top
  93. * @param positionInfo.right
  94. * @param positionInfo.bottom
  95. * @param positionInfo.width Only for opt.boundingModel: 'raw'
  96. * @param positionInfo.height Only for opt.boundingModel: 'raw'
  97. * @param containerRect
  98. * @param margin
  99. * @param opt
  100. * @param opt.hv Only horizontal or only vertical. Default to be [1, 1]
  101. * @param opt.boundingMode
  102. * Specify how to calculate boundingRect when locating.
  103. * 'all': Position the boundingRect that is transformed and uioned
  104. * both itself and its descendants.
  105. * This mode simplies confine the elements in the bounding
  106. * of their container (e.g., using 'right: 0').
  107. * 'raw': Position the boundingRect that is not transformed and only itself.
  108. * This mode is useful when you want a element can overflow its
  109. * container. (Consider a rotated circle needs to be located in a corner.)
  110. * In this mode positionInfo.width/height can only be number.
  111. */
  112. export declare function positionElement(el: Element, positionInfo: BoxLayoutOptionMixin, containerRect: {
  113. width: number;
  114. height: number;
  115. }, margin?: number[] | number, opt?: {
  116. hv: [1 | 0 | boolean, 1 | 0 | boolean];
  117. boundingMode: 'all' | 'raw';
  118. }, out?: {
  119. x?: number;
  120. y?: number;
  121. }): boolean;
  122. /**
  123. * @param option Contains some of the properties in HV_NAMES.
  124. * @param hvIdx 0: horizontal; 1: vertical.
  125. */
  126. export declare function sizeCalculable(option: BoxLayoutOptionMixin, hvIdx: number): boolean;
  127. export declare function fetchLayoutMode(ins: any): ComponentLayoutMode;
  128. /**
  129. * Consider Case:
  130. * When default option has {left: 0, width: 100}, and we set {right: 0}
  131. * through setOption or media query, using normal zrUtil.merge will cause
  132. * {right: 0} does not take effect.
  133. *
  134. * @example
  135. * ComponentModel.extend({
  136. * init: function () {
  137. * ...
  138. * let inputPositionParams = layout.getLayoutParams(option);
  139. * this.mergeOption(inputPositionParams);
  140. * },
  141. * mergeOption: function (newOption) {
  142. * newOption && zrUtil.merge(thisOption, newOption, true);
  143. * layout.mergeLayoutParam(thisOption, newOption);
  144. * }
  145. * });
  146. *
  147. * @param targetOption
  148. * @param newOption
  149. * @param opt
  150. */
  151. export declare function mergeLayoutParam<T extends BoxLayoutOptionMixin>(targetOption: T, newOption: T, opt?: ComponentLayoutMode): void;
  152. /**
  153. * Retrieve 'left', 'right', 'top', 'bottom', 'width', 'height' from object.
  154. */
  155. export declare function getLayoutParams(source: BoxLayoutOptionMixin): BoxLayoutOptionMixin;
  156. /**
  157. * Retrieve 'left', 'right', 'top', 'bottom', 'width', 'height' from object.
  158. * @param {Object} source
  159. * @return {Object} Result contains those props.
  160. */
  161. export declare function copyLayoutParams(target: BoxLayoutOptionMixin, source: BoxLayoutOptionMixin): BoxLayoutOptionMixin;
  162. export {};