feat: remove the worker of mobile layout

This commit is contained in:
毅羽 2021-01-11 15:39:52 +08:00 committed by Yanyan Wang
parent 0864e423ae
commit c2428abe55
3 changed files with 1 additions and 95 deletions

View File

@ -40,6 +40,7 @@ export default class LayoutController extends AbstractLayout {
start = start.then(() => this.updateLayoutMethod(layoutMethod, currentCfg));
});
}
this.data = this.setDataFromGraph();
start
.then(() => {

View File

@ -1,77 +0,0 @@
/**
* @fileoverview web worker for layout
* @author changzhe.zb@antfin.com
*/
import { LAYOUT_MESSAGE } from './layoutConst';
import { getLayoutByName } from '@antv/layout';
interface Event {
type: string;
data: any;
}
const ctx: Worker = self as any;
function isLayoutMessage(event: Event) {
const { type } = event.data;
return type === LAYOUT_MESSAGE.RUN || type === LAYOUT_MESSAGE.GPURUN;
}
function handleLayoutMessage(event: Event) {
const { type } = event.data;
switch (type) {
case LAYOUT_MESSAGE.RUN: {
const { nodes, edges, layoutCfg = {} } = event.data;
const { type: layoutType } = layoutCfg;
const LayoutClass = getLayoutByName(layoutType);
if (!LayoutClass) {
ctx.postMessage({ type: LAYOUT_MESSAGE.ERROR, message: `layout ${layoutType} not found` });
break;
}
const layoutMethod = new LayoutClass(layoutCfg);
layoutMethod.init({ nodes, edges });
layoutMethod.execute();
ctx.postMessage({ type: LAYOUT_MESSAGE.END, nodes });
layoutMethod.destroy();
break;
}
case LAYOUT_MESSAGE.GPURUN: {
const { nodes, edges, layoutCfg = {}, canvas } = event.data;
const { type: layoutType } = layoutCfg;
const LayoutClass = getLayoutByName(layoutType);
if (!LayoutClass) {
ctx.postMessage({ type: LAYOUT_MESSAGE.ERROR, message: `layout ${layoutType} not found` });
break;
}
if (layoutType.split('-')[1] !== 'gpu') {
ctx.postMessage({
type: LAYOUT_MESSAGE.ERROR,
message: `layout ${layoutType} does not support GPU`,
});
break;
}
const layoutMethod = new LayoutClass(layoutCfg);
layoutMethod.init({ nodes, edges });
layoutMethod.executeWithWorker(canvas, ctx);
break;
}
default:
break;
}
}
// listen to message posted to web worker
ctx.onmessage = (event: Event) => {
if (isLayoutMessage(event)) {
handleLayoutMessage(event);
}
};
// https://stackoverflow.com/questions/50210416/webpack-worker-loader-fails-to-compile-typescript-worker
export default null as any;

View File

@ -1,18 +0,0 @@
/**
* @fileoverview constants for layout
* @author changzhe.zb@antfin.com
*/
/** layout message type */
export const LAYOUT_MESSAGE = {
// run layout
RUN: 'LAYOUT_RUN',
// layout ended with success
END: 'LAYOUT_END',
// layout error
ERROR: 'LAYOUT_ERROR',
// layout tick, used in force directed layout
TICK: 'LAYOUT_TICK',
GPURUN: 'GPU_LAYOUT_RUN',
GPUEND: 'GPU_LAYOUT_END',
};