This file is indexed.

/usr/share/pyshared/gdchart.py is in python-gdchart2 0.beta1-3.4+b6.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
# PyGDChart
# 
# Copyright (c) 2003, Nullcube Pty Ltd
# All rights reserved.
# 
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# 
# *   Redistributions of source code must retain the above copyright notice, this
#     list of conditions and the following disclaimer.
# *   Redistributions in binary form must reproduce the above copyright notice,
#     this list of conditions and the following disclaimer in the documentation
#     and/or other materials provided with the distribution.
# *   Neither the name of Nullcube nor the names of its contributors may be used to
#     endorse or promote products derived from this software without specific prior
#     written permission.
# 
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
"""
PyGDChart is an interface to the gdchart graphing library.
"""
import types
import _gdchartc

class GDChartError(Exception): pass

class _Bucket:
    """
        An internal PyGDChart general dataholder class. 
    """
    def __init__(self, **kwargs):
        self.__dict__ = kwargs

def _uniformLength(*lst):
    """
        Takes a list of lists, and tests wether all lists have the same length.
        Returns a 0 if lengths differ, 1 if not.
        This is an internal PyGDChart utility function.
    """
    baselen = len(lst[0])
    for l in lst:
        if len(l) != baselen:
            return -1
    return baselen

def _flattenList(*lst):
    """
        Takes a set of lists, and flattens them by appending them all
        together. 
        This is an internal PyGDChart utility function.
    """
    flat = []
    for i in lst:
        flat.extend(i)
    return flat


class RGB:
    """
        A simple class for representing RGB colors.
    """
    def __init__(self, r=0, g=0, b=0):
        self.r, self.g, self.b = r, g, b
        self._sanity()

    def _sanity(self):
        checks = [0 <= i <= 256 for i in (self.r, self.g, self.b)]
        if 0 in checks:
            raise ValueError("All RGB values should be 0 <= val <= 100")

    def __int__(self):
        self._sanity()
        intval = self.r*(256**2)
        intval += self.g*(256)
        intval += self.b
        return intval

    def __hex__(self):
        return hex(int(self))

    def __repr__(self):
        return hex(self)


def rgbFactory(color):
    """
        Manufacture an RGB object by colour name. Included colours are:
            black, white, blue, green, yellow, red, orange
    """
    # This should be re-written using a dictionary.
    if color == "black":
        return RGB(0,0,0)
    elif color == "white":
        return RGB(255,255,255)
    elif color == "blue":
        return RGB(50,50,204)
    elif color == "green":
        return RGB(37,180,21)
    elif color == "yellow":
        return RGB(255,255,21)
    elif color == "red":
        return RGB(255,0,0)
    elif color == "orange":
        return RGB(255,127,0)
    raise GDChartError, "No such colour: %s."%color


