src/reportlab/graphics/charts/lineplots.py
author robin <robin@reportlab.com>
Tue, 07 Mar 2017 10:00:34 +0000
changeset 4330 617ffa6bbdc8
parent 4275 54ce6704aa97
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: 4275
diff changeset
     1
#Copyright ReportLab Europe Ltd. 2000-2017
817
8c3a399effda License text changes
rgbecker
parents: 737
diff changeset
     2
#see license.txt for license details
2332
2a7ab4405e18 Remove $Header:, fix CopyRight & history
rgbecker
parents: 2306
diff changeset
     3
#history http://www.reportlab.co.uk/cgi-bin/viewcvs.cgi/public/reportlab/trunk/reportlab/graphics/charts/lineplots.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: 4236
diff changeset
     5
__version__='3.3.0'
3032
22224b1b4d24 New docstrings mainly for module titles
damian
parents: 2964
diff changeset
     6
__doc__="""This module defines a very preliminary Line Plot example."""
737
8f0e58918da9 Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff changeset
     7
8f0e58918da9 Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff changeset
     8
import string, time
8f0e58918da9 Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff changeset
     9
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1677
diff changeset
    10
from reportlab.lib import colors
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1677
diff changeset
    11
from reportlab.lib.validators import *
948
2531b35adf85 New AttrMap emplacement
rgbecker
parents: 942
diff changeset
    12
from reportlab.lib.attrmap import *
1934
104a813e8402 Attempt at getting SplitLinePlot & allow for inFill
rgbecker
parents: 1803
diff changeset
    13
from reportlab.graphics.shapes import Drawing, Group, Rect, Line, PolyLine, Polygon, _SetKeyWordArgs
920
254852733833 Switched to using PropHolder superclass for LinePlotProperties.
dinu_gherman
parents: 915
diff changeset
    14
from reportlab.graphics.widgetbase import Widget, TypedPropertyCollection, PropHolder
737
8f0e58918da9 Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff changeset
    15
from reportlab.graphics.charts.textlabels import Label
1616
fcd8fe41df7e Added GridLinePlot
rgbecker
parents: 1573
diff changeset
    16
from reportlab.graphics.charts.axes import XValueAxis, YValueAxis, AdjYValueAxis, NormalDateXValueAxis
827
be88a17f65ca Moved utility functions into new module utils.py.
dinu_gherman
parents: 817
diff changeset
    17
from reportlab.graphics.charts.utils import *
1278
ac6d47b25759 Move to new markers
rgbecker
parents: 1234
diff changeset
    18
from reportlab.graphics.widgets.markers import uSymbol2Symbol, isSymbol, makeMarker
2361
c64b69975f8f lineplots.py: added filler handling
rgbecker
parents: 2332
diff changeset
    19
from reportlab.graphics.widgets.grids import Grid, DoubleGrid, ShadedRect, ShadedPolygon
1628
b9328908d6e6 Added ScatterPlot
rgbecker
parents: 1616
diff changeset
    20
from reportlab.pdfbase.pdfmetrics import stringWidth, getFont
1692
dc56f53c8322 Added areas.PlotArea for chart plot areas
rgbecker
parents: 1683
diff changeset
    21
from reportlab.graphics.charts.areas import PlotArea
737
8f0e58918da9 Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff changeset
    22
889
abb621a39a36 Changed defaultColors to defaultStyles.
dinu_gherman
parents: 842
diff changeset
    23
# This might be moved again from here...
920
254852733833 Switched to using PropHolder superclass for LinePlotProperties.
dinu_gherman
parents: 915
diff changeset
    24
class LinePlotProperties(PropHolder):
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
    25
    _attrMap = AttrMap(
1797
468918442f54 Started adding Shader
rgbecker
parents: 1692
diff changeset
    26
        strokeWidth = AttrMapValue(isNumber, desc='Width of a line.'),
2144
7122e953ee36 Add dasharray to allowed attributes for linechart lines
rgbecker
parents: 2099
diff changeset
    27
        strokeColor = AttrMapValue(isColorOrNone, desc='Color of a line.'),
7122e953ee36 Add dasharray to allowed attributes for linechart lines
rgbecker
parents: 2099
diff changeset
    28
        strokeDashArray = AttrMapValue(isListOfNumbersOrNone, desc='Dash array of a line.'),
3271
c14b161b62bf attributes help messages
meitham
parents: 3248
diff changeset
    29
        symbol = AttrMapValue(None, desc='Widget placed at data points.',advancedUsage=1),
c14b161b62bf attributes help messages
meitham
parents: 3248
diff changeset
    30
        shader = AttrMapValue(None, desc='Shader Class.',advancedUsage=1),
c14b161b62bf attributes help messages
meitham
parents: 3248
diff changeset
    31
        filler = AttrMapValue(None, desc='Filler Class.',advancedUsage=1),
2426
fac927fa6f7c Auto Legends
rgbecker
parents: 2419
diff changeset
    32
        name = AttrMapValue(isStringOrNone, desc='Name of the line.'),
3271
c14b161b62bf attributes help messages
meitham
parents: 3248
diff changeset
    33
        inFill = AttrMapValue(isBoolean, desc='If true flood fill to x axis',advancedUsage=1),
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
    34
        )
889
abb621a39a36 Changed defaultColors to defaultStyles.
dinu_gherman
parents: 842
diff changeset
    35
4169
bffa5d27d3b4 lineplots.py: added InFillValue to allow varying baseline for fill
robin
parents: 3975
diff changeset
    36
class InFillValue(int):
bffa5d27d3b4 lineplots.py: added InFillValue to allow varying baseline for fill
robin
parents: 3975
diff changeset
    37
    def __new__(cls,v,yValue=None):
bffa5d27d3b4 lineplots.py: added InFillValue to allow varying baseline for fill
robin
parents: 3975
diff changeset
    38
        self = int.__new__(cls,v)
bffa5d27d3b4 lineplots.py: added InFillValue to allow varying baseline for fill
robin
parents: 3975
diff changeset
    39
        self.yValue = yValue
bffa5d27d3b4 lineplots.py: added InFillValue to allow varying baseline for fill
robin
parents: 3975
diff changeset
    40
        return self
bffa5d27d3b4 lineplots.py: added InFillValue to allow varying baseline for fill
robin
parents: 3975
diff changeset
    41
1797
468918442f54 Started adding Shader
rgbecker
parents: 1692
diff changeset
    42
class Shader(_SetKeyWordArgs):
468918442f54 Started adding Shader
rgbecker
parents: 1692
diff changeset
    43
    _attrMap = AttrMap(BASE=PlotArea,
468918442f54 Started adding Shader
rgbecker
parents: 1692
diff changeset
    44
        vertical = AttrMapValue(isBoolean, desc='If true shade to x axis'),
468918442f54 Started adding Shader
rgbecker
parents: 1692
diff changeset
    45
        colors = AttrMapValue(SequenceOf(isColorOrNone,lo=2,hi=2), desc='(AxisColor, LineColor)'),
468918442f54 Started adding Shader
rgbecker
parents: 1692
diff changeset
    46
        )
468918442f54 Started adding Shader
rgbecker
parents: 1692
diff changeset
    47
468918442f54 Started adding Shader
rgbecker
parents: 1692
diff changeset
    48
    def shade(self, lp, g, rowNo, rowColor, row):
468918442f54 Started adding Shader
rgbecker
parents: 1692
diff changeset
    49
        c = [None,None]
468918442f54 Started adding Shader
rgbecker
parents: 1692
diff changeset
    50
        c = getattr(self,'colors',c) or c
468918442f54 Started adding Shader
rgbecker
parents: 1692
diff changeset
    51
        if not c[0]: c[0] = getattr(lp,'fillColor',colors.white)
468918442f54 Started adding Shader
rgbecker
parents: 1692
diff changeset
    52
        if not c[1]: c[1] = rowColor
889
abb621a39a36 Changed defaultColors to defaultStyles.
dinu_gherman
parents: 842
diff changeset
    53
2419
30033c8145c3 lineplots.py: allow filled/unfilled plotting
rgbecker
parents: 2361
diff changeset
    54
class NoFiller:
30033c8145c3 lineplots.py: allow filled/unfilled plotting
rgbecker
parents: 2361
diff changeset
    55
    def fill(self, lp, g, rowNo, rowColor, points):
30033c8145c3 lineplots.py: allow filled/unfilled plotting
rgbecker
parents: 2361
diff changeset
    56
        pass
30033c8145c3 lineplots.py: allow filled/unfilled plotting
rgbecker
parents: 2361
diff changeset
    57
2361
c64b69975f8f lineplots.py: added filler handling
rgbecker
parents: 2332
diff changeset
    58
class Filler:
c64b69975f8f lineplots.py: added filler handling
rgbecker
parents: 2332
diff changeset
    59
    '''mixin providing simple polygon fill'''
2419
30033c8145c3 lineplots.py: allow filled/unfilled plotting
rgbecker
parents: 2361
diff changeset
    60
    _attrMap = AttrMap(
30033c8145c3 lineplots.py: allow filled/unfilled plotting
rgbecker
parents: 2361
diff changeset
    61
        fillColor = AttrMapValue(isColorOrNone, desc='filler interior color'),
30033c8145c3 lineplots.py: allow filled/unfilled plotting
rgbecker
parents: 2361
diff changeset
    62
        strokeColor = AttrMapValue(isColorOrNone, desc='filler edge color'),
30033c8145c3 lineplots.py: allow filled/unfilled plotting
rgbecker
parents: 2361
diff changeset
    63
        strokeWidth = AttrMapValue(isNumberOrNone, desc='filler edge width'),
30033c8145c3 lineplots.py: allow filled/unfilled plotting
rgbecker
parents: 2361
diff changeset
    64
        )
30033c8145c3 lineplots.py: allow filled/unfilled plotting
rgbecker
parents: 2361
diff changeset
    65
    def __init__(self,**kw):
30033c8145c3 lineplots.py: allow filled/unfilled plotting
rgbecker
parents: 2361
diff changeset
    66
        self.__dict__ = kw
30033c8145c3 lineplots.py: allow filled/unfilled plotting
rgbecker
parents: 2361
diff changeset
    67
2361
c64b69975f8f lineplots.py: added filler handling
rgbecker
parents: 2332
diff changeset
    68
    def fill(self, lp, g, rowNo, rowColor, points):
2419
30033c8145c3 lineplots.py: allow filled/unfilled plotting
rgbecker
parents: 2361
diff changeset
    69
        g.add(Polygon(points,
30033c8145c3 lineplots.py: allow filled/unfilled plotting
rgbecker
parents: 2361
diff changeset
    70
            fillColor=getattr(self,'fillColor',rowColor),
30033c8145c3 lineplots.py: allow filled/unfilled plotting
rgbecker
parents: 2361
diff changeset
    71
            strokeColor=getattr(self,'strokeColor',rowColor),
30033c8145c3 lineplots.py: allow filled/unfilled plotting
rgbecker
parents: 2361
diff changeset
    72
            strokeWidth=getattr(self,'strokeWidth',0.1)))
2361
c64b69975f8f lineplots.py: added filler handling
rgbecker
parents: 2332
diff changeset
    73
c64b69975f8f lineplots.py: added filler handling
rgbecker
parents: 2332
diff changeset
    74
class ShadedPolyFiller(Filler,ShadedPolygon):
c64b69975f8f lineplots.py: added filler handling
rgbecker
parents: 2332
diff changeset
    75
    pass
c64b69975f8f lineplots.py: added filler handling
rgbecker
parents: 2332
diff changeset
    76
c64b69975f8f lineplots.py: added filler handling
rgbecker
parents: 2332
diff changeset
    77
class PolyFiller(Filler,Polygon):
c64b69975f8f lineplots.py: added filler handling
rgbecker
parents: 2332
diff changeset
    78
    pass
c64b69975f8f lineplots.py: added filler handling
rgbecker
parents: 2332
diff changeset
    79
3975
4a3599863c11 eliminate from . imports in favour of absolutes to allow running modules
robin
parents: 3800
diff changeset
    80
from reportlab.graphics.charts.linecharts import AbstractLineChart
2427
1de04210b407 charts: autolegending in place, legend now has boxAnchor
rgbecker
parents: 2426
diff changeset
    81
class LinePlot(AbstractLineChart):
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
    82
    """Line plot with multiple lines.
737
8f0e58918da9 Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff changeset
    83
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
    84
    Both x- and y-axis are value axis (so there are no seperate
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
    85
    X and Y versions of this class).
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
    86
    """
1692
dc56f53c8322 Added areas.PlotArea for chart plot areas
rgbecker
parents: 1683
diff changeset
    87
    _attrMap = AttrMap(BASE=PlotArea,
3271
c14b161b62bf attributes help messages
meitham
parents: 3248
diff changeset
    88
        reversePlotOrder = AttrMapValue(isBoolean, desc='If true reverse plot order.',advancedUsage=1),
c14b161b62bf attributes help messages
meitham
parents: 3248
diff changeset
    89
        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
    90
        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
    91
        lineLabelFormat = AttrMapValue(None, desc='Formatting string or function used for data point labels.'),
2018
6ffd97616aab Fixes to lineLabelArray detection
rgbecker
parents: 2006
diff changeset
    92
        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
    93
        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
    94
        strokeColor = AttrMapValue(isColorOrNone, desc='Color used for background border of plot area.'),
dc56f53c8322 Added areas.PlotArea for chart plot areas
rgbecker
parents: 1683
diff changeset
    95
        fillColor = AttrMapValue(isColorOrNone, desc='Color used for background interior of plot area.'),
dc56f53c8322 Added areas.PlotArea for chart plot areas
rgbecker
parents: 1683
diff changeset
    96
        lines = AttrMapValue(None, desc='Handle of the lines.'),
dc56f53c8322 Added areas.PlotArea for chart plot areas
rgbecker
parents: 1683
diff changeset
    97
        xValueAxis = AttrMapValue(None, desc='Handle of the x axis.'),
dc56f53c8322 Added areas.PlotArea for chart plot areas
rgbecker
parents: 1683
diff changeset
    98
        yValueAxis = AttrMapValue(None, desc='Handle of the y axis.'),
dc56f53c8322 Added areas.PlotArea for chart plot areas
rgbecker
parents: 1683
diff changeset
    99
        data = AttrMapValue(None, desc='Data to be plotted, list of (lists of) x/y tuples.'),
3271
c14b161b62bf attributes help messages
meitham
parents: 3248
diff changeset
   100
        annotations = AttrMapValue(None, desc='list of callables, will be called with self, xscale, yscale.',advancedUsage=1),
c14b161b62bf attributes help messages
meitham
parents: 3248
diff changeset
   101
        behindAxes = AttrMapValue(isBoolean, desc='If true use separate line group.',advancedUsage=1),
c14b161b62bf attributes help messages
meitham
parents: 3248
diff changeset
   102
        gridFirst = AttrMapValue(isBoolean, desc='If true use draw grids before axes.',advancedUsage=1),
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   103
        )
737
8f0e58918da9 Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff changeset
   104
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   105
    def __init__(self):
1692
dc56f53c8322 Added areas.PlotArea for chart plot areas
rgbecker
parents: 1683
diff changeset
   106
        PlotArea.__init__(self)
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   107
        self.reversePlotOrder = 0
737
8f0e58918da9 Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff changeset
   108
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   109
        self.xValueAxis = XValueAxis()
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   110
        self.yValueAxis = YValueAxis()
737
8f0e58918da9 Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff changeset
   111
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   112
        # 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: 1628
diff changeset
   113
        self.data = [
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   114
            ((1,1), (2,2), (2.5,1), (3,3), (4,5)),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   115
            ((1,2), (2,3), (2.5,2), (3,4), (4,6))
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   116
            ]
737
8f0e58918da9 Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff changeset
   117
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   118
        self.lines = TypedPropertyCollection(LinePlotProperties)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   119
        self.lines.strokeWidth = 1
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   120
        self.lines[0].strokeColor = colors.red
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   121
        self.lines[1].strokeColor = colors.blue
1628
b9328908d6e6 Added ScatterPlot
rgbecker
parents: 1616
diff changeset
   122
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   123
        self.lineLabels = TypedPropertyCollection(Label)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   124
        self.lineLabelFormat = None
2018
6ffd97616aab Fixes to lineLabelArray detection
rgbecker
parents: 2006
diff changeset
   125
        self.lineLabelArray = None
889
abb621a39a36 Changed defaultColors to defaultStyles.
dinu_gherman
parents: 842
diff changeset
   126
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   127
        # this says whether the origin is inside or outside
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   128
        # the bar - +10 means put the origin ten points
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   129
        # above the tip of the bar if value > 0, or ten
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   130
        # points inside if bar value < 0.  This is different
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   131
        # 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: 1628
