selectTopNodes returns a slice of the top maxNodes nodes in a graph.
(maxNodes int, visualMode bool)
| 854 | |
| 855 | // selectTopNodes returns a slice of the top maxNodes nodes in a graph. |
| 856 | func (g *Graph) selectTopNodes(maxNodes int, visualMode bool) Nodes { |
| 857 | if maxNodes > 0 { |
| 858 | if visualMode { |
| 859 | var count int |
| 860 | // If generating a visual graph, count tags as nodes. Update |
| 861 | // maxNodes to account for them. |
| 862 | for i, n := range g.Nodes { |
| 863 | tags := min(countTags(n), maxNodelets) |
| 864 | if count += tags + 1; count >= maxNodes { |
| 865 | maxNodes = i + 1 |
| 866 | break |
| 867 | } |
| 868 | } |
| 869 | } |
| 870 | } |
| 871 | if maxNodes > len(g.Nodes) { |
| 872 | maxNodes = len(g.Nodes) |
| 873 | } |
| 874 | return g.Nodes[:maxNodes] |
| 875 | } |
| 876 | |
| 877 | // countTags counts the tags with flat count. This underestimates the |
| 878 | // number of tags being displayed, but in practice is close enough. |
no test coverage detected