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 Circle(NodeShape):24 def __init__(self, node, metrics=None):25 super(Circle, self).__init__(node, metrics)2627 cell = metrics.cell(node)28 r = min(cell.box.width, cell.box.height) // 2 + \29 metrics.cellsize // 230 pt = metrics.cell(node).center31 self.connectors = [XY(pt.x, pt.y - r), # top32 XY(pt.x + r, pt.y), # right33 XY(pt.x, pt.y + r), # bottom34 XY(pt.x - r, pt.y)] # left35 self.textbox = Box(pt.x - r, pt.y - r, pt.x + r, pt.y + r)3637 def render_shape(self, drawer, _, **kwargs):38 fill = kwargs.get('fill')3940 # draw outline41 if kwargs.get('shadow'):42 box = self.shift_shadow(self.textbox)43 if kwargs.get('style') == 'blur':44 drawer.ellipse(box, fill=fill, outline=fill,45 filter='transp-blur')46 else:47 drawer.ellipse(box, fill=fill, outline=fill)48 elif self.node.background:49 drawer.ellipse(self.textbox, fill=self.node.color,50 outline=self.node.color)51 drawer.image(self.textbox, self.node.background)52 drawer.ellipse(self.textbox, fill="none",53 outline=self.node.linecolor, style=self.node.style)54 else:55 drawer.ellipse(self.textbox, fill=self.node.color,56 outline=self.node.linecolor, style=self.node.style)575859def setup(self):60 install_renderer('circle', Circle)