# Custom node dependent `nodesize`

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

``````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)
``````

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