src/reportlab/graphics/charts/linecharts.py
author robin <robin@reportlab.com>
Tue, 07 Mar 2017 10:00:34 +0000
changeset 4330 617ffa6bbdc8
parent 4252 fe660f227cac
child 4370 823a8c33ce43
permissions -rw-r--r--
changes for release 3.4.0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4330
617ffa6bbdc8 changes for release 3.4.0
robin <robin@reportlab.com>
parents: 4252
diff changeset
     1
#Copyright ReportLab Europe Ltd. 2000-2017
817
8c3a399effda License text changes
rgbecker
parents: 773
diff changeset
     2
#see license.txt for license details
2332
2a7ab4405e18 Remove $Header:, fix CopyRight & history
rgbecker
parents: 2152
diff changeset
     3
#history http://www.reportlab.co.uk/cgi-bin/viewcvs.cgi/public/reportlab/trunk/reportlab/graphics/charts/linecharts.py
3032
22224b1b4d24 New docstrings mainly for module titles
damian
parents: 2964
diff changeset
     4
4252
fe660f227cac changes for release 3.3.0
robin
parents: 3975
diff changeset
     5
__version__='3.3.0'
3032
22224b1b4d24 New docstrings mainly for module titles
damian
parents: 2964
diff changeset
     6
__doc__="""This modules defines a very preliminary Line Chart example."""
22224b1b4d24 New docstrings mainly for module titles
damian
parents: 2964
diff changeset
     7
1272
3172686c9ee5 Made linecharts use the new markers/flags some of which were improved
rgbecker
parents: 1236
diff changeset
     8
from reportlab.lib import colors
3625
c459ddaafe88 linecharts.py: added in lineStyle (for bars)
rgbecker
parents: 3617
diff changeset
     9
from reportlab.lib.validators import isNumber, isNumberOrNone, isColor, isColorOrNone, isListOfStrings, \
2145
7146753877a5 Missing import
rgbecker
parents: 2144
diff changeset
    10
                                    isListOfStringsOrNone, SequenceOf, isBoolean, NoneOr, \
3625
c459ddaafe88 linecharts.py: added in lineStyle (for bars)
rgbecker
parents: 3617
diff changeset
    11
                                    isListOfNumbersOrNone, isStringOrNone, OneOf, Percentage
948
2531b35adf85 New AttrMap emplacement
rgbecker
parents: 947
diff changeset
    12
from reportlab.lib.attrmap import *
917
a4aea7356094 Switched to using typed collection styles.
dinu_gherman
parents: 909
diff changeset
    13
from reportlab.graphics.widgetbase import Widget, TypedPropertyCollection, PropHolder
1995
aef8565e39a1 Added inFill stuff/reversePlotOrder for LineChart
rgbecker
parents: 1974
diff changeset
    14
from reportlab.graphics.shapes import Line, Rect, Group, Drawing, Polygon, PolyLine
1236
1ee0c38e3d19 Changes related to symbols coming of age
rgbecker
parents: 1080
diff changeset
    15
from reportlab.graphics.widgets.signsandsymbols import NoEntry
909
a5ee7d2bdb17 Extracted validator functions into lib.validators.
dinu_gherman
parents: 907
diff changeset
    16
from reportlab.graphics.charts.axes import XCategoryAxis, YValueAxis
737
8f0e58918da9 Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff changeset
    17
from reportlab.graphics.charts.textlabels import Label
1272
3172686c9ee5 Made linecharts use the new markers/flags some of which were improved
rgbecker
parents: 1236
diff changeset
    18
from reportlab.graphics.widgets.markers import uSymbol2Symbol, isSymbol, makeMarker
1692
dc56f53c8322 Added areas.PlotArea for chart plot areas
rgbecker
parents: 1683
diff changeset
    19
from reportlab.graphics.charts.areas import PlotArea
2856
2225ac76e622 charts: fix unicode labels using _objStr (bug from Sebastian Ware sebastian@urbantalk.se)
rgbecker
parents: 2830
diff changeset
    20
from reportlab.graphics.charts.legends import _objStr
737
8f0e58918da9 Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff changeset
    21
917
a4aea7356094 Switched to using typed collection styles.
dinu_gherman
parents: 909
diff changeset
    22
class LineChartProperties(PropHolder):
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
    23
    _attrMap = AttrMap(
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
    24
        strokeWidth = AttrMapValue(isNumber, desc='Width of a line.'),
3625
c459ddaafe88 linecharts.py: added in lineStyle (for bars)
rgbecker
parents: 3617
diff changeset
    25
        strokeColor = AttrMapValue(isColorOrNone, desc='Color of a line or border.'),
c459ddaafe88 linecharts.py: added in lineStyle (for bars)
rgbecker
parents: 3617
diff changeset
    26
        fillColor = AttrMapValue(isColorOrNone, desc='fill color of a bar.'),
2144
7122e953ee36 Add dasharray to allowed attributes for linechart lines
rgbecker
parents: 2091
diff changeset
    27
        strokeDashArray = AttrMapValue(isListOfNumbersOrNone, desc='Dash array of a line.'),
3271
c14b161b62bf attributes help messages
meitham
parents: 3248
diff changeset
    28
        symbol = AttrMapValue(NoneOr(isSymbol), desc='Widget placed at data points.',advancedUsage=1),
c14b161b62bf attributes help messages
meitham
parents: 3248
diff changeset
    29
        shader = AttrMapValue(None, desc='Shader Class.',advancedUsage=1),
c14b161b62bf attributes help messages
meitham
parents: 3248
diff changeset
    30
        filler = AttrMapValue(None, desc='Filler Class.',advancedUsage=1),
2426
fac927fa6f7c Auto Legends
rgbecker
parents: 2332
diff changeset
    31
        name = AttrMapValue(isStringOrNone, desc='Name of the line.'),
3625
c459ddaafe88 linecharts.py: added in lineStyle (for bars)
rgbecker
parents: 3617
diff changeset
    32
        lineStyle = AttrMapValue(NoneOr(OneOf('line','joinedLine','bar')), desc="What kind of plot this line is",advancedUsage=1),
c459ddaafe88 linecharts.py: added in lineStyle (for bars)
rgbecker
parents: 3617
diff changeset
    33
        barWidth = AttrMapValue(isNumberOrNone,desc="Percentage of available width to be used for a bar",advancedUsage=1),
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
    34
        )
917
a4aea7356094 Switched to using typed collection styles.
dinu_gherman
parents: 909
diff changeset
    35
2427
1de04210b407 charts: autolegending in place, legend now has boxAnchor
rgbecker
parents: 2426
diff changeset
    36
class AbstractLineChart(PlotArea):
2426
fac927fa6f7c Auto Legends
rgbecker
parents: 2332
diff changeset
    37
fac927fa6f7c Auto Legends
rgbecker
parents: 2332
diff changeset
    38
    def makeSwatchSample(self,rowNo, x, y, width, height):
fac927fa6f7c Auto Legends
rgbecker
parents: 2332
diff changeset
    39
        baseStyle = self.lines
2427
1de04210b407 charts: autolegending in place, legend now has boxAnchor
rgbecker
parents: 2426
diff changeset
    40
        styleIdx = rowNo % len(baseStyle)
2426
fac927fa6f7c Auto Legends
rgbecker
parents: 2332
diff changeset
    41
        style = baseStyle[styleIdx]
fac927fa6f7c Auto Legends
rgbecker
parents: 2332
diff changeset
    42
        color = style.strokeColor
3625
c459ddaafe88 linecharts.py: added in lineStyle (for bars)
rgbecker
parents: 3617
diff changeset
    43
        yh2 = y+height/2.
c459ddaafe88 linecharts.py: added in lineStyle (for bars)
rgbecker
parents: 3617
diff changeset
    44
        lineStyle = getattr(style,'lineStyle',None)
c459ddaafe88 linecharts.py: added in lineStyle (for bars)
rgbecker
parents: 3617
diff changeset
    45
        if lineStyle=='bar':
2427
1de04210b407 charts: autolegending in place, legend now has boxAnchor
rgbecker
parents: 2426
diff changeset
    46
            dash = getattr(style, 'strokeDashArray', getattr(baseStyle,'strokeDashArray',None))
1de04210b407 charts: autolegending in place, legend now has boxAnchor
rgbecker
parents: 2426
diff changeset
    47
            strokeWidth= getattr(style, 'strokeWidth', getattr(style, 'strokeWidth',None))
3627
22648486fbc0 linecharts.py: fix swatch creation
rgbecker
parents: 3625
diff changeset
    48
            L = Rect(x,y,width,height,strokeWidth=strokeWidth,strokeColor=color,strokeLineCap=0,strokeDashArray=dash,fillColor=getattr(style,'fillColor',color))
3625
c459ddaafe88 linecharts.py: added in lineStyle (for bars)
rgbecker
parents: 3617
diff changeset
    49
        elif self.joinedLines or lineStyle=='joinedLine':
c459ddaafe88 linecharts.py: added in lineStyle (for bars)
rgbecker
parents: 3617
diff changeset
    50
            dash = getattr(style, 'strokeDashArray', getattr(baseStyle,'strokeDashArray',None))
c459ddaafe88 linecharts.py: added in lineStyle (for bars)
rgbecker
parents: 3617
diff changeset
    51
            strokeWidth= getattr(style, 'strokeWidth', getattr(style, 'strokeWidth',None))
c459ddaafe88 linecharts.py: added in lineStyle (for bars)
rgbecker
parents: 3617
diff changeset
    52
            L = Line(x,yh2,x+width,yh2,strokeColor=color,strokeLineCap=0)
