Due to the way that d3-dag (and typescript) infers types, a constant
function (e.g. () => [1, 1]
) may infer data types as never
producing
errors down the line. In these cases, you'll want to use a constant tuple.
This example sets the node width to the length of the name. In most cases you'd probably want to actually render the text and measure the size, rather than assume a fixed width, but this example is easier to understand.
function widthSize({ data }: GraphNode<{ name: string }>): [number, number] {
return [data.name.length, 1];
}
Generated using TypeDoc
an accessor for computing the size of a node in the layout
A node size can either be a constant tuple of
[width, height]
, or a callable, that takes a node and returns the width and height for that node.