Example #1
0
def formatYear(y, prettyPower=False):
    if abs(y) < 10**4:  ## FIXME
        y_st = _(y)
    else:
        #y_st = textNumEncode('%.0E'%y, changeDot=True)## FIXME
        fac, pw = getNum10FactPow(y)
        if not prettyPower or abs(fac) >= 100:  ## FIXME
            y_e = '%E' % y
            for i in range(10):
                y_e = y_e.replace('0E', 'E')
            y_e = y_e.replace('.E', 'E')
            y_st = textNumEncode(y_e, changeDot=True)
        else:
            sign = ('-' if fac < 0 else '')
            fac = abs(fac)
            if fac == 1:
                fac_s = ''
            else:
                fac_s = '%s×' % _(fac)
            pw_s = _(10) + 'ˆ' + _(pw)
            ## pw_s = _(10) + '<span rise="5" size="small">' + _(pw) + '</span>'## Pango Markup Language
            y_st = sign + fac_s + pw_s
    return addLRM(y_st)
Example #2
0
def formatYear(y, prettyPower=False):
    if abs(y) < 10 ** 4:## FIXME
        y_st = _(y)
    else:
        #y_st = textNumEncode('%.0E'%y, changeDot=True)## FIXME
        fac, pw = getNum10FactPow(y)
        if not prettyPower or abs(fac) >= 100:## FIXME
            y_e = '%E'%y
            for i in range(10):
                y_e = y_e.replace('0E', 'E')
            y_e = y_e.replace('.E', 'E')
            y_st = textNumEncode(y_e, changeDot=True)
        else:
            sign = ('-' if fac < 0 else '')
            fac = abs(fac)
            if fac == 1:
                fac_s = ''
            else:
                fac_s = '%s×'%_(fac)
            pw_s = _(10) + 'ˆ' + _(pw)
            ## pw_s = _(10) + '<span rise="5" size="small">' + _(pw) + '</span>'## Pango Markup Language
            y_st = sign + fac_s + pw_s
    return addLRM(y_st)
Example #3
0
def formatYear(y, prettyPower=False):
    if abs(y) < 10**4:  ## FIXME
        y_st = _(y)
    else:
        #y_st = textNumEncode("%.0E"%y, changeDot=True)## FIXME
        fac, pw = getNum10FactPow(y)
        if not prettyPower or abs(fac) >= 100:  ## FIXME
            y_e = "%E" % y
            for i in range(10):
                y_e = y_e.replace("0E", "E")
            y_e = y_e.replace(".E", "E")
            y_st = textNumEncode(y_e, changeDot=True)
        else:
            sign = ("-" if fac < 0 else "")
            fac = abs(fac)
            if fac == 1:
                fac_s = ""
            else:
                fac_s = "%s×" % _(fac)
            pw_s = _(10) + "ˆ" + _(pw)
            #pw_s = _(10) + "<span rise="5" size="small">" + \
            #	_(pw) + "</span>"  # Pango Markup Language
            y_st = sign + fac_s + pw_s
    return addLRM(y_st)
Example #4
0
def formatYear(y, prettyPower=False):
	if abs(y) < 10 ** 4:## FIXME
		y_st = _(y)
	else:
		#y_st = textNumEncode("%.0E"%y, changeDot=True)## FIXME
		fac, pw = getNum10FactPow(y)
		if not prettyPower or abs(fac) >= 100:## FIXME
			y_e = "%E" % y
			for i in range(10):
				y_e = y_e.replace("0E", "E")
			y_e = y_e.replace(".E", "E")
			y_st = textNumEncode(y_e, changeDot=True)
		else:
			sign = ("-" if fac < 0 else "")
			fac = abs(fac)
			if fac == 1:
				fac_s = ""
			else:
				fac_s = "%s×" % _(fac)
			pw_s = _(10) + "ˆ" + _(pw)
			#pw_s = _(10) + "<span rise="5" size="small">" + \
			#	_(pw) + "</span>"  # Pango Markup Language
			y_st = sign + fac_s + pw_s
	return addLRM(y_st)
