Beispiel #1
0
def render_minimal_graph():
    print('rendering minimal graph')
    N = 8
    node_indices = list(range(N))

    plot = Plot(
        sizing_mode='stretch_both',
        x_range=(-1.1, 1.1), y_range=(-1.1, 1.1),
        tools="", toolbar_location=None)

    graph_renderer = GraphRenderer()

    graph_renderer.node_renderer.glyph = Oval(
        height=0.1, width=0.2, fill_color="fill_color", )

    graph_renderer.node_renderer.data_source.data = dict(
        index=node_indices,
        fill_color=Spectral8)
    graph_renderer.edge_renderer.data_source.data = dict(
        start=[0]*N,
        end=node_indices)

    # start of layout code (this is the part networkX helps to build!
    # the layout...)
    circ = [i*2*math.pi/8 for i in node_indices]
    x = [math.cos(i) for i in circ]
    y = [math.sin(i) for i in circ]

    graph_layout = dict(zip(node_indices, zip(x, y)))
    graph_renderer.layout_provider = StaticLayoutProvider(
        graph_layout=graph_layout)

    plot.axis.axis_line_width = 0
    plot.grid.grid_line_width = 0
    plot.xaxis.major_tick_line_color = None  # turn off x-axis major ticks
    plot.xaxis.minor_tick_line_color = None  # turn off x-axis minor ticks
    plot.yaxis.major_tick_line_color = None  # turn off y-axis major ticks
    plot.yaxis.minor_tick_line_color = None  # turn off y-axis minor ticks
    plot.xaxis.major_label_text_color = None  # Remove label x axis
    plot.yaxis.major_label_text_color = None  # Remove label x axis
    plot.border_fill_color = None
    plot.outline_line_color = None
    plot.renderers.append(graph_renderer)
    return plot
Beispiel #2
0
def example_func_1():
    import math

    from bokeh.io import show, output_file
    from bokeh.plotting import figure
    from bokeh.models import GraphRenderer, StaticLayoutProvider, Oval
    from bokeh.palettes import Spectral8

    N = 8
    node_indices = list(range(N))

    # plot = figure(title='Graph Layout Demonstration', x_range=(-1.1,1.1), y_range=(-1.1,1.1),
    #               tools='', toolbar_location=None)
    plot = figure(title='Graph Layout Demonstration',
                  x_range=(-1.1, 1.1),
                  y_range=(-1.1, 1.1))

    graph = GraphRenderer()

    graph.node_renderer.data_source.add(node_indices, 'index')
    graph.node_renderer.data_source.add(Spectral8, 'color')
    graph.node_renderer.glyph = Oval(height=0.1, width=0.2, fill_color='color')

    graph.edge_renderer.data_source.data = dict(start=[0] * N,
                                                end=node_indices)

    ### start of layout code
    circ = [i * 2 * math.pi / 8 for i in node_indices]
    x = [math.cos(i) for i in circ]
    y = [math.sin(i) for i in circ]

    graph_layout = dict(zip(node_indices, zip(x, y)))
    graph.layout_provider = StaticLayoutProvider(graph_layout=graph_layout)

    plot.renderers.append(graph)

    output_file('graph.html')
    show(plot)
Beispiel #3
0
    def draw(self):
        # N = 8
        self.generate_edges()
        node_indices = list(self.graph.vertices.keys())

        plot = figure(title='Graph Layout Demonstration',
                      x_range=(-1.1, 1.1),
                      y_range=(-1.1, 1.1),
                      tools='',
                      toolbar_location=None)

        graph = GraphRenderer()

        graph.node_renderer.data_source.add(node_indices, 'index')
        # graph.node_renderer.data_source.add(Spectral8, 'color')
        graph.node_renderer.glyph = Oval(height=0.1,
                                         width=0.2,
                                         fill_color='pink')

        # start = [0, 0, 1, 3]
        # end = [1, 3, 0, 0]
        graph.edge_renderer.data_source.data = dict(start=self.start_verts,
                                                    end=self.end_verts)

        ### start of layout code
        circ = [int(i) * 2 * math.pi / 8 for i in node_indices]
        x = [math.cos(i) for i in circ]
        y = [math.sin(i) for i in circ]

        graph_layout = dict(zip(node_indices, zip(x, y)))
        graph.layout_provider = StaticLayoutProvider(graph_layout=graph_layout)

        plot.renderers.append(graph)

        output_file('graph.html')
        show(plot)
