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 packetdiag.metrics import DiagramMetrics192021class DiagramDraw(blockdiag.drawer.DiagramDraw):22 def create_metrics(self, *args, **kwargs):23 return DiagramMetrics(*args, **kwargs)2425 def _draw_background(self):26 # do not call blockdiag.DiagramDraw#_draw_background()2728 scale_interval = self.diagram.scale_interval29 if scale_interval is None:30 scale_interval = self.diagram.colwidth / 23132 # draw measure lines and labels33 font = self.metrics.font_for(None)34 for i in range(self.diagram.colwidth + 1):35 line = self.metrics.measure_line(i)36 self.drawer.line(line, fill=self.diagram.linecolor)3738 if (i % scale_interval) == 0:39 box = self.metrics.measure_label(i)4041 if self.diagram.scale_direction == "left_to_right":42 label = str(i)43 else:44 label = str(self.diagram.colwidth - i)4546 self.drawer.textarea(box, label, font,47 fill=self.diagram.textcolor)