Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class BarChartActivityMultiDataset : DemoBase(), OnSeekBarChangeListener, OnChar
val xAxis = binding.chart1.xAxis
xAxis.typeface = tfLight
xAxis.granularity = 1f
xAxis.setCenterAxisLabels(true)
xAxis.centerAxisLabels = true
xAxis.valueFormatter = object : IAxisValueFormatter {
override fun getFormattedValue(value: Float, axis: AxisBase?): String {
return value.toInt().toString()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class BarChartPositiveNegative : DemoBase() {
xAxis.textColor = Color.LTGRAY
xAxis.textSize = 13f
xAxis.labelCount = 5
xAxis.setCenterAxisLabels(true)
xAxis.centerAxisLabels = true
xAxis.granularity = 1f

val left = binding.chart1.axisLeft
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class LineChartTimeActivity : DemoBase(), OnSeekBarChangeListener {
xAxis.isDrawAxisLine = false
xAxis.isDrawGridLines = true
xAxis.textColor = Color.rgb(255, 192, 56)
xAxis.setCenterAxisLabels(true)
xAxis.centerAxisLabels = true
xAxis.granularity = 1f // one hour
xAxis.valueFormatter = object : IAxisValueFormatter {
private val simpleDateFormat = SimpleDateFormat("dd MMM HH:mm", Locale.ENGLISH)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class StackedBarActivityNegative : DemoBase(), OnChartValueSelectedListener {
xAxis.textSize = 9f
xAxis.axisMinimum = 0f
xAxis.axisMaximum = 110f
xAxis.setCenterAxisLabels(true)
xAxis.centerAxisLabels = true
xAxis.labelCount = 12
xAxis.granularity = 10f
xAxis.valueFormatter = object : IAxisValueFormatter {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ abstract class BarLineChartBase<T : BarLineScatterCandleBubbleData<IBarLineScatt
}

if (mXAxis.isEnabled && mXAxis.isDrawLabelsEnabled) {
val xLabelHeight = mXAxis.mLabelHeight + mXAxis.yOffset
val xLabelHeight = mXAxis.labelHeight + mXAxis.yOffset

// offsets for x-labels
when (mXAxis.position) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ open class HorizontalBarChart : BarChart {
offsetBottom += mAxisRight.getRequiredHeightSpace(axisRendererRight.paintAxisLabels)
}

val xLabelWidth = mXAxis.mLabelWidth.toFloat()
val xLabelWidth = mXAxis.labelWidth.toFloat()

if (mXAxis.isEnabled) {
// offsets for x-labels
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ abstract class PieRadarChartBase<T : ChartData<out IDataSet<out Entry>>>
val x = this.xAxis

if (x.isEnabled && x.isDrawLabelsEnabled) {
minOffset = max(minOffset, x.mLabelWidth.toFloat())
minOffset = max(minOffset, x.labelWidth.toFloat())
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ open class RadarChart : PieRadarChartBase<RadarData> {
}

override val requiredBaseOffset: Float
get() = if (mXAxis.isEnabled && mXAxis.isDrawLabelsEnabled) mXAxis.mLabelWidth.toFloat() else 10f.convertDpToPixel()
get() = if (mXAxis.isEnabled && mXAxis.isDrawLabelsEnabled) mXAxis.labelWidth.toFloat() else 10f.convertDpToPixel()

override val radius: Float
get() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ abstract class AxisBase : ComponentBase() {
/**
* custom formatter that is used instead of the auto-formatter if set
*/
protected var mAxisValueFormatter: IAxisValueFormatter? = null
protected var axisValueFormatter: IAxisValueFormatter? = null

/**
* The color of the grid lines for this axis (the horizontal lines
Expand Down Expand Up @@ -96,7 +96,11 @@ abstract class AxisBase : ComponentBase() {
var isDrawLabelsEnabled = true
protected set

protected var mCenterAxisLabels: Boolean = false
/**
* Centers the axis labels instead of drawing them at their original position.
* This is useful especially for grouped BarChart.
*/
var centerAxisLabels: Boolean = false

/**
* the path effect of the axis line that makes dashed lines possible
Expand Down Expand Up @@ -212,16 +216,8 @@ abstract class AxisBase : ComponentBase() {
this.limitRanges = ArrayList<LimitRange>()
}

/**
* Centers the axis labels instead of drawing them at their original position.
* This is useful especially for grouped BarChart.
*/
fun setCenterAxisLabels(enabled: Boolean) {
mCenterAxisLabels = enabled
}

val isCenterAxisLabelsEnabled: Boolean
get() = mCenterAxisLabels && entryCount > 0
get() = centerAxisLabels && entryCount > 0

/**
* The width of the border surrounding the chart in dp.
Expand Down Expand Up @@ -401,16 +397,18 @@ abstract class AxisBase : ComponentBase() {
*/
var valueFormatter: IAxisValueFormatter?
get() {
if (mAxisValueFormatter == null || (mAxisValueFormatter is DefaultAxisValueFormatter &&
(mAxisValueFormatter as DefaultAxisValueFormatter).decimalDigits != decimals)
if (axisValueFormatter == null ||
(axisValueFormatter is DefaultAxisValueFormatter && (axisValueFormatter as DefaultAxisValueFormatter).decimalDigits != decimals)
)
mAxisValueFormatter = DefaultAxisValueFormatter(decimals)
axisValueFormatter = DefaultAxisValueFormatter(decimals)

return mAxisValueFormatter
return axisValueFormatter
}
set(f) {
if (f == null) mAxisValueFormatter = DefaultAxisValueFormatter(decimals)
else mAxisValueFormatter = f
if (f == null)
axisValueFormatter = DefaultAxisValueFormatter(decimals)
else
axisValueFormatter = f
}

/**
Expand Down Expand Up @@ -518,17 +516,15 @@ abstract class AxisBase : ComponentBase() {

/**
* By calling this method, any custom maximum value that has been previously set is reseted,
* and the calculation is
* done automatically.
* and the calculation is done automatically.
*/
fun resetAxisMaximum() {
this.isAxisMaxCustom = false
}

/**
* By calling this method, any custom minimum value that has been previously set is reseted,
* and the calculation is
* done automatically.
* and the calculation is done automatically.
*/
fun resetAxisMinimum() {
this.isAxisMinCustom = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,19 @@ class XAxis : AxisBase() {
* width of the x-axis labels in pixels - this is automatically
* calculated by the computeSize() methods in the renderers
*/
var mLabelWidth: Int = 1
var labelWidth: Int = 1

/**
* height of the x-axis labels in pixels - this is automatically
* calculated by the computeSize() methods in the renderers
*/
var mLabelHeight: Int = 1
var labelHeight: Int = 1

/**
* This is the angle for drawing the X axis labels (in degrees)
*/
var labelRotationAngle: Float = 0f


/**
* if set to true, the chart will avoid that the first and last label entry
* in the chart "clip" off the edge of the chart
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ open class XAxisRenderer(
xAxis.labelRotationAngle
)

xAxis.mLabelWidth = labelRotatedSize.width.roundToInt()
xAxis.mLabelHeight = labelRotatedSize.height.roundToInt()
xAxis.labelWidth = labelRotatedSize.width.roundToInt()
xAxis.labelHeight = labelRotatedSize.height.roundToInt()

FSize.recycleInstance(labelRotatedSize)
FSize.recycleInstance(labelSize)
Expand All @@ -110,7 +110,7 @@ open class XAxisRenderer(
XAxisPosition.TOP_INSIDE -> {
pointF.x = 0.5f
pointF.y = 1.0f
drawLabels(canvas, viewPortHandler.contentTop() + yOffset + xAxis.mLabelHeight, pointF)
drawLabels(canvas, viewPortHandler.contentTop() + yOffset + xAxis.labelHeight, pointF)
}

XAxisPosition.BOTTOM -> {
Expand All @@ -122,7 +122,7 @@ open class XAxisRenderer(
XAxisPosition.BOTTOM_INSIDE -> {
pointF.x = 0.5f
pointF.y = 0.0f
drawLabels(canvas, viewPortHandler.contentBottom() - yOffset - xAxis.mLabelHeight, pointF)
drawLabels(canvas, viewPortHandler.contentBottom() - yOffset - xAxis.labelHeight, pointF)
}

else -> { // BOTH SIDED
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ open class XAxisRendererHorizontalBarChart(
xAxis.labelRotationAngle
)

xAxis.mLabelWidth = labelRotatedSize.width.roundToInt()
xAxis.mLabelHeight = labelRotatedSize.height.roundToInt()
xAxis.labelWidth = labelRotatedSize.width.roundToInt()
xAxis.labelHeight = labelRotatedSize.height.roundToInt()

FSize.recycleInstance(labelRotatedSize)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ class XAxisRendererRadarChart(

val angle = (sliceAngle * i + chart.rotationAngle) % 360f

pOut = center.getPosition(chart.yRange * factor + xAxis.mLabelWidth / 2f, angle)
pOut = center.getPosition(chart.yRange * factor + xAxis.labelWidth / 2f, angle)

drawLabel(
canvas, label, pOut.x, pOut.y - xAxis.mLabelHeight / 2f,
canvas, label, pOut.x, pOut.y - xAxis.labelHeight / 2f,
drawLabelAnchor, labelRotationAngleDegrees
)
}
Expand Down
Loading