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
4 changes: 3 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
<activity android:name="info.appdev.chartexample.LineChartDualAxisActivity" />
<activity android:name="info.appdev.chartexample.LineChartTimeActivity" />
<activity android:name="info.appdev.chartexample.BarChartActivity" />
<activity android:name="info.appdev.chartexample.BarRoundedChartActivity" />
<activity android:name="info.appdev.chartexample.HorizontalBarChartActivity" />
<activity android:name="info.appdev.chartexample.HorizontalBarRoundedChartActivity" />
<activity android:name="info.appdev.chartexample.compose.HorizontalBarComposeActivity" />
<activity android:name="info.appdev.chartexample.HorizontalBarNegativeChartActivity" />
<activity android:name="info.appdev.chartexample.PieChartActivity" />
Expand All @@ -38,7 +40,7 @@
<activity android:name="info.appdev.chartexample.ListViewBarChartActivity" />
<activity android:name="info.appdev.chartexample.ListViewMultiChartActivity" />
<activity android:name="info.appdev.chartexample.StackedBarActivity" />
<activity android:name="AnotherBarActivity" />
<activity android:name=".AnotherBarActivity" />
<activity android:name="info.appdev.chartexample.InvertedLineChartActivity" />
<activity android:name="info.appdev.chartexample.CandleStickChartActivity" />
<activity android:name="info.appdev.chartexample.CubicLineChartActivity" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ import info.appdev.chartexample.formatter.MyAxisValueFormatter
import info.appdev.chartexample.notimportant.DemoBase
import timber.log.Timber

