speedcontrol.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. "use strict";
  2. // import { CustomElement, CustomEvent, DisplayObjectConfig } from '../../shapes';
  3. // import { deepMix } from '@antv/util';
  4. // import { applyStyle, maybeAppend, select } from '../../util';
  5. // import { DEFAULT_TIMELINE_STYLE } from './constants';
  6. // import { SpeedControlStyleProps } from './types';
  7. // type StyleProps = SpeedControlStyleProps & {
  8. // x?: number;
  9. // y?: number;
  10. // };
  11. // function getOffsetByIndex(index: number, height: number): number {
  12. // const OFFSET = [1.43, 2.79, 4.89, 7.57, 11.66];
  13. // return (OFFSET[index] / 11.66) * height;
  14. // }
  15. // const DEFAULT_STYLE = deepMix({}, DEFAULT_TIMELINE_STYLE.speedControl, {
  16. // markerFill: '#8c8c8c',
  17. // spacing: 1,
  18. // lineStyle: {
  19. // stroke: '#bfbfbf',
  20. // lineWidth: 1,
  21. // },
  22. // });
  23. // export class SpeedControl extends CustomElement<StyleProps> {
  24. // public static tag = 'speed-control';
  25. // public static defaultOptions: DisplayObjectConfig<StyleProps> = {
  26. // style: DEFAULT_STYLE,
  27. // };
  28. // constructor(options: DisplayObjectConfig<StyleProps>) {
  29. // super(deepMix({}, SpeedControl.defaultOptions, options));
  30. // }
  31. // public update(cfg: Partial<StyleProps> = {}): void {
  32. // this.attr(deepMix({}, this.attributes, cfg));
  33. // this.render();
  34. // }
  35. // private get styles(): Required<SpeedControlStyleProps> {
  36. // return deepMix({}, SpeedControl.defaultOptions.style, this.attributes);
  37. // }
  38. // private render() {
  39. // const {
  40. // initialSpeed,
  41. // markerSize,
  42. // markerFill,
  43. // lineStyle,
  44. // speeds,
  45. // labelStyle: label,
  46. // spacing,
  47. // formatter = (v) => `${v}`,
  48. // } = this.styles;
  49. // let initialSpeedIdx = speeds.indexOf(initialSpeed);
  50. // if (initialSpeedIdx === -1) initialSpeedIdx = 0;
  51. // const size = markerSize * 2;
  52. // const y = getOffsetByIndex(initialSpeedIdx, size * 2);
  53. // const r = markerSize * Math.tan(Math.PI / 6) * 2;
  54. // maybeAppend(this, '.speed-marker', 'path')
  55. // .attr('className', 'speed-marker')
  56. // .style('fill', markerFill)
  57. // .style('path', [['M', 0, y - r / 2], ['L', markerSize, y], ['L', 0, y + r / 2], ['Z']]);
  58. // const x = markerSize - 0.5;
  59. // const group = maybeAppend(this, '.line-group', 'rect')
  60. // .attr('className', 'line-group')
  61. // .style('x', x)
  62. // .style('y', 0)
  63. // .style('width', size)
  64. // .style('height', size * 2)
  65. // .style('cursor', 'pointer')
  66. // .style('fill', 'transparent')
  67. // .node();
  68. // const path = speeds.reduce((arr: any[], _: any, idx: number) => {
  69. // const offset = getOffsetByIndex(idx, size * 2);
  70. // arr.push(['M', 0, offset], ['L', size, offset]);
  71. // return arr;
  72. // }, [] as any[]);
  73. // maybeAppend(group, '.speed-path', 'path')
  74. // .attr('className', 'speed-path')
  75. // .style('path', path)
  76. // .call(applyStyle, lineStyle);
  77. // maybeAppend(this, '.speed-label', 'text')
  78. // .attr('className', 'speed-label')
  79. // .style('x', x + size + spacing)
  80. // .style('y', 2)
  81. // .style('text', formatter(speeds[initialSpeedIdx]))
  82. // .call(applyStyle, label);
  83. // }
  84. // private bindEvents() {
  85. // const lineGroup = this.querySelector('.line-group')! as any;
  86. // lineGroup.addEventListener('pointerdown', (evt: any) => this.onClick(evt));
  87. // // Only for mobile.
  88. // lineGroup.addEventListener('touchmove', (evt: any) => this.onClick(evt));
  89. // }
  90. // private onClick(evt: any) {
  91. // const { speeds, markerSize, formatter = (v) => `${v}` } = this.styles;
  92. // const height = markerSize * 2 * 2;
  93. // const lineGroup = this.querySelector('.line-group')! as any;
  94. // const speedText = select(this).select('.speed-label').node();
  95. // const speedMarker = select(this).select('.speed-marker').node();
  96. // if (evt.currentTarget === lineGroup) {
  97. // const diff = evt.y - lineGroup.getBBox().y;
  98. // const idx = speeds.findIndex((_: any, idx: number) => {
  99. // const offset = getOffsetByIndex(idx, height);
  100. // const offset0 = getOffsetByIndex(idx - 1, height);
  101. // const offset1 = getOffsetByIndex(idx + 1, height);
  102. // if (idx === 0) return diff < offset + (getOffsetByIndex(1, height) - offset) / 2;
  103. // if (idx === speeds.length - 1) return diff > offset - (offset - offset0) / 2;
  104. // const range = [offset - (offset - offset0) / 2, offset + (offset1 - offset) / 2];
  105. // return diff >= range[0] && diff < range[1];
  106. // });
  107. // if (idx === -1) return;
  108. // speedText.setAttribute('text', formatter(speeds[idx]));
  109. // speedMarker.setLocalPosition(0, getOffsetByIndex(idx, height) - height / 8);
  110. // this.dispatchEvent(new CustomEvent('speedChanged', { detail: { speed: speeds[idx] } }));
  111. // }
  112. // }
  113. // }
  114. //# sourceMappingURL=speedcontrol.js.map