diff changeset
   132
        # sign of the data.
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   133
        self.lineLabelNudge = 10
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   134
        # if you have multiple series, by default they butt
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   135
        # together.
1278
ac6d47b25759 Move to new markers
rgbecker
parents: 1234
diff changeset
   136
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   137
        # New line chart attributes.
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   138
        self.joinedLines = 1 # Connect items with straight lines.
1278
ac6d47b25759 Move to new markers
rgbecker
parents: 1234
diff changeset
   139
1936
9012de7856f5 Adaptations for quickchart
andy_robinson
parents: 1935
diff changeset
   140
        #private attributes
9012de7856f5 Adaptations for quickchart
andy_robinson
parents: 1935
diff changeset
   141
        self._inFill = None
2701
a6547c2502f9 lineplots.py: small change to annotations
rgbecker
parents: 2700
diff changeset
   142
        self.annotations = []
2848
62db2318e9fa charts: more changes to axes and lineplots
rgbecker
parents: 2714
diff changeset
   143
        self.behindAxes = 0
62db2318e9fa charts: more changes to axes and lineplots
rgbecker
parents: 2714
diff changeset
   144
        self.gridFirst = 0
1936
9012de7856f5 Adaptations for quickchart
andy_robinson
parents: 1935
diff changeset
   145
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   146
    def demo(self):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   147
        """Shows basic use of a line chart."""
737
8f0e58918da9 Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff changeset
   148
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   149
        drawing = Drawing(400, 200)
1278
ac6d47b25759 Move to new markers
rgbecker
parents: 1234
diff changeset
   150
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   151
        data = [
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   152
            ((1,1), (2,2), (2.5,1), (3,3), (4,5)),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   153
            ((1,2), (2,3), (2.5,2), (3.5,5), (4,6))
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   154
            ]
1628
b9328908d6e6 Added ScatterPlot
rgbecker
parents: 1616
diff changeset
   155
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   156
        lp = LinePlot()
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: 1628
diff changeset
   158
        lp.x = 50
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   159
        lp.y = 50
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   160
        lp.height = 125
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   161
        lp.width = 300
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   162
        lp.data = data
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   163
        lp.joinedLines = 1
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   164
        lp.lineLabelFormat = '%2.0f'
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   165
        lp.strokeColor = colors.black
839
0782188b7a4c Splitted draw() method.
dinu_gherman
parents: 828
diff changeset
   166
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   167
        lp.lines[0].strokeColor = colors.red
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   168
        lp.lines[0].symbol = makeMarker('FilledCircle')
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   169
        lp.lines[1].strokeColor = colors.blue
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   170
        lp.lines[1].symbol = makeMarker('FilledDiamond')
1278
ac6d47b25759 Move to new markers
rgbecker
parents: 1234
diff changeset
   171
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   172
        lp.xValueAxis.valueMin = 0
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   173
        lp.xValueAxis.valueMax = 5
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   174
        lp.xValueAxis.valueStep = 1
839
0782188b7a4c Splitted draw() method.
dinu_gherman
parents: 828
diff changeset
   175
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   176
        lp.yValueAxis.valueMin = 0
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   177
        lp.yValueAxis.valueMax = 7
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   178
        lp.yValueAxis.valueStep = 1
1628
b9328908d6e6 Added ScatterPlot
rgbecker
parents: 1616
diff changeset
   179
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   180
        drawing.add(lp)
1278
ac6d47b25759 Move to new markers
rgbecker
parents: 1234
diff changeset
   181
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   182
        return drawing
1278
ac6d47b25759 Move to new markers
rgbecker
parents: 1234
diff changeset
   183
839
0782188b7a4c Splitted draw() method.
dinu_gherman
parents: 828
diff changeset
   184
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   185
    def calcPositions(self):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   186
        """Works out where they go.
1278
ac6d47b25759 Move to new markers
rgbecker
parents: 1234
diff changeset
   187
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   188
        Sets an attribute _positions which is a list of
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   189
        lists of (x, y) matching the data.
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   190
        """
915
a9dd06401ef3 Removed dead code.
dinu_gherman
parents: 913
diff changeset
   191
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   192
        self._seriesCount = len(self.data)
3721
0c93dd8ff567 initial changes from 2to3-3.3
rptlab
parents: 3652
diff changeset
   193
        self._rowLength = max(list(map(len,self.data)))
1628
b9328908d6e6 Added ScatterPlot
rgbecker
parents: 1616
diff changeset
   194
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   195
        self._positions = []
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   196
        for rowNo in range(len(self.data)):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   197
            line = []
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   198
            for colNo in range(len(self.data[rowNo])):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   199
                datum = self.data[rowNo][colNo] # x,y value
3800
e8547b00eb59 attempt to remove old type testing
robin
parents: 3721
diff changeset
   200
                if isinstance(datum[0],str):
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   201
                    x = self.xValueAxis.scale(mktime(mkTimeTuple(datum[0])))
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   202
                else:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   203
                    x = self.xValueAxis.scale(datum[0])
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   204
                y = self.yValueAxis.scale(datum[1])
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   205
                line.append((x, y))
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   206
            self._positions.append(line)
737
8f0e58918da9 Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff changeset
   207
2070
fb34cff995ab Minor adjustmenst and added LinePlot3D
rgbecker
parents: 2054
diff changeset
   208
    def _innerDrawLabel(self, rowNo, colNo, x, y):
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   209
        "Draw a label for a given item in the list."
737
8f0e58918da9 Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff changeset
   210
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   211
        labelFmt = self.lineLabelFormat
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   212
        labelValue = self.data[rowNo][colNo][1] ###
839
0782188b7a4c Splitted draw() method.
dinu_gherman
parents: 828
diff changeset
   213
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   214
        if labelFmt is None:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   215
            labelText = None
3800
e8547b00eb59 attempt to remove old type testing
robin
parents: 3721
diff changeset
   216
        elif isinstance(labelFmt,str):
2018
6ffd97616aab Fixes to lineLabelArray detection
rgbecker
parents: 2006
diff changeset
   217
            if labelFmt == 'values':
6ffd97616aab Fixes to lineLabelArray detection
rgbecker
parents: 2006
diff changeset
   218
                labelText = self.lineLabelArray[rowNo][colNo]
6ffd97616aab Fixes to lineLabelArray detection
rgbecker
parents: 2006
diff changeset
   219
            else:
6ffd97616aab Fixes to lineLabelArray detection
rgbecker
parents: 2006
diff changeset
   220
                labelText = labelFmt % labelValue
3326
ce725978d11c Initial Python3 compatibility fixes
damian
parents: 3298
diff changeset
   221
        elif hasattr(labelFmt,'__call__'):
3513
7c77623a9b88 lineplots.py: add features making symbols/ linelabels more usable
rgbecker
parents: 3401
diff changeset
   222
            if not hasattr(labelFmt,'__labelFmtEX__'):
7c77623a9b88 lineplots.py: add features making symbols/ linelabels more usable
rgbecker
parents: 3401
diff changeset
   223
                labelText = labelFmt(labelValue)
7c77623a9b88 lineplots.py: add features making symbols/ linelabels more usable
rgbecker
parents: 3401
diff changeset
   224
            else:
7c77623a9b88 lineplots.py: add features making symbols/ linelabels more usable
rgbecker
parents: 3401
diff changeset
   225
                labelText = labelFmt(self,rowNo,colNo,x,y)
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   226
        else:
3800
e8547b00eb59 attempt to remove old type testing
robin
parents: 3721
diff changeset
   227
            raise ValueError("Unknown formatter type %s, expected string or function"% labelFmt)
839
0782188b7a4c Splitted draw() method.
dinu_gherman
parents: 828
diff changeset
   228
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   229
        if labelText:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   230
            label = self.lineLabels[(rowNo, colNo)]
3248
97d4415ab527 lineplots/linecharts: fix lineLabels.visble and also remove Formatter usage
rgbecker
parents: 3239
diff changeset
   231
            if not label.visible: return
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   232
            #hack to make sure labels are outside the bar
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   233
            if y > 0:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   234
                label.setOrigin(x, y + self.lineLabelNudge)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   235
            else:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   236
                label.setOrigin(x, y - self.lineLabelNudge)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   237
            label.setText(labelText)
2070
fb34cff995ab Minor adjustmenst and added LinePlot3D
rgbecker
parents: 2054
diff changeset
   238
        else:
fb34cff995ab Minor adjustmenst and added LinePlot3D
rgbecker
parents: 2054
diff changeset
   239
            label = None
fb34cff995ab Minor adjustmenst and added LinePlot3D
rgbecker
parents: 2054
diff changeset
   240
        return label
fb34cff995ab Minor adjustmenst and added LinePlot3D
rgbecker
parents: 2054
diff changeset
   241
fb34cff995ab Minor adjustmenst and added LinePlot3D
rgbecker
parents: 2054
diff changeset
   242
    def drawLabel(self, G, rowNo, colNo, x, y):
fb34cff995ab Minor adjustmenst and added LinePlot3D
rgbecker
parents: 2054
diff changeset
   243
        '''Draw a label for a given item in the list.
fb34cff995ab Minor adjustmenst and added LinePlot3D
rgbecker
parents: 2054
diff changeset
   244
        G must have an add method'''
fb34cff995ab Minor adjustmenst and added LinePlot3D
rgbecker
parents: 2054
diff changeset
   245
        G.add(self._innerDrawLabel(rowNo,colNo,x,y))
839
0782188b7a4c Splitted draw() method.
dinu_gherman
parents: 828
diff changeset
   246
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   247
    def makeLines(self):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   248
        g = Group()
4169
bffa5d27d3b4 lineplots.py: added InFillValue to allow varying baseline for fill
robin
parents: 3975
diff changeset
   249
        yA = self.yValueAxis
bffa5d27d3b4 lineplots.py: added InFillValue to allow varying baseline for fill
robin
parents: 3975
diff changeset
   250
        xA = self.xValueAxis
1998
bac8395354d1 Fixup for bubble charts
rgbecker
parents: 1996
diff changeset
   251
        bubblePlot = getattr(self,'_bubblePlot',None)
bac8395354d1 Fixup for bubble charts
rgbecker
parents: 1996
diff changeset
   252
        if bubblePlot:
bac8395354d1 Fixup for bubble charts
rgbecker
parents: 1996
diff changeset
   253
            bubbleR = min(yA._bubbleRadius,xA._bubbleRadius)
bac8395354d1 Fixup for bubble charts
rgbecker
parents: 1996
diff changeset
   254
            bubbleMax = xA._bubbleMax
889
abb621a39a36 Changed defaultColors to defaultStyles.
dinu_gherman
parents: 842
diff changeset
   255
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   256
        labelFmt = self.lineLabelFormat
889
abb621a39a36 Changed defaultColors to defaultStyles.
dinu_gherman
parents: 842
diff changeset
   257
3721
0c93dd8ff567 initial changes from 2to3-3.3
rptlab
parents: 3652
diff changeset
   258
        P = list(range(len(self._positions)))
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   259
        if self.reversePlotOrder: P.reverse()
1934
104a813e8402 Attempt at getting SplitLinePlot & allow for inFill
rgbecker
parents: 1803
diff changeset
   260
        inFill = getattr(self,'_inFill',None)
4236
f5833d6b1ecd improved lineplot marker handling
robin
parents: 4169
diff changeset
   261
        lines = self.lines
f5833d6b1ecd improved lineplot marker handling
robin
parents: 4169
diff changeset
   262
        styleCount = len(lines)
f5833d6b1ecd improved lineplot marker handling
robin
parents: 4169
diff changeset
   263
        if inFill or [rowNo for rowNo in P if getattr(lines[rowNo%styleCount],'inFill',False)]:
4169
bffa5d27d3b4 lineplots.py: added InFillValue to allow varying baseline for fill
robin
parents: 3975
diff changeset
   264
            inFillY = getattr(inFill,'yValue',None)
bffa5d27d3b4 lineplots.py: added InFillValue to allow varying baseline for fill
robin
parents: 3975
diff changeset
   265
            if inFillY is None:
bffa5d27d3b4 lineplots.py: added InFillValue to allow varying baseline for fill
robin
parents: 3975
diff changeset
   266
                inFillY = xA._y
bffa5d27d3b4 lineplots.py: added InFillValue to allow varying baseline for fill
robin
parents: 3975
diff changeset
   267
            else:
bffa5d27d3b4 lineplots.py: added InFillValue to allow varying baseline for fill
robin
parents: 3975
diff changeset
   268
                inFillY = yA.scale(inFillY)
bffa5d27d3b4 lineplots.py: added InFillValue to allow varying baseline for fill
robin
parents: 3975
diff changeset
   269
            inFillX0 = yA._x
bffa5d27d3b4 lineplots.py: added InFillValue to allow varying baseline for fill
robin
parents: 3975
diff changeset
   270
            inFillX1 = inFillX0 + xA._length
1934
104a813e8402 Attempt at getting SplitLinePlot & allow for inFill
rgbecker
parents: 1803
diff changeset
   271
            inFillG = getattr(self,'_inFillG',g)
2848
62db2318e9fa charts: more changes to axes and lineplots
rgbecker
parents: 2714
diff changeset
   272
        lG = getattr(self,'_lineG',g)
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   273
        # Iterate over data rows.
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   274
        for rowNo in P:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   275
            row = self._positions[rowNo]
4236
f5833d6b1ecd improved lineplot marker handling
robin
parents: 4169
diff changeset
   276
            styleRowNo = rowNo % styleCount
f5833d6b1ecd improved lineplot marker handling
robin
parents: 4169
diff changeset
   277
            rowStyle = lines[styleRowNo]
3298
e726372f6a88 robust accesser for strokeColor in ScatterPlot
meitham
parents: 3271
diff changeset
   278
            rowColor = getattr(rowStyle,'strokeColor',None)
1998
bac8395354d1 Fixup for bubble charts
rgbecker
parents: 1996
diff changeset
   279
            dash = getattr(rowStyle, 'strokeDashArray', None)
889
abb621a39a36 Changed defaultColors to defaultStyles.
dinu_gherman
parents: 842
diff changeset
   280
1998
bac8395354d1 Fixup for bubble charts
rgbecker
parents: 1996
diff changeset
   281
            if hasattr(rowStyle, 'strokeWidth'):
bac8395354d1 Fixup for bubble charts
rgbecker
parents: 1996
diff changeset
   282
                width = rowStyle.strokeWidth
4236
f5833d6b1ecd improved lineplot marker handling
robin
parents: 4169
diff changeset
   283
            elif hasattr(lines, 'strokeWidth'):
f5833d6b1ecd improved lineplot marker handling
robin
parents: 4169
diff changeset
   284
                width = lines.strokeWidth
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   285
            else:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   286
                width = None
920
254852733833 Switched to using PropHolder superclass for LinePlotProperties.
dinu_gherman
parents: 915
diff changeset
   287
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   288
            # Iterate over data columns.
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   289
            if self.joinedLines:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   290
                points = []
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   291
                for xy in row:
3367
bce0159f2980 lineplots.py: minor speedup
rgbecker
parents: 3329
diff changeset
   292
                    points += [xy[0], xy[1]]
2698
c9740075f020 graphics: minor fixes and improvements to lineplots
rgbecker
parents: 2690
diff changeset
   293
                if inFill or getattr(rowStyle,'inFill',False):
2516
cdfd0126c655 merge stable 2657:2658 axes/lineplots.py: fix inFill behaviour
rgbecker
parents: 2427
diff changeset
   294
                    fpoints = [inFillX0,inFillY] + points + [inFillX1,inFillY]
2361
c64b69975f8f lineplots.py: added filler handling
rgbecker
parents: 2332
diff changeset
   295
                    filler = getattr(rowStyle, 'filler', None)
c64b69975f8f lineplots.py: added filler handling
rgbecker
parents: 2332
diff changeset
   296
                    if filler:
2419
30033c8145c3 lineplots.py: allow filled/unfilled plotting
rgbecker
parents: 2361
diff changeset
   297
                        filler.fill(self,inFillG,rowNo,rowColor,fpoints)
2361
c64b69975f8f lineplots.py: added filler handling
rgbecker
parents: 2332
diff changeset
   298
                    else:
2516
cdfd0126c655 merge stable 2657:2658 axes/lineplots.py: fix inFill behaviour
rgbecker
parents: 2427
diff changeset
   299
                        inFillG.add(Polygon(fpoints,fillColor=rowColor,strokeColor=rowColor,strokeWidth=width or 0.1))
2426
fac927fa6f7c Auto Legends
rgbecker
parents: 2419
diff changeset
   300
                if inFill in (None,0,2):