Beispiel #4
0
from bokeh.plotting import figure

N = 8
node_indices = list(range(N))

plot = figure(title="Graph Layout Demonstration",
              x_range=(-1.1, 1.1),
              y_range=(-1.1, 1.1),
              tools="",
              toolbar_location=None)

graph = GraphRenderer()

graph.node_renderer.data_source.add(node_indices, 'index')
graph.node_renderer.data_source.add(Spectral8, 'color')
graph.node_renderer.glyph = Oval(height=0.1, width=0.2, fill_color="color")

graph.edge_renderer.data_source.data = dict(start=[0] * N, end=node_indices)

### start of layout code
circ = [i * 2 * math.pi / 8 for i in node_indices]
x = [math.cos(i) for i in circ]
y = [math.sin(i) for i in circ]
graph_layout = dict(zip(node_indices, zip(x, y)))
graph.layout_provider = StaticLayoutProvider(graph_layout=graph_layout)


### Draw quadratic bezier paths
def bezier(start, end, control, steps):
    return [(1 - s)**2 * start + 2 * (1 - s) * s * control + s**2 * end
            for s in steps]
Beispiel #5
0
node_indices = list(range(N))

plot = figure(title="Graph Layout Demonstration",
              x_range=(-1.1, 1.1),
              y_range=(-1.1, 1.1),
              plot_width=250,
              plot_height=250,
              tools="",
              toolbar_location=None)

node_ds = ColumnDataSource(data=dict(index=node_indices, color=Spectral8),
                           name="Node Renderer")
edge_ds = ColumnDataSource(data=dict(start=[0] * N, end=node_indices),
                           name="Edge Renderer")
### start of layout code
circ = [i * 2 * math.pi / 8 for i in node_indices]
x = [math.cos(i) for i in circ]
y = [math.sin(i) for i in circ]
graph_layout = dict(zip(node_indices, zip(x, y)))

graph = GraphRenderer(
    node_renderer=GlyphRenderer(glyph=Oval(height=0.1,
                                           width=0.2,
                                           fill_color="color"),
                                data_source=node_ds),
    edge_renderer=GlyphRenderer(glyph=MultiLine(), data_source=edge_ds),
    layout_provider=StaticLayoutProvider(graph_layout=graph_layout))

plot.renderers.append(graph)

show(plot)
Beispiel #6
0
    color_list.append(vertex.color)

plot = figure(x_range=(0, WIDTH), y_range=(0, HEIGHT),
              tools='', toolbar_location=None, plot_width=WIDTH, plot_height=HEIGHT, background_fill_color='gray')
#plot.xgrid.grid_line_color = None
plot.grid.grid_line_color = None
plot.axis.visible = False
plot.outline_line_color = None
plot.toolbar.logo = None
plot.toolbar_location = None

graph = GraphRenderer()

graph.node_renderer.data_source.add(node_indices, 'index')
graph.node_renderer.data_source.add(color_list, 'color')
graph.node_renderer.glyph = Oval(height=CIRCLE_SIZE, width=CIRCLE_SIZE, fill_color='color')

###this is drawing the edges from start to end
edge_start=[]
edge_end=[]
for vertex in graph_data.vertexes:
    for edge in vertex.edges:
        edge_start.append(vertex.index)
        edge_end.append(edge.destination.index)        

graph.edge_renderer.data_source.data = dict(
    start=edge_start,
    end=edge_end
)
### start of layout code
x = [v.pos['x'] for v in graph_data.vertexes]
Beispiel #7
0
color_list = []
for vertex in graph_data.vertexes:
    color_list.append(vertex.color)

plot = figure(title='Graph Layout Demonstration',
              x_range=(0, 500),
              y_range=(0, 500),
              tools='',
              toolbar_location=None)

graph = GraphRenderer()

graph.node_renderer.data_source.add(node_indices, 'index')
graph.node_renderer.data_source.add(color_list, 'color')
graph.node_renderer.glyph = Oval(height=30, width=38, fill_color='color')

# this is drawing the edges from start to end
# need to change how this works a bit
graph.edge_renderer.data_source.data = dict(
    start=[], end=[])  # this has to do with ending points
