Bug still present in text annotation
This commit is contained in:
parent
d4e1d08494
commit
152fe466f8
@ -36,7 +36,6 @@ class MemoryDrawer():
|
||||
else:
|
||||
raise ValueError('Input must be a path to a .csv file or a pandas DataFrame')
|
||||
|
||||
|
||||
fig = MemoryDrawer.draw_diagram(data)
|
||||
MemoryDrawer.write_output(fig, output)
|
||||
|
||||
@ -56,8 +55,8 @@ class MemoryDrawer():
|
||||
data['end'] = data['end'].apply(_convert_to_int)
|
||||
data['size'] = data['end'] - data['start']
|
||||
|
||||
#data.sort_values(by=['size'], inplace=True, ascending=False)
|
||||
data.sort_values(by=['start', 'size'], inplace=True, ascending=True)
|
||||
# Sort start on ascending order, and size on descending order
|
||||
data.sort_values(by=['start', 'size'], inplace=True, ascending=[True, False])
|
||||
|
||||
# Inverse the order of the data
|
||||
data.reset_index(drop=True, inplace=True)
|
||||
@ -76,13 +75,13 @@ class MemoryDrawer():
|
||||
data.at[i, 'overlapped_by'] = ','.join(temp['index'].astype(str).to_list())
|
||||
|
||||
# Annotate rows that partially overlap the current row (from start, but not to end)
|
||||
temp = data.loc[(data['start'] <= row['start']) & (data['end'] < row['end']) & (data['end'] >= row['start'])]
|
||||
temp = data.loc[(data['start'] <= row['start']) & (data['end'] < row['end']) & (data['end'] > row['start'])]
|
||||
if temp.shape[0] > 1:
|
||||
data.at[i, 'partial_overlap'] = "Bottom"
|
||||
data.at[i, 'partial_overlapped_by'] = ','.join(temp['index'].astype(str).to_list())
|
||||
|
||||
# Annotate rows that partially overlap the current row (from end, but not to start)
|
||||
temp = data.loc[(data['start'] > row['start']) & (data['end'] >= row['end']) & (data['start'] <= row['end'])]
|
||||
temp = data.loc[(data['start'] > row['start']) & (data['end'] >= row['end']) & (data['start'] < row['end'])]
|
||||
if temp.shape[0] > 1:
|
||||
data.at[i, 'partial_overlap'] = "Top"
|
||||
data.at[i, 'partial_overlapped_by'] = ','.join(temp['index'].astype(str).to_list())
|
||||
@ -97,6 +96,8 @@ class MemoryDrawer():
|
||||
if (data['size'] < 0).any():
|
||||
print(f'Warning: Negative sizes detected at indices {data[data["size"] < 0].index}')
|
||||
|
||||
data["n_overlaps"] = data["overlapped_by"].apply(lambda x: len(str(x).split(',')) if pd.notna(x) else pd.NA)
|
||||
|
||||
return data
|
||||
|
||||
|
||||
@ -114,6 +115,8 @@ class MemoryDrawer():
|
||||
plot_bgcolor='#FFFFFF',
|
||||
)
|
||||
|
||||
extra_y = 0
|
||||
|
||||
for i, d in data.iterrows():
|
||||
fillcolor = random_color()
|
||||
data.at[i, 'fillcolor'] = fillcolor
|
||||
@ -124,9 +127,12 @@ class MemoryDrawer():
|
||||
|
||||
# Set base y values. Height of the rectangle.
|
||||
y0 = d['index']
|
||||
y1 = d['index']+1
|
||||
y1 = d['index']+1 # +(data['n_overlaps'].max() - data['n_overlaps'].min())
|
||||
|
||||
if d['overlap'] == True:
|
||||
# Count number of overlaps using overlapped_by
|
||||
n_overlaps = str(d['overlapped_by']).split(',')
|
||||
|
||||
# Row is overlapping the current row
|
||||
if pd.notna(d['overlapping']):
|
||||
y0 = sorted(map(int, d['overlapping'].split(',')))[0]
|
||||
@ -135,20 +141,16 @@ class MemoryDrawer():
|
||||
if pd.notna(d['overlapped_by']):
|
||||
y0 = y0 + vertical_gap_percentage
|
||||
y1 = y1 - vertical_gap_percentage
|
||||
x0 = x0 + horizontal_gap
|
||||
x1 = x1 - horizontal_gap
|
||||
x0 = x0 + (horizontal_gap*d['n_overlaps'])
|
||||
x1 = x1 - (horizontal_gap*d['n_overlaps'])
|
||||
|
||||
if d['partial_overlap'] == "Bottom":
|
||||
if pd.notna(d['partial_overlapped_by']):
|
||||
y0 = y0 + 0.25 + (0.6**len(d['partial_overlapped_by'].split(',')))
|
||||
#x0 = x0 + horizontal_gap
|
||||
#x1 = x1 - horizontal_gap
|
||||
|
||||
if d['partial_overlap'] == "Top":
|
||||
if pd.notna(d['partial_overlapped_by']):
|
||||
y1 = y1 - (0.6**len(d['partial_overlapped_by'].split(',')))
|
||||
#x0 = x0 + horizontal_gap
|
||||
#x1 = x1 - horizontal_gap
|
||||
|
||||
fig.add_shape(
|
||||
type="rect",
|
||||
@ -166,7 +168,7 @@ class MemoryDrawer():
|
||||
fig.add_trace(go.Scatter
|
||||
(
|
||||
x=[(x0+x1)/2],
|
||||
y=[i+0.5],
|
||||
y=[y0+0.5],
|
||||
text=d['name'],
|
||||
mode="text",
|
||||
textposition="middle center",
|
||||
@ -254,9 +256,7 @@ class MemoryDrawer():
|
||||
tickpointers = [i for i in range(len(data))]
|
||||
|
||||
fig.update_yaxes(
|
||||
# tickvals=[i for i in range(len(data)+1)],
|
||||
tickvals = tickpointers,
|
||||
#ticktext= labels, # Adds labels to the left-hand side of the graph
|
||||
griddash="longdashdot",
|
||||
gridwidth=0,
|
||||
gridcolor="black",
|
||||
|
Loading…
x
Reference in New Issue
Block a user