Ejemplo n.º 1
0
def html_visit_dispatcher(self, node):
    warn_for_deprecated_option(self, node)
    i = len(self.body)
    prefix = 'dispatcher'

    try:
        render_dot_html(self, node, node['code'], node['options'], prefix)
    except nodes.SkipNode:
        n = self.body[i:]
        if n:
            format = self.builder.config.graphviz_output_format
            fname, outfn = get_graphviz_fn(self, node['code'], node['options'],
                                           format, prefix)
            if fname is not None:
                copy_files(node, outfn)
                root = etree.fromstring('<div>%s</div>' % ''.join(n))
                imgs = {
                    c: p
                    for p in root.iter() for c in p.findall('img')
                    if c.attrib.get('src') == fname
                }
                for c, p in imgs.items():
                    c.attrib.update(node.get('img_opt', {}))
                    j = list(p).index(c)
                    p.remove(c)
                    a = etree.Element('a', href=fname)
                    p.insert(j, a)
                    a.append(c)
                del self.body[-len(n):]
                for c in root:
                    self.body.append(etree.tostring(c, 'unicode'))

        raise nodes.SkipNode
Ejemplo n.º 2
0
def html_visit_inheritance_diagram(self, node):
    """
    Output the graph for HTML.  This will insert a PNG with clickable
    image map.
    """
    graph = node['graph']

    graph_hash = get_graph_hash(node)
    name = 'inheritance%s' % graph_hash

    # Create a mapping from fully-qualified class names to URLs.
    graphviz_output_format = self.builder.env.config.graphviz_output_format.upper()
    current_filename = self.builder.current_docname + self.builder.out_suffix
    urls = {}
    for child in node:
        if child.get('refuri') is not None:
            if graphviz_output_format == 'SVG':
                urls[child['reftitle']] = "../" + child.get('refuri')
            else:
                urls[child['reftitle']] = child.get('refuri')
        elif child.get('refid') is not None:
            if graphviz_output_format == 'SVG':
                urls[child['reftitle']] = '../' + current_filename + '#' + child.get('refid')
            else:
                urls[child['reftitle']] = '#' + child.get('refid')

    dotcode = graph.generate_dot(name, urls, env=self.builder.env)
    render_dot_html(self, node, dotcode, {}, 'inheritance', 'inheritance',
                    alt='Inheritance diagram of ' + node['content'])
    raise nodes.SkipNode
Ejemplo n.º 3
0
def html_visit_inheritance_diagram(self, node):
    # type: (HTMLTranslator, inheritance_diagram) -> None
    """
    Output the graph for HTML.  This will insert a PNG with clickable
    image map.
    """
    graph = node['graph']

    graph_hash = get_graph_hash(node)
    name = 'inheritance%s' % graph_hash

    # Create a mapping from fully-qualified class names to URLs.
    graphviz_output_format = self.builder.env.config.graphviz_output_format.upper()
    current_filename = self.builder.current_docname + self.builder.out_suffix
    urls = {}
    for child in node:
        if child.get('refuri') is not None:
            if graphviz_output_format == 'SVG':
                urls[child['reftitle']] = "../" + child.get('refuri')
            else:
                urls[child['reftitle']] = child.get('refuri')
        elif child.get('refid') is not None:
            if graphviz_output_format == 'SVG':
                urls[child['reftitle']] = '../' + current_filename + '#' + child.get('refid')
            else:
                urls[child['reftitle']] = '#' + child.get('refid')

    dotcode = graph.generate_dot(name, urls, env=self.builder.env)
    render_dot_html(self, node, dotcode, {}, 'inheritance', 'inheritance',
                    alt='Inheritance diagram of ' + node['content'])
    raise nodes.SkipNode
Ejemplo n.º 4
0
def html_visit_inheritance_diagram(self, node):
    """
    Output the graph for HTML.  This will insert a PNG with clickable
    image map.
    """
    graph = node['graph']

    graph_hash = get_graph_hash(node)
    name = 'inheritance%s' % graph_hash

    # Create a mapping from fully-qualified class names to URLs.
    urls = {}
    for child in node:
        if child.get('refuri') is not None:
            urls[child['reftitle']] = child.get('refuri')
        elif child.get('refid') is not None:
            urls[child['reftitle']] = '#' + child.get('refid')

    dotcode = graph.generate_dot(name, urls, env=self.builder.env)
    render_dot_html(self,
                    node,
                    dotcode, [],
                    'inheritance',
                    'inheritance',
                    alt='Inheritance diagram of ' + node['content'])
    raise nodes.SkipNode
Ejemplo n.º 5
0
def html_visit_inheritance_diagram(
    self: NodeVisitor, node: inheritance_diagram
) -> None:
    """
    Builds HTML output from an :py:class:`~uqbar.sphinx.inheritance.inheritance_diagram` node.
    """
    inheritance_graph = node["graph"]
    urls = build_urls(self, node)
    graphviz_graph = inheritance_graph.build_graph(urls)
    dot_code = format(graphviz_graph, "graphviz")
    # TODO: We can perform unflattening here
    aspect_ratio = inheritance_graph.aspect_ratio
    if aspect_ratio:
        aspect_ratio = math.ceil(math.sqrt(aspect_ratio[1] / aspect_ratio[0]))
    if aspect_ratio > 1:
        process = subprocess.Popen(
            ["unflatten", "-l", str(aspect_ratio), "-c", str(aspect_ratio), "-f"],
            stdout=subprocess.PIPE,
            stdin=subprocess.PIPE,
            stderr=subprocess.PIPE,
        )
        stdout, stderr = process.communicate(dot_code.encode())
        dot_code = stdout.decode()
    render_dot_html(self, node, dot_code, {}, "inheritance", "inheritance")
    raise SkipNode
