octagonal_graph   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 19
dl 0
loc 45
rs 10
c 0
b 0
f 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A edge() 0 5 2
1
import graphinate
2
3
N: int = 8
4
5
# First Define a GraphModel instance.
6
# It will be used to hold the graph definitions
7
graph_model: graphinate.GraphModel = graphinate.model(name="Octagonal Graph")
8
9
# Register in the Graph Model the edges' supplier generator function
10
@graph_model.edge()
11
def edge():
12
    for i in range(N):
13
        yield {'source': i, 'target': i + 1}
14
    yield {'source': N, 'target': 0}
15
16
17
# Use the NetworkX Builder
18
builder = graphinate.builders.NetworkxBuilder(graph_model)
19
20
# build the NetworkX GraphRepresentation
21
# the output in this case is a nx.Graph instance
22
graph = builder.build()
23
24
# this supplied plot method uses matplotlib to display the graph
25
graphinate.matplotlib.plot(graph, with_edge_labels=True)
26
27
# or use the Mermaid Builder
28
builder = graphinate.builders.MermaidBuilder(graph_model)
29
30
# to create a Mermaid diagram
31
diagram: str = builder.build()
32
33
# and get Markdown or single page HTML to display it
34
mermaid_markdown: str = graphinate.mermaid.markdown(diagram)
35
mermaid_html: str = graphinate.mermaid.html(diagram, title=graph_model.name)
36
37
# or use the GraphQL Builder
38
builder = graphinate.builders.GraphQLBuilder(graph_model)
39
40
# to create a Strawberry GraphQL schema
41
schema = builder.build()
42
43
# and serve it using Uvicorn web server
44
graphinate.graphql.server(schema)
45