class ChartBase(object):
    """
        Base class of both Pie and Graph chart classes.
    """
    _ImageTypes = {
        "GIF":      _gdchartc.GDC_GIF,
        "JPEG":     _gdchartc.GDC_JPEG,
        "PNG":      _gdchartc.GDC_PNG,
        "WBMP":     _gdchartc.GDC_WBMP
    }
    _FontSizes = {
        "TINY":     _gdchartc.GDC_TINY,
        "SMALL":    _gdchartc.GDC_SMALL,
        "MEDBOLD":  _gdchartc.GDC_MEDBOLD,
        "LARGE":    _gdchartc.GDC_LARGE,
        "GIANT":    _gdchartc.GDC_GIANT
    }
    _lookupOptions = {}
    _maskOptions = {}
    def __init__(self):
        self.__dict__["_options"] = {}
        self.__dict__["_width"] = 500
        self.__dict__["_height"] = 500
        self.__dict__["_data"] = None
        self.__dict__["_labels"] = None
        self.__dict__["_datalen"] = None
        self.__dict__["_scatterPoints"] = None

    def __getattr__(self, attr):
        try:
            return self.getOption(attr)
        except ValueError:
            raise AttributeError

    def __setattr__(self, attr, val):
        try:
            return self.setOption(attr, val)
        except ValueError:
            if self.__dict__.has_key(attr):
                self.__dict__[attr] = val
            else:
                raise AttributeError

    def _actualiseOptions(self):
        for i in self._defaultOptions.values():
            _gdchartc.setOption(self._myType, i[0], i[2])
        for k, v in self._options.iteritems():
            index = self._defaultOptions[k][0]
            _gdchartc.setOption(self._myType, index, v)
        _gdchartc.setScatter(self._scatterPoints)

    def setOption(self, option, myval):
        """
            Set an option. Using this function explicitly is discouraged - it
            is equivalent to using explicit attribute assignment, like so:
                myclass.foo = val
        """
        if self._defaultOptions.has_key(option):
            if self._lookupOptions.has_key(option):
                # We have to look the value up in our dictionary
                if self._lookupOptions[option].has_key(myval):
                    val = self._lookupOptions[option][myval]
                else:
                    values = ", ".join([k for k in self._lookupOptions[option].keys()])
                    raise GDChartError("%s must be one of the following: %s"%(option, values))
            elif self._maskOptions.has_key(option):
                val = 0
                for i in myval:
                    bits = self._maskOptions[option].get(i, None)
                    if bits is not None:
                        val |= bits
                    else:
                        values = ", ".join([k for k in self._maskOptions[option].keys()])
                        raise GDChartError("%s must be a list chosen from the following strings: %s"%
                                                                                        (option, values))
            else:
                # Now we do some standard format checks
                type = self._defaultOptions[option][1]
                if type == _gdchartc.OPT_FLOAT:
                    try:
                        val = float(myval)
                    except ValueError:
                        raise GDChartError("%s must be representable as a float."%(option))
                elif type in (  _gdchartc.OPT_FONTSIZE, 
                                _gdchartc.OPT_INT,
                                _gdchartc.OPT_LONG,
                                _gdchartc.OPT_SHORT,
                                _gdchartc.OPT_USHORT,
                                _gdchartc.OPT_UCHAR,
                                _gdchartc.OPT_CHAR):
                    try:
                        val = int(myval)
                    except ValueError:
                        raise GDChartError("%s must be representable as an int."%(option))
                elif type == _gdchartc.OPT_COLOR:
                    try:
                        rgb = rgbFactory(myval)
                    except GDChartError:
                        try:
                            val = int(myval)
                        except ValueError:
                            raise GDChartError("%s must be representable as an int."%(option))
                    else:
                        val = int(rgb)
                elif type == _gdchartc.OPT_PERCENT:
                    try:
                        val = int(myval)
                    except ValueError:
                        raise GDChartError("%s must be representable as an int."%(option))
                    if not (0 <= val <= 100):
                        raise GDChartError, "Percentage must be > 0, and < 100"
                elif type == _gdchartc.OPT_COLOR_A:
                    try:
                        colours = [rgbFactory(i) for i in myval]
                    except GDChartError:
                        colours = myval
                    try:
                        val = [int(i) for i in colours]
                    except ValueError:
                        raise GDChartError("%s must be representable as a list of ints."%(option))
                elif type in [_gdchartc.OPT_COLOR_A, _gdchartc.OPT_INT_A, _gdchartc.OPT_BOOL_A]:
                    try:
                        val = [int(i) for i in myval]
                    except ValueError:
                        raise GDChartError("%s must be representable as a list of ints."%(option))
                else:
                    val = myval
            self.__dict__["_options"][option] = val
        elif option == "width":
            self.__dict__["_width"] = int(myval)
        elif option == "height":
            self.__dict__["_height"] = int(myval)
        else:
            raise ValueError, "No such option: %s"%option

    def getOption(self, option):
        """
            Retrieve an option. Using this function is equivalent to just
            referring to an option as a chart-object attribute.
        """
        if self._options.has_key(option):
            # Now convert it to a value the user will recognise...
            val = self._options[option]
            if self._lookupOptions.has_key(option):
                for k, v in self._lookupOptions[option].items():
                    if v == val:
                        return k
                else:
                    raise GDChartError, "Lookup value not known - this should never happen. Please contact software authors."
            elif self._maskOptions.has_key(option):
                lst = []
                for k, v in self._maskOptions[option].items():
                    if (val&v):
                        lst.append(k)
                return lst
            else:
                return self._options[option]
        elif self._defaultOptions.has_key(option):
            return self._defaultOptions[option][2]
        elif option == "width":
            return self._width
        elif option == "height":
            return self._height
        else:
            raise ValueError, "No such option: %s"%option

    def getAllOptions(self):
        """
            Retrieve a dictionary of all options.
        """
        x = {}
        for i in self._defaultOptions:
            x[i] = self.getOption(i)
        x["width"] = self._width
        x["height"] = self._height
        return x

    def restoreDefaultOptions(self):
        """
            Restore options to their default values. 
        """
        self._options = {}
        self._scatterPoints = None

    def setLabels(self, labels):
        """
            Set chart labels. The argument is a single list of strings.
        """
        if self._datalen:
            if len(labels) != self._datalen:
                raise GDChartError, "List of labels must have same length as data."
        self._labels = labels