1935
56ba8fa8fc1b Cosmetics
rgbecker
parents: 1934
diff changeset
   301
                    line = PolyLine(points,strokeColor=rowColor,strokeLineCap=0,strokeLineJoin=1)
56ba8fa8fc1b Cosmetics
rgbecker
parents: 1934
diff changeset
   302
                    if width:
56ba8fa8fc1b Cosmetics
rgbecker
parents: 1934
diff changeset
   303
                        line.strokeWidth = width
56ba8fa8fc1b Cosmetics
rgbecker
parents: 1934
diff changeset
   304
                    if dash:
56ba8fa8fc1b Cosmetics
rgbecker
parents: 1934
diff changeset
   305
                        line.strokeDashArray = dash
2848
62db2318e9fa charts: more changes to axes and lineplots
rgbecker
parents: 2714
diff changeset
   306
                    lG.add(line)
889
abb621a39a36 Changed defaultColors to defaultStyles.
dinu_gherman
parents: 842
diff changeset
   307
1998
bac8395354d1 Fixup for bubble charts
rgbecker
parents: 1996
diff changeset
   308
            if hasattr(rowStyle, 'symbol'):
bac8395354d1 Fixup for bubble charts
rgbecker
parents: 1996
diff changeset
   309
                uSymbol = rowStyle.symbol
4236
f5833d6b1ecd improved lineplot marker handling
robin
parents: 4169
diff changeset
   310
            elif hasattr(lines, 'symbol'):
f5833d6b1ecd improved lineplot marker handling
robin
parents: 4169
diff changeset
   311
                uSymbol = lines.symbol
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   312
            else:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   313
                uSymbol = None
889
abb621a39a36 Changed defaultColors to defaultStyles.
dinu_gherman
parents: 842
diff changeset
   314
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   315
            if uSymbol:
1998
bac8395354d1 Fixup for bubble charts
rgbecker
parents: 1996
diff changeset
   316
                if bubblePlot: drow = self.data[rowNo]
3513
7c77623a9b88 lineplots.py: add features making symbols/ linelabels more usable
rgbecker
parents: 3401
diff changeset
   317
                for j,xy in enumerate(row):
4275
54ce6704aa97 fixes to TypedPropertyCollection
robin
parents: 4252
diff changeset
   318
                    if (styleRowNo,j) in lines:
4236
f5833d6b1ecd improved lineplot marker handling
robin
parents: 4169
diff changeset
   319
                        juSymbol = getattr(lines[styleRowNo,j],'symbol',uSymbol)
f5833d6b1ecd improved lineplot marker handling
robin
parents: 4169
diff changeset
   320
                    else:
f5833d6b1ecd improved lineplot marker handling
robin
parents: 4169
diff changeset
   321
                        juSymbol = uSymbol
f5833d6b1ecd improved lineplot marker handling
robin
parents: 4169
diff changeset
   322
                    if juSymbol is uSymbol:
f5833d6b1ecd improved lineplot marker handling
robin
parents: 4169
diff changeset
   323
                        symbol = uSymbol
f5833d6b1ecd improved lineplot marker handling
robin
parents: 4169
diff changeset
   324
                        symColor = rowColor
f5833d6b1ecd improved lineplot marker handling
robin
parents: 4169
diff changeset
   325
                    else:
f5833d6b1ecd improved lineplot marker handling
robin
parents: 4169
diff changeset
   326
                        symbol = juSymbol
f5833d6b1ecd improved lineplot marker handling
robin
parents: 4169
diff changeset
   327
                        symColor = getattr(symbol,'fillColor',rowColor)
f5833d6b1ecd improved lineplot marker handling
robin
parents: 4169
diff changeset
   328
                    symbol = uSymbol2Symbol(symbol,xy[0],xy[1],symColor)
3513
7c77623a9b88 lineplots.py: add features making symbols/ linelabels more usable
rgbecker
parents: 3401
diff changeset
   329
                    if symbol:
7c77623a9b88 lineplots.py: add features making symbols/ linelabels more usable
rgbecker
parents: 3401
diff changeset
   330
                        if bubblePlot:
7c77623a9b88 lineplots.py: add features making symbols/ linelabels more usable
rgbecker
parents: 3401
diff changeset
   331
                            symbol.size = bubbleR*(drow[j][2]/bubbleMax)**0.5
7c77623a9b88 lineplots.py: add features making symbols/ linelabels more usable
rgbecker
parents: 3401
diff changeset
   332
                        g.add(symbol)
7c77623a9b88 lineplots.py: add features making symbols/ linelabels more usable
rgbecker
parents: 3401
diff changeset
   333
            else:
7c77623a9b88 lineplots.py: add features making symbols/ linelabels more usable
rgbecker
parents: 3401
diff changeset
   334
                if bubblePlot: drow = self.data[rowNo]
7c77623a9b88 lineplots.py: add features making symbols/ linelabels more usable
rgbecker
parents: 3401
diff changeset
   335
                for j,xy in enumerate(row):
4236
f5833d6b1ecd improved lineplot marker handling
robin
parents: 4169
diff changeset
   336
                    juSymbol = getattr(lines[styleRowNo,j],'symbol',None)
f5833d6b1ecd improved lineplot marker handling
robin
parents: 4169
diff changeset
   337
                    if not juSymbol: continue
f5833d6b1ecd improved lineplot marker handling
robin
parents: 4169
diff changeset
   338
                    symColor = getattr(juSymbol,'fillColor',getattr(juSymbol,'strokeColor',rowColor))
f5833d6b1ecd improved lineplot marker handling
robin
parents: 4169
diff changeset
   339
                    symbol = uSymbol2Symbol(juSymbol,xy[0],xy[1],symColor)
1998
bac8395354d1 Fixup for bubble charts
rgbecker
parents: 1996
diff changeset
   340
                    if symbol:
bac8395354d1 Fixup for bubble charts
rgbecker
parents: 1996
diff changeset
   341
                        if bubblePlot:
bac8395354d1 Fixup for bubble charts
rgbecker
parents: 1996
diff changeset
   342
                            symbol.size = bubbleR*(drow[j][2]/bubbleMax)**0.5
bac8395354d1 Fixup for bubble charts
rgbecker
parents: 1996
diff changeset
   343
                        g.add(symbol)
1628
b9328908d6e6 Added ScatterPlot
rgbecker
parents: 1616
diff changeset
   344
1998
bac8395354d1 Fixup for bubble charts
rgbecker
parents: 1996
diff changeset
   345
            # Draw data labels.
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   346
            for colNo in range(len(row)):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   347
                x1, y1 = row[colNo]
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   348
                self.drawLabel(g, rowNo, colNo, x1, y1)
1278
ac6d47b25759 Move to new markers
rgbecker
parents: 1234
diff changeset
   349
1998
bac8395354d1 Fixup for bubble charts
rgbecker
parents: 1996
diff changeset
   350
            shader = getattr(rowStyle, 'shader', None)
1797
468918442f54 Started adding Shader
rgbecker
parents: 1692
diff changeset
   351
            if shader: shader.shade(self,g,rowNo,rowColor,row)
468918442f54 Started adding Shader
rgbecker
parents: 1692
diff changeset
   352
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   353
        return g
889
abb621a39a36 Changed defaultColors to defaultStyles.
dinu_gherman
parents: 842
diff changeset
   354
1934
104a813e8402 Attempt at getting SplitLinePlot & allow for inFill
rgbecker
parents: 1803
diff changeset
   355
    def draw(self):
104a813e8402 Attempt at getting SplitLinePlot & allow for inFill
rgbecker
parents: 1803
diff changeset
   356
        yA = self.yValueAxis
104a813e8402 Attempt at getting SplitLinePlot & allow for inFill
rgbecker
parents: 1803
diff changeset
   357
        xA = self.xValueAxis
1998
bac8395354d1 Fixup for bubble charts
rgbecker
parents: 1996
diff changeset
   358
        if getattr(self,'_bubblePlot',None):
bac8395354d1 Fixup for bubble charts
rgbecker
parents: 1996
diff changeset
   359
            yA._bubblePlot = xA._bubblePlot = 1
1934
104a813e8402 Attempt at getting SplitLinePlot & allow for inFill
rgbecker
parents: 1803
diff changeset
   360
        yA.setPosition(self.x, self.y, self.height)
2099
4d92af695e43 JoinAxis fix - similar to one in lineCharts
johnprecedo
parents: 2079
diff changeset
   361
        if yA: yA.joinAxis = xA
4d92af695e43 JoinAxis fix - similar to one in lineCharts
johnprecedo
parents: 2079
diff changeset
   362
        if xA: xA.joinAxis = yA
1934
104a813e8402 Attempt at getting SplitLinePlot & allow for inFill
rgbecker
parents: 1803
diff changeset
   363
        yA.configure(self.data)
889
abb621a39a36 Changed defaultColors to defaultStyles.
dinu_gherman
parents: 842
diff changeset
   364
1934
104a813e8402 Attempt at getting SplitLinePlot & allow for inFill
rgbecker
parents: 1803
diff changeset
   365
        # if zero is in chart, put x axis there, otherwise use bottom.
104a813e8402 Attempt at getting SplitLinePlot & allow for inFill
rgbecker
parents: 1803
diff changeset
   366
        xAxisCrossesAt = yA.scale(0)
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   367
        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: 1628
diff changeset
   368
            y = self.y
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   369
        else:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   370
            y = xAxisCrossesAt
737
8f0e58918da9 Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff changeset
   371
1934
104a813e8402 Attempt at getting SplitLinePlot & allow for inFill
rgbecker
parents: 1803
diff changeset
   372
        xA.setPosition(self.x, y, self.width)
104a813e8402 Attempt at getting SplitLinePlot & allow for inFill
rgbecker
parents: 1803
diff changeset
   373
        xA.configure(self.data)
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   374
        self.calcPositions()
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   375
        g = Group()
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   376
        g.add(self.makeBackground())
2848
62db2318e9fa charts: more changes to axes and lineplots
rgbecker
parents: 2714
diff changeset
   377
        if self._inFill or self.behindAxes:
2516
cdfd0126c655 merge stable 2657:2658 axes/lineplots.py: fix inFill behaviour
rgbecker
parents: 2427
diff changeset
   378
            xA._joinToAxis()
2848
62db2318e9fa charts: more changes to axes and lineplots
rgbecker
parents: 2714
diff changeset
   379
            if self._inFill:
62db2318e9fa charts: more changes to axes and lineplots
rgbecker
parents: 2714
diff changeset
   380
                self._inFillG = Group()
62db2318e9fa charts: more changes to axes and lineplots
rgbecker
parents: 2714
diff changeset
   381
                g.add(self._inFillG)
62db2318e9fa charts: more changes to axes and lineplots
rgbecker
parents: 2714
diff changeset
   382
            if self.behindAxes:
62db2318e9fa charts: more changes to axes and lineplots
rgbecker
parents: 2714
diff changeset
   383
                self._lineG = Group()
62db2318e9fa charts: more changes to axes and lineplots
rgbecker
parents: 2714
diff changeset
   384
                g.add(self._lineG)
3550
cb2afd524453 lineplots.py: fix grid avoidance
rgbecker
parents: 3548
diff changeset
   385
        xA._joinToAxis()
cb2afd524453 lineplots.py: fix grid avoidance
rgbecker
parents: 3548
diff changeset
   386
        yA._joinToAxis()
3548
dfb3110087ad axes.py, lineplots.py: added some features for lines/grids on charts
rgbecker
parents: 3513
diff changeset
   387
        xAex = xA.visibleAxis and [xA._y] or []
dfb3110087ad axes.py, lineplots.py: added some features for lines/grids on charts
rgbecker
parents: 3513
diff changeset
   388
        yAex = yA.visibleAxis and [yA._x] or []
dfb3110087ad axes.py, lineplots.py: added some features for lines/grids on charts
rgbecker
parents: 3513
diff changeset
   389
        skipGrid = getattr(xA,'skipGrid','none')
dfb3110087ad axes.py, lineplots.py: added some features for lines/grids on charts
rgbecker
parents: 3513
diff changeset
   390
        if skipGrid!=None:
dfb3110087ad axes.py, lineplots.py: added some features for lines/grids on charts
rgbecker
parents: 3513
diff changeset
   391
            if skipGrid in ('both','top'):
dfb3110087ad axes.py, lineplots.py: added some features for lines/grids on charts
rgbecker
parents: 3513
diff changeset
   392
                yAex.append(xA._x+xA._length)
dfb3110087ad axes.py, lineplots.py: added some features for lines/grids on charts
rgbecker
parents: 3513
diff changeset
   393
            if skipGrid in ('both','bottom'):
dfb3110087ad axes.py, lineplots.py: added some features for lines/grids on charts
rgbecker
parents: 3513
diff changeset
   394
                yAex.append(xA._x)
dfb3110087ad axes.py, lineplots.py: added some features for lines/grids on charts
rgbecker
parents: 3513
diff changeset
   395
        skipGrid = getattr(yA,'skipGrid','none')
dfb3110087ad axes.py, lineplots.py: added some features for lines/grids on charts
rgbecker
parents: 3513
diff changeset
   396
        if skipGrid!=None:
dfb3110087ad axes.py, lineplots.py: added some features for lines/grids on charts
rgbecker
parents: 3513
diff changeset
   397
            if skipGrid in ('both','top'):
dfb3110087ad axes.py, lineplots.py: added some features for lines/grids on charts
rgbecker
parents: 3513
diff changeset
   398
                xAex.append(yA._y+yA._length)
dfb3110087ad axes.py, lineplots.py: added some features for lines/grids on charts
rgbecker
parents: 3513
diff changeset
   399
            if skipGrid in ('both','bottom'):
dfb3110087ad axes.py, lineplots.py: added some features for lines/grids on charts
rgbecker
parents: 3513
diff changeset
   400
                xAex.append(yA._y)
2848
62db2318e9fa charts: more changes to axes and lineplots
rgbecker
parents: 2714
diff changeset
   401
        if self.gridFirst:
3548
dfb3110087ad axes.py, lineplots.py: added some features for lines/grids on charts
rgbecker
parents: 3513
diff changeset
   402
            xA.makeGrid(g,parent=self,dim=yA.getGridDims,exclude=yAex)
dfb3110087ad axes.py, lineplots.py: added some features for lines/grids on charts
rgbecker
parents: 3513
diff changeset
   403
            yA.makeGrid(g,parent=self,dim=xA.getGridDims,exclude=xAex)
3401
f403f999fcc6 lineplots.py: attempt to fix grid exclusion
rgbecker
parents: 3398
diff changeset
   404
        g.add(xA.draw())
f403f999fcc6 lineplots.py: attempt to fix grid exclusion
rgbecker
parents: 3398
diff changeset
   405
        g.add(yA.draw())
2848
62db2318e9fa charts: more changes to axes and lineplots
rgbecker
parents: 2714
diff changeset
   406
        if not self.gridFirst:
3206
25606c688529 charts: silly attempt at getting the grid to draw last
rgbecker
parents: 3032
diff changeset
   407
            xAdgl = getattr(xA,'drawGridLast',False)
25606c688529 charts: silly attempt at getting the grid to draw last
rgbecker
parents: 3032
diff changeset
   408
            yAdgl = getattr(yA,'drawGridLast',False)
3398
ac8ff8482dae lineplots.py, axes.py: start support for excluding grid lines
rgbecker
parents: 3367
diff changeset
   409
            if not xAdgl: xA.makeGrid(g,parent=self,dim=yA.getGridDims,exclude=yAex)
ac8ff8482dae lineplots.py, axes.py: start support for excluding grid lines
rgbecker
parents: 3367
diff changeset
   410
            if not yAdgl: yA.makeGrid(g,parent=self,dim=xA.getGridDims,exclude=xAex)
2701
a6547c2502f9 lineplots.py: small change to annotations
rgbecker
parents: 2700
diff changeset
   411
        annotations = getattr(self,'annotations',[])
2700
1fa1f6a89e52 charts: improvements to Axes
rgbecker
parents: 2698
diff changeset
   412
        for a in annotations:
2701
a6547c2502f9 lineplots.py: small change to annotations
rgbecker
parents: 2700
diff changeset
   413
            if getattr(a,'beforeLines',None):
2700
1fa1f6a89e52 charts: improvements to Axes
rgbecker
parents: 2698
diff changeset
   414
                g.add(a(self,xA.scale,yA.scale))
3239
4cce2dfb5c34 charts: fix drawGridLast behaviours
rgbecker
parents: 3217
diff changeset
   415
        g.add(self.makeLines())
3206
25606c688529 charts: silly attempt at getting the grid to draw last
rgbecker
parents: 3032
diff changeset
   416
        if not self.gridFirst:
