legacy/createcsvs.py
def categorise_paths(paths):
    """Categorise paths into background lines and the trend line.

    Args:
        paths: Paths extracted from single plot SVG

    Returns:
        (xlim, y_lines, points)
        xlim: Limits of the x axis (in SVG coordinates)
        y_lines: [Bottom, Middle, Top]
            i.e. (-80%, baseline, +80%) (in SVG coordinates)
        points: Points on the trend line (in SVG coordinates)

    Raises:
        ValueError: Assuming single segment trend line, not yet handled
    """
    single_segment_lines = [path for path in paths if len(path) == 1]

    short_trends = []
    if len(single_segment_lines) > 5:

        single_segment_lines.sort(key=lambda p: p.length())

        short_trends = single_segment_lines[:-5]
        single_segment_lines = single_segment_lines[:5]

    y_lines = sorted([path.start.imag for path in single_segment_lines])

    if len(y_lines) == 5:
        y_lines = [y_lines[0], y_lines[2], y_lines[-1]]

    points = []

    if len(y_lines) == 3:

        xlim = [(path.start.real, path.end.real) for path in paths if len(path) == 1][1]

        trends = [path for path in paths if len(path) > 1] + short_trends

        for trend in trends:
            if isinstance(trend[0], svgpathtools.path.CubicBezier):
                point_xmin, point_xmax, point_ymin, point_ymax = trend.bbox()
                xmid = (point_xmin + point_xmax) / 2
                ymid = (point_ymin + point_ymax) / 2

                points.append(complex(xmid, ymid))

            else:

                for sub_path in trend.continuous_subpaths():
                    points += [segment.start for segment in sub_path]
                    points.append(sub_path.end)

        y_lines = sorted(y_lines, reverse=True)

        return xlim, y_lines, points

    else:
        raise ValueError(f"Wrong number of y_lines: {len(y_lines)}")
Categorise paths into background lines and the trend line.

    Args:
        paths: Paths extracted from single plot SVG

    Returns:
        (xlim, y_lines, points)
        xlim: Limits of the x axis (in SVG coordinates)
        y_lines: [Bottom, Middle, Top]
            i.e. (-80%, baseline, +80%) (in SVG coordinates)
        points: Points on the trend line (in SVG coordinates)

    Raises:
        ValueError: Assuming single segment trend line, not yet handled
    
Categorise paths into background lines and the trend line.
Categorise paths into background lines and the trend line .
def categorise_paths(paths):
    single_segment_lines = [path for path in paths if len(path) == 1]
    short_trends = []
    if len(single_segment_lines) > 5:
        single_segment_lines.sort(key=lambda p: p.length())
        short_trends = single_segment_lines[:-5]
        single_segment_lines = single_segment_lines[:5]
    y_lines = sorted([path.start.imag for path in single_segment_lines])
    if len(y_lines) == 5:
        y_lines = [y_lines[0], y_lines[2], y_lines[-1]]
    points = []
    if len(y_lines) == 3:
        xlim = [(path.start.real, path.end.real) for path in paths if len(path) == 1][1]
        trends = [path for path in paths if len(path) > 1] + short_trends
        for trend in trends:
            if isinstance(trend[0], svgpathtools.path.CubicBezier):
                point_xmin, point_xmax, point_ymin, point_ymax = trend.bbox()
                xmid = (point_xmin + point_xmax) / 2
                ymid = (point_ymin + point_ymax) / 2
                points.append(complex(xmid, ymid))
            else:
                for sub_path in trend.continuous_subpaths():
                    points += [segment.start for segment in sub_path]
                    points.append(sub_path.end)
        y_lines = sorted(y_lines, reverse=True)
        return xlim, y_lines, points
    else:
        raise ValueError(f"Wrong number of y_lines: {len(y_lines)}")
def categorise_paths ( paths ) : single_segment_lines = [ path for path in paths if len ( path ) == 1 ] short_trends = [ ] if len ( single_segment_lines ) > 5 : single_segment_lines . sort ( key = lambda p : p . length ( ) ) short_trends = single_segment_lines [ : - 5 ] single_segment_lines = single_segment_lines [ : 5 ] y_lines = sorted ( [ path . start . imag for path in single_segment_lines ] ) if len ( y_lines ) == 5 : y_lines = [ y_lines [ 0 ] , y_lines [ 2 ] , y_lines [ - 1 ] ] points = [ ] if len ( y_lines ) == 3 : xlim = [ ( path . start . real , path . end . real ) for path in paths if len ( path ) == 1 ] [ 1 ] trends = [ path for path in paths if len ( path ) > 1 ] + short_trends for trend in trends : if isinstance ( trend [ 0 ] , svgpathtools . path . CubicBezier ) : point_xmin , point_xmax , point_ymin , point_ymax = trend . bbox ( ) xmid = ( point_xmin + point_xmax ) / 2 ymid = ( point_ymin + point_ymax ) / 2 points . append ( complex ( xmid , ymid ) ) else : for sub_path in trend . continuous_subpaths ( ) : points += [ segment . start for segment in sub_path ] points . append ( sub_path . end ) y_lines = sorted ( y_lines , reverse = True ) return xlim , y_lines , points else : raise ValueError ( f"Wrong number of y_lines: {len(y_lines)}" )
Categorise paths into background lines and the trend line.
Categorise paths into background lines and the trend line .
"""Categorise paths into background lines and the trend line.

    Args:
        paths: Paths extracted from single plot SVG

    Returns:
        (xlim, y_lines, points)
        xlim: Limits of the x axis (in SVG coordinates)
        y_lines: [Bottom, Middle, Top]
            i.e. (-80%, baseline, +80%) (in SVG coordinates)
        points: Points on the trend line (in SVG coordinates)

    Raises:
        ValueError: Assuming single segment trend line, not yet handled
    """
(xlim, y_lines, points)
xlim: Limits of the x axis (in SVG coordinates)
y_lines: [Bottom, Middle, Top]
i.e. (-80%, baseline, +80%) (in SVG coordinates)
points: Points on the trend line (in SVG coordinates)
( xlim y_lines points ) xlim : Limits of the x axis ( in SVG coordinates ) y_lines : [ Bottom Middle Top ] i . e . ( - 80% baseline + 80% ) ( in SVG coordinates ) points : Points on the trend line ( in SVG coordinates )
Assuming single segment trend line, not yet handled
Assuming single segment trend line not yet handled
ValueError
paths
Paths extracted from single plot SVG
Paths extracted from single plot SVG