class PieBase(ChartBase):
    """
        Base class of all Pie chart classes.
    """
    _myType = _gdchartc.PIE
    _defaultOptions = _gdchartc.getOptions(_gdchartc.PIE)
    _ChartTypes = {
        "3D":                   _gdchartc.GDC_3DPIE,
        "2D":                   _gdchartc.GDC_2DPIE,
    }
    _PercentPlacement = {
        "NONE":                 _gdchartc.GDCPIE_PCT_NONE,
        "ABOVE":                _gdchartc.GDCPIE_PCT_ABOVE,
        "BELOW":                _gdchartc.GDCPIE_PCT_BELOW,
        "RIGHT":                _gdchartc.GDCPIE_PCT_RIGHT,
        "LEFT":                 _gdchartc.GDCPIE_PCT_LEFT,
    }
    _lookupOptions = {
        "title_size":           ChartBase._FontSizes,
        "label_size":           ChartBase._FontSizes,
        "image_type":           ChartBase._ImageTypes,
        "percent_labels":       _PercentPlacement,
    }
    def __init__(self, *args, **kwargs):
        ChartBase.__init__(self, *args, **kwargs)

    def _conformanceCheck(self):
        if self._labels:
            if self._datalen:
                if self._datalen != len(self._labels):
                    raise GDChartError, "Datasets must be of same length as list of labels."

    def draw(self, filedef):
        """
            Draw a graph to filename. 
        """
        if not self._datalen:
            raise GDChartError, "No data to graph"
        if type(filedef) in types.StringTypes:
            filedef = open(filedef, "w")
        self._actualiseOptions()
        try:
            _gdchartc.out_pie(   self._width, 
                                    self._height,
                                    filedef,
                                    self._type,
                                    self._datalen,
                                    self._labels,               
                                    self._data,
                                )
        except _gdchartc.PGError, val:
            raise GDChartError, val

    def setData(self, *data):
        """
            Set pie data to be graphed. 
            mypie.setData(1, 2, 3, 4)
        """
        self._datalen = len(data)
        self._data = data
        self._conformanceCheck()

class Pie(PieBase): 
    """
        A 2D pie chart.
    """
    _type = _gdchartc.GDC_2DPIE

class Pie3D(PieBase): 
    """
        A 3D pie chart.
    """
    _type = _gdchartc.GDC_3DPIE


class Scatter(object):
    """
        This class represents a scatter point. You would normally construct an
        array of these to pass to the setScatter method of graph classes. 
        
        The constructor takes the following arguments:
            type        - Scatter graph types are:
                                    TRIANGLE_DOWN
                                    TRIANGLE_UP
                                    CIRCLE
            point       - X-axis co-ordinate
            val         - Y-axis co-ordinate
            width       - 0-100%
            color       - An RGB object, or an integer representing the point colour.
    """
    _ScatterTypes = {
        "TRIANGLE_DOWN":        _gdchartc.GDC_SCATTER_TRIANGLE_DOWN,
        "TRIANGLE_UP":          _gdchartc.GDC_SCATTER_TRIANGLE_UP,
        "CIRCLE":               _gdchartc.GDC_SCATTER_CIRCLE,
    }
    def __init__(self, point, val, type="TRIANGLE_DOWN", width=100, color="white"):
        self.type = type
        self.point = point
        self.val = val
        self.width = width
        try:
            color = rgbFactory(color)
        except GDChartError:
            pass
        try:
            self.color = int(color)
        except ValueError:
            raise GDChartError, "Colour must be representable as an int."

    def _setType(self, val):
        if not self._ScatterTypes.has_key(val):
            values = ", ".join([k for k in self._ScatterTypes.keys()])
            raise ValueError("Scatter type must be one of %s"%values)
        else:
            self._type = self._ScatterTypes[val]

    def _getType(self):
        for k, v in self._ScatterTypes.items():
            if (v == self._type):
                return k
        else:
            raise GDChartError("Unknown type set. This should never happen.")

    def _setWidth(self, val):
        i = int(val)
        if  (i < 0) or (i > 100): 
            raise ValueError("Width must be 0 > width > 100.")
        self._width = val

    def _getWidth(self):
        return self._width 
            
    type = property(_getType, _setType)
    width = property(_getWidth, _setWidth)


