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 / database.py
database.py 5.1K
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.imagedraw.simplesvg import pathdata19from blockdiag.noderenderer import install_renderer20from blockdiag.noderenderer.base import NodeShape21from blockdiag.utils import XY, Box222324class Database(NodeShape):25 def __init__(self, node, metrics=None):26 super(Database, self).__init__(node, metrics)2728 m = self.metrics.cell(self.node)29 r = self.metrics.cellsize30 self.textbox = Box(m.topleft.x, m.topleft.y + r * 3 // 2,31 m.bottomright.x, m.bottomright.y - r // 2)3233 def render_shape(self, drawer, _, **kwargs):34 # draw background35 self.render_shape_background(drawer, **kwargs)3637 # draw background image38 if self.node.background:39 drawer.image(self.textbox, self.node.background)4041 def render_shape_background(self, drawer, **kwargs):42 fill = kwargs.get('fill')4344 m = self.metrics.cell(self.node)45 r = self.metrics.cellsize46 box = m.box4748 ellipse = Box(box[0], box[3] - r * 2, box[2], box[3])49 if kwargs.get('shadow'):50 ellipse = self.shift_shadow(ellipse)51 if kwargs.get('style') == 'blur':52 drawer.ellipse(ellipse, fill=fill, outline=fill,53 filter='transp-blur')54 else:55 drawer.ellipse(ellipse, fill=fill, outline=fill)56 else:57 drawer.ellipse(ellipse, fill=self.node.color,58 outline=self.node.linecolor, style=self.node.style)5960 rect = Box(box[0], box[1] + r, box[2], box[3] - r)61 if kwargs.get('shadow'):62 rect = self.shift_shadow(rect)63 if kwargs.get('style') == 'blur':64 drawer.rectangle(rect, fill=fill, outline=fill,65 filter='transp-blur')66 else:67 drawer.rectangle(rect, fill=fill, outline=fill)68 else:69 drawer.rectangle(rect, fill=self.node.color,70 outline=self.node.color)7172 ellipse = Box(box[0], box[1], box[2], box[1] + r * 2)73 if kwargs.get('shadow'):74 ellipse = self.shift_shadow(ellipse)75 if kwargs.get('style') == 'blur':76 drawer.ellipse(ellipse, fill=fill, outline=fill,77 filter='transp-blur')78 else:79 drawer.ellipse(ellipse, fill=fill, outline=fill)80 else:81 drawer.ellipse(ellipse, fill=self.node.color,82 outline=self.node.linecolor, style=self.node.style)8384 # line both side85 lines = [(XY(box[0], box[1] + r), XY(box[0], box[3] - r)),86 (XY(box[2], box[1] + r), XY(box[2], box[3] - r))]87 for line in lines:88 if not kwargs.get('shadow'):89 drawer.line(line, fill=self.node.linecolor,90 style=self.node.style)9192 def render_vector_shape(self, drawer, _, **kwargs):93 fill = kwargs.get('fill')9495 m = self.metrics.cell(self.node)96 r = self.metrics.cellsize97 width = self.metrics.node_width9899 box = m.box100 if kwargs.get('shadow'):101 box = self.shift_shadow(box)102103 path = pathdata(box[0], box[1] + r)104 path.ellarc(width // 2, r, 0, 0, 1, box[2], box[1] + r)105 path.line(box[2], box[3] - r)106 path.ellarc(width // 2, r, 0, 0, 1, box[0], box[3] - r)107 path.line(box[0], box[1] + r)108109 # draw outline110 if kwargs.get('shadow'):111 if kwargs.get('style') == 'blur':112 drawer.path(path, fill=fill, outline=fill,113 filter='transp-blur')114 else:115 drawer.path(path, fill=fill, outline=fill)116 elif self.node.background:117 drawer.path(path, fill=self.node.color,118 outline=self.node.color)119 drawer.image(self.textbox, self.node.background)120 drawer.path(path, fill="none",121 outline=self.node.linecolor, style=self.node.style)122 else:123 drawer.path(path, fill=self.node.color,124 outline=self.node.linecolor, style=self.node.style)125126 # draw cap of cylinder127 if not kwargs.get('shadow'):128 path = pathdata(box[2], box[1] + r)129 path.ellarc(width // 2, r, 0, 0, 1, box[0], box[1] + r)130 drawer.path(path, fill=self.node.color,131 outline=self.node.linecolor, style=self.node.style)132133134def setup(self):135 install_renderer('flowchart.database', Database)