|
|
@ -29,6 +29,7 @@ import org.isoron.uhabits.core.utils.DateUtils.Companion.getShortWeekdayNames
|
|
|
|
import org.isoron.uhabits.core.utils.DateUtils.Companion.getStartOfTodayCalendar
|
|
|
|
import org.isoron.uhabits.core.utils.DateUtils.Companion.getStartOfTodayCalendar
|
|
|
|
import org.isoron.uhabits.core.utils.DateUtils.Companion.getStartOfTodayCalendarWithOffset
|
|
|
|
import org.isoron.uhabits.core.utils.DateUtils.Companion.getStartOfTodayCalendarWithOffset
|
|
|
|
import org.isoron.uhabits.core.utils.DateUtils.Companion.getWeekdaySequence
|
|
|
|
import org.isoron.uhabits.core.utils.DateUtils.Companion.getWeekdaySequence
|
|
|
|
|
|
|
|
import org.isoron.uhabits.core.utils.DateUtils.Companion.getWeekdaysInMonth
|
|
|
|
import org.isoron.uhabits.utils.ColorUtils.mixColors
|
|
|
|
import org.isoron.uhabits.utils.ColorUtils.mixColors
|
|
|
|
import org.isoron.uhabits.utils.StyledResources
|
|
|
|
import org.isoron.uhabits.utils.StyledResources
|
|
|
|
import org.isoron.uhabits.utils.toSimpleDataFormat
|
|
|
|
import org.isoron.uhabits.utils.toSimpleDataFormat
|
|
|
@ -166,6 +167,7 @@ class FrequencyChart : ScrollableChart {
|
|
|
|
|
|
|
|
|
|
|
|
private fun drawColumn(canvas: Canvas, rect: RectF?, date: GregorianCalendar) {
|
|
|
|
private fun drawColumn(canvas: Canvas, rect: RectF?, date: GregorianCalendar) {
|
|
|
|
val values = frequency[Timestamp(date)]
|
|
|
|
val values = frequency[Timestamp(date)]
|
|
|
|
|
|
|
|
val weekDaysInMonth = getWeekdaysInMonth(Timestamp(date))
|
|
|
|
val rowHeight = rect!!.height() / 8.0f
|
|
|
|
val rowHeight = rect!!.height() / 8.0f
|
|
|
|
prevRect!!.set(rect)
|
|
|
|
prevRect!!.set(rect)
|
|
|
|
val localeWeekdayList: Array<Int> = getWeekdaySequence(firstWeekday)
|
|
|
|
val localeWeekdayList: Array<Int> = getWeekdaySequence(firstWeekday)
|
|
|
@ -174,7 +176,7 @@ class FrequencyChart : ScrollableChart {
|
|
|
|
rect.offset(prevRect!!.left, prevRect!!.top + baseSize * j)
|
|
|
|
rect.offset(prevRect!!.left, prevRect!!.top + baseSize * j)
|
|
|
|
val i = localeWeekdayList[j] % 7
|
|
|
|
val i = localeWeekdayList[j] % 7
|
|
|
|
if (values != null)
|
|
|
|
if (values != null)
|
|
|
|
drawMarker(canvas, rect, values[i])
|
|
|
|
drawMarker(canvas, rect, values[i], weekDaysInMonth[i])
|
|
|
|
rect.offset(0f, rowHeight)
|
|
|
|
rect.offset(0f, rowHeight)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
drawFooter(canvas, rect, date)
|
|
|
|
drawFooter(canvas, rect, date)
|
|
|
@ -222,7 +224,7 @@ class FrequencyChart : ScrollableChart {
|
|
|
|
canvas.drawLine(rGrid.left, rGrid.top, rGrid.right, rGrid.top, pGrid!!)
|
|
|
|
canvas.drawLine(rGrid.left, rGrid.top, rGrid.right, rGrid.top, pGrid!!)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private fun drawMarker(canvas: Canvas, rect: RectF?, value: Int?) {
|
|
|
|
private fun drawMarker(canvas: Canvas, rect: RectF?, value: Int?, frequency: Int) {
|
|
|
|
// value can be negative when the entry is skipped
|
|
|
|
// value can be negative when the entry is skipped
|
|
|
|
val valueCopy = value?.let { max(0, it) }
|
|
|
|
val valueCopy = value?.let { max(0, it) }
|
|
|
|
|
|
|
|
|
|
|
@ -230,7 +232,8 @@ class FrequencyChart : ScrollableChart {
|
|
|
|
// maximal allowed mark radius
|
|
|
|
// maximal allowed mark radius
|
|
|
|
val maxRadius = (rect.height() - 2 * padding) / 2.0f
|
|
|
|
val maxRadius = (rect.height() - 2 * padding) / 2.0f
|
|
|
|
// the real mark radius is scaled down by a factor depending on the maximal frequency
|
|
|
|
// the real mark radius is scaled down by a factor depending on the maximal frequency
|
|
|
|
val scale = 1.0f / maxFreq * valueCopy!!
|
|
|
|
|
|
|
|
|
|
|
|
val scale = 1.0f / frequency * valueCopy!!
|
|
|
|
val radius = maxRadius * scale
|
|
|
|
val radius = maxRadius * scale
|
|
|
|
val colorIndex = min((colors.size - 1), ((colors.size - 1) * scale).roundToInt())
|
|
|
|
val colorIndex = min((colors.size - 1), ((colors.size - 1) * scale).roundToInt())
|
|
|
|
pGraph!!.color = colors[colorIndex]
|
|
|
|
pGraph!!.color = colors[colorIndex]
|
|
|
|