Skip to content

Commit 42f875f

Browse files
committed
Compact clusters with many records in timeline
1 parent cdb99ff commit 42f875f

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

timetagger/app/front.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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):

0 commit comments

Comments
 (0)