reportlab/graphics/charts/barcharts.py
changeset 2660 c147aff8edae
parent 2511 83406bfe8569
child 2676 2142d5f874d8
equal deleted inserted replaced
2659:08af1b8a5d05 2660:c147aff8edae
    14 from types import FunctionType, StringType
    14 from types import FunctionType, StringType
    15 
    15 
    16 from reportlab.lib import colors
    16 from reportlab.lib import colors
    17 from reportlab.lib.validators import isNumber, isColor, isColorOrNone, isString,\
    17 from reportlab.lib.validators import isNumber, isColor, isColorOrNone, isString,\
    18             isListOfStrings, SequenceOf, isBoolean, isNoneOrShape, isStringOrNone,\
    18             isListOfStrings, SequenceOf, isBoolean, isNoneOrShape, isStringOrNone,\
    19             NoneOr
    19             NoneOr, isListOfNumbersOrNone
    20 from reportlab.graphics.widgets.markers import uSymbol2Symbol, isSymbol
    20 from reportlab.graphics.widgets.markers import uSymbol2Symbol, isSymbol
    21 from reportlab.lib.formatters import Formatter
    21 from reportlab.lib.formatters import Formatter
    22 from reportlab.lib.attrmap import AttrMap, AttrMapValue
    22 from reportlab.lib.attrmap import AttrMap, AttrMapValue
    23 from reportlab.pdfbase.pdfmetrics import stringWidth
    23 from reportlab.pdfbase.pdfmetrics import stringWidth
    24 from reportlab.graphics.widgetbase import Widget, TypedPropertyCollection, PropHolder
    24 from reportlab.graphics.widgetbase import Widget, TypedPropertyCollection, PropHolder
    30 class BarChartProperties(PropHolder):
    30 class BarChartProperties(PropHolder):
    31     _attrMap = AttrMap(
    31     _attrMap = AttrMap(
    32         strokeColor = AttrMapValue(isColorOrNone, desc='Color of the bar border.'),
    32         strokeColor = AttrMapValue(isColorOrNone, desc='Color of the bar border.'),
    33         fillColor = AttrMapValue(isColorOrNone, desc='Color of the bar interior area.'),
    33         fillColor = AttrMapValue(isColorOrNone, desc='Color of the bar interior area.'),
    34         strokeWidth = AttrMapValue(isNumber, desc='Width of the bar border.'),
    34         strokeWidth = AttrMapValue(isNumber, desc='Width of the bar border.'),
       
    35         strokeDashArray = AttrMapValue(isListOfNumbersOrNone, desc='Dash array of a line.'),
    35         symbol = AttrMapValue(None, desc='A widget to be used instead of a normal bar.'),
    36         symbol = AttrMapValue(None, desc='A widget to be used instead of a normal bar.'),
    36         name = AttrMapValue(isString, desc='Text to be associated with a bar (eg seriesname)'),
    37         name = AttrMapValue(isString, desc='Text to be associated with a bar (eg seriesname)'),
    37         swatchMarker = AttrMapValue(NoneOr(isSymbol), desc="None or makeMarker('Diamond') ..."),
    38         swatchMarker = AttrMapValue(NoneOr(isSymbol), desc="None or makeMarker('Diamond') ..."),
    38         )
    39         )
    39 
    40 
   131 
   132 
   132         # we really need some well-designed default lists of
   133         # we really need some well-designed default lists of
   133         # colors e.g. from Tufte.  These will be used in a
   134         # colors e.g. from Tufte.  These will be used in a
   134         # cycle to set the fill color of each series.
   135         # cycle to set the fill color of each series.
   135         self.bars = TypedPropertyCollection(BarChartProperties)
   136         self.bars = TypedPropertyCollection(BarChartProperties)
   136 ##        self.bars.symbol = None
       
   137         self.bars.strokeWidth = 1
   137         self.bars.strokeWidth = 1
   138         self.bars.strokeColor = colors.black
   138         self.bars.strokeColor = colors.black
       
   139         self.bars.strokeDashArray = None
   139 
   140 
   140         self.bars[0].fillColor = colors.red
   141         self.bars[0].fillColor = colors.red
   141         self.bars[1].fillColor = colors.green
   142         self.bars[1].fillColor = colors.green
   142         self.bars[2].fillColor = colors.blue
   143         self.bars[2].fillColor = colors.blue
   143         self.naLabel = None#NA_Label()
   144         self.naLabel = None #NA_Label()
   144 
   145 
   145 
   146 
   146     def demo(self):
   147     def demo(self):
   147         """Shows basic use of a bar chart"""
   148         """Shows basic use of a bar chart"""
   148         if self.__class__.__name__=='BarChart':
   149         if self.__class__.__name__=='BarChart':
   417     def _makeBar(self,g,x,y,width,height,rowNo,style):
   418     def _makeBar(self,g,x,y,width,height,rowNo,style):
   418         r = Rect(x, y, width, height)
   419         r = Rect(x, y, width, height)
   419         r.strokeWidth = style.strokeWidth
   420         r.strokeWidth = style.strokeWidth
   420         r.fillColor = style.fillColor
   421         r.fillColor = style.fillColor
   421         r.strokeColor = style.strokeColor
   422         r.strokeColor = style.strokeColor
       
   423         if style.strokeDashArray:
       
   424             r.strokeDashArray = style.strokeDashArray
   422         g.add(r)
   425         g.add(r)
   423 
   426 
   424     def _makeBars(self,g,lg):
   427     def _makeBars(self,g,lg):
   425         lenData = len(self.data)
   428         lenData = len(self.data)
   426         bars = self.bars
   429         bars = self.bars