summaryrefslogtreecommitdiff
path: root/ero1/src/helper/color_suburbs.py
blob: 76689996edf9a97015cd2b3836acb3f6af3bcaa4 (plain)
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import osmnx as ox

colors = [
    "#e6194b",  # rouge vif     1
    "#3cb44b",  # vert vif      2
    "#ffe119",  # jaune         3
    "#4363d8",  # bleu          4 
    "#f58231",  # orange        5
    "#911eb4",  # violet        6
    "#46f0f0",  # cyan clair    7
    "#f032e6",  # rose          8
    "#bcf60c",  # vert citron   9
    "#fabebe",  # rose pâle     10
    "#008080",  # turquoise foncé 11
    "#e6beff",  # lavande       12
    "#9a6324",  # brun          13
    "#fffac8",  # crème         14
    "#800000",  # bordeaux      15
    "#aaffc3",  # vert menthe   16
    "#808000",  # olive         17
    "#ffd8b1",  # pêche         18
    "#000075",  # bleu marine   19
]


def display_suburbs_with_colors(G, path, connections=None):
    """
        Colorie chaque quartier d'une couleur différente
    Parameter:
        path (map<String, List<(int, int, data)>>: resultat du postier chinois,
        G (DiGraph): graph de montreal
    Result:
        void
    """

    associated_color = {}
    connection_color = "#FFFFFF"  # noir

    i = 0
    for suburb in path:
        for u, v in path[suburb]:
            if (v,u) in G.edges(keys=False):
                associated_color[(v, u)] = colors[i]
            associated_color[(u, v)] = colors[i]

        i += 1

    if connections:
        for _, _, conn_path in connections:
            if conn_path is None or len(conn_path) < 2:
                continue
            for i in range(len(conn_path) - 1):
                u, v = conn_path[i], conn_path[i + 1]
                if (v, u) in G.edges(keys=False):
                    associated_color[(v, u)] = connection_color
                associated_color[(u, v)] = connection_color

    count = 0
    edge_colors = []
    for u, v in G.edges(keys=False):
        if (u,v) in associated_color:
            edge_colors.append(associated_color[(u, v)])
            count += 1
        else:
            edge_colors.append("grey")

    # print(f"{count} arêtes colorées (quartiers + connexions)")

    fig, ax = ox.plot_graph(G, edge_color=edge_colors,
                            node_size=0, edge_linewidth=1)