# Custom node dependent \`nodesize\`

**URL:** <https://discourse.julialang.org/t/custom-node-dependent-nodesize/46098>\
**Category:** Visualization\
**Tags:** question, plotting\
**Created:** [September 5, 2020, 11:09am UTC](https://discourse.julialang.org/t/custom-node-dependent-nodesize/46098 "2020-09-05T11:09:13Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![ohmsweetohm1](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ohmsweetohm1/32/49126_2.png) [@ohmsweetohm1](https://discourse.julialang.org/u/ohmsweetohm1)\
**Post date:** [September 5, 2020, 11:09am UTC](https://discourse.julialang.org/t/custom-node-dependent-nodesize/46098/1 "2020-09-05T11:09:13Z")

</div>

Is it possible to use a custom method to compute the node size for a tree?

```julia
using AbstractTrees, Plots, GraphRecipes

mutable struct BinaryNode{T}
    data::T
    parent::BinaryNode{T}
    left::BinaryNode{T}
    right::BinaryNode{T}

    # Root constructor
    BinaryNode{T}(data) where T = new{T}(data)
    # Child node constructor
    BinaryNode{T}(data, parent::BinaryNode{T}) where T = new{T}(data, parent)
end
BinaryNode(data) = BinaryNode{typeof(data)}(data)

function leftchild(data, parent::BinaryNode)
    !isdefined(parent, :left) || error("left child is already assigned")
    node = typeof(parent)(data, parent)
    parent.left = node
end
function rightchild(data, parent::BinaryNode)
    !isdefined(parent, :right) || error("right child is already assigned")
    node = typeof(parent)(data, parent)
    parent.right = node
end

## Things we need to define
function AbstractTrees.children(node::BinaryNode)
    if isdefined(node, :left)
        if isdefined(node, :right)
            return (node.left, node.right)
        end
        return (node.left,)
    end
    isdefined(node, :right) && return (node.right,)
    return ()
end

## Things that make printing prettier
AbstractTrees.printnode(io::IO, node::BinaryNode) = print(io, node.data)

root = BinaryNode(1)
l = leftchild(1, root)
r = rightchild(2, root)
lr = rightchild(3, l)

plot(TreePlot(root), method=:buchheim, fontsize=7, nodeshape=:circle)

```

![image](https://global.discourse-cdn.com/julialang/original/3X/b/b/bbb415b767da3640aa4818c848ce18e4f11e43ea.png)

In this simple example I would chose the node size: `size = 1 / node.data`.