2427
1de04210b407 charts: autolegending in place, legend now has boxAnchor
rgbecker
parents: 2426
diff changeset
    53
            if strokeWidth: L.strokeWidth = strokeWidth
1de04210b407 charts: autolegending in place, legend now has boxAnchor
rgbecker
parents: 2426
diff changeset
    54
            if dash: L.strokeDashArray = dash
1de04210b407 charts: autolegending in place, legend now has boxAnchor
rgbecker
parents: 2426
diff changeset
    55
        else:
1de04210b407 charts: autolegending in place, legend now has boxAnchor
rgbecker
parents: 2426
diff changeset
    56
            L = None
1de04210b407 charts: autolegending in place, legend now has boxAnchor
rgbecker
parents: 2426
diff changeset
    57
1de04210b407 charts: autolegending in place, legend now has boxAnchor
rgbecker
parents: 2426
diff changeset
    58
        if hasattr(style, 'symbol'):
1de04210b407 charts: autolegending in place, legend now has boxAnchor
rgbecker
parents: 2426
diff changeset
    59
            S = style.symbol
1de04210b407 charts: autolegending in place, legend now has boxAnchor
rgbecker
parents: 2426
diff changeset
    60
        elif hasattr(baseStyle, 'symbol'):
1de04210b407 charts: autolegending in place, legend now has boxAnchor
rgbecker
parents: 2426
diff changeset
    61
            S = baseStyle.symbol
1de04210b407 charts: autolegending in place, legend now has boxAnchor
rgbecker
parents: 2426
diff changeset
    62
        else:
1de04210b407 charts: autolegending in place, legend now has boxAnchor
rgbecker
parents: 2426
diff changeset
    63
            S = None
1de04210b407 charts: autolegending in place, legend now has boxAnchor
rgbecker
parents: 2426
diff changeset
    64
3625
c459ddaafe88 linecharts.py: added in lineStyle (for bars)
rgbecker
parents: 3617
diff changeset
    65
        if S: S = uSymbol2Symbol(S,x+width/2.,yh2,color)
2427
1de04210b407 charts: autolegending in place, legend now has boxAnchor
rgbecker
parents: 2426
diff changeset
    66
        if S and L:
1de04210b407 charts: autolegending in place, legend now has boxAnchor
rgbecker
parents: 2426
diff changeset
    67
            g = Group()
1de04210b407 charts: autolegending in place, legend now has boxAnchor
rgbecker
parents: 2426
diff changeset
    68
            g.add(L)
1de04210b407 charts: autolegending in place, legend now has boxAnchor
rgbecker
parents: 2426
diff changeset
    69
            g.add(S)
1de04210b407 charts: autolegending in place, legend now has boxAnchor
rgbecker
parents: 2426
diff changeset
    70
            return g
1de04210b407 charts: autolegending in place, legend now has boxAnchor
rgbecker
parents: 2426
diff changeset
    71
        return S or L
1de04210b407 charts: autolegending in place, legend now has boxAnchor
rgbecker
parents: 2426
diff changeset
    72
1de04210b407 charts: autolegending in place, legend now has boxAnchor
rgbecker
parents: 2426
diff changeset
    73
    def getSeriesName(self,i,default=None):
1de04210b407 charts: autolegending in place, legend now has boxAnchor
rgbecker
parents: 2426
diff changeset
    74
        '''return series name i or default'''
2856
2225ac76e622 charts: fix unicode labels using _objStr (bug from Sebastian Ware sebastian@urbantalk.se)
rgbecker
parents: 2830
diff changeset
    75
        return _objStr(getattr(self.lines[i],'name',default))
2427
1de04210b407 charts: autolegending in place, legend now has boxAnchor
rgbecker
parents: 2426
diff changeset
    76
1de04210b407 charts: autolegending in place, legend now has boxAnchor
rgbecker
parents: 2426
diff changeset
    77
class LineChart(AbstractLineChart):
1de04210b407 charts: autolegending in place, legend now has boxAnchor
rgbecker
parents: 2426
diff changeset
    78
    pass
737
8f0e58918da9 Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff changeset
    79
838
74df7db022e1 Aplitted draw method.
dinu_gherman
parents: 817
diff changeset
    80
# This is conceptually similar to the VerticalBarChart.
74df7db022e1 Aplitted draw method.
dinu_gherman
parents: 817
diff changeset
    81
# Still it is better named HorizontalLineChart... :-/
737
8f0e58918da9 Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff changeset
    82
838
74df7db022e1 Aplitted draw method.
dinu_gherman
parents: 817
diff changeset
    83
class HorizontalLineChart(LineChart):
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
    84
    """Line chart with multiple lines.
737
8f0e58918da9 Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff changeset
    85
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
    86
    A line chart is assumed to have one category and one value axis.
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
    87
    Despite its generic name this particular line chart class has
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
    88
    a vertical value axis and a horizontal category one. It may
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
    89
    evolve into individual horizontal and vertical variants (like
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
    90
    with the existing bar charts).
773
7b1fa8676a0b Added to docstrings and tidied-up a bit.
dinu_gherman
parents: 737
diff changeset
    91
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
    92
    Available attributes are:
773
7b1fa8676a0b Added to docstrings and tidied-up a bit.
dinu_gherman
parents: 737
diff changeset
    93
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
    94
        x: x-position of lower-left chart origin
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
    95
        y: y-position of lower-left chart origin
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
    96
        width: chart width
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
    97
        height: chart height
773
7b1fa8676a0b Added to docstrings and tidied-up a bit.
dinu_gherman
parents: 737
diff changeset
    98
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
    99
        useAbsolute: disables auto-scaling of chart elements (?)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   100
        lineLabelNudge: distance of data labels to data points
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   101
        lineLabels: labels associated with data values
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   102
        lineLabelFormat: format string or callback function
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   103
        groupSpacing: space between categories
773
7b1fa8676a0b Added to docstrings and tidied-up a bit.
dinu_gherman
parents: 737
diff changeset
   104
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   105
        joinedLines: enables drawing of lines
773
7b1fa8676a0b Added to docstrings and tidied-up a bit.
dinu_gherman
parents: 737
diff changeset
   106
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   107
        strokeColor: color of chart lines (?)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   108
        fillColor: color for chart background (?)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   109
        lines: style list, used cyclically for data series
773
7b1fa8676a0b Added to docstrings and tidied-up a bit.
dinu_gherman
parents: 737
diff changeset
   110
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   111
        valueAxis: value axis object
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   112
        categoryAxis: category axis object
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   113
        categoryNames: category names
773
7b1fa8676a0b Added to docstrings and tidied-up a bit.
dinu_gherman
parents: 737
diff changeset
   114
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   115
        data: chart data, a list of data series of equal length
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   116
    """
737
8f0e58918da9 Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff changeset
   117
1692
dc56f53c8322 Added areas.PlotArea for chart plot areas
rgbecker
parents: 1683
diff changeset
   118
    _attrMap = AttrMap(BASE=LineChart,
3271
c14b161b62bf attributes help messages
meitham
parents: 3248
diff changeset
   119
        useAbsolute = AttrMapValue(isNumber, desc='Flag to use absolute spacing values.',advancedUsage=1),
c14b161b62bf attributes help messages
meitham
parents: 3248
diff changeset
   120
        lineLabelNudge = AttrMapValue(isNumber, desc='Distance between a data point and its label.',advancedUsage=1),
1692
dc56f53c8322 Added areas.PlotArea for chart plot areas
rgbecker
parents: 1683
diff changeset
   121
        lineLabels = AttrMapValue(None, desc='Handle to the list of data point labels.'),
dc56f53c8322 Added areas.PlotArea for chart plot areas
rgbecker
parents: 1683
diff changeset
   122
        lineLabelFormat = AttrMapValue(None, desc='Formatting string or function used for data point labels.'),
1996
0150666f5022 dded in stuff for area plots, fixes to axis formatting etc
rgbecker
parents: 1995
diff changeset
   123
        lineLabelArray = AttrMapValue(None, desc='explicit array of line label values, must match size of data if present.'),
1692
dc56f53c8322 Added areas.PlotArea for chart plot areas
rgbecker
parents: 1683
diff changeset
   124
        groupSpacing = AttrMapValue(isNumber, desc='? - Likely to disappear.'),
dc56f53c8322 Added areas.PlotArea for chart plot areas
rgbecker
parents: 1683
diff changeset
   125
        joinedLines = AttrMapValue(isNumber, desc='Display data points joined with lines if true.'),
dc56f53c8322 Added areas.PlotArea for chart plot areas
rgbecker
parents: 1683
diff changeset
   126
        lines = AttrMapValue(None, desc='Handle of the lines.'),
dc56f53c8322 Added areas.PlotArea for chart plot areas
rgbecker
parents: 1683
diff changeset
   127
        valueAxis = AttrMapValue(None, desc='Handle of the value axis.'),
dc56f53c8322 Added areas.PlotArea for chart plot areas
rgbecker
parents: 1683
diff changeset
   128
        categoryAxis = AttrMapValue(None, desc='Handle of the category axis.'),
dc56f53c8322 Added areas.PlotArea for chart plot areas
rgbecker
parents: 1683
diff changeset
   129
        categoryNames = AttrMapValue(isListOfStringsOrNone, desc='List of category names.'),
dc56f53c8322 Added areas.PlotArea for chart plot areas
rgbecker
parents: 1683
diff changeset
   130
        data = AttrMapValue(None, desc='Data to be plotted, list of (lists of) numbers.'),
3271
c14b161b62bf attributes help messages
meitham
parents: 3248
diff changeset
   131
        inFill = AttrMapValue(isBoolean, desc='Whether infilling should be done.',advancedUsage=1),
c14b161b62bf attributes help messages
meitham
parents: 3248
diff changeset
   132
        reversePlotOrder = AttrMapValue(isBoolean, desc='If true reverse plot order.',advancedUsage=1),
c14b161b62bf attributes help messages
meitham
parents: 3248
diff changeset
   133
        annotations = AttrMapValue(None, desc='list of callables, will be called with self, xscale, yscale.',advancedUsage=1),
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   134
        )
