提交 ea111b6e 编写于 作者: P pissang

test: support mousewheel event record and replay

上级 5c2d8cff
...@@ -196,7 +196,7 @@ export default echarts.extendChartView({ ...@@ -196,7 +196,7 @@ export default echarts.extendChartView({
this.group.setClipPath(clipPath); this.group.setClipPath(clipPath);
} }
else { else {
this.group.removeClipPath(null); this.group.removeClipPath();
} }
}, },
...@@ -258,7 +258,7 @@ var clip = { ...@@ -258,7 +258,7 @@ var clip = {
layout.width = x2 - x; layout.width = x2 - x;
layout.height = y2 - y; layout.height = y2 - y;
var clipped = layout.width < 0 || layout.height < 0;; var clipped = layout.width < 0 || layout.height < 0;
// Reverse back // Reverse back
if (signWidth < 0) { if (signWidth < 0) {
......
...@@ -29,6 +29,8 @@ module.exports = class Timeline { ...@@ -29,6 +29,8 @@ module.exports = class Timeline {
this._ops = []; this._ops = [];
this._currentOpIndex = 0; this._currentOpIndex = 0;
this._client;
} }
_reset() { _reset() {
...@@ -39,6 +41,10 @@ module.exports = class Timeline { ...@@ -39,6 +41,10 @@ module.exports = class Timeline {
async runAction(action, takeScreenshot, playbackSpeed) { async runAction(action, takeScreenshot, playbackSpeed) {
if (!this._client) {
this._client = await this._page.target().createCDPSession();
}
this.stop(); this.stop();
playbackSpeed = playbackSpeed || 1; playbackSpeed = playbackSpeed || 1;
...@@ -108,6 +114,32 @@ module.exports = class Timeline { ...@@ -108,6 +114,32 @@ module.exports = class Timeline {
case 'mousemove': case 'mousemove':
await page.mouse.move(op.x, op.y); await page.mouse.move(op.x, op.y);
break; break;
case 'mousewheel':
await page.evaluate((x, y, deltaX, deltaY) => {
let element = document.elementFromPoint(x, y);
// Here dispatch mousewheel event because echarts used it.
// TODO Consider upgrade?
let event = new WheelEvent('mousewheel', {
// PENDING
// Needs inverse delta?
deltaY,
clientX: x, clientY: y,
// Needs bubble to parent container
bubbles: true
});
element.dispatchEvent(event);
}, op.x, op.y, op.deltaX || 0, op.deltaY);
// console.log('mousewheel', op.x, op.y, op.deltaX, op.deltaY);
// await this._client.send('Input.dispatchMouseEvent', {
// type: 'mouseWheel',
// x: op.x,
// y: op.y,
// deltaX: op.deltaX,
// deltaY: op.deltaY
// });
// break;
case 'screenshot': case 'screenshot':
await takeScreenshot(); await takeScreenshot();
break; break;
......
...@@ -143,6 +143,7 @@ const app = new Vue({ ...@@ -143,6 +143,7 @@ const app = new Vue({
if (action) { if (action) {
action.ops = []; action.ops = [];
} }
saveData();
}).catch(e => {}); }).catch(e => {});
}, },
...@@ -240,6 +241,10 @@ function keyboardRecordingHandler(e) { ...@@ -240,6 +241,10 @@ function keyboardRecordingHandler(e) {
} }
} }
function sign(value) {
return value > 0 ? 1 : -1;
}
function recordIframeEvents(iframe, app) { function recordIframeEvents(iframe, app) {
let innerDocument = iframe.contentWindow.document; let innerDocument = iframe.contentWindow.document;
...@@ -247,12 +252,23 @@ function recordIframeEvents(iframe, app) { ...@@ -247,12 +252,23 @@ function recordIframeEvents(iframe, app) {
function addMouseOp(type, e) { function addMouseOp(type, e) {
if (app.recordingAction) { if (app.recordingAction) {
let time = getEventTime(); let time = getEventTime();
app.recordingAction.ops.push({ let op = {
type, type,
time: time, time: time,
x: e.clientX, x: e.clientX,
y: e.clientY y: e.clientY
}); };
app.recordingAction.ops.push(op);
if (type === 'mousewheel') {
// TODO Sreenshot after mousewheel?
op.deltaY = e.deltaY;
// In a reversed direction.
// When creating WheelEvent, the sign of wheelData and deltaY are same
if (sign(e.wheelDelta) !== sign(e.deltaY)) {
op.deltaY = -op.deltaY;
}
}
if (type === 'mouseup' && app.config.screenshotAfterMouseUp) { if (type === 'mouseup' && app.config.screenshotAfterMouseUp) {
// Add a auto screenshot after mouseup // Add a auto screenshot after mouseup
app.recordingAction.ops.push({ app.recordingAction.ops.push({
...@@ -288,6 +304,10 @@ function recordIframeEvents(iframe, app) { ...@@ -288,6 +304,10 @@ function recordIframeEvents(iframe, app) {
} }
preventRecordingFollowingMouseEvents = false; preventRecordingFollowingMouseEvents = false;
}, true); }, true);
iframe.contentWindow.addEventListener('mousewheel', e => {
console.log(e);
addMouseOp('mousewheel', e);
}, true);
innerDocument.body.addEventListener('change', e => { innerDocument.body.addEventListener('change', e => {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册