You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Sources/SwiftViz/Scale.swift
+27-1Lines changed: 27 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -61,7 +61,7 @@ public protocol Scale {
61
61
/// - Returns: `true` if the value is between the lower and upper domain values.
62
62
func domainContains(_ value:InputType)->Bool
63
63
64
-
/// Converts a value between the input _domain_ and output _range_.
64
+
/// Converts a value comparing it to the input domain, transforming the value, and mapping it between the range values you provide.
65
65
///
66
66
/// Before scaling the value, the scale may transform or drop the value based on the setting of ``Scale/transformType``.
67
67
///
@@ -121,6 +121,32 @@ public extension Scale {
121
121
func domainContains(_ value:InputType)->Bool{
122
122
value >= domainLower && value <= domainHigher
123
123
}
124
+
125
+
/// Converts a value comparing it to the input domain, transforming the value, and mapping it into values between `0` and to the upper bound you provide.
126
+
///
127
+
/// This method is a convenience method that sets the lower value of the range is `0`.
128
+
/// Before scaling the value, the scale may transform or drop the value based on the setting of ``Scale/transformType``.
129
+
///
130
+
/// - Parameter inputValue: The value to be scaled.
131
+
/// - Parameter to: The higher bounding value of the range to transform from.
132
+
/// - Returns: a value within the bounds of the range values you provide, or `nil` if the value was dropped.
133
+
func scale(_ domainValue:InputType, to upper:OutputType)->OutputType?{
134
+
self.scale(domainValue, from:0, to: upper)
135
+
}
136
+
137
+
/// Converts a value comparing it to the upper value of a range, mapping it to the input domain, and inverting scale's transform.
138
+
///
139
+
/// This method is a convenience method that sets the lower value of the range is `0`.
140
+
/// The inverse of ``Scale/scale(_:to:)``.
141
+
/// After converting the data back to the domain range, the scale may transform or drop the value based on the setting of ``Scale/transformType``.
142
+
///
143
+
/// - Parameter rangeValue: The value to be scaled back from the range values to the domain.
144
+
/// - Parameter to: The higher bounding value of the range to transform from.
145
+
/// - Returns: a value within the bounds of the range values you provide, or `nil` if the value was dropped.
146
+
func invert(_ rangeValue:OutputType, to upper:OutputType)->InputType?{
147
+
self.invert(rangeValue, from:0, to: upper)
148
+
}
149
+
124
150
}
125
151
126
152
// NOTE(heckj): OTHER SCALES: make a PowScale (& maybe Sqrt, Log, Ln)
0 commit comments