737
8f0e58918da9 Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff changeset
   135
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   136
    def __init__(self):
1692
dc56f53c8322 Added areas.PlotArea for chart plot areas
rgbecker
parents: 1683
diff changeset
   137
        LineChart.__init__(self)
737
8f0e58918da9 Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff changeset
   138
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   139
        # Allow for a bounding rectangle.
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   140
        self.strokeColor = None
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   141
        self.fillColor = None
737
8f0e58918da9 Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff changeset
   142
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   143
        # Named so we have less recoding for the horizontal one :-)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   144
        self.categoryAxis = XCategoryAxis()
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   145
        self.valueAxis = YValueAxis()
737
8f0e58918da9 Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff changeset
   146
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   147
        # This defines two series of 3 points.  Just an example.
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   148
        self.data = [(100,110,120,130),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   149
                     (70, 80, 80, 90)]
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   150
        self.categoryNames = ('North','South','East','West')
917
a4aea7356094 Switched to using typed collection styles.
dinu_gherman
parents: 909
diff changeset
   151
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   152
        self.lines = TypedPropertyCollection(LineChartProperties)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   153
        self.lines.strokeWidth = 1
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   154
        self.lines[0].strokeColor = colors.red
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   155
        self.lines[1].strokeColor = colors.green
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   156
        self.lines[2].strokeColor = colors.blue
737
8f0e58918da9 Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff changeset
   157
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   158
        # control spacing. if useAbsolute = 1 then
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   159
        # the next parameters are in points; otherwise
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   160
        # they are 'proportions' and are normalized to
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   161
        # fit the available space.
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   162
        self.useAbsolute = 0   #- not done yet
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   163
        self.groupSpacing = 1 #5
737
8f0e58918da9 Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff changeset
   164
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   165
        self.lineLabels = TypedPropertyCollection(Label)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   166
        self.lineLabelFormat = None
1996
0150666f5022 dded in stuff for area plots, fixes to axis formatting etc
rgbecker
parents: 1995
diff changeset
   167
        self.lineLabelArray = None
737
8f0e58918da9 Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff changeset
   168
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   169
        # This says whether the origin is above or below
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   170
        # the data point. +10 means put the origin ten points
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   171
        # above the data point if value > 0, or ten
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   172
        # points below if data value < 0.  This is different
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   173
        # to label dx/dy which are not dependent on the
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   174
        # sign of the data.
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   175
        self.lineLabelNudge = 10
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   176
        # If you have multiple series, by default they butt
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   177
        # together.
737
8f0e58918da9 Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff changeset
   178
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   179
        # New line chart attributes.
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   180
        self.joinedLines = 1 # Connect items with straight lines.
1995
aef8565e39a1 Added inFill stuff/reversePlotOrder for LineChart
rgbecker
parents: 1974
diff changeset
   181
        self.inFill = 0
aef8565e39a1 Added inFill stuff/reversePlotOrder for LineChart
rgbecker
parents: 1974
diff changeset
   182
        self.reversePlotOrder = 0
737
8f0e58918da9 Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff changeset
   183
8f0e58918da9 Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff changeset
   184
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   185
    def demo(self):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   186
        """Shows basic use of a line chart."""
1272
3172686c9ee5 Made linecharts use the new markers/flags some of which were improved
rgbecker
parents: 1236
diff changeset
   187
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   188
        drawing = Drawing(200, 100)
737
8f0e58918da9 Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff changeset
   189
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   190
        data = [
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   191
                (13, 5, 20, 22, 37, 45, 19, 4),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   192
                (14, 10, 21, 28, 38, 46, 25, 5)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   193
                ]
737
8f0e58918da9 Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff changeset
   194
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   195
        lc = HorizontalLineChart()
773
7b1fa8676a0b Added to docstrings and tidied-up a bit.
dinu_gherman
parents: 737
diff changeset
   196
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   197
        lc.x = 20
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   198
        lc.y = 10
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   199
        lc.height = 85
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   200
        lc.width = 170
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   201
        lc.data = data
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   202
        lc.lines.symbol = makeMarker('Circle')
773
7b1fa8676a0b Added to docstrings and tidied-up a bit.
dinu_gherman
parents: 737
diff changeset
   203
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   204
        drawing.add(lc)
737
8f0e58918da9 Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff changeset
   205
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   206
        return drawing
737
8f0e58918da9 Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff changeset
   207
8f0e58918da9 Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff changeset
   208
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   209
    def calcPositions(self):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   210
        """Works out where they go.
737
8f0e58918da9 Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff changeset
   211
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   212
        Sets an attribute _positions which is a list of
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   213
        lists of (x, y) matching the data.
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   214
        """
1272
3172686c9ee5 Made linecharts use the new markers/flags some of which were improved
rgbecker
parents: 1236
diff changeset
   215
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   216
        self._seriesCount = len(self.data)
3721
0c93dd8ff567 initial changes from 2to3-3.3
rptlab
parents: 3627
diff changeset
   217
        self._rowLength = max(list(map(len,self.data)))
737
8f0e58918da9 Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff changeset
   218
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   219
        if self.useAbsolute:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   220
            # Dimensions are absolute.
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   221
            normFactor = 1.0
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   222
        else:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   223
            # Dimensions are normalized to fit.
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   224
            normWidth = self.groupSpacing
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   225
            availWidth = self.categoryAxis.scale(0)[1]
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   226
            normFactor = availWidth / normWidth
3625
c459ddaafe88 linecharts.py: added in lineStyle (for bars)
rgbecker
parents: 3617
diff changeset
   227
        self._normFactor = normFactor
c459ddaafe88 linecharts.py: added in lineStyle (for bars)
rgbecker
parents: 3617
diff changeset
   228
        self._yzero = yzero = self.valueAxis.scale(0)
c459ddaafe88 linecharts.py: added in lineStyle (for bars)
rgbecker
parents: 3617
diff changeset
   229
        self._hngs = hngs = 0.5 * self.groupSpacing * normFactor
737
8f0e58918da9 Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff changeset
   230
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   231
        self._positions = []
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   232
        for rowNo in range(len(self.data)):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   233
            lineRow = []
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   234
            for colNo in range(len(self.data[rowNo])):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   235
                datum = self.data[rowNo][colNo]
1925
07fbda84456a Dirk Datzert's None Patch
rgbecker
parents: 1692
diff changeset
   236
                if datum is not None:
07fbda84456a Dirk Datzert's None Patch
rgbecker
parents: 1692
diff changeset
   237
                    (groupX, groupWidth) = self.categoryAxis.scale(colNo)
3625
c459ddaafe88 linecharts.py: added in lineStyle (for bars)
rgbecker
parents: 3617
diff changeset
   238
                    x = groupX + hngs
c459ddaafe88 linecharts.py: added in lineStyle (for bars)
rgbecker
parents: 3617
diff changeset
   239
                    y = yzero
1925
07fbda84456a Dirk Datzert's None Patch
rgbecker
parents: 1692
diff changeset
   240
                    height = self.valueAxis.scale(datum) - y
07fbda84456a Dirk Datzert's None Patch
rgbecker
parents: 1692
diff changeset
   241
                    lineRow.append((x, y+height))
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   242
            self._positions.append(lineRow)
838
74df7db022e1 Aplitted draw method.
dinu_gherman
parents: 817
diff changeset
   243
74df7db022e1 Aplitted draw method.
dinu_gherman
parents: 817
diff changeset
   244
2068
6a398064dd55 Working HorizontalLineCharts3D
rgbecker
parents: 2054
diff changeset
   245
    def _innerDrawLabel(self, rowNo, colNo, x, y):
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   246
        "Draw a label for a given item in the list."
1272
3172686c9ee5 Made linecharts use the new markers/flags some of which were improved
rgbecker
parents: 1236
diff changeset
   247
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   248
        labelFmt = self.lineLabelFormat
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   249
        labelValue = self.data[rowNo][colNo]
1272
3172686c9ee5 Made linecharts use the new markers/flags some of which were improved
rgbecker
parents: 1236
diff changeset
   250
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   251
        if labelFmt is None:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   252
            labelText = None
2690
ccc09da782f6 charts: minor label format fixes and minor changes inspired by Gael Chardon
rgbecker
parents: 2427
diff changeset
   253
        elif type(labelFmt) is str:
2018
6ffd97616aab Fixes to lineLabelArray detection
rgbecker
parents: 1996
diff changeset
   254
            if labelFmt == 'values':
2830
144ae590acb5 linecharts.py: allow empty lables
rgbecker
parents: 2714
diff changeset
   255
                try:
144ae590acb5 linecharts.py: allow empty lables
rgbecker
parents: 2714
diff changeset
   256
                    labelText = self.lineLabelArray[rowNo][colNo]
144ae590acb5 linecharts.py: allow empty lables
rgbecker
parents: 2714
diff changeset
   257
                except:
144ae590acb5 linecharts.py: allow empty lables
rgbecker
parents: 2714
diff changeset
   258
                    labelText = None
2018
6ffd97616aab Fixes to lineLabelArray detection
rgbecker
parents: 1996
diff changeset
   259
            else:
6ffd97616aab Fixes to lineLabelArray detection
rgbecker
parents: 1996
diff changeset
   260
                labelText = labelFmt % labelValue