3398
ac8ff8482dae lineplots.py, axes.py: start support for excluding grid lines
rgbecker
parents: 3367
diff changeset
   417
            if xAdgl: xA.makeGrid(g,parent=self,dim=yA.getGridDims,exclude=yAex)
ac8ff8482dae lineplots.py, axes.py: start support for excluding grid lines
rgbecker
parents: 3367
diff changeset
   418
            if yAdgl: yA.makeGrid(g,parent=self,dim=xA.getGridDims,exclude=xAex)
2700
1fa1f6a89e52 charts: improvements to Axes
rgbecker
parents: 2698
diff changeset
   419
        for a in annotations:
2701
a6547c2502f9 lineplots.py: small change to annotations
rgbecker
parents: 2700
diff changeset
   420
            if not getattr(a,'beforeLines',None):
2700
1fa1f6a89e52 charts: improvements to Axes
rgbecker
parents: 2698
diff changeset
   421
                g.add(a(self,xA.scale,yA.scale))
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   422
        return g
737
8f0e58918da9 Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff changeset
   423
3217
b9443ad80a6e lineplots.py: add in addCrossHair
rgbecker
parents: 3206
diff changeset
   424
    def addCrossHair(self,name,xv,yv,strokeColor=colors.black,strokeWidth=1,beforeLines=True):
b9443ad80a6e lineplots.py: add in addCrossHair
rgbecker
parents: 3206
diff changeset
   425
        from reportlab.graphics.shapes import Group, Line
b9443ad80a6e lineplots.py: add in addCrossHair
rgbecker
parents: 3206
diff changeset
   426
        annotations = [a for a in getattr(self,'annotations',[]) if getattr(a,'name',None)!=name]
b9443ad80a6e lineplots.py: add in addCrossHair
rgbecker
parents: 3206
diff changeset
   427
        def annotation(self,xScale,yScale):
b9443ad80a6e lineplots.py: add in addCrossHair
rgbecker
parents: 3206
diff changeset
   428
            x = xScale(xv)
b9443ad80a6e lineplots.py: add in addCrossHair
rgbecker
parents: 3206
diff changeset
   429
            y = yScale(yv)
b9443ad80a6e lineplots.py: add in addCrossHair
rgbecker
parents: 3206
diff changeset
   430
            g = Group()
3721
0c93dd8ff567 initial changes from 2to3-3.3
rptlab
parents: 3652
diff changeset
   431
            xA = xScale.__self__ #the x axis
3217
b9443ad80a6e lineplots.py: add in addCrossHair
rgbecker
parents: 3206
diff changeset
   432
            g.add(Line(xA._x,y,xA._x+xA._length,y,strokeColor=strokeColor,strokeWidth=strokeWidth))
3721
0c93dd8ff567 initial changes from 2to3-3.3
rptlab
parents: 3652
diff changeset
   433
            yA = yScale.__self__ #the y axis
3217
b9443ad80a6e lineplots.py: add in addCrossHair
rgbecker
parents: 3206
diff changeset
   434
            g.add(Line(x,yA._y,x,yA._y+yA._length,strokeColor=strokeColor,strokeWidth=strokeWidth))
b9443ad80a6e lineplots.py: add in addCrossHair
rgbecker
parents: 3206
diff changeset
   435
            return g
b9443ad80a6e lineplots.py: add in addCrossHair
rgbecker
parents: 3206
diff changeset
   436
        annotation.beforeLines = beforeLines
b9443ad80a6e lineplots.py: add in addCrossHair
rgbecker
parents: 3206
diff changeset
   437
        annotations.append(annotation)
b9443ad80a6e lineplots.py: add in addCrossHair
rgbecker
parents: 3206
diff changeset
   438
        self.annotations = annotations
b9443ad80a6e lineplots.py: add in addCrossHair
rgbecker
parents: 3206
diff changeset
   439
2070
fb34cff995ab Minor adjustmenst and added LinePlot3D
rgbecker
parents: 2054
diff changeset
   440
class LinePlot3D(LinePlot):
fb34cff995ab Minor adjustmenst and added LinePlot3D
rgbecker
parents: 2054
diff changeset
   441
    _attrMap = AttrMap(BASE=LinePlot,
fb34cff995ab Minor adjustmenst and added LinePlot3D
rgbecker
parents: 2054
diff changeset
   442
        theta_x = AttrMapValue(isNumber, desc='dx/dz'),
fb34cff995ab Minor adjustmenst and added LinePlot3D
rgbecker
parents: 2054
diff changeset
   443
        theta_y = AttrMapValue(isNumber, desc='dy/dz'),
fb34cff995ab Minor adjustmenst and added LinePlot3D
rgbecker
parents: 2054
diff changeset
   444
        zDepth = AttrMapValue(isNumber, desc='depth of an individual series'),
fb34cff995ab Minor adjustmenst and added LinePlot3D
rgbecker
parents: 2054
diff changeset
   445
        zSpace = AttrMapValue(isNumber, desc='z gap around series'),
fb34cff995ab Minor adjustmenst and added LinePlot3D
rgbecker
parents: 2054
diff changeset
   446
        )
fb34cff995ab Minor adjustmenst and added LinePlot3D
rgbecker
parents: 2054
diff changeset
   447
    theta_x = .5
fb34cff995ab Minor adjustmenst and added LinePlot3D
rgbecker
parents: 2054
diff changeset
   448
    theta_y = .5
fb34cff995ab Minor adjustmenst and added LinePlot3D
rgbecker
parents: 2054
diff changeset
   449
    zDepth = 10
2079
2ec043bb4c85 Set reasonable zSpace
rgbecker
parents: 2072
diff changeset
   450
    zSpace = 3
2070
fb34cff995ab Minor adjustmenst and added LinePlot3D
rgbecker
parents: 2054
diff changeset
   451
fb34cff995ab Minor adjustmenst and added LinePlot3D
rgbecker
parents: 2054
diff changeset
   452
    def calcPositions(self):
fb34cff995ab Minor adjustmenst and added LinePlot3D
rgbecker
parents: 2054
diff changeset
   453
        LinePlot.calcPositions(self)
fb34cff995ab Minor adjustmenst and added LinePlot3D
rgbecker
parents: 2054
diff changeset
   454
        nSeries = self._seriesCount
fb34cff995ab Minor adjustmenst and added LinePlot3D
rgbecker
parents: 2054
diff changeset
   455
        zSpace = self.zSpace
fb34cff995ab Minor adjustmenst and added LinePlot3D
rgbecker
parents: 2054
diff changeset
   456
        zDepth = self.zDepth
fb34cff995ab Minor adjustmenst and added LinePlot3D
rgbecker
parents: 2054
diff changeset
   457
        if self.xValueAxis.style=='parallel_3d':
2079
2ec043bb4c85 Set reasonable zSpace
rgbecker
parents: 2072
diff changeset
   458
            _3d_depth = nSeries*zDepth+(nSeries+1)*zSpace
2070
fb34cff995ab Minor adjustmenst and added LinePlot3D
rgbecker
parents: 2054
diff changeset
   459
        else:
fb34cff995ab Minor adjustmenst and added LinePlot3D
rgbecker
parents: 2054
diff changeset
   460
            _3d_depth = zDepth + 2*zSpace
fb34cff995ab Minor adjustmenst and added LinePlot3D
rgbecker
parents: 2054
diff changeset
   461
        self._3d_dx = self.theta_x*_3d_depth
fb34cff995ab Minor adjustmenst and added LinePlot3D
rgbecker
parents: 2054
diff changeset
   462
        self._3d_dy = self.theta_y*_3d_depth
fb34cff995ab Minor adjustmenst and added LinePlot3D
rgbecker
parents: 2054
diff changeset
   463
fb34cff995ab Minor adjustmenst and added LinePlot3D
rgbecker
parents: 2054
diff changeset
   464
    def _calc_z0(self,rowNo):
fb34cff995ab Minor adjustmenst and added LinePlot3D
rgbecker
parents: 2054
diff changeset
   465
        zSpace = self.zSpace
fb34cff995ab Minor adjustmenst and added LinePlot3D
rgbecker
parents: 2054
diff changeset
   466
        if self.xValueAxis.style=='parallel_3d':
fb34cff995ab Minor adjustmenst and added LinePlot3D
rgbecker
parents: 2054
diff changeset
   467
            z0 = rowNo*(self.zDepth+zSpace)+zSpace
fb34cff995ab Minor adjustmenst and added LinePlot3D
rgbecker
parents: 2054
diff changeset
   468
        else:
fb34cff995ab Minor adjustmenst and added LinePlot3D
rgbecker
parents: 2054
diff changeset
   469
            z0 = zSpace
fb34cff995ab Minor adjustmenst and added LinePlot3D
rgbecker
parents: 2054
diff changeset
   470
        return z0
fb34cff995ab Minor adjustmenst and added LinePlot3D
rgbecker
parents: 2054
diff changeset
   471
fb34cff995ab Minor adjustmenst and added LinePlot3D
rgbecker
parents: 2054
diff changeset
   472
    def _zadjust(self,x,y,z):
2071
ccbed33977a9 Added in lineplot3d and got data labels working
rgbecker
parents: 2070
diff changeset
   473
        return x+z*self.theta_x, y+z*self.theta_y
2070
fb34cff995ab Minor adjustmenst and added LinePlot3D
rgbecker
parents: 2054
diff changeset
   474
fb34cff995ab Minor adjustmenst and added LinePlot3D
rgbecker
parents: 2054
diff changeset
   475
    def makeLines(self):
fb34cff995ab Minor adjustmenst and added LinePlot3D
rgbecker
parents: 2054
diff changeset
   476
        bubblePlot = getattr(self,'_bubblePlot',None)
fb34cff995ab Minor adjustmenst and added LinePlot3D
rgbecker
parents: 2054
diff changeset
   477
        assert not bubblePlot, "_bubblePlot not supported for 3d yet"
fb34cff995ab Minor adjustmenst and added LinePlot3D
rgbecker
parents: 2054
diff changeset
   478
        #if bubblePlot:
fb34cff995ab Minor adjustmenst and added LinePlot3D
rgbecker
parents: 2054
diff changeset
   479
        #   yA = self.yValueAxis
fb34cff995ab Minor adjustmenst and added LinePlot3D
rgbecker
parents: 2054
diff changeset
   480
        #   xA = self.xValueAxis
fb34cff995ab Minor adjustmenst and added LinePlot3D
rgbecker
parents: 2054
diff changeset
   481
        #   bubbleR = min(yA._bubbleRadius,xA._bubbleRadius)
fb34cff995ab Minor adjustmenst and added LinePlot3D
rgbecker
parents: 2054
diff changeset
   482
        #   bubbleMax = xA._bubbleMax
fb34cff995ab Minor adjustmenst and added LinePlot3D
rgbecker
parents: 2054
diff changeset
   483
fb34cff995ab Minor adjustmenst and added LinePlot3D
rgbecker
parents: 2054
diff changeset
   484
        labelFmt = self.lineLabelFormat
2152
212b90cdb3c4 Fixes to 3D lines
rgbecker
parents: 2151
diff changeset
   485
        positions = self._positions
2070
fb34cff995ab Minor adjustmenst and added LinePlot3D
rgbecker
parents: 2054
diff changeset
   486
3721
0c93dd8ff567 initial changes from 2to3-3.3
rptlab
parents: 3652
diff changeset
   487
        P = list(range(len(positions)))
2070
fb34cff995ab Minor adjustmenst and added LinePlot3D
rgbecker
parents: 2054
diff changeset
   488
        if self.reversePlotOrder: P.reverse()
fb34cff995ab Minor adjustmenst and added LinePlot3D
rgbecker
parents: 2054
diff changeset
   489
        inFill = getattr(self,'_inFill',None)
fb34cff995ab Minor adjustmenst and added LinePlot3D
rgbecker
parents: 2054
diff changeset
   490
        assert not inFill, "inFill not supported for 3d yet"
fb34cff995ab Minor adjustmenst and added LinePlot3D
rgbecker
parents: 2054
diff changeset
   491
        #if inFill:
fb34cff995ab Minor adjustmenst and added LinePlot3D
rgbecker
parents: 2054
diff changeset
   492
        #   inFillY = self.xValueAxis._y
fb34cff995ab Minor adjustmenst and added LinePlot3D
rgbecker
parents: 2054
diff changeset
   493
        #   inFillX0 = self.yValueAxis._x
fb34cff995ab Minor adjustmenst and added LinePlot3D
rgbecker
parents: 2054
diff changeset
   494
        #   inFillX1 = inFillX0 + self.xValueAxis._length
fb34cff995ab Minor adjustmenst and added LinePlot3D
rgbecker
parents: 2054
diff changeset
   495
        #   inFillG = getattr(self,'_inFillG',g)
fb34cff995ab Minor adjustmenst and added LinePlot3D
rgbecker
parents: 2054
diff changeset
   496
        zDepth = self.zDepth
fb34cff995ab Minor adjustmenst and added LinePlot3D
rgbecker
parents: 2054
diff changeset
   497
        _zadjust = self._zadjust
fb34cff995ab Minor adjustmenst and added LinePlot3D
rgbecker
parents: 2054
diff changeset
   498
        theta_x = self.theta_x
fb34cff995ab Minor adjustmenst and added LinePlot3D
rgbecker
parents: 2054
diff changeset
   499
        theta_y = self.theta_y
3975
4a3599863c11 eliminate from . imports in favour of absolutes to allow running modules
robin
parents: 3800
diff changeset
   500
        from reportlab.graphics.charts.linecharts import _FakeGroup
2070
fb34cff995ab Minor adjustmenst and added LinePlot3D
rgbecker
parents: 2054
diff changeset
   501
        F = _FakeGroup()
2152
212b90cdb3c4 Fixes to 3D lines
rgbecker
parents: 2151
diff changeset
   502
3975
4a3599863c11 eliminate from . imports in favour of absolutes to allow running modules
robin
parents: 3800
diff changeset
   503
        from reportlab.graphics.charts.utils3d import _make_3d_line_info, find_intersections
2152
212b90cdb3c4 Fixes to 3D lines
rgbecker
parents: 2151
diff changeset
   504
        if self.xValueAxis.style!='parallel_3d':
212b90cdb3c4 Fixes to 3D lines
rgbecker
parents: 2151
diff changeset
   505
            tileWidth = getattr(self,'_3d_tilewidth',1)
212b90cdb3c4 Fixes to 3D lines
rgbecker
parents: 2151
diff changeset
   506
            if getattr(self,'_find_intersections',None):
212b90cdb3c4 Fixes to 3D lines
rgbecker
parents: 2151
diff changeset
   507
                from copy import copy
3721
0c93dd8ff567 initial changes from 2to3-3.3
rptlab
parents: 3652
diff changeset
   508
                fpositions = list(map(copy,positions))
2152
212b90cdb3c4 Fixes to 3D lines
rgbecker
parents: 2151
diff changeset
   509
                I = find_intersections(fpositions,small=tileWidth)
212b90cdb3c4 Fixes to 3D lines
rgbecker
parents: 2151
diff changeset
   510
                ic = None
212b90cdb3c4 Fixes to 3D lines
rgbecker
parents: 2151
diff changeset
   511
                for i,j,x,y in I:
212b90cdb3c4 Fixes to 3D lines
rgbecker
parents: 2151
diff changeset
   512
                    if ic!=i:
212b90cdb3c4 Fixes to 3D lines
rgbecker
parents: 2151
diff changeset
   513
                        ic = i
212b90cdb3c4 Fixes to 3D lines
rgbecker
parents: 2151
diff changeset
   514
                        jc = 0
212b90cdb3c4 Fixes to 3D lines
rgbecker
parents: 2151
diff changeset
   515
                    else:
212b90cdb3c4 Fixes to 3D lines
rgbecker
parents: 2151
diff changeset
   516
                        jc+=1
212b90cdb3c4 Fixes to 3D lines
rgbecker
parents: 2151
diff changeset
   517
                    fpositions[i].insert(j+jc,(x,y))
212b90cdb3c4 Fixes to 3D lines
rgbecker
parents: 2151
diff changeset
   518
                tileWidth = None
212b90cdb3c4 Fixes to 3D lines
rgbecker
parents: 2151
diff changeset
   519
            else:
212b90cdb3c4 Fixes to 3D lines
rgbecker
parents: 2151
diff changeset
   520
                fpositions = positions
212b90cdb3c4 Fixes to 3D lines
rgbecker
parents: 2151
diff changeset
   521
        else:
212b90cdb3c4 Fixes to 3D lines
rgbecker
parents: 2151
diff changeset
   522
            tileWidth = None
212b90cdb3c4 Fixes to 3D lines
rgbecker
parents: 2151
diff changeset
   523
            fpositions = positions
2151
fad2252e4e6f Allow for non-tiling!
rgbecker
parents: 2147
diff changeset
   524
2070
fb34cff995ab Minor adjustmenst and added LinePlot3D
rgbecker
parents: 2054
diff changeset
   525
        # Iterate over data rows.
fb34cff995ab Minor adjustmenst and added LinePlot3D
rgbecker
parents: 2054
diff changeset
   526
        styleCount = len(self.lines)
fb34cff995ab Minor adjustmenst and added LinePlot3D
rgbecker
parents: 2054
diff changeset
   527
        for rowNo in P:
2152
212b90cdb3c4 Fixes to 3D lines
rgbecker
parents: 2151
diff changeset
   528
            row = positions[rowNo]
2070
fb34cff995ab Minor adjustmenst and added LinePlot3D
rgbecker
parents: 2054
diff changeset
   529
            n = len(row)
fb34cff995ab Minor adjustmenst and added LinePlot3D
rgbecker
parents: 2054
diff changeset
   530
            rowStyle = self.lines[rowNo % styleCount]
fb34cff995ab Minor adjustmenst and added LinePlot3D
rgbecker
parents: 2054
diff changeset
   531
            rowColor = rowStyle.strokeColor
fb34cff995ab Minor adjustmenst and added LinePlot3D
rgbecker
parents: 2054
diff changeset
   532
            dash = getattr(rowStyle, 'strokeDashArray', None)
fb34cff995ab Minor adjustmenst and added LinePlot3D
rgbecker
parents: 2054
diff changeset
   533
            z0 = self._calc_z0(rowNo)
fb34cff995ab Minor adjustmenst and added LinePlot3D
rgbecker
parents: 2054
diff changeset
   534
            z1 = z0 + zDepth
fb34cff995ab Minor adjustmenst and added LinePlot3D
rgbecker
parents: 2054
diff changeset
   535
fb34cff995ab Minor adjustmenst and added LinePlot3D
rgbecker
parents: 2054
diff changeset
   536
            if hasattr(rowStyle, 'strokeWidth'):
fb34cff995ab Minor adjustmenst and added LinePlot3D
rgbecker
parents: 2054
diff changeset
   537
                width = rowStyle.strokeWidth
fb34cff995ab Minor adjustmenst and added LinePlot3D
rgbecker
parents: 2054
diff changeset
   538
            elif hasattr(self.lines, 'strokeWidth'):
fb34cff995ab Minor adjustmenst and added LinePlot3D
rgbecker
parents: 2054
diff changeset
   539
                width = self.lines.strokeWidth
fb34cff995ab Minor adjustmenst and added LinePlot3D
rgbecker
parents: 2054
diff changeset
   540
            else:
fb34cff995ab Minor adjustmenst and added LinePlot3D
rgbecker
parents: 2054
diff changeset
   541
                width = None
fb34cff995ab Minor adjustmenst and added LinePlot3D
rgbecker
parents: 2054
diff changeset
   542
fb34cff995ab Minor adjustmenst and added LinePlot3D
rgbecker
parents: 2054
diff changeset
   543
            # Iterate over data columns.
fb34cff995ab Minor adjustmenst and added LinePlot3D
rgbecker
parents: 2054
diff changeset
   544
            if self.joinedLines:
fb34cff995ab Minor adjustmenst and added LinePlot3D
rgbecker
parents: 2054
diff changeset
   545
                if n:
2152
212b90cdb3c4 Fixes to 3D lines
rgbecker
parents: 2151
diff changeset
   546
                    frow = fpositions[rowNo]
212b90cdb3c4 Fixes to 3D lines
rgbecker
parents: 2151
diff changeset
   547
                    x0, y0 = frow[0]
3721
0c93dd8ff567 initial changes from 2to3-3.3
rptlab
parents: 3652
diff changeset
   548
                    for colNo in range(1,len(frow)):
2152
212b90cdb3c4 Fixes to 3D lines
rgbecker
parents: 2151
diff changeset
   549
                        x1, y1 = frow[colNo]
2070
fb34cff995ab Minor adjustmenst and added LinePlot3D
rgbecker
parents: 2054
diff changeset
   550
                        _make_3d_line_info( F, x0, x1, y0, y1, z0, z1,
fb34cff995ab Minor adjustmenst and added LinePlot3D
rgbecker
parents: 2054
diff changeset
   551
                                theta_x, theta_y,
2152
212b90cdb3c4 Fixes to 3D lines
rgbecker
parents: 2151
diff changeset
   552
                                rowColor, fillColorShaded=None, tileWidth=tileWidth,
2070
fb34cff995ab Minor adjustmenst and added LinePlot3D
rgbecker
parents: 2054
diff changeset
   553
                                strokeColor=None, strokeWidth=None, strokeDashArray=None,
fb34cff995ab Minor adjustmenst and added LinePlot3D
rgbecker
parents: 2054
diff changeset
   554
                                shading=0.1)
fb34cff995ab Minor adjustmenst and added LinePlot3D
rgbecker
parents: 2054
diff changeset
   555
                        x0, y0 = x1, y1
fb34cff995ab Minor adjustmenst and added LinePlot3D
rgbecker
parents: 2054
diff changeset
   556
fb34cff995ab Minor adjustmenst and added LinePlot3D
rgbecker
parents: 2054
diff changeset
   557
            if hasattr(rowStyle, 'symbol'):
fb34cff995ab Minor adjustmenst and added LinePlot3D
rgbecker
parents: 2054
diff changeset
   558
                uSymbol = rowStyle.symbol
fb34cff995ab Minor adjustmenst and added LinePlot3D
rgbecker
parents: 2054
diff changeset
   559
            elif hasattr(self.lines, 'symbol'):
fb34cff995ab Minor adjustmenst and added LinePlot3D
rgbecker
parents: 2054
diff changeset
   560
                uSymbol = self.lines.symbol
fb34cff995ab Minor adjustmenst and added LinePlot3D
rgbecker
parents: 2054
diff changeset
   561
            else:
fb34cff995ab Minor adjustmenst and added LinePlot3D
rgbecker
parents: 2054
diff changeset
   562
                uSymbol = None
fb34cff995ab Minor adjustmenst and added LinePlot3D
rgbecker
parents: 2054
diff changeset
   563
fb34cff995ab Minor adjustmenst and added LinePlot3D
rgbecker
parents: 2054
diff changeset
   564
            if uSymbol:
fb34cff995ab Minor adjustmenst and added LinePlot3D
rgbecker
parents: 2054
diff changeset
   565
                for xy in row:
fb34cff995ab Minor adjustmenst and added LinePlot3D
rgbecker
parents: 2054
diff changeset
   566
                    x1, y1 = row[colNo]
2072
c4356af95fe6 Furniture should be at low z
rgbecker
parents: 2071
diff changeset
   567
                    x1, y1 = _zadjust(x1,y1,z0)
2070
fb34cff995ab Minor adjustmenst and added LinePlot3D
rgbecker
parents: 2054
diff changeset
   568
                    symbol = uSymbol2Symbol(uSymbol,xy[0],xy[1],rowColor)
2072
c4356af95fe6 Furniture should be at low z
rgbecker
parents: 2071
diff changeset
   569
                    if symbol: F.add((1,z0,z0,x1,y1,symbol))
2070
fb34cff995ab Minor adjustmenst and added LinePlot3D
rgbecker
parents: 2054
diff changeset
   570
fb34cff995ab Minor adjustmenst and added LinePlot3D
rgbecker
parents: 2054
diff changeset
   571
            # Draw data labels.
3721
0c93dd8ff567 initial changes from 2to3-3.3
rptlab
parents: 3652
diff changeset
   572
            for colNo in range(n):
2070
fb34cff995ab Minor adjustmenst and added LinePlot3D
rgbecker
parents: 2054
diff changeset
   573
                x1, y1 = row[colNo]
2072
c4356af95fe6 Furniture should be at low z
rgbecker
parents: 2071
diff changeset
   574
                x1, y1 = _zadjust(x1,y1,z0)
2070
fb34cff995ab Minor adjustmenst and added LinePlot3D
rgbecker
parents: 2054
diff changeset
   575
                L = self._innerDrawLabel(rowNo, colNo, x1, y1)
2072
c4356af95fe6 Furniture should be at low z
rgbecker
parents: 2071
diff changeset
   576
                if L: F.add((2,z0,z0,x1,y1,L))
2070
fb34cff995ab Minor adjustmenst and added LinePlot3D
rgbecker
parents: 2054
diff changeset
   577
fb34cff995ab Minor adjustmenst and added LinePlot3D
rgbecker
parents: 2054
diff changeset
   578
        F.sort()
fb34cff995ab Minor adjustmenst and added LinePlot3D
rgbecker
parents: 2054
diff changeset
   579
        g = Group()
3328
4d7f836cd947 reportlab: fix 2to3 warnings
rgbecker
parents: 3326
diff changeset
   580
        for v in F.value(): g.add(v[-1])
2070
fb34cff995ab Minor adjustmenst and added LinePlot3D
rgbecker
parents: 2054
diff changeset
   581
        return g
fb34cff995ab Minor adjustmenst and added LinePlot3D
rgbecker
parents: 2054
diff changeset
   582
1616
fcd8fe41df7e Added GridLinePlot
rgbecker
parents: 1573
diff changeset
   583
_monthlyIndexData = [[(19971202, 100.0),
fcd8fe41df7e Added GridLinePlot
rgbecker
parents: 1573
diff changeset
   584
  (19971231, 100.1704367),
fcd8fe41df7e Added GridLinePlot
rgbecker
parents: 1573
diff changeset
   585
  (19980131, 101.5639577),
fcd8fe41df7e Added GridLinePlot
rgbecker
parents: 1573
diff changeset
   586
  (19980228, 102.1879927),
fcd8fe41df7e Added GridLinePlot
rgbecker
parents: 1573
diff changeset
   587
  (19980331, 101.6337257),
fcd8fe41df7e Added GridLinePlot
rgbecker
parents: 1573
diff changeset
   588
  (19980430, 102.7640446),
fcd8fe41df7e Added GridLinePlot
rgbecker
parents: 1573
diff changeset
   589
  (19980531, 102.9198038),
fcd8fe41df7e Added GridLinePlot
rgbecker
parents: 1573
diff changeset
   590
  (19980630, 103.25938789999999),
fcd8fe41df7e Added GridLinePlot
rgbecker
parents: 1573
diff changeset
   591
  (19980731, 103.2516421),
fcd8fe41df7e Added GridLinePlot
rgbecker
parents: 1573
diff changeset
   592
  (19980831, 105.4744329),
fcd8fe41df7e Added GridLinePlot
rgbecker
parents: 1573
diff changeset
   593
  (19980930, 109.3242705),
fcd8fe41df7e Added GridLinePlot
rgbecker
parents: 1573
diff changeset
   594
  (19981031, 111.9859291),
fcd8fe41df7e Added GridLinePlot
rgbecker
parents: 1573
diff changeset
   595
  (19981130, 110.9184642),
fcd8fe41df7e Added GridLinePlot
rgbecker
parents: 1573
diff changeset
   596
  (19981231, 110.9184642),
fcd8fe41df7e Added GridLinePlot
rgbecker
parents: 1573
diff changeset
   597
  (19990131, 111.9882532),
fcd8fe41df7e Added GridLinePlot
rgbecker
parents: 1573
diff changeset
   598
  (19990228, 109.7912614),
fcd8fe41df7e Added GridLinePlot
rgbecker
parents: 1573
diff changeset
   599
  (19990331, 110.24189629999999),
fcd8fe41df7e Added GridLinePlot
rgbecker
parents: 1573
diff changeset
   600
  (19990430, 110.4279321),
fcd8fe41df7e Added GridLinePlot
rgbecker
parents: 1573
diff changeset
   601
  (19990531, 109.33955469999999),
fcd8fe41df7e Added GridLinePlot
rgbecker
parents: 1573
diff changeset
   602
  (19990630, 108.2341748),
fcd8fe41df7e Added GridLinePlot
rgbecker
parents: 1573
diff changeset
   603
  (19990731, 110.21294469999999),
fcd8fe41df7e Added GridLinePlot
rgbecker
parents: 1573
diff changeset
   604
  (19990831, 110.9683062),
fcd8fe41df7e Added GridLinePlot
rgbecker
parents: 1573
diff changeset
   605
  (19990930, 112.4425371),
fcd8fe41df7e Added GridLinePlot
rgbecker
parents: 1573
diff changeset
   606
  (19991031, 112.7314032),
fcd8fe41df7e Added GridLinePlot
rgbecker
parents: 1573
diff changeset
   607
  (19991130, 112.3509645),
fcd8fe41df7e Added GridLinePlot
rgbecker
parents: 1573
diff changeset
   608
  (19991231, 112.3660659),
fcd8fe41df7e Added GridLinePlot
rgbecker
parents: 1573
diff changeset
   609
  (20000131, 110.9255248),
fcd8fe41df7e Added GridLinePlot
rgbecker
parents: 1573
diff changeset
   610
  (20000229, 110.5266306),
fcd8fe41df7e Added GridLinePlot
rgbecker
parents: 1573
diff changeset
   611
  (20000331, 113.3116101),
fcd8fe41df7e Added GridLinePlot
rgbecker
parents: 1573
diff changeset
   612
  (20000430, 111.0449133),
fcd8fe41df7e Added GridLinePlot
rgbecker
parents: 1573
diff changeset
   613
  (20000531, 111.702717),
fcd8fe41df7e Added GridLinePlot
rgbecker
parents: 1573
diff changeset
   614
  (20000630, 113.5832178)],
fcd8fe41df7e Added GridLinePlot
rgbecker
parents: 1573
diff changeset
   615
 [(19971202, 100.0),
fcd8fe41df7e Added GridLinePlot
rgbecker
parents: 1573
diff changeset
   616
  (19971231, 100.0),
fcd8fe41df7e Added GridLinePlot
rgbecker
parents: 1573
diff changeset
   617
  (19980131, 100.8),
fcd8fe41df7e Added GridLinePlot
rgbecker
parents: 1573
diff changeset
   618
  (19980228, 102.0),
fcd8fe41df7e Added GridLinePlot
rgbecker
parents: 1573
diff changeset
   619
  (19980331, 101.9),
fcd8fe41df7e Added GridLinePlot
rgbecker
parents: 1573
diff changeset
   620
  (19980430, 103.0),
fcd8fe41df7e Added GridLinePlot
rgbecker
parents: 1573
diff changeset
   621
  (19980531, 103.0),
fcd8fe41df7e Added GridLinePlot
rgbecker
parents: 1573
diff changeset
   622
  (19980630, 103.1),
fcd8fe41df7e Added GridLinePlot
rgbecker
parents: 1573
diff changeset
   623
  (19980731, 103.1),
fcd8fe41df7e Added GridLinePlot
rgbecker
parents: 1573
diff changeset
   624
  (19980831, 102.8),
fcd8fe41df7e Added GridLinePlot
rgbecker
parents: 1573
diff changeset
   625
  (19980930, 105.6),
fcd8fe41df7e Added GridLinePlot
rgbecker
parents: 1573
diff changeset
   626
  (19981031, 108.3),
fcd8fe41df7e Added GridLinePlot
rgbecker
parents: 1573
diff changeset
   627
  (19981130, 108.1),
fcd8fe41df7e Added GridLinePlot
rgbecker
parents: 1573
diff changeset
   628
  (19981231, 111.9),
fcd8fe41df7e Added GridLinePlot
rgbecker
parents: 1573
diff changeset
   629
  (19990131, 113.1),
fcd8fe41df7e Added GridLinePlot
rgbecker
parents: 1573
diff changeset
   630
  (19990228, 110.2),
fcd8fe41df7e Added GridLinePlot
rgbecker
parents: 1573
diff changeset
   631
  (19990331, 111.8),
fcd8fe41df7e Added GridLinePlot
rgbecker
parents: 1573
diff changeset
   632
  (19990430, 112.3),
fcd8fe41df7e Added GridLinePlot
rgbecker
parents: 1573
diff changeset
   633
  (19990531, 110.1),
fcd8fe41df7e Added GridLinePlot
rgbecker
parents: 1573
diff changeset
   634
  (19990630, 109.3),
fcd8fe41df7e Added GridLinePlot
rgbecker
parents: 1573
diff changeset
   635
  (19990731, 111.2),
fcd8fe41df7e Added GridLinePlot
rgbecker
parents: 1573
diff changeset
   636
  (19990831, 111.7),
fcd8fe41df7e Added GridLinePlot
rgbecker
parents: 1573
diff changeset
   637
  (19990930, 112.6),
fcd8fe41df7e Added GridLinePlot
rgbecker
parents: 1573
diff changeset
   638
  (19991031, 113.2),
fcd8fe41df7e Added GridLinePlot
rgbecker
parents: 1573
diff changeset
   639
  (19991130, 113.9),
fcd8fe41df7e Added GridLinePlot
rgbecker
parents: 1573
diff changeset
   640
  (19991231, 115.4),
fcd8fe41df7e Added GridLinePlot
rgbecker
parents: 1573
diff changeset
   641
  (20000131, 112.7),
fcd8fe41df7e Added GridLinePlot
rgbecker
parents: 1573
diff changeset
   642
  (20000229, 113.9),
fcd8fe41df7e Added GridLinePlot
rgbecker
parents: 1573
diff changeset
   643
  (20000331, 115.8),
fcd8fe41df7e Added GridLinePlot
rgbecker
parents: 1573
diff changeset
   644
  (20000430, 112.2),
fcd8fe41df7e Added GridLinePlot
rgbecker
parents: 1573
diff changeset
   645
  (20000531, 112.6),
fcd8fe41df7e Added GridLinePlot
rgbecker
parents: 1573
diff changeset
   646
  (20000630, 114.6)]]
