Skip to content

Commit 1c6450d

Browse files
authored
Merge pull request #119 from dengzq1234/desktop_v2
Desktop v2
2 parents 65855ff + fd4e46e commit 1c6450d

File tree

4 files changed

+370
-70
lines changed

4 files changed

+370
-70
lines changed

treeprofiler/app.py

Lines changed: 138 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@
6969
'piechart-layout',
7070
'background-layout',
7171
'categorical-matrix-layout',
72-
'profiling-layout'
72+
'profiling-layout',
73+
'nodesymbol-layout',
7374
]
7475

7576
categorical_prefix = [
@@ -80,7 +81,9 @@
8081
"piechart",
8182
"background",
8283
"categorical-matrix",
83-
"profiling"
84+
"profiling",
85+
'textbranch',
86+
'nodesymbol'
8487
]
8588

8689
numerical_prefix = [
@@ -914,9 +917,40 @@ def explore_tree(treename):
914917
},
915918
"layer": {}
916919
}
917-
layout_config['layer']['categoricalColorscheme'] = layer.get('categoricalColorscheme', 'default')
920+
if layout_prefix == 'textbranch':
921+
layout_config['layer']['textPosition'] = layer.get('textPosition', 'branch_bottom')
922+
if layer.get('textunicolorColor'):
923+
layout_config['layer']['istextUnicolor'] = 'True'
924+
else:
925+
layout_config['layer']['istextUnicolor'] = 'False'
926+
layout_config['layer']['textColorScheme'] = layer.get('textColorScheme')
927+
layout_config['layer']['textunicolorColor'] = layer.get('textunicolorColor')
928+
929+
else:
930+
layout_config['layer']['categoricalColorscheme'] = layer.get('categoricalColorscheme', 'default')
931+
932+
# numerical layout
933+
934+
elif layout_prefix in ['circlenode', 'squarenode', 'trianglenode']:
935+
# basic
936+
color_config = color_config.get(applied_props, {})
937+
layout_config = {
938+
"layout_name": name, # Retrieve layout name from processed layouts
939+
"applied_props": [applied_props], # Props linked to this layout
940+
"config": {
941+
"level": getattr(layout, 'column', level),
942+
"column_width": getattr(layout, 'column_width', default_configs['column_width']),
943+
"padding_x": getattr(layout, 'padding_x', default_configs['padding_x']),
944+
"padding_y": getattr(layout, 'padding_y', default_configs['padding_y']),
945+
#"color_config": color_config
946+
},
947+
"layer": {}
948+
}
949+
layout_config['layer']['categoricalColorscheme'] = layer.get('categoricalColorscheme', 'default')
950+
layout_config['layer']['symbolOption'] = layer.get('symbolOption', 'circle')
951+
layout_config['layer']['symbolSize'] = float(layer.get('symbolSize', 5))
952+
layout_config['layer']['fgopacity'] = float(layer.get('fgopacity', 0.8))
918953

919-
# numerical layout
920954
elif layout_prefix in numerical_prefix:
921955
if layout_prefix == 'barplot':
922956
# basic
@@ -1085,7 +1119,6 @@ def explore_tree(treename):
10851119
for layout_meta in updated_metadata:
10861120
layout = layout_manager.get(layout_meta['layout_name'])
10871121
layout_prefix = layout_meta['layout_name'].split('_')[0].lower()
1088-
10891122
if layout:
10901123
# for categorical
10911124
if layout_prefix in categorical_prefix:
@@ -1107,6 +1140,30 @@ def explore_tree(treename):
11071140
layout.padding_x = layout_meta['config']['padding_x']
11081141
layout.padding_y = layout_meta['config']['padding_y']
11091142
layout.color_dict = color_config.get(prop).get('value2color')
1143+
elif layout_prefix == 'textbranch':
1144+
1145+
layout.position = layout_meta['layer'].get('textPosition')
1146+
1147+
if layout_meta['layer'].get('istextUnicolor') == 'True':
1148+
layout.text_color = layout_meta['layer'].get('textunicolorColor')
1149+
layout.color_dict = {}
1150+
else:
1151+
layout.text_color = None
1152+
text_color_scheme = layout_meta['layer'].get('textColorScheme', None)
1153+
prop_values = sorted(list(set(utils.tree_prop_array(t, prop))))
1154+
paired_color = get_colormap_hex_colors(text_color_scheme, len(prop_values))
1155+
color_config[prop] = {}
1156+
color_config[prop]['value2color'] = utils.assign_color_to_values(prop_values, paired_color)
1157+
color_config[prop]['detail2color'] = {}
1158+
color_dict = color_config.get(prop).get('value2color')
1159+
layout.color_dict = color_dict
1160+
1161+
# change directly in layout
1162+
layout.column = layout_meta['config']['level']
1163+
layout.width = layout_meta['config']['column_width']
1164+
layout.padding_x = layout_meta['config']['padding_x']
1165+
layout.padding_y = layout_meta['config']['padding_y']
1166+
11101167
else:
11111168
categorical_color_scheme = layout_meta['layer'].get('categoricalColorscheme', 'default')
11121169
prop_values = sorted(list(set(utils.tree_prop_array(t, prop))))
@@ -1122,6 +1179,26 @@ def explore_tree(treename):
11221179
layout.padding_y = layout_meta['config']['padding_y']
11231180
layout.color_dict = color_config.get(prop).get('value2color')
11241181

