def build(self,values): """ build a treemap from a list of numbers This funciton is for building a fault-tree without a tree-structure. It takes 'values' as a list of numbers and builds a single-level treemap out of that. """ pos = self.sceneRect().getRect() x0,y0,w,h = pos self.addOutline( x0,y0,x0+w,y0+h, 1) rectangles, _ = layout(values, [x0+1,y0+1,x0+w-1,y0+h-1]) for el in rectangles: if el: xa,ya,xb,yb = el Rectangle(self,[xa,ya,xb-xa,yb-ya])
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(self,[xa,ya,xb-xa,yb-ya], fill=Qt.Dense3Pattern); leftoverRect.color = randomColor(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(Rectangle(self,[xa,ya,xb-xa,yb-ya])) 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(Rectangle(self, [xa,ya,xb-xa,yb-ya])) 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) > 10*10 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) self.addOutline(xa+1,ya+1, xb-1, yb-1, mLevel+2) fault.addRectangle(Rectangle(self,[xa+1,ya+1,xb-xa-2,yb-ya-2]))