2

我想设置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 计划并且有人可以帮助我,那就太好了。

4

1 回答 1

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 库的两个教程:

祝你好运!

于 2014-06-30T19:12:46.190 回答