for vertex in graph_data.vertexes:
    if len(vertex.edges) > 0:
        for edge in vertex.edges:
            start = graph_data.vertexes.index(vertex)
            graph.edge_renderer.data_source.data['start'].append(start)

            end = graph_data.vertexes.index(edge.destination)
            graph.edge_renderer.data_source.data['end'].append(end)

### start of layout code
Beispiel #8
0
#Configure the number of nodes

total_nodes = 10
node_points = list(range(total_nodes))

#Create the network

plot = figure(x_range=(-1.1,1.1), y_range=(-1.1,1.1))

network = GraphRenderer()

#Customize your network

network.node_renderer.data_source.add(node_points, 'index')

network.node_renderer.glyph = Oval(height=0.2, width=0.3, fill_color='blue')

network.edge_renderer.data_source.data = dict(start=[1]*total_nodes, end=node_points)

#Render your network in 2-D space

node_circumference = [node*2*math.pi/10 for node in node_points]

x = [math.cos(circum) for circum in node_circumference]

y = [math.sin(circum) for circum in node_circumference]

network_layout = dict(zip(node_points, zip(x, y)))

#Output the network
Beispiel #9
0
N = 9
x = np.linspace(-2, 2, N)
y = x**2

source = ColumnDataSource(dict(x=x, y=y))

plot = Plot(title=None,
            plot_width=300,
            plot_height=300,
            min_border=0,
            toolbar_location=None)

glyph = Oval(x="x",
             y="y",
             width=0.4,
             height=0.6,
             angle=-0.7,
             fill_color="#1d91d0")
plot.add_glyph(source, glyph)

xaxis = LinearAxis()
plot.add_layout(xaxis, 'below')

yaxis = LinearAxis()
plot.add_layout(yaxis, 'left')

plot.add_layout(Grid(dimension=0, ticker=xaxis.ticker))
plot.add_layout(Grid(dimension=1, ticker=yaxis.ticker))

curdoc().add_root(plot)
Beispiel #10
0
def example_func_2():
    import math

    from bokeh.io import show, output_file
    from bokeh.plotting import figure
    from bokeh.models import GraphRenderer, StaticLayoutProvider, Oval
    from bokeh.palettes import Spectral11, Inferno256, Category20_20

    import networkx as nx
    from bokeh.models.graphs import from_networkx, NodesAndLinkedEdges, EdgesAndLinkedNodes

    from bokeh.models import Plot, Range1d, MultiLine, Circle, HoverTool, TapTool, BoxSelectTool
    from bokeh.palettes import Spectral4

    # N = 32 # 8
    # node_indices = list(range(N))
    # print(node_indices)
    box_limit = 2  # 1.1

    plot = figure(title="Graph Layout Demonstration",
                  x_range=(-box_limit, box_limit),
                  y_range=(-box_limit, box_limit))
    # tools="", toolbar_location=None)

    plot.add_tools(HoverTool(tooltips=None), TapTool(), BoxSelectTool())

    # graph = GraphRenderer()
    g = nx.karate_club_graph()
    N = (len(g.nodes()))
    g_layout = nx.spring_layout(g)
    graph_layout = g_layout

    graph = from_networkx(g, g_layout, scale=2, center=(0, 0))

    colors = Category20_20 + Category20_20

    node_indices = list(range(N))

    graph.node_renderer.data_source.add(node_indices, 'index')
    graph.node_renderer.data_source.add(colors, 'color')

    graph.node_renderer.glyph = Oval(height=0.1,
                                     width=0.2,
                                     fill_color=Spectral4[0])  # 'color'
    graph.node_renderer.selection_glyph = Oval(height=0.1,
                                               width=0.2,
                                               fill_color=Spectral4[1])
    graph.node_renderer.hover_glyph = Oval(height=0.1,
                                           width=0.2,
                                           fill_color=Spectral4[2])

    graph.edge_renderer.glyph = MultiLine(line_color="#CCCCCC",
                                          line_alpha=0.8,
                                          line_width=5)
    graph.edge_renderer.selection_glyph = MultiLine(line_color=Spectral4[2],
                                                    line_width=5)
    graph.edge_renderer.hover_glyph = MultiLine(line_color=Spectral4[1],
                                                line_width=5)

    graph.selection_policy = NodesAndLinkedEdges()
    graph.inspection_policy = EdgesAndLinkedNodes()

    if True:
        if True:  # make edges only from node 0 to all others.
            graph.edge_renderer.data_source.data = dict(start=[0] * N,
                                                        end=node_indices)

        if False:  # change and make nodes positions on a circle
            ### start of layout code
            circ = [i * 2 * math.pi / N for i in node_indices]
            x = [math.cos(i) for i in circ]
            y = [math.sin(i) for i in circ]
            graph_layout = dict(zip(node_indices, zip(x, y)))
            graph.layout_provider = StaticLayoutProvider(
                graph_layout=graph_layout)

        ### Draw quadratic bezier paths
        def bezier(start, end, control, steps):
            return [(1 - s)**2 * start + 2 * (1 - s) * s * control + s**2 * end
                    for s in steps]

        xs, ys = [], []
        sx, sy = graph_layout[0]
        steps = [i / 100. for i in range(100)]
        # make run on all nodes. setting edges from [0] node to all others
        for node_index in node_indices:
            ex, ey = graph_layout[node_index]
            xs.append(bezier(sx, ex, 0, steps))
            ys.append(bezier(sy, ey, 0, steps))
        graph.edge_renderer.data_source.data['xs'] = xs
        graph.edge_renderer.data_source.data['ys'] = ys

    plot.renderers.append(graph)

    output_file("graph2.html")
    show(plot)
