Skip to content
Open
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 @@ -24,6 +24,7 @@ import info.appdev.chartexample.DataTools.Companion.setData
import info.appdev.chartexample.custom.MyMarkerView
import info.appdev.chartexample.databinding.ActivityLinechartBinding
import info.appdev.chartexample.notimportant.DemoBase
import info.appdev.charting.components.XAxis
import timber.log.Timber

/**
Expand All @@ -37,7 +38,7 @@ class LineChartActivity : DemoBase(), OnSeekBarChangeListener, OnChartValueSelec
super.onCreate(savedInstanceState)
binding = ActivityLinechartBinding.inflate(layoutInflater)
setContentView(binding.root)

binding.seekBarX.setOnSeekBarChangeListener(this)
binding.seekBarY.max = 180
binding.seekBarY.setOnSeekBarChangeListener(this)
Expand All @@ -47,6 +48,8 @@ class LineChartActivity : DemoBase(), OnSeekBarChangeListener, OnChartValueSelec

// disable description text
binding.chart1.description.isEnabled = false
binding.chart1.legend?.isEnabled = false
binding.chart1.xAxis.position = XAxis.XAxisPosition.BOTTOM

// enable touch gestures
binding.chart1.setTouchEnabled(true)
Expand Down Expand Up @@ -136,8 +139,7 @@ class LineChartActivity : DemoBase(), OnSeekBarChangeListener, OnChartValueSelec
binding.chart1.animateX(1500)

// get the legend (only possible after setting data)
val legend = binding.chart1.legend
legend.form = LegendForm.LINE
binding.chart1.legend.form = LegendForm.LINE
}

override fun onCreateOptionsMenu(menu: Menu): Boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ class LineChartActivityColored : DemoBase() {
chart.animateX(2500)
}

@Suppress("SameParameterValue")
private fun getData(range: Float): LineData {
val count = 36
val values = ArrayList<Entry>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,21 @@ import info.appdev.charting.data.BarData
import info.appdev.charting.data.ChartData
import info.appdev.chartexample.R

class BarChartItem(cd: ChartData<*>, c: Context) : ChartItem(cd) {
private val typeface: Typeface? = Typeface.createFromAsset(c.assets, "OpenSans-Regular.ttf")
class BarChartItem(chartData: ChartData<*>, context: Context) : ChartItem(chartData) {
private val typeface: Typeface? = Typeface.createFromAsset(context.assets, "OpenSans-Regular.ttf")

override val itemType: Int
get() = TYPE_BARCHART

@SuppressLint("InflateParams")
override fun getView(position: Int, convertView: View?, c: Context?): View? {
override fun getView(position: Int, convertView: View?, context: Context?): View? {
var convertView = convertView
val holder: ViewHolder

if (convertView == null) {
holder = ViewHolder()

convertView = LayoutInflater.from(c).inflate(
convertView = LayoutInflater.from(context).inflate(
R.layout.list_item_barchart, null
)
holder.chart = convertView.findViewById(R.id.chart)
Expand Down Expand Up @@ -58,10 +58,10 @@ class BarChartItem(cd: ChartData<*>, c: Context) : ChartItem(cd) {
rightAxis.spaceTop = 20f
rightAxis.axisMinimum = 0f // this replaces setStartAtZero(true)

chartData.setValueTypeface(typeface)
this@BarChartItem.chartData.setValueTypeface(typeface)

// set data
holder.chart!!.setData(chartData as BarData?)
holder.chart!!.setData(this@BarChartItem.chartData as BarData?)
holder.chart!!.setFitBars(true)

// do not forget to refresh the chart
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import info.appdev.charting.data.ChartData
abstract class ChartItem internal constructor(var chartData: ChartData<*>) {
abstract val itemType: Int

abstract fun getView(position: Int, convertView: View?, c: Context?): View?
abstract fun getView(position: Int, convertView: View?, context: Context?): View?

companion object {
const val TYPE_BARCHART: Int = 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,21 @@ import info.appdev.charting.data.ChartData
import info.appdev.charting.data.LineData
import info.appdev.chartexample.R

class LineChartItem(cd: ChartData<*>, c: Context) : ChartItem(cd) {
private val typeface: Typeface? = Typeface.createFromAsset(c.assets, "OpenSans-Regular.ttf")
class LineChartItem(chartData: ChartData<*>, context: Context) : ChartItem(chartData) {
private val typeface: Typeface? = Typeface.createFromAsset(context.assets, "OpenSans-Regular.ttf")

override val itemType: Int
get() = TYPE_LINECHART

@SuppressLint("InflateParams")
override fun getView(position: Int, convertView: View?, c: Context?): View {
override fun getView(position: Int, convertView: View?, context: Context?): View {
var convertView = convertView
val holder: ViewHolder

if (convertView == null) {
holder = ViewHolder()

convertView = LayoutInflater.from(c).inflate(
convertView = LayoutInflater.from(context).inflate(
R.layout.list_item_linechart, null
)
holder.chart = convertView.findViewById(R.id.chart)
Expand Down Expand Up @@ -58,7 +58,7 @@ class LineChartItem(cd: ChartData<*>, c: Context) : ChartItem(cd) {
rightAxis.axisMinimum = 0f // this replaces setStartAtZero(true)

// set data
holder.chart!!.setData(chartData as LineData?)
holder.chart!!.setData(this@LineChartItem.chartData as LineData?)

// do not forget to refresh the chart
// holder.chart.invalidate();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import info.appdev.charting.formatter.PercentFormatter
import info.appdev.charting.utils.ColorTemplate
import info.appdev.chartexample.R

class PieChartItem(cd: ChartData<*>, c: Context) : ChartItem(cd) {
private val typeface: Typeface? = Typeface.createFromAsset(c.assets, "OpenSans-Regular.ttf")
class PieChartItem(chartData: ChartData<*>, context: Context) : ChartItem(chartData) {
private val typeface: Typeface? = Typeface.createFromAsset(context.assets, "OpenSans-Regular.ttf")
private val centerText: SpannableString

init {
Expand All @@ -30,14 +30,14 @@ class PieChartItem(cd: ChartData<*>, c: Context) : ChartItem(cd) {
get() = TYPE_PIECHART

@SuppressLint("InflateParams")
override fun getView(position: Int, convertView: View?, c: Context?): View {
override fun getView(position: Int, convertView: View?, context: Context?): View {
var convertView = convertView
val holder: ViewHolder

if (convertView == null) {
holder = ViewHolder()

convertView = LayoutInflater.from(c).inflate(
convertView = LayoutInflater.from(context).inflate(
R.layout.list_item_piechart, null
)
holder.chart = convertView.findViewById(R.id.chart)
Expand All @@ -57,12 +57,12 @@ class PieChartItem(cd: ChartData<*>, c: Context) : ChartItem(cd) {
holder.chart!!.setUsePercentValues(true)
holder.chart!!.setExtraOffsets(5f, 10f, 50f, 10f)

chartData.setValueFormatter(PercentFormatter())
chartData.setValueTypeface(typeface)
chartData.setValueTextSize(11f)
chartData.setValueTextColor(Color.WHITE)
this@PieChartItem.chartData.setValueFormatter(PercentFormatter())
this@PieChartItem.chartData.setValueTypeface(typeface)
this@PieChartItem.chartData.setValueTextSize(11f)
this@PieChartItem.chartData.setValueTextColor(Color.WHITE)
// set data
holder.chart?.setData(chartData as PieData?)
holder.chart?.setData(this@PieChartItem.chartData as PieData?)

holder.chart?.legend?.apply {
verticalAlignment = Legend.LegendVerticalAlignment.TOP
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -527,15 +527,15 @@ abstract class BarLineChartBase<T : BarLineScatterCandleBubbleData<IBarLineScatt
/**
* draws the grid background
*/
protected fun drawGridBackground(c: Canvas) {
protected fun drawGridBackground(canvas: Canvas) {
if (mDrawGridBackground) {
// draw the grid background

c.drawRect(viewPortHandler.contentRect, mGridBackgroundPaint!!)
canvas.drawRect(viewPortHandler.contentRect, mGridBackgroundPaint!!)
}

if (this.isDrawBordersEnabled) {
c.drawRect(viewPortHandler.contentRect, mBorderPaint!!)
canvas.drawRect(viewPortHandler.contentRect, mBorderPaint!!)
}
}

Expand Down
4 changes: 2 additions & 2 deletions chartLib/src/main/kotlin/info/appdev/charting/charts/Chart.kt
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ abstract class Chart<T : ChartData<out IDataSet<out Entry>>> : ViewGroup, IBaseP
/**
* Draws the description text in the bottom right corner of the chart (per default)
*/
protected fun drawDescription(c: Canvas) {
protected fun drawDescription(canvas: Canvas) {
// check if description should be drawn

if (description.isEnabled) {
Expand All @@ -402,7 +402,7 @@ abstract class Chart<T : ChartData<out IDataSet<out Entry>>> : ViewGroup, IBaseP
y = position.y
}

c.drawText(description.text!!, x, y, mDescPaint)
canvas.drawText(description.text!!, x, y, mDescPaint)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ open class LineChartRenderer(
/**
* Draws a normal line.
*/
protected fun drawLinear(c: Canvas, dataSet: ILineDataSet) {
protected fun drawLinear(canvas: Canvas, dataSet: ILineDataSet) {
val entryCount = dataSet.entryCount

val pointsPerEntryPair = if (dataSet.isDrawSteppedEnabled) 4 else 2
Expand All @@ -266,14 +266,14 @@ open class LineChartRenderer(
val canvas: Canvas? = if (dataSet.isDashedLineEnabled) {
bitmapCanvas
} else {
c
canvas
}

xBounds.set(dataProvider, dataSet)

// if drawing filled is enabled
if (dataSet.isDrawFilledEnabled && entryCount > 0) {
drawLinearFill(c, dataSet, trans!!, xBounds)
drawLinearFill(canvas!!, dataSet, trans!!, xBounds)
}

// more than 1 color
Expand Down Expand Up @@ -491,10 +491,11 @@ open class LineChartRenderer(

val trans = dataProvider.getTransformer(dataSet.axisDependency)

// make sure the values do not interfear with the circles
// make sure the values do not interfere with the circles
var valOffset = (dataSet.circleRadius * 1.75f).toInt()

if (!dataSet.isDrawCirclesEnabled) valOffset = valOffset / 2
if (!dataSet.isDrawCirclesEnabled)
valOffset /= 2

xBounds.set(dataProvider, dataSet)

Expand Down Expand Up @@ -534,7 +535,7 @@ open class LineChartRenderer(

icon?.let {
canvas.drawImage(
it,
icon,
(x + iconsOffset.x).toInt(),
(y + iconsOffset.y).toInt()
)
Expand Down
48 changes: 25 additions & 23 deletions chartLib/src/main/kotlin/info/appdev/charting/utils/Fill.kt
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ open class Fill {
}

fun fillRect(
c: Canvas, paint: Paint,
canvas: Canvas, paint: Paint,
left: Float, top: Float, right: Float, bottom: Float,
gradientDirection: Direction?, mRoundedBarRadius: Float
) {
Expand All @@ -90,12 +90,12 @@ open class Fill {
}

if (this.isClipPathSupported) {
val save = c.save()
val save = canvas.save()

c.clipRect(left, top, right, bottom)
c.drawColor(mFinalColor!!)
canvas.clipRect(left, top, right, bottom)
canvas.drawColor(mFinalColor!!)

c.restoreToCount(save)
canvas.restoreToCount(save)
} else {
// save
val previous = paint.style
Expand All @@ -105,7 +105,7 @@ open class Fill {
paint.style = Paint.Style.FILL
paint.color = mFinalColor!!

c.drawRoundRect(RectF(left, top, right, bottom), mRoundedBarRadius, mRoundedBarRadius, paint)
canvas.drawRoundRect(RectF(left, top, right, bottom), mRoundedBarRadius, mRoundedBarRadius, paint)

// restore
paint.color = previousColor
Expand Down Expand Up @@ -142,7 +142,7 @@ open class Fill {

paint.shader = gradient

c.drawRoundRect(RectF(left, top, right, bottom), mRoundedBarRadius, mRoundedBarRadius, paint)
canvas.drawRoundRect(RectF(left, top, right, bottom), mRoundedBarRadius, mRoundedBarRadius, paint)
}

Type.DRAWABLE -> {
Expand All @@ -151,13 +151,15 @@ open class Fill {
}

drawable!!.setBounds(left.toInt(), top.toInt(), right.toInt(), bottom.toInt())
drawable!!.draw(c)
drawable!!.draw(canvas)
}
}
}

fun fillPath(
c: Canvas, path: Path, paint: Paint,
canvas: Canvas,
path: Path,
paint: Paint,
clipRect: RectF?
) {
when (this.type) {
Expand All @@ -169,12 +171,12 @@ open class Fill {
}

if (clipRect != null && this.isClipPathSupported) {
val save = c.save()
val save = canvas.save()

c.clipPath(path)
c.drawColor(mFinalColor!!)
canvas.clipPath(path)
canvas.drawColor(mFinalColor!!)

c.restoreToCount(save)
canvas.restoreToCount(save)
} else {
// save
val previous = paint.style
Expand All @@ -184,7 +186,7 @@ open class Fill {
paint.style = Paint.Style.FILL
paint.color = mFinalColor!!

c.drawPath(path, paint)
canvas.drawPath(path, paint)

// restore
paint.color = previousColor
Expand All @@ -196,16 +198,16 @@ open class Fill {
val gradient = LinearGradient(
0f,
0f,
c.width.toFloat(),
c.height.toFloat(),
canvas.width.toFloat(),
canvas.height.toFloat(),
this.gradientColors!!,
this.gradientPositions,
Shader.TileMode.MIRROR
)

paint.shader = gradient

c.drawPath(path, paint)
canvas.drawPath(path, paint)
}

Type.DRAWABLE -> {
Expand All @@ -215,18 +217,18 @@ open class Fill {

ensureClipPathSupported()

val save = c.save()
c.clipPath(path)
val save = canvas.save()
canvas.clipPath(path)

drawable!!.setBounds(
if (clipRect == null) 0 else clipRect.left.toInt(),
if (clipRect == null) 0 else clipRect.top.toInt(),
if (clipRect == null) c.width else clipRect.right.toInt(),
if (clipRect == null) c.height else clipRect.bottom.toInt()
if (clipRect == null) canvas.width else clipRect.right.toInt(),
if (clipRect == null) canvas.height else clipRect.bottom.toInt()
)
drawable!!.draw(c)
drawable!!.draw(canvas)

c.restoreToCount(save)
canvas.restoreToCount(save)
}
}
}
Expand Down
Loading