mxgraphの使用のいくつかのVUE-CLI3概要

非常にフローチャートmxgGaph、私の英語の読解力(ここでは無力な笑顔だ)の運動の発展に満足。

ここで私は最初それを2日間、小さな水たまりを、それを記述するためにどのようにカードを、記録しました。ステップは知らないはいけない、私は笑いを辞任しました。PS:ここでは、プラグインや赤ちゃんのいくつかを理解しているこのプラグインを使用するための記録問題のみを記録していません。

1、のmxgraphに自動レイアウト。

  、レイアウト、ノード編集を設定するために、自動レイアウトmxgraphを使用してそうでなければ無効、ああ小さな水たまり水たまり、喜びの水たまり。

 

  B、バックオフィスのプロセスの多くは、ノード間の接続が双方向であるので、ツリーのレイアウトで、この時間は、無効となり、そこにコールバックされ、双方向の接続は、ツリーのレイアウトを満たしていないので、この時間はmxHierarchicalLayoutのレイアウト例を置き換えることができますこの:

 

 図2に示すように、ノードをレンダリングするためのHTMLコードの使用に

  オープンサポートHTMLに設定された第1のステップ:

 

   次に、作成し、キャンバスにノードを追加します。

 

 3、写真に使用されるノードがあなたはセットSTYLE_SHAPEにSHAPE_LABELにしたいことができ、以下では、画像の下にラベルピクチャースタイルの設定を使用してノードです。

 

 4、NPMによってVUE-CLI3をインストールして使用mxgraph

  プロジェクトタスクは、タイトなルーティングを行うためにVUE-ルータを使用して足場、単一ページの開発モード、この怠惰な公式の使用です。

  インターネットVUE-CLI3使用mxgraph上のその他の記事は誤りで述べたが、私は出会いませんでした、それを統合する私の方法でここに掲載しました:

  mxgraph.jsで:

 

     VUEのページまたはコンポーネント:クラス定義を使用するために組み込まれmxgraphの必要性と 

 

 

最後に、コードmxgraphの部品を取り付けます:

<template>
    <div class="container" :class="boxClass">
        <div id="pannel"></div>
    </div>
</template>
<style>
    .cirlce{
        height: 60px;
        width: 60px;
        background-color: green;
        border-radius: 30px;
        font-size: 16px;
        color: #fff;
        line-height: 60px;
        text-align: center;
    }
</style>
<script>
    import mxgraph from '../../../plugins/mxgraph';
    import utils from '../../base/utils';
    import { popup } from '../popup/popup';
    const {mxHierarchicalLayout,mxConstants,mxCell,mxClient,mxGraph,mxGraphModel,mxGeometry} = mxgraph;
    const colorMap = {
        '00': '#999', // 正常
        '11': 'red' // 失败
    }
    var graph;
    export default {
        name: 'workflow',
        props: {
            boxClass: String,
            oriData: Object
        },
        data() {
            return {

                
            }
        },
        mounted(){
            this.init();
        },
        methods: {
            init(){
                var container = document.getElementById('pannel');
                // Checks if the browser is supported
                if(!mxClient.isBrowserSupported()){
                    // Displays an error message if the browser is not supported.
                    popup.bubble('error','Browser is not supported!');
                    return;
                }
                //init容器
                var model = new mxGraphModel();
                graph = new mxGraph(container, model);
                //设置元素可被连接线连接
                graph.setConnectable(false);
                //设置元素可编辑,不然无法自动布局
                graph.setCellsLocked(false);
                //设置两个节点是否可以建立多个连接
                graph.setMultigraph(true);
                //cell创建支持传入html
                graph.setHtmlLabels(true);
                //是否允许线单独存在
                graph.setAllowDanglingEdges(false);
                //设置cell可选中
                graph.setCellsSelectable(false);
                //设置面板可以扩大
                graph.setPanning(false);
                /*设置连接线样式*/
                var style = graph.getStylesheet().getDefaultEdgeStyle();
                //圆角连线
               style[mxConstants.STYLE_ROUNDED] = true;
                //labelsize
                style[mxConstants.STYLE_FONTSIZE] = 18;
                //label位置
                style[mxConstants.STYLE_SPACING_BOTTOM] = 30;
                this.initProcessData();
            },
            initProcessData(){
                const parent = graph.getDefaultParent();
                const model = utils.copyObject(this.oriData);
                if(model.nodeList.length <= 0)return;
                var lines = model.lineList || [];
                var nodes = model.nodeList || [];
                nodes.map((item)=>{
                    var info = {
                        key: item.key,
                        name: item.name,
                        state: item.state
                    }
                    this.addCell(info, item);
                });
                lines.map((item)=>{
                    var sourceCell = this.getCellById(item.source);
                    var targetCell = this.getCellById(item.target);
                    if(!sourceCell || !targetCell)return;
                    var line = graph.insertEdge(graph.getDefaultParent(), item.key, "", sourceCell, targetCell);
                    this.setCellStyle('strokeColor', colorMap[item.state], [line]);
                });
                // 自动布局
                var layout = new mxHierarchicalLayout(graph,mxConstants.DIRECTION_WEST);
                layout.execute(graph.getDefaultParent());
                this.adjustPos(); // 调整位置,让流程图剧中
            },
            adjustPos(){
                var bounds = graph.getGraphBounds();
                var margin = margin || 10;
                graph.container.style.overflow = "hidden";
                graph.view.setTranslate(
                    -bounds.x -(bounds.width - graph.container.clientWidth)/ 2,
                    -bounds.y - (bounds.height - graph.container.clientHeight) / 2
                );
                while( (bounds.width + margin * 2) > graph.container.clientWidth 
                        || (bounds.height + margin * 2) > graph.container.clientHeight ){
                    graph.zoomOut();
                    bounds = graph.getGraphBounds();
                }
                graph.container.style.overflow = "auto";
            },
            getCellById(id){
                var cells = graph.getChildVertices(graph.getDefaultParent());
                var nodes = cells.filter((item)=>{
                    return item.id == id;
                });
                if(nodes.length > 0)return nodes[0];
            },
            addCell(info){
                /*info{
                    key,//节点唯一标识
                    name, //节点label
                    state: 
                }*/
                if(!info)return;
                // 清除默认样式
                var style = 'text;strokeColor=none;fillColor=none;html=1;whiteSpace=wrap;verticalAlign=middle;overflow=hidden;';
                // 节点html结构
                var html = '<div class="cirlce">'+info.name+'</div>'
                // 创建节点
                var cell = new mxCell(html, new mxGeometry(0, 0, 65, 85), style);
                // 设置cell为节点(在mxgraph中,链接线段也属于一种cell,所以这里新建了cell以后要设置它的类型)
                cell.setVertex(true);
                // 添加节点到画布
                graph.addCell(cell);
                if(info.key){
                    cell.setId(info.key);
                }
            },

            setCellStyle(key, value, cells){
                if(!cells)return;
                graph.setCellStyles(key, value, cells);
                //graph.refresh(cell);
            }
        },
        watch: {
            oriData(){
                this.initProcessData();
            }
        }
    }
</script>

 

おすすめ

転載: www.cnblogs.com/solaZhan/p/11912015.html