3326
ce725978d11c Initial Python3 compatibility fixes
damian
parents: 3271
diff changeset
   261
        elif hasattr(labelFmt,'__call__'):
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   262
            labelText = labelFmt(labelValue)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   263
        else:
3248
97d4415ab527 lineplots/linecharts: fix lineLabels.visble and also remove Formatter usage
rgbecker
parents: 3239
diff changeset
   264
            raise ValueError("Unknown formatter type %s, expected string or function"%labelFmt)
737
8f0e58918da9 Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff changeset
   265
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   266
        if labelText:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   267
            label = self.lineLabels[(rowNo, colNo)]
3248
97d4415ab527 lineplots/linecharts: fix lineLabels.visble and also remove Formatter usage
rgbecker
parents: 3239
diff changeset
   268
            if not label.visible: return
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   269
            # Make sure labels are some distance off the data point.
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   270
            if y > 0:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   271
                label.setOrigin(x, y + self.lineLabelNudge)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   272
            else:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   273
                label.setOrigin(x, y - self.lineLabelNudge)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   274
            label.setText(labelText)
2068
6a398064dd55 Working HorizontalLineCharts3D
rgbecker
parents: 2054
diff changeset
   275
        else:
6a398064dd55 Working HorizontalLineCharts3D
rgbecker
parents: 2054
diff changeset
   276
            label = None
6a398064dd55 Working HorizontalLineCharts3D
rgbecker
parents: 2054
diff changeset
   277
        return label
1272
3172686c9ee5 Made linecharts use the new markers/flags some of which were improved
rgbecker
parents: 1236
diff changeset
   278
2068
6a398064dd55 Working HorizontalLineCharts3D
rgbecker
parents: 2054
diff changeset
   279
    def drawLabel(self, G, rowNo, colNo, x, y):
6a398064dd55 Working HorizontalLineCharts3D
rgbecker
parents: 2054
diff changeset
   280
        '''Draw a label for a given item in the list.
6a398064dd55 Working HorizontalLineCharts3D
rgbecker
parents: 2054
diff changeset
   281
        G must have an add method'''
6a398064dd55 Working HorizontalLineCharts3D
rgbecker
parents: 2054
diff changeset
   282
        G.add(self._innerDrawLabel(rowNo,colNo,x,y))
1272
3172686c9ee5 Made linecharts use the new markers/flags some of which were improved
rgbecker
parents: 1236
diff changeset
   283
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   284
    def makeLines(self):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   285
        g = Group()
737
8f0e58918da9 Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff changeset
   286
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   287
        labelFmt = self.lineLabelFormat
3721
0c93dd8ff567 initial changes from 2to3-3.3
rptlab
parents: 3627
diff changeset
   288
        P = list(range(len(self._positions)))
1995
aef8565e39a1 Added inFill stuff/reversePlotOrder for LineChart
rgbecker
parents: 1974
diff changeset
   289
        if self.reversePlotOrder: P.reverse()
aef8565e39a1 Added inFill stuff/reversePlotOrder for LineChart
rgbecker
parents: 1974
diff changeset
   290
        inFill = self.inFill
aef8565e39a1 Added inFill stuff/reversePlotOrder for LineChart
rgbecker
parents: 1974
diff changeset
   291
        if inFill:
aef8565e39a1 Added inFill stuff/reversePlotOrder for LineChart
rgbecker
parents: 1974
diff changeset
   292
            inFillY = self.categoryAxis._y
aef8565e39a1 Added inFill stuff/reversePlotOrder for LineChart
rgbecker
parents: 1974
diff changeset
   293
            inFillX0 = self.valueAxis._x
aef8565e39a1 Added inFill stuff/reversePlotOrder for LineChart
rgbecker
parents: 1974
diff changeset
   294
            inFillX1 = inFillX0 + self.categoryAxis._length
aef8565e39a1 Added inFill stuff/reversePlotOrder for LineChart
rgbecker
parents: 1974
diff changeset
   295
            inFillG = getattr(self,'_inFillG',g)
3625
c459ddaafe88 linecharts.py: added in lineStyle (for bars)
rgbecker
parents: 3617
diff changeset
   296
        yzero = self._yzero
917
a4aea7356094 Switched to using typed collection styles.
dinu_gherman
parents: 909
diff changeset
   297
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   298
        # Iterate over data rows.
1995
aef8565e39a1 Added inFill stuff/reversePlotOrder for LineChart
rgbecker
parents: 1974
diff changeset
   299
        for rowNo in P:
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   300
            row = self._positions[rowNo]
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   301
            styleCount = len(self.lines)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   302
            styleIdx = rowNo % styleCount
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   303
            rowStyle = self.lines[styleIdx]
1995
aef8565e39a1 Added inFill stuff/reversePlotOrder for LineChart
rgbecker
parents: 1974
diff changeset
   304
            rowColor = rowStyle.strokeColor
aef8565e39a1 Added inFill stuff/reversePlotOrder for LineChart
rgbecker
parents: 1974
diff changeset
   305
            dash = getattr(rowStyle, 'strokeDashArray', None)
3625
c459ddaafe88 linecharts.py: added in lineStyle (for bars)
rgbecker
parents: 3617
diff changeset
   306
            lineStyle = getattr(rowStyle,'lineStyle',None)
737
8f0e58918da9 Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff changeset
   307
3625
c459ddaafe88 linecharts.py: added in lineStyle (for bars)
rgbecker
parents: 3617
diff changeset
   308
            if hasattr(rowStyle, 'strokeWidth'):
c459ddaafe88 linecharts.py: added in lineStyle (for bars)
rgbecker
parents: 3617
diff changeset
   309
                strokeWidth = rowStyle.strokeWidth
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   310
            elif hasattr(self.lines, 'strokeWidth'):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   311
                strokeWidth = self.lines.strokeWidth
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   312
            else:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   313
                strokeWidth = None
737
8f0e58918da9 Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff changeset
   314
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   315
            # Iterate over data columns.
3625
c459ddaafe88 linecharts.py: added in lineStyle (for bars)
rgbecker
parents: 3617
diff changeset
   316
            if lineStyle=='bar':
c459ddaafe88 linecharts.py: added in lineStyle (for bars)
rgbecker
parents: 3617
diff changeset
   317
                barWidth = getattr(rowStyle,'barWidth',Percentage(50))
c459ddaafe88 linecharts.py: added in lineStyle (for bars)
rgbecker
parents: 3617
diff changeset
   318
                fillColor = getattr(rowStyle,'fillColor',rowColor)
c459ddaafe88 linecharts.py: added in lineStyle (for bars)
rgbecker
parents: 3617
diff changeset
   319
                if isinstance(barWidth,Percentage):
c459ddaafe88 linecharts.py: added in lineStyle (for bars)
rgbecker
parents: 3617
diff changeset
   320
                    hbw = self._hngs*barWidth*0.01
c459ddaafe88 linecharts.py: added in lineStyle (for bars)
rgbecker
parents: 3617
diff changeset
   321
                else:
c459ddaafe88 linecharts.py: added in lineStyle (for bars)
rgbecker
parents: 3617
diff changeset
   322
                    hbw = barWidth*0.5
c459ddaafe88 linecharts.py: added in lineStyle (for bars)
rgbecker
parents: 3617
diff changeset
   323
                for colNo in range(len(row)):
c459ddaafe88 linecharts.py: added in lineStyle (for bars)
rgbecker
parents: 3617
diff changeset
   324
                    x,y = row[colNo]
c459ddaafe88 linecharts.py: added in lineStyle (for bars)
rgbecker
parents: 3617
diff changeset
   325
                    g.add(Rect(x-hbw,min(y,yzero),2*hbw,abs(y-yzero),strokeWidth=strokeWidth,strokeColor=rowColor,fillColor=fillColor))
c459ddaafe88 linecharts.py: added in lineStyle (for bars)
rgbecker
parents: 3617
diff changeset
   326
            elif self.joinedLines or lineStyle=='joinedLine':
1995
aef8565e39a1 Added inFill stuff/reversePlotOrder for LineChart
rgbecker
parents: 1974
diff changeset
   327
                points = []
aef8565e39a1 Added inFill stuff/reversePlotOrder for LineChart
rgbecker
parents: 1974
diff changeset
   328
                for colNo in range(len(row)):
aef8565e39a1 Added inFill stuff/reversePlotOrder for LineChart
rgbecker
parents: 1974
diff changeset
   329
                    points += row[colNo]
aef8565e39a1 Added inFill stuff/reversePlotOrder for LineChart
rgbecker
parents: 1974
diff changeset
   330
                if inFill:
aef8565e39a1 Added inFill stuff/reversePlotOrder for LineChart
rgbecker
parents: 1974
diff changeset
   331
                    points = points + [inFillX1,inFillY,inFillX0,inFillY]
aef8565e39a1 Added inFill stuff/reversePlotOrder for LineChart
rgbecker
parents: 1974
diff changeset
   332
                    inFillG.add(Polygon(points,fillColor=rowColor,strokeColor=rowColor,strokeWidth=0.1))
aef8565e39a1 Added inFill stuff/reversePlotOrder for LineChart
rgbecker
parents: 1974
diff changeset
   333
                else:
aef8565e39a1 Added inFill stuff/reversePlotOrder for LineChart
rgbecker
parents: 1974
diff changeset
   334
                    line = PolyLine(points,strokeColor=rowColor,strokeLineCap=0,strokeLineJoin=1)
aef8565e39a1 Added inFill stuff/reversePlotOrder for LineChart
rgbecker
parents: 1974
diff changeset
   335
                    if strokeWidth:
