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

Compact clusters with many records in timeline #516

Merged
merged 3 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
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
12 changes: 8 additions & 4 deletions timetagger/app/front.py
Original file line number Diff line number Diff line change
Expand Up @@ -2009,7 +2009,7 @@ def _draw_records(self, ctx, x1, x2, x3, y1, y2):

y0, y3 = y1 - 50, self._canvas.h
t1, t2 = self._canvas.range.get_range()
now = self._canvas.now()
# now = self._canvas.now()

# Get range, in seconds and pixels for the time range
npixels = y2 - y1 # number if logical pixels we can use
Expand All @@ -2032,7 +2032,10 @@ def _draw_records(self, ctx, x1, x2, x3, y1, y2):
# self._help_text = "click a record to edit it"

# Sort records by size, so records cannot be completely overlapped by another
records.sort(key=lambda r: r.t1 - (now if (r.t1 == r.t2) else r.t2))
# Or ... by t2, which works better when the labels are made to overlap in a cluster,
# see the distance = ref_distance - ... below
# records.sort(key=lambda r: r.t1 - (now if (r.t1 == r.t2) else r.t2))
records.sort(key=lambda r: -r.t2)

# Prepare by collecting stuff per record, and determine selected record
self._record_times = {}
Expand All @@ -2057,15 +2060,15 @@ def _draw_records(self, ctx, x1, x2, x3, y1, y2):
clusters.push([pos])

# Iteratively merge clusters
distance = 40 + 8
ref_distance = 40 + 8
for iter in range(5): # while-loop with max 5 iters, just in case
# Try merging clusters if they're close. Do this from back to front,
# so we can merge multiple together in one pass
merged_a_cluster = False
for i in range(len(clusters) - 2, -1, -1):
pos1 = clusters[i][-1]
pos2 = clusters[i + 1][0]
if pos2.y - pos1.y < distance:
if pos2.y - pos1.y < ref_distance:
merged_a_cluster = True
cluster = []
cluster.extend(clusters.pop(i))
Expand All @@ -2077,6 +2080,7 @@ def _draw_records(self, ctx, x1, x2, x3, y1, y2):
# Reposition the elements in each cluster. The strategy for setting
# positions depends on whether the cluster is near the top/bottom.
for cluster in clusters:
distance = ref_distance - min(20, 0.7 * len(cluster))
if cluster[0].visible == "top":
ref_y = cluster[0].y
for i, pos in enumerate(cluster):
Expand Down
9 changes: 9 additions & 0 deletions timetagger/app/stores.py
Original file line number Diff line number Diff line change
Expand Up @@ -1042,6 +1042,15 @@ def reset(self):
self._create_tags()
self._create_one_year_of_data(self._years.pop(-1))

# Add many small records, for testing
# ds = "hello #there"
# t = dt.now()
# for i in range(20):
# t2 = t + 220
# record = self.records.create(t, t2, ds)
# t = t2
# self.records._put_received(record)

async def _sync(self):
"""Emulate a sync action."""
for kind in ["settings", "records"]:
Expand Down
Loading