import {
    Graph,Shape
} from '@antv/x6';
import { myEvents,bindKey } from './event';
//非编辑页的配置
const viewConfig = {
    resizing:false,//不允许节点缩放
    translating:{
        restrict:true,//节点移动时无法超出画布
    },
    interacting:function (cellView){ //禁止节点移动
        /* if(cellView.cell.getData().disableMove){
            return false
        } */
        return false
    },
    highlighting:{},
    /* connecting:{}, */
    history:false,//关闭画布撤销/重做能力。
    keyboard:false,
    clipboard: false,
}
export function myGraph(wrapper,tempThis) {
    const otherConfig = window.location.pathname.startsWith('/chartframe')?viewConfig:{}
    const graph = new Graph({...{
        container: document.getElementById(wrapper),
        background: {
            color: '#fff',
        },
        history:true,
        keyboard:{
            enabled:true,
            global:true
        },
        clipboard: true,
        selecting:{
            enabled: true,
            showNodeSelectionBox: false,
            multiple: false
        },
        snapline: true,
        scroller: {
            enabled: true,
            pannable: true,
            minVisibleWidth: 50,
            minVisibleHeight: 50,
        },
        //节点是否允许缩放
        resizing: {
            enabled: true,
            orthogonal: false,
        },
        scaling: {
            min: 0.5,
            max: 2
        },
        mousewheel:{
            enabled: true,
            modifiers:['ctrl','meta']
        },
        highlighting: {
            //当链接桩可以被链接时，在链接桩外围渲染一个 2px 宽的红色矩形框
            magnetAvailable: {
                name: "stroke",
                args: {
                    padding: 0.8,
                    attrs: {
                            "stroke-width": 2,
                            stroke: "skyblue",
                    },
                },
            },
            //连线过程中，自动吸附到链接桩时被使用
            magnetAdsorbed: {
                name: "stroke",
                args: {
                    padding: 0.8,
                    attrs: {
                            "stroke-width": 4,
                            stroke: "skyblue",
                    },
                },
            },
        },
        connecting: {
            snap: true,
            highlight: true,
            allowLoop:false,
            allowNode:false,
            connector: {
                name: 'normal',
                args: {
                    padding:1
                }
            },
            connectionPoint: 'anchor',
            router:{
                name:'manhattan',
                args:{
                }
            },
            /*
            router: {
                name: 'er',
                args: {
                    direction: 'V',
                },
            },
             */
            // 定义边样式
            createEdge() {
                return new Shape.Edge({
                    attrs: {
                        line: {
                            stroke: '#0052D9',
                            strokeWidth: 1,
                            strokeDasharray: "",//虚线间隔
                            sourceMarker: false,//起始箭头 
                            targetMarker: 'classic',//终止箭头
                        },
                    },
                    zIndex: 0,
                })
            },
        },//连线
        minimap: {
            enabled: true,
            container: document.getElementById("frameMinimap"),
        }
    },...otherConfig})
    myEvents(graph,tempThis)

    bindKey(graph,tempThis)
    return graph
}