ed51488b59fdfd607124a45b666f7c3f43f56a443d46234788e63009cbe6fe99757422a121612f2b75439b5c9f3e79d2e877d4ca35a7ea0510ec230bcba773 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. import * as zrUtil from 'zrender/lib/core/util.js';
  2. import * as modelUtil from '../../util/model.js';
  3. import { ComponentOption, BoxLayoutOptionMixin, Dictionary, ZRStyleProps, OptionId, CommonTooltipOption, AnimationOptionMixin, AnimationOption } from '../../util/types.js';
  4. import ComponentModel from '../../model/Component.js';
  5. import Element, { ElementTextConfig } from 'zrender/lib/Element.js';
  6. import Displayable from 'zrender/lib/graphic/Displayable.js';
  7. import { PathProps, PathStyleProps } from 'zrender/lib/graphic/Path.js';
  8. import { ImageStyleProps, ImageProps } from 'zrender/lib/graphic/Image.js';
  9. import { TextStyleProps, TextProps } from 'zrender/lib/graphic/Text.js';
  10. import GlobalModel from '../../model/Global.js';
  11. import { TransitionOptionMixin } from '../../animation/customGraphicTransition.js';
  12. import { ElementKeyframeAnimationOption } from '../../animation/customGraphicKeyframeAnimation.js';
  13. import { GroupProps } from 'zrender/lib/graphic/Group.js';
  14. import { TransformProp } from 'zrender/lib/core/Transformable.js';
  15. import { ElementEventNameWithOn } from 'zrender/lib/core/types.js';
  16. interface GraphicComponentBaseElementOption extends Partial<Pick<Element, TransformProp | 'silent' | 'ignore' | 'textConfig' | 'draggable' | ElementEventNameWithOn>>,
  17. /**
  18. * left/right/top/bottom: (like 12, '22%', 'center', default undefined)
  19. * If left/rigth is set, shape.x/shape.cx/position will not be used.
  20. * If top/bottom is set, shape.y/shape.cy/position will not be used.
  21. * This mechanism is useful when you want to position a group/element
  22. * against the right side or the center of this container.
  23. */
  24. Partial<Pick<BoxLayoutOptionMixin, 'left' | 'right' | 'top' | 'bottom'>> {
  25. /**
  26. * element type, mandatory.
  27. * Only can be omit if call setOption not at the first time and perform merge.
  28. */
  29. type?: string;
  30. id?: OptionId;
  31. name?: string;
  32. parentId?: OptionId;
  33. parentOption?: GraphicComponentElementOption;
  34. children?: GraphicComponentElementOption[];
  35. hv?: [boolean, boolean];
  36. /**
  37. * bounding: (enum: 'all' (default) | 'raw')
  38. * Specify how to calculate boundingRect when locating.
  39. * 'all': Get uioned and transformed boundingRect
  40. * from both itself and its descendants.
  41. * This mode simplies confining a group of elements in the bounding
  42. * of their ancester container (e.g., using 'right: 0').
  43. * 'raw': Only use the boundingRect of itself and before transformed.
  44. * This mode is similar to css behavior, which is useful when you
  45. * want an element to be able to overflow its container. (Consider
  46. * a rotated circle needs to be located in a corner.)
  47. */
  48. bounding?: 'raw' | 'all';
  49. /**
  50. * info: custom info. enables user to mount some info on elements and use them
  51. * in event handlers. Update them only when user specified, otherwise, remain.
  52. */
  53. info?: GraphicExtraElementInfo;
  54. clipPath?: Omit<GraphicComponentZRPathOption, 'clipPath'> | false;
  55. textContent?: Omit<GraphicComponentTextOption, 'clipPath'>;
  56. textConfig?: ElementTextConfig;
  57. $action?: 'merge' | 'replace' | 'remove';
  58. tooltip?: CommonTooltipOption<unknown>;
  59. enterAnimation?: AnimationOption;
  60. updateAnimation?: AnimationOption;
  61. leaveAnimation?: AnimationOption;
  62. }
  63. export interface GraphicComponentDisplayableOption extends GraphicComponentBaseElementOption, Partial<Pick<Displayable, 'zlevel' | 'z' | 'z2' | 'invisible' | 'cursor'>> {
  64. style?: ZRStyleProps;
  65. z2?: number;
  66. }
  67. export interface GraphicComponentGroupOption extends GraphicComponentBaseElementOption, TransitionOptionMixin<GroupProps> {
  68. type?: 'group';
  69. /**
  70. * width/height: (can only be pixel value, default 0)
  71. * Only be used to specify contianer(group) size, if needed. And
  72. * can not be percentage value (like '33%'). See the reason in the
  73. * layout algorithm below.
  74. */
  75. width?: number;
  76. height?: number;
  77. children: GraphicComponentElementOption[];
  78. keyframeAnimation?: ElementKeyframeAnimationOption<GroupProps> | ElementKeyframeAnimationOption<GroupProps>[];
  79. }
  80. export interface GraphicComponentZRPathOption extends GraphicComponentDisplayableOption, TransitionOptionMixin<PathProps> {
  81. shape?: PathProps['shape'] & TransitionOptionMixin<PathProps['shape']>;
  82. style?: PathStyleProps & TransitionOptionMixin<PathStyleProps>;
  83. keyframeAnimation?: ElementKeyframeAnimationOption<PathProps> | ElementKeyframeAnimationOption<PathProps>[];
  84. }
  85. export interface GraphicComponentImageOption extends GraphicComponentDisplayableOption, TransitionOptionMixin<ImageProps> {
  86. type?: 'image';
  87. style?: ImageStyleProps & TransitionOptionMixin<ImageStyleProps>;
  88. keyframeAnimation?: ElementKeyframeAnimationOption<ImageProps> | ElementKeyframeAnimationOption<ImageProps>[];
  89. }
  90. interface GraphicComponentTextOption extends Omit<GraphicComponentDisplayableOption, 'textContent' | 'textConfig'>, TransitionOptionMixin<TextProps> {
  91. type?: 'text';
  92. style?: TextStyleProps & TransitionOptionMixin<TextStyleProps>;
  93. keyframeAnimation?: ElementKeyframeAnimationOption<TextProps> | ElementKeyframeAnimationOption<TextProps>[];
  94. }
  95. export declare type GraphicComponentElementOption = GraphicComponentGroupOption | GraphicComponentZRPathOption | GraphicComponentImageOption | GraphicComponentTextOption;
  96. declare type GraphicExtraElementInfo = Dictionary<unknown>;
  97. export declare type ElementMap = zrUtil.HashMap<Element, string>;
  98. export declare type GraphicComponentLooseOption = (GraphicComponentOption | GraphicComponentElementOption) & {
  99. mainType?: 'graphic';
  100. };
  101. export interface GraphicComponentOption extends ComponentOption, AnimationOptionMixin {
  102. elements?: GraphicComponentElementOption[];
  103. }
  104. export declare function setKeyInfoToNewElOption(resultItem: ReturnType<typeof modelUtil.mappingToExists>[number], newElOption: GraphicComponentElementOption): void;
  105. export declare class GraphicComponentModel extends ComponentModel<GraphicComponentOption> {
  106. static type: string;
  107. type: string;
  108. preventAutoZ: boolean;
  109. static defaultOption: GraphicComponentOption;
  110. /**
  111. * Save el options for the sake of the performance (only update modified graphics).
  112. * The order is the same as those in option. (ancesters -> descendants)
  113. */
  114. private _elOptionsToUpdate;
  115. mergeOption(option: GraphicComponentOption, ecModel: GlobalModel): void;
  116. optionUpdated(newOption: GraphicComponentOption, isInit: boolean): void;
  117. /**
  118. * Convert
  119. * [{
  120. * type: 'group',
  121. * id: 'xx',
  122. * children: [{type: 'circle'}, {type: 'polygon'}]
  123. * }]
  124. * to
  125. * [
  126. * {type: 'group', id: 'xx'},
  127. * {type: 'circle', parentId: 'xx'},
  128. * {type: 'polygon', parentId: 'xx'}
  129. * ]
  130. */
  131. private _flatten;
  132. useElOptionsToUpdate(): GraphicComponentElementOption[];
  133. }
  134. export {};