2012-08-07 123 views
2

我想设置OKFN泡泡树。 https://github.com/okfn/bubbletree/wiki/Bubble-Tree-DocumentationOKFN泡泡树中的数据输入

现在我想在这里输入一些数据。我想深入三层。但是由于某种原因它不起作用。这是html文件中的代码

<!DOCTYPE html> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
    <meta charset="UTF-8"/> 
    <title>Mijn financien</title> 
    <script type="text/javascript" src="../../lib/jquery-1.5.2.min.js"></script> 
    <script type="text/javascript" src="../../lib/jquery.history.js"></script> 
    <script type="text/javascript" src="../../lib/raphael.js"></script> 
    <script type="text/javascript" src="../../lib/vis4.js"></script> 
    <script type="text/javascript" src="../../lib/Tween.js"></script> 
    <script type="text/javascript" src="../../build/bubbletree.js"></script> 
    <script type="text/javascript" src="http://assets.openspending.org/openspendingjs/master/lib/aggregator.js"></script> 
    <link rel="stylesheet" type="text/css" href="../../build/bubbletree.css" /> 
    <script type="text/javascript" src="../../styles/cofog.js"></script> 


    <script type="text/javascript"> 

     $(function() { 


      var data = { 
       label: 'Totaal', 
       amount: 100, 
       children: [ 
        { label: 'Een hele lange zin om te testen hoe dat eruit komt te zien', amount: 10, color: '#D95F02', 
         children: [ 
         { label: 'Dingen', amount: 5, color: '#66C2A4' }, 
         { label: 'Stuff', amount: 5, color: '#B2E2E2' } 
        ] }, 
        { label: 'Dingen en stuff', amount: 80, color: '#1B9E77', 
         children: [ 
         { label: 'Dingen', amount: 30, color: '#66C2A4' }, 
         { label: 'Stuff', amount: 50, color: '#B2E2E2' } 
        ] 
        }, 
        { label: 'Bananen in pyjamas', amount: 10, color: '#7570B3', 
         children: [ 
         { label: 'Bananen', amount: 5, color: '#7570B3' }, 
         { label: 'Pyjamas', amount: 5, color: '#7570B3', 
         children: [ 
         { label: 'Dingen', amount: 3, color: '#66C2A4' }, 
         { label: 'Stuff', amount: 2, color: '#B2E2E2' } 
        ] } 
        ] 
        } 
       ] 
      }; 

      new BubbleTree({ 
       data: data, 
       bubbleType: 'icon', 
       container: '.bubbletree' 
      }); 

     }); 

    </script> 
</head> 
<body> 
    <div class="bubbletree-wrapper"> 
     <div class="bubbletree"></div> 
    </div> 
</body> 
</html> 

它在我移除最深层时起作用,但这还不够。我该如何做这项工作?

我知道还有一种方法可以使这种可视化工作与JSON,但我真的不明白这个逻辑。如果这是B计划,有人可以帮助我,那会很棒。

回答

0

您可能会想要设置一个小提琴,以确定您遇到的问题。开箱即用,BubbleTree GitHub存储库上的演示绝对有效。根据您提供的信息,这听起来像是您遇到了原始图书馆的一个已知问题,即只有一个(或只有两个)孩子的泡泡不能正常工作。

这里的原始问题的文档: https://github.com/okfn/bubbletree/issues/15

你会想一些更好的代码替换断码。在原来的文件,它在521线替换这...

rad2 = 0 - Math.max(
    //hw *0.8 - tgtScale * (a2rad(node.parent.amount)+a2rad(node.amount)), // maximum visible part 
    hw * 0.8 - tgtScale * (a2rad(node.parent.amount) + a2rad(Math.max(node.amount*1.15 +  node.maxChildAmount*1.15, node.left.amount * 0.85, node.right.amount * 0.85))), 
    tgtScale*a2rad(node.parent.amount)*-1 + hw*0.15 // minimum visible part 
) + hw; 

...这... ...

rad2 = 0 - Math.max(
    hw * 0.8 - tgtScale * (a2rad(node.parent.amount) + a2rad(Math.max(node.amount*1.15 + node.maxChildAmount*1.15, (node.left ? node.left.amount : 0) * 0.85, (node.right ? node.right.amount : 0) * 0.85))), 
    tgtScale*a2rad(node.parent.amount)*-1 + hw*0.15 // minimum visible part 
) + hw; 

那一定会得到你更近了一步。您的代码可能存在其他问题,但我可以从个人经验告诉您,我现在还没有任何其他问题与即时可用的实现(尚未)。

我强烈建议在BubbleTree.JS库中的以下两个教程:

祝你好运!