clone

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

main
diagramzip / renderers / python / blockdiag-family / src / actdiag / drawer.py
drawer.py 1.9K
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.1516import blockdiag.drawer1718from actdiag.metrics import DiagramMetrics192021class DiagramDraw(blockdiag.drawer.DiagramDraw):22 def create_metrics(self, *args, **kwargs):23 return DiagramMetrics(*args, **kwargs)2425 def _draw_elements(self, **kwargs):26 m = self.metrics2728 # render label of lanes29 for i, lane in enumerate(self.diagram.lanes):30 if lane.label:31 label = lane.label32 elif isinstance(lane.id, str):33 label = lane.id34 else:35 label = 'Lane %d' % (i + 1)3637 if lane.href and self.format == 'SVG':38 drawer = self.drawer.anchor(lane.href)39 else:40 drawer = self.drawer4142 headerbox = m.lane_headerbox(lane)43 drawer.rectangle(headerbox, fill=lane.color, outline=lane.color)4445 textbox = m.lane_textbox(lane)46 drawer.textarea(textbox, label, fill=self.fill,47 font=self.metrics.font_for(lane))4849 # render frame of activity lanes50 frame = m.frame(self.diagram.lanes)51 self.drawer.rectangle(frame.outline, outline='gray')52 for xy in frame.separators:53 self.drawer.line(xy, fill='gray')5455 super(DiagramDraw, self)._draw_elements(**kwargs)