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 / diamond.py
diamond.py 2.6K
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 Diamond(NodeShape):24 def __init__(self, node, metrics=None):25 super(Diamond, self).__init__(node, metrics)2627 r = metrics.cellsize28 m = metrics.cell(node)29 self.connectors = [XY(m.top.x, m.top.y - r),30 XY(m.right.x + r, m.right.y),31 XY(m.bottom.x, m.bottom.y + r),32 XY(m.left.x - r, m.left.y),33 XY(m.top.x, m.top.y - r)]34 self.textbox = Box((self.connectors[0].x + self.connectors[3].x) // 2,35 (self.connectors[0].y + self.connectors[3].y) // 2,36 (self.connectors[1].x + self.connectors[2].x) // 2,37 (self.connectors[1].y + self.connectors[2].y) // 2)3839 def render_shape(self, drawer, _, **kwargs):40 fill = kwargs.get('fill')4142 # draw outline43 if kwargs.get('shadow'):44 diamond = self.shift_shadow(self.connectors)45 if kwargs.get('style') == 'blur':46 drawer.polygon(diamond, fill=fill, outline=fill,47 filter='transp-blur')48 else:49 drawer.polygon(diamond, fill=fill, outline=fill)50 elif self.node.background:51 drawer.polygon(self.connectors, fill=self.node.color,52 outline=self.node.color)53 drawer.image(self.textbox, self.node.background)54 drawer.polygon(self.connectors, fill="none",55 outline=self.node.linecolor, style=self.node.style)56 else:57 drawer.polygon(self.connectors, fill=self.node.color,58 outline=self.node.linecolor, style=self.node.style)596061def setup(self):62 install_renderer('diamond', Diamond)63 install_renderer('flowchart.condition', Diamond)