mirror of
https://github.com/dzeiocom/charts.git
synced 2025-04-23 02:52:10 +00:00
fix: barchart: text overflowing if bar is too small (#41)
This commit is contained in:
parent
4f5fb6fae4
commit
b9379d6526
@ -52,7 +52,7 @@ class XAxis(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun getPositionOnRect(entry: Entry, drawableSpace: RectF): Double {
|
override fun getPositionOnRect(entry: Entry, drawableSpace: RectF): Double {
|
||||||
val result = drawableSpace.left + drawableSpace.width() * (entry.x - x) / getDataWidth()
|
val result = getPositionOnRect(entry.x, drawableSpace)
|
||||||
if (view.type == ChartType.GROUPED) {
|
if (view.type == ChartType.GROUPED) {
|
||||||
val serie = view.series.find { it.entries.contains(entry) }
|
val serie = view.series.find { it.entries.contains(entry) }
|
||||||
val index = view.series.indexOf(serie)
|
val index = view.series.indexOf(serie)
|
||||||
@ -61,6 +61,10 @@ class XAxis(
|
|||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun getPositionOnRect(position: Double, drawableSpace: RectF): Double {
|
||||||
|
return drawableSpace.left + drawableSpace.width() * (position - x) / getDataWidth()
|
||||||
|
}
|
||||||
|
|
||||||
override fun getXMax(): Double {
|
override fun getXMax(): Double {
|
||||||
return view.series.maxOf { serie ->
|
return view.series.maxOf { serie ->
|
||||||
if (serie.entries.isEmpty()) {
|
if (serie.entries.isEmpty()) {
|
||||||
@ -79,7 +83,7 @@ class XAxis(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var onValueFormat: (value: Double) -> String = { it -> it.roundToInt().toString() }
|
override var onValueFormat: (value: Double) -> String = { it -> it.roundToInt().toString() }
|
||||||
|
|
||||||
override fun onDraw(canvas: Canvas, space: RectF): Float {
|
override fun onDraw(canvas: Canvas, space: RectF): Float {
|
||||||
if (!enabled) {
|
if (!enabled) {
|
||||||
|
@ -41,6 +41,8 @@ sealed interface XAxisInterface {
|
|||||||
*/
|
*/
|
||||||
var scrollEnabled: Boolean
|
var scrollEnabled: Boolean
|
||||||
|
|
||||||
|
var onValueFormat: (value: Double) -> String
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* run when manually refreshing the system
|
* run when manually refreshing the system
|
||||||
*
|
*
|
||||||
@ -51,10 +53,23 @@ sealed interface XAxisInterface {
|
|||||||
/**
|
/**
|
||||||
* get the entry position on the rect
|
* get the entry position on the rect
|
||||||
*
|
*
|
||||||
|
* @param entry the entry to place
|
||||||
|
* @param drawableSpace the space it should go into
|
||||||
|
*
|
||||||
* @return the left side of the position of the entry
|
* @return the left side of the position of the entry
|
||||||
*/
|
*/
|
||||||
fun getPositionOnRect(entry: Entry, drawableSpace: RectF): Double
|
fun getPositionOnRect(entry: Entry, drawableSpace: RectF): Double
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get the entry position on the rect
|
||||||
|
*
|
||||||
|
* @param position the position of your point
|
||||||
|
* @param drawableSpace the space it should go into
|
||||||
|
*
|
||||||
|
* @return the left side of the position of the entry
|
||||||
|
*/
|
||||||
|
fun getPositionOnRect(position: Double, drawableSpace: RectF): Double
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get the maximum the X can get to
|
* get the maximum the X can get to
|
||||||
*/
|
*/
|
||||||
|
@ -36,7 +36,7 @@ class YAxis(
|
|||||||
strokeWidth = 4f
|
strokeWidth = 4f
|
||||||
}
|
}
|
||||||
|
|
||||||
var onValueFormat: (value: Float) -> String = { it -> it.roundToInt().toString() }
|
override var onValueFormat: (value: Float) -> String = { it -> it.roundToInt().toString() }
|
||||||
|
|
||||||
override var labelCount = 5
|
override var labelCount = 5
|
||||||
|
|
||||||
|
@ -39,6 +39,8 @@ sealed interface YAxisInterface {
|
|||||||
*/
|
*/
|
||||||
var scrollEnabled: Boolean
|
var scrollEnabled: Boolean
|
||||||
|
|
||||||
|
var onValueFormat: (value: Float) -> String
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* do the Zero line gets drawn?
|
* do the Zero line gets drawn?
|
||||||
*/
|
*/
|
||||||
|
@ -5,11 +5,11 @@ import android.graphics.Color
|
|||||||
import android.graphics.Paint
|
import android.graphics.Paint
|
||||||
import android.graphics.Rect
|
import android.graphics.Rect
|
||||||
import android.graphics.RectF
|
import android.graphics.RectF
|
||||||
import com.dzeio.charts.ChartView
|
import com.dzeio.charts.ChartViewInterface
|
||||||
import com.dzeio.charts.utils.drawRoundRect
|
import com.dzeio.charts.utils.drawRoundRect
|
||||||
|
|
||||||
class BarSerie(
|
class BarSerie(
|
||||||
private val view: ChartView
|
private val view: ChartViewInterface
|
||||||
) : BaseSerie(view) {
|
) : BaseSerie(view) {
|
||||||
|
|
||||||
private companion object {
|
private companion object {
|
||||||
@ -48,6 +48,7 @@ class BarSerie(
|
|||||||
val barWidth = view.xAxis.getEntryWidth(drawableSpace).toFloat()
|
val barWidth = view.xAxis.getEntryWidth(drawableSpace).toFloat()
|
||||||
|
|
||||||
val zero = view.yAxis.getPositionOnRect(0f, drawableSpace)
|
val zero = view.yAxis.getPositionOnRect(0f, drawableSpace)
|
||||||
|
.coerceIn(drawableSpace.top, drawableSpace.bottom)
|
||||||
|
|
||||||
var needUpdate = false
|
var needUpdate = false
|
||||||
|
|
||||||
@ -134,6 +135,10 @@ class BarSerie(
|
|||||||
|
|
||||||
textPaint.getTextBounds(text, 0, text.length, rect)
|
textPaint.getTextBounds(text, 0, text.length, rect)
|
||||||
|
|
||||||
|
if (barWidth < rect.width()) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
// text center X
|
// text center X
|
||||||
val textX = (posX + barWidth / 2)
|
val textX = (posX + barWidth / 2)
|
||||||
|
|
||||||
|
@ -4,11 +4,11 @@ import android.graphics.Canvas
|
|||||||
import android.graphics.Color
|
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.ChartViewInterface
|
||||||
import kotlin.math.abs
|
import kotlin.math.abs
|
||||||
|
|
||||||
class LineSerie(
|
class LineSerie(
|
||||||
private val view: ChartView
|
private val view: ChartViewInterface
|
||||||
) : BaseSerie(view) {
|
) : BaseSerie(view) {
|
||||||
|
|
||||||
private companion object {
|
private companion object {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user