clone

a browser-first diagram editor with live svg previews, local drafts and encrypted, accountless sharing

main
diagramzip / renderers / python / blockdiag-family / src / blockdiag / noderenderer / flowchart / loopin.py
loopin.py 2.5K
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 LoopIn(NodeShape):24 def __init__(self, node, metrics=None):25 super(LoopIn, self).__init__(node, metrics)2627 m = self.metrics.cell(self.node)28 ydiff = self.metrics.node_height // 42930 self.textbox = Box(m.topleft.x, m.topleft.y + ydiff,31 m.bottomright.x, m.bottomright.y)3233 def render_shape(self, drawer, _, **kwargs):34 fill = kwargs.get('fill')3536 m = self.metrics.cell(self.node)37 xdiff = self.metrics.node_width // 438 ydiff = self.metrics.node_height // 43940 shape = [XY(m.topleft.x + xdiff, m.topleft.y),41 XY(m.topright.x - xdiff, m.topleft.y),42 XY(m.topright.x, m.topright.y + ydiff),43 XY(m.topright.x, m.bottomright.y),44 XY(m.topleft.x, m.bottomleft.y),45 XY(m.topleft.x, m.topleft.y + ydiff),46 XY(m.topleft.x + xdiff, m.topleft.y)]4748 # draw outline49 if kwargs.get('shadow'):50 shape = self.shift_shadow(shape)51 if kwargs.get('style') == 'blur':52 drawer.polygon(shape, fill=fill, outline=fill,53 filter='transp-blur')54 else:55 drawer.polygon(shape, fill=fill, outline=fill)56 elif self.node.background:57 drawer.polygon(shape, fill=self.node.color,58 outline=self.node.color)59 drawer.image(self.textbox, self.node.background)60 drawer.polygon(shape, fill="none",61 outline=self.node.linecolor, style=self.node.style)62 else:63 drawer.polygon(shape, fill=self.node.color,64 outline=self.node.linecolor, style=self.node.style)656667def setup(self):68 install_renderer('flowchart.loopin', LoopIn)