b96e81a89bf7c53ef0ba33fe39e9eece8b51a4a7d0ba4f5261cb9e71cb5bb88995f6f94882e831ecfac10cf816248b69790467d4ef6b050b5ae6555eb64480 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. import Eventful from 'zrender/lib/core/Eventful.js';
  2. import * as graphic from '../../util/graphic.js';
  3. import { Dictionary } from '../../util/types.js';
  4. import { ZRenderType } from 'zrender/lib/zrender.js';
  5. import { ElementEvent } from 'zrender/lib/Element.js';
  6. import * as matrix from 'zrender/lib/core/matrix.js';
  7. import { PathStyleProps } from 'zrender/lib/graphic/Path.js';
  8. /**
  9. * BrushController not only used in "brush component",
  10. * but also used in "tooltip DataZoom", and other possible
  11. * futher brush behavior related scenarios.
  12. * So `BrushController` should not depends on "brush component model".
  13. */
  14. export declare type BrushType = 'polygon' | 'rect' | 'lineX' | 'lineY';
  15. /**
  16. * Only for drawing (after enabledBrush).
  17. * 'line', 'rect', 'polygon' or false
  18. * If passing false/null/undefined, disable brush.
  19. * If passing 'auto', determined by panel.defaultBrushType
  20. */
  21. export declare type BrushTypeUncertain = BrushType | false | 'auto';
  22. export declare type BrushMode = 'single' | 'multiple';
  23. export declare type BrushDimensionMinMax = number[];
  24. export declare type BrushAreaRange = BrushDimensionMinMax | BrushDimensionMinMax[];
  25. export interface BrushCoverConfig {
  26. brushType: BrushType;
  27. id?: string;
  28. range?: BrushAreaRange;
  29. panelId?: string;
  30. brushMode?: BrushMode;
  31. brushStyle?: Pick<PathStyleProps, BrushStyleKey>;
  32. transformable?: boolean;
  33. removeOnClick?: boolean;
  34. z?: number;
  35. }
  36. /**
  37. * `BrushAreaCreatorOption` input to brushModel via `setBrushOption`,
  38. * merge and convert to `BrushCoverCreatorConfig`.
  39. */
  40. export interface BrushCoverCreatorConfig extends Pick<BrushCoverConfig, 'brushMode' | 'transformable' | 'removeOnClick' | 'brushStyle' | 'z'> {
  41. brushType: BrushTypeUncertain;
  42. }
  43. declare type BrushStyleKey = 'fill' | 'stroke' | 'lineWidth' | 'opacity' | 'shadowBlur' | 'shadowOffsetX' | 'shadowOffsetY' | 'shadowColor';
  44. declare const BRUSH_PANEL_GLOBAL: true;
  45. export interface BrushPanelConfig {
  46. panelId: string;
  47. clipPath(localPoints: number[][], transform: matrix.MatrixArray): number[][];
  48. isTargetByCursor(e: ElementEvent, localCursorPoint: number[], transform: matrix.MatrixArray): boolean;
  49. defaultBrushType?: BrushType;
  50. getLinearBrushOtherExtent?(xyIndex: number): number[];
  51. }
  52. declare type BrushPanelConfigOrGlobal = BrushPanelConfig | typeof BRUSH_PANEL_GLOBAL;
  53. interface BrushCover extends graphic.Group {
  54. __brushOption: BrushCoverConfig;
  55. }
  56. export interface BrushControllerEvents {
  57. brush: {
  58. areas: {
  59. brushType: BrushType;
  60. panelId: string;
  61. range: BrushAreaRange;
  62. }[];
  63. isEnd: boolean;
  64. removeOnClick: boolean;
  65. };
  66. }
  67. /**
  68. * params:
  69. * areas: Array.<Array>, coord relates to container group,
  70. * If no container specified, to global.
  71. * opt {
  72. * isEnd: boolean,
  73. * removeOnClick: boolean
  74. * }
  75. */
  76. declare class BrushController extends Eventful<{
  77. [key in keyof BrushControllerEvents]: (params: BrushControllerEvents[key]) => void | undefined;
  78. }> {
  79. readonly group: graphic.Group;
  80. /**
  81. * @internal
  82. */
  83. _zr: ZRenderType;
  84. /**
  85. * @internal
  86. */
  87. _brushType: BrushTypeUncertain;
  88. /**
  89. * @internal
  90. * Only for drawing (after enabledBrush).
  91. */
  92. _brushOption: BrushCoverCreatorConfig;
  93. /**
  94. * @internal
  95. * Key: panelId
  96. */
  97. _panels: Dictionary<BrushPanelConfig>;
  98. /**
  99. * @internal
  100. */
  101. _track: number[][];
  102. /**
  103. * @internal
  104. */
  105. _dragging: boolean;
  106. /**
  107. * @internal
  108. */
  109. _covers: BrushCover[];
  110. /**
  111. * @internal
  112. */
  113. _creatingCover: BrushCover;
  114. /**
  115. * @internal
  116. */
  117. _creatingPanel: BrushPanelConfigOrGlobal;
  118. private _enableGlobalPan;
  119. private _mounted;
  120. /**
  121. * @internal
  122. */
  123. _transform: matrix.MatrixArray;
  124. private _uid;
  125. private _handlers;
  126. constructor(zr: ZRenderType);
  127. /**
  128. * If set to `false`, select disabled.
  129. */
  130. enableBrush(brushOption: Partial<BrushCoverCreatorConfig> | false): BrushController;
  131. private _doEnableBrush;
  132. private _doDisableBrush;
  133. /**
  134. * @param panelOpts If not pass, it is global brush.
  135. */
  136. setPanels(panelOpts?: BrushPanelConfig[]): BrushController;
  137. mount(opt?: {
  138. enableGlobalPan?: boolean;
  139. x?: number;
  140. y?: number;
  141. rotation?: number;
  142. scaleX?: number;
  143. scaleY?: number;
  144. }): BrushController;
  145. /**
  146. * Update covers.
  147. * @param coverConfigList
  148. * If coverConfigList is null/undefined, all covers removed.
  149. */
  150. updateCovers(coverConfigList: BrushCoverConfig[]): this;
  151. unmount(): this;
  152. dispose(): void;
  153. }
  154. export default BrushController;