fcd8fe41df7e Added GridLinePlot
rgbecker
parents: 1573
diff changeset
   647
3650
ee1ab6a5402a lineplots.py: added SimpleTimeSeriesPlot
robin
parents: 3617
diff changeset
   648
class SimpleTimeSeriesPlot(LinePlot):
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   649
    """A customized version of LinePlot.
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   650
    It uses NormalDateXValueAxis() and AdjYValueAxis() for the X and Y axes.
3650
ee1ab6a5402a lineplots.py: added SimpleTimeSeriesPlot
robin
parents: 3617
diff changeset
   651
    """
ee1ab6a5402a lineplots.py: added SimpleTimeSeriesPlot
robin
parents: 3617
diff changeset
   652
    def __init__(self):
ee1ab6a5402a lineplots.py: added SimpleTimeSeriesPlot
robin
parents: 3617
diff changeset
   653
        LinePlot.__init__(self)
ee1ab6a5402a lineplots.py: added SimpleTimeSeriesPlot
robin
parents: 3617
diff changeset
   654
        self.xValueAxis = NormalDateXValueAxis()
3652
f73d5baa5c86 fixed y axis in the simple time series plot
tom
parents: 3650
diff changeset
   655
        self.yValueAxis = YValueAxis()
3650
ee1ab6a5402a lineplots.py: added SimpleTimeSeriesPlot
robin
parents: 3617
diff changeset
   656
        self.data = _monthlyIndexData
ee1ab6a5402a lineplots.py: added SimpleTimeSeriesPlot
robin
parents: 3617
diff changeset
   657
ee1ab6a5402a lineplots.py: added SimpleTimeSeriesPlot
robin
parents: 3617
diff changeset
   658
class GridLinePlot(SimpleTimeSeriesPlot):
ee1ab6a5402a lineplots.py: added SimpleTimeSeriesPlot
robin
parents: 3617
diff changeset
   659
    """A customized version of SimpleTimeSeriesSPlot.
ee1ab6a5402a lineplots.py: added SimpleTimeSeriesPlot
robin
parents: 3617
diff changeset
   660
    It uses NormalDateXValueAxis() and AdjYValueAxis() for the X and Y axes.
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   661
    The chart has a default grid background with thin horizontal lines
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   662
    aligned with the tickmarks (and labels). You can change the back-
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   663
    ground to be any Grid or ShadedRect, or scale the whole chart.
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   664
    If you do provide a background, you can specify the colours of the
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   665
    stripes with 'background.stripeColors'.
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   666
    """
1616
fcd8fe41df7e Added GridLinePlot
rgbecker
parents: 1573
diff changeset
   667
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   668
    _attrMap = AttrMap(BASE=LinePlot,
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   669
        background = AttrMapValue(None, desc='Background for chart area (now Grid or ShadedRect).'),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   670
        scaleFactor = AttrMapValue(isNumberOrNone, desc='Scalefactor to apply to whole drawing.'),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   671
        )
1616
fcd8fe41df7e Added GridLinePlot
rgbecker
parents: 1573
diff changeset
   672
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   673
    def __init__(self):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   674
        from reportlab.lib import colors
3650
ee1ab6a5402a lineplots.py: added SimpleTimeSeriesPlot
robin
parents: 3617
diff changeset
   675
        SimpleTimeSeriesPlot.__init__(self)
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   676
        self.scaleFactor = None
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   677
        self.background = Grid()
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   678
        self.background.orientation = 'horizontal'
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   679
        self.background.useRects = 0
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   680
        self.background.useLines = 1
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   681
        self.background.strokeWidth = 0.5
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   682
        self.background.strokeColor = colors.black
1616
fcd8fe41df7e Added GridLinePlot
rgbecker
parents: 1573
diff changeset
   683
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   684
    def demo(self,drawing=None):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   685
        from reportlab.lib import colors
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   686
        if not drawing:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   687
            drawing = Drawing(400, 200)
3650
ee1ab6a5402a lineplots.py: added SimpleTimeSeriesPlot
robin
parents: 3617
diff changeset
   688
        lp = GridLinePlot()
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   689
        lp.x = 50
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   690
        lp.y = 50
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   691
        lp.height = 125
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   692
        lp.width = 300
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   693
        lp.data = _monthlyIndexData
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   694
        lp.joinedLines = 1
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   695
        lp.strokeColor = colors.black
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   696
        c0 = colors.PCMYKColor(100,65,0,30, spotName='PANTONE 288 CV', density=100)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   697
        lp.lines[0].strokeColor = c0
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   698
        lp.lines[0].strokeWidth = 2
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   699
        lp.lines[0].strokeDashArray = None
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   700
        c1 = colors.PCMYKColor(0,79,91,0, spotName='PANTONE Wm Red CV', density=100)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   701
        lp.lines[1].strokeColor = c1
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   702
        lp.lines[1].strokeWidth = 1
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   703
        lp.lines[1].strokeDashArray = [3,1]
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   704
        lp.xValueAxis.labels.fontSize = 10
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   705
        lp.xValueAxis.labels.textAnchor = 'start'
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   706
        lp.xValueAxis.labels.boxAnchor = 'w'
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   707
        lp.xValueAxis.labels.angle = -45
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   708
        lp.xValueAxis.labels.dx = 0
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   709
        lp.xValueAxis.labels.dy = -8
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   710
        lp.xValueAxis.xLabelFormat = '{mm}/{yy}'
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   711
        lp.yValueAxis.labelTextFormat = '%5d%% '
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   712
        lp.yValueAxis.tickLeft = 5
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   713
        lp.yValueAxis.labels.fontSize = 10
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   714
        lp.background = Grid()
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   715
        lp.background.stripeColors = [colors.pink, colors.lightblue]
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   716
        lp.background.orientation = 'vertical'
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   717
        drawing.add(lp,'plot')
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   718
        return drawing
1616
fcd8fe41df7e Added GridLinePlot
rgbecker
parents: 1573
diff changeset
   719
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   720
    def draw(self):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   721
        xva, yva = self.xValueAxis, self.yValueAxis
1803
1f02a9cb6f48 Fix up bugs in joinAxisMode handling
rgbecker
parents: 1802
diff changeset
   722
        if xva: xva.joinAxis = yva
1f02a9cb6f48 Fix up bugs in joinAxisMode handling
rgbecker
parents: 1802
diff changeset
   723
        if yva: yva.joinAxis = xva
1616
fcd8fe41df7e Added GridLinePlot
rgbecker
parents: 1573
diff changeset
   724
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   725
        yva.setPosition(self.x, self.y, self.height)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   726
        yva.configure(self.data)
1616
fcd8fe41df7e Added GridLinePlot
rgbecker
parents: 1573
diff changeset
   727
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   728
        # 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: 1628
diff changeset
   729
        # use bottom.
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   730
        xAxisCrossesAt = yva.scale(0)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   731
        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: 1628
diff changeset
   732
            y = self.y
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   733
        else:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   734
            y = xAxisCrossesAt
1616
fcd8fe41df7e Added GridLinePlot
rgbecker
parents: 1573
diff changeset
   735
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   736
        xva.setPosition(self.x, y, self.width)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   737
        xva.configure(self.data)
1616
fcd8fe41df7e Added GridLinePlot
rgbecker
parents: 1573
diff changeset
   738
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   739
        back = self.background
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   740
        if isinstance(back, Grid):
1802
878ddb7b513f Use _tickValues instead of valueSteps
rgbecker
parents: 1800
diff changeset
   741
            if back.orientation == 'vertical' and xva._tickValues:
3721
0c93dd8ff567 initial changes from 2to3-3.3
rptlab
parents: 3652
diff changeset
   742
                xpos = list(map(xva.scale, [xva._valueMin] + xva._tickValues))
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   743
                steps = []
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   744
                for i in range(len(xpos)-1):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   745
                    steps.append(xpos[i+1] - xpos[i])
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   746
                back.deltaSteps = steps
1802
878ddb7b513f Use _tickValues instead of valueSteps
rgbecker
parents: 1800
diff changeset
   747
            elif back.orientation == 'horizontal' and yva._tickValues:
3721
0c93dd8ff567 initial changes from 2to3-3.3
rptlab
parents: 3652
diff changeset
   748
                ypos = list(map(yva.scale, [yva._valueMin] + yva._tickValues))
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   749
                steps = []
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   750
                for i in range(len(ypos)-1):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   751
                    steps.append(ypos[i+1] - ypos[i])
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   752
                back.deltaSteps = steps
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   753
        elif isinstance(back, DoubleGrid):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   754
            # Ideally, these lines would not be needed...
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   755
            back.grid0.x = self.x
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   756
            back.grid0.y = self.y
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   757
            back.grid0.width = self.width
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   758
            back.grid0.height = self.height
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   759
            back.grid1.x = self.x
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   760
            back.grid1.y = self.y
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   761
            back.grid1.width = self.width
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   762
            back.grid1.height = self.height
1616
fcd8fe41df7e Added GridLinePlot
rgbecker
parents: 1573
diff changeset
   763
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   764
            # some room left for optimization...
1802
878ddb7b513f Use _tickValues instead of valueSteps
rgbecker
parents: 1800
diff changeset
   765
            if back.grid0.orientation == 'vertical' and xva._tickValues:
3721
0c93dd8ff567 initial changes from 2to3-3.3
rptlab
parents: 3652
diff changeset
   766
                xpos = list(map(xva.scale, [xva._valueMin] + xva._tickValues))
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   767
                steps = []
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   768
                for i in range(len(xpos)-1):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   769
                    steps.append(xpos[i+1] - xpos[i])
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   770
                back.grid0.deltaSteps = steps
1802
878ddb7b513f Use _tickValues instead of valueSteps
rgbecker
parents: 1800
diff changeset
   771
            elif back.grid0.orientation == 'horizontal' and yva._tickValues:
3721
0c93dd8ff567 initial changes from 2to3-3.3
rptlab
parents: 3652
diff changeset
   772
                ypos = list(map(yva.scale, [yva._valueMin] + yva._tickValues))
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   773
                steps = []
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   774
                for i in range(len(ypos)-1):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   775
                    steps.append(ypos[i+1] - ypos[i])
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   776
                back.grid0.deltaSteps = steps
1802
878ddb7b513f Use _tickValues instead of valueSteps
rgbecker
parents: 1800
diff changeset
   777
            if back.grid1.orientation == 'vertical' and xva._tickValues:
3721
0c93dd8ff567 initial changes from 2to3-3.3
rptlab
parents: 3652
diff changeset
   778
                xpos = list(map(xva.scale, [xva._valueMin] + xva._tickValues))
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   779
                steps = []
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   780
                for i in range(len(xpos)-1):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   781
                    steps.append(xpos[i+1] - xpos[i])
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   782
                back.grid1.deltaSteps = steps
1802
878ddb7b513f Use _tickValues instead of valueSteps
rgbecker
parents: 1800
diff changeset
   783
            elif back.grid1.orientation == 'horizontal' and yva._tickValues:
3721
0c93dd8ff567 initial changes from 2to3-3.3
rptlab
parents: 3652
diff changeset
   784
                ypos = list(map(yva.scale, [yva._valueMin] + yva._tickValues))
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   785
                steps = []
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   786
                for i in range(len(ypos)-1):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   787
                    steps.append(ypos[i+1] - ypos[i])
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   788
                back.grid1.deltaSteps = steps
1616
fcd8fe41df7e Added GridLinePlot
rgbecker
parents: 1573
diff changeset
   789
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   790
        self.calcPositions()
1616
fcd8fe41df7e Added GridLinePlot
rgbecker
parents: 1573
diff changeset
   791
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   792
        width, height, scaleFactor = self.width, self.height, self.scaleFactor
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   793
        if scaleFactor and scaleFactor!=1:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   794
            #g = Drawing(scaleFactor*width, scaleFactor*height)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   795
            g.transform = (scaleFactor, 0, 0, scaleFactor,0,0)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   796
        else:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   797
            g = Group()
1616
fcd8fe41df7e Added GridLinePlot
rgbecker
parents: 1573
diff changeset
   798
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   799
        g.add(self.makeBackground())
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   800
        g.add(self.xValueAxis)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   801
        g.add(self.yValueAxis)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   802
        g.add(self.makeLines())
1616
fcd8fe41df7e Added GridLinePlot
rgbecker
parents: 1573
diff changeset
   803
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   804
        return g
1616
fcd8fe41df7e Added GridLinePlot
rgbecker
parents: 1573
diff changeset
   805
1996
0150666f5022 dded in stuff for area plots, fixes to axis formatting etc
rgbecker
parents: 1974
diff changeset
   806
class AreaLinePlot(LinePlot):
2306
5370ae88b2ab Make a couple of files emacs font-lock friendly
jjlee
parents: 2152
diff changeset
   807
    '''we're given data in the form [(X1,Y11,..Y1M)....(Xn,Yn1,...YnM)]'''#'
1934
104a813e8402 Attempt at getting SplitLinePlot & allow for inFill
rgbecker
parents: 1803
diff changeset
   808
    def __init__(self):
104a813e8402 Attempt at getting SplitLinePlot & allow for inFill
rgbecker
parents: 1803
diff changeset
   809
        LinePlot.__init__(self)
104a813e8402 Attempt at getting SplitLinePlot & allow for inFill
rgbecker
parents: 1803
diff changeset
   810
        self._inFill = 1
104a813e8402 Attempt at getting SplitLinePlot & allow for inFill
rgbecker
parents: 1803
diff changeset
   811
        self.reversePlotOrder = 1
2006
92f879e52bbe Add proper data for AreaLinePlot
rgbecker
parents: 1998
diff changeset
   812
        self.data = [(1,20,100,30),(2,11,50,15),(3,15,70,40)]
1934
104a813e8402 Attempt at getting SplitLinePlot & allow for inFill
rgbecker
parents: 1803
diff changeset
   813
104a813e8402 Attempt at getting SplitLinePlot & allow for inFill
rgbecker
parents: 1803
diff changeset
   814
    def draw(self):
104a813e8402 Attempt at getting SplitLinePlot & allow for inFill
rgbecker
parents: 1803
diff changeset
   815
        try:
104a813e8402 Attempt at getting SplitLinePlot & allow for inFill
rgbecker
parents: 1803
diff changeset
   816
            odata = self.data
104a813e8402 Attempt at getting SplitLinePlot & allow for inFill
rgbecker
parents: 1803
diff changeset
   817
            n = len(odata)
104a813e8402 Attempt at getting SplitLinePlot & allow for inFill
rgbecker
parents: 1803
diff changeset
   818
            m = len(odata[0])
104a813e8402 Attempt at getting SplitLinePlot & allow for inFill
rgbecker
parents: 1803
diff changeset
   819
            S = n*[0]
104a813e8402 Attempt at getting SplitLinePlot & allow for inFill
rgbecker
parents: 1803
diff changeset
   820
            self.data = []
3721
0c93dd8ff567 initial changes from 2to3-3.3
rptlab
parents: 3652
diff changeset
   821
            for i in range(1,m):
1934
104a813e8402 Attempt at getting SplitLinePlot & allow for inFill
rgbecker
parents: 1803
diff changeset
   822
                D = []
3721
0c93dd8ff567 initial changes from 2to3-3.3
rptlab
parents: 3652
diff changeset
   823
                for j in range(n):
1934
104a813e8402 Attempt at getting SplitLinePlot & allow for inFill
rgbecker
parents: 1803
diff changeset
   824
                    S[j] = S[j] + odata[j][i]
