Skip to content

Commit

Permalink
Re-arrange reference lines and labels files
Browse files Browse the repository at this point in the history
  • Loading branch information
philackm committed Jul 3, 2017
1 parent aea31de commit 5c192bc
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 57 deletions.
53 changes: 53 additions & 0 deletions Classes/Reference/LabelPool.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@

import UIKit

internal class LabelPool {

var labels = [UILabel]()
var relations = [Int : Int]()
var unused = [Int]()

func deactivateLabel(forPointIndex pointIndex: Int){

if let unusedLabelIndex = relations[pointIndex] {
unused.append(unusedLabelIndex)
}
relations[pointIndex] = nil
}

@discardableResult
func activateLabel(forPointIndex pointIndex: Int) -> UILabel {
var label: UILabel

if(unused.count >= 1) {
let unusedLabelIndex = unused.first!
unused.removeFirst()

label = labels[unusedLabelIndex]
relations[pointIndex] = unusedLabelIndex
}
else {
label = UILabel()
labels.append(label)
let newLabelIndex = labels.index(of: label)!
relations[pointIndex] = newLabelIndex
}

return label
}

var activeLabels: [UILabel] {
get {

var currentlyActive = [UILabel]()
let numberOfLabels = labels.count

for i in 0 ..< numberOfLabels {
if(!unused.contains(i)) {
currentlyActive.append(labels[i])
}
}
return currentlyActive
}
}
}
File renamed without changes.
53 changes: 0 additions & 53 deletions Classes/ScrollableGraphView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -793,59 +793,6 @@ import UIKit
}
}

// MARK: - LabelPool
// #################

private class LabelPool {

var labels = [UILabel]()
var relations = [Int : Int]()
var unused = [Int]()

func deactivateLabel(forPointIndex pointIndex: Int){

if let unusedLabelIndex = relations[pointIndex] {
unused.append(unusedLabelIndex)
}
relations[pointIndex] = nil
}

@discardableResult
func activateLabel(forPointIndex pointIndex: Int) -> UILabel {
var label: UILabel

if(unused.count >= 1) {
let unusedLabelIndex = unused.first!
unused.removeFirst()

label = labels[unusedLabelIndex]
relations[pointIndex] = unusedLabelIndex
}
else {
label = UILabel()
labels.append(label)
let newLabelIndex = labels.index(of: label)!
relations[pointIndex] = newLabelIndex
}

return label
}

var activeLabels: [UILabel] {
get {

var currentlyActive = [UILabel]()
let numberOfLabels = labels.count

for i in 0 ..< numberOfLabels {
if(!unused.contains(i)) {
currentlyActive.append(labels[i])
}
}
return currentlyActive
}
}
}

