Skip to content

Visualize

visualize¤

load_graph(connections_json, title) ¤

Load json file that contains the paper connection information, and build a graph using it.

Parameters:

Name Type Description Default
connections_json Union[str, Path]

json file that contains the paper connection information

required
title str

title of the graph which will be shown in the top of the chart

required
Source code in kirsche/visualize.py
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
def load_graph(connections_json: Union[str, Path], title: str) -> PaperGraph:
    """Load json file that contains the paper connection information, and build a graph using it.

    :param connections_json: json file that contains the paper connection information
    :param title: title of the graph which will be shown in the top of the chart
    """

    data = load_json(connections_json)

    if data:
        g = PaperGraph(data, title=title)
    else:
        raise ValueError(f"No data in json file: {connections_json}!")

    return g

make_chart(connections_json, target, title) ¤

Generate interactive graphs

Parameters:

Name Type Description Default
connections_json Union[Path, str]

json file that contains the paper connection information

required
target Union[Path, str]

target file path

required
title str

title of the graph which will be shown in the top of the chart

required
Source code in kirsche/visualize.py
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
def make_chart(
    connections_json: Union[Path, str], target: Union[Path, str], title: str
) -> None:
    """Generate interactive graphs

    :param connections_json: json file that contains the paper connection information
    :param target: target file path
    :param title: title of the graph which will be shown in the top of the chart
    """

    g = load_graph(connections_json, title)

    nodes = g.nodes
    edges = g.edges

    visualize(nodes, edges, g.title, target)

visualize(nodes, edges, title, target) ¤

Generate interactive graphs

Parameters:

Name Type Description Default
nodes list

nodes of the graph

required
edges list

edges of the graph

required
title str

title of the graph which will be shown in the top of the chart

required
target Union[str, Path]

target file path

required
Source code in kirsche/visualize.py
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
def visualize(nodes: list, edges: list, title: str, target: Union[str, Path]) -> None:
    """Generate interactive graphs

    :param nodes: nodes of the graph
    :param edges: edges of the graph
    :param title: title of the graph which will be shown in the top of the chart
    :param target: target file path
    """

    if isinstance(target, str):
        target = Path(target)

    if not target.parent.exists():
        target.parent.mkdir(parents=True)

    # Build the graph and export it to html file
    (
        Graph(init_opts=opts.InitOpts(width="1600px", height="800px", page_title=title))
        .add(
            series_name="",
            nodes=nodes,
            links=edges,
            layout="none",
            is_roam=True,
            is_focusnode=True,
            label_opts=opts.LabelOpts(is_show=False),
            linestyle_opts=opts.LineStyleOpts(width=10, curve=0.3, opacity=0.5),
        )
        .set_global_opts(title_opts=opts.TitleOpts(title=title))
        .render(target)
    )