1182+
1183+
elif layout_prefix in ['circlenode', 'squarenode', 'trianglenode']:
1184+
prop = layout_meta['applied_props'][0]
1185+
layout.symbol = layout_meta['layer'].get('symbolOption', 'circle')
1186+
layout.symbol_size = float(layout_meta['layer'].get('symbolSize', 5))
1187+
layout.fgopacity = float(layout_meta['layer'].get('fgopacity', 0.8))
1188+
1189+
categorical_color_scheme = layout_meta['layer'].get('categoricalColorscheme', 'default')
1190+
prop_values = sorted(list(set(utils.tree_prop_array(t, prop))))
1191+
paired_color = get_colormap_hex_colors(categorical_color_scheme, len(prop_values))
1192+
color_config[prop] = {}
1193+
color_config[prop]['value2color'] = utils.assign_color_to_values(prop_values, paired_color)
1194+
color_config[prop]['detail2color'] = {}
1195+
1196+
# change directly in layout
1197+
layout.column = layout_meta['config']['level']
1198+
layout.width = layout_meta['config']['column_width']
1199+
layout.padding_x = layout_meta['config']['padding_x']
1200+
layout.padding_y = layout_meta['config']['padding_y']
1201+
layout.color_dict = color_config.get(prop).get('value2color')
11251202
# for binary
11261203
elif layout_prefix in binary_prefix:
11271204
prop = layout_meta['applied_props'][0]
@@ -1139,7 +1216,7 @@ def explore_tree(treename):
11391216
layout.width = layout_meta['config']['column_width']
11401217
layout.padding_x = layout_meta['config']['padding_x']
11411218
layout.padding_y = layout_meta['config']['padding_y']
1142-
1219+
11431220
# for numerical
11441221
elif layout_prefix in numerical_prefix:
11451222
prop = layout_meta['applied_props'][0]
@@ -1379,12 +1456,12 @@ def process_layer(t, layer, tree_info, current_layouts, current_props, level, co
13791456

13801457
# binary settings
13811458
if selected_layout == 'binary-layout':
1382-
same_color = layer.get('isUnicolor', True)
1459+
same_color = layer.get('isbinaryUnicolor', True)
13831460

13841461
if not same_color:
1385-
bianry_color_scheme = layer.get('binaryColorscheme', 'default')
1462+
bianry_color_scheme = layer.get('binaryColorScheme', 'default')
13861463
else:
1387-
unicolorColor = layer.get('unicolorColor', '#ff0000')
1464+
unicolorColor = layer.get('binaryunicolorColor', '#ff0000')
13881465

13891466
aggregate_option = layer.get('aggregateOption', 'gradient')
13901467

@@ -1399,16 +1476,66 @@ def process_layer(t, layer, tree_info, current_layouts, current_props, level, co
13991476

14001477
# Apply selected layout based on type directly within this function
14011478
if selected_layout in categorical_layout_list:
1402-
14031479
for index, prop in enumerate(selected_props):
14041480
prop_values = sorted(list(set(utils.tree_prop_array(t, prop))))
14051481
paired_color = get_colormap_hex_colors(categorical_color_scheme, len(prop_values))
14061482
color_config[prop] = {}
14071483
color_config[prop]['value2color'] = utils.assign_color_to_values(prop_values, paired_color)
14081484
color_config[prop]['detail2color'] = {}
14091485

1410-
level, current_layouts = apply_categorical_layouts(t, selected_layout, selected_props, tree_info, current_layouts, level, column_width, padding_x, padding_y, color_config)
1486+
if selected_layout == 'nodesymbol-layout':
1487+
for prop in selected_props:
1488+
color_dict = color_config.get(prop)['value2color']
1489+
symbol = layer.get('symbolOption', 'circle')
1490+
symbol_size = layer.get('symbolSize', 5)
1491+
if symbol_size:
1492+
symbol_size = float(symbol_size)
1493+
fgopacity = layer.get('fgopacity', 0.8)
1494+
1495+
layout = layouts.text_layouts.LayoutSymbolNode(f'{symbol}Node_{prop}', prop=prop,
1496+
column=level, symbol=symbol, symbol_color=None, color_dict=color_dict,
1497+
symbol_size=symbol_size,
1498+
padding_x=padding_x, padding_y=padding_y, fgopacity=fgopacity,
1499+
scale=True, legend=True, active=True
1500+
)
1501+
level +=1
1502+
current_layouts.append(layout)
1503+
1504+
else:
1505+
level, current_layouts = apply_categorical_layouts(t, selected_layout, selected_props, tree_info, current_layouts, level, column_width, padding_x, padding_y, color_config)
14111506

1507+
elif selected_layout == 'textbranch-layout':
1508+
# text branch
1509+
1510+
text_position = layer.get('textPosition', 'branch_bottom')
1511+
text_color_scheme = layer.get('textColorScheme', None)
1512+
1513+
text_color = layer.get('textunicolorColor', None)
1514+
1515+
if text_color:
1516+
for prop in selected_props:
1517+
layout = layouts.text_layouts.LayoutTextbranch(name='TextBranch_'+prop,
1518+
column=level, text_color=text_color, color_dict={}, prop=prop,
1519+
position=text_position, width=column_width,
1520+
padding_x=padding_x, padding_y=padding_y)
1521+
level +=1
1522+
current_layouts.append(layout)
1523+
else:
1524+
for index, prop in enumerate(selected_props):
1525+
prop_values = sorted(list(set(utils.tree_prop_array(t, prop))))
1526+
paired_color = get_colormap_hex_colors(text_color_scheme, len(prop_values))
1527+
color_config[prop] = {}
1528+
color_config[prop]['value2color'] = utils.assign_color_to_values(prop_values, paired_color)
1529+
color_config[prop]['detail2color'] = {}
1530+
for prop in selected_props:
1531+
color_dict = color_config.get(prop).get('value2color')
1532+
layout = layouts.text_layouts.LayoutTextbranch(name='TextBranch_'+prop,
1533+
column=level, text_color=None, color_dict=color_dict, prop=prop,
1534+
position=text_position, width=column_width,
1535+
padding_x=padding_x, padding_y=padding_y)
1536+
level +=1
1537+
current_layouts.append(layout)
1538+
14121539
elif selected_layout == 'binary-layout':
14131540
for index, prop in enumerate(selected_props):
14141541
prop_values = utils.tree_prop_array(t, prop, leaf_only=True)

treeprofiler/layouts/text_layouts.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -263,13 +263,14 @@ def set_node_style(self, node):
263263
# node.add_face(prop_face, column=self.column, position="branch_right", collapsed_only=True)
264264

265265
class LayoutTextbranch(TreeLayout):
266-
def __init__(self, name, column, text_color, color_dict, prop, width=70, min_fsize=5, max_fsize=15, padding_x=1, padding_y=0, legend=True, aligned_faces=True):
266+
def __init__(self, name, column, text_color, color_dict, prop, position="branch_bottom", width=70, min_fsize=5, max_fsize=15, padding_x=1, padding_y=0, legend=True, aligned_faces=True):
267267
super().__init__(name, aligned_faces=aligned_faces)
268268
self.aligned_faces = True
269269
self.prop = prop
270270
self.column = column
271271
self.text_color = text_color
272272
self.color_dict = color_dict
273+
self.position = position
273274
self.legend = legend
274275
self.width = width
275276
self.height = None
@@ -303,12 +304,16 @@ def set_node_style(self, node):
303304
prop_text = ",".join(prop_text)
304305
else:
305306
pass
306-
if self.text_color:
307+
308+
if self.color_dict and self.color_dict.get(prop_text):
309+
color = self.color_dict.get(prop_text)
310+
prop_face = TextFace(prop_text, color=color, min_fsize=self.min_fsize, max_fsize=self.max_fsize, padding_x=self.padding_x, width=self.width)
311+
elif self.text_color:
307312
prop_face = TextFace(prop_text, color=self.text_color, min_fsize=self.min_fsize, max_fsize=self.max_fsize, padding_x=self.padding_x, width=self.width)
308313
else:
309-
prop_face = TextFace(prop_text, color='black', min_fsize=self.min_fsize, max_fsize=self.max_fsize, padding_x=self.padding_x, width=self.width )
310-
node.add_face(prop_face, position="branch_bottom")
311-
node.add_face(prop_face, position="branch_bottom", collapsed_only=True)
314+
prop_face = TextFace(prop_text, color='black', min_fsize=self.min_fsize, max_fsize=self.max_fsize, padding_x=self.padding_x, width=self.width)
315+
node.add_face(prop_face, position=self.position)
316+
node.add_face(prop_face, position=self.position, collapsed_only=True)
312317

313318
class LayoutColorbranch(TreeLayout):
314319
def __init__(self, name, column, color_dict, prop, legend=True, width=70, padding_x=1, padding_y=0):
@@ -599,14 +604,14 @@ def set_node_style(self, node):
599604
node.add_face(prop_face, column=self.column,
600605
position="branch_right", collapsed_only=False)
601606

602-
class LayoutSymbolbranch(TreeLayout):
607+
class LayoutSymbolNode(TreeLayout):
603608
def __init__(self, name=None, prop=None, position="branch_right",
604609
column=0, symbol='circle', symbol_color=None, color_dict=None,
605610
max_radius=1, symbol_size=5, fgopacity=0.8,
606611
padding_x=2, padding_y=0,
607612
scale=True, legend=True, active=True):
608613

609-
name = name or f'{symbol}Branch_{prop}'
614+
name = name or f'{symbol}Node_{prop}'
610615
super().__init__(name)
611616

612617
self.aligned_faces = True

0 commit comments

Comments
 (0)