class BarChartActivity : DemoBase(), OnSeekBarChangeListener, OnChartValueSelectedListener {
open class BarChartActivity : DemoBase(), OnSeekBarChangeListener, OnChartValueSelectedListener {

private lateinit var binding: ActivityBarchartBinding
lateinit var binding: ActivityBarchartBinding

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package info.appdev.chartexample

import android.os.Bundle
import info.appdev.chartexample.databinding.ActivityBarchartBinding

class BarRoundedChartActivity : BarChartActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding.chart1.isOwnRoundedRendererUsed = true
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ import info.appdev.chartexample.databinding.ActivityHorizontalbarchartBinding
import info.appdev.chartexample.notimportant.DemoBase
import timber.log.Timber

class HorizontalBarChartActivity : DemoBase(), OnSeekBarChangeListener, OnChartValueSelectedListener {
open class HorizontalBarChartActivity : DemoBase(), OnSeekBarChangeListener, OnChartValueSelectedListener {

private lateinit var binding: ActivityHorizontalbarchartBinding
lateinit var binding: ActivityHorizontalbarchartBinding

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package info.appdev.chartexample

import android.os.Bundle

class HorizontalBarRoundedChartActivity : HorizontalBarChartActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

binding.chart1.isOwnRoundedRendererUsed = true
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import info.appdev.chartexample.BarChartActivity
import info.appdev.chartexample.BarChartActivityMultiDataset
import info.appdev.chartexample.BarChartActivitySinus
import info.appdev.chartexample.BarChartPositiveNegative
import info.appdev.chartexample.BarRoundedChartActivity
import info.appdev.chartexample.BubbleChartActivity
import info.appdev.chartexample.CandleStickChartActivity
import info.appdev.chartexample.CombinedChartActivity
Expand All @@ -57,6 +58,7 @@ import info.appdev.chartexample.FilledLineActivity
import info.appdev.chartexample.GradientActivity
import info.appdev.chartexample.HalfPieChartActivity
import info.appdev.chartexample.HorizontalBarChartActivity
import info.appdev.chartexample.HorizontalBarRoundedChartActivity
import info.appdev.chartexample.InvertedLineChartActivity
import info.appdev.chartexample.LineChartActivity
import info.appdev.chartexample.LineChartActivityColored
Expand Down Expand Up @@ -167,9 +169,11 @@ class MainActivity : ComponentActivity() {

add(ContentItem("Bar Charts"))
add(ContentItem("Basic", "Simple bar chart.", BarChartActivity::class.java))
add(ContentItem("Basic with own rounded renderer", "Simple rounded bar chart.", BarRoundedChartActivity::class.java))
add(ContentItem("Basic 2", "Variation of the simple bar chart.", AnotherBarActivity::class.java))
add(ContentItem("Multiple", "Show multiple data sets.", BarChartActivityMultiDataset::class.java))
add(ContentItem("Horizontal", "Render bar chart horizontally.", HorizontalBarChartActivity::class.java))
add(ContentItem("Horizontal with own rounded renderer", "Render bar rounded chart horizontally.", HorizontalBarRoundedChartActivity::class.java))
add(ContentItem("Stacked", "Stacked bar chart.", StackedBarActivity::class.java))
add(ContentItem("Negative", "Positive and negative values with unique colors.", BarChartPositiveNegative::class.java))
//objects.add(ContentItem("Negative Horizontal", "demonstrates how to create a HorizontalBarChart with positive and negative values."))
Expand Down
16 changes: 15 additions & 1 deletion chartLib/src/main/kotlin/info/appdev/charting/charts/BarChart.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import info.appdev.charting.highlight.BarHighlighter
import info.appdev.charting.highlight.Highlight
import info.appdev.charting.interfaces.dataprovider.BarDataProvider
import info.appdev.charting.renderer.BarChartRenderer
import info.appdev.charting.renderer.RoundedBarChartRenderer
import timber.log.Timber
import java.util.Locale

Expand All @@ -26,6 +27,12 @@ open class BarChart : BarLineChartBase<BarData>, BarDataProvider {
*/
override var isHighlightFullBarEnabled: Boolean = false

override var isOwnRoundedRendererUsed: Boolean = false
set(value) {
field = value
init()
}

/**
* if set to true, all values are drawn above their bars, instead of below their top
*/
Expand Down Expand Up @@ -54,10 +61,17 @@ open class BarChart : BarLineChartBase<BarData>, BarDataProvider {

constructor(context: Context?, attrs: AttributeSet?, defStyle: Int) : super(context, attrs, defStyle)

protected open fun setRenderer() {
mRenderer = if (isOwnRoundedRendererUsed)
RoundedBarChartRenderer(this, mAnimator, viewPortHandler)
else
BarChartRenderer(this, mAnimator, viewPortHandler, mDrawRoundedBars, mRoundedBarRadius)
}

override fun init() {
super.init()

mRenderer = BarChartRenderer(this, mAnimator, viewPortHandler, mDrawRoundedBars, mRoundedBarRadius)
setRenderer()

setHighlighter(BarHighlighter(this))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ open class CombinedChart : BarLineChartBase<CombinedData>, CombinedDataProvider
* false to make it highlight single values (relevant only for stacked).
*/
override var isHighlightFullBarEnabled: Boolean = false
override var isOwnRoundedRendererUsed: Boolean = false
set(value) {
if (value) {
Timber.e("CombinedChart does not support Rounded Renderer")
}
}

/**
* if set to true, a grey area is drawn behind each bar that indicates the maximum value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import info.appdev.charting.data.Entry
import info.appdev.charting.highlight.Highlight
import info.appdev.charting.highlight.HorizontalBarHighlighter
import info.appdev.charting.renderer.HorizontalBarChartRenderer
import info.appdev.charting.renderer.RoundedHorizontalBarChartRenderer
import info.appdev.charting.renderer.XAxisRendererHorizontalBarChart
import info.appdev.charting.renderer.YAxisRendererHorizontalBarChart
import info.appdev.charting.utils.HorizontalViewPortHandler
Expand All @@ -35,6 +36,13 @@ open class HorizontalBarChart : BarChart {

constructor(context: Context?, attrs: AttributeSet?, defStyle: Int) : super(context, attrs, defStyle)

override fun setRenderer() {
mRenderer = if (isOwnRoundedRendererUsed)
RoundedHorizontalBarChartRenderer(this, mAnimator, viewPortHandler)
else
HorizontalBarChartRenderer(this, mAnimator, viewPortHandler)
}

init {
viewPortHandler = HorizontalViewPortHandler()

Expand All @@ -43,7 +51,6 @@ open class HorizontalBarChart : BarChart {
mLeftAxisTransformer = TransformerHorizontalBarChart(viewPortHandler)
mRightAxisTransformer = TransformerHorizontalBarChart(viewPortHandler)

mRenderer = HorizontalBarChartRenderer(this, mAnimator, viewPortHandler)
setHighlighter(HorizontalBarHighlighter(this))

axisRendererLeft = YAxisRendererHorizontalBarChart(viewPortHandler, mAxisLeft, mLeftAxisTransformer)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ interface BarDataProvider : BarLineScatterCandleBubbleDataProvider {
var isDrawBarShadowEnabled: Boolean
var isDrawValueAboveBarEnabled: Boolean
var isHighlightFullBarEnabled: Boolean
var isOwnRoundedRendererUsed : Boolean
}
Loading
Loading