cellAxis.js 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. "use strict";
  2. // import { DisplayObjectConfig, RectStyleProps, CustomEvent } from '../../shapes';
  3. // import { Band as BandScale } from '@antv/scale';
  4. // import { deepMix } from '@antv/util';
  5. // import { Axis, AxisOptions } from '../axis';
  6. // import { applyStyle, maybeAppend, select } from '../../util';
  7. // import { GUI } from '../../core';
  8. // import {
  9. // AxisBase,
  10. // AxisStyleProps,
  11. // DEFAULT_AXIS_CFG,
  12. // DEFAULT_STYLE as BASE_DEFAULT_STYLE,
  13. // normalSelection,
  14. // } from './playAxis';
  15. // type CellAxisStyleProps = AxisStyleProps & {};
  16. // type CellAxisOptions = DisplayObjectConfig<CellAxisStyleProps>;
  17. // function getScale(data: any[], range: [number, number]) {
  18. // return new BandScale({
  19. // domain: data.map((_, idx) => idx),
  20. // range,
  21. // paddingOuter: 0,
  22. // paddingInner: 0,
  23. // });
  24. // }
  25. // export class CellAxis extends AxisBase<CellAxisStyleProps> {
  26. // public static defaultOptions: CellAxisOptions = {
  27. // style: deepMix({}, BASE_DEFAULT_STYLE, {
  28. // tag: 'cell-axis',
  29. // backgroundStyle: {
  30. // fill: '#416180',
  31. // fillOpacity: 0.05,
  32. // },
  33. // size: 16,
  34. // spacing: 4,
  35. // cellGap: 2,
  36. // cellStyle: {
  37. // fill: '#416180',
  38. // fillOpacity: 0.1,
  39. // },
  40. // selectionStyle: {
  41. // fillOpacity: 0.45,
  42. // },
  43. // label: {
  44. // autoHideTickLine: true,
  45. // },
  46. // }),
  47. // };
  48. // constructor(options: CellAxisOptions) {
  49. // super(deepMix({}, CellAxis.defaultOptions, options));
  50. // this.selection = normalSelection(this.style.selection, this.style.singleMode);
  51. // }
  52. // private get styles(): Required<CellAxisStyleProps> {
  53. // return deepMix({}, CellAxis.defaultOptions.style, this.attributes);
  54. // }
  55. // protected setSelection(newSelection: { start?: number | undefined; end?: number | undefined }): void {
  56. // const [s0, e0] = this.selection;
  57. // this.selection = normalSelection([newSelection.start ?? s0, newSelection.end ?? e0], this.style.singleMode);
  58. // this.dispatchEvent(new CustomEvent('selectionChanged', { detail: { selection: this.selection } }));
  59. // this.render();
  60. // }
  61. // protected render() {
  62. // const style = this.styles;
  63. // const cellSize = style.size;
  64. // const spacing = style.spacing;
  65. // const [xName, yName, widthName, heightName] = this.ifH(
  66. // ['x', 'y', 'width', 'height'],
  67. // ['y', 'x', 'height', 'width']
  68. // );
  69. // const bg = maybeAppend(this, '.slider-background', 'rect')
  70. // .attr('className', 'slider-background')
  71. // .style('x', 0)
  72. // .style('y', 0)
  73. // .style(widthName, style.length)
  74. // .style(heightName, cellSize + spacing)
  75. // .call(applyStyle, style.backgroundStyle)
  76. // .node();
  77. // const scale = this.getCellScale();
  78. // const bandWidth = scale.getBandWidth();
  79. // const cells = style.data.map((_, idx: number) => {
  80. // return {
  81. // [xName]: scale.map(idx),
  82. // [yName]: spacing / 2,
  83. // [widthName]: bandWidth - style.cellGap,
  84. // [heightName]: cellSize,
  85. // ...style.cellStyle,
  86. // };
  87. // }) as RectStyleProps[];
  88. // select(bg)
  89. // .selectAll('.cell')
  90. // .data(cells)
  91. // .join(
  92. // (enter) =>
  93. // enter
  94. // .append('rect')
  95. // .attr('className', 'cell')
  96. // .each(function (datum) {
  97. // this.attr(datum);
  98. // }),
  99. // (update) =>
  100. // update.each(function (datum) {
  101. // this.attr(datum);
  102. // }),
  103. // (exit) => exit.remove()
  104. // );
  105. // const selectedCells = cells
  106. // .filter((__, idx) => {
  107. // const [a, b] = this.selection;
  108. // return idx >= a && idx <= b;
  109. // })
  110. // .map((cell) => {
  111. // return { ...cell, ...style.selectionStyle };
  112. // });
  113. // const animationOptions = {
  114. // duration: this.style.playInterval! / 2,
  115. // easing: 'cubic-bezier(0.250, 0.460, 0.450, 0.940)', // 缓动函数
  116. // fill: 'both' as any,
  117. // };
  118. // select(bg)
  119. // .selectAll('.selected-cell')
  120. // .data(selectedCells)
  121. // .join(
  122. // (enter) =>
  123. // enter
  124. // .append('rect')
  125. // .attr('className', 'selected-cell')
  126. // .each(function (datum) {
  127. // this.attr(datum);
  128. // }),
  129. // (update) =>
  130. // update.each(function (datum) {
  131. // this.animate([datum], animationOptions);
  132. // }),
  133. // (exit) => exit.remove()
  134. // );
  135. // const axisLength = style.length - style.spacing * 2 + style.cellGap;
  136. // const tickScale = getScale(style.data, [0, axisLength]);
  137. // const ticks = style.data.map((tick, idx) => ({
  138. // value: (tickScale.map(idx) + (bandWidth - style.cellGap) / 2) / axisLength,
  139. // text: tick.date,
  140. // }));
  141. // const { position: verticalFactor = -1, tickLine: tickLineCfg, ...axisLabelCfg } = style.label || {};
  142. // const y = verticalFactor === -1 ? -2 : style.spacing + cellSize + 2;
  143. // let startPos: any = [style.spacing, y];
  144. // let endPos: any = [spacing + axisLength, y];
  145. // if (this.orientation === 'vertical') {
  146. // startPos = [startPos[1], startPos[0]];
  147. // endPos = [endPos[1], endPos[0]];
  148. // }
  149. // maybeAppend(
  150. // bg,
  151. // '.slider-axis',
  152. // () =>
  153. // new Axis({
  154. // className: 'slider-axis',
  155. // style: DEFAULT_AXIS_CFG,
  156. // })
  157. // ).call((selection) =>
  158. // (selection.node() as GUI<AxisOptions>).update({
  159. // startPos,
  160. // endPos,
  161. // ticks,
  162. // verticalFactor,
  163. // tickLine: style.label === null ? null : tickLineCfg,
  164. // label: style.label === null ? null : axisLabelCfg,
  165. // })
  166. // );
  167. // }
  168. // private bindEvents() {
  169. // this.dragSelection();
  170. // }
  171. // private getCellScale() {
  172. // const cellGap = this.styles.cellGap!;
  173. // const length = this.styles.length!;
  174. // const spacing = this.styles.spacing!;
  175. // return getScale(this.style.data, [spacing, length! - spacing + cellGap!]);
  176. // }
  177. // private dragSelection() {
  178. // const selection = select(this).select('.slider-background');
  179. // let dragging = false; // 拖拽状态
  180. // let firstPosition: number | undefined; // 保存首次位置
  181. // const padding = this.styles.spacing;
  182. // const mapPositionToIndex = (pos: number) => {
  183. // const [x0, y0] = selection.node().getPosition();
  184. // const offset = this.ifH(x0 + 4, y0 + padding);
  185. // const cellGap = this.styles.cellGap!;
  186. // const scale = this.getCellScale();
  187. // const step = scale.getStep();
  188. // return Math.floor((pos - offset + cellGap!) / step);
  189. // };
  190. // const dragStart = (event: any) => {
  191. // if (this.playTimer) {
  192. // clearInterval(this.playTimer);
  193. // }
  194. // dragging = true;
  195. // firstPosition = this.ifH(event.x, event.y);
  196. // const pos = mapPositionToIndex(firstPosition!);
  197. // this.setSelection({ start: pos, end: pos });
  198. // };
  199. // const dragMove = (event: any) => {
  200. // if (!dragging) return;
  201. // const idx1 = mapPositionToIndex(this.ifH(event.x, event.y));
  202. // const idx0 = firstPosition ? mapPositionToIndex(firstPosition!) : idx1;
  203. // const [start, end] = idx0 < idx1 ? [idx0, idx1] : [idx1, idx0];
  204. // this.setSelection({ start, end });
  205. // };
  206. // const dragEnd = () => {
  207. // dragging = false;
  208. // if (this.playTimer) {
  209. // this.play();
  210. // }
  211. // };
  212. // selection
  213. // // events for drag start
  214. // .on('pointerdown', dragStart)
  215. // // events for drag end
  216. // .on('pointerup', dragEnd)
  217. // .on('mouseupoutside', dragEnd)
  218. // .on('touchendoutside', dragEnd)
  219. // // events for drag move
  220. // .on('pointermove', dragMove);
  221. // }
  222. // }
  223. //# sourceMappingURL=cellAxis.js.map