Beispiel #11
0
def generate_bokeh_graph():

    N = 8
    node_indices = list(range(N))

    plot = figure(title="Graph Layout Demonstration",
                  x_range=(-1.1, 1.1),
                  y_range=(-1.1, 1.1),
                  tools="",
                  toolbar_location=None)

    graph = GraphRenderer()

    graph.node_renderer.data_source.add(node_indices, 'index')
    graph.node_renderer.data_source.add(Spectral8, 'color')
    graph.node_renderer.glyph = Oval(height=0.1, width=0.2, fill_color="color")

    graph.edge_renderer.data_source.data = dict(start=[0] * N,
                                                end=node_indices)

    ### start of layout code
    circ = [i * 2 * math.pi / 8 for i in node_indices]
    x = [math.cos(i) for i in circ]
    y = [math.sin(i) for i in circ]
    graph_layout = dict(zip(node_indices, zip(x, y)))
    graph.layout_provider = StaticLayoutProvider(graph_layout=graph_layout)

    ### Draw quadratic bezier paths
    def bezier(start, end, control, steps):
        return [(1 - s)**2 * start + 2 * (1 - s) * s * control + s**2 * end
                for s in steps]

    xs, ys = [], []
    sx, sy = graph_layout[0]
    steps = [i / 100. for i in range(100)]
    for node_index in node_indices:
        ex, ey = graph_layout[node_index]
        xs.append(bezier(sx, ex, 0, steps))
        ys.append(bezier(sy, ey, 0, steps))
    graph.edge_renderer.data_source.data['xs'] = xs
    graph.edge_renderer.data_source.data['ys'] = ys

    plot.renderers.append(graph)

    output_file("graph.html")
    show(plot)


# generate_bokeh_graph()
#
# u = Digraph('digraph', file_path='digraph.gv',
#             node_attr={'color': 'lightblue2', 'style': 'filled'})
# u.attr(size='6,6')
#
# u.edge('5th Edition', '6th Edition', label='n')
# u.edge('5th Edition', 'PWB 1.0',label='n')
# u.edge('6th Edition', 'LSX',label='n')
# u.edge('6th Edition', '1 BSD')
# u.edge('6th Edition', 'Mini Unix')
# u.edge('6th Edition', 'Wollongong')
# u.edge('6th Edition', 'Interdata')
# u.edge('Interdata', 'Unix/TS 3.0')
# u.edge('Interdata', 'PWB 2.0')
# u.edge('Interdata', '7th Edition')
# u.edge('7th Edition', '8th Edition')
# u.edge('7th Edition', '32V')
# u.edge('7th Edition', 'V7M')
# u.edge('7th Edition', 'Ultrix-11')
# u.view()

