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