|
1 | | -/* global inject */ |
2 | | -const { I } = inject(); |
3 | | - |
4 | | -module.exports = { |
5 | | - _rootSelector: '.htx-timeseries', |
6 | | - get _channelStageSelector() { |
7 | | - return `${this._rootSelector} .htx-timeseries-channel .new_brush`; |
8 | | - }, |
9 | | - _stageBBox: { x: 0, y: 0, width: 0, height: 0 }, |
10 | | - |
11 | | - async lookForStage() { |
12 | | - I.scrollPageToTop(); |
13 | | - const bbox = await I.grabElementBoundingRect(this._channelStageSelector); |
14 | | - |
15 | | - this._stageBBox = bbox; |
16 | | - }, |
17 | | - |
18 | | - /** |
19 | | - * Mousedown - mousemove - mouseup drawing a region on the first Channel. Works in conjunction with lookForStage. |
20 | | - * @example |
21 | | - * await AtTimeSeries.lookForStage(); |
22 | | - * AtTimeseries.drawByDrag(50, 200); |
23 | | - * @param x |
24 | | - * @param shiftX |
25 | | - */ |
26 | | - drawByDrag(x,shiftX) { |
27 | | - I.scrollPageToTop(); |
28 | | - I.moveMouse(this._stageBBox.x + x, this._stageBBox.y + this._stageBBox.height / 2); |
29 | | - I.pressMouseDown(); |
30 | | - I.moveMouse(this._stageBBox.x + x + shiftX, this._stageBBox.y + this._stageBBox.height / 2, 3); |
31 | | - I.pressMouseUp(); |
32 | | - }, |
33 | | -}; |
| 1 | +/* global inject */ |
| 2 | +const { I } = inject(); |
| 3 | + |
| 4 | +module.exports = { |
| 5 | + _rootSelector: '.htx-timeseries', |
| 6 | + _channelSelector: '.htx-timeseries-channel .overlay', |
| 7 | + _overviewSelector: '.htx-timeseries-overview .overlay', |
| 8 | + _westHandleSelector: '.htx-timeseries-overview .handle--w', |
| 9 | + _eastHandleSelector: '.htx-timeseries-overview .handle--e', |
| 10 | + get _channelStageSelector() { |
| 11 | + return `${this._rootSelector} .htx-timeseries-channel .new_brush`; |
| 12 | + }, |
| 13 | + _stageBBox: { x: 0, y: 0, width: 0, height: 0 }, |
| 14 | + |
| 15 | + WEST: 'west', |
| 16 | + EAST: 'east', |
| 17 | + |
| 18 | + async lookForStage() { |
| 19 | + I.scrollPageToTop(); |
| 20 | + const bbox = await I.grabElementBoundingRect(this._channelStageSelector); |
| 21 | + |
| 22 | + this._stageBBox = bbox; |
| 23 | + }, |
| 24 | + |
| 25 | + /** |
| 26 | + * Select range on overview to zoom in |
| 27 | + * @param {number} from - relative position of start between 0 and 1 |
| 28 | + * @param {number} to - relative position of finish between 0 and 1 |
| 29 | + * @returns {Promise<void>} |
| 30 | + * |
| 31 | + * @example |
| 32 | + * await AtTimeSeries.selectOverviewRange(.25, .75); |
| 33 | + */ |
| 34 | + async selectOverviewRange(from, to) { |
| 35 | + I.scrollPageToTop(); |
| 36 | + const overviewBBox = await I.grabElementBoundingRect(this._overviewSelector); |
| 37 | + |
| 38 | + I.moveMouse(overviewBBox.x + overviewBBox.width * from, overviewBBox.y + overviewBBox.height / 2); |
| 39 | + I.pressMouseDown(); |
| 40 | + I.moveMouse(overviewBBox.x + overviewBBox.width * to, overviewBBox.y + overviewBBox.height / 2, 3); |
| 41 | + I.pressMouseUp(); |
| 42 | + }, |
| 43 | + |
| 44 | + /** |
| 45 | + * Move range on overview to another position |
| 46 | + * @param {number} where - position between 0 and 1 |
| 47 | + * @returns {Promise<void>} |
| 48 | + */ |
| 49 | + async clickOverview(where) { |
| 50 | + I.scrollPageToTop(); |
| 51 | + const overviewBBox = await I.grabElementBoundingRect(this._overviewSelector); |
| 52 | + |
| 53 | + I.clickAt(overviewBBox.x + overviewBBox.width * where, overviewBBox.y + overviewBBox.height / 2); |
| 54 | + }, |
| 55 | + |
| 56 | + /** |
| 57 | + * Move overview handle by mouse drag |
| 58 | + * @param {number} where - position between 0 and 1 |
| 59 | + * @param {"west"|"east"} [which="west"] - handler name |
| 60 | + * @returns {Promise<void>} |
| 61 | + * |
| 62 | + * @example |
| 63 | + * await AtTimeSeries.moveHandle(.5, AtTimeSeries.WEST); |
| 64 | + */ |
| 65 | + async moveHandle(where, which = this.WEST) { |
| 66 | + I.scrollPageToTop(); |
| 67 | + const handlerBBox = await I.grabElementBoundingRect(this[`_${which}HandleSelector`]); |
| 68 | + const overviewBBox = await I.grabElementBoundingRect(this._overviewSelector); |
| 69 | + |
| 70 | + I.moveMouse(handlerBBox.x + handlerBBox.width / 2, handlerBBox.y + handlerBBox.height / 2); |
| 71 | + I.pressMouseDown(); |
| 72 | + I.moveMouse(overviewBBox.x + overviewBBox.width * where, overviewBBox.y + overviewBBox.height / 2, 3); |
| 73 | + I.pressMouseUp(); |
| 74 | + }, |
| 75 | + |
| 76 | + /** |
| 77 | + * Zoom by mouse wheel over the channel |
| 78 | + * @param {number} deltaY |
| 79 | + * @param {Object} [atPoint] - Point where will be called wheel action |
| 80 | + * @param {number} [atPoint.x=0.5] - relative X coordinate |
| 81 | + * @param {number} [atPoint.y=0.5] - relative Y coordinate |
| 82 | + * @returns {Promise<void>} |
| 83 | + * |
| 84 | + * @example |
| 85 | + * // zoom in |
| 86 | + * await AtTimeSeries.zoomByMouse(-100, { x: .01 }); |
| 87 | + * // zoom out |
| 88 | + * await AtTimeSeries.zoomByMouse(100); |
| 89 | + */ |
| 90 | + async zoomByMouse(deltaY, atPoint) { |
| 91 | + const { x = 0.5, y = 0.5 } = atPoint; |
| 92 | + |
| 93 | + I.scrollPageToTop(); |
| 94 | + const channelBBox = await I.grabElementBoundingRect(this._channelSelector); |
| 95 | + |
| 96 | + I.moveMouse(channelBBox.x + channelBBox.width * x, channelBBox.y + channelBBox.height* y); |
| 97 | + I.mouseWheel({ deltaY }); |
| 98 | + }, |
| 99 | + |
| 100 | + /** |
| 101 | + * Mousedown - mousemove - mouseup drawing a region on the first Channel. Works in conjunction with lookForStage. |
| 102 | + * @example |
| 103 | + * await AtTimeSeries.lookForStage(); |
| 104 | + * AtTimeseries.drawByDrag(50, 200); |
| 105 | + * @param x |
| 106 | + * @param shiftX |
| 107 | + */ |
| 108 | + drawByDrag(x,shiftX) { |
| 109 | + I.scrollPageToTop(); |
| 110 | + I.moveMouse(this._stageBBox.x + x, this._stageBBox.y + this._stageBBox.height / 2); |
| 111 | + I.pressMouseDown(); |
| 112 | + I.moveMouse(this._stageBBox.x + x + shiftX, this._stageBBox.y + this._stageBBox.height / 2, 3); |
| 113 | + I.pressMouseUp(); |
| 114 | + }, |
| 115 | +}; |
0 commit comments