#https://stackoverflow.com/questions/51038073/flask-dynamic-graphviz-and-svg-example
# You can use svg just like this:
#
# {{ chart_output|safe }}
# and also, you can use png format:
#
# @app.route('/')
# def svgtest():
#     chart_data = Graph()
#
#     chart_data.node('H', 'Hello')
#     chart_data.node('W', 'World')
#     chart_data.edge('H', 'W')
#
#
#     chart_output = chart_data.pipe(format='png')
#     chart_output = base64.b64encode(chart_output).decode('utf-8')
#
#     return render_template('svgtest.html', chart_output=chart_output)
# and the html like this:
#
# <img src="data:image/png;base64,{{chart_output|safe}}" />
Beispiel #12
0
from bokeh.models import ColumnDataSource, Range1d, LabelSet, Label
import pprint
pp = pprint.PrettyPrinter(indent=4)
N = 8
node_indices = list(range(N))

plot = figure(title="Graph Layout Demonstration",
              x_range=(-1.1, 1.1),
              y_range=(-1.1, 1.1),
              tools="",
              toolbar_location=None)

graph = GraphRenderer()
#just one oval
graph.node_renderer.glyph = Oval(height=0.1,
                                 width=0.2,
                                 fill_color="fill_color",
                                 name="text")

fill_c = [Spectral8[0] for x in Spectral8]
fill_c[0] = Spectral8[1]
text = ['a', 'a', 'a', 'a', 'a', 'a', 'a']
ed = {'start': [0, 0, 0, 0, 1, 2, 3, 4, 1], 'end': [0, 1, 2, 3, 4, 5, 6, 7, 7]}
graph.node_renderer.data_source.data = dict(index=node_indices,
                                            fill_color=fill_c)
graph.edge_renderer.data_source.data = ed

