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 Box192021class Ellipse(NodeShape):22 def __init__(self, node, metrics=None):23 super(Ellipse, self).__init__(node, metrics)2425 r = metrics.cellsize26 box = metrics.cell(node).box27 self.textbox = Box(box[0] + r, box[1] + r, box[2] - r, box[3] - r)2829 def render_shape(self, drawer, _, **kwargs):30 fill = kwargs.get('fill')3132 # draw outline33 box = self.metrics.cell(self.node).box34 if kwargs.get('shadow'):35 box = self.shift_shadow(box)36 if kwargs.get('style') == 'blur':37 drawer.ellipse(box, fill=fill, outline=fill,38 filter='transp-blur')39 else:40 drawer.ellipse(box, fill=fill, outline=fill)41 elif self.node.background:42 drawer.ellipse(box, fill=self.node.color,43 outline=self.node.color)44 drawer.image(self.textbox, self.node.background)45 drawer.ellipse(box, fill="none",46 outline=self.node.linecolor, style=self.node.style)47 else:48 drawer.ellipse(box, fill=self.node.color,49 outline=self.node.linecolor, style=self.node.style)505152def setup(self):53 install_renderer('ellipse', Ellipse)