2013-10-30 2 views
1

저는 사용중인 Jit Infovis의 이상한 행동에 직면하고 있습니다. Javascript 파일에서로드 json 함수를 포함하는 두 개의 다른 html 파일이 있습니다. 이 함수는 infovis 라이브러리를 사용하여 json 파일에서 하이퍼 트리 맵을 표시합니다. 두 html 파일 모두 동일한 json 파일을로드합니다.Infovis가 루트 노드를 반복하지 않습니다

하나의 html 파일이 맵 렌더링에 성공했습니다. 그러나 다른 사람은 그렇지 않습니다. 지도를 거의 제대로 렌더링하지만, 디버깅 한 후에 루트 노드를 반복하지 않습니다. 그런 다음 레이블 및 클릭 가능성없이 루트 노드가 비활성화됩니다.

이것은 내가 사용하고있는 js 기능입니다.

 var labelType, useGradients, nativeTextSupport, animate; 

     (function() { 
      var ua = navigator.userAgent, 
      iStuff = ua.match(/iPhone/i) || ua.match(/iPad/i), 
      typeOfCanvas = typeof HTMLCanvasElement, 
      nativeCanvasSupport = (typeOfCanvas == 'object' || typeOfCanvas == 'function'), 
      textSupport = nativeCanvasSupport 
      && (typeof document.createElement('canvas').getContext('2d').fillText == 'function'); 
         //I'm setting this based on the fact that ExCanvas provides text support for IE 
         //and that as of today iPhone/iPad current text support is lame 
         labelType = (!nativeCanvasSupport || (textSupport && !iStuff)) ? 'Native' : 'HTML'; 
         nativeTextSupport = labelType == 'Native'; 
         useGradients = nativeCanvasSupport; 
         animate = !(iStuff || !nativeCanvasSupport); 
        })(); 

        var Log = { 
         elem: false, 
         write: function (text) { 
          if (!this.elem) 
           this.elem = document.getElementById('log'); 
          this.elem.innerHTML = text; 
          this.elem.style.left = (350 - this.elem.offsetWidth/2) + 'px'; 
         } 
        }; 



        function init(slugParam, pageParam) { 
         var isFirst = true; 
         var isSetAsRoot = false; 
         // alert(slugParam+ " | "+pageParam); 

         var url = Routing.generate('trade_map_buyer_json', { slug : slugParam, page : pageParam }); 
         //init data 
         $.getJSON(url, function (json) { 
          var type = 'Buyer'; 
          //end 
          var infovis = document.getElementById('infovis'); 
          infovis.style.align = "center"; 
          infovis.innerHTML = ''; 
          // infovis.innerHTML = '<img align="center" id="gifloader" style="margin-left:50%; margin-top:50%" src="{{ asset('/bundles/jariffproject/frontend/images/preloader.gif') }}" width="30px" height="30px"/>' 
          var w = infovis.offsetWidth - 50, h = infovis.offsetHeight - 50; 

          url = url.replace("/json/", "/"); 
          window.history.pushState("object or string", "Title", url); 
          //init Hypertree 
          var ht = new $jit.Hypertree({ 
           //id of the visualization container 
           injectInto: 'infovis', 
           Navigation: { 
            enable: false, 
            panning: 'avoid nodes', 
           }, 
           //canvas width and height 
           width: w, 
           height 

    : h, 
          //Change node and edge styles such as 
          //color, width and dimensions. 

          Node: { 
           dim: 9, 
           overridable: true, 
           color: "#66FF33" 
          }, 
         Tips: { 
          enable: true, 
          type: 'HTML', 
          offsetX: 0, 
          offsetY: 0, 
          onShow: function(tip, node) { 
           // dump(tip); 
           tip.innerHTML = "<div style='background-color:#F8FFC9;text-align:center;border-radius:5px; padding:10px 10px;' class='node-tip'><p style='font-size:100%;font-weight:bold;'>"+node.name+"</p><p style='font-size:50%pt'>"+node.data.address+"</p></div>"; 
          }  
         }, 
         Events: { 
          enable: true, 
          type: 'HTML', 
          onMouseEnter: function(node, eventInfo, e){ 
           var nodeId = node.id; 
           var menu1 = [ 
           {'set as Root':function(menuItem,menu) { 
            menu.hide(); 
            isSetAsRoot = true; 
            console.log(nodeId); 
            init(nodeId, 0); 
           }}, 
           $.contextMenu.separator, 
           {'View details':function(menuItem,menu) { 
           }} 
           ]; 
           $('.node').contextMenu(menu1,{theme:'vista'}); 
          } 
         }, 
         Edge: { 
          lineWidth: 1, 
          color: "#52D5DE", 
          overridable: true, 
         }, 
         onBeforePlotNode: function(node) 
         { 
          if (isFirst) { 
           console.log(node._depth); 
           var odd = isOdd(node._depth); 
           if (odd) { 
            node.setData('color', "#66FF33"); // hijau (supplier) 
           } else { 
            node.setData('color', "#FF3300"); // merah (buyer) 
           } 
           isFirst = false; 
          } 
         }, 
         onPlotNode: function(node) 
         { 
          if (isSetAsRoot) { 
           var nodeInstance = node.getNode(); 
           var nodeId = nodeInstance.id; 
           init(nodeId, 0); 
           isSetAsRoot = false; 
          } 
         }, 
         onBeforeCompute: function (domElement, node) { 
          var dot = ht.graph.getClosestNodeToOrigin("current"); 
          type = isOdd(dot._depth) ? 'Supplier' : 'Buyer'; 
         }, 
         //Attach event handlers and add text to the 
         //labels. This method is only triggered on label 
         //creation 
         onCreateLabel: function (domElement, node) { 
          var odd = isOdd(node._depth); 
          if (odd) { 
           node.setData('color', "#66FF33"); // hijau (supplier) 
          } else { 
           node.setData('color', "#FF3300"); // merah (buyer) 
          } 

          domElement.innerHTML = node.name; 
          // if (node._depth == 1) { 
           console.log("|"+node.name+"|"+node._depth+"|"); 
          // } 
          $jit.util.addEvent(domElement, 'click', function() { 
           ht.onClick(node.id, { 
            onComplete: function() { 
             console.log(node.id); 
             ht.controller.onComplete(node); 
            } 
           }); 
          }); 

         }, 

         onPlaceLabel: function (domElement, node) { 
          var style = domElement.style; 
          style.display = ''; 
          style.cursor = 'pointer'; 
          if (node._depth <= 1) { 
           style.fontSize = "0.8em"; 
           style.color = "#000"; 
           style.fontWeight = "normal"; 

          } else if (node._depth == 2) { 
           style.fontSize = "0.7em"; 
           style.color = "#555"; 

          } else { 
           style.display = 'none'; 
          } 

          var left = parseInt(style.left); 
          var w = domElement.offsetWidth; 
          style.left = (left - w/2) + 'px'; 
         }, 

         onComplete: function (node) { 
          var dot = ht.graph.getClosestNodeToOrigin("current"); 
          console.log(dot._depth); 
          var connCount = dot.data.size; 
          var showingCount = ''; 
          if (connCount != undefined) { 
           var pageParamInt = (parseInt(pageParam)+1) * 10; 
           var modulus = connCount%10; 

           showingCount = (pageParamInt - 9) + " - " + pageParamInt; 

           if (connCount - (pageParamInt - 9) < 10) { 
            showingCount = (pageParamInt - 10) + " - " + ((pageParamInt - 10) + modulus); 
           } 
          } else { 
           connCount = '0'; 
           showingCount = 'No Connections Shown' 
          } 

         } 
        }); 
        //load JSON data. 
        ht.loadJSON(json); 

        //compute positions and plot. 
        ht.refresh(); 
        //end 
        ht.controller.onComplete(); 
       }); 
} 

function isEven(n) 
{ 
    return isNumber(n) && (n % 2 == 0); 
} 

function isOdd(n) 
{ 
    return isNumber(n) && (n % 2 == 1); 
} 
function isNumber(n) 
{ 
    return n === parseFloat(n); 
} 

function processAjaxData(response, urlPath){ 
} 

function dump(obj) { 
    var out = ''; 
    for (var i in obj) { 
     out += i + ": " + obj[i] + "\n"; 
    } 
    out = out + "\n\n" 

    console.log(out); 

    // or, if you wanted to avoid alerts... 

    var pre = document.createElement('pre'); 
    pre.innerHTML = out; 
    document.body.appendChild(pre) 
} 

아마도이 문제의 원인은 무엇일까요?

답변

1

충돌 ID가 있는지 확인하십시오. 기본적으로 infovis는 각 노드를 id로 렌더링합니다. 노드의 DOM 요소 하나와 동일한 ID를 가진 DOM 요소가있는 경우. 충돌을 일으키고 렌더링하지 않습니다.

dom 요소를 노드를 거치지 않고 확인하여 확인할 수 있습니다.

+0

물론 사실입니다! –

관련 문제