button.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. "use strict";
  2. // import {
  3. // CustomElement,
  4. // DisplayObjectConfig,
  5. // PathStyleProps,
  6. // RectStyleProps,
  7. // BaseCustomElementStyleProps,
  8. // } from '../../shapes';
  9. // import { deepMix, omit } from '@antv/util';
  10. // import { FunctionalSymbol } from '../marker/types';
  11. // import { applyStyle, maybeAppend, normalPadding, select } from '../../util';
  12. // type ButtonBackgroundStyle = Omit<RectStyleProps, 'x' | 'y' | 'width' | 'height'>;
  13. // type ButtonMarkerStyle = Omit<PathStyleProps, 'path'>;
  14. // export type ControlButtonStyleProps = {
  15. // // The size of marker is equal to [size - padding[1] - padding[3], size - padding[0] - padding[2]]
  16. // size: number;
  17. // symbol?: string;
  18. // disabled?: boolean;
  19. // // Used to enlarge the hot area of button.
  20. // margin?: number | number[];
  21. // padding?: number | number[];
  22. // backgroundStyle?: ButtonBackgroundStyle & {
  23. // active?: Omit<RectStyleProps, 'x' | 'y' | 'width' | 'height'>;
  24. // disabled?: Omit<RectStyleProps, 'x' | 'y' | 'width' | 'height'>;
  25. // };
  26. // markerStyle?: ButtonMarkerStyle & {
  27. // active?: Omit<PathStyleProps, 'path'>;
  28. // disabled?: Omit<PathStyleProps, 'path'>;
  29. // };
  30. // };
  31. // export type ButtonStyleProps = BaseCustomElementStyleProps & ControlButtonStyleProps;
  32. // export class Button extends CustomElement<ButtonStyleProps> {
  33. // private active: boolean = false;
  34. // private disabled: boolean = false;
  35. // private static MARKER_SYMBOL_MAP = new Map<string, FunctionalSymbol>();
  36. // /**
  37. // * 注册 icon 类型
  38. // * @param type
  39. // * @param path
  40. // */
  41. // public static registerSymbol = (type: string, symbol: FunctionalSymbol) => {
  42. // Button.MARKER_SYMBOL_MAP.set(type, symbol);
  43. // };
  44. // /**
  45. // * 获取已经注册的 icon 的 path
  46. // */
  47. // public static getSymbol = (type: string): FunctionalSymbol | undefined => {
  48. // return Button.MARKER_SYMBOL_MAP.get(type);
  49. // };
  50. // constructor(options: DisplayObjectConfig<ButtonStyleProps>) {
  51. // super(options);
  52. // this.disabled = this.style.disabled || false;
  53. // }
  54. // public update(cfg: Partial<ButtonStyleProps> = {}) {
  55. // this.attr(deepMix({}, this.attributes, cfg));
  56. // if (cfg.disabled) {
  57. // this.active = false;
  58. // this.disabled = true;
  59. // }
  60. // this.render();
  61. // }
  62. // public setState(state?: 'disabled' | 'default') {
  63. // if (state === 'disabled') {
  64. // this.active = false;
  65. // this.disabled = true;
  66. // } else {
  67. // this.disabled = false;
  68. // }
  69. // this.render();
  70. // }
  71. // private render() {
  72. // const { size = 8, symbol, markerStyle, margin = 0, padding = 0, backgroundStyle } = this.style;
  73. // const [mt, mr, mb, ml] = normalPadding(margin);
  74. // const [pt, pr, pb, pl] = normalPadding(padding);
  75. // const rx = (size - pr - pl) / 2;
  76. // const ry = (size - pt - pb) / 2;
  77. // maybeAppend(this, '.container', 'rect')
  78. // .attr('className', 'container')
  79. // .style('x', -(rx + pl + ml))
  80. // .style('y', -(ry + pt + mt))
  81. // .style('width', size + mr + ml)
  82. // .style('height', size + mt + mb)
  83. // .style('fill', 'transparent')
  84. // .style('cursor', this.disabled ? 'not-allowed' : 'pointer')
  85. // .style('zIndex', 1);
  86. // const { active: bgActiveStyle, disabled: bgDisabledStyle, ...bgStyles } = backgroundStyle || {};
  87. // maybeAppend(this, '.background', 'rect')
  88. // .attr('className', 'background')
  89. // .style('x', -(rx + pl))
  90. // .style('y', -(ry + pt))
  91. // .style('width', size)
  92. // .style('height', size)
  93. // .call(applyStyle, bgStyles)
  94. // .call(applyStyle, this.active ? bgActiveStyle : {})
  95. // .call(applyStyle, this.disabled ? bgDisabledStyle : {});
  96. // const symbolFn = typeof symbol === 'function' ? symbol : Button.getSymbol(symbol || '');
  97. // const { active: markerActiveStyle, disabled: markerDisabledStyle, ...markerStyles } = markerStyle || {};
  98. // maybeAppend(this, '.marker', 'path')
  99. // .attr('className', 'marker')
  100. // .style('x', 0)
  101. // .style('y', 0)
  102. // .style('path', symbolFn?.(0, 0, Math.min(rx, ry)))
  103. // .call(applyStyle, markerStyles)
  104. // .call(applyStyle, this.active ? markerActiveStyle : {})
  105. // .call(applyStyle, this.disabled ? markerDisabledStyle : {});
  106. // }
  107. // private bindEvents() {
  108. // const marker = select(this).select('.marker');
  109. // const background = select(this).select('.background');
  110. // select(this).on('pointerup', () => {
  111. // if (this.disabled) return;
  112. // this.active = true;
  113. // });
  114. // select(this).on('pointermove', () => {
  115. // if (this.disabled) return;
  116. // this.active = true;
  117. // applyStyle(marker, this.style.markerStyle?.active as any);
  118. // applyStyle(background, this.style.backgroundStyle?.active as any);
  119. // });
  120. // select(this).on('pointerout', () => {
  121. // if (this.disabled) return;
  122. // this.active = false;
  123. // applyStyle(marker, omit(this.style.markerStyle || {}, ['active']) as any);
  124. // applyStyle(background, omit(this.style.backgroundStyle || {}, ['active']) as any);
  125. // });
  126. // }
  127. // }
  128. // Button.registerSymbol('timeline-prev-button', (x: number, y: number, r: number) => {
  129. // return [
  130. // ['M', x + r, y + r],
  131. // ['L', x, y],
  132. // ['L', x + r, y - r],
  133. // ['M', x, y + r],
  134. // ['L', x - r, y],
  135. // ['L', x, y - r],
  136. // ];
  137. // });
  138. // Button.registerSymbol('timeline-next-button', (x: number, y: number, r: number) => {
  139. // return [
  140. // ['M', x, y + r],
  141. // ['L', x + r, y],
  142. // ['L', x, y - r],
  143. // ['M', x - r, y + r],
  144. // ['L', x, y],
  145. // ['L', x - r, y - r],
  146. // ];
  147. // });
  148. // Button.registerSymbol('timeline-play-button', (x: number, y: number, r: number) => {
  149. // return [
  150. // ['M', x + 2, y + 3],
  151. // ['L', x + 2, y - 3],
  152. // ['M', x - 2, y + 3],
  153. // ['L', x - 2, y - 3],
  154. // ];
  155. // });
  156. // Button.registerSymbol('timeline-stop-button', (x: number, y: number, r: number) => {
  157. // return [['M', x + 3, y], ['L', x - 1.5, y - 1.5 * Math.sqrt(3)], ['L', x - 1.5, y + 1.5 * Math.sqrt(3)], ['Z']];
  158. // });
  159. //# sourceMappingURL=button.js.map