swing - How to draw timelines in a tree table -
i writing analyzer visually see application spending time. interface trying achieve (see below) similar tree table
- lines or boxes denote response time.
- be collapsible tree graph
- the ability display metrics in table columns (e.g., start time, cost, etc)
- the ability display labels or description , metrics on left , lines on right
i create following diagram (see below) in r -- unfortunately, although graph production automated, approach not interactive. wondering if suggest better way -- maybe tree table. looked @ many swing, javafx tree table examples. have not seen example has lines (time lines) in tree table.
any suggestions appreciated. in advance.
you can show node in treetablecell
using grahic
property in javafx. includes rectangle
s.
this simple example of showing bars in column using rectangles
:
// arrays in treeitems contain {startvalue, endvalue} (both positive) treeitem<int[]> root = new treeitem<>(new int[]{0, 10}); root.getchildren().addall(new treeitem<>(new int[]{0, 5}), new treeitem<>(new int[]{5, 10})); treetableview<int[]> ttv = new treetableview<>(root); // column displaying bars based on data of treeitem. not use // first column, otherwise alignment off depending on // distance root. treetablecolumn<int[], int[]> column = new treetablecolumn<>(); column.setcellvaluefactory(c -> c.getvalue().valueproperty()); final double bar_size = 20; column.setcellfactory((t) -> new treetablecell<int[], int[]>() { // bar private final rectangle rectangle = new rectangle(0, 10); { setcontentdisplay(contentdisplay.graphic_only); // bar invisible default rectangle.setvisible(false); setgraphic(rectangle); } @override protected void updateitem(int[] item, boolean empty) { super.updateitem(item, empty); if (!empty && item != null) { // resize , display bar, item present rectangle.setwidth((item[1] - item[0]) * bar_size); rectangle.settranslatex(item[0] * bar_size); rectangle.setvisible(true); } else { // no item -> hide bar rectangle.setvisible(false); } } }); // add columns new column // add additional empty column @ start prevent bars being // aligned based on distance root ttv.getcolumns().addall(new treetablecolumn<>(), column);
things need do
- use data type different
int[]
; cell value factory ,treetablecell
needs adjusted accordingly; example of more complex model can found e.g. in oracle tutorial: https://docs.oracle.com/javase/8/javafx/user-interface-tutorial/tree-table-view.htm - choose better colors; these colors e.g. stored in
map
, created if new 1 needed. - add additional colums
Comments
Post a Comment