2017-06-06 60 views
0

使用the latest Flare build最初由prefuse構建,我試圖獲得一個縮進字段,如Layouts中看到的縮進字段here。我正在處理從Google Firebase提取的對象列表。雖然我可以把它們放在一張圖上,並比較一個值和其他值,但我無法在不同的佈局上找到說明。我即將學習文檔,但我想知道是否還有其他東西可以參考。Flare ItemVisualisation


編輯: http://flare.prefuse.org/api/flare/vis/operator/layout/Layout.html我發現一般佈局在這裏。但是,除非我使用AxisLayout,否則我只能顯示1或2個圓圈。

僅供參考,我從firebase中獲取的數據就是這樣的。

一組對象。 每個對象都有屬性名稱,銷售量,日期,活動等。

我希望它像上面的例子一樣,並在每個圓圈中顯示項目名稱。然後,當用戶點擊該圈子時,他可以顯示該項目的屬性。


編輯:我能找到的一篇文章,而是構建在他設定的格式我的數據了幾個小時之後,我不能夠完全模擬它。 http://simon.oconnorlamb.com/ria/2012/03/visualising-data-with-flare/


編輯:細講:

當我從谷歌火力地堡的json名單拉我解析它,以便它把在referencable類別的項目。所有這些都進入了一個數組來模擬我上面鏈接的教程。我試圖儘可能地模擬結構。