aef8565e39a1 Added inFill stuff/reversePlotOrder for LineChart
rgbecker
parents: 1974
diff changeset
   336
                        line.strokeWidth = strokeWidth
aef8565e39a1 Added inFill stuff/reversePlotOrder for LineChart
rgbecker
parents: 1974
diff changeset
   337
                    if dash:
aef8565e39a1 Added inFill stuff/reversePlotOrder for LineChart
rgbecker
parents: 1974
diff changeset
   338
                        line.strokeDashArray = dash
aef8565e39a1 Added inFill stuff/reversePlotOrder for LineChart
rgbecker
parents: 1974
diff changeset
   339
                    g.add(line)
838
74df7db022e1 Aplitted draw method.
dinu_gherman
parents: 817
diff changeset
   340
3625
c459ddaafe88 linecharts.py: added in lineStyle (for bars)
rgbecker
parents: 3617
diff changeset
   341
            if hasattr(rowStyle, 'symbol'):
c459ddaafe88 linecharts.py: added in lineStyle (for bars)
rgbecker
parents: 3617
diff changeset
   342
                uSymbol = rowStyle.symbol
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   343
            elif hasattr(self.lines, 'symbol'):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   344
                uSymbol = self.lines.symbol
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   345
            else:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   346
                uSymbol = None
737
8f0e58918da9 Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff changeset
   347
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   348
            if uSymbol:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   349
                for colNo in range(len(row)):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   350
                    x1, y1 = row[colNo]
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   351
                    symbol = uSymbol2Symbol(uSymbol,x1,y1,rowStyle.strokeColor)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   352
                    if symbol: g.add(symbol)
917
a4aea7356094 Switched to using typed collection styles.
dinu_gherman
parents: 909
diff changeset
   353
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   354
            # Draw item labels.
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   355
            for colNo in range(len(row)):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   356
                x1, y1 = row[colNo]
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   357
                self.drawLabel(g, rowNo, colNo, x1, y1)
1272
3172686c9ee5 Made linecharts use the new markers/flags some of which were improved
rgbecker
parents: 1236
diff changeset
   358
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   359
        return g
838
74df7db022e1 Aplitted draw method.
dinu_gherman
parents: 817
diff changeset
   360
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   361
    def draw(self):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   362
        "Draws itself."
1272
3172686c9ee5 Made linecharts use the new markers/flags some of which were improved
rgbecker
parents: 1236
diff changeset
   363
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   364
        vA, cA = self.valueAxis, self.categoryAxis
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   365
        vA.setPosition(self.x, self.y, self.height)
2091
c50250de3016 Fix up for joinAxis modes
rgbecker
parents: 2079
diff changeset
   366
        if vA: vA.joinAxis = cA
c50250de3016 Fix up for joinAxis modes
rgbecker
parents: 2079
diff changeset
   367
        if cA: cA.joinAxis = vA
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   368
        vA.configure(self.data)
838
74df7db022e1 Aplitted draw method.
dinu_gherman
parents: 817
diff changeset
   369
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   370
        # If zero is in chart, put x axis there, otherwise
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   371
        # use bottom.
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   372
        xAxisCrossesAt = vA.scale(0)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   373
        if ((xAxisCrossesAt > self.y + self.height) or (xAxisCrossesAt < self.y)):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   374
            y = self.y
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   375
        else:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   376
            y = xAxisCrossesAt
838
74df7db022e1 Aplitted draw method.
dinu_gherman
parents: 817
diff changeset
   377
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   378
        cA.setPosition(self.x, y, self.width)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   379
        cA.configure(self.data)
1272
3172686c9ee5 Made linecharts use the new markers/flags some of which were improved
rgbecker
parents: 1236
diff changeset
   380
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   381
        self.calcPositions()
1272
3172686c9ee5 Made linecharts use the new markers/flags some of which were improved
rgbecker
parents: 1236
diff changeset
   382
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   383
        g = Group()
1995
aef8565e39a1 Added inFill stuff/reversePlotOrder for LineChart
rgbecker
parents: 1974
diff changeset
   384
        g.add(self.makeBackground())
aef8565e39a1 Added inFill stuff/reversePlotOrder for LineChart
rgbecker
parents: 1974
diff changeset
   385
        if self.inFill:
aef8565e39a1 Added inFill stuff/reversePlotOrder for LineChart
rgbecker
parents: 1974
diff changeset
   386
            self._inFillG = Group()
aef8565e39a1 Added inFill stuff/reversePlotOrder for LineChart
rgbecker
parents: 1974
diff changeset
   387
            g.add(self._inFillG)
838
74df7db022e1 Aplitted draw method.
dinu_gherman
parents: 817
diff changeset
   388
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   389
        g.add(cA)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   390
        g.add(vA)
3206
25606c688529 charts: silly attempt at getting the grid to draw last
rgbecker
parents: 3032
diff changeset
   391
        cAdgl = getattr(cA,'drawGridLast',False)
25606c688529 charts: silly attempt at getting the grid to draw last
rgbecker
parents: 3032
diff changeset
   392
        vAdgl = getattr(vA,'drawGridLast',False)
25606c688529 charts: silly attempt at getting the grid to draw last
rgbecker
parents: 3032
diff changeset
   393
        if not cAdgl: cA.makeGrid(g,parent=self,dim=vA.getGridDims)
25606c688529 charts: silly attempt at getting the grid to draw last
rgbecker
parents: 3032
diff changeset
   394
        if not vAdgl: vA.makeGrid(g,parent=self,dim=cA.getGridDims)
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   395
        g.add(self.makeLines())
3239
4cce2dfb5c34 charts: fix drawGridLast behaviours
rgbecker
parents: 3206
diff changeset
   396
        if cAdgl: cA.makeGrid(g,parent=self,dim=vA.getGridDims)
4cce2dfb5c34 charts: fix drawGridLast behaviours
rgbecker
parents: 3206
diff changeset
   397
        if vAdgl: vA.makeGrid(g,parent=self,dim=cA.getGridDims)
2147
b3b1ed8ac522 Add annotations
rgbecker
parents: 2145
diff changeset
   398
        for a in getattr(self,'annotations',()): g.add(a(self,cA.scale,vA.scale))
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   399
        return g
737
8f0e58918da9 Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff changeset
   400
3818
6f3973d1e134 attempt to fix cmp-->key sorting
robin
parents: 3721
diff changeset
   401
def _fakeItemKey(a):
2068
6a398064dd55 Working HorizontalLineCharts3D
rgbecker
parents: 2054
diff changeset
   402
    '''t, z0, z1, x, y = a[:5]'''
3818
6f3973d1e134 attempt to fix cmp-->key sorting
robin
parents: 3721
diff changeset
   403
    return (-a[1],a[3],a[0],-a[4])
2068
6a398064dd55 Working HorizontalLineCharts3D
rgbecker
parents: 2054
diff changeset
   404
6a398064dd55 Working HorizontalLineCharts3D
rgbecker
parents: 2054
diff changeset
   405
class _FakeGroup:
6a398064dd55 Working HorizontalLineCharts3D
rgbecker
parents: 2054
diff changeset
   406
    def __init__(self):
6a398064dd55 Working HorizontalLineCharts3D
rgbecker
parents: 2054
diff changeset
   407
        self._data = []
6a398064dd55 Working HorizontalLineCharts3D
rgbecker
parents: 2054
diff changeset
   408
6a398064dd55 Working HorizontalLineCharts3D
rgbecker
parents: 2054
diff changeset
   409
    def add(self,what):
6a398064dd55 Working HorizontalLineCharts3D
rgbecker
parents: 2054
diff changeset
   410
        if what: self._data.append(what)
6a398064dd55 Working HorizontalLineCharts3D
rgbecker
parents: 2054
diff changeset
   411
6a398064dd55 Working HorizontalLineCharts3D
rgbecker
parents: 2054
diff changeset
   412
    def value(self):
6a398064dd55 Working HorizontalLineCharts3D
rgbecker
parents: 2054
diff changeset
   413
        return self._data
6a398064dd55 Working HorizontalLineCharts3D
rgbecker
parents: 2054
diff changeset
   414
6a398064dd55 Working HorizontalLineCharts3D
rgbecker
parents: 2054
diff changeset
   415
    def sort(self):
3818
6f3973d1e134 attempt to fix cmp-->key sorting
robin
parents: 3721
diff changeset
   416
        self._data.sort(key=_fakeItemKey)
2068
6a398064dd55 Working HorizontalLineCharts3D
rgbecker
parents: 2054
diff changeset
   417
        #for t in self._data: print t
6a398064dd55 Working HorizontalLineCharts3D
rgbecker
parents: 2054
diff changeset
   418
6a398064dd55 Working HorizontalLineCharts3D
rgbecker
parents: 2054
diff changeset
   419
class HorizontalLineChart3D(HorizontalLineChart):
6a398064dd55 Working HorizontalLineCharts3D
rgbecker
parents: 2054
diff changeset
   420
    _attrMap = AttrMap(BASE=HorizontalLineChart,
6a398064dd55 Working HorizontalLineCharts3D
rgbecker
parents: 2054
diff changeset
   421
        theta_x = AttrMapValue(isNumber, desc='dx/dz'),
6a398064dd55 Working HorizontalLineCharts3D
rgbecker
parents: 2054
diff changeset
   422
        theta_y = AttrMapValue(isNumber, desc='dy/dz'),
6a398064dd55 Working HorizontalLineCharts3D
rgbecker
parents: 2054
diff changeset
   423
        zDepth = AttrMapValue(isNumber, desc='depth of an individual series'),
6a398064dd55 Working HorizontalLineCharts3D
rgbecker
parents: 2054
diff changeset
   424
        zSpace = AttrMapValue(isNumber, desc='z gap around series'),
6a398064dd55 Working HorizontalLineCharts3D
rgbecker
parents: 2054
diff changeset
   425
        )
