DemoListViewController.swift 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. //
  2. // DemoListViewController.swift
  3. // ChartsDemo-iOS
  4. //
  5. // Created by Jacob Christie on 2017-07-09.
  6. // Copyright © 2017 jc. All rights reserved.
  7. //
  8. #if canImport(UIKit)
  9. import UIKit
  10. #endif
  11. private struct ItemDef {
  12. let title: String
  13. let subtitle: String
  14. let `class`: AnyClass
  15. }
  16. class DemoListViewController: UIViewController {
  17. @IBOutlet var tableView: UITableView!
  18. private var itemDefs = [ItemDef(title: "Line Chart",
  19. subtitle: "A simple demonstration of the linechart.",
  20. class: LineChart1ViewController.self),
  21. ItemDef(title: "Line Chart (Dual YAxis)",
  22. subtitle: "Demonstration of the linechart with dual y-axis.",
  23. class: LineChart2ViewController.self),
  24. ItemDef(title: "Bar Chart",
  25. subtitle: "A simple demonstration of the bar chart.",
  26. class: BarChartViewController.self),
  27. ItemDef(title: "Horizontal Bar Chart",
  28. subtitle: "A simple demonstration of the horizontal bar chart.",
  29. class: HorizontalBarChartViewController.self),
  30. ItemDef(title: "Combined Chart",
  31. subtitle: "Demonstrates how to create a combined chart (bar and line in this case).",
  32. class: CombinedChartViewController.self),
  33. ItemDef(title: "Pie Chart",
  34. subtitle: "A simple demonstration of the pie chart.",
  35. class: PieChartViewController.self),
  36. ItemDef(title: "Pie Chart with value lines",
  37. subtitle: "A simple demonstration of the pie chart with polyline notes.",
  38. class: PiePolylineChartViewController.self),
  39. ItemDef(title: "Scatter Chart",
  40. subtitle: "A simple demonstration of the scatter chart.",
  41. class: ScatterChartViewController.self),
  42. ItemDef(title: "Bubble Chart",
  43. subtitle: "A simple demonstration of the bubble chart.",
  44. class: BubbleChartViewController.self),
  45. ItemDef(title: "Stacked Bar Chart",
  46. subtitle: "A simple demonstration of a bar chart with stacked bars.",
  47. class: StackedBarChartViewController.self),
  48. ItemDef(title: "Stacked Bar Chart Negative",
  49. subtitle: "A simple demonstration of stacked bars with negative and positive values.",
  50. class: NegativeStackedBarChartViewController.self),
  51. ItemDef(title: "Another Bar Chart",
  52. subtitle: "Implementation of a BarChart that only shows values at the bottom.",
  53. class: AnotherBarChartViewController.self),
  54. ItemDef(title: "Multiple Lines Chart",
  55. subtitle: "A line chart with multiple DataSet objects. One color per DataSet.",
  56. class: MultipleLinesChartViewController.self),
  57. ItemDef(title: "Multiple Bars Chart",
  58. subtitle: "A bar chart with multiple DataSet objects. One multiple colors per DataSet.",
  59. class: MultipleBarChartViewController.self),
  60. ItemDef(title: "Candle Stick Chart",
  61. subtitle: "Demonstrates usage of the CandleStickChart.",
  62. class: CandleStickChartViewController.self),
  63. ItemDef(title: "Cubic Line Chart",
  64. subtitle: "Demonstrates cubic lines in a LineChart.",
  65. class: CubicLineChartViewController.self),
  66. ItemDef(title: "Radar Chart",
  67. subtitle: "Demonstrates the use of a spider-web like (net) chart.",
  68. class: RadarChartViewController.self),
  69. ItemDef(title: "Colored Line Chart",
  70. subtitle: "Shows a LineChart with different background and line color.",
  71. class: ColoredLineChartViewController.self),
  72. ItemDef(title: "Sinus Bar Chart",
  73. subtitle: "A Bar Chart plotting the sinus function with 8.000 values.",
  74. class: SinusBarChartViewController.self),
  75. ItemDef(title: "BarChart positive / negative",
  76. subtitle: "This demonstrates how to create a BarChart with positive and negative values in different colors.",
  77. class: PositiveNegativeBarChartViewController.self),
  78. ItemDef(title: "Time Line Chart",
  79. subtitle: "Simple demonstration of a time-chart. This chart draws one line entry per hour originating from the current time in milliseconds.",
  80. class: LineChartTimeViewController.self),
  81. ItemDef(title: "Filled Line Chart",
  82. subtitle: "This demonstrates how to fill an area between two LineDataSets.",
  83. class: LineChartFilledViewController.self),
  84. ItemDef(title: "Half Pie Chart",
  85. subtitle: "This demonstrates how to create a 180 degree PieChart.",
  86. class: HalfPieChartViewController.self)
  87. ]
  88. override func viewDidLoad() {
  89. super.viewDidLoad()
  90. self.title = "Charts Demonstration"
  91. self.tableView.rowHeight = 70
  92. //FIXME: Add TimeLineChart
  93. }
  94. }
  95. extension DemoListViewController: UITableViewDelegate, UITableViewDataSource {
  96. func numberOfSections(in tableView: UITableView) -> Int {
  97. return 1
  98. }
  99. func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  100. return self.itemDefs.count
  101. }
  102. func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  103. let def = self.itemDefs[indexPath.row]
  104. let cell = tableView.dequeueReusableCell(withIdentifier: "Cell") ?? UITableViewCell(style: .subtitle, reuseIdentifier: "Cell")
  105. cell.textLabel?.text = def.title
  106. cell.detailTextLabel?.text = def.subtitle
  107. cell.detailTextLabel?.numberOfLines = 0
  108. return cell
  109. }
  110. func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
  111. let def = self.itemDefs[indexPath.row]
  112. let vcClass = def.class as! UIViewController.Type
  113. let vc = vcClass.init()
  114. self.navigationController?.pushViewController(vc, animated: true)
  115. tableView.deselectRow(at: indexPath, animated: true)
  116. }
  117. }