104a813e8402 Attempt at getting SplitLinePlot & allow for inFill
rgbecker
parents: 1803
diff changeset
   825
                    D.append((odata[j][0],S[j]))
104a813e8402 Attempt at getting SplitLinePlot & allow for inFill
rgbecker
parents: 1803
diff changeset
   826
                self.data.append(D)
104a813e8402 Attempt at getting SplitLinePlot & allow for inFill
rgbecker
parents: 1803
diff changeset
   827
            return LinePlot.draw(self)
104a813e8402 Attempt at getting SplitLinePlot & allow for inFill
rgbecker
parents: 1803
diff changeset
   828
        finally:
104a813e8402 Attempt at getting SplitLinePlot & allow for inFill
rgbecker
parents: 1803
diff changeset
   829
            self.data = odata
104a813e8402 Attempt at getting SplitLinePlot & allow for inFill
rgbecker
parents: 1803
diff changeset
   830
1996
0150666f5022 dded in stuff for area plots, fixes to axis formatting etc
rgbecker
parents: 1974
diff changeset
   831
class SplitLinePlot(AreaLinePlot):
0150666f5022 dded in stuff for area plots, fixes to axis formatting etc
rgbecker
parents: 1974
diff changeset
   832
    def __init__(self):
0150666f5022 dded in stuff for area plots, fixes to axis formatting etc
rgbecker
parents: 1974
diff changeset
   833
        AreaLinePlot.__init__(self)
0150666f5022 dded in stuff for area plots, fixes to axis formatting etc
rgbecker
parents: 1974
diff changeset
   834
        self.xValueAxis = NormalDateXValueAxis()
0150666f5022 dded in stuff for area plots, fixes to axis formatting etc
rgbecker
parents: 1974
diff changeset
   835
        self.yValueAxis = AdjYValueAxis()
0150666f5022 dded in stuff for area plots, fixes to axis formatting etc
rgbecker
parents: 1974
diff changeset
   836
        self.data=[(20030601,0.95,0.05,0.0),(20030701,0.95,0.05,0.0),(20030801,0.95,0.05,0.0),(20030901,0.95,0.05,0.0),(20031001,0.95,0.05,0.0),(20031101,0.95,0.05,0.0),(20031201,0.95,0.05,0.0),(20040101,0.95,0.05,0.0),(20040201,0.95,0.05,0.0),(20040301,0.95,0.05,0.0),(20040401,0.95,0.05,0.0),(20040501,0.95,0.05,0.0),(20040601,0.95,0.05,0.0),(20040701,0.95,0.05,0.0),(20040801,0.95,0.05,0.0),(20040901,0.95,0.05,0.0),(20041001,0.95,0.05,0.0),(20041101,0.95,0.05,0.0),(20041201,0.95,0.05,0.0),(20050101,0.95,0.05,0.0),(20050201,0.95,0.05,0.0),(20050301,0.95,0.05,0.0),(20050401,0.95,0.05,0.0),(20050501,0.95,0.05,0.0),(20050601,0.95,0.05,0.0),(20050701,0.95,0.05,0.0),(20050801,0.95,0.05,0.0),(20050901,0.95,0.05,0.0),(20051001,0.95,0.05,0.0),(20051101,0.95,0.05,0.0),(20051201,0.95,0.05,0.0),(20060101,0.95,0.05,0.0),(20060201,0.95,0.05,0.0),(20060301,0.95,0.05,0.0),(20060401,0.95,0.05,0.0),(20060501,0.95,0.05,0.0),(20060601,0.95,0.05,0.0),(20060701,0.95,0.05,0.0),(20060801,0.95,0.05,0.0),(20060901,0.95,0.05,0.0),(20061001,0.95,0.05,0.0),(20061101,0.95,0.05,0.0),(20061201,0.95,0.05,0.0),(20070101,0.95,0.05,0.0),(20070201,0.95,0.05,0.0),(20070301,0.95,0.05,0.0),(20070401,0.95,0.05,0.0),(20070501,0.95,0.05,0.0),(20070601,0.95,0.05,0.0),(20070701,0.95,0.05,0.0),(20070801,0.95,0.05,0.0),(20070901,0.95,0.05,0.0),(20071001,0.95,0.05,0.0),(20071101,0.95,0.05,0.0),(20071201,0.95,0.05,0.0),(20080101,0.95,0.05,0.0),(20080201,0.95,0.05,0.0),(20080301,0.95,0.05,0.0),(20080401,0.95,0.05,0.0),(20080501,0.95,0.05,0.0),(20080601,0.95,0.05,0.0),(20080701,0.95,0.05,0.0),(20080801,0.95,0.05,0.0),(20080901,0.95,0.05,0.0),(20081001,0.95,0.05,0.0),(20081101,0.95,0.05,0.0),(20081201,0.95,0.05,0.0),(20090101,0.95,0.05,0.0),(20090201,0.91,0.09,0.0),(20090301,0.91,0.09,0.0),(20090401,0.91,0.09,0.0),(20090501,0.91,0.09,0.0),(20090601,0.91,0.09,0.0),(20090701,0.91,0.09,0.0),(20090801,0.91,0.09,0.0),(20090901,0.91,0.09,0.0),(20091001,0.91,0.09,0.0),(20091101,0.91,0.09,0.0),(20091201,0.91,0.09,0.0),(20100101,0.91,0.09,0.0),(20100201,0.81,0.19,0.0),(20100301,0.81,0.19,0.0),(20100401,0.81,0.19,0.0),(20100501,0.81,0.19,0.0),(20100601,0.81,0.19,0.0),(20100701,0.81,0.19,0.0),(20100801,0.81,0.19,0.0),(20100901,0.81,0.19,0.0),(20101001,0.81,0.19,0.0),(20101101,0.81,0.19,0.0),(20101201,0.81,0.19,0.0),(20110101,0.81,0.19,0.0),(20110201,0.72,0.28,0.0),(20110301,0.72,0.28,0.0),(20110401,0.72,0.28,0.0),(20110501,0.72,0.28,0.0),(20110601,0.72,0.28,0.0),(20110701,0.72,0.28,0.0),(20110801,0.72,0.28,0.0),(20110901,0.72,0.28,0.0),(20111001,0.72,0.28,0.0),(20111101,0.72,0.28,0.0),(20111201,0.72,0.28,0.0),(20120101,0.72,0.28,0.0),(20120201,0.53,0.47,0.0),(20120301,0.53,0.47,0.0),(20120401,0.53,0.47,0.0),(20120501,0.53,0.47,0.0),(20120601,0.53,0.47,0.0),(20120701,0.53,0.47,0.0),(20120801,0.53,0.47,0.0),(20120901,0.53,0.47,0.0),(20121001,0.53,0.47,0.0),(20121101,0.53,0.47,0.0),(20121201,0.53,0.47,0.0),(20130101,0.53,0.47,0.0),(20130201,0.44,0.56,0.0),(20130301,0.44,0.56,0.0),(20130401,0.44,0.56,0.0),(20130501,0.44,0.56,0.0),(20130601,0.44,0.56,0.0),(20130701,0.44,0.56,0.0),(20130801,0.44,0.56,0.0),(20130901,0.44,0.56,0.0),(20131001,0.44,0.56,0.0),(20131101,0.44,0.56,0.0),(20131201,0.44,0.56,0.0),(20140101,0.44,0.56,0.0),(20140201,0.36,0.5,0.14),(20140301,0.36,0.5,0.14),(20140401,0.36,0.5,0.14),(20140501,0.36,0.5,0.14),(20140601,0.36,0.5,0.14),(20140701,0.36,0.5,0.14),(20140801,0.36,0.5,0.14),(20140901,0.36,0.5,0.14),(20141001,0.36,0.5,0.14),(20141101,0.36,0.5,0.14),(20141201,0.36,0.5,0.14),(20150101,0.36,0.5,0.14),(20150201,0.3,0.41,0.29),(20150301,0.3,0.41,0.29),(20150401,0.3,0.41,0.29),(20150501,0.3,0.41,0.29),(20150601,0.3,0.41,0.29),(20150701,0.3,0.41,0.29),(20150801,0.3,0.41,0.29),(20150901,0.3,0.41,0.29),(20151001,0.3,0.41,0.29),(20151101,0.3,0.41,0.29),(20151201,0.3,0.41,0.29),(20160101,0.3,0.41,0.29),(20160201,0.26,0.36,0.38),(20160301,0.26,0.36,0.38),(20160401,0.26,0.36,0.38),(20160501,0.26,0.36,0.38),(20160601,0.26,0.36,0.38),(20160701,0.26,0.36,0.38),(20160801,0.26,0.36,0.38),(20160901,0.26,0.36,0.38),(20161001,0.26,0.36,0.38),(20161101,0.26,0.36,0.38),(20161201,0.26,0.36,0.38),(20170101,0.26,0.36,0.38),(20170201,0.2,0.3,0.5),(20170301,0.2,0.3,0.5),(20170401,0.2,0.3,0.5),(20170501,0.2,0.3,0.5),(20170601,0.2,0.3,0.5),(20170701,0.2,0.3,0.5),(20170801,0.2,0.3,0.5),(20170901,0.2,0.3,0.5),(20171001,0.2,0.3,0.5),(20171101,0.2,0.3,0.5),(20171201,0.2,0.3,0.5),(20180101,0.2,0.3,0.5),(20180201,0.13,0.37,0.5),(20180301,0.13,0.37,0.5),(20180401,0.13,0.37,0.5),(20180501,0.13,0.37,0.5),(20180601,0.13,0.37,0.5),(20180701,0.13,0.37,0.5),(20180801,0.13,0.37,0.5),(20180901,0.13,0.37,0.5),(20181001,0.13,0.37,0.5),(20181101,0.13,0.37,0.5),(20181201,0.13,0.37,0.5),(20190101,0.13,0.37,0.5),(20190201,0.1,0.4,0.5),(20190301,0.1,0.4,0.5),(20190401,0.1,0.4,0.5),(20190501,0.1,0.4,0.5),(20190601,0.1,0.4,0.5),(20190701,0.1,0.4,0.5),(20190801,0.1,0.4,0.5),(20190901,0.1,0.4,0.5),(20191001,0.1,0.4,0.5),(20191101,0.1,0.4,0.5),(20191201,0.1,0.4,0.5),(20200101,0.1,0.4,0.5)]
0150666f5022 dded in stuff for area plots, fixes to axis formatting etc
rgbecker
parents: 1974
diff changeset
   837
        self.yValueAxis.requiredRange = None
0150666f5022 dded in stuff for area plots, fixes to axis formatting etc
rgbecker
parents: 1974
diff changeset
   838
        self.yValueAxis.leftAxisPercent = 0
0150666f5022 dded in stuff for area plots, fixes to axis formatting etc
rgbecker
parents: 1974
diff changeset
   839
        self.yValueAxis.leftAxisOrigShiftMin = 0
0150666f5022 dded in stuff for area plots, fixes to axis formatting etc
rgbecker
parents: 1974
diff changeset
   840
        self.yValueAxis.leftAxisOrigShiftIPC = 0
0150666f5022 dded in stuff for area plots, fixes to axis formatting etc
rgbecker
parents: 1974
diff changeset
   841
        self.lines[0].strokeColor = colors.toColor(0x0033cc)
0150666f5022 dded in stuff for area plots, fixes to axis formatting etc
rgbecker
parents: 1974
diff changeset
   842
        self.lines[1].strokeColor = colors.toColor(0x99c3ff)
0150666f5022 dded in stuff for area plots, fixes to axis formatting etc
rgbecker
parents: 1974
diff changeset
   843
        self.lines[2].strokeColor = colors.toColor(0xCC0033)
0150666f5022 dded in stuff for area plots, fixes to axis formatting etc
rgbecker
parents: 1974
diff changeset
   844
1628
b9328908d6e6 Added ScatterPlot
rgbecker
parents: 1616
diff changeset
   845
def _maxWidth(T, fontName, fontSize):
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   846
    '''return max stringWidth for the list of strings T'''
3800
e8547b00eb59 attempt to remove old type testing
robin
parents: 3721
diff changeset
   847
    if not isinstance(T,(tuple,list)): T = (T,)
3721
0c93dd8ff567 initial changes from 2to3-3.3
rptlab
parents: 3652
diff changeset
   848
    T = [_f for _f in T if _f]
0c93dd8ff567 initial changes from 2to3-3.3
rptlab
parents: 3652
diff changeset
   849
    return T and max(list(map(lambda t,sW=stringWidth,fN=fontName, fS=fontSize: sW(t,fN,fS),T))) or 0
1628
b9328908d6e6 Added ScatterPlot
rgbecker
parents: 1616
diff changeset
   850
b9328908d6e6 Added ScatterPlot
rgbecker
parents: 1616
diff changeset
   851
class ScatterPlot(LinePlot):
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   852
    """A scatter plot widget"""
1628
b9328908d6e6 Added ScatterPlot
rgbecker
parents: 1616
diff changeset
   853
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   854
    _attrMap = AttrMap(BASE=LinePlot,
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   855
                    width = AttrMapValue(isNumber, desc="Width of the area inside the axes"),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   856
                    height = AttrMapValue(isNumber, desc="Height of the area inside the axes"),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   857
                    outerBorderOn = AttrMapValue(isBoolean, desc="Is there an outer border (continuation of axes)"),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   858
                    outerBorderColor = AttrMapValue(isColorOrNone, desc="Color of outer border (if any)"),
3271
c14b161b62bf attributes help messages
meitham
parents: 3248
diff changeset
   859
                    labelOffset = AttrMapValue(isNumber, desc="Space between label and Axis (or other labels)",advancedUsage=1),
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   860
                    axisTickLengths = AttrMapValue(isNumber, desc="Lenth of the ticks on both axes"),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   861
                    axisStrokeWidth = AttrMapValue(isNumber, desc="Stroke width for both axes"),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   862
                    xLabel = AttrMapValue(isString, desc="Label for the whole X-Axis"),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   863
                    yLabel = AttrMapValue(isString, desc="Label for the whole Y-Axis"),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   864
                    data = AttrMapValue(isAnything, desc='Data points - a list of x/y tuples.'),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   865
                    strokeColor = AttrMapValue(isColorOrNone, desc='Color used for border of plot area.'),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   866
                    fillColor = AttrMapValue(isColorOrNone, desc='Color used for background interior of plot area.'),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   867
                    leftPadding = AttrMapValue(isNumber, desc='Padding on left of drawing'),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   868
                    rightPadding = AttrMapValue(isNumber, desc='Padding on right of drawing'),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   869
                    topPadding = AttrMapValue(isNumber, desc='Padding at top of drawing'),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   870
                    bottomPadding = AttrMapValue(isNumber, desc='Padding at bottom of drawing'),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   871
                    )
1628
b9328908d6e6 Added ScatterPlot
rgbecker
parents: 1616
diff changeset
   872
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   873
    def __init__(self):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   874
        LinePlot.__init__(self)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   875
        self.width = 142
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   876
        self.height = 77
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   877
        self.outerBorderOn = 1
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   878
        self.outerBorderColor = colors.black
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   879
        self.background = None
1628
b9328908d6e6 Added ScatterPlot
rgbecker
parents: 1616
diff changeset
   880
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   881
        _labelOffset = 3
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   882
        _axisTickLengths = 2
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   883
        _axisStrokeWidth = 0.5
1628
b9328908d6e6 Added ScatterPlot
rgbecker
parents: 1616
diff changeset
   884
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   885
        self.yValueAxis.valueMin = None
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   886
        self.yValueAxis.valueMax = None
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   887
        self.yValueAxis.valueStep = None
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   888
        self.yValueAxis.labelTextFormat  = '%s'
1628
b9328908d6e6 Added ScatterPlot
rgbecker
parents: 1616
diff changeset
   889
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   890
        self.xLabel="X Lable"
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   891
        self.xValueAxis.labels.fontSize = 6
1628
b9328908d6e6 Added ScatterPlot
rgbecker
parents: 1616
diff changeset
   892
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   893
        self.yLabel="Y Lable"
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   894
        self.yValueAxis.labels.fontSize = 6
1628
b9328908d6e6 Added ScatterPlot
rgbecker
parents: 1616
diff changeset
   895
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   896
        self.data =[((0.030, 62.73),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   897
                     (0.074, 54.363),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   898
                     (1.216, 17.964)),
1628
b9328908d6e6 Added ScatterPlot
rgbecker
parents: 1616
diff changeset
   899
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   900
                     ((1.360, 11.621),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   901
                     (1.387, 50.011),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   902
                     (1.428, 68.953)),
1628
b9328908d6e6 Added ScatterPlot
rgbecker
parents: 1616
diff changeset
   903
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   904
                     ((1.444, 86.888),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   905
                     (1.754, 35.58),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   906
                     (1.766, 36.05))]
