File: __init__.py

package info (click to toggle)
python-vispy 0.15.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 8,868 kB
  • sloc: python: 59,799; javascript: 6,800; makefile: 69; sh: 6
file content (55 lines) | stat: -rw-r--r-- 1,466 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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
# -*- coding: utf-8 -*-
# Copyright (c) Vispy Development Team. All Rights Reserved.
# Distributed under the (new) BSD License. See LICENSE.txt for more info.

import inspect

from .random import random
from .circular import circular
from .force_directed import fruchterman_reingold
from .networkx_layout import NetworkxCoordinates


_layout_map = {
    'random': random,
    'circular': circular,
    'force_directed': fruchterman_reingold,
    'spring_layout': fruchterman_reingold,
    "networkx_layout": NetworkxCoordinates,
}

AVAILABLE_LAYOUTS = tuple(_layout_map.keys())


def get_layout(name, *args, **kwargs):
    """
    Retrieve a graph layout

    Some graph layouts accept extra options. Please refer to their
    documentation for more information.

    Parameters
    ----------
    name : string
        The name of the layout. The variable `AVAILABLE_LAYOUTS`
        contains all available layouts.
    *args
        Positional arguments which are passed to the layout.
    **kwargs
        Keyword arguments which are passed to the layout.

    Returns
    -------
    layout : callable
        The callable generator which will calculate the graph layout
    """
    if name not in _layout_map:
        raise KeyError("Graph layout '%s' not found. Should be one of %s"
                       % (name, AVAILABLE_LAYOUTS))

    layout = _layout_map[name]

    if inspect.isclass(layout):
        layout = layout(*args, **kwargs)

    return layout