Ejemplo n.º 6
0
def html_visit_er_diagram(self, node):
    digraph = Digraph(node)
    dotcode = digraph.generate_dot()
    render_dot_html(self,
                    node,
                    dotcode, {},
                    'ERDiagram',
                    'ERDiagram',
                    alt='ER図')
    raise nodes.SkipNode
Ejemplo n.º 7
0
    def visit_graphviz(self: HTML5Translator,
                       node: sphinx_graphviz.graphviz) -> None:
        if builder_name in node:
            self.body.append(
                f'<div class="resizer" style="{node[builder_name]}">')
        else:
            self.body.append(f'<div class="resizer">')

        try:
            sphinx_graphviz.render_dot_html(self, node, node["code"],
                                            node["options"])
        except SkipNode:
            self.body.append("</div>")

        raise SkipNode
Ejemplo n.º 8
0
def visit_html(self, node):
    graph = Graph(
        spec=node['spec'],
        graph=node['graph'],
        node=node['node'],
        edge=node['edge'],
        root=node['root'],
    )
    render_dot_html(
        self=self,
        node=node,
        code=graph.dot(),
        options={},
        prefix='db-diagram',
        imgcls='db-diagram',
        alt='Database Diagram',
    )
    raise nodes.SkipNode
Ejemplo n.º 9
0
def html_visit_inheritance_diagram(self: HTMLTranslator,
                                   node: inheritance_diagram) -> None:
    """
    Output the graph for HTML.  This will insert a PNG with clickable
    image map.
    """
    graph = node["graph"]

    graph_hash = get_graph_hash(node)
    name = "inheritance%s" % graph_hash

    # Create a mapping from fully-qualified class names to URLs.
    graphviz_output_format = self.builder.env.config.graphviz_output_format.upper(
    )
    current_filename = self.builder.current_docname + self.builder.out_suffix
    urls = {}
    pending_xrefs = cast(Iterable[addnodes.pending_xref], node)
    for child in pending_xrefs:
        if child.get("refuri") is not None:
            if graphviz_output_format == "SVG":
                urls[child["reftitle"]] = "../" + child.get("refuri")
            else:
                urls[child["reftitle"]] = child.get("refuri")
        elif child.get("refid") is not None:
            if graphviz_output_format == "SVG":
                urls[child["reftitle"]] = ("../" + current_filename + "#" +
                                           child.get("refid"))
            else:
                urls[child["reftitle"]] = "#" + child.get("refid")

    dotcode = graph.generate_dot(name, urls, env=self.builder.env)
    render_dot_html(
        self,
        node,
        dotcode,
        {},
        "inheritance",
        "inheritance",
        alt="Inheritance diagram of " + node["content"],
    )
    raise nodes.SkipNode
Ejemplo n.º 10
0
def html_visit_inheritance_diagram(self, node):
    """
    Output the graph for HTML.  This will insert a PNG with clickable
    image map.
    """
    graph = node['graph']

    graph_hash = get_graph_hash(node)
    name = 'inheritance%s' % graph_hash

    # Create a mapping from fully-qualified class names to URLs.
    urls = {}
    for child in node:
        if child.get('refuri') is not None:
            urls[child['reftitle']] = child.get('refuri')
        elif child.get('refid') is not None:
            urls[child['reftitle']] = '#' + child.get('refid')

    dotcode = graph.generate_dot(name, urls, env=self.builder.env)
    render_dot_html(self, node, dotcode, [], 'inheritance', 'inheritance',
                    alt='Inheritance diagram of ' + node['content'])
    raise nodes.SkipNode
Ejemplo n.º 11
0
def html_visit_inheritance_diagram(self, node):
    """
    Output the graph for HTML.  This will insert a PNG with clickable
    image map.
    """
    graph = node["graph"]
    parts = node["parts"]

    graph_hash = get_graph_hash(node)
    name = "inheritance%s" % graph_hash

    # Create a mapping from fully-qualified class names to URLs.
    urls = {}
    for child in node:
        if child.get("refuri") is not None:
            urls[child["reftitle"]] = child.get("refuri")
        elif child.get("refid") is not None:
            urls[child["reftitle"]] = "#" + child.get("refid")

    dotcode = graph.generate_dot(name, parts, urls, env=self.builder.env)
    render_dot_html(self, node, dotcode, [], "inheritance", "inheritance")
    raise nodes.SkipNode
Ejemplo n.º 12
0
def html_visit_er_diagram(self, node):
    digraph = Digraph(node)
    dotcode = digraph.generate_dot()
    render_dot_html(self, node, dotcode, {}, 'ERDiagram', 'ERDiagram',
                    alt='ER図')
    raise nodes.SkipNode