forked from PhilJay/MPAndroidChart
-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathGanttChartData.kt
More file actions
90 lines (81 loc) · 1.84 KB
/
GanttChartData.kt
File metadata and controls
90 lines (81 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package info.appdev.charting.data
import kotlin.math.max
import kotlin.math.min
/**
* Data container for Gantt chart.
* Manages a list of tasks and provides convenient access methods.
*/
class GanttChartData {
/**
* Get all tasks.
*
* @return List of all tasks
*/
val tasks: MutableList<GanttTask> = ArrayList<GanttTask>()
/**
* Add a task to the Gantt chart.
*
* @param task The task to add
*/
fun addTask(task: GanttTask?) {
tasks.add(task!!)
}
/**
* Add multiple tasks to the Gantt chart.
*
* @param taskList List of tasks to add
*/
fun addTasks(taskList: MutableList<GanttTask>) {
tasks.addAll(taskList)
}
/**
* Get a specific task by index.
*
* @param index Task index
* @return The task at the given index
*/
fun getTask(index: Int): GanttTask {
return tasks[index]
}
/**
* Get the number of tasks.
*
* @return Number of tasks in the chart
*/
val taskCount: Int
get() = tasks.size
/**
* Get the earliest start time across all tasks.
*
* @return Minimum start time
*/
val minTime: Float
get() {
if (tasks.isEmpty()) return 0f
var min = Float.MAX_VALUE
for (task in tasks) {
min = min(min, task.startTime)
}
return min
}
/**
* Get the latest end time across all tasks.
*
* @return Maximum end time
*/
val maxTime: Float
get() {
if (tasks.isEmpty()) return 100f
var max = 0f
for (task in tasks) {
max = max(max, task.endTime)
}
return max
}
/**
* Clear all tasks.
*/
fun clearTasks() {
tasks.clear()
}
}