From 42f875ff835160e0207268188941998faaa4e718 Mon Sep 17 00:00:00 2001 From: Almar Klein Date: Wed, 11 Dec 2024 16:51:22 +0100 Subject: [PATCH 1/3] Compact clusters with many records in timeline --- timetagger/app/front.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/timetagger/app/front.py b/timetagger/app/front.py index a998b71..5eed4ce 100644 --- a/timetagger/app/front.py +++ b/timetagger/app/front.py @@ -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 = {} @@ -2057,7 +2060,7 @@ 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 @@ -2065,7 +2068,7 @@ def _draw_records(self, ctx, x1, x2, x3, y1, y2): 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)) @@ -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): From 58542131a9885c7180ce0e3992c9f134345b88ad Mon Sep 17 00:00:00 2001 From: Almar Klein Date: Wed, 11 Dec 2024 16:54:10 +0100 Subject: [PATCH 2/3] add test code (commented) --- timetagger/app/stores.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/timetagger/app/stores.py b/timetagger/app/stores.py index 9ce7287..cbf2c02 100644 --- a/timetagger/app/stores.py +++ b/timetagger/app/stores.py @@ -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"]: From 39f88cc16f06f101fc2539dd7d879a9d4fc365c5 Mon Sep 17 00:00:00 2001 From: Almar Klein Date: Wed, 11 Dec 2024 16:55:43 +0100 Subject: [PATCH 3/3] flake --- timetagger/app/front.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/timetagger/app/front.py b/timetagger/app/front.py index 5eed4ce..fc35b09 100644 --- a/timetagger/app/front.py +++ b/timetagger/app/front.py @@ -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