fix: fix for horizontal overflow started on vertical (#30)

This commit is contained in:
Florian Bouillon 2023-01-16 00:37:31 +01:00 committed by GitHub
parent 4cdace91ff
commit 4f5fb6fae4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 85 additions and 8 deletions

View File

@ -4,7 +4,7 @@ buildscript {
mavenCentral() mavenCentral()
} }
dependencies { dependencies {
classpath("com.android.tools.build:gradle:7.3.1") classpath("com.android.tools.build:gradle:7.4.0")
// NOTE: Do not place your application dependencies here; they belong // NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files // in the individual module build.gradle files
@ -12,8 +12,8 @@ buildscript {
} }
plugins { plugins {
id("com.android.application") version "7.3.1" apply false id("com.android.application") version "7.4.0" apply false
id("com.android.library") version "7.3.1" apply false id("com.android.library") version "7.4.0" apply false
id("org.jetbrains.kotlin.android") version "1.7.0" apply false id("org.jetbrains.kotlin.android") version "1.7.0" apply false
} }

View File

@ -42,8 +42,8 @@ sealed class BaseSerie(
for (i in 0 until entries.size) { for (i in 0 until entries.size) {
val it = entries[i] val it = entries[i]
if (it.x in minX..maxX) { if (it.x in minX..maxX) {
if (result.size == 0 && i > 0) { if (result.size < 2 && i > 0) {
result.add((entries[i - 1])) result.add(entries[i - 1])
} }
lastIndex = i lastIndex = i
result.add(it) result.add(it)

View File

@ -5,6 +5,7 @@ import android.graphics.Color
import android.graphics.Paint import android.graphics.Paint
import android.graphics.RectF import android.graphics.RectF
import com.dzeio.charts.ChartView import com.dzeio.charts.ChartView
import kotlin.math.abs
class LineSerie( class LineSerie(
private val view: ChartView private val view: ChartView
@ -80,15 +81,91 @@ class LineSerie(
paint.color = entry.color!! paint.color = entry.color!!
} }
val doDraw = drawableSpace.contains(posX, top) ||
(
previousPosX != null &&
previousPosY != null &&
drawableSpace.contains(previousPosX, previousPosY)
) || (
previousPosX != null &&
previousPosY != null &&
posX < drawableSpace.right && (
top <= drawableSpace.top &&
previousPosY >= drawableSpace.bottom ||
top >= drawableSpace.top &&
previousPosY <= drawableSpace.bottom
)
)
// draw smol point // draw smol point
if (posX < drawableSpace.right) { if (drawableSpace.contains(posX, top)) {
canvas.drawCircle(posX, top, paint.strokeWidth, paint) canvas.drawCircle(posX, top, paint.strokeWidth, paint)
} }
// draw line // draw line
if (previousPosX != null && previousPosY != null) { if (doDraw && previousPosY != null && previousPosX != null) {
canvas.drawLine(previousPosX, previousPosY, posX, top, paint) var startX = previousPosX
var startY = previousPosY
var stopX = posX
var stopY = top
val debugPaint = Paint(linePaint)
val py = previousPosY
val px = previousPosX
val dy = abs(py - top)
val dx = abs(posX - px)
if (previousPosX < drawableSpace.left) {
val ratio = dy / dx
val dcx = abs(px)
val dcy = dcx * ratio
val ny = if (startY > stopY) py - dcy else py + dcy
startY = ny
startX = drawableSpace.left
debugPaint.color = Color.YELLOW
} else if (posX > drawableSpace.right) {
val ratio = dy / dx
val dcx = posX - drawableSpace.right
val dcy = dcx * ratio
val ny = if (py > top) top + dcy else top - dcy
stopY = ny
stopX = drawableSpace.right
debugPaint.color = Color.GRAY
}
if (
startX == previousPosX &&
(previousPosY > drawableSpace.bottom || previousPosY < drawableSpace.top)
) {
val dvb = if (top > py) top else drawableSpace.bottom - top
val ratio = dx / dy
val dcy = dy - dvb
val dcx = dcy * ratio
val nx = px + dcx
startX = nx
startY = if (top > py) drawableSpace.top else drawableSpace.bottom
debugPaint.color = Color.BLUE
}
if (top > drawableSpace.bottom) {
val ratio = dx / dy
val dcy = drawableSpace.bottom - py
val dcx = dcy * ratio
stopX = px + dcx
stopY = drawableSpace.bottom
if (startX != previousPosX) {
debugPaint.color = Color.GREEN
} else {
debugPaint.color = Color.RED
}
}
canvas.drawLine(startX, startY, stopX, stopY, if (view.debug) debugPaint else linePaint)
} }
previousPosX = posX previousPosX = posX
previousPosY = top previousPosY = top