JFG-784 Display legend as tree and add possibility to collapse it

!NOTE! first of all should be merged https://github.com/griddynamics/jagger/pull/529
why here? why not in for loop before break?