Skip to content

Commit d780bbf

Browse files
authored
Update API changes
1 parent 9814b74 commit d780bbf

File tree

1 file changed

+26
-154
lines changed

1 file changed

+26
-154
lines changed

APIv4.md

Lines changed: 26 additions & 154 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,15 @@ The new proposed API aims to resolve these issues by:
1717

1818
## Contents
1919

20-
- [API - ScrollableGraphView](#proposed-api---scrollablegraphview-class)
21-
- [API - ScrollableGraphViewDataSource](#proposed-api---scrollablegraphviewdatasource-protocol)
22-
- [API - ReferenceLines](#proposed-api---referencelines-class)
23-
- [API - Encapsulating Settings](#proposed-api---encapsulating-customisation-settings)
24-
- [API - Configuration Files](#proposed-api---configuration-files)
20+
- [API - ScrollableGraphView](#api---scrollablegraphview-class)
21+
- [API - ScrollableGraphViewDataSource](#api---scrollablegraphviewdatasource-protocol)
22+
- [API - ReferenceLines](#api---referencelines-class)
2523
- [Example Usage](#example-usage)
2624
- [Creating a Graph via Configuration File](#creating-a-graph-via-configuration-file)
2725
- [Creating a Graph and Configuring it Programmatically](#creating-a-graph-and-configuring-it-programmatically)
2826
- [List of New Protocols and Types](#list-of-new-protocols-and-types)
2927

30-
# Proposed API - ScrollableGraphView Class
28+
API - ScrollableGraphView Class
3129

3230
## Creating a Graph
3331

@@ -40,16 +38,10 @@ Returns a graph instance. The data source for the graph is an object which confo
4038
## Adding/Removing Plots
4139

4240
```swift
43-
func addPlot(type: PlotType, id: String, config: PlotConfiguration)
41+
func addPlot(plot: Plot)
4442
```
4543

46-
Adds a plot to the graph. Can be called multiple times to add multiple plots. The `id` for the plot is passed to the `dataSource` delegate when requesting data.
47-
48-
```swift
49-
func removePlot(id: String)
50-
```
51-
52-
Removes a plot from the graph for a given id.
44+
Adds a plot to the graph. Can be called multiple times to add multiple plots. The `identifier` for the plot is passed to the `dataSource` delegate when requesting data.
5345

5446
## Adding Reference Lines to the Graph
5547

@@ -62,7 +54,7 @@ Adds an instance of ReferenceLines to the graph. Multiple calls will override th
6254
## Giving the Graph Data
6355

6456
```swift
65-
var dataSource: GraphViewDataSource
57+
var dataSource: ScrollableGraphViewDataSource
6658
```
6759

6860
The data source delegate which provides the graph data. This object must conform to the `GraphViewDataSource` protocol by implementing the following three methods.
@@ -71,17 +63,9 @@ The data source delegate which provides the graph data. This object must conform
7163
func reload()
7264
```
7365

74-
Causes the graph to recall the delegate functions, to refetch the data. The delegate method `numberOfPoints` will also be called. This is used when points have been added/removed from the plot.
75-
76-
## Using Configuration Files
77-
78-
```swift
79-
var configurationFilePath: String
80-
```
81-
82-
Path to the JSON configuration file.
66+
Causes the graph to recall the delegate functions, to refetch the data.
8367

84-
# Proposed API - ScrollableGraphViewDataSource Protocol
68+
# API - ScrollableGraphViewDataSource Protocol
8569

8670
```swift
8771
func value(forPlot plot: Plot, atIndex pointIndex: Int) -> Double
@@ -101,7 +85,7 @@ func numberOfPoints(forPlot plot: Plot) -> Int
10185

10286
Provides the number of points for each each plot.
10387

104-
# Proposed API - ReferenceLines Class
88+
# API - ReferenceLines Class
10589

10690
## New Customisation Options for Reference Lines
10791

@@ -123,108 +107,13 @@ var absolutePositions: [Double]
123107

124108
An array of positions specified in absolute values where the reference lines will be rendered.
125109

126-
# Proposed API - Encapsulating Customisation Settings
110+
# API - Encapsulating Customisation Settings
127111

128112
Refactoring is required to organise the customisation settings. The `PlotConfiguration` and `GraphConfiguration` classes will encapsulate the settings for the plot and graph respectively. These data structures are then passed to the graph via the `setConfiguration` and `addPlot` methods.
129113

130-
# Proposed API - Configuration Files
114+
## Example Usage
131115

132-
In addition to the `PlotConfiguration` and `GraphConfiguration` classes, an alternative method of using JSON configuration files to specify the appearance of the graph will be provided.
133-
134-
# Example Usage
135-
136-
## Creating a graph via Configuration File
137-
138-
```ViewController.swift```
139-
140-
```swift
141-
class ViewController: UIViewController, ScrollableGraphViewDataSource {
142-
143-
// Class members and init...
144-
145-
var linePlotData: [Double] = // data for line plot
146-
var barPlotData: [Double] = // data for bar plot
147-
var xAxisLabels: [String] = // the labels along the x axis
148-
149-
override func viewDidLoad() {
150-
super.viewDidLoad()
151-
152-
let graph = ScrollableGraphView(frame: self.view.frame, dataSource: self)
153-
graph.configuration = Bundle.main.path(forResource: "configuration", ofType: "json")
154-
155-
self.view.addSubview(graph)
156-
}
157-
158-
// Other class methods...
159-
160-
// Implementation for ScrollableGraphViewDataSource
161-
func value(forPlot plot: Plot, atIndex pointIndex: Int) -> Double {
162-
switch(plot.name) {
163-
case "linePlot":
164-
return linePlotData[pointIndex]
165-
break
166-
case "barPlot":
167-
return barPlotData[pointIndex]
168-
break
169-
}
170-
}
171-
172-
func label(forPlot plot: Plot, atIndex pointIndex: Int) -> String {
173-
return xAxisLabels[pointIndex]
174-
}
175-
176-
func numberOfPoints(forPlot plot: Plot) -> Int {
177-
switch(plot.name) {
178-
case "linePlot":
179-
return linePlotData.count
180-
break
181-
case "barPlot":
182-
return barPlotData.count
183-
break
184-
}
185-
}
186-
}
187-
```
188-
189-
```configuration.json```
190-
191-
```json
192-
// Example JSON configuration file.
193-
{
194-
"graph":
195-
{
196-
"backgroundColor" : "#FFFFFF",
197-
"shouldAnimateOnStartup" : true,
198-
"animationDuration" : 2.0
199-
},
200-
201-
"reference":
202-
{
203-
"positionType" : "relative",
204-
"relativePositions" : [0, 0.5, 0.8, 0.9, 1]
205-
},
206-
207-
"plots":
208-
[
209-
{
210-
"id" : "lineplot",
211-
"type" : "line",
212-
"lineWidth" : 5,
213-
"lineColor" : "#000000",
214-
},
215-
216-
{
217-
"id" : "barplot",
218-
"type" : "bar",
219-
"barWidth" : 20,
220-
"barFillColor" : "#000000",
221-
"barOutlineColor" : "#333333"
222-
}
223-
]
224-
}
225-
```
226-
227-
## Creating a Graph and Configuring it Programmatically
116+
### Creating a Graph and Configuring it Programmatically
228117

229118
```ViewController.swift```
230119

@@ -245,12 +134,8 @@ class ViewController: UIViewController, ScrollableGraphViewDataSource {
245134
// Graph Configuration
246135
// ###################
247136

248-
let graphConfig = GraphConfiguration()
249-
graphConfig.backgroundColor = UIColor.white
250-
graphConfig.shouldAnimateOnStartup = true
251-
graphConfig.animationDuration = 2.0
252-
253-
graph.setConfiguration(graphConfig)
137+
graph.backgroundColor = UIColor.white
138+
graph.shouldAnimateOnStartup = true
254139

255140
// Reference Lines
256141
// ###############
@@ -264,17 +149,17 @@ class ViewController: UIViewController, ScrollableGraphViewDataSource {
264149
// Adding Plots
265150
// ############
266151

267-
let lineConfig = PlotConfiguration()
268-
lineConfig.lineWidth = 5
269-
lineConfig.color = UIColor.black
152+
let linePlot = LinePlot(identifier: "linePlot")
153+
linePlot.lineWidth = 5
154+
linePlot.color = UIColor.black
270155

271-
let barConfig = PlotConfiguration()
272-
barConfig.barWidth = 20
273-
barConfig.barFillColor = UIColor.black
274-
barConfig.barOutlineColor = UIColor.gray
156+
let barPlot = BarPlot(identifier: "barPlot")
157+
barPlot.barWidth = 20
158+
barPlot.barFillColor = UIColor.black
159+
barPlot.barOutlineColor = UIColor.gray
275160

276-
graph.addPlot(PlotType.line, "lineplot", lineConfig?)
277-
graph.addPlot(PlotType.bar, "barplot", barConfig?)
161+
graph.addPlot(linePlot)
162+
graph.addPlot(barPlot)
278163

279164
self.view.addSubview(graph)
280165
}
@@ -297,15 +182,8 @@ class ViewController: UIViewController, ScrollableGraphViewDataSource {
297182
return xAxisLabels[pointIndex]
298183
}
299184

300-
func numberOfPoints(forPlot plot: Plot) -> Int {
301-
switch(plot.name) {
302-
case "linePlot":
303-
return linePlotData.count
304-
break
305-
case "barPlot":
306-
return barPlotData.count
307-
break
308-
}
185+
func numberOfPoints() -> Int {
186+
return numberOfPointsInGraph
309187
}
310188
}
311189
```
@@ -320,10 +198,4 @@ class ViewController: UIViewController, ScrollableGraphViewDataSource {
320198

321199
`Plot`
322200

323-
`PlotType`
324-
325201
`ReferenceLines`
326-
327-
`PlotConfiguration`
328-
329-
`GraphConfiguration`

0 commit comments

Comments
 (0)