Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix: fix for horizontal overflow started on vertical #30

Merged
merged 3 commits into from
Jan 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ buildscript {
mavenCentral()
}
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
// in the individual module build.gradle files
}
}

plugins {
id("com.android.application") version "7.3.1" apply false
id("com.android.library") version "7.3.1" apply false
id("com.android.application") version "7.4.0" apply false
id("com.android.library") version "7.4.0" apply false
id("org.jetbrains.kotlin.android") version "1.7.0" apply false
}

Expand Down
4 changes: 2 additions & 2 deletions library/src/main/java/com/dzeio/charts/series/BaseSerie.kt
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ sealed class BaseSerie(
for (i in 0 until entries.size) {
val it = entries[i]
if (it.x in minX..maxX) {
if (result.size == 0 && i > 0) {
result.add((entries[i - 1]))
if (result.size < 2 && i > 0) {
result.add(entries[i - 1])
}
lastIndex = i
result.add(it)
Expand Down
83 changes: 80 additions & 3 deletions library/src/main/java/com/dzeio/charts/series/LineSerie.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import android.graphics.Color
import android.graphics.Paint
import android.graphics.RectF
import com.dzeio.charts.ChartView
import kotlin.math.abs

class LineSerie(
private val view: ChartView
Expand Down Expand Up @@ -80,15 +81,91 @@ class LineSerie(
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
if (posX < drawableSpace.right) {
if (drawableSpace.contains(posX, top)) {
canvas.drawCircle(posX, top, paint.strokeWidth, paint)
}

// draw line
if (previousPosX != null && previousPosY != null) {
canvas.drawLine(previousPosX, previousPosY, posX, top, paint)
if (doDraw && previousPosY != null && previousPosX != null) {
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
previousPosY = top
Expand Down