Example #5
0
def calcTimeLineData(timeStart, timeWidth, pixelPerSec, borderTm):
    timeEnd = timeStart + timeWidth
    jd0 = getJdFromEpoch(timeStart)
    jd1 = getJdFromEpoch(timeEnd)
    widthDays = float(timeWidth) / dayLen
    dayPixel = dayLen * pixelPerSec  ## px
    #print('dayPixel = %s px'%dayPixel)
    getEPos = lambda epoch: (epoch - timeStart) * pixelPerSec
    getJPos = lambda jd: (getEpochFromJd(jd) - timeStart) * pixelPerSec
    ######################## Holidays
    holidays = []
    if changeHolidayBg and changeHolidayBgMinDays < widthDays < changeHolidayBgMaxDays:
        for jd in getHolidaysJdList(jd0, jd1 + 1):
            holidays.append(getJPos(jd))
    ######################## Ticks
    ticks = []
    tickEpochList = []
    minStep = minorStepMin / pixelPerSec  ## second
    #################
    year0, month0, day0 = jd_to_primary(jd0)
    year1, month1, day1 = jd_to_primary(jd1)
    ############ Year
    minStepYear = minStep // minYearLenSec  ## years ## int or iceil?
    yearPixel = minYearLenSec * pixelPerSec  ## pixels
    for (year, size) in getYearRangeTickValues(year0, year1 + 1, minStepYear):
        tmEpoch = getEpochFromDate(year, 1, 1, calTypes.primary)
        if tmEpoch in tickEpochList:
            continue
        unitSize = size * yearPixel
        label = formatYear(year) if unitSize >= majorStepMin else ''
        ticks.append(Tick(
            tmEpoch,
            getEPos(tmEpoch),
            unitSize,
            label,
        ))
        tickEpochList.append(tmEpoch)
    ############ Month
    monthPixel = avgMonthLen * pixelPerSec  ## px
    minMonthUnit = float(minStep) / avgMonthLen  ## month
    if minMonthUnit <= 3:
        for ym in range(year0 * 12 + month0 - 1,
                        year1 * 12 + month1 - 1 + 1):  ## +1 FIXME
            if ym % 3 == 0:
                monthUnit = 3
            else:
                monthUnit = 1
            if monthUnit < minMonthUnit:
                continue
            y, m = divmod(ym, 12)
            m += 1
            tmEpoch = getEpochFromDate(y, m, 1, calTypes.primary)
            if tmEpoch in tickEpochList:
                continue
            unitSize = monthPixel * monthUnit
            ticks.append(
                Tick(
                    tmEpoch,
                    getEPos(tmEpoch),
                    unitSize,
                    getMonthName(calTypes.primary, m)
                    if unitSize >= majorStepMin else '',
                ))
            tickEpochList.append(tmEpoch)
    ################
    if showWeekStart and showWeekStartMinDays < widthDays < showWeekStartMaxDays:
        wd0 = jwday(jd0)
        jdw0 = jd0 + (core.firstWeekDay - wd0) % 7
        unitSize = dayPixel * 7
        if unitSize < majorStepMin:
            label = ''
        else:
            label = core.weekDayNameAb[core.firstWeekDay]
        for jd in range(jdw0, jd1 + 1, 7):
            tmEpoch = getEpochFromJd(jd)
            ticks.append(
                Tick(
                    tmEpoch,
                    getEPos(tmEpoch),
                    unitSize,
                    label,
                    color=weekStartTickColor,
                ))
            #tickEpochList.append(tmEpoch)
    ############ Day of Month
    hasMonthName = timeWidth < 5 * dayLen
    minDayUnit = float(minStep) / dayLen  ## days
    if minDayUnit <= 15:
        for jd in range(jd0, jd1 + 1):
            tmEpoch = getEpochFromJd(jd)
            if tmEpoch in tickEpochList:
                continue
            year, month, day = jd_to_primary(jd)
            if day == 16:
                dayUnit = 15
            elif day in (6, 11, 21, 26):
                dayUnit = 5
            else:
                dayUnit = 1
            if dayUnit < minDayUnit:
                continue
            unitSize = dayPixel * dayUnit
            if unitSize < majorStepMin:
                label = ''
            elif hasMonthName:
                label = _(day) + ' ' + getMonthName(calTypes.primary, month)
            else:
                label = _(day)
            ticks.append(Tick(
                tmEpoch,
                getEPos(tmEpoch),
                unitSize,
                label,
            ))
            tickEpochList.append(tmEpoch)
    ############ Hour, Minute, Second
    for stepUnit, stepValue in unitSteps:
        stepSec = stepUnit * stepValue
        if stepSec < minStep:
            break
        unitSize = stepSec * pixelPerSec
        utcOffset = int(getUtcOffsetCurrent())
        firstEpoch = iceil(
            (timeStart + utcOffset) / stepSec) * stepSec - utcOffset
        for tmEpoch in range(firstEpoch, iceil(timeEnd), stepSec):
            if tmEpoch in tickEpochList:
                continue
            if unitSize < majorStepMin:
                label = ''
            else:
                jd, h, m, s = getJhmsFromEpoch(tmEpoch)
                if s == 0:
                    label = '%s:%s' % (
                        _(h),
                        _(m, fillZero=2),
                    )
                else:  # elif timeWidth < 60 or stepSec < 30:
                    label = addLRM('%s"' % _(s, fillZero=2))
                #else:
                #    label = '%s:%s:%s'%(
                #        _(h),
                #        _(m, fillZero=2),
                #        _(s, fillZero=2),
                #    )
            ticks.append(Tick(
                tmEpoch,
                getEPos(tmEpoch),
                unitSize,
                label,
            ))
            tickEpochList.append(tmEpoch)
    ######################## Event Boxes
    data = {
        'holidays': holidays,
        'ticks': ticks,
        'boxes': [],
    }
    ###
    data['boxes'] = calcEventBoxes(
        timeStart,
        timeEnd,
        pixelPerSec,
        borderTm,
    )
    ###
    return data