### start of layout code
circ = [i * 2 * math.pi / 8 for i in node_indices]
x = [math.cos(i) for i in circ]
y = [math.sin(i) for i in circ]
Beispiel #13
0
    def show_flow_from_outside_to_buffers_to_tasks(self):
        from bokeh.io import output_file, show
        from bokeh.models import GraphRenderer, Oval, StaticLayoutProvider, ColumnDataSource, LabelSet, Arrow, OpenHead
        from bokeh.plotting import figure
        from bokeh.palettes import Plasma256
        # vector alpha >0 , vector a can be any value
        # a is input/output coming from outside
        # alpha is initial value in buffer
        # matrix G connected buffers and tasks
        # in matrix G , flow between a task and multiple buffers
        # a to buffer to task

        number_of_io_nodes = len(self.a)
        number_of_buffers = self.K
        number_of_tasks = len(self.H[0])
        index_array_of_io = list(range(1, number_of_io_nodes + 1))
        index_array_of_buffers = list(
            range(number_of_io_nodes + 1,
                  number_of_io_nodes + number_of_buffers + 1))
        index_array_of_tasks = list(
            range(number_of_io_nodes + number_of_buffers + 1,
                  number_of_io_nodes + number_of_buffers + number_of_tasks +
                  1))

        node_indices = np.concatenate(
            (index_array_of_io, index_array_of_buffers, index_array_of_tasks),
            axis=None).tolist()
        node_x_location = np.concatenate(
            (index_array_of_io, list(range(1,
                                           len(index_array_of_buffers) + 1)),
             list(range(1,
                        len(index_array_of_tasks) + 1))),
            axis=None).tolist()
        node_y_location = np.concatenate(
            (np.full(number_of_io_nodes, 7), np.full(
                number_of_buffers, 5), np.full(number_of_tasks, 3)),
            axis=None).tolist()

        max_x_range = max(number_of_io_nodes, number_of_buffers,
                          number_of_tasks) + 1

        plot = figure(title='Flow from outside to buffers to tasks',
                      x_range=(0, max_x_range),
                      y_range=(0, 9),
                      tools='',
                      toolbar_location=None)

        graph = GraphRenderer()

        graph.node_renderer.data_source.add(node_indices, 'index')
        graph.node_renderer.data_source.add(Plasma256[:len(node_indices)],
                                            'color')
        graph.node_renderer.glyph = Oval(height=0, width=0, fill_color='color')

        start = index_array_of_io
        end = index_array_of_buffers

        network_graph_buffer_task_hash = {}

        for buffer_index in range(number_of_buffers):
            network_graph_buffer_task_hash[buffer_index + 1] = np.sum(
                self.G[buffer_index, :])

        graph.edge_renderer.data_source.data = dict(start=start, end=end)

        x = node_x_location
        y = node_y_location

        graph_layout = dict(zip(node_indices, zip(x, y)))
        graph.layout_provider = StaticLayoutProvider(graph_layout=graph_layout)

        plot.renderers.append(graph)

        x_io = list(range(1, number_of_io_nodes + 1))
        y_io = np.full(number_of_io_nodes, 7)
        plot.triangle(x_io,
                      y_io,
                      size=30,
                      color=getLargePalette(number_of_io_nodes, Plasma256),
                      alpha=0.5,
                      line_width=2)

        x_buffers = list(range(1, number_of_buffers + 1))
        y_buffers = np.full(number_of_buffers, 5)
        plot.rect(x_buffers,
                  y_buffers,
                  color=getLargePalette(number_of_buffers, Plasma256),
                  alpha=0.5,
                  width=0.5,
                  height=0.5)

        x_tasks = list(range(1, number_of_tasks + 1))
        y_tasks = np.full(number_of_tasks, 3)
        plot.circle(x_tasks,
                    y_tasks,
                    size=30,
                    color=getLargePalette(number_of_tasks, Plasma256),
                    alpha=0.5)

        for i in range(number_of_buffers):
            for j in range(number_of_tasks):
                if self.G[i, j] > 0:
                    x_start_node = x_buffers[i]
                    y_start_node = y_buffers[i]
                    x_end_node = x_tasks[j]
                    y_end_node = y_tasks[j]
                elif self.G[i, j] < 0:
                    x_start_node = x_tasks[j]
                    y_start_node = y_tasks[j]
                    x_end_node = x_buffers[i]
                    y_end_node = y_buffers[i]
                plot.add_layout(
                    Arrow(end=OpenHead(),
                          x_start=x_start_node,
                          y_start=y_start_node,
                          x_end=x_end_node,
                          y_end=y_end_node))

        text_label_values = np.round(
            np.multiply(
                np.round(list(network_graph_buffer_task_hash.values()), 2),
                100)).tolist()
        text_label_values = [
            str(int(capacity)) + '%' for capacity in text_label_values
        ]

        source = ColumnDataSource(
            data=dict(x=list(network_graph_buffer_task_hash.keys()),
                      y=np.full(number_of_buffers, 4.8),
                      values=text_label_values))
        capacityLabels = LabelSet(x='x',
                                  y='y',
                                  text='values',
                                  level='glyph',
                                  x_offset=-8,
                                  y_offset=10,
                                  source=source,
                                  render_mode='canvas',
                                  text_font_size="10pt")

        plot.add_layout(capacityLabels)

        source = ColumnDataSource(
            data=dict(x=[
                max_x_range / 2 - 0.5, max_x_range / 2 - 0.5, max_x_range / 2 -
                0.5
            ],
                      y=[2.5, 5.5, 7.5],
                      values=['tasks', 'buffers', 'outside sources']))

        typeLabel = LabelSet(x='x',
                             y='y',
                             text='values',
                             level='glyph',
                             x_offset=0,
                             y_offset=0,
                             source=source,
                             render_mode='canvas',
                             text_font_size="10pt")
        plot.add_layout(typeLabel)

        output_file('graph.html')
        show(plot)

        return None