class GraphBase(ChartBase):
    """
        Base class for all Graph charts.
    """
    _myType = _gdchartc.GRAPH
    _defaultOptions = _gdchartc.getOptions(_gdchartc.GRAPH)
    _StackTypes = {
        "DEPTH":                _gdchartc.GDC_STACK_DEPTH,
        "SUM":                  _gdchartc.GDC_STACK_SUM,
        "BESIDE":               _gdchartc.GDC_STACK_BESIDE,
        "LAYER":                _gdchartc.GDC_STACK_LAYER,
    }
    _TickTypes = {
        "LABELS":               _gdchartc.GDC_TICK_LABELS,
        "POINTS":               _gdchartc.GDC_TICK_POINTS,
        "NONE":                 _gdchartc.GDC_TICK_NONE,
    }
    _BorderTypes = {
        "NONE":                 _gdchartc.GDC_BORDER_NONE,
        "ALL":                  _gdchartc.GDC_BORDER_ALL,
        "X":                    _gdchartc.GDC_BORDER_X,
        "Y":                    _gdchartc.GDC_BORDER_Y,
        "Y2":                   _gdchartc.GDC_BORDER_Y2,
        "TOP":                  _gdchartc.GDC_BORDER_TOP,
    }
    _HilocloseTypes = {
        "DIAMOND":              _gdchartc.GDC_HLC_DIAMOND,
        "CLOSE_CONNECTED":      _gdchartc.GDC_HLC_CLOSE_CONNECTED,
        "CONNECTING":           _gdchartc.GDC_HLC_CONNECTING,
        "I_CAP":                _gdchartc.GDC_HLC_I_CAP,
    }
    _lookupOptions = {
        "image_type":           ChartBase._ImageTypes,
        "stack_type":           _StackTypes,
        "grid":                 _TickTypes,
        "ticks":                _TickTypes,
        "title_font_size":      ChartBase._FontSizes,
        "xtitle_font_size":     ChartBase._FontSizes,
        "ytitle_font_size":     ChartBase._FontSizes,
        "xaxisfont_size":       ChartBase._FontSizes,
        "yaxisfont_size":       ChartBase._FontSizes,
        "annotation_font_size": ChartBase._FontSizes,
    }
    _maskOptions = {
        "hlc_style":            _HilocloseTypes,
        "border":               _BorderTypes,
    }
    def __init__(self, *args, **kwargs):
        ChartBase.__init__(self, *args, **kwargs)
        self.__dict__["_numsets"] = None
        self.__dict__["_combodata"] = None
        self.__dict__["_combodatalen"] = None
        self.__dict__["_combonumsets"] = None
        self.__dict__["_annotation"] = None

    def _conformanceCheck(self):
        if self._labels:
            if self._datalen:
                if self._datalen != len(self._labels):
                    raise GDChartError, "Datasets must be of same length as list of labels."
            if self._combodatalen:
                if self._combodatalen != len(self._labels):
                    raise GDChartError, "Combo datasets must be of same length as list of labels."
        if self._datalen:
            if self._combodatalen:
                if self._datalen != self._combodatalen:
                    raise GDChartError, "Main and combo datasets must be of same length."

    def setScatter(self, scatterpoints):
        """
            Set scatter points. This should be a list of Scatter objects.
        """
        slen = None
        if self._datalen:
            slen = self._datalen
        elif self._labels:
            slen = len(self._labels)

        if slen:
            for i in scatterpoints:
                if i.point > slen or i.point < 0:
                    raise ValueError("Scatter point value must be > 0 and < numpoints.")
        self._scatterPoints = scatterpoints

    def clearAnnotation(self):
        self._annotation = None

    def annotate(self, point=0, note = "", color="white"):
        """
            Set an annotation. At the moment the gdchart library is limited to
            one annotation per graph.
        """
        slen = None
        if self._datalen:
            slen = self._datalen
        elif self._labels:
            slen = len(self._labels)

        if slen:
            if (point>slen) or (point<0):
                raise ValueError("Annotation point value must be > 0 and < numpoints.")

        if len(note) > _gdchartc.MAX_NOTE_LEN:
                raise ValueError("Annotation note length must be < %i."%(_gdchartc.MAX_NOTE_LEN))

        try:
            intcolor = rgbFactory(color)
        except GDChartError:
            try:
                intcolor = int(color)
            except ValueError:
                raise GDChartError("color must be representable as an int.")
        intcolor = int(intcolor)

        b = _Bucket(point=point, note=note, color=intcolor)
        self._annotation = b

    def draw(self, filedef):
        """
            Draw a graph to file. 
        """
        if not self._datalen:
            raise GDChartError, "No data to graph"
        if type(filedef) in types.StringTypes:
            filedef = open(filedef, "w")
        self._actualiseOptions()
        _gdchartc.annotate(self._annotation)
        try:
            _gdchartc.out_graph(    self._width, 
                                    self._height,
                                    filedef,
                                    self._type,
                                    self._datalen,
                                    self._labels,               
                                    self._numsets,
                                    self._data,
                                    self._combodata          
                                )
        except _gdchartc.PGError, val:
            raise GDChartError, val

