Skip to content

Stack

net-bench enables fast processing of multiple ImageGenerators with ImageCollection. In an ImageCollection object, multiple ImageGenerator objects can be added in a similar way as to a list. This allows for several usages:

Creating a Flipbook

A flipbook in the form of a PDF or a Powerpoint can be created with an ImageCollection object. First some preparation to get a simple graph:

import pathlib
import dsslab.net_bench as dnb
import networkx as nx

graph = nx.DiGraph()
graph.add_nodes_from([1, 2, 3, 4, 5])
graph.add_edges_from([(1, 2), (2, 3), (3, 4), (4, 5)])

pathlib allows for the easy usage of paths to directories and files.

We create an ImageGenerator and set positions, which we choose ourselves:

image_generator = ImageGenerator(graph)
positions = {
    1: [-0.64773329, -0.61381879],
    2: [-0.08689388, -0.64267512],
    3: [0.11388331, -0.15139483],
    4: [0.13119441, 0.40788873],
    5: [0.48954945, 1.0],
}
image_generator.nodes.set_positions(positions)

We create an ImageCollection with a ImageGenerator and add a second ImageGenerator.

image_stack = dnb.ImageCollection([image_generator])
image_stack.append(image_generator)

Now we can draw using the object image_stack, in this case a powerpoint presentation:

path = pathlib.Path("myPresentation.pptx")
image_stack.create_flipbook(path)

To draw a PDF with all ImageGenerators, we would have to do this:

path = pathlib.Path("myPDF.pdf")
image_stack.create_flipbook(path)

Note

Look at the different file endings! When working with net-bench, this is how you recognize if you want to export as a PDF or as a PPTX.