Bin
2025-12-16 9e0b2ba2c317b1a86212f24cbae3195ad1f3dbfa
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
const { I } = inject();
 
module.exports = {
  _rootSelector: ".htx-timeseries",
  _channelSelector: ".htx-timeseries-channel .overlay",
  _overviewSelector: ".htx-timeseries-overview .overlay",
  _westHandleSelector: ".htx-timeseries-overview .handle--w",
  _eastHandleSelector: ".htx-timeseries-overview .handle--e",
  _stickSelector: '[text-anchor="start"]',
 
  get _channelStageSelector() {
    return `${this._rootSelector} .htx-timeseries-channel .new_brush`;
  },
  get _channelStickSelector() {
    return `${this._rootSelector} .htx-timeseries-channel [text-anchor="start"]`;
  },
  _stageBBox: { x: 0, y: 0, width: 0, height: 0 },
 
  WEST: "west",
  EAST: "east",
 
  async lookForStage() {
    I.scrollPageToTop();
    const bbox = await I.grabElementBoundingRect(this._channelStageSelector);
 
    this._stageBBox = bbox;
  },
 
  /**
   * Retrieves timestamp value from a text element of timeseries' stick (cursor).
   * **should be used inside async with `await`** operator.
   *
   * ```js
   * let timestamp = await I.grabStickTime();
   * ```
   * @returns timestamp value
   *
   * {{ react }}
   */
  async grabStickTime() {
    // xPath cannot find `text` tag so we exchange it with `*`
    const rawValue = await I.grabTextFrom(locate(this._channelStickSelector).find("*").at(2));
    const numericPart = rawValue.match(/-?\d+(?:\.\d+)?/);
    const parsedValue = numericPart ? Number(numericPart[0]) : Number(rawValue);
 
    // Cursor labels are formatted with one decimal place (e.g. "0.8 Hz") even when the
    // underlying data is integer-based. Round to the nearest integer so equality checks
    // on sequential timestamps keep passing regardless of the display format.
    return Number.isFinite(parsedValue) ? Math.round(parsedValue) : parsedValue;
  },
 
  /**
   * Select range on overview to zoom in
   * **should be used inside async with `await`** operator.
   * @param {number} from - relative position of start between 0 and 1
   * @param {number} to - relative position of finish between 0 and 1
   * @returns {Promise<void>}
   *
   * @example
   * await AtTimeSeries.selectOverviewRange(.25, .75);
   */
  async selectOverviewRange(from, to) {
    I.scrollPageToTop();
    const overviewBBox = await I.grabElementBoundingRect(this._overviewSelector);
 
    I.moveMouse(overviewBBox.x + overviewBBox.width * from, overviewBBox.y + overviewBBox.height / 2);
    I.pressMouseDown();
    I.moveMouse(overviewBBox.x + overviewBBox.width * to, overviewBBox.y + overviewBBox.height / 2, 3);
    I.pressMouseUp();
  },
 
  /**
   * Move range on overview to another position
   * @param {number} where - position between 0 and 1
   * @returns {Promise<void>}
   */
  async clickOverview(where) {
    I.scrollPageToTop();
    const overviewBBox = await I.grabElementBoundingRect(this._overviewSelector);
 
    I.clickAt(overviewBBox.x + overviewBBox.width * where, overviewBBox.y + overviewBBox.height / 2);
  },
 
  /**
   * Move overview handle by mouse drag
   * **should be used inside async with `await`** operator.
   * @param {number} where - position between 0 and 1
   * @param {"west"|"east"} [which="west"] - handler name
   * @returns {Promise<void>}
   *
   * @example
   * await AtTimeSeries.moveHandle(.5, AtTimeSeries.WEST);
   */
  async moveHandle(where, which = this.WEST) {
    I.scrollPageToTop();
    const handlerBBox = await I.grabElementBoundingRect(this[`_${which}HandleSelector`]);
    const overviewBBox = await I.grabElementBoundingRect(this._overviewSelector);
 
    I.moveMouse(handlerBBox.x + handlerBBox.width / 2, handlerBBox.y + handlerBBox.height / 2);
    I.pressMouseDown();
    I.moveMouse(overviewBBox.x + overviewBBox.width * where, overviewBBox.y + overviewBBox.height / 2, 3);
    I.pressMouseUp();
  },
 
  /**
   *  Zoom by mouse wheel over the channel
   *  **should be used inside async with `await`** operator.
   * @param {number} deltaY
   * @param {Object} [atPoint] - Point where will be called wheel action
   * @param {number} [atPoint.x=0.5] - relative X coordinate
   * @param {number} [atPoint.y=0.5] - relative Y coordinate
   * @returns {Promise<void>}
   *
   * @example
   * // zoom in
   * await AtTimeSeries.zoomByMouse(-100, { x: .01 });
   * // zoom out
   * await AtTimeSeries.zoomByMouse(100);
   */
  async zoomByMouse(deltaY, atPoint) {
    const { x = 0.5, y = 0.5 } = atPoint;
 
    I.scrollPageToTop();
    const channelBBox = await I.grabElementBoundingRect(this._channelSelector);
 
    I.moveMouse(channelBBox.x + channelBBox.width * x, channelBBox.y + channelBBox.height * y);
    I.pressKeyDown("CommandOrControl");
    I.mouseWheel({ deltaY });
    I.pressKeyUp("CommandOrControl");
  },
 
  /**
   * Move mouse over the channel
   * **should be used inside async with `await`** operator.
   * @param {Object} [atPoint] - Point where will be called wheel action
   * @param {number} [atPoint.x=0.5] - relative X coordinate
   * @param {number} [atPoint.y=0.5] - relative Y coordinate
   * @returns {Promise<void>}
   *
   * @example
   * await AtTimeSeries.moveMouseOverChannel({ x: .01 });
   */
  async moveMouseOverChannel(atPoint) {
    const { x = 0.5, y = 0.5 } = atPoint;
 
    I.scrollPageToTop();
    const channelBBox = await I.grabElementBoundingRect(this._channelSelector);
 
    I.moveMouse(channelBBox.x + channelBBox.width * x, channelBBox.y + channelBBox.height * y);
  },
 
  /**
   * Mousedown - mousemove - mouseup drawing a region on the first Channel. Works in conjunction with lookForStage.
   * @example
   * await AtTimeSeries.lookForStage();
   * AtTimeseries.drawByDrag(50, 200);
   * @param x
   * @param shiftX
   */
  drawByDrag(x, shiftX) {
    I.scrollPageToTop();
    I.moveMouse(this._stageBBox.x + x, this._stageBBox.y + this._stageBBox.height / 2);
    I.pressMouseDown();
    I.moveMouse(this._stageBBox.x + x + shiftX, this._stageBBox.y + this._stageBBox.height / 2, 3);
    I.pressMouseUp();
  },
};