def drawTreeMap(self, myCanvas,pos,sliver=0, secondary_weight=None, colorSeed=None): color = self.randomColor(seed=colorSeed, secondary_weight = secondary_weight) if self.hasChildren(): #draw sub-tree values = [treemap.value for treemap in self.children] secondaries = [treemap.secondary for treemap in self.children] secondary_weights = [compare(self.secondary, secondary) for secondary in secondaries] def normalize(array): array = np.array(array) return (array-np.min(array))/np.max(array) secondary_weights = normalize(secondary_weights) rectangles = layout(values, pos) for index,child in enumerate(self.children): child.drawTreeMap(myCanvas, rectangles[index], secondary_weight = secondary_weights[index],colorSeed=color) #draw outlines for index,rectangle in enumerate(rectangles): borderColor = "#%02X%02X%02X" % tuple([int( (self.level) * 255 *2/10)]*3) self.drawOutline(myCanvas, rectangles[index]) else: sliver= max(0,2-self.level); Treemap.canvas_drawRectangle(myCanvas, pos, color=color)
def recursive_build(faultList, square, mLevel, parent = None): mLevel = len(faultList[0].elements) # x0,y0,xn,yn = square self.addOutline(x0,y0,xn,yn, mLevel) square = [x0+1,y0+1,xn-1,yn-1] if len(faultList) == 0: return None #lay out faults rectangles, leftovers = layout(([parent.value] if parent is not None else [])+[fault.subValue for fault in faultList], square) # rectangles, leftovers = layout(([parent.value] if parent is not None else [])+[fault.value for fault in faultList], square) if parent is not None: parentRect = rectangles.pop(0) #rectangle representing elements that were too small if len(faultList) < len(rectangles): xa,ya,xb,yb = rectangles.pop() leftoverRect = Rectangle([xa,ya,xb-xa,yb-ya], parent=self, color=QColor(150,150,150)); leftoverRect.setColor(mLevel) self.addOutline(xa,ya,xb,yb,mLevel+1) #rectangle representing the parent fault if parent is not None and parentRect: fault = parent xa,ya,xb,yb = parentRect fault.addRectangle(self, [xa,ya,xb-xa,yb-ya], level = mLevel - startLimit) self.addOutline(xa,ya,xb,yb, mLevel+1) if mLevel >= depthLimit: #lay out faults and add a rectangle widget to each fault # for fault,rectangle in zip(faultList,rectangles): if not rectangle: continue xa,ya,xb,yb = rectangle fault.addRectangle(self,[xa,ya, xb-xa, yb-ya], level=mLevel-startLimit+1) self.addOutline(xa,ya,xb,yb,mLevel+1) # mWindow.addWidget(fault) else: """ There should be some limit here as to how small a rectangle gets recursively built. """ for fault, rectangle in zip(faultList, rectangles): if not rectangle: continue xa,ya,xb,yb = rectangle if (xb-xa)*(yb-ya) > 50*50 and fault.connections: randomColor(mLevel-startLimit+1)#prime random colour generator recursive_build(fault.connections, rectangle, mLevel+1, parent = fault) else: # print( "{},...".format(rectangle)) self.addOutline(xa,ya,xb,yb,mLevel + 1) # fault.addRectangle(self, [xa, ya, xb-xa, yb-ya]) self.addOutline(xa+1,ya+1, xb-1, yb-1, mLevel+2) fault.addRectangle(self, [xa+1,ya+1,xb-xa-2,yb-ya-2])