@@ -2032,7 +2032,10 @@ def _draw_records(self, ctx, x1, x2, x3, y1, y2):
2032
2032
# self._help_text = "click a record to edit it"
2033
2033
2034
2034
# 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 )
2036
2039
2037
2040
# Prepare by collecting stuff per record, and determine selected record
2038
2041
self ._record_times = {}
@@ -2057,15 +2060,15 @@ def _draw_records(self, ctx, x1, x2, x3, y1, y2):
2057
2060
clusters .push ([pos ])
2058
2061
2059
2062
# Iteratively merge clusters
2060
- distance = 40 + 8
2063
+ ref_distance = 40 + 8
2061
2064
for iter in range (5 ): # while-loop with max 5 iters, just in case
2062
2065
# Try merging clusters if they're close. Do this from back to front,
2063
2066
# so we can merge multiple together in one pass
2064
2067
merged_a_cluster = False
2065
2068
for i in range (len (clusters ) - 2 , - 1 , - 1 ):
2066
2069
pos1 = clusters [i ][- 1 ]
2067
2070
pos2 = clusters [i + 1 ][0 ]
2068
- if pos2 .y - pos1 .y < distance :
2071
+ if pos2 .y - pos1 .y < ref_distance :
2069
2072
merged_a_cluster = True
2070
2073
cluster = []
2071
2074
cluster .extend (clusters .pop (i ))
@@ -2077,6 +2080,7 @@ def _draw_records(self, ctx, x1, x2, x3, y1, y2):
2077
2080
# Reposition the elements in each cluster. The strategy for setting
2078
2081
# positions depends on whether the cluster is near the top/bottom.
2079
2082
for cluster in clusters :
2083
+ distance = ref_distance - min (20 , 0.7 * len (cluster ))
2080
2084
if cluster [0 ].visible == "top" :
2081
2085
ref_y = cluster [0 ].y
2082
2086
for i , pos in enumerate (cluster ):
0 commit comments