src/reportlab/graphics/charts/legends.py
branchpy33
changeset 3793 cc3f9cc828f7
parent 3721 0c93dd8ff567
child 4187 8b8e63cfdb15
equal deleted inserted replaced
3792:7a74dc41cc2c 3793:cc3f9cc828f7
    15 from reportlab.pdfbase.pdfmetrics import stringWidth, getFont
    15 from reportlab.pdfbase.pdfmetrics import stringWidth, getFont
    16 from reportlab.graphics.widgetbase import Widget, TypedPropertyCollection, PropHolder
    16 from reportlab.graphics.widgetbase import Widget, TypedPropertyCollection, PropHolder
    17 from reportlab.graphics.shapes import Drawing, Group, String, Rect, Line, STATE_DEFAULTS
    17 from reportlab.graphics.shapes import Drawing, Group, String, Rect, Line, STATE_DEFAULTS
    18 from reportlab.graphics.charts.areas import PlotArea
    18 from reportlab.graphics.charts.areas import PlotArea
    19 from reportlab.graphics.widgets.markers import uSymbol2Symbol, isSymbol
    19 from reportlab.graphics.widgets.markers import uSymbol2Symbol, isSymbol
    20 from reportlab.lib.utils import isSeqType, find_locals
    20 from reportlab.lib.utils import isSeq, find_locals
    21 from reportlab.graphics.shapes import _baseGFontName
    21 from reportlab.graphics.shapes import _baseGFontName
    22 from functools import reduce
    22 from functools import reduce
    23 
    23 
    24 def _transMax(n,A):
    24 def _transMax(n,A):
    25     X = n*[0]
    25     X = n*[0]
    38         return s
    38         return s
    39     else:
    39     else:
    40         return str(s)
    40         return str(s)
    41 
    41 
    42 def _getStr(s):
    42 def _getStr(s):
    43     if isSeqType(s):
    43     if isSeq(s):
    44         return list(map(_getStr,s))
    44         return list(map(_getStr,s))
    45     else:
    45     else:
    46         return _objStr(s)
    46         return _objStr(s)
    47 
    47 
    48 def _getLines(s):
    48 def _getLines(s):
    49     if isSeqType(s):
    49     if isSeq(s):
    50         return tuple([(x or '').split('\n') for x in s])
    50         return tuple([(x or '').split('\n') for x in s])
    51     else:
    51     else:
    52         return (s or '').split('\n')
    52         return (s or '').split('\n')
    53 
    53 
    54 def _getLineCount(s):
    54 def _getLineCount(s):
    55     T = _getLines(s)
    55     T = _getLines(s)
    56     if isSeqType(s):
    56     if isSeq(s):
    57         return max([len(x) for x in T])
    57         return max([len(x) for x in T])
    58     else:
    58     else:
    59         return len(T)
    59         return len(T)
    60 
    60 
    61 def _getWidths(i,s, fontName, fontSize, subCols):
    61 def _getWidths(i,s, fontName, fontSize, subCols):
    62     S = []
    62     S = []
    63     aS = S.append
    63     aS = S.append
    64     if isSeqType(s):
    64     if isSeq(s):
    65         for j,t in enumerate(s):
    65         for j,t in enumerate(s):
    66             sc = subCols[j,i]
    66             sc = subCols[j,i]
    67             fN = getattr(sc,'fontName',fontName)
    67             fN = getattr(sc,'fontName',fontName)
    68             fS = getattr(sc,'fontSize',fontSize)
    68             fS = getattr(sc,'fontSize',fontSize)
    69             m = [stringWidth(x, fN, fS) for x in t.split('\n')]
    69             m = [stringWidth(x, fN, fS) for x in t.split('\n')]
   400             elif alignment == "right":
   400             elif alignment == "right":
   401                 x = thisx+dx+dxTextSpace
   401                 x = thisx+dx+dxTextSpace
   402                 xn = thisx
   402                 xn = thisx
   403             else:
   403             else:
   404                 raise ValueError("bad alignment")
   404                 raise ValueError("bad alignment")
   405             if not isSeqType(name):
   405             if not isSeq(name):
   406                 T = [T]
   406                 T = [T]
   407             yd = y
   407             yd = y
   408             for k,lines in enumerate(T):
   408             for k,lines in enumerate(T):
   409                 y = y0
   409                 y = y0
   410                 kk = k*2
   410                 kk = k*2