private function handleDataRead(e:DatabaseEvent):void 
    { 
     var trueDataArray:Array = new Array(); 

     //Extract manufacturers. 
     var manufacturers:Vector.<String> = new Vector.<String>(); 
     for each (var item:Object in e.data) 
     { 
      if (manufacturers.indexOf(item.Manufacturer) == -1) 
      { 
       manufacturers.push(item.Manufacturer); 
       //Example: {type:'Manufacturer',id:'0',name:'Company A'} 
       trueDataArray.push({type:'manufacturer', 
       id:manufacturers.indexOf(item.Manufacturer).toString(), 
       name:item.Manufacturer}); 
      } 
     } 

     //Extract Item Name 
     var itemNames:Vector.<String> = new Vector.<String>(); 
     for each (var item:Object in e.data) 
     { 
      if (itemNames.indexOf(item.ItemName) == -1) 
      { 
       itemNames.push(item.ItemName); 
       var idValue:String = new String(itemNames.indexOf(item.ItemName) + (manufacturers.length - 1) +1); 
       trueDataArray.push({type:'item', 
       id:idValue, 
       name:item.ItemName, 
       manufacturer:manufacturers.indexOf(item.Manufacturer).toString()}); 
      } 
     } 


     //Extract property 1 
     var mlCount:Vector.<int> = new Vector.<int>(); 
     for each (var item:Object in e.data) 
     { 
      if (item.hasOwnProperty("ML")) 
      { 
       if (mlCount.indexOf(item.ML) == -1) 
       { 
        mlCount.push(item.ML); 
        var idValue:String = new String(mlCount.indexOf(item.ML) + (itemNames.length - 1) + (manufacturers.length - 1) +1); 
        trueDataArray.push({type:'mL', 
        id:idValue, 
        name:(item.ML as int).toString(), 
        item:itemNames.indexOf(item.ItemName).toString()}); 
       } 
      }    
     } 

     //Extract another property 
     var mgCount:Vector.<int> = new Vector.<int>(); 
     for each (var item:Object in e.data) 
     { 
      if (item.hasOwnProperty("MG")) 
      { 
       if (mgCount.indexOf(item.MG) == -1) 
       { 
        mgCount.push(item.MG); 
        var idValue:String = new String(mgCount.indexOf(item.MG) + mlCount.indexOf(item.ML) + (itemNames.length - 1) + (manufacturers.length - 1) +1); 
        trueDataArray.push({type:'mG', 
        id:idValue, 
        name:(item.MG as int).toString(), 
        mL:mlCount.indexOf(item.ML).toString()}); 
       } 
      } 

     } 

結果看起來像這樣。

[ 
    { 
     "name":"Company A", 
     "type":"manufacturer", 
     "id":"0" 
    }, 
    { 
     "name":"Company B", 
     "type":"manufacturer", 
     "id":"1" 
    }, 
    { 
     "name":"Company C", 
     "type":"manufacturer", 
     "id":"2" 
    }, 
    { 
     "name":"Company D", 
     "type":"manufacturer", 
     "id":"3" 
    }, 
    { 
     "name":"Company E", 
     "type":"manufacturer", 
     "id":"4" 
    }, 
    { 
     "type":"manufacturer", 
     "id":"5" 
    }, 
... //So on 
    { 
     "manufacturer":"0", 
     "name":"Item Name 1", 
     "type":"item", 
     "id":"18" 
    }, 
    { 
     "manufacturer":"0", 
     "name":"Item Name 2", 
     "type":"item", 
     "id":"19" 
    }, 
    { 
     "manufacturer":"0", 
     "name":"Item Name 3", 
     "type":"item", 
     "id":"20" 
    }, 
    { 
     "manufacturer":"0", 
     "name":"Item Name 4", 
     "type":"item", 
     "id":"21" 
...//So on 
    { 
     "name":"60", 
     "item":"0", 
     "type":"mL", 
     "id":"195" 
    }, 
    { 
     "name":"100", 
     "item":"5", 
     "type":"mL", 
     "id":"196" 
    }, 
    { 
     "name":"120", 
     "item":"36", 
     "type":"mL", 
     "id":"197" 
    }, 
    { 
     "name":"30", 
     "item":"100", 
     "type":"mL", 
     "id":"198" 
    } 
    ...//and so forth 
] 

當我通過這我的函數來創建節點和邊緣(即我又基於關閉在上面的鏈接博客)

public function buildTree(arr:Array):Data 
    { 
     var d:Data = new Data(true); 
     //Keyed lookup for easy edge addition in step 2 
     var nodeLookup:Object = {}; 
     var row:Object; 
     var ns:NodeSprite; 
     //Step 1: Add all rows of data; 
     for each(row in arr){ 
      ns = d.addNode(row); 
      nodeLookup[row.id] = ns; 
     } 
     //Step 2: Add edges 
     for each(ns in d.nodes){ 
      if(ns.data.hasOwnProperty('manufacturer')){ 
       d.addEdgeFor(nodeLookup[ns.data.manufacturer],ns); 
      } 
      else if(ns.data.hasOwnProperty('item')){ 
       d.addEdgeFor(nodeLookup[ns.data.item],ns); 
      } 
      else if(ns.data.hasOwnProperty('mL')){ 
       d.addEdgeFor(nodeLookup[ns.data.mL],ns); 
      } 
     } 
     return d; 
    } 

,構建它

 data = buildTree(trueDataArray); 
     sourceTree = new ItemVisualisation(data); 


     sourceTree.bounds = new Rectangle(10, 10, 550, 550); 
     sourceTree.x = 20; 
     sourceTree.y = 20; 
     addChild(sourceTree); 

     sourceTree.operators.add(new IndentedTreeLayout()); 
     sourceTree.operators.add(new ShapeEncoder("data.type")); 
     sourceTree.operators.add(new ColorEncoder("data.type", Data.NODES, "lineColor", ScaleType.CATEGORIES)); 
     sourceTree.data.nodes.setProperties({fillColor:0, lineWidth:2}); 
     sourceTree.update(); 

我得到以下... enter image description here

我差點把這下來但我不知道我做錯了什麼。一切似乎都是應該的。


編輯:似乎節點可能正確鏈接,但這不是我想要的佈局。我無法獲得任何其他佈局。

enter image description here

回答

0
trueDataArray.push({type:'root', id:0, name:'rootname'}); 

我能夠通過結合一切1個節點來解決這個問題。我列出了兩步以外的任何問題,但這超出了我的項目要求。 enter image description here

相關問題