generated from mwc/lab_scatter
72 lines
1.5 KiB
Python
72 lines
1.5 KiB
Python
# transform.py
|
|
# ------------
|
|
# By MWC Contributors
|
|
# The functions in this module transform data.
|
|
# None of them are finished; this is your job!
|
|
|
|
import sys
|
|
|
|
def maximum(data):
|
|
highest = None
|
|
for number in data:
|
|
if highest is None:
|
|
highest = number
|
|
if number > highest:
|
|
highest = number
|
|
return highest
|
|
|
|
|
|
def minimum(data):
|
|
lowest = None
|
|
for number in data:
|
|
if lowest is None:
|
|
lowest = number
|
|
if number < lowest:
|
|
lowest = number
|
|
return lowest
|
|
|
|
|
|
def bounds(data):
|
|
highest = None
|
|
lowest = None
|
|
for number in data:
|
|
if highest is None:
|
|
highest = number
|
|
if lowest is None:
|
|
lowest = number
|
|
if number > highest:
|
|
highest = number
|
|
if number < lowest:
|
|
lowest = number
|
|
return [lowest, highest]
|
|
|
|
def clamp(value, low, high):
|
|
if value >= low and value <= high:
|
|
return value
|
|
elif value < low:
|
|
return low
|
|
elif value > high:
|
|
return high
|
|
|
|
|
|
def ratio(value, start, end):
|
|
ratio = (value - start)/(end - start)
|
|
return clamp(ratio,0,1)
|
|
|
|
|
|
|
|
def scale(value, domain_min, domain_max, range_min, range_max):
|
|
scale = range_min + (ratio(value, domain_min, domain_max)) * (range_max - range_min)
|
|
return scale
|
|
|
|
|
|
def get_x_values(points):
|
|
for (x, y) in points:
|
|
return ([x], )
|
|
|
|
def get_y_values(points):
|
|
for (x, y) in points:
|
|
return ([y], )
|
|
|
|
|
|
|