// MARK: - ScrollableGraphView Settings Enums
// ##########################################
Expand Down
20 changes: 16 additions & 4 deletions graphview_example_code/GraphView.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
299482F41F060FE0007BCDCA /* ScrollableGraphViewDrawingDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 299482F31F060FE0007BCDCA /* ScrollableGraphViewDrawingDelegate.swift */; };
299482F71F06931F007BCDCA /* GraphPointAnimation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 299482F61F06931F007BCDCA /* GraphPointAnimation.swift */; };
299482F91F069337007BCDCA /* GraphPoint.swift in Sources */ = {isa = PBXBuildFile; fileRef = 299482F81F069337007BCDCA /* GraphPoint.swift */; };
29A5903A1F0501A3004D219C /* ReferenceLines.swift in Sources */ = {isa = PBXBuildFile; fileRef = 29A590391F0501A3004D219C /* ReferenceLines.swift */; };
29A2477C1F09ECE400F75511 /* LabelPool.swift in Sources */ = {isa = PBXBuildFile; fileRef = 29A2477B1F09ECE400F75511 /* LabelPool.swift */; };
29A2477E1F09ED4E00F75511 /* ReferenceLines.swift in Sources */ = {isa = PBXBuildFile; fileRef = 29A2477D1F09ED4E00F75511 /* ReferenceLines.swift */; };
29A5903C1F05030F004D219C /* ScrollableGraphViewDrawingLayer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 29A5903B1F05030F004D219C /* ScrollableGraphViewDrawingLayer.swift */; };
29A5903E1F05035F004D219C /* BarDrawingLayer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 29A5903D1F05035F004D219C /* BarDrawingLayer.swift */; };
29A590401F050378004D219C /* DotDrawingLayer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 29A5903F1F050378004D219C /* DotDrawingLayer.swift */; };
Expand Down Expand Up @@ -49,7 +50,8 @@
299482F31F060FE0007BCDCA /* ScrollableGraphViewDrawingDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ScrollableGraphViewDrawingDelegate.swift; path = ../../Classes/Protocols/ScrollableGraphViewDrawingDelegate.swift; sourceTree = "<group>"; };
299482F61F06931F007BCDCA /* GraphPointAnimation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = GraphPointAnimation.swift; path = ../../Classes/Plots/Animation/GraphPointAnimation.swift; sourceTree = "<group>"; };
299482F81F069337007BCDCA /* GraphPoint.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = GraphPoint.swift; path = ../../Classes/Plots/Animation/GraphPoint.swift; sourceTree = "<group>"; };
29A590391F0501A3004D219C /* ReferenceLines.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ReferenceLines.swift; path = ../../Classes/ReferenceLines.swift; sourceTree = "<group>"; };
29A2477B1F09ECE400F75511 /* LabelPool.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = LabelPool.swift; path = ../../Classes/Reference/LabelPool.swift; sourceTree = "<group>"; };
29A2477D1F09ED4E00F75511 /* ReferenceLines.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ReferenceLines.swift; path = ../../Classes/Reference/ReferenceLines.swift; sourceTree = "<group>"; };
29A5903B1F05030F004D219C /* ScrollableGraphViewDrawingLayer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ScrollableGraphViewDrawingLayer.swift; path = ../../Classes/Drawing/ScrollableGraphViewDrawingLayer.swift; sourceTree = "<group>"; };
29A5903D1F05035F004D219C /* BarDrawingLayer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = BarDrawingLayer.swift; path = ../../Classes/Drawing/BarDrawingLayer.swift; sourceTree = "<group>"; };
29A5903F1F050378004D219C /* DotDrawingLayer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = DotDrawingLayer.swift; path = ../../Classes/Drawing/DotDrawingLayer.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -92,7 +94,7 @@
291839A01C72E6A400753A45 /* Classes */ = {
isa = PBXGroup;
children = (
29A590391F0501A3004D219C /* ReferenceLines.swift */,
29A2477A1F09ECC600F75511 /* Reference */,
294A1ACD1CF80CB30070FACD /* ScrollableGraphView.swift */,
299482F01F060F72007BCDCA /* Protocols */,
29A590491F0509AA004D219C /* Plots */,
Expand Down Expand Up @@ -142,6 +144,15 @@
name = Animation;
sourceTree = "<group>";
};
29A2477A1F09ECC600F75511 /* Reference */ = {
isa = PBXGroup;
children = (
29A2477D1F09ED4E00F75511 /* ReferenceLines.swift */,
29A2477B1F09ECE400F75511 /* LabelPool.swift */,
);
name = Reference;
sourceTree = "<group>";
};
29A590381F0500F5004D219C /* Drawing */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -248,13 +259,14 @@
29A5903C1F05030F004D219C /* ScrollableGraphViewDrawingLayer.swift in Sources */,
29A590401F050378004D219C /* DotDrawingLayer.swift in Sources */,
29A590441F0503AC004D219C /* FillDrawingLayer.swift in Sources */,
29A2477E1F09ED4E00F75511 /* ReferenceLines.swift in Sources */,
299482F71F06931F007BCDCA /* GraphPointAnimation.swift in Sources */,
299482EB1F060CBE007BCDCA /* LinePlot.swift in Sources */,
299482F91F069337007BCDCA /* GraphPoint.swift in Sources */,
29A5903A1F0501A3004D219C /* ReferenceLines.swift in Sources */,
299482EF1F060CEA007BCDCA /* BarPlot.swift in Sources */,
299482F41F060FE0007BCDCA /* ScrollableGraphViewDrawingDelegate.swift in Sources */,
299482F21F060FB5007BCDCA /* ScrollableGraphViewDataSource.swift in Sources */,
29A2477C1F09ECE400F75511 /* LabelPool.swift in Sources */,
291839A41C72E6A400753A45 /* ViewController.swift in Sources */,
29559B801C742D7800E77931 /* UIColor+colorFromHex.swift in Sources */,
299482ED1F060CDC007BCDCA /* DotPlot.swift in Sources */,
Expand Down

0 comments on commit 5c192bc

Please sign in to comment.