#
# Simple data graphs
#
class SimpleBase(GraphBase):
    """
        Base class for "Simple" graph types. 
    """
    def _getSimpleData(self, *data):
        """
            Returns the data length, the number of sets and the flattened data
        """
        length = _uniformLength(*data)
        if length < 0:
            raise GDChartError, "All data sets have to be of the same length."
        return length, _flattenList(*data)

    def setData(self, *data):
        """
            Set the data to graph. This method takes a set of lists of data,
            that should all be of the same length. I.e.
                x.setData([1, 2, 3], [4, 5, 6])
        """
        self._numsets = len(data)
        self._datalen, self._data = self._getSimpleData(*data)
        self._conformanceCheck()

class Line(SimpleBase):
    """
        A simple line graph.
    """
    _type = _gdchartc.GDC_LINE

class Area(SimpleBase):
    """
        A graph with the area under the data filled.
    """
    _type = _gdchartc.GDC_AREA

class Bar(SimpleBase):
    """
        A classical bar graph.
    """
    _type = _gdchartc.GDC_BAR

class Area3D(SimpleBase):
    """
        A 3D graph with the area under the line filled.
    """
    _type = _gdchartc.GDC_3DAREA

class Line3D(SimpleBase):
    """
        A 3D line graph.
    """
    _type = _gdchartc.GDC_3DLINE

class Bar3D(SimpleBase):
    """
        A 3D bar graph.
    """
    _type = _gdchartc.GDC_3DBAR


class MultisetGraphBase(GraphBase):
    """
        The base class of all multiset graphs.
    """
    def _getMultisetData(self, setlen, *data):
        """
            Returns the data length, the number of sets and the flattened data
        """
        baseLength = None
        allData = []
        for i in data:
            if len(i) != setlen:
                raise GDChartError("Sets of %s data lists required."%setlen)
            length = _uniformLength(*i)
            if length < 0:
                raise GDChartError, "All data sets must be of the same length."
            if baseLength:
                if length != baseLength:
                    raise GDChartError, "All data sets must be of the same length."
            else:
                baseLength = length
            allData += _flattenList(*i)
        return baseLength, allData

#
# Floating Bars
#
class FloatingBarBase(MultisetGraphBase):
    """
        Base class of all floating bar graphs. 
    """
    def setData(self, *data):
        """

            This function takes a set of data tuples, where the first element
            of the tuple are all of the lower values, and the second element
            the upper values. Eg.

            x.setData(((1, 2, 3), (4, 5, 6)), ((3, 6, 9), (6, 9, 12)))
        """
        self._numsets = len(data)
        self._datalen, self._data = self._getMultisetData(2, *data)
        self._conformanceCheck()

class FloatingBar(FloatingBarBase):
    """
        A floating bar graph. 
    """
    _type = _gdchartc.GDC_FLOATINGBAR

