Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement 'unit' property #34

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 23 additions & 3 deletions kivy_garden/graph/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,7 @@ def _update_labels(self):
ymax = self.ymax
xmin = self.xmin
precision = self.precision
unit = self.unit
x_overlap = False
y_overlap = False
# set up x and y axis labels
Expand Down Expand Up @@ -392,19 +393,25 @@ def _update_labels(self):
funcexp = exp10 if self.xlog else identity
funclog = log10 if self.xlog else identity
# find the distance from the end that'll fit the last tick label
xlabels[0].text = precision % funcexp(xpoints[-1])
xlabels[0].text = precision % (
funcexp(xpoints[-1]) / (unit if unit != 0 else 1) + 0
)
xlabels[0].texture_update()
xextent = x + width - xlabels[0].texture_size[0] / 2. - padding
# find the distance from the start that'll fit the first tick label
if not x_next:
xlabels[0].text = precision % funcexp(xpoints[0])
xlabels[0].text = precision % (
funcexp(xpoints[0]) / (unit if unit != 0 else 1) + 0
)
xlabels[0].texture_update()
x_next = padding + xlabels[0].texture_size[0] / 2.
xmin = funclog(xmin)
ratio = (xextent - x_next) / float(funclog(self.xmax) - xmin)
right = -1
for k in range(len(xlabels)):
xlabels[k].text = precision % funcexp(xpoints[k])
xlabels[k].text = precision % (
funcexp(xpoints[k]) / (unit if unit != 0 else 1) + 0
)
# update the size so we can center the labels on ticks
xlabels[k].texture_update()
xlabels[k].size = xlabels[k].texture_size
Expand Down Expand Up @@ -785,6 +792,19 @@ def to_data(self, x, y):
to False.
'''

unit = NumericProperty(1)
'''Determines the unit of x-axis values. The distance between the major
tick marks is divided by this number. Setting this to 0 will work as
if it was set to 0 to avoid division by 0. Negative numbers are allowed.

For example, setting this and x_ticks_major to 60 will display x-axis ticks
in minutes (by dividing major ticks by 60), assuming that data rate is once
per second.

:data:`unit` is a :class:`~kivy.properties.NumericProperty`, defaults
to 1.
'''

x_ticks_major = BoundedNumericProperty(0, min=0)
'''Distance between major tick marks on the x-axis.

Expand Down