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 blockdiag.noderenderer import install_renderer17from blockdiag.noderenderer.base import NodeShape18from blockdiag.utils import XY, Box192021class MiniDiamond(NodeShape):22 def __init__(self, node, metrics=None):23 super(MiniDiamond, self).__init__(node, metrics)2425 r = metrics.cellsize26 m = metrics.cell(node)27 c = m.center28 self.connectors = (XY(c.x, c.y - r),29 XY(c.x + r, c.y),30 XY(c.x, c.y + r),31 XY(c.x - r, c.y),32 XY(c.x, c.y - r))33 self.textbox = Box(m.top.x, m.top.y, m.right.x, m.right.y)34 self.textalign = 'left'3536 def render_shape(self, drawer, _, **kwargs):37 fill = kwargs.get('fill')3839 # draw outline40 if kwargs.get('shadow'):41 diamond = self.shift_shadow(self.connectors)42 if kwargs.get('style') == 'blur':43 drawer.polygon(diamond, fill=fill, outline=fill,44 filter='transp-blur')45 else:46 drawer.polygon(diamond, fill=fill, outline=fill)47 else:48 drawer.polygon(self.connectors, fill=self.node.color,49 outline=self.node.linecolor, style=self.node.style)505152def setup(self):53 install_renderer('minidiamond', MiniDiamond)