6a398064dd55 Working HorizontalLineCharts3D
rgbecker
parents: 2054
diff changeset
   426
    theta_x = .5
6a398064dd55 Working HorizontalLineCharts3D
rgbecker
parents: 2054
diff changeset
   427
    theta_y = .5
6a398064dd55 Working HorizontalLineCharts3D
rgbecker
parents: 2054
diff changeset
   428
    zDepth = 10
2079
2ec043bb4c85 Set reasonable zSpace
rgbecker
parents: 2072
diff changeset
   429
    zSpace = 3
2068
6a398064dd55 Working HorizontalLineCharts3D
rgbecker
parents: 2054
diff changeset
   430
6a398064dd55 Working HorizontalLineCharts3D
rgbecker
parents: 2054
diff changeset
   431
    def calcPositions(self):
6a398064dd55 Working HorizontalLineCharts3D
rgbecker
parents: 2054
diff changeset
   432
        HorizontalLineChart.calcPositions(self)
6a398064dd55 Working HorizontalLineCharts3D
rgbecker
parents: 2054
diff changeset
   433
        nSeries = self._seriesCount
6a398064dd55 Working HorizontalLineCharts3D
rgbecker
parents: 2054
diff changeset
   434
        zSpace = self.zSpace
6a398064dd55 Working HorizontalLineCharts3D
rgbecker
parents: 2054
diff changeset
   435
        zDepth = self.zDepth
6a398064dd55 Working HorizontalLineCharts3D
rgbecker
parents: 2054
diff changeset
   436
        if self.categoryAxis.style=='parallel_3d':
2079
2ec043bb4c85 Set reasonable zSpace
rgbecker
parents: 2072
diff changeset
   437
            _3d_depth = nSeries*zDepth+(nSeries+1)*zSpace
2068
6a398064dd55 Working HorizontalLineCharts3D
rgbecker
parents: 2054
diff changeset
   438
        else:
6a398064dd55 Working HorizontalLineCharts3D
rgbecker
parents: 2054
diff changeset
   439
            _3d_depth = zDepth + 2*zSpace
6a398064dd55 Working HorizontalLineCharts3D
rgbecker
parents: 2054
diff changeset
   440
        self._3d_dx = self.theta_x*_3d_depth
6a398064dd55 Working HorizontalLineCharts3D
rgbecker
parents: 2054
diff changeset
   441
        self._3d_dy = self.theta_y*_3d_depth
6a398064dd55 Working HorizontalLineCharts3D
rgbecker
parents: 2054
diff changeset
   442
6a398064dd55 Working HorizontalLineCharts3D
rgbecker
parents: 2054
diff changeset
   443
    def _calc_z0(self,rowNo):
6a398064dd55 Working HorizontalLineCharts3D
rgbecker
parents: 2054
diff changeset
   444
        zSpace = self.zSpace
6a398064dd55 Working HorizontalLineCharts3D
rgbecker
parents: 2054
diff changeset
   445
        if self.categoryAxis.style=='parallel_3d':
6a398064dd55 Working HorizontalLineCharts3D
rgbecker
parents: 2054
diff changeset
   446
            z0 = rowNo*(self.zDepth+zSpace)+zSpace
6a398064dd55 Working HorizontalLineCharts3D
rgbecker
parents: 2054
diff changeset
   447
        else:
6a398064dd55 Working HorizontalLineCharts3D
rgbecker
parents: 2054
diff changeset
   448
            z0 = zSpace
6a398064dd55 Working HorizontalLineCharts3D
rgbecker
parents: 2054
diff changeset
   449
        return z0
6a398064dd55 Working HorizontalLineCharts3D
rgbecker
parents: 2054
diff changeset
   450
6a398064dd55 Working HorizontalLineCharts3D
rgbecker
parents: 2054
diff changeset
   451
    def _zadjust(self,x,y,z):
2071
ccbed33977a9 Added in lineplot3d and got data labels working
rgbecker
parents: 2070
diff changeset
   452
        return x+z*self.theta_x, y+z*self.theta_y
2068
6a398064dd55 Working HorizontalLineCharts3D
rgbecker
parents: 2054
diff changeset
   453
6a398064dd55 Working HorizontalLineCharts3D
rgbecker
parents: 2054
diff changeset
   454
    def makeLines(self):
6a398064dd55 Working HorizontalLineCharts3D
rgbecker
parents: 2054
diff changeset
   455
        labelFmt = self.lineLabelFormat
3721
0c93dd8ff567 initial changes from 2to3-3.3
rptlab
parents: 3627
diff changeset
   456
        P = list(range(len(self._positions)))
2068
6a398064dd55 Working HorizontalLineCharts3D
rgbecker
parents: 2054
diff changeset
   457
        if self.reversePlotOrder: P.reverse()
6a398064dd55 Working HorizontalLineCharts3D
rgbecker
parents: 2054
diff changeset
   458
        inFill = self.inFill
6a398064dd55 Working HorizontalLineCharts3D
rgbecker
parents: 2054
diff changeset
   459
        assert not inFill, "inFill not supported for 3d yet"
6a398064dd55 Working HorizontalLineCharts3D
rgbecker
parents: 2054
diff changeset
   460
        #if inFill:
6a398064dd55 Working HorizontalLineCharts3D
rgbecker
parents: 2054
diff changeset
   461
            #inFillY = self.categoryAxis._y
6a398064dd55 Working HorizontalLineCharts3D
rgbecker
parents: 2054
diff changeset
   462
            #inFillX0 = self.valueAxis._x
6a398064dd55 Working HorizontalLineCharts3D
rgbecker
parents: 2054
diff changeset
   463
            #inFillX1 = inFillX0 + self.categoryAxis._length
6a398064dd55 Working HorizontalLineCharts3D
rgbecker
parents: 2054
diff changeset
   464
            #inFillG = getattr(self,'_inFillG',g)
6a398064dd55 Working HorizontalLineCharts3D
rgbecker
parents: 2054
diff changeset
   465
        zDepth = self.zDepth
6a398064dd55 Working HorizontalLineCharts3D
rgbecker
parents: 2054
diff changeset
   466
        _zadjust = self._zadjust
6a398064dd55 Working HorizontalLineCharts3D
rgbecker
parents: 2054
diff changeset
   467
        theta_x = self.theta_x
6a398064dd55 Working HorizontalLineCharts3D
rgbecker
parents: 2054
diff changeset
   468
        theta_y = self.theta_y
6a398064dd55 Working HorizontalLineCharts3D
rgbecker
parents: 2054
diff changeset
   469
        F = _FakeGroup()
3975
4a3599863c11 eliminate from . imports in favour of absolutes to allow running modules
robin
parents: 3818
diff changeset
   470
        from reportlab.graphics.charts.utils3d import _make_3d_line_info
2151
fad2252e4e6f Allow for non-tiling!
rgbecker
parents: 2147
diff changeset
   471
        tileWidth = getattr(self,'_3d_tilewidth',None)
fad2252e4e6f Allow for non-tiling!
rgbecker
parents: 2147
diff changeset
   472
        if not tileWidth and self.categoryAxis.style!='parallel_3d': tileWidth = 1
2068
6a398064dd55 Working HorizontalLineCharts3D
rgbecker
parents: 2054
diff changeset
   473
6a398064dd55 Working HorizontalLineCharts3D
rgbecker
parents: 2054
diff changeset
   474
        # Iterate over data rows.
6a398064dd55 Working HorizontalLineCharts3D
rgbecker
parents: 2054
diff changeset
   475
        for rowNo in P:
6a398064dd55 Working HorizontalLineCharts3D
rgbecker
parents: 2054
diff changeset
   476
            row = self._positions[rowNo]
2070
fb34cff995ab Minor adjustmenst and added LinePlot3D
rgbecker
parents: 2069
diff changeset
   477
            n = len(row)
2068
6a398064dd55 Working HorizontalLineCharts3D
rgbecker
parents: 2054
diff changeset
   478
            styleCount = len(self.lines)
6a398064dd55 Working HorizontalLineCharts3D
rgbecker
parents: 2054
diff changeset
   479
            styleIdx = rowNo % styleCount
6a398064dd55 Working HorizontalLineCharts3D
rgbecker
parents: 2054
diff changeset
   480
            rowStyle = self.lines[styleIdx]
6a398064dd55 Working HorizontalLineCharts3D
rgbecker
parents: 2054
diff changeset
   481
            rowColor = rowStyle.strokeColor
6a398064dd55 Working HorizontalLineCharts3D
rgbecker
parents: 2054
diff changeset
   482
            dash = getattr(rowStyle, 'strokeDashArray', None)
6a398064dd55 Working HorizontalLineCharts3D
rgbecker
parents: 2054
diff changeset
   483
            z0 = self._calc_z0(rowNo)
6a398064dd55 Working HorizontalLineCharts3D
rgbecker
parents: 2054
diff changeset
   484
            z1 = z0 + zDepth
6a398064dd55 Working HorizontalLineCharts3D
rgbecker
parents: 2054
diff changeset
   485
6a398064dd55 Working HorizontalLineCharts3D
rgbecker
parents: 2054
diff changeset
   486
            if hasattr(self.lines[styleIdx], 'strokeWidth'):
6a398064dd55 Working HorizontalLineCharts3D
rgbecker
parents: 2054
diff changeset
   487
                strokeWidth = self.lines[styleIdx].strokeWidth
