Skip to content

Commit

Permalink
feat: Re-work colors generation.
Browse files Browse the repository at this point in the history
  • Loading branch information
tzebrowski committed May 31, 2024
1 parent e7059f0 commit f7c22d3
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class TripsViewAdapter internal constructor(
SimpleDateFormat("yyyy.MM.dd HH:mm:ss", Locale.getDefault())

private val profileColors = mutableMapOf<String, Int>().apply {
val colors = Colors().generate()
val colors = Colors().get()
profile.getAvailableProfiles().forEach { (s, _) ->
if (colors.hasNext()) {
put(s, colors.nextInt())
Expand Down
9 changes: 3 additions & 6 deletions app/src/main/java/org/obd/graphs/ui/graph/GraphFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@ class GraphFragment : Fragment() {

private val simpleDateFormat = SimpleDateFormat("HH:mm:ss", Locale.getDefault())
private lateinit var chart: LineChart
private lateinit var colors: IntIterator
private val valueScaler = ValueScaler()
private var tripStartTs: Long = System.currentTimeMillis()
private lateinit var preferences: GraphPreferences
Expand Down Expand Up @@ -231,7 +230,7 @@ class GraphFragment : Fragment() {
}

private fun initializeChart(root: View) {
colors = Colors().generate()
val colors = Colors().get()
chart = buildChart(root).apply {

val pidRegistry: PidDefinitionRegistry = dataLogger.getPidDefinitionRegistry()
Expand All @@ -243,7 +242,7 @@ class GraphFragment : Fragment() {

val dataSets = LineData(metrics.mapNotNull {
try {
val dataSet = createDataSet(it)
val dataSet = createDataSetFor(it, colors.nextInt())
Log.d(LOG_TAG, "Created chart data-set for PID: ${it.id}")
dataSet
}catch (e: Throwable){
Expand All @@ -253,7 +252,6 @@ class GraphFragment : Fragment() {
}.toList())

Log.i(LOG_TAG,"Created data-set size: ${dataSets.dataSetCount}")

data = dataSets
setOnTouchListener(onDoubleClickListener(requireContext()))
invalidate()
Expand Down Expand Up @@ -399,10 +397,9 @@ class GraphFragment : Fragment() {
}
}

private fun createDataSet(pid: PidDefinition): LineDataSet {
private fun createDataSetFor(pid: PidDefinition, col: Int): LineDataSet {
val values = mutableListOf<Entry>()
val lineDataSet = LineDataSet(values, pid.description)
val col = colors.nextInt()
lineDataSet.run {
mode = LineDataSet.Mode.CUBIC_BEZIER
label = pid.description
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@
<string name="pref.pids_category">OBD2 PIDs/Sensors</string>
<string name="pref.dashboard_category">Dashboard view configuration</string>

<string name="pref.giulia_apply_graph_filter">Apply PID filter to Graph View</string>
<string name="pref.giulia_apply_graph_filter">Apply PID selection to Graph View</string>

<string name="pref.giulia_category">Giulia view configuration</string>
<string name="pref.giulia.virtual_screens.number_of_items_in_column.category">Number of items in the column</string>
Expand Down
60 changes: 35 additions & 25 deletions common/src/main/java/org/obd/graphs/ui/common/Colors.kt
Original file line number Diff line number Diff line change
Expand Up @@ -70,31 +70,41 @@ fun String.colorize(color: Int, typeface: Int, size: Float) : SpannableString {

class Colors {

private val base: List<Int> = mutableListOf<Int>().apply {
add(COLOR_CARDINAL)
add(COLOR_PHILIPPINE_GREEN)
add(Color.parseColor("#1C3D72"))
add(Color.parseColor("#BBBBBB"))

add(Color.parseColor("#C0CA33"))
add(Color.parseColor("#FF9800"))
add(Color.parseColor("#F44336"))
add(Color.parseColor("#4A148C"))
add(Color.parseColor("#FFFF00"))
add(Color.parseColor("#42A5F5"))
add(Color.parseColor("#4DB6AC"))
add(Color.parseColor("#3F51B5"))

add(Color.parseColor("#FF6F00"))
add(Color.parseColor("#E8F5E9"))
add(Color.parseColor("#757575"))
add(Color.parseColor("#FFCCBC"))
add(Color.parseColor("#00C853"))
add(Color.parseColor("#66BB6A"))
}

fun generate(): IntIterator {
return base.toIntArray().iterator()
private val base: IntArray = mutableListOf<Int>().apply {
val inner = mutableListOf<Int>().apply {
add(COLOR_CARDINAL)
add(COLOR_PHILIPPINE_GREEN)
add(COLOR_WHITE)
add(COLOR_DYNAMIC_SELECTOR_NORMAL)
add(COLOR_DYNAMIC_SELECTOR_RACE)
add(COLOR_DYNAMIC_SELECTOR_ECO)

add(Color.parseColor("#1C3D72"))
add(Color.parseColor("#BBBBBB"))
add(Color.parseColor("#C0CA33"))
add(Color.parseColor("#FF9800"))
add(Color.parseColor("#F44336"))
add(Color.parseColor("#4A148C"))
add(Color.parseColor("#FFFF00"))
add(Color.parseColor("#42A5F5"))
add(Color.parseColor("#4DB6AC"))
add(Color.parseColor("#3F51B5"))
add(Color.parseColor("#FF6F00"))
add(Color.parseColor("#E8F5E9"))
add(Color.parseColor("#757575"))
add(Color.parseColor("#FFCCBC"))
add(Color.parseColor("#00C853"))
add(Color.parseColor("#66BB6A"))
}

(1 .. 5).forEach { _ ->
addAll(inner)
}

}.toIntArray()

fun get(): IntIterator {
return base.iterator()
}
}

Expand Down

0 comments on commit f7c22d3

Please sign in to comment.