Skip to content

Commit de30734

Browse files
authored
Merge pull request #516 from almarklein/cluster-compact
* Compact clusters with many records in timeline * add test code (commented) * flake
2 parents cdb99ff + 39f88cc commit de30734

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

timetagger/app/front.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2009,7 +2009,7 @@ def _draw_records(self, ctx, x1, x2, x3, y1, y2):
20092009

20102010
y0, y3 = y1 - 50, self._canvas.h
20112011
t1, t2 = self._canvas.range.get_range()
2012-
now = self._canvas.now()
2012+
# now = self._canvas.now()
20132013

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

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

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

20592062
# Iteratively merge clusters
2060-
distance = 40 + 8
2063+
ref_distance = 40 + 8
20612064
for iter in range(5): # while-loop with max 5 iters, just in case
20622065
# Try merging clusters if they're close. Do this from back to front,
20632066
# so we can merge multiple together in one pass
20642067
merged_a_cluster = False
20652068
for i in range(len(clusters) - 2, -1, -1):
20662069
pos1 = clusters[i][-1]
20672070
pos2 = clusters[i + 1][0]
2068-
if pos2.y - pos1.y < distance:
2071+
if pos2.y - pos1.y < ref_distance:
20692072
merged_a_cluster = True
20702073
cluster = []
20712074
cluster.extend(clusters.pop(i))
@@ -2077,6 +2080,7 @@ def _draw_records(self, ctx, x1, x2, x3, y1, y2):
20772080
# Reposition the elements in each cluster. The strategy for setting
20782081
# positions depends on whether the cluster is near the top/bottom.
20792082
for cluster in clusters:
2083+
distance = ref_distance - min(20, 0.7 * len(cluster))
20802084
if cluster[0].visible == "top":
20812085
ref_y = cluster[0].y
20822086
for i, pos in enumerate(cluster):

timetagger/app/stores.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,6 +1042,15 @@ def reset(self):
10421042
self._create_tags()
10431043
self._create_one_year_of_data(self._years.pop(-1))
10441044

1045+
# Add many small records, for testing
1046+
# ds = "hello #there"
1047+
# t = dt.now()
1048+
# for i in range(20):
1049+
# t2 = t + 220
1050+
# record = self.records.create(t, t2, ds)
1051+
# t = t2
1052+
# self.records._put_received(record)
1053+
10451054
async def _sync(self):
10461055
"""Emulate a sync action."""
10471056
for kind in ["settings", "records"]:

0 commit comments

Comments
 (0)