picar / pyrrd

Automatically exported from code.google.com/p/pyrrd
BSD 3-Clause "New" or "Revised" License
1 stars 0 forks source link

TICK:GraphTick Support #29

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
class GraphTick(object):
    '''
    Plot a tick mark (a vertical line) for each value of vname that
    is non-zero and not *UNKNOWN*. The fraction argument specifies
    the length of the tick mark as a fraction of the y-axis; the
    default value is 0.1 (10% of the axis). Note that the color
    specification is not optional.

    >>> def1 = DEF(rrdfile='/home/rrdtool/data/router1.rrd',
    ...   vname='ds0a', dsName='ds0')

    >>> GraphTick(def1,'#ffffff',0.3,'Alarm!')
    TICK:ds0a#ffffff:0.3:"Alarm!"
    '''
    def __init__(self, defObj=None, color=None, fraction=None, legend=''):
        if not defObj:
            raise Exception, "You must provide either a value " + \
                "or a definition object."
        else:
            value1 = defObj.vname

        if fraction:
            if not (isinstance(fraction, float) or isinstance(fraction, int)):
                raise TypeError, "The parameter 'fraction' must" + \
                        "be a float value between 0 and 1."
            else:
                if 0 <= fraction <= 1:
                    value2 = fraction
                else:
                    raise ValueError, "The parameter 'fraction' must" + \
                        "be a value between 0 and 1."
        if not color:
            raise ValueError, "Missing required parameter color"

        self.vname = value1
        self.color = color
        self.fraction = value2
        self.legend = legend
        self.abbr = 'TICK'

    def __repr__(self):
        main = self.abbr
        main += ':%s' % self.vname
        if self.color:
            main += self.color
        if self.fraction:
            main += ':%s' % self.fraction
        if self.legend:
            main += ':"%s"' % self.legend
        return main

TICK = GraphTick

Original issue reported on code.google.com by colin.ho...@gmail.com on 4 Mar 2011 at 2:09

GoogleCodeExporter commented 9 years ago
Thanks Colin!

This has just been added to the repo.

Original comment by duncan.m...@gmail.com on 22 Jun 2011 at 3:18