Beispiel #14
0
    def show_task_capacity_per_server(self):
        from bokeh.io import output_file, show
        from bokeh.models import GraphRenderer, Oval, StaticLayoutProvider, ColumnDataSource, LabelSet
        from bokeh.plotting import figure
        from bokeh.palettes import Category20c, Category20
        # we have 12 kinds of tasks (number of columns in H) and 4 time_slots (number of rows in H)
        number_of_servers = len(self.H)
        tasks = ['task ' + str(i) for i in range(1, len(self.H[0]) + 1)]

        index_array_of_tasks = list(range(1, len(tasks) + 1))
        index_array_of_servers = list(
            range(len(tasks) + 1,
                  len(tasks) + number_of_servers + 1))

        number_of_tasks = len(tasks)

        node_indices = np.concatenate(
            (index_array_of_tasks, index_array_of_servers),
            axis=None).tolist()
        node_x_location = np.concatenate(
            (index_array_of_tasks,
             list(range(1,
                        len(index_array_of_servers) + 1))),
            axis=None).tolist()
        node_y_location = np.concatenate(
            (np.full(len(index_array_of_tasks),
                     5), np.full(len(index_array_of_servers), 3)),
            axis=None).tolist()

        plot = figure(title='Task capacity per server',
                      x_range=(0, max(number_of_servers, number_of_tasks) + 1),
                      y_range=(0, 8),
                      tools='',
                      toolbar_location=None)

        graph = GraphRenderer()

        graph.node_renderer.data_source.add(node_indices, 'index')
        graph.node_renderer.data_source.add(Category20c[len(node_indices)],
                                            'color')
        graph.node_renderer.glyph = Oval(height=0, width=0, fill_color='color')

        network_graph_tasks_indices = []
        network_graph_server_indices = []
        network_graph_tasks_server_hash = {}

        for k in range(number_of_servers):  # servers
            for j in range(number_of_tasks):  # tasks
                if self.H[k, j] > 0:
                    network_graph_tasks_indices.append(j + 1)
                    network_graph_server_indices.append(len(tasks) + k + 1)
                    network_graph_tasks_server_hash[j + 1] = self.H[k, j]

        graph.edge_renderer.data_source.data = dict(
            start=list(network_graph_tasks_indices),
            end=list(network_graph_server_indices))

        x = node_x_location
        y = node_y_location

        graph_layout = dict(zip(node_indices, zip(x, y)))
        graph.layout_provider = StaticLayoutProvider(graph_layout=graph_layout)

        plot.renderers.append(graph)

        x_servers = list(range(1, len(index_array_of_servers) + 1))
        y_servers = np.full(len(index_array_of_servers), 3)
        plot.square(x_servers,
                    y_servers,
                    size=30,
                    color=Category20[number_of_servers],
                    alpha=0.5)

        x_tasks = index_array_of_tasks
        y_tasks = np.full(len(index_array_of_tasks), 5)
        plot.circle(x_tasks,
                    y_tasks,
                    size=30,
                    color=Category20[len(index_array_of_tasks)],
                    alpha=0.5)
        text_label_values = np.round(
            np.multiply(
                np.round(list(network_graph_tasks_server_hash.values()), 2),
                100)).tolist()
        text_label_values = [
            str(int(capacity)) + '%' for capacity in text_label_values
        ]

        source = ColumnDataSource(
            data=dict(x=list(network_graph_tasks_server_hash.keys()),
                      y=np.full(len(network_graph_tasks_indices), 4.8),
                      values=text_label_values))
        capacityLabels = LabelSet(x='x',
                                  y='y',
                                  text='values',
                                  level='glyph',
                                  x_offset=-8,
                                  y_offset=10,
                                  source=source,
                                  render_mode='canvas',
                                  text_font_size="10pt")

        plot.add_layout(capacityLabels)

        source = ColumnDataSource(
            data=dict(x=[6, 6], y=[2.5, 5.5], values=['servers', 'tasks']))

        typeLabel = LabelSet(x='x',
                             y='y',
                             text='values',
                             level='glyph',
                             x_offset=0,
                             y_offset=0,
                             source=source,
                             render_mode='canvas',
                             text_font_size="10pt")
        plot.add_layout(typeLabel)

        output_file('graph.html')
        show(plot)

        return None
Beispiel #15
0
from bokeh.io import show, output_file
from bokeh.models import GraphRenderer, StaticLayoutProvider, Oval
from bokeh.palettes import Spectral10
from bokeh.plotting import figure

total_nodes = 10
node_points = list(range(total_nodes))
print(node_points)

# Create the plot
plot = figure(x_range=(-1.1, 1.1), y_range=(-1.1, 1.1))

network = GraphRenderer()
network.node_renderer.data_source.add(Spectral10, 'color')
network.node_renderer.data_source.add(node_points, 'index')
network.node_renderer.glyph = Oval(height=0.2, width=0.3, fill_color='color')
network.edge_renderer.data_source.data = dict(start=[1] * total_nodes,
                                              end=node_points)