1628
b9328908d6e6 Added ScatterPlot
rgbecker
parents: 1616
diff changeset
   907
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   908
        #values for lineplot
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   909
        self.joinedLines = 0
1628
b9328908d6e6 Added ScatterPlot
rgbecker
parents: 1616
diff changeset
   910
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   911
        self.leftPadding=5
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   912
        self.rightPadding=10
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   913
        self.topPadding=5
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   914
        self.bottomPadding=5
1628
b9328908d6e6 Added ScatterPlot
rgbecker
parents: 1616
diff changeset
   915
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   916
        self.x = self.leftPadding+_axisTickLengths+(_labelOffset*2)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   917
        self.x=self.x+_maxWidth(str(self.yValueAxis.valueMax), self.yValueAxis.labels.fontName, self.yValueAxis.labels.fontSize)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   918
        self.y = self.bottomPadding+_axisTickLengths+_labelOffset+self.xValueAxis.labels.fontSize
1628
b9328908d6e6 Added ScatterPlot
rgbecker
parents: 1616
diff changeset
   919
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1677
diff changeset
   920
        self.xValueAxis.labels.dy = -_labelOffset
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   921
        self.xValueAxis.tickDown = _axisTickLengths
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   922
        self.xValueAxis.strokeWidth = _axisStrokeWidth
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   923
        self.xValueAxis.rangeRound='both'
1683
7fa753e4420a Removed all trailing whitespace
andy_robinson
parents: 1677
diff changeset
   924
        self.yValueAxis.labels.dx = -_labelOffset
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   925
        self.yValueAxis.tickLeft = _axisTickLengths
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   926
        self.yValueAxis.strokeWidth = _axisStrokeWidth
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   927
        self.yValueAxis.rangeRound='both'
1628
b9328908d6e6 Added ScatterPlot
rgbecker
parents: 1616
diff changeset
   928
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   929
        self.lineLabelFormat="%.2f"
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   930
        self.lineLabels.fontSize = 5
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   931
        self.lineLabels.boxAnchor = 'e'
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   932
        self.lineLabels.dx             = -2
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   933
        self.lineLabelNudge = 0
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   934
        self.lines.symbol=makeMarker('FilledCircle',size=3)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   935
        self.lines[1].symbol=makeMarker('FilledDiamond',size=3)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   936
        self.lines[2].symbol=makeMarker('FilledSquare',size=3)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   937
        self.lines[2].strokeColor = colors.green
1628
b9328908d6e6 Added ScatterPlot
rgbecker
parents: 1616
diff changeset
   938
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   939
    def _getDrawingDimensions(self):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   940
        tx = self.leftPadding+self.yValueAxis.tickLeft+(self.yValueAxis.labels.dx*2)+self.xValueAxis.labels.fontSize
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   941
        tx=tx+(5*_maxWidth(str(self.yValueAxis.valueMax), self.yValueAxis.labels.fontName, self.yValueAxis.labels.fontSize))
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   942
        tx=tx+self.width+self.rightPadding
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   943
        t=('%.2f%%'%self.xValueAxis.valueMax)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   944
        tx=tx+(_maxWidth(t, self.yValueAxis.labels.fontName, self.yValueAxis.labels.fontSize))
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   945
        ty = self.bottomPadding+self.xValueAxis.tickDown+(self.xValueAxis.labels.dy*2)+(self.xValueAxis.labels.fontSize*2)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   946
        ty=ty+self.yValueAxis.labels.fontSize+self.height+self.topPadding
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   947
        #print (tx, ty)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   948
        return (tx,ty)
1628
b9328908d6e6 Added ScatterPlot
rgbecker
parents: 1616
diff changeset
   949
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   950
    def demo(self,drawing=None):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   951
        if not drawing:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   952
            tx,ty=self._getDrawingDimensions()
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   953
            drawing = Drawing(tx,ty)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   954
        drawing.add(self.draw())
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   955
        return drawing
1628
b9328908d6e6 Added ScatterPlot
rgbecker
parents: 1616
diff changeset
   956
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   957
    def draw(self):
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   958
        ascent=getFont(self.xValueAxis.labels.fontName).face.ascent
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   959
        if ascent==0:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   960
            ascent=0.718 # default (from helvetica)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   961
        ascent=ascent*self.xValueAxis.labels.fontSize # normalize
1628
b9328908d6e6 Added ScatterPlot
rgbecker
parents: 1616
diff changeset
   962
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   963
        #basic LinePlot - does the Axes, Ticks etc
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   964
        lp = LinePlot.draw(self)
1628
b9328908d6e6 Added ScatterPlot
rgbecker
parents: 1616
diff changeset
   965
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   966
        xLabel = self.xLabel
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   967
        if xLabel: #Overall label for the X-axis
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   968
            xl=Label()
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   969
            xl.x = (self.x+self.width)/2.0
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   970
            xl.y = 0
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   971
            xl.fontName = self.xValueAxis.labels.fontName
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   972
            xl.fontSize = self.xValueAxis.labels.fontSize
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   973
            xl.setText(xLabel)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   974
            lp.add(xl)
1628
b9328908d6e6 Added ScatterPlot
rgbecker
parents: 1616
diff changeset
   975
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   976
        yLabel = self.yLabel
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   977
        if yLabel: #Overall label for the Y-axis
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   978
            yl=Label()
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   979
            yl.angle = 90
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   980
            yl.x = 0
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   981
            yl.y = (self.y+self.height/2.0)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   982
            yl.fontName = self.yValueAxis.labels.fontName
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   983
            yl.fontSize = self.yValueAxis.labels.fontSize
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   984
            yl.setText(yLabel)
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   985
            lp.add(yl)
1628
b9328908d6e6 Added ScatterPlot
rgbecker
parents: 1616
diff changeset
   986
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   987
        # do a bounding box - in the same style as the axes
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   988
        if self.outerBorderOn:
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   989
            lp.add(Rect(self.x, self.y, self.width, self.height,
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   990
                       strokeColor = self.outerBorderColor,
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   991
                       strokeWidth = self.yValueAxis.strokeWidth,
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   992
                       fillColor = None))
1628
b9328908d6e6 Added ScatterPlot
rgbecker
parents: 1616
diff changeset
   993
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   994
        lp.shift(self.leftPadding, self.bottomPadding)
1628
b9328908d6e6 Added ScatterPlot
rgbecker
parents: 1616
diff changeset
   995
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   996
        return lp
737
8f0e58918da9 Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff changeset
   997
839
0782188b7a4c Splitted draw() method.
dinu_gherman
parents: 828
diff changeset
   998
def sample1a():
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
   999
    "A line plot with non-equidistant points in x-axis."
1628
b9328908d6e6 Added ScatterPlot
rgbecker
parents: 1616
diff changeset
  1000
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
  1001
    drawing = Drawing(400, 200)
737
8f0e58918da9 Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff changeset
  1002
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
  1003
    data = [
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
  1004
            ((1,1), (2,2), (2.5,1), (3,3), (4,5)),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
  1005
            ((1,2), (2,3), (2.5,2), (3.5,5), (4,6))
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
  1006
        ]
1628
b9328908d6e6 Added ScatterPlot
rgbecker
parents: 1616
diff changeset
  1007
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
  1008
    lp = LinePlot()
839
0782188b7a4c Splitted draw() method.
dinu_gherman
parents: 828
diff changeset
  1009
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
  1010
    lp.x = 50
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
  1011
    lp.y = 50
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
  1012
    lp.height = 125
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
  1013
    lp.width = 300
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
  1014
    lp.data = data
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
  1015
    lp.joinedLines = 1
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
  1016
    lp.strokeColor = colors.black
839
0782188b7a4c Splitted draw() method.
dinu_gherman
parents: 828
diff changeset
  1017
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
  1018
    lp.lines.symbol = makeMarker('UK_Flag')
1336
f016b2e924dc Use UK flag in example
rgbecker
parents: 1330
diff changeset
  1019
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
  1020
    lp.lines[0].strokeWidth = 2
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
  1021
    lp.lines[1].strokeWidth = 4
920
254852733833 Switched to using PropHolder superclass for LinePlotProperties.
dinu_gherman
parents: 915
diff changeset
  1022
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
  1023
    lp.xValueAxis.valueMin = 0
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
  1024
    lp.xValueAxis.valueMax = 5
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
  1025
    lp.xValueAxis.valueStep = 1
839
0782188b7a4c Splitted draw() method.
dinu_gherman
parents: 828
diff changeset
  1026
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
  1027
    lp.yValueAxis.valueMin = 0
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
  1028
    lp.yValueAxis.valueMax = 7
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
  1029
    lp.yValueAxis.valueStep = 1
1628
b9328908d6e6 Added ScatterPlot
rgbecker
parents: 1616
diff changeset
  1030
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
  1031
    drawing.add(lp)
839
0782188b7a4c Splitted draw() method.
dinu_gherman
parents: 828
diff changeset
  1032
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
  1033
    return drawing
839
0782188b7a4c Splitted draw() method.
dinu_gherman
parents: 828
diff changeset
  1034
0782188b7a4c Splitted draw() method.
dinu_gherman
parents: 828
diff changeset
  1035
0782188b7a4c Splitted draw() method.
dinu_gherman
parents: 828
diff changeset
  1036
def sample1b():
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
  1037
    "A line plot with non-equidistant points in x-axis."
1628
b9328908d6e6 Added ScatterPlot
rgbecker
parents: 1616
diff changeset
  1038
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
  1039
    drawing = Drawing(400, 200)
839
0782188b7a4c Splitted draw() method.
dinu_gherman
parents: 828
diff changeset
  1040
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
  1041
    data = [
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
  1042
            ((1,1), (2,2), (2.5,1), (3,3), (4,5)),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
  1043
            ((1,2), (2,3), (2.5,2), (3.5,5), (4,6))
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
  1044
        ]
1628
b9328908d6e6 Added ScatterPlot
rgbecker
parents: 1616
diff changeset
  1045
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
  1046
    lp = LinePlot()
737
8f0e58918da9 Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff changeset
  1047
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
  1048
    lp.x = 50
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
  1049
    lp.y = 50
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
  1050
    lp.height = 125
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
  1051
    lp.width = 300
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
  1052
    lp.data = data
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
  1053
    lp.joinedLines = 1
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
  1054
    lp.lines.symbol = makeMarker('Circle')
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
  1055
    lp.lineLabelFormat = '%2.0f'
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
  1056
    lp.strokeColor = colors.black
737
8f0e58918da9 Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff changeset
  1057
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
  1058
    lp.xValueAxis.valueMin = 0
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
  1059
    lp.xValueAxis.valueMax = 5
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
  1060
    lp.xValueAxis.valueSteps = [1, 2, 2.5, 3, 4, 5]
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
  1061
    lp.xValueAxis.labelTextFormat = '%2.1f'
737
8f0e58918da9 Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff changeset
  1062
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
  1063
    lp.yValueAxis.valueMin = 0
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
  1064
    lp.yValueAxis.valueMax = 7
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
  1065
    lp.yValueAxis.valueStep = 1
1628
b9328908d6e6 Added ScatterPlot
rgbecker
parents: 1616
diff changeset
  1066
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
  1067
    drawing.add(lp)
737
8f0e58918da9 Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff changeset
  1068
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
  1069
    return drawing
737
8f0e58918da9 Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff changeset
  1070
8f0e58918da9 Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff changeset
  1071
839
0782188b7a4c Splitted draw() method.
dinu_gherman
parents: 828
diff changeset
  1072
def sample1c():
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
  1073
    "A line plot with non-equidistant points in x-axis."
1628
b9328908d6e6 Added ScatterPlot
rgbecker
parents: 1616
diff changeset
  1074
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
  1075
    drawing = Drawing(400, 200)
737
8f0e58918da9 Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff changeset
  1076
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
  1077
    data = [
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
  1078
            ((1,1), (2,2), (2.5,1), (3,3), (4,5)),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
  1079
            ((1,2), (2,3), (2.5,2), (3.5,5), (4,6))
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
  1080
        ]
1628
b9328908d6e6 Added ScatterPlot
rgbecker
parents: 1616
diff changeset
  1081
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
  1082
    lp = LinePlot()
737
8f0e58918da9 Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff changeset
  1083
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
  1084
    lp.x = 50
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
  1085
    lp.y = 50
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
  1086
    lp.height = 125
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
  1087
    lp.width = 300
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
  1088
    lp.data = data
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
  1089
    lp.joinedLines = 1
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
  1090
    lp.lines[0].symbol = makeMarker('FilledCircle')
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
  1091
    lp.lines[1].symbol = makeMarker('Circle')
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
  1092
    lp.lineLabelFormat = '%2.0f'
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
  1093
    lp.strokeColor = colors.black
737
8f0e58918da9 Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff changeset
  1094
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
  1095
    lp.xValueAxis.valueMin = 0
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
  1096
    lp.xValueAxis.valueMax = 5
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
  1097
    lp.xValueAxis.valueSteps = [1, 2, 2.5, 3, 4, 5]
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
  1098
    lp.xValueAxis.labelTextFormat = '%2.1f'
737
8f0e58918da9 Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff changeset
  1099
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
  1100
    lp.yValueAxis.valueMin = 0
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
  1101
    lp.yValueAxis.valueMax = 7
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
  1102
    lp.yValueAxis.valueSteps = [1, 2, 3, 5, 6]
1628
b9328908d6e6 Added ScatterPlot
rgbecker
parents: 1616
diff changeset
  1103
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
  1104
    drawing.add(lp)
737
8f0e58918da9 Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff changeset
  1105
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
  1106
    return drawing
737
8f0e58918da9 Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff changeset
  1107
8f0e58918da9 Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff changeset
  1108
8f0e58918da9 Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff changeset
  1109
def preprocessData(series):
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
  1110
    "Convert date strings into seconds and multiply values by 100."
737
8f0e58918da9 Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff changeset
  1111
3721
0c93dd8ff567 initial changes from 2to3-3.3
rptlab
parents: 3652
diff changeset
  1112
    return [(str2seconds(x[0]), x[1]*100) for x in series]
737
8f0e58918da9 Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff changeset
  1113
8f0e58918da9 Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff changeset
  1114
8f0e58918da9 Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff changeset
  1115
def sample2():
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
  1116
    "A line plot with non-equidistant points in x-axis."
1628
b9328908d6e6 Added ScatterPlot
rgbecker
parents: 1616
diff changeset
  1117
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
  1118
    drawing = Drawing(400, 200)
737
8f0e58918da9 Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff changeset
  1119
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
  1120
    data = [
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
  1121
        (('25/11/1991',1),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
  1122
         ('30/11/1991',1.000933333),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
  1123
         ('31/12/1991',1.0062),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
  1124
         ('31/01/1992',1.0112),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
  1125
         ('29/02/1992',1.0158),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
  1126
         ('31/03/1992',1.020733333),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
  1127
         ('30/04/1992',1.026133333),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
  1128
         ('31/05/1992',1.030266667),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
  1129
         ('30/06/1992',1.034466667),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
  1130
         ('31/07/1992',1.038733333),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
  1131
         ('31/08/1992',1.0422),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
  1132
         ('30/09/1992',1.045533333),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
  1133
         ('31/10/1992',1.049866667),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
  1134
         ('30/11/1992',1.054733333),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
  1135
         ('31/12/1992',1.061),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
  1136
         ),
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
  1137
        ]
737
8f0e58918da9 Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff changeset
  1138
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
  1139
    data[0] = preprocessData(data[0])
1628
b9328908d6e6 Added ScatterPlot
rgbecker
parents: 1616
diff changeset
  1140
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
  1141
    lp = LinePlot()
737
8f0e58918da9 Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff changeset
  1142
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
  1143
    lp.x = 50
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
  1144
    lp.y = 50
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
  1145
    lp.height = 125
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
  1146
    lp.width = 300
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
  1147
    lp.data = data
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
  1148
    lp.joinedLines = 1
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
  1149
    lp.lines.symbol = makeMarker('FilledDiamond')
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
  1150
    lp.strokeColor = colors.black
737
8f0e58918da9 Initial checkin, replacing previous trailing digit filenames.
dinu_gherman
parents:
diff changeset
  1151
1677
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
  1152
    start = mktime(mkTimeTuple('25/11/1991'))
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
  1153
    t0 = mktime(mkTimeTuple('30/11/1991'))
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_robinson
parents: 1628
diff changeset
  1154
    t1 = mktime(mkTimeTuple('31/12/1991'))
1450177dd19e Exterminated all tab characters and added a test to make sure
andy_r&#