v0.3.0:今日筛选含逾期与今日完成、统计今日区间、重复任务自动滚动、通知自定义布局
This commit is contained in:
@@ -25,6 +25,12 @@ class BarChartView @JvmOverloads constructor(
|
||||
|
||||
private var bars: List<Bar> = emptyList()
|
||||
|
||||
/**
|
||||
* 横轴标签密度:0 = 自动(7 根以内全标,超过则每 5 根标一次);
|
||||
* 大于 0 表示每 N 根标一次。24 小时的今日视图用 3,避免标签糊成一片。
|
||||
*/
|
||||
var labelStep: Int = 0
|
||||
|
||||
private val barPaint = Paint(Paint.ANTI_ALIAS_FLAG)
|
||||
private val gridPaint = Paint(Paint.ANTI_ALIAS_FLAG).apply {
|
||||
style = Paint.Style.STROKE
|
||||
@@ -68,6 +74,9 @@ class BarChartView @JvmOverloads constructor(
|
||||
val barW = (slot * if (n <= 7) 0.42f else 0.62f).coerceAtLeast(context.dpf(2f))
|
||||
val radius = minOf(barW / 2f, context.dpf(4f))
|
||||
val lastIndex = n - 1
|
||||
// 标签密度:显式设置优先,否则 <=7 根全标、多根每 5 根标一次
|
||||
val step = if (labelStep > 0) labelStep else if (n <= 7) 1 else 5
|
||||
val denseValue = labelStep == 0 && n <= 7
|
||||
|
||||
bars.forEachIndexed { i, bar ->
|
||||
val cx = slot * i + slot / 2f
|
||||
@@ -78,16 +87,13 @@ class BarChartView @JvmOverloads constructor(
|
||||
canvas.drawRoundRect(r, radius, radius, barPaint)
|
||||
}
|
||||
|
||||
if (n <= 7) {
|
||||
if (bar.value > 0) {
|
||||
if (i % step == 0 || i == lastIndex) {
|
||||
if (denseValue && bar.value > 0) {
|
||||
valuePaint.color = context.col(R.color.text_secondary)
|
||||
canvas.drawText("${bar.value}", cx, baseY - h - context.dpf(5f), valuePaint)
|
||||
}
|
||||
textPaint.color = context.col(R.color.text_tertiary)
|
||||
canvas.drawText(bar.label, cx, height - context.dpf(5f), textPaint)
|
||||
} else if (i % 5 == 0 || i == lastIndex) {
|
||||
textPaint.color = context.col(R.color.text_tertiary)
|
||||
canvas.drawText(bar.label, cx, height - context.dpf(5f), textPaint)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user