Example #6
0
def calcTimeLineData(timeStart, timeWidth, pixelPerSec, borderTm):
    timeEnd = timeStart + timeWidth
    jd0 = getJdFromEpoch(timeStart)
    jd1 = getJdFromEpoch(timeEnd)
    widthDays = float(timeWidth) / dayLen
    dayPixel = dayLen * pixelPerSec ## px
    #print('dayPixel = %s px'%dayPixel)
    getEPos = lambda epoch: (epoch-timeStart)*pixelPerSec
    getJPos = lambda jd: (getEpochFromJd(jd)-timeStart)*pixelPerSec
    ######################## Holidays
    holidays = []
    if changeHolidayBg and changeHolidayBgMinDays < widthDays < changeHolidayBgMaxDays:
        for jd in getHolidaysJdList(jd0, jd1+1):
            holidays.append(getJPos(jd))
    ######################## Ticks
    ticks = []
    tickEpochList = []
    minStep = minorStepMin / pixelPerSec ## second
    #################
    year0, month0, day0 = jd_to_primary(jd0)
    year1, month1, day1 = jd_to_primary(jd1)
    ############ Year
    minStepYear = minStep // minYearLenSec ## years ## int or iceil?
    yearPixel = minYearLenSec * pixelPerSec ## pixels
    for (year, size) in getYearRangeTickValues(year0, year1+1, minStepYear):
        tmEpoch = getEpochFromDate(year, 1, 1, calTypes.primary)
        if tmEpoch in tickEpochList:
            continue
        unitSize = size * yearPixel
        label = formatYear(year) if unitSize >= majorStepMin else ''
        ticks.append(Tick(
            tmEpoch,
            getEPos(tmEpoch),
            unitSize,
            label,
        ))
        tickEpochList.append(tmEpoch)
    ############ Month
    monthPixel = avgMonthLen * pixelPerSec ## px
    minMonthUnit = float(minStep) / avgMonthLen ## month
    if minMonthUnit <= 3:
        for ym in range(year0*12+month0-1, year1*12+month1-1+1):## +1 FIXME
            if ym%3==0:
                monthUnit = 3
            else:
                monthUnit = 1
            if monthUnit < minMonthUnit:
                continue
            y, m = divmod(ym, 12) ; m+=1
            tmEpoch = getEpochFromDate(y, m, 1, calTypes.primary)
            if tmEpoch in tickEpochList:
                continue
            unitSize = monthPixel * monthUnit
            ticks.append(Tick(
                tmEpoch,
                getEPos(tmEpoch),
                unitSize,
                getMonthName(calTypes.primary, m) if unitSize >= majorStepMin else '',
            ))
            tickEpochList.append(tmEpoch)
    ################
    if showWeekStart and showWeekStartMinDays < widthDays < showWeekStartMaxDays:
        wd0 = jwday(jd0)
        jdw0 = jd0 + (core.firstWeekDay - wd0) % 7
        unitSize = dayPixel * 7
        if unitSize < majorStepMin:
            label = ''
        else:
            label = core.weekDayNameAb[core.firstWeekDay]
        for jd in range(jdw0, jd1+1, 7):
            tmEpoch = getEpochFromJd(jd)
            ticks.append(Tick(
                tmEpoch,
                getEPos(tmEpoch),
                unitSize,
                label,
                color=weekStartTickColor,
            ))
            #tickEpochList.append(tmEpoch)
    ############ Day of Month
    hasMonthName = timeWidth < 5 * dayLen
    minDayUnit = float(minStep) / dayLen ## days
    if minDayUnit <= 15:
        for jd in range(jd0, jd1+1):
            tmEpoch = getEpochFromJd(jd)
            if tmEpoch in tickEpochList:
                continue
            year, month, day = jd_to_primary(jd)
            if day==16:
                dayUnit = 15
            elif day in (6, 11, 21, 26):
                dayUnit = 5
            else:
                dayUnit = 1
            if dayUnit < minDayUnit:
                continue
            unitSize = dayPixel*dayUnit
            if unitSize < majorStepMin:
                label = ''
            elif hasMonthName:
                label = _(day) + ' ' + getMonthName(calTypes.primary, month)
            else:
                label = _(day)
            ticks.append(Tick(
                tmEpoch,
                getEPos(tmEpoch),
                unitSize,
                label,
            ))
            tickEpochList.append(tmEpoch)
    ############ Hour, Minute, Second
    for stepUnit, stepValue in unitSteps:
        stepSec = stepUnit*stepValue
        if stepSec < minStep:
            break
        unitSize = stepSec*pixelPerSec
        utcOffset = int(getUtcOffsetCurrent())
        firstEpoch = iceil((timeStart+utcOffset) / stepSec) * stepSec - utcOffset
        for tmEpoch in range(firstEpoch, iceil(timeEnd), stepSec):
            if tmEpoch in tickEpochList:
                continue
            if unitSize < majorStepMin:
                label = ''
            else:
                jd, h, m, s = getJhmsFromEpoch(tmEpoch)
                if s==0:
                    label = '%s:%s'%(
                        _(h),
                        _(m, fillZero=2),
                    )
                else:# elif timeWidth < 60 or stepSec < 30:
                    label = addLRM('%s"'%_(s, fillZero=2))
                #else:
                #    label = '%s:%s:%s'%(
                #        _(h),
                #        _(m, fillZero=2),
                #        _(s, fillZero=2),
                #    )
            ticks.append(Tick(
                tmEpoch,
                getEPos(tmEpoch),
                unitSize,
                label,
            ))
            tickEpochList.append(tmEpoch)
    ######################## Event Boxes
    data = {
        'holidays': holidays,
        'ticks': ticks,
        'boxes': [],
    }
    ###
    data['boxes'] = calcEventBoxes(
        timeStart,
        timeEnd,
        pixelPerSec,
        borderTm,
    )
    ###
    return data