class FloatingBar3D(FloatingBarBase):
    """
        A 3D floating bar graph. 
    """
    _type = _gdchartc.GDC_3DFLOATINGBAR

#
# HLC
#
class HLCBase(MultisetGraphBase):
    """
        Base class for High-Low-Close graphs. 
    """
    def setData(self, *data):
        """
            Takes a list of data triplets, where the first element is high, the
            second, low, and the third close. Eg.

            x.setData(((6, 9, 12), (1, 2, 3), (5, 6, 7)))
        """
        self._numsets = len(data)
        self._datalen, self._data = self._getMultisetData(3, *data)
        self._conformanceCheck()

class HLC(HLCBase):
    _type = _gdchartc.GDC_HILOCLOSE

class HLC3D(HLCBase):
    _type = _gdchartc.GDC_3DHILOCLOSE

#
# HLC Combo Graphs
#
class HLCComboBase(HLCBase, SimpleBase):
    """
        Base class for HLC combo data.
    """
    def setComboData(self, *data):
        """
            Set the combo data for this graph. This function takes a simple
            list of data sets.
        """
        self._combonumsets = len(data)
        self._combodatalen, self._combodata = self._getSimpleData(*data)
        self._conformanceCheck()

    def draw(self, filename):
        """
            Write the graph to file. 
        """
        if not self._combodata:
            raise GDChartError, "Combo data must be specified for a combo graph."
        # We should be using super for this...
        SimpleBase.draw(self, filename)

class HLCAreaCombo(HLCComboBase):
    """
        A High-Low-Close/Area combo graph.
    """
    _type = _gdchartc.GDC_COMBO_HLC_AREA

class HLCAreaCombo3D(HLCComboBase):
    """
        A 3D High-Low-Close/Area combo graph.
    """
    _type = _gdchartc.GDC_3DCOMBO_HLC_AREA

class HLCBarCombo(HLCComboBase):
    """
        A High-Low-Close/Bar combo graph.
    """
    _type = _gdchartc.GDC_COMBO_HLC_BAR

class HLCBarCombo3D(HLCComboBase):
    """
        A 3D High-Low-Close/Bar combo graph.
    """
    _type = _gdchartc.GDC_3DCOMBO_HLC_BAR

#
# Simple Combo Graphs
#
class SimpleComboBase(SimpleBase):
    """
        Base class for "simple" combo graph types. 
    """
    def setData(self, *data):
        """
            Set the data to graph. This method takes a set of lists of data,
            that should all be of the same length. I.e.
                x.setData([1, 2, 3], [4, 5, 6])
        """
        self._numsets = len(data)
        self._datalen, self._data = self._getSimpleData(*data)
        self._conformanceCheck()

    def setComboData(self, *data):
        """
            Set the combo data to graph. This method takes a set of lists of data,
            that should all be of the same length. I.e.
                x.setComboData([1, 2, 3], [4, 5, 6])
        """
        self._combonumsets = len(data)
        self._combodatalen, self._combodata = self._getSimpleData(*data)
        self._conformanceCheck()

    def draw(self, filename):
        if not self._combodata:
            raise GDChartError, "Combo data must be specified for a combo graph."
        # We should be using super for this...
        SimpleBase.draw(self, filename)

class LineBarCombo(SimpleComboBase):
    """
        A Line/Bar combo graph.
    """
    _type = _gdchartc.GDC_COMBO_LINE_BAR

class LineAreaCombo(SimpleComboBase):
    """
        A Line/Area combo graph.
    """
    _type = _gdchartc.GDC_COMBO_LINE_AREA

class LineLineCombo(SimpleComboBase):
    """
        A Line/Line combo graph.
    """
    _type = _gdchartc.GDC_COMBO_LINE_LINE

class LineBarCombo3D(SimpleComboBase):
    """
        A 3D Line/Bar combo graph.
    """
    _type = _gdchartc.GDC_3DCOMBO_LINE_BAR

class LineAreaCombo3D(SimpleComboBase):
    """
        A 3D Line/Area combo graph.
    """
    _type = _gdchartc.GDC_3DCOMBO_LINE_AREA

class LineLineCombo3D(SimpleComboBase):
    """
        A 3D Line/Line combo graph.
    """
    _type = _gdchartc.GDC_3DCOMBO_LINE_LINE