forked from windelbouwman/lognplot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtransform.py
More file actions
36 lines (28 loc) · 1.06 KB
/
Copy pathtransform.py
File metadata and controls
36 lines (28 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
from ...utils import clip
def to_x_pixel(value, axis, layout):
""" Transform the given X value to a pixel position.
"""
domain = axis.domain
a = layout.chart_width / domain
x = layout.chart_left + a * (value - axis.minimum)
return clip(x, layout.chart_left, layout.chart_right)
def to_y_pixel(value, axis, layout):
""" Transform the given Y value to a pixel position.
"""
domain = axis.domain
a = layout.chart_height / domain
y = layout.chart_bottom - a * (value - axis.minimum)
return clip(y, layout.chart_top, layout.chart_bottom)
def to_x_value(pixel, axis, layout):
""" Given a pixel, determine its domain value. """
domain = axis.domain
a = domain / layout.chart_width
value = axis.minimum + a * (pixel - layout.chart_left)
return value
# return clip(x, layout.chart_left, layout.chart_right)
def x_pixels_to_domain(pixels, axis, layout):
""" Convert a pixel distance to a domain distance """
domain = axis.domain
a = domain / layout.chart_width
shift = a * pixels
return shift