From f419769396747931535eba264fd3143afd89f0fd Mon Sep 17 00:00:00 2001 From: Alexander Urban Date: Tue, 12 Mar 2019 11:06:42 -0500 Subject: [PATCH] Import some HTML constructor utilities from gwdetchar --- bin/hveto | 5 +- hveto/html.py | 140 +++------------------------------------ hveto/plot.py | 30 --------- hveto/tests/test_html.py | 59 ----------------- hveto/tests/test_plot.py | 13 ---- 5 files changed, 12 insertions(+), 235 deletions(-) diff --git a/bin/hveto b/bin/hveto index e2f5cc5..ddd023b 100755 --- a/bin/hveto +++ b/bin/hveto @@ -54,9 +54,10 @@ from gwpy.time import to_gps from gwpy.segments import (Segment, SegmentList, DataQualityFlag, DataQualityDict) +from gwdetchar.io.html import FancyPlot + from hveto import (__version__, log, config, core, plot, html, utils) -from hveto.plot import (HEADER_CAPTION, ROUND_CAPTION, FancyPlot, - get_column_label) +from hveto.plot import (HEADER_CAPTION, ROUND_CAPTION, get_column_label) from hveto.segments import (write_ascii as write_ascii_segments, read_veto_definer_file) from hveto.triggers import (get_triggers, find_auxiliary_channels) diff --git a/hveto/html.py b/hveto/html.py index f26f364..49b6f53 100755 --- a/hveto/html.py +++ b/hveto/html.py @@ -33,7 +33,7 @@ from MarkupPy import markup -from gwdetchar.io.html import package_table +from gwdetchar.io import html as gwhtml from ._version import get_versions @@ -325,128 +325,6 @@ def bold_param(key, value, **attrs): return markup.oneliner.p('%s: %s' % (key, value), **attrs) -def html_link(href, txt, target="_blank", **params): - """Write an HTML tag - - Parameters - ---------- - href : `str` - the URL to point to - txt : `str` - the text for the link - target : `str`, optional - the ``target`` of this link - **params - other HTML parameters for the ```` tag - - Returns - ------- - html : `str` - """ - if target is not None: - params.setdefault('target', target) - return markup.oneliner.a(txt, href=href, **params) - - -def cis_link(channel, **params): - """Write a channel name as a link to the Channel Information System - - Parameters - ---------- - channel : `str` - the name of the channel to link - **params - other HTML parmeters for the ```` tag - - Returns - ------- - html : `str` - """ - kwargs = { - 'title': "CIS entry for %s" % channel, - 'style': "font-family: Monaco, \"Courier New\", monospace;", - } - kwargs.update(params) - return html_link("https://cis.ligo.org/channel/byname/%s" % channel, - channel, **kwargs) - - -def fancybox_img(img, linkparams=dict(), **params): - """Return the markup to embed an in HTML - - Parameters - ---------- - img : `FancyPlot` - a `FancyPlot` object containing the path of the image to embed - and its caption to be displayed - linkparams : `dict` - the HTML attributes for the ```` tag - **params - the HTML attributes for the ```` tag - - Returns - ------- - html : `str` - - Notes - ----- - See `~hveto.plot.FancyPlot` for more about the `FancyPlot` class. - """ - page = markup.page() - aparams = { - 'title': img.caption, - 'class_': 'fancybox', - 'target': '_blank', - 'data-fancybox-group': 'hveto-image', - } - aparams.update(linkparams) - img = str(img) - page.a(href=img, **aparams) - imgparams = { - 'alt': os.path.basename(img), - 'class_': 'img-responsive', - } - if img.endswith('.svg') and os.path.isfile(img.replace('.svg', '.png')): - imgparams['src'] = img.replace('.svg', '.png') - else: - imgparams['src'] = img - imgparams.update(params) - page.img(**imgparams) - page.a.close() - return str(page) - - -def scaffold_plots(plots, nperrow=2): - """Embed a `list` of images in a bootstrap scaffold - - Parameters - ---------- - plot : `list` of `str` - the list of image paths to embed - nperrow : `int` - the number of images to place in a row (on a desktop screen) - - Returns - ------- - page : `~MarkupPy.markup.page` - the markup object containing the scaffolded HTML - """ - page = markup.page() - x = int(12//nperrow) - # scaffold plots - for i, p in enumerate(plots): - if i % nperrow == 0: - page.div(class_='row') - page.div(class_='col-sm-%d' % x) - page.add(fancybox_img(p)) - page.div.close() # col - if i % nperrow == nperrow - 1: - page.div.close() # row - if i % nperrow < nperrow-1: - page.div.close() # row - return page() - - def write_footer(about=None, date=None): """Write a