'create a complete bar graph (horizontal, vertical, progress, or fader)'

def create(self):

    self.type = self.type.lower()
    d = self.values
    t = ((hasattr(self.titles, 'split') and self.titles.split(',')) or self.titles)
    r = ((hasattr(self.labels, 'split') and self.labels.split(',')) or self.labels)
    drc = ((hasattr(self.barColors, 'split') and self.barColors.split(',')) or self.barColors)
    val = []
    bc = []
    if (self.barLength < 0.1):
        self.barLength = 0.1
    elif (self.barLength > 2.9):
        self.barLength = 2.9
    labels = (((len(d) > len(r)) and len(d)) or len(r))
    if ((self.type == 'pbar') or (self.type == 'fader')):
        if (not self.barBGColor):
            self.barBGColor = self.labelBGColor
        if ((self.labelBGColor == self.barBGColor) and (len(t) == 0)):
            self.labelBGColor = ''
            self.labelBorder = ''
    self.set_styles()
    graph = (('<table    border=0    cellspacing=0    cellpadding=' + str(self.graphPadding)) + '><tr>')
    graph += (('<td' + ((self.__cssGRAPH and (('    style="' + self.__cssGRAPH) + '"')) or '')) + '>')
    if (self.legend and (self.type != 'pbar') and (self.type != 'fader')):
        graph += '<table    border=0    cellspacing=0    cellpadding=0><tr><td>'
    if (self.charts > 1):
        divide = math.ceil((labels / self.charts))
        graph += '<table    border=0    cellspacing=0    cellpadding=6><tr    valign=top><td>'
    else:
        divide = 0
    sum = 0
    max = 0
    max_neg = 0
    max_dec = 0
    ccnt = 0
    lcnt = 0
    chart = 0
    for i in range(labels):
        if (divide and i and (not (i % divide))):
            lcnt = 0
            chart += 1
        try:
            drv = ((len(d[i]) and [e for e in d[i]]) or [d[i]])
        except:
            drv = [d[i]]
        j = 0
        dec = 0
        if (len(val) <= chart):
            val.append([])
        for v in drv:
            s = str(v)
            if (s.find('.') != (-1)):
                dec = len(s[(s.find('.') + 1):])
                if (dec > max_dec):
                    max_dec = dec
            if (len(val[chart]) <= lcnt):
                val[chart].append([])
            val[chart][lcnt].append(v)
            if (v != 0):
                v -= self.baseValue
            if (v > max):
                max = v
            elif (v < max_neg):
                max_neg = v
            if (v < 0):
                v *= (-1)
            sum += v
            if (len(bc) <= j):
                if (ccnt >= len(self.__colors)):
                    ccnt = 0
                if ((len(drc) <= j) or (len(drc[j]) < 3)):
                    bc.append(self.__colors[ccnt])
                    ccnt += 1
                else:
                    bc.append(drc[j].strip())
            j += 1
        lcnt += 1
    border = int(self.barBorder[0])
    mPerc = ((sum and int(round(((max * 100.0) / sum)))) or 0)
    if ((self.type == 'pbar') or (self.type == 'fader')):
        mul = 2
    else:
        mul = ((mPerc and (100.0 / mPerc)) or 1)
    mul *= self.barLength
    if (self.showValues < 2):
        if (self.type == 'hbar'):
            valSpace = ((self.percValuesDecimals * (self.percValuesSize / 1.6)) + (self.percValuesSize * 3.2))
        else:
            valSpace = (self.percValuesSize * 1.2)
    else:
        valSpace = self.percValuesSize
    spacer = maxSize = int(round((((mPerc * mul) + valSpace) + (border * 2))))
    if max_neg:
        mPerc_neg = ((sum and int(round((((- max_neg) * 100.0) / sum)))) or 0)
        if ((mPerc_neg > mPerc) and (self.type != 'pbar') and (self.type != 'fader')):
            mul = ((100.0 / mPerc_neg) * self.barLength)
        spacer_neg = int(round((((mPerc_neg * mul) + valSpace) + (border * 2))))
        maxSize += spacer_neg
    else:
        mPerc_neg = spacer_neg = 0
    titleLabel = ''
    titleValue = ''
    titleBar = ''
    if (len(t) > 0):
        titleLabel = (((t[0] == '') and '&nbsp;') or t[0])
        if ((self.showValues == 1) or (self.showValues == 2)):
            titleValue = (((t[1] == '') and '&nbsp;') or t[1])
            titleBar = (((t[2] == '') and '&nbsp;') or t[2])
        else:
            titleBar = (((t[1] == '') and '&nbsp;') or t[1])
    chart = 0
    lcnt = 0
    for v in val:
        graph += '<table    border=0    cellspacing=2    cellpadding=0>'
        if (self.type == 'hbar'):
            if (len(t) > 0):
                graph += self.build_hTitle(titleLabel, titleValue, titleBar)
            for i in range(len(v)):
                label = (((lcnt < len(r)) and r[lcnt].strip()) or str((lcnt + 1)))
                rowspan = len(v[i])
                graph += (((('<tr><td    style="' + self.__cssLABEL) + '"') + (((rowspan > 1) and ('    rowspan=' + str(rowspan))) or '')) + '>')
                graph += (('&nbsp;' + label) + '&nbsp;</td>')
                for j in range(len(v[i])):
                    value = ((v[i][j] and (v[i][j] - self.baseValue)) or 0)
                    percent = ((sum and ((value * 100.0) / sum)) or 0)
                    value = _number_format(v[i][j], max_dec)
                    bColor = self.level_color(v[i][j], bc[j])
                    if ((self.showValues == 1) or (self.showValues == 2)):
                        graph += self.build_value(v[i][j], max_dec, 0, 'right')
                    graph += (((('<td' + ((self.__cssBARBG and (('    style="' + self.__cssBARBG) + '"')) or '')) + '    height=100%    width=') + str(maxSize)) + '>')
                    graph += self.create_hBar(value, percent, mPerc, mPerc_neg, max_neg, mul, valSpace, bColor, border, spacer, spacer_neg)
                    graph += '</td></tr>'
                    if (j < (len(v[i]) - 1)):
                        graph += '<tr>'
                if (self.labelSpace and (i < (len(v) - 1))):
                    graph += (('<tr><td    colspan=3    height=' + str(self.labelSpace)) + '></td></tr>')
                lcnt += 1
        elif (self.type == 'vbar'):
            graph += '<tr    align=center    valign=bottom>'
            if (titleBar != ''):
                titleBar = titleBar.replace('-', '-<br>')
                graph += (((('<td    style="' + self.__cssTITLE) + '"    valign=middle>') + titleBar) + '</td>')
            for i in range(len(v)):
                for j in range(len(v[i])):
                    value = ((v[i][j] and (v[i][j] - self.baseValue)) or 0)
                    percent = ((sum and ((value * 100.0) / sum)) or 0)
                    value = _number_format(v[i][j], max_dec)
                    bColor = self.level_color(v[i][j], bc[j])
                    graph += (('<td' + ((self.__cssBARBG and (('    style="' + self.__cssBARBG) + '"')) or '')) + '>')
                    graph += self.create_vBar(value, percent, mPerc, mPerc_neg, max_neg, mul, valSpace, bColor, border, spacer, spacer_neg)
                    graph += '</td>'
                if self.labelSpace:
                    graph += (('<td    width=' + str(self.labelSpace)) + '></td>')
            if ((self.showValues == 1) or (self.showValues == 2)):
                graph += '</tr><tr    align=center>'
                if (titleValue != ''):
                    graph += (((('<td    style="' + self.__cssTITLE) + '">') + titleValue) + '</td>')
                for i in range(len(v)):
                    for j in range(len(v[i])):
                        graph += self.build_value(v[i][j], max_dec)
                    if self.labelSpace:
                        graph += (('<td    width=' + str(self.labelSpace)) + '></td>')
            graph += '</tr><tr>'
            if (titleLabel != ''):
                graph += (((('<td    style="' + self.__cssTITLE) + '">') + titleLabel) + '</td>')
            for i in range(len(v)):
                label = (((lcnt < len(r)) and r[lcnt].strip()) or str((lcnt + 1)))
                colspan = len(v[i])
                graph += (((('<td    style="' + self.__cssLABEL) + '"') + (((colspan > 1) and ('    colspan=' + str(colspan))) or '')) + '>')
                graph += (('&nbsp;' + label) + '&nbsp;</td>')
                if self.labelSpace:
                    graph += (('<td    width=' + str(self.labelSpace)) + '></td>')
                lcnt += 1
            graph += '</tr>'
        elif ((self.type == 'pbar') or (self.type == 'fader')):
            if (len(t) > 0):
                graph += self.build_hTitle(titleLabel, titleValue, titleBar)
            for i in range(len(v)):
                try:
                    m = (((len(v[i]) > 1) and True) or False)
                except:
                    m = False
                if (m or (not i)):
                    label = (((lcnt < len(r)) and r[lcnt].strip()) or str((i + 1)))
                    graph += '<tr>'
                    if len(r):
                        graph += (('<td    style="' + self.__cssLABEL) + '">')
                        graph += (('&nbsp;' + label) + '&nbsp;</td>')
                    try:
                        sum = ((v[i][1] and v[i][1]) or v[(-1)][0])
                    except:
                        sum = v[(-1)][0]
                    percent = ((sum and ((v[i][0] * 100.0) / sum)) or 0)
                    value = _number_format(v[i][0], max_dec)
                    if ((self.showValues == 1) or (self.showValues == 2)):
                        graph += self.build_value(v[i][0], max_dec, sum, 'right')
                    graph += (('<td' + ((self.__cssBARBG and (('    style="' + self.__cssBARBG) + '"')) or '')) + '>')
                    self.barColors = (((len(drc) >= (i + 1)) and drc[i].strip()) or self.__colors[0])
                    bColor = self.level_color(v[i][0], self.barColors)
                    graph += '<table    border=0    cellspacing=0    cellpadding=0><tr><td>'
                    if (self.type == 'fader'):
                        graph += self.build_fader(value, int(round((self.barWidth / 2))), self.barWidth, int(round((percent * mul))), bColor)
                    else:
                        graph += self.build_bar(value, int(round((percent * mul))), self.barWidth, bColor)
                    graph += (('</td><td    width=' + str(int(round(((100 - percent) * mul))))) + '></td>')
                    graph += '</tr></table></td>'
                    if (self.showValues < 2):
                        graph += (((('<td    style="' + self.__cssPERCVALUES) + '"    nowrap>&nbsp;') + str(_number_format(percent, self.percValuesDecimals))) + '%</td>')
                    graph += '</tr>'
                    if (self.labelSpace and (i < (len(v) - 1))):
                        graph += (('<td    colspan=3    height=' + str(self.labelSpace)) + '></td>')
                    lcnt += 1
        else:
            graph += (('<tr><td>' + self.__err_type) + '</td></tr>')
        graph += '</table>'
        if ((chart < (self.charts - 1)) and len(val[(chart + 1)])):
            graph += '</td>'
            if (self.type == 'vbar'):
                graph += '</tr><tr    valign=top>'
            graph += '<td>'
        chart += 1
    if (self.charts > 1):
        graph += '</td></tr></table>'
    if (self.legend and (self.type != 'pbar') and (self.type != 'fader')):
        graph += (('</td><td    width=10>&nbsp;</td><td' + ((self.legendAlign and ('    valign=' + self.legendAlign)) or '')) + '>')
        graph += self.build_legend(bc)
        graph += '</td></tr></table>'
    if self.debug:
        graph += ('<br>sum=%s    max=%s    max_neg=%s    max_dec=%s    ' % (sum, max, max_neg, max_dec))
        graph += ('mPerc=%s    mPerc_neg=%s    mul=%s    valSpace=%s' % (mPerc, mPerc_neg, mul, valSpace))
    graph += '</td></tr></table>'
    return graph
