1# -*- coding: utf-8 -*-2# Copyright 2011 Takeshi KOMIYA3#4# Licensed under the Apache License, Version 2.0 (the "License");5# you may not use this file except in compliance with the License.6# You may obtain a copy of the License at7#8# http://www.apache.org/licenses/LICENSE-2.09#10# Unless required by applicable law or agreed to in writing, software11# distributed under the License is distributed on an "AS IS" BASIS,12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.13# See the License for the specific language governing permissions and14# limitations under the License.1516from __future__ import division1718from blockdiag.noderenderer import install_renderer19from blockdiag.noderenderer.base import NodeShape20from blockdiag.utils import XY, Box212223class Square(NodeShape):24 def __init__(self, node, metrics=None):25 super(Square, self).__init__(node, metrics)2627 r = min(metrics.node_width, metrics.node_height) // 2 + \28 metrics.cellsize // 229 pt = metrics.cell(node).center30 self.connectors = [XY(pt.x, pt.y - r), # top31 XY(pt.x + r, pt.y), # right32 XY(pt.x, pt.y + r), # bottom33 XY(pt.x - r, pt.y)] # left34 self.textbox = Box(pt.x - r, pt.y - r, pt.x + r, pt.y + r)3536 def render_shape(self, drawer, _, **kwargs):37 fill = kwargs.get('fill')3839 # draw outline40 if kwargs.get('shadow'):41 box = self.shift_shadow(self.textbox)42 if kwargs.get('style') == 'blur':43 drawer.rectangle(box, fill=fill, outline=fill,44 filter='transp-blur')45 else:46 drawer.rectangle(box, fill=fill, outline=fill)47 elif self.node.background:48 drawer.rectangle(self.textbox, fill=self.node.color,49 outline=self.node.color)50 drawer.image(self.textbox, self.node.background)51 drawer.rectangle(self.textbox, fill="none",52 outline=self.node.linecolor,53 style=self.node.style)54 else:55 drawer.rectangle(self.textbox, fill=self.node.color,56 outline=self.node.linecolor,57 style=self.node.style)585960def setup(self):61 install_renderer('square', Square)