Skip to content

Commit b0a565d

Browse files
committed
Dark and light theme support added.
1 parent f6c7eab commit b0a565d

File tree

64 files changed

+4740
-1195
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+4740
-1195
lines changed

README.md

Lines changed: 384 additions & 218 deletions
Large diffs are not rendered by default.

app/api/app.api

Lines changed: 37 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -18,40 +18,14 @@ public final class io/androidpoet/drafterdemo/ChartTitleKt {
1818
public final class io/androidpoet/drafterdemo/ComposableSingletons$MainActivityKt {
1919
public static final field INSTANCE Lio/androidpoet/drafterdemo/ComposableSingletons$MainActivityKt;
2020
public static field lambda-1 Lkotlin/jvm/functions/Function3;
21-
public static field lambda-10 Lkotlin/jvm/functions/Function3;
22-
public static field lambda-11 Lkotlin/jvm/functions/Function3;
23-
public static field lambda-12 Lkotlin/jvm/functions/Function3;
24-
public static field lambda-13 Lkotlin/jvm/functions/Function3;
25-
public static field lambda-14 Lkotlin/jvm/functions/Function3;
26-
public static field lambda-15 Lkotlin/jvm/functions/Function3;
27-
public static field lambda-16 Lkotlin/jvm/functions/Function2;
28-
public static field lambda-17 Lkotlin/jvm/functions/Function2;
2921
public static field lambda-2 Lkotlin/jvm/functions/Function3;
30-
public static field lambda-3 Lkotlin/jvm/functions/Function3;
31-
public static field lambda-4 Lkotlin/jvm/functions/Function3;
32-
public static field lambda-5 Lkotlin/jvm/functions/Function3;
33-
public static field lambda-6 Lkotlin/jvm/functions/Function3;
34-
public static field lambda-7 Lkotlin/jvm/functions/Function3;
35-
public static field lambda-8 Lkotlin/jvm/functions/Function3;
36-
public static field lambda-9 Lkotlin/jvm/functions/Function3;
22+
public static field lambda-3 Lkotlin/jvm/functions/Function2;
23+
public static field lambda-4 Lkotlin/jvm/functions/Function2;
3724
public fun <init> ()V
3825
public final fun getLambda-1$app_release ()Lkotlin/jvm/functions/Function3;
39-
public final fun getLambda-10$app_release ()Lkotlin/jvm/functions/Function3;
40-
public final fun getLambda-11$app_release ()Lkotlin/jvm/functions/Function3;
41-
public final fun getLambda-12$app_release ()Lkotlin/jvm/functions/Function3;
42-
public final fun getLambda-13$app_release ()Lkotlin/jvm/functions/Function3;
43-
public final fun getLambda-14$app_release ()Lkotlin/jvm/functions/Function3;
44-
public final fun getLambda-15$app_release ()Lkotlin/jvm/functions/Function3;
45-
public final fun getLambda-16$app_release ()Lkotlin/jvm/functions/Function2;
46-
public final fun getLambda-17$app_release ()Lkotlin/jvm/functions/Function2;
4726
public final fun getLambda-2$app_release ()Lkotlin/jvm/functions/Function3;
48-
public final fun getLambda-3$app_release ()Lkotlin/jvm/functions/Function3;
49-
public final fun getLambda-4$app_release ()Lkotlin/jvm/functions/Function3;
50-
public final fun getLambda-5$app_release ()Lkotlin/jvm/functions/Function3;
51-
public final fun getLambda-6$app_release ()Lkotlin/jvm/functions/Function3;
52-
public final fun getLambda-7$app_release ()Lkotlin/jvm/functions/Function3;
53-
public final fun getLambda-8$app_release ()Lkotlin/jvm/functions/Function3;
54-
public final fun getLambda-9$app_release ()Lkotlin/jvm/functions/Function3;
27+
public final fun getLambda-3$app_release ()Lkotlin/jvm/functions/Function2;
28+
public final fun getLambda-4$app_release ()Lkotlin/jvm/functions/Function2;
5529
}
5630

5731
public final class io/androidpoet/drafterdemo/MainActivity : androidx/activity/ComponentActivity {
@@ -60,88 +34,79 @@ public final class io/androidpoet/drafterdemo/MainActivity : androidx/activity/C
6034
}
6135

6236
public final class io/androidpoet/drafterdemo/bars/GroupedBarChartExampleKt {
63-
public static final fun GroupedBarChartExample (Landroidx/compose/runtime/Composer;I)V
37+
public static final fun GroupedBarChartExample (Ljava/util/List;Landroidx/compose/ui/Modifier;Landroidx/compose/runtime/Composer;II)V
6438
}
6539

6640
public final class io/androidpoet/drafterdemo/bars/HistogramChartExampleKt {
6741
public static final fun HistogramChartExample (Landroidx/compose/ui/Modifier;ZLandroidx/compose/runtime/Composer;II)V
6842
}
6943

7044
public final class io/androidpoet/drafterdemo/bars/SimpleBarChartExampleKt {
71-
public static final fun SimpleBarChartExample (Landroidx/compose/runtime/Composer;I)V
45+
public static final fun SimpleBarChartExample (Ljava/util/List;Landroidx/compose/ui/Modifier;Landroidx/compose/runtime/Composer;II)V
7246
}
7347

7448
public final class io/androidpoet/drafterdemo/bars/StackedBarChartExampleKt {
75-
public static final fun StackedBarChartExample (Landroidx/compose/ui/Modifier;Landroidx/compose/runtime/Composer;II)V
49+
public static final fun StackedBarChartExample (Ljava/util/List;Landroidx/compose/ui/Modifier;Landroidx/compose/runtime/Composer;II)V
7650
}
7751

7852
public final class io/androidpoet/drafterdemo/bars/WaterfallChartExampleKt {
79-
public static final fun WaterfallChartExample (Landroidx/compose/ui/Modifier;Landroidx/compose/runtime/Composer;II)V
53+
public static final fun WaterfallChartExample (Ljava/util/List;Landroidx/compose/ui/Modifier;Landroidx/compose/runtime/Composer;II)V
8054
}
8155

8256
public final class io/androidpoet/drafterdemo/buble/BubbleChartKt {
83-
public static final fun BubbleChartExample (Landroidx/compose/runtime/Composer;I)V
57+
public static final fun BubbleChartExample (Ljava/util/List;Landroidx/compose/ui/Modifier;Landroidx/compose/runtime/Composer;II)V
8458
}
8559

8660
public final class io/androidpoet/drafterdemo/gantt/GanntChartDemoKt {
87-
public static final fun GanttChartExample (Landroidx/compose/runtime/Composer;I)V
61+
public static final fun GanttChartExample (Ljava/util/List;Landroidx/compose/ui/Modifier;Landroidx/compose/runtime/Composer;II)V
8862
}
8963

9064
public final class io/androidpoet/drafterdemo/githubgraph/GithubGraphKt {
91-
public static final fun GithubGraph (Landroidx/compose/runtime/Composer;I)V
92-
}
93-
94-
public final class io/androidpoet/drafterdemo/line/ComposableSingletons$GroupedLineChartExampleKt {
95-
public static final field INSTANCE Lio/androidpoet/drafterdemo/line/ComposableSingletons$GroupedLineChartExampleKt;
96-
public static field lambda-1 Lkotlin/jvm/functions/Function2;
97-
public fun <init> ()V
98-
public final fun getLambda-1$app_release ()Lkotlin/jvm/functions/Function2;
99-
}
100-
101-
public final class io/androidpoet/drafterdemo/line/ComposableSingletons$ScatterPlotChartExampleKt {
102-
public static final field INSTANCE Lio/androidpoet/drafterdemo/line/ComposableSingletons$ScatterPlotChartExampleKt;
103-
public static field lambda-1 Lkotlin/jvm/functions/Function2;
104-
public fun <init> ()V
105-
public final fun getLambda-1$app_release ()Lkotlin/jvm/functions/Function2;
106-
}
107-
108-
public final class io/androidpoet/drafterdemo/line/ComposableSingletons$SimpleLineChartExampleKt {
109-
public static final field INSTANCE Lio/androidpoet/drafterdemo/line/ComposableSingletons$SimpleLineChartExampleKt;
110-
public static field lambda-1 Lkotlin/jvm/functions/Function2;
111-
public fun <init> ()V
112-
public final fun getLambda-1$app_release ()Lkotlin/jvm/functions/Function2;
113-
}
114-
115-
public final class io/androidpoet/drafterdemo/line/ComposableSingletons$StackedLineChartExampleKt {
116-
public static final field INSTANCE Lio/androidpoet/drafterdemo/line/ComposableSingletons$StackedLineChartExampleKt;
117-
public static field lambda-1 Lkotlin/jvm/functions/Function2;
118-
public fun <init> ()V
119-
public final fun getLambda-1$app_release ()Lkotlin/jvm/functions/Function2;
65+
public static final fun GithubGraph-iJQMabo (Landroidx/compose/ui/Modifier;JLandroidx/compose/runtime/Composer;II)V
12066
}
12167

12268
public final class io/androidpoet/drafterdemo/line/GroupedLineChartExampleKt {
123-
public static final fun GroupedLineChartExample (Landroidx/compose/runtime/Composer;I)V
69+
public static final fun GroupedLineChartExample (Ljava/util/List;Landroidx/compose/ui/Modifier;Landroidx/compose/runtime/Composer;II)V
12470
}
12571

12672
public final class io/androidpoet/drafterdemo/line/ScatterPlotChartExampleKt {
127-
public static final fun ScatterPlotChartExample (Landroidx/compose/runtime/Composer;I)V
73+
public static final fun ScatterPlotChartExample (Ljava/util/List;Landroidx/compose/ui/Modifier;Landroidx/compose/runtime/Composer;II)V
12874
}
12975

13076
public final class io/androidpoet/drafterdemo/line/SimpleLineChartExampleKt {
131-
public static final fun SimpleLineChartExample (Landroidx/compose/runtime/Composer;I)V
77+
public static final fun SimpleLineChartExample (Ljava/util/List;Landroidx/compose/ui/Modifier;Landroidx/compose/runtime/Composer;II)V
13278
}
13379

13480
public final class io/androidpoet/drafterdemo/line/StackedLineChartExampleKt {
135-
public static final fun StackedLineChartExample (Landroidx/compose/runtime/Composer;I)V
81+
public static final fun StackedLineChartExample (Ljava/util/List;Landroidx/compose/ui/Modifier;Landroidx/compose/runtime/Composer;II)V
82+
}
83+
84+
public final class io/androidpoet/drafterdemo/manager/ChartThemeManager {
85+
public static final field $stable I
86+
public static final field INSTANCE Lio/androidpoet/drafterdemo/manager/ChartThemeManager;
87+
public final fun getCurrentTheme ()Landroidx/compose/runtime/State;
88+
public final fun getGithubColors ()Ljava/util/List;
89+
public final fun getPalette ()Landroidx/compose/runtime/State;
90+
public final fun setTheme (Lio/androidpoet/drafterdemo/manager/ChartThemeManager$ColorTheme;)V
91+
}
92+
93+
public final class io/androidpoet/drafterdemo/manager/ChartThemeManager$ColorTheme : java/lang/Enum {
94+
public static final field MATERIAL Lio/androidpoet/drafterdemo/manager/ChartThemeManager$ColorTheme;
95+
public static final field MODERN Lio/androidpoet/drafterdemo/manager/ChartThemeManager$ColorTheme;
96+
public static final field NATURE Lio/androidpoet/drafterdemo/manager/ChartThemeManager$ColorTheme;
97+
public static final field PROFESSIONAL Lio/androidpoet/drafterdemo/manager/ChartThemeManager$ColorTheme;
98+
public static fun getEntries ()Lkotlin/enums/EnumEntries;
99+
public static fun valueOf (Ljava/lang/String;)Lio/androidpoet/drafterdemo/manager/ChartThemeManager$ColorTheme;
100+
public static fun values ()[Lio/androidpoet/drafterdemo/manager/ChartThemeManager$ColorTheme;
136101
}
137102

138103
public final class io/androidpoet/drafterdemo/pie/PieChartExampleKt {
139-
public static final fun DonutChartExample (Landroidx/compose/runtime/Composer;I)V
140-
public static final fun PieChartExample (Landroidx/compose/runtime/Composer;I)V
104+
public static final fun DonutChartExample (Ljava/util/List;Landroidx/compose/ui/Modifier;Landroidx/compose/runtime/Composer;II)V
105+
public static final fun PieChartExample (Ljava/util/List;Landroidx/compose/ui/Modifier;Landroidx/compose/runtime/Composer;II)V
141106
}
142107

143108
public final class io/androidpoet/drafterdemo/radar/RadarChartKt {
144-
public static final fun RadarChartExample (Landroidx/compose/runtime/Composer;I)V
109+
public static final fun RadarChartExample (Ljava/util/List;Landroidx/compose/ui/Modifier;Landroidx/compose/runtime/Composer;II)V
145110
}
146111

147112
public final class io/androidpoet/drafterdemo/ui/theme/ColorKt {

app/src/main/kotlin/io/androidpoet/drafterdemo/ChartContainer.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ fun ChartContainer(
3131
) {
3232
Box(
3333
modifier =
34-
modifier
35-
.fillMaxWidth()
36-
.height(200.dp)
37-
.padding(horizontal = 16.dp),
34+
modifier
35+
.fillMaxWidth()
36+
.height(200.dp)
37+
.padding(horizontal = 16.dp),
3838
contentAlignment = Alignment.Center,
3939
) {
4040
content()

app/src/main/kotlin/io/androidpoet/drafterdemo/ChartTitle.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,13 @@
1515
*/
1616
package io.androidpoet.drafterdemo
1717

18+
import androidx.compose.foundation.layout.fillMaxWidth
1819
import androidx.compose.foundation.layout.padding
1920
import androidx.compose.material3.MaterialTheme
2021
import androidx.compose.material3.Text
2122
import androidx.compose.runtime.Composable
2223
import androidx.compose.ui.Modifier
24+
import androidx.compose.ui.text.style.TextAlign
2325
import androidx.compose.ui.unit.dp
2426

2527
@Composable
@@ -29,7 +31,11 @@ fun ChartTitle(
2931
) {
3032
Text(
3133
text = text,
32-
modifier = modifier.padding(horizontal = 16.dp),
34+
modifier =
35+
modifier
36+
.padding(horizontal = 16.dp)
37+
.fillMaxWidth(),
3338
style = MaterialTheme.typography.titleLarge,
39+
textAlign = TextAlign.Center,
3440
)
3541
}

app/src/main/kotlin/io/androidpoet/drafterdemo/MainActivity.kt

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ import androidx.compose.runtime.remember
3939
import androidx.compose.ui.Modifier
4040
import androidx.compose.ui.graphics.Color
4141
import androidx.compose.ui.unit.dp
42-
import io.androidpoet.drafter.ChartThemeManager
4342
import io.androidpoet.drafterdemo.bars.GroupedBarChartExample
4443
import io.androidpoet.drafterdemo.bars.HistogramChartExample
4544
import io.androidpoet.drafterdemo.bars.SimpleBarChartExample
@@ -52,6 +51,7 @@ import io.androidpoet.drafterdemo.line.GroupedLineChartExample
5251
import io.androidpoet.drafterdemo.line.ScatterPlotChartExample
5352
import io.androidpoet.drafterdemo.line.SimpleLineChartExample
5453
import io.androidpoet.drafterdemo.line.StackedLineChartExample
54+
import io.androidpoet.drafterdemo.manager.ChartThemeManager
5555
import io.androidpoet.drafterdemo.pie.DonutChartExample
5656
import io.androidpoet.drafterdemo.pie.PieChartExample
5757
import io.androidpoet.drafterdemo.radar.RadarChartExample
@@ -70,23 +70,23 @@ class MainActivity : ComponentActivity() {
7070
// Theme Selector Row
7171
Row(
7272
modifier =
73-
Modifier
74-
.fillMaxWidth()
75-
.padding(16.dp),
73+
Modifier
74+
.fillMaxWidth()
75+
.padding(16.dp),
7676
horizontalArrangement = Arrangement.spacedBy(8.dp),
7777
) {
7878
ChartThemeManager.ColorTheme.entries.forEach { theme ->
7979
Button(
8080
onClick = { ChartThemeManager.setTheme(theme) },
8181
colors =
82-
ButtonDefaults.buttonColors(
83-
containerColor =
84-
if (theme == currentTheme) {
85-
MaterialTheme.colorScheme.primary
86-
} else {
87-
MaterialTheme.colorScheme.secondary
88-
},
89-
),
82+
ButtonDefaults.buttonColors(
83+
containerColor =
84+
if (theme == currentTheme) {
85+
MaterialTheme.colorScheme.primary
86+
} else {
87+
MaterialTheme.colorScheme.secondary
88+
},
89+
),
9090
modifier = Modifier.weight(1f),
9191
) {
9292
Text(
@@ -194,7 +194,7 @@ class MainActivity : ComponentActivity() {
194194
item {
195195
Column {
196196
ChartTitle(text = "Github Contribution Graph")
197-
GithubGraph(color = palette.first())
197+
GithubGraph(color = Color.Green)
198198
}
199199
}
200200
}

app/src/main/kotlin/io/androidpoet/drafterdemo/bars/GroupedBarChartExample.kt

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,18 @@ import androidx.compose.ui.unit.dp
2424
import io.androidpoet.drafter.bars.BarChart
2525
import io.androidpoet.drafter.bars.model.GroupedBarChartData
2626
import io.androidpoet.drafter.bars.renderer.GroupedBarChartRenderer
27-
import io.androidpoet.drafterdemo.ChartTitle
2827

2928
private fun getBarChartRenderer() =
3029
GroupedBarChartRenderer(
3130
GroupedBarChartData(
3231
labelsList = listOf("2020", "2021", "2022"),
3332
itemNames = listOf("Product A", "Product B", "Product C"),
3433
groupedValues =
35-
listOf(
36-
listOf(10f, 20f, 15f), // 2020
37-
listOf(25f, 5f, 30f), // 2021
38-
listOf(12f, 28f, 10f), // 2022
39-
),
34+
listOf(
35+
listOf(10f, 20f, 15f), // 2020
36+
listOf(25f, 5f, 30f), // 2021
37+
listOf(12f, 28f, 10f), // 2022
38+
),
4039
colors = listOf(Color.Red, Color.Green, Color.Blue),
4140
),
4241
)
@@ -46,13 +45,12 @@ fun GroupedBarChartExample(
4645
colors: List<Color>,
4746
modifier: Modifier = Modifier,
4847
) {
49-
ChartTitle(text = "Grouped Bar Chart")
5048
BarChart(
5149
renderer = getBarChartRenderer(),
5250
modifier =
53-
Modifier
54-
.height(300.dp)
55-
.fillMaxWidth(),
51+
Modifier
52+
.height(300.dp)
53+
.fillMaxWidth(),
5654
animate = true,
5755
)
5856
}

app/src/main/kotlin/io/androidpoet/drafterdemo/bars/HistogramChartExample.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
*/
1616
package io.androidpoet.drafterdemo.bars
1717

18-
import androidx.compose.foundation.layout.size
18+
import androidx.compose.foundation.layout.fillMaxWidth
19+
import androidx.compose.foundation.layout.height
1920
import androidx.compose.runtime.Composable
2021
import androidx.compose.ui.Modifier
2122
import androidx.compose.ui.graphics.Color
@@ -39,7 +40,10 @@ fun HistogramChartExample(
3940
) {
4041
BarChart(
4142
renderer = getHistogramRenderer(),
42-
modifier = modifier.size(300.dp),
43+
modifier =
44+
modifier
45+
.height(300.dp)
46+
.fillMaxWidth(),
4347
animate = animate,
4448
)
4549
}

app/src/main/kotlin/io/androidpoet/drafterdemo/bars/SimpleBarChartExample.kt

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import androidx.compose.ui.unit.dp
2424
import io.androidpoet.drafter.bars.BarChart
2525
import io.androidpoet.drafter.bars.model.SimpleBarChartData
2626
import io.androidpoet.drafter.bars.renderer.BarChartRenderer
27-
import io.androidpoet.drafterdemo.ChartTitle
2827

2928
private fun getBarChartData(colors: List<Color>) =
3029
SimpleBarChartData(
@@ -41,14 +40,12 @@ fun SimpleBarChartExample(
4140
colors: List<Color>,
4241
modifier: Modifier = Modifier,
4342
) {
44-
ChartTitle(text = "Simple Bar Chart")
45-
4643
BarChart(
4744
renderer = getSimpleBarChartRenderer(colors = colors),
4845
modifier =
49-
modifier
50-
.height(300.dp)
51-
.fillMaxWidth(),
46+
modifier
47+
.height(300.dp)
48+
.fillMaxWidth(),
5249
animate = true,
5350
)
5451
}

app/src/main/kotlin/io/androidpoet/drafterdemo/bars/StackedBarChartExample.kt

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,16 @@ import androidx.compose.ui.unit.dp
2424
import io.androidpoet.drafter.bars.BarChart
2525
import io.androidpoet.drafter.bars.model.StackedBarChartData
2626
import io.androidpoet.drafter.bars.renderer.StackedBarChartRenderer
27-
import io.androidpoet.drafterdemo.ChartTitle
2827

2928
private fun getStackedBarChartData(colors: List<Color>) =
3029
StackedBarChartData(
3130
labelsList = listOf("Q1", "Q2", "Q3"),
3231
stacks =
33-
listOf(
34-
listOf(10f, 15f, 5f), // Q1
35-
listOf(8f, 12f, 20f), // Q2
36-
listOf(18f, 10f, 15f), // Q3
37-
),
32+
listOf(
33+
listOf(10f, 15f, 5f), // Q1
34+
listOf(8f, 12f, 20f), // Q2
35+
listOf(18f, 10f, 15f), // Q3
36+
),
3837
colors = colors,
3938
)
4039

@@ -46,8 +45,6 @@ fun StackedBarChartExample(
4645
colors: List<Color>,
4746
modifier: Modifier = Modifier,
4847
) {
49-
ChartTitle(text = "Stacked Bar Chart")
50-
5148
BarChart(
5249
renderer = getStackedBarChartRenderer(colors = colors),
5350
modifier =

0 commit comments

Comments
 (0)