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
12 changes: 12 additions & 0 deletions app/src/androidTest/kotlin/info/appdev/chartexample/StartTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.platform.app.InstrumentationRegistry.getInstrumentation
import info.appdev.chartexample.compose.HorizontalBarComposeActivity
import info.appdev.chartexample.compose.HorizontalBarFullComposeActivity
import info.appdev.chartexample.compose.MultiLineComposeActivity
import info.appdev.chartexample.fragments.ViewPagerSimpleChartDemo
import info.appdev.chartexample.notimportant.ContentItem
import info.appdev.chartexample.notimportant.DemoBase
Expand Down Expand Up @@ -185,6 +186,16 @@ class StartTest {
optionMenu = "$index->$menuTitle"
Timber.d("Testing Compose menu item: $optionMenu")

// Check if menu item exists first
try {
composeTestRule
.onNodeWithTag("menuItem_$menuTitle")
.assertExists()
} catch (_: AssertionError) {
Timber.e("Menu item '$menuTitle' not found for ${contentClass.simpleName}, skipping")
return@forEach
}

// Click the menu item
composeTestRule
.onNodeWithTag("menuItem_$menuTitle")
Expand Down Expand Up @@ -265,6 +276,7 @@ class StartTest {
contentItem.clazz == LineChartTimeActivity::class.java ||
contentItem.clazz == HorizontalBarComposeActivity::class.java ||
contentItem.clazz == HorizontalBarFullComposeActivity::class.java ||
contentItem.clazz == MultiLineComposeActivity::class.java ||
contentItem.clazz == GradientActivity::class.java ||
contentItem.clazz == TimeLineActivity::class.java
) {
Expand Down
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
<activity android:name="info.appdev.chartexample.HorizontalBarChartActivity" />
<activity android:name="info.appdev.chartexample.compose.HorizontalBarComposeActivity" />
<activity android:name="info.appdev.chartexample.compose.HorizontalBarFullComposeActivity" />
<activity android:name="info.appdev.chartexample.compose.MultiLineComposeActivity" />
<activity android:name="info.appdev.chartexample.HorizontalBarNegativeChartActivity" />
<activity android:name="info.appdev.chartexample.PieChartActivity" />
<activity android:name="info.appdev.chartexample.PieChartRoundedActivity" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import androidx.compose.material3.TopAppBar
import androidx.compose.material3.TopAppBarDefaults
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.key
import androidx.compose.runtime.mutableFloatStateOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
Expand Down Expand Up @@ -66,14 +67,23 @@ class HorizontalBarFullComposeActivity : DemoBaseCompose() {
onSaveToGallery: () -> Unit,
onViewGithub: () -> Unit
) {
// State management
var showValues by remember { mutableStateOf(true) }
var showIcons by remember { mutableStateOf(false) }
var highlightEnabled by remember { mutableStateOf(true) }
var pinchZoomEnabled by remember { mutableStateOf(true) }
var autoScaleMinMaxEnabled by remember { mutableStateOf(false) }
var barBordersEnabled by remember { mutableStateOf(false) }
var animationTrigger by remember { mutableStateOf(0) }

var showMenu by remember { mutableStateOf(false) }
var seekBarXValue by remember { mutableFloatStateOf(12f) }
var seekBarYValue by remember { mutableFloatStateOf(50f) }

Scaffold(
topBar = {
TopAppBar(
title = { Text(this.javaClass.simpleName.replace("Activity", "")) },
title = { Text("HorizontalBarFullCompose") },
colors = TopAppBarDefaults.topAppBarColors(
containerColor = MaterialTheme.colorScheme.primary,
titleContentColor = MaterialTheme.colorScheme.onPrimary
Expand Down Expand Up @@ -107,71 +117,71 @@ class HorizontalBarFullComposeActivity : DemoBaseCompose() {
text = { Text("Toggle Values") },
onClick = {
showMenu = false
toggleValues()
showValues = !showValues
},
modifier = Modifier.testTag("menuItem_Toggle Values")
)
DropdownMenuItem(
text = { Text("Toggle Icons") },
onClick = {
showMenu = false
toggleIcons()
showIcons = !showIcons
},
modifier = Modifier.testTag("menuItem_Toggle Icons")
)
DropdownMenuItem(
text = { Text("Toggle Highlight") },
onClick = {
showMenu = false
toggleHighlight()
highlightEnabled = !highlightEnabled
},
modifier = Modifier.testTag("menuItem_Toggle Highlight")
)
DropdownMenuItem(
text = { Text("Toggle Pinch Zoom") },
onClick = {
showMenu = false
togglePinchZoom()
pinchZoomEnabled = !pinchZoomEnabled
},
modifier = Modifier.testTag("menuItem_Toggle Pinch Zoom")
)
DropdownMenuItem(
text = { Text("Toggle Auto Scale MinMax") },
onClick = {
showMenu = false
toggleAutoScaleMinMax()
autoScaleMinMaxEnabled = !autoScaleMinMaxEnabled
},
modifier = Modifier.testTag("menuItem_Toggle Auto Scale MinMax")
)
DropdownMenuItem(
text = { Text("Toggle Bar Borders") },
onClick = {
showMenu = false
toggleBarBorders()
barBordersEnabled = !barBordersEnabled
},
modifier = Modifier.testTag("menuItem_Toggle Bar Borders")
)
DropdownMenuItem(
text = { Text("Animate X") },
onClick = {
showMenu = false
animateX()
animationTrigger++
},
modifier = Modifier.testTag("menuItem_Animate X")
)
DropdownMenuItem(
text = { Text("Animate Y") },
onClick = {
showMenu = false
animateY()
animationTrigger++
},
modifier = Modifier.testTag("menuItem_Animate Y")
)
DropdownMenuItem(
text = { Text("Animate XY") },
onClick = {
showMenu = false
animateXY()
animationTrigger++
},
modifier = Modifier.testTag("menuItem_Animate XY")
)
Expand All @@ -196,51 +206,74 @@ class HorizontalBarFullComposeActivity : DemoBaseCompose() {
.background(Color.White)
) {
// Chart - Using Compose HorizontalBarChart
val barData = remember(seekBarXValue, seekBarYValue) {
createBarData(seekBarXValue.toInt(), seekBarYValue)
val barData = remember(
seekBarXValue,
seekBarYValue,
showIcons,
barBordersEnabled,
showValues
) {
createBarData(
seekBarXValue.toInt(),
seekBarYValue,
showIcons,
barBordersEnabled,
showValues
)
}

HorizontalBarChart(
data = barData,
modifier = Modifier
.fillMaxWidth()
.weight(1f),
drawValueAboveBar = true,
drawBarShadow = false,
animationDuration = 2500,
onValueSelected = { entry, highlight ->
entry?.let {
Timber.d("Selected: x=${it.x}, y=${it.y}")
key(showIcons) {
HorizontalBarChart(
data = barData,
modifier = Modifier
.fillMaxWidth()
.weight(1f)
.testTag("horizontalBarChart_$showIcons"),
drawValueAboveBar = true,
drawBarShadow = false,
scaleEnabled = pinchZoomEnabled,
touchEnabled = true,
dragEnabled = true,
highlightFullBarEnabled = highlightEnabled,
animationDuration = if (animationTrigger > 0) 2500 else 0,
onValueSelected = { entry, _ ->
entry?.let {
Timber.d("Selected: x=${it.x}, y=${it.y}")
}
},
xAxisConfig = { xAxis ->
xAxis.position = XAxisPosition.BOTTOM
xAxis.typeface = tfLight
xAxis.isDrawAxisLine = true
xAxis.isDrawGridLines = false
xAxis.granularity = 10f
},
leftAxisConfig = { leftAxis ->
leftAxis.typeface = tfLight
leftAxis.isDrawAxisLine = true
leftAxis.isDrawGridLines = true
if (!autoScaleMinMaxEnabled) {
leftAxis.axisMinimum = 0f
}
},
rightAxisConfig = { rightAxis ->
rightAxis.typeface = tfLight
rightAxis.isDrawAxisLine = true
rightAxis.isDrawGridLines = false
if (!autoScaleMinMaxEnabled) {
rightAxis.axisMinimum = 0f
}
},
legend = { legend ->
legend.verticalAlignment = Legend.LegendVerticalAlignment.BOTTOM
legend.horizontalAlignment = Legend.LegendHorizontalAlignment.LEFT
legend.orientation = Legend.LegendOrientation.HORIZONTAL
legend.setDrawInside(false)
legend.formSize = 8f
legend.xEntrySpace = 4f
}
},
xAxisConfig = { xAxis ->
xAxis.position = XAxisPosition.BOTTOM
xAxis.typeface = tfLight
xAxis.isDrawAxisLine = true
xAxis.isDrawGridLines = false
xAxis.granularity = 10f
},
leftAxisConfig = { leftAxis ->
leftAxis.typeface = tfLight
leftAxis.isDrawAxisLine = true
leftAxis.isDrawGridLines = true
leftAxis.axisMinimum = 0f
},
rightAxisConfig = { rightAxis ->
rightAxis.typeface = tfLight
rightAxis.isDrawAxisLine = true
rightAxis.isDrawGridLines = false
rightAxis.axisMinimum = 0f
},
legend = { legend ->
legend.verticalAlignment = Legend.LegendVerticalAlignment.BOTTOM
legend.horizontalAlignment = Legend.LegendHorizontalAlignment.LEFT
legend.orientation = Legend.LegendOrientation.HORIZONTAL
legend.setDrawInside(false)
legend.formSize = 8f
legend.xEntrySpace = 4f
}
)
)
}

// SeekBar X with label
Row(
Expand Down Expand Up @@ -289,24 +322,33 @@ class HorizontalBarFullComposeActivity : DemoBaseCompose() {
}
}

private fun createBarData(count: Int, range: Float): BarData {
private fun createBarData(count: Int, range: Float, showIcons: Boolean, barBordersEnabled: Boolean, showValues: Boolean): BarData {
val barWidth = 9f
val spaceForBar = 10f
val values = ArrayList<BarEntry>()
val sampleValues = getValues(100)

for (i in 0..<count) {
val value = sampleValues[i]!!.toFloat() * range
val barEntry = BarEntry(
i * spaceForBar, value,
val icon = if (showIcons) {
ResourcesCompat.getDrawable(resources, R.drawable.star, null)
)
} else null

val barEntry = BarEntry(i * spaceForBar, value, icon)
Timber.d("x=${barEntry.x} y=${barEntry.y}")
values.add(barEntry)
}

val set1 = BarDataSet(values, "DataSet 1")
set1.isDrawIcons = false
set1.isDrawIcons = showIcons
set1.isDrawValues = showValues

if (barBordersEnabled) {
set1.barBorderWidth = 1f
set1.barBorderColor = android.graphics.Color.BLACK
} else {
set1.barBorderWidth = 0f
}

val data = BarData(set1)
data.setValueTextSize(10f)
Expand All @@ -315,42 +357,5 @@ class HorizontalBarFullComposeActivity : DemoBaseCompose() {
return data
}

// Note: The following methods are not functional with the Compose wrapper
// They would need to be implemented differently using state management
private fun toggleValues() {
Timber.d("toggleValues not yet implemented for Compose wrapper")
}

private fun toggleIcons() {
Timber.d("toggleIcons not yet implemented for Compose wrapper")
}

private fun toggleHighlight() {
Timber.d("toggleHighlight not yet implemented for Compose wrapper")
}

private fun togglePinchZoom() {
Timber.d("togglePinchZoom not yet implemented for Compose wrapper")
}

private fun toggleAutoScaleMinMax() {
Timber.d("toggleAutoScaleMinMax not yet implemented for Compose wrapper")
}

private fun toggleBarBorders() {
Timber.d("toggleBarBorders not yet implemented for Compose wrapper")
}

private fun animateX() {
Timber.d("animateX not yet implemented for Compose wrapper")
}

private fun animateY() {
Timber.d("animateY not yet implemented for Compose wrapper")
}

private fun animateXY() {
Timber.d("animateXY not yet implemented for Compose wrapper")
}

}
Loading
Loading