mxGraph之在流程图上显示图片及泳道

mxGraph开发过程中,显示流程图相信好多朋友通过fileio.html那个示例已经都能熟练操作了,至于为什么客户端Graph换出来的流程图上面的图片为什么在web层面上不显示,这是个很麻烦的问题,关键是样式的问题,如果你研究grapheditor.html你就可以发现这个示例上面有一个showxml的菜单选项,每次你画完图点击这个菜单项就会显示最新的xml定义,注意看里面关于图片的内容的代码style="roundImage;image=images/earth.png" 和style="image;image=images/printer.png" ,对于上面的内容你可能会觉得这肯定是跟某项配置有关,没错,你猜对了,就是配置问题,之前我一直在想方面的东西结果经过尝试筛选终于验证了resources下面的default-style.xml是真正起作用的,现在我把关键代码贴在此处,其实就多了三行代码

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <META http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <link rel="stylesheet" type="text/css" href="extjs/ext-all.css" />
 <script type="text/javascript" src="extjs/ext-base.js"></script>
 <script type="text/javascript" src="extjs/ext-all.js"></script>

 <!-- Sets the basepath for the library if not in same directory -->
 <script type="text/javascript">
  mxBasePath = 'src';
 </script>

 <!-- Loads and initiaizes the library -->
 <script type="text/javascript" src="mxclient.js"></script>
     
   <script type="text/javascript">
  function main(container)
  {
   if (!mxClient.isBrowserSupported())
   {
    mxUtils.error('Browser is not supported!', 200, false);
   }
   else
   {
    var graph = new mxGraph(container);
    graph.setCellsResizable(false);
    graph.setEnabled(false);//设置启用,就是允不允许你改变CELL的形状内容。这里我要说明的是必须设置为TRUE才可显示右边的值
    graph.setPanning(true);//移动镜头
    //重写方法不允许那条线可以编辑
    graph.isCellEditable = function(cell)
    {
     return !this.getModel().isEdge(cell)&&!this.getModel().isVertex(cell);
    };
    new mxCellTracker(graph);

 

  //就是这三行代码,一定要记得default-style.xml是editors里面reourse文件夹下的

     var node = mxUtils.load('default-style.xml').getDocumentElement();
    var dec = new mxCodec(node.ownerDocument);
    dec.decode(node, graph.getStylesheet());

    
    var style = graph.getStylesheet().getDefaultVertexStyle();
    style[mxConstants.STYLE_STROKECOLOR] = 'gray';
    style[mxConstants.STYLE_SHADOW] = true;
    style[mxConstants.STYLE_FILLCOLOR] = '#DFDFDF';
    style[mxConstants.STYLE_GRADIENTCOLOR] = 'white';
    style[mxConstants.STYLE_FONTCOLOR] = 'black';
    style[mxConstants.STYLE_FONTSIZE] = '12';
    style[mxConstants.STYLE_SPACING] = 4;
    
    style = graph.getStylesheet().getDefaultEdgeStyle();
    style[mxConstants.STYLE_STROKECOLOR] = '#0C0C0C';
    style[mxConstants.STYLE_LABEL_BACKGROUNDCOLOR] = 'white';
    //定义为形状的关键。可能的值是一个形状前缀或新定义的任何形状的名称的所有常量。
    style[mxConstants.STYLE_EDGE] = mxEdgeStyle.ElbowConnector;
    style[mxConstants.STYLE_ROUNDED] = true;
    style[mxConstants.STYLE_FONTCOLOR] = 'black';
    style[mxConstants.STYLE_FONTSIZE] = '10';    
    graph.gridSize = 20;
    graph.setResizeContainer(true);
    graph.minimumContainerSize = new mxRectangle(0, 0, 500, 380);
    graph.setBorder(60);
    graph.getModel().beginUpdate();
    try
    { 
     read(graph, 'MyXml.xml');
    }
    finally
    {
     graph.getModel().endUpdate();
    }
    new mxDivResizer(container);
    var cell=null;
    var oid;
    var name;
    var div = document.getElementById('properties');//获取属性面板
    // Forces focusout in IE //IE中强调焦点移出事件
    graph.container.focus()
    // Clears the DIV the non-DOM way
    div.innerHTML = ''; //清理DIV没有DOM
    // Gets the selection cell
    //mxUtils.writeln(div, '当前没有选择一项'); //当没有获取CELL时,就显示什么也没有选择
    graph.addListener(mxEvent.CLICK, function(sender, evt)
    {    
     //cell= evt.getProperty('cell');
      //Ext.Ajax.request({   
     //  url:path+'diagram/findDiagram.action',
     //  params:{
     //   id:cell.getId()
     //   },
     //   success: function(resp,opts) { 
                           //  var respText = Ext.util.JSON.decode(resp.responseText);                                                 
                           //  name=respText.name;
                           //  oid=respText.id;  
                          //findbyid(graph,cell,oid,name);
                             //Ext.Msg.alert('错误', respText.name+"====="+respText.id); 
                     //}, 
                    // failure: function(resp,opts) { 
                     //        var respText = Ext.util.JSON.decode(resp.responseText); 
                      //       Ext.Msg.alert('错误', respText.error); 
                     // }   
       
      //});    
    });
   }
  }; 
  function findbyid(graph,cell,oid,name)
  {
   var div = document.getElementById('properties');//获取属性面板
   // Forces focusout in IE //IE中强调焦点移出事件
   graph.container.focus()
   // Clears the DIV the non-DOM way
   div.innerHTML = ''; //清理DIV没有DOM
   // Gets the selection cell
   
   if (cell == null)
   {
    //mxUtils.writeln(div, '当前没有选择一项'); //当没有获取CELL时,就显示什么也没有选择
   }
   else
   {  
    var a=cell.value;
    if(typeof(a)=="object"&&id!="undefined"&&name!="undefined")//判断每个CELL的值是否是对象类型的,如果是就执行对象类型的ID
      var center = document.createElement('center');
       mxUtils.writeln(center, name);
       div.appendChild(center);//将创建好的文本标题填入到DIV层里面去
       mxUtils.br(div);
       var form = new mxForm(); //从USER对象的属性中创建一个FORM 
       form.addText('id:', oid); //创建文本框
       form.addText('name:', name); //创建文本框
       div.appendChild(form.getTable()); //将创建的文本框组合成表格追加到DIV里面去vav
       mxUtils.br(div);
   }
    
    
   }
 
  // Parses the mxGraph XML file format
  function read(graph, filename)
  {
   var req = mxUtils.load(filename);
   var root = req.getDocumentElement();
   var dec = new mxCodec(root.ownerDocument);
   dec.decode(root, graph.getModel());
  }
 </script>
</head>
<!-- Page passes the container for the graph to the grogram -->
<body onLoad="main(document.getElementById('graphContainer'))">
<table>
 <tr>
  <td>
   <div id="graphContainer">
   </div>
  </td>
  <!--<td valign="top"> 垂直对齐在顶部,这个是属性面板 -->
   <!--<div id="properties"
    style="border: solid 1px black; padding: 10px;">
   </div>
  </td> -->

 </tr>
</table>
</body>
</html>

 

 

 

可能有人会问,泳道呢,其实加了刚才三行代码泳道也就自然能显示了

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值