Changeset 700 for mds-and-trees
- Timestamp:
- 09/19/17 15:45:07 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
mds-and-trees/tree-genealogy.py
r697 r700 31 31 'color': { 32 32 'meaning': 'Lifespan', 33 'normalize_cmap': False, 34 'cmap': {}, 33 35 'start': 'red', 34 36 'end': 'green', … … 51 53 'color': { 52 54 'meaning': 'adepth', 55 'normalize_cmap': False, 56 'cmap': {}, 53 57 'start': 'black', 54 58 'end': 'red', … … 77 81 else: 78 82 destination[key] = value 79 80 83 return destination 81 84 … … 85 88 self.settings = merge(c, self.settings) 86 89 #print(json.dumps(self.settings, indent=4, sort_keys=True)) 90 91 self.compile_cmaps() 92 93 def compile_cmaps(self): 94 95 # normalization of color breaking points 96 for part in ['dots', 'lines']: 97 if self.settings[part]['color']['cmap'] \ 98 and self.settings[part]['color']['normalize_cmap']: 99 cmap = self.settings[part]['color']['cmap'] 100 min = self.design.props[self.settings[part]['color']['meaning'] + "_min"] 101 max = self.design.props[self.settings[part]['color']['meaning'] + "_max"] 102 for key in cmap: 103 for arr in cmap[key]: 104 arr[0] = (arr[0] - min) / (max-min) 105 if cmap[key][0][0] != 0: 106 cmap[key].insert(0, cmap[key][0][:]) 107 cmap[key][0][0] = 0 108 if cmap[key][-1][0] != 1: 109 cmap[key].append(cmap[key][-1][:]) 110 cmap[key][-1][0] = 1 111 112 113 for part in ['dots', 'lines']: 114 if self.settings[part]['color']['cmap']: 115 cmap = self.settings[part]['color']['cmap'] 116 for key in cmap: 117 new_arr = [] 118 for arr in cmap[key]: 119 new_arr.append(tuple(arr)) 120 cmap[key] = tuple(new_arr) 121 #print(cmap) 122 self.settings[part]['color']['cmap'] = colors.LinearSegmentedColormap('Custom', cmap) 87 123 88 124 def draw_dots(self, file, min_width, max_width, max_height): … … 137 173 bias = self.settings[part][prop]['bias'] 138 174 if prop == "color": 139 return self.compute_color(start, end, value, bias) 175 if not self.settings[part][prop]['cmap']: 176 return self.compute_color(start, end, value, bias) 177 else: 178 return self.compute_color_from_cmap(self.settings[part][prop]['cmap'], value, bias) 140 179 else: 141 180 return self.compute_value(start, end, value, bias) 181 182 def compute_color_from_cmap(self, cmap, value, bias=1): 183 value = 1 - (1-value)**bias 184 rgba = cmap(value) 185 return (100*rgba[0], 100*rgba[1], 100*rgba[2]) 186 142 187 143 188 def compute_color(self, start, end, value, bias=1): … … 220 265 offset = (min(fx-w, tx-w), min(fy-w, ty-w)) 221 266 size = (abs(fx-tx)+2*w, abs(fy-ty)+2*w) 267 if size[0] == 0 or size[1] == 0: 268 return 222 269 223 270 c = style['color']
Note: See TracChangeset
for help on using the changeset viewer.