2

I want to set up the Bubble Tree, made by OKFN. https://github.com/okfn/bubbletree/wiki/Bubble-Tree-Documentation

Now I want to input some data in here. I want to go three layers deep. But it doesn't work for some reason. This is the code in the html-file

<!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>

It works when I remove the deepest layer, but that's not sufficient. How can I make this work?

I know there's also a way to make this visualisation work with JSON, but I really don't understand this logic. If that's plan B and someone can help me, that would be great.

1 Answer 1

0

You'll probably want to set up a fiddle, in order to be certain of the issue(s) you're having. Out of the box, the demo found on the BubbleTree GitHub repository definitely works. Based on the information you've provided, it sounds like you're experiencing a known issue with the original library, whereby bubbles with a single (or only two) children don't work right.

Here's the documentation on the original issue: https://github.com/okfn/bubbletree/issues/15

You'll want to replace the broken code with some better code. In the original file, it's at line 521. Replace this...

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;

... with this...

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;

That will definitely get you one step closer. There might be other issues with your code, but I can tell you from personal experience that I didn't have any other issues with the out-of-the-box implementation (yet).

I highly recommend the following two tutorials on the BubbleTree.JS library:

Good luck!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.