node_circumference = [node * 2 * math.pi / 10 for node in node_points]
x = [math.cos(circum) for circum in node_circumference]
y = [math.sin(circum) for circum in node_circumference]
print('x:')
print(x)
print('y')
print(y)

network_layout = dict(zip(node_points, zip(x, y)))
print('network_layout:')
print(network_layout)
Beispiel #16
0
           h=0.4,
           url=dict(value="https://static.bokeh.org/logos/logo.png"),
           anchor="center")),
 ("line", Line(x="x", y="y", line_color="#F46D43")),
 ("multi_line",
  MultiLine(xs="xs", ys="ys", line_color="#8073AC", line_width=2)),
 ("multi_polygons",
  MultiPolygons(xs="xsss",
                ys="ysss",
                line_color="#8073AC",
                fill_color="#FB9A99",
                line_width=2)),
 ("oval",
  Oval(x="x",
       y="y",
       width=screen(15),
       height=screen(25),
       angle=-0.7,
       fill_color="#1D91C0")),
 ("patch", Patch(x="x", y="y", fill_color="#A6CEE3")),
 ("patches", Patches(xs="xs", ys="ys", fill_color="#FB9A99")),
 ("quad",
  Quad(left="x", right="xp01", top="y", bottom="ym01",
       fill_color="#B3DE69")),
 ("quadratic",
  Quadratic(x0="x",
            y0="y",
            x1="xp02",
            y1="y",
            cx="xp01",
            cy="yp01",
            line_color="#4DAF4A",
Beispiel #17
0
from bokeh.palettes import Spectral8

N = 8
node_indices = list(range(N))

plot = figure(title='Graph Layout Demonstration',
              x_range=(-1.1, 1.1),
              y_range=(-1.1, 1.1),
              tools='',
              toolbar_location=None)

graph = GraphRenderer()

graph.node_renderer.data_source.add(node_indices, 'index')
graph.node_renderer.data_source.add(Spectral8, 'color')
graph.node_renderer.glyph = Oval(height=0.8, width=0.6, fill_color='color')

graph.edge_renderer.data_source.data = dict(start=[0] * N, end=node_indices)

### start of layout code
circ = [i * 2 * math.pi / 8 for i in node_indices]
x = [math.cos(i) for i in circ]
y = [math.sin(i) for i in circ]

graph_layout = dict(zip(node_indices, zip(x, y)))
graph.layout_provider = StaticLayoutProvider(graph_layout=graph_layout)

plot.renderers.append(graph)

output_file('graph.html')
show(plot)
Beispiel #18
0
    def show(self):
        graph = self.graph
        N = len(self.graph.vertices)
        # node_indices = 4
        node_indices = list(self.graph.vertices.keys())

        plot = figure(title="Mike Kerbleski Graph",
                      x_range=(0, 10.1),
                      y_range=(0, 10.1),
                      tools="",
                      toolbar_location=None)

        graph_renderer = GraphRenderer()

        edge_start = []
        edge_end = []

        # print(node_indices)

        for vertex_id in node_indices:
            for v in graph.vertices[vertex_id].edges:
                edge_start.append(vertex_id)
                edge_end.append(v)

        graph_renderer.edge_renderer.data_source.data = dict(start=edge_start,
                                                             end=edge_end)

        x = []
        y = []

        colors = []
        labels = []
        color1 = "red"
        color2 = "blue"

        for vertex_id in node_indices:
            labels.append('hello')
            if vertex_id in edge_start:
                colors.append(color1)
            else:
                colors.append(color2)

            vertex = graph.vertices[vertex_id]
            x.append(vertex.x)
            y.append(vertex.y)

        graph_renderer.node_renderer.data_source.add(node_indices, 'index')
        graph_renderer.node_renderer.data_source.add(colors, 'color')
        graph_renderer.node_renderer.glyph = Oval(height=0.1,
                                                  width=0.2,
                                                  fill_color="color")

        graph_layout = dict(zip(node_indices, zip(x, y)))
        graph_renderer.layout_provider = StaticLayoutProvider(
            graph_layout=graph_layout)

        ### Draw quadratic bezier paths
        def bezier(start, end, control, steps):
            return [(1 - s)**2 * start + 2 * (1 - s) * s * control + s**2 * end
                    for s in steps]

        plot.renderers.append(graph_renderer)

        output_file("graph.html")
        show(plot)