Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Hides virtualization support for Gantt charts, allowing client code to pass all items at once and filtering them based on the user interface controller's needs.
- public class GanttChartItemSource: GanttChartItemManager {
- // Client code would set up entire items and dependencies collections.
- public var items = [GanttChartItem]()
- public var dependencies = [GanttChartDependency]()
- // The totally available row count and the preferred (total) timeline used by the items are needed by the user interface controller to set up the maximum scrollable size of the view (that the viewport is scrolling within).
- public override var sourceTotalRowCount: Int {
- return max(0, 1 + (items.map { item in item.row }.max() ?? -1))
- }
- public override var sourcePreferredTimeline: TimeRange {
- return TimeRange(
- from: items.map { item in item.start }.min() ?? Time(),
- to: items.map { item in item.finish }.max() ?? Time())
- }
- // Only the filtered items and dependencies that are visible in the current range and timeline are required by the user interface controller.
- public var sourceFilteredItems: [GanttChartItem] {
- return Array(items.filter { item in
- timeline.intersects(item.time) && range.contains(item.row) })
- }
- public var sourceFilteredDependencies: [GanttChartDependency] {
- return Array(dependencies.filter { dependency in
- return items.contains { item in item === dependency.from }
- && items.contains { item in item === dependency.to }
- && (sourceFilteredItems.contains { item in item === dependency.from } ||
- sourceFilteredItems.contains { item in item === dependency.to }) })
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement