forked from philackm/ScrollableGraphView
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Re-arrange reference lines and labels files
- Loading branch information
Showing
4 changed files
with
69 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters