Improve edgeplot for hybrid

pull/153/head
Frh 2020-04-25 13:31:10 -07:00
parent bb842f21b9
commit 22f4287788
7 changed files with 50 additions and 18 deletions

View File

@ -147,7 +147,7 @@ class TextAlignments(object):
def _create_new_text_alignment(coord, textline, align): def _create_new_text_alignment(coord, textline, align):
return TextAlignment(coord, textline, align) return TextAlignment(coord, textline, align)
def _update_edge(self, edge, coord, textline): def _update_alignment(self, alignment, coord, textline):
return NotImplemented return NotImplemented
def _register_textline(self, textline): def _register_textline(self, textline):
@ -172,7 +172,7 @@ class TextAlignments(object):
coord, coord,
atol=0.5 atol=0.5
): ):
self._update_edge( self._update_alignment(
alignment_array[idx_closest], alignment_array[idx_closest],
coord, coord,
textline textline
@ -209,7 +209,7 @@ class TextEdges(TextAlignments):
te = self._create_new_text_alignment(coord, textline, align) te = self._create_new_text_alignment(coord, textline, align)
self._text_alignments[align].append(te) self._text_alignments[align].append(te)
def _update_edge(self, edge, coord, textline): def _update_alignment(self, edge, coord, textline):
edge.update_coords(coord, textline, self.edge_tol) edge.update_coords(coord, textline, self.edge_tol)
def generate(self, textlines): def generate(self, textlines):

View File

@ -21,8 +21,6 @@ from ..utils import (
find_columns_coordinates find_columns_coordinates
) )
from matplotlib import patches as patches
# maximum number of columns over which a header can spread # maximum number of columns over which a header can spread
MAX_COL_SPREAD_IN_HEADER = 3 MAX_COL_SPREAD_IN_HEADER = 3
@ -220,8 +218,8 @@ class TextNetworks(TextAlignments):
# "number of textlines aligned" # "number of textlines aligned"
self._textlines_alignments = {} self._textlines_alignments = {}
def _update_edge(self, edge, coord, textline): def _update_alignment(self, alignment, coord, textline):
edge.register_aligned_textline(textline, coord) alignment.register_aligned_textline(textline, coord)
def _register_all_text_lines(self, textlines): def _register_all_text_lines(self, textlines):
"""Add all textlines to our network repository to """Add all textlines to our network repository to

View File

@ -8,7 +8,7 @@ except ImportError:
else: else:
_HAS_MPL = True _HAS_MPL = True
from .utils import bbox_from_str from .utils import (bbox_from_str, get_textline_coords)
def draw_labeled_bbox( def draw_labeled_bbox(
@ -287,16 +287,15 @@ class PlotMethods(object):
patches.Rectangle( patches.Rectangle(
(t[0], t[1]), t[2] - t[0], t[3] - t[1], (t[0], t[1]), t[2] - t[0], t[3] - t[1],
color="blue", color="blue",
alpha=0.5 alpha=0.2
) )
) )
ax.set_xlim(min(xs) - 10, max(xs) + 10) ax.set_xlim(min(xs) - 10, max(xs) + 10)
ax.set_ylim(min(ys) - 10, max(ys) + 10) ax.set_ylim(min(ys) - 10, max(ys) + 10)
if table.flavor == "hybrid": if table.flavor == "hybrid":
for text_network in table.parse_details["network_searches"]: for network in table.parse_details["network_searches"]:
# FRHTODO: This is too busy and doesn't plot lines most_connected_tl = network.most_connected_textline()
most_connected_tl = text_network.most_connected_textline()
ax.add_patch( ax.add_patch(
patches.Rectangle( patches.Rectangle(
@ -307,13 +306,48 @@ class PlotMethods(object):
alpha=0.5 alpha=0.5
) )
) )
for tl, alignments in text_network._textlines_alignments.items(): for tl, alignments in network._textlines_alignments.items():
coords = get_textline_coords(tl)
alignment_id_h, tls_h = alignments.max_v()
alignment_id_v, tls_v = alignments.max_h()
xs = list(map(lambda tl: tl.x0, tls_v))
ys = list(map(lambda tl: tl.y1, tls_h))
top_h = max(ys)
ax.text( ax.text(
tl.x0 - 5, coords[alignment_id_h],
tl.y0 - 5, top_h + 5,
f"{alignments.max_h_count()}x{alignments.max_v_count()}", "{max_h_count}".format(max_h_count=len(tls_h)),
fontsize=5, verticalalignment="bottom",
color="black" horizontalalignment="center",
fontsize=8,
color="green"
)
ax.plot(
[coords[alignment_id_h]] * len(ys), ys,
color="green",
linestyle="dashed",
linewidth=1,
marker="o",
markersize=3
)
left_v = min(map(lambda tl: tl.x0, tls_v))
ax.text(
left_v - 5,
coords[alignment_id_v],
"{max_v_count}".format(max_v_count=len(tls_v)),
verticalalignment="center",
horizontalalignment="right",
fontsize=8,
color="blue"
)
ax.plot(
xs, [coords[alignment_id_v]] * len(xs),
color="blue",
linestyle="dotted",
linewidth=1,
marker="o",
markersize=3
) )
else: else:
for te in table._textedges: for te in table._textedges:

Binary file not shown.

Before

Width:  |  Height:  |  Size: 105 KiB

After

Width:  |  Height:  |  Size: 105 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 100 KiB

After

Width:  |  Height:  |  Size: 102 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 192 KiB

After

Width:  |  Height:  |  Size: 164 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 113 KiB

After

Width:  |  Height:  |  Size: 113 KiB