6a398064dd55 Working HorizontalLineCharts3D
rgbecker
parents: 2054
diff changeset
   488
            elif hasattr(self.lines, 'strokeWidth'):
6a398064dd55 Working HorizontalLineCharts3D
rgbecker
parents: 2054
diff changeset
   489
                strokeWidth = self.lines.strokeWidth
6a398064dd55 Working HorizontalLineCharts3D
rgbecker
parents: 2054
diff changeset
   490
            else:
6a398064dd55 Working HorizontalLineCharts3D
rgbecker
parents: 2054
diff changeset
   491
                strokeWidth = None
6a398064dd55 Working HorizontalLineCharts3D
rgbecker
parents: 2054
diff changeset
   492
6a398064dd55 Working HorizontalLineCharts3D
rgbecker
parents: 2054
diff changeset
   493
            # Iterate over data columns.
6a398064dd55 Working HorizontalLineCharts3D
rgbecker
parents: 2054
diff changeset
   494
            if self.joinedLines:
6a398064dd55 Working HorizontalLineCharts3D
rgbecker
parents: 2054
diff changeset
   495
                if n:
6a398064dd55 Working HorizontalLineCharts3D
rgbecker
parents: 2054
diff changeset
   496
                    x0, y0 = row[0]
3721
0c93dd8ff567 initial changes from 2to3-3.3
rptlab
parents: 3627
diff changeset
   497
                    for colNo in range(1,n):
2068
6a398064dd55 Working HorizontalLineCharts3D
rgbecker
parents: 2054
diff changeset
   498
                        x1, y1 = row[colNo]
6a398064dd55 Working HorizontalLineCharts3D
rgbecker
parents: 2054
diff changeset
   499
                        _make_3d_line_info( F, x0, x1, y0, y1, z0, z1,
6a398064dd55 Working HorizontalLineCharts3D
rgbecker
parents: 2054
diff changeset
   500
                                theta_x, theta_y,
2152
212b90cdb3c4 Fixes to 3D lines
rgbecker
parents: 2151
diff changeset
   501
                                rowColor, fillColorShaded=None, tileWidth=tileWidth,
2068
6a398064dd55 Working HorizontalLineCharts3D
rgbecker
parents: 2054
diff changeset
   502
                                strokeColor=None, strokeWidth=None, strokeDashArray=None,
6a398064dd55 Working HorizontalLineCharts3D
rgbecker
parents: 2054
diff changeset
   503
                                shading=0.1)
6a398064dd55 Working HorizontalLineCharts3D
rgbecker
parents: 2054
diff changeset
   504
                        x0, y0 = x1, y1
6a398064dd55 Working HorizontalLineCharts3D
rgbecker
parents: 2054
diff changeset
   505
6a398064dd55 Working HorizontalLineCharts3D
rgbecker
parents: 2054
diff changeset
   506
            if hasattr(self.lines[styleIdx], 'symbol'):
6a398064dd55 Working HorizontalLineCharts3D
rgbecker
parents: 2054
diff changeset
   507
                uSymbol = self.lines[styleIdx].symbol
6a398064dd55 Working HorizontalLineCharts3D
rgbecker
parents: 2054
diff changeset
   508
            elif hasattr(self.lines, 'symbol'):
6a398064dd55 Working HorizontalLineCharts3D
rgbecker
parents: 2054
diff changeset
   509
                uSymbol = self.lines.symbol
6a398064dd55 Working HorizontalLineCharts3D
rgbecker
parents: 2054
diff changeset
   510
            else:
6a398064dd55 Working HorizontalLineCharts3D
rgbecker
parents: 2054
diff changeset
   511
                uSymbol = None
6a398064dd55 Working HorizontalLineCharts3D
rgbecker
parents: 2054
diff changeset
   512
6a398064dd55 Working HorizontalLineCharts3D
rgbecker
parents: 2054
diff changeset
   513
            if uSymbol:
3721
0c93dd8ff567 initial changes from 2to3-3.3
rptlab
parents: 3627
diff changeset
   514
                for colNo in range(n):
2068
6a398064dd55 Working HorizontalLineCharts3D
rgbecker
parents: 2054
diff changeset
   515
                    x1, y1 = row[colNo]
2072
c4356af95fe6 Furniture should be at low z
rgbecker
parents: 2071
diff changeset
   516
                    x1, y1 = _zadjust(x1,y1,z0)
2070
fb34cff995ab Minor adjustmenst and added LinePlot3D
rgbecker
parents: 2069
diff changeset
   517
                    symbol = uSymbol2Symbol(uSymbol,x1,y1,rowColor)
2072
c4356af95fe6 Furniture should be at low z
rgbecker
parents: 2071
diff changeset
   518
                    if symbol: F.add((2,z0,z0,x1,y1,symbol))
2068
6a398064dd55 Working HorizontalLineCharts3D
rgbecker
parents: 2054
diff changeset
   519
6a398064dd55 Working HorizontalLineCharts3D
rgbecker
parents: 2054
diff changeset
   520
            # Draw item labels.
3721
0c93dd8ff567 initial changes from 2to3-3.3
rptlab
parents: 3627
diff changeset
   521
            for colNo in range(n):
2068
6a398064dd55 Working HorizontalLineCharts3D
rgbecker
parents: 2054
diff changeset
   522
                x1, y1 = row[colNo]
2072
c4356af95fe6 Furniture should be at low z
rgbecker
parents: 2071
diff changeset
   523
                x1, y1 = _zadjust(x1,y1,z0)
2068
6a398064dd55 Working HorizontalLineCharts3D
rgbecker
parents: 2054
diff changeset
   524
                L = self._innerDrawLabel(rowNo, colNo, x1, y1)
2072
c4356af95fe6 Furniture should be at low z
rgbecker
parents: 2071
diff changeset
   525
                if L: F.add((2,z0,z0,x1,y1,L))
2068
6a398064dd55 Working HorizontalLineCharts3D
rgbecker
parents: 2054
diff changeset
   526
6a398064dd55 Working HorizontalLineCharts3D
rgbecker
parents: 2054
diff changeset
   527
        F.sort()
6a398064dd55 Working HorizontalLineCharts3D
rgbecker
parents: 2054
diff changeset
   528
        g = Group()
3328
4d7f836cd947 reportlab: fix 2to3 warnings
rgbecker
parents: 3326
diff changeset
   529
        for v in F.value(): g.add(v[-1])
2068
6a398064dd55 Working HorizontalLineCharts3D
rgbecker
parents: 2054
diff changeset
   530
        return g
737
8f0e58918da9 Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff changeset
   531
838
74df7db022e1 Aplitted draw method.
dinu_gherman
parents: 817
diff changeset
   532
class VerticalLineChart(LineChart):
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   533
    pass
737
8f0e58918da9 Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff changeset
   534
8f0e58918da9 Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff changeset
   535
8f0e58918da9 Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff changeset
   536
def sample1():
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   537
    drawing = Drawing(400, 200)
737
8f0e58918da9 Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff changeset
   538
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   539
    data = [
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   540
            (13, 5, 20, 22, 37, 45, 19, 4),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   541
            (5, 20, 46, 38, 23, 21, 6, 14)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   542
            ]
1272
3172686c9ee5 Made linecharts use the new markers/flags some of which were improved
rgbecker
parents: 1236
diff changeset
   543
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   544
    lc = HorizontalLineChart()
773
7b1fa8676a0b Added to docstrings and tidied-up a bit.
dinu_gherman
parents: 737
diff changeset
   545
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   546
    lc.x = 50
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   547
    lc.y = 50
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   548
    lc.height = 125
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   549
    lc.width = 300
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   550
    lc.data = data
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   551
    lc.joinedLines = 1
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   552
    lc.lines.symbol = makeMarker('FilledDiamond')
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   553
    lc.lineLabelFormat = '%2.0f'
737
8f0e58918da9 Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff changeset
   554
2856
2225ac76e622 charts: fix unicode labels using _objStr (bug from Sebastian Ware sebastian@urbantalk.se)
rgbecker
parents: 2830
diff changeset
   555
    catNames = 'Jan Feb Mar Apr May Jun Jul Aug'.split(' ')
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   556
    lc.categoryAxis.categoryNames = catNames
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   557
    lc.categoryAxis.labels.boxAnchor = 'n'
838
74df7db022e1 Aplitted draw method.
dinu_gherman
parents: 817
diff changeset
   558
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   559
    lc.valueAxis.valueMin = 0
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   560
    lc.valueAxis.valueMax = 60
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   561
    lc.valueAxis.valueStep = 15
838
74df7db022e1 Aplitted draw method.
dinu_gherman
parents: 817
diff changeset
   562
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   563
    drawing.add(lc)
1272
3172686c9ee5 Made linecharts use the new markers/flags some of which were improved
rgbecker
parents: 1236
diff changeset
   564
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   565
    return drawing
838
74df7db022e1 Aplitted draw method.
dinu_gherman
parents: 817
diff changeset
   566
74df7db022e1 Aplitted draw method.
dinu_gherman
parents: 817
diff changeset
   567
74df7db022e1 Aplitted draw method.
dinu_gherman
parents: 817
diff changeset
   568
class SampleHorizontalLineChart(HorizontalLineChart):
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   569
    "Sample class overwriting one method to draw additional horizontal lines."
1272
3172686c9ee5 Made linecharts use the new markers/flags some of which were improved
rgbecker
parents: 1236
diff changeset
   570
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   571
    def demo(self):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   572
        """Shows basic use of a line chart."""
838
74df7db022e1 Aplitted draw method.
dinu_gherman
parents: 817
diff changeset
   573
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   574
        drawing = Drawing(200, 100)
1272
3172686c9ee5 Made linecharts use the new markers/flags some of which were improved
rgbecker
parents: 1236
diff changeset
   575
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   576
        data = [
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   577
                (13, 5, 20, 22, 37, 45, 19, 4),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   578
                (14, 10, 21, 28, 38, 46, 25, 5)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   579
                ]
838
74df7db022e1 Aplitted draw method.
dinu_gherman
parents: 817
diff changeset
   580
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   581
        lc = SampleHorizontalLineChart()
838
74df7db022e1 Aplitted draw method.
dinu_gherman
parents: 817
diff changeset
   582
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   583
        lc.x = 20
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   584
        lc.y = 10
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   585
        lc.height = 85
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   586
        lc.width = 170
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   587
        lc.data = data
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   588
        lc.strokeColor = colors.white
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   589
        lc.fillColor = colors.HexColor(0xCCCCCC)
838
74df7db022e1 Aplitted draw method.
dinu_gherman
parents: 817
diff changeset
   590
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   591
        drawing.add(lc)
838
74df7db022e1 Aplitted draw method.
dinu_gherman
parents: 817
diff changeset
   592
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   593
        return drawing
838
74df7db022e1 Aplitted draw method.
dinu_gherman
parents: 817
diff changeset
   594
74df7db022e1 Aplitted draw method.
dinu_gherman
parents: 817
diff changeset
   595
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   596
    def makeBackground(self):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   597
        g = Group()
838
74df7db022e1 Aplitted draw method.
dinu_gherman
parents: 817
diff changeset
   598
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   599
        g.add(HorizontalLineChart.makeBackground(self))
838
74df7db022e1 Aplitted draw method.
dinu_gherman
parents: 817
diff changeset
   600
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   601
        valAxis = self.valueAxis
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   602
        valTickPositions = valAxis._tickValues
838
74df7db022e1 Aplitted draw method.
dinu_gherman
parents: 817
diff changeset
   603
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   604
        for y in valTickPositions:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   605
            y = valAxis.scale(y)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   606
            g.add(Line(self.x, y, self.x+self.width, y,
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   607
                       strokeColor = self.strokeColor))
1272
3172686c9ee5 Made linecharts use the new markers/flags some of which were improved
rgbecker
parents: 1236
diff changeset
   608
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   609
        return g
838
74df7db022e1 Aplitted draw method.
dinu_gherman
parents: 817
diff changeset
   610
74df7db022e1 Aplitted draw method.
dinu_gherman
parents: 817
diff changeset
   611
74df7db022e1 Aplitted draw method.
dinu_gherman
parents: 817
diff changeset
   612
74df7db022e1 Aplitted draw method.
dinu_gherman
parents: 817
diff changeset
   613
def sample1a():
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   614
    drawing = Drawing(400, 200)
838
74df7db022e1 Aplitted draw method.
dinu_gherman
parents: 817
diff changeset
   615
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   616
    data = [
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   617
            (13, 5, 20, 22, 37, 45, 19, 4),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   618
            (5, 20, 46, 38, 23, 21, 6, 14)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   619
            ]
838
74df7db022e1 Aplitted draw method.
dinu_gherman
parents: 817
diff changeset
   620
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   621
    lc = SampleHorizontalLineChart()
838
74df7db022e1 Aplitted draw method.
dinu_gherman
parents: 817
diff changeset
   622
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   623
    lc.x = 50
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   624
    lc.y = 50
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   625
    lc.height = 125
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   626
    lc.width = 300
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   627
    lc.data = data
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   628
    lc.joinedLines = 1
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   629
    lc.strokeColor = colors.white
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   630
    lc.fillColor = colors.HexColor(0xCCCCCC)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   631
    lc.lines.symbol = makeMarker('FilledDiamond')
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   632
    lc.lineLabelFormat = '%2.0f'
838
74df7db022e1 Aplitted draw method.
dinu_gherman
parents: 817
diff changeset
   633
2856
2225ac76e622 charts: fix unicode labels using _objStr (bug from Sebastian Ware sebastian@urbantalk.se)
rgbecker
parents: 2830
diff changeset
   634
    catNames = 'Jan Feb Mar Apr May Jun Jul Aug'.split(' ')
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   635
    lc.categoryAxis.categoryNames = catNames
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   636
    lc.categoryAxis.labels.boxAnchor = 'n'
737
8f0e58918da9 Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff changeset
   637
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   638
    lc.valueAxis.valueMin = 0
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   639
    lc.valueAxis.valueMax = 60
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   640
    lc.valueAxis.valueStep = 15
737
8f0e58918da9 Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff changeset
   641
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   642
    drawing.add(lc)
1272
3172686c9ee5 Made linecharts use the new markers/flags some of which were improved
rgbecker
parents: 1236
diff changeset
   643
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   644
    return drawing
737
8f0e58918da9 Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff changeset
   645
8f0e58918da9 Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff changeset
   646
8f0e58918da9 Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff changeset
   647
def sample2():
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   648
    drawing = Drawing(400, 200)
737
8f0e58918da9 Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff changeset
   649
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   650
    data = [
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   651
            (13, 5, 20, 22, 37, 45, 19, 4),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   652
            (5, 20, 46, 38, 23, 21, 6, 14)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   653
            ]
1272
3172686c9ee5 Made linecharts use the new markers/flags some of which were improved
rgbecker
parents: 1236
diff changeset
   654
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   655
    lc = HorizontalLineChart()
773
7b1fa8676a0b Added to docstrings and tidied-up a bit.
dinu_gherman
parents: 737
diff changeset
   656
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   657
    lc.x = 50
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   658
    lc.y = 50
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   659
    lc.height = 125
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   660
    lc.width = 300
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   661
    lc.data = data
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   662
    lc.joinedLines = 1
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   663
    lc.lines.symbol = makeMarker('Smiley')
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   664
    lc.lineLabelFormat = '%2.0f'
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   665
    lc.strokeColor = colors.black
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   666
    lc.fillColor = colors.lightblue
737
8f0e58918da9 Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff changeset
   667
2856
2225ac76e622 charts: fix unicode labels using _objStr (bug from Sebastian Ware sebastian@urbantalk.se)
rgbecker
parents: 2830
diff changeset
   668
    catNames = 'Jan Feb Mar Apr May Jun Jul Aug'.split(' ')
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   669
    lc.categoryAxis.categoryNames = catNames
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   670
    lc.categoryAxis.labels.boxAnchor = 'n'
737
8f0e58918da9 Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff changeset
   671
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   672
    lc.valueAxis.valueMin = 0
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   673
    lc.valueAxis.valueMax = 60
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   674
    lc.valueAxis.valueStep = 15
737
8f0e58918da9 Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff changeset
   675
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   676
    drawing.add(lc)
1272
3172686c9ee5 Made linecharts use the new markers/flags some of which were improved
rgbecker
parents: 1236
diff changeset
   677
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   678
    return drawing
838
74df7db022e1 Aplitted draw method.
dinu_gherman
parents: 817
diff changeset
   679
74df7db022e1 Aplitted draw method.
dinu_gherman
parents: 817
diff changeset
   680
74df7db022e1 Aplitted draw method.
dinu_gherman
parents: 817
diff changeset
   681
def sample3():
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   682
    drawing = Drawing(400, 200)
838
74df7db022e1 Aplitted draw method.
dinu_gherman
parents: 817
diff changeset
   683
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   684
    data = [
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   685
            (13, 5, 20, 22, 37, 45, 19, 4),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   686
            (5, 20, 46, 38, 23, 21, 6, 14)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   687
            ]
1272
3172686c9ee5 Made linecharts use the new markers/flags some of which were improved
rgbecker
parents: 1236
diff changeset
   688
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   689
    lc = HorizontalLineChart()
838
74df7db022e1 Aplitted draw method.
dinu_gherman
parents: 817
diff changeset
   690
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   691
    lc.x = 50
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   692
    lc.y = 50
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   693
    lc.height = 125
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   694
    lc.width = 300
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   695
    lc.data = data
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   696
    lc.joinedLines = 1
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   697
    lc.lineLabelFormat = '%2.0f'
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   698
    lc.strokeColor = colors.black
838
74df7db022e1 Aplitted draw method.
dinu_gherman
parents: 817
diff changeset
   699
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   700
    lc.lines[0].symbol = makeMarker('Smiley')
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   701
    lc.lines[1].symbol = NoEntry
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   702
    lc.lines[0].strokeWidth = 2
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   703
    lc.lines[1].strokeWidth = 4
917
a4aea7356094 Switched to using typed collection styles.
dinu_gherman
parents: 909
diff changeset
   704
2856
2225ac76e622 charts: fix unicode labels using _objStr (bug from Sebastian Ware sebastian@urbantalk.se)
rgbecker
parents: 2830
diff changeset
   705
    catNames = 'Jan Feb Mar Apr May Jun Jul Aug'.split(' ')
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   706
    lc.categoryAxis.categoryNames = catNames
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   707
    lc.categoryAxis.labels.boxAnchor = 'n'
838
74df7db022e1 Aplitted draw method.
dinu_gherman
parents: 817
diff changeset
   708
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   709
    lc.valueAxis.valueMin = 0
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   710
    lc.valueAxis.valueMax = 60
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   711
    lc.valueAxis.valueStep = 15
838
74df7db022e1 Aplitted draw method.
dinu_gherman
parents: 817
diff changeset
   712
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1573
diff changeset
   713
    drawing.add(lc)
1272
3172686c9ee5 Made linecharts use the new markers/flags some of which were improved
rgbecker
parents: 1236
diff changeset
   714
1692
dc56f53c8322 Added areas.PlotArea for chart plot areas
rgbecker
parents: 1683
diff changeset
   715
    return drawing