OKFN Bubble Tree中的数据输入

时间:2012-08-07 08:42:12

标签: javascript data-visualization bubble-chart

我想设置由OKFN制作的泡泡树。 https://github.com/okfn/bubbletree/wiki/Bubble-Tree-Documentation

现在我想在这里输入一些数据。我想深入三层。但它出于某种原因并不起作用。这是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和某人可以帮助我,那就太好了。

1 个答案:

答案 0 :(得分: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库上的以下两个教程:

祝你好运!