iplotx 0.3.0__py3-none-any.whl → 0.4.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,49 +4,15 @@ from typing import (
4
4
  Sequence,
5
5
  )
6
6
  from collections.abc import Hashable
7
- import copy
8
7
  from contextlib import contextmanager
9
8
  import numpy as np
10
9
  import pandas as pd
11
10
 
12
-
13
- style_leaves = (
14
- "cmap",
15
- "color",
16
- "size",
17
- "edgecolor",
18
- "facecolor",
19
- "linewidth",
20
- "linestyle",
21
- "alpha",
22
- "zorder",
23
- "tension",
24
- "looptension",
25
- "loopmaxangle",
26
- "paralleloffset",
27
- "offset",
28
- "rotate",
29
- "marker",
30
- "waypoints",
31
- "horizontalalignment",
32
- "verticalalignment",
33
- "boxstyle",
34
- "hpadding",
35
- "vpadding",
36
- "hmargin",
37
- "vmargin",
38
- "ports",
39
- "extend",
40
- )
41
-
42
- # These properties are not allowed to be rotated (global throughout the graph).
43
- # This might change in the future as the API improves.
44
- nonrotating_leaves = (
45
- "paralleloffset",
46
- "looptension",
47
- "loopmaxangle",
48
- "vertexpadding",
49
- "extend",
11
+ from ..utils.style import copy_with_deep_values
12
+ from .library import style_library
13
+ from .leaf_info import (
14
+ style_leaves,
15
+ nonrotating_leaves,
50
16
  )
51
17
 
52
18
 
@@ -68,10 +34,10 @@ default = {
68
34
  "linestyle": "-",
69
35
  "color": "black",
70
36
  "curved": False,
71
- "paralleloffset": 3,
72
37
  "tension": 1,
73
38
  "looptension": 4,
74
39
  "loopmaxangle": 60,
40
+ "paralleloffset": 3,
75
41
  "label": {
76
42
  "horizontalalignment": "center",
77
43
  "verticalalignment": "center",
@@ -97,59 +63,14 @@ default = {
97
63
  }
98
64
 
99
65
 
100
- def copy_with_deep_values(style):
101
- """Make a deep copy of the style dict but do not create copies of the keys."""
102
- newdict = {}
103
- for key, value in style.items():
104
- if isinstance(value, dict):
105
- newdict[key] = copy_with_deep_values(value)
106
- else:
107
- newdict[key] = copy.copy(value)
108
- return newdict
109
-
110
-
111
- hollow = copy_with_deep_values(default)
112
- hollow["vertex"]["color"] = None
113
- hollow["vertex"]["facecolor"] = "none"
114
- hollow["vertex"]["edgecolor"] = "black"
115
- hollow["vertex"]["linewidth"] = 1.5
116
- hollow["vertex"]["marker"] = "r"
117
- hollow["vertex"]["size"] = "label"
118
- hollow["vertex"]["label"]["color"] = "black"
119
-
120
- tree = copy_with_deep_values(default)
121
- tree["vertex"]["size"] = 0
122
- tree["vertex"]["alpha"] = 0
123
- tree["edge"]["linewidth"] = 2.5
124
- tree["vertex"]["label"]["bbox"] = {
125
- "boxstyle": "square,pad=0.5",
126
- "facecolor": "white",
127
- "edgecolor": "none",
128
- }
129
- tree["vertex"]["label"]["color"] = "black"
130
- tree["vertex"]["label"]["size"] = 12
131
- tree["vertex"]["label"]["verticalalignment"] = "center"
132
- tree["vertex"]["label"]["hmargin"] = 10
133
-
134
-
135
66
  styles = {
136
67
  "default": default,
137
- "hollow": hollow,
138
- "tree": tree,
139
68
  }
140
69
 
141
70
 
142
- stylename = "default"
143
-
144
-
145
71
  current = copy_with_deep_values(styles["default"])
146
72
 
147
73
 
148
- def get_stylename():
149
- """Return the name of the current iplotx style."""
150
- return str(stylename)
151
-
152
-
153
74
  def get_style(name: str = "", *args) -> dict[str, Any]:
154
75
  """Get a *deep copy* of the chosen style.
155
76
 
@@ -403,3 +324,20 @@ def rotate_style(
403
324
  style[prop] = valtype()
404
325
 
405
326
  return style
327
+
328
+
329
+ def add_style(name: str, style: dict[str, Any]) -> None:
330
+ """Add a style to the default dictionary of styles.
331
+
332
+ Parameters:
333
+ name: The name of the style to add.
334
+ style: A dictionary with the style properties to add.
335
+ """
336
+ with context(["default", style]):
337
+ styles[name] = get_style()
338
+
339
+
340
+ # Populate style library
341
+ for name, style in style_library.items():
342
+ add_style(name, style)
343
+ del name, style
@@ -0,0 +1,41 @@
1
+ # These properties are at the bottom of a style dictionary. Values corresponding
2
+ # to these keys are rotatable.
3
+ rotating_leaves = (
4
+ "cmap",
5
+ "color",
6
+ "size",
7
+ "edgecolor",
8
+ "facecolor",
9
+ "linewidth",
10
+ "linestyle",
11
+ "alpha",
12
+ "zorder",
13
+ "tension",
14
+ "offset",
15
+ "rotate",
16
+ "marker",
17
+ "waypoints",
18
+ "horizontalalignment",
19
+ "verticalalignment",
20
+ "boxstyle",
21
+ "hpadding",
22
+ "vpadding",
23
+ "hmargin",
24
+ "vmargin",
25
+ "ports",
26
+ )
27
+
28
+ # These properties are also terminal style properties, but they cannot be rotated.
29
+ # This might change in the future as the API improves.
30
+ nonrotating_leaves = (
31
+ "paralleloffset",
32
+ "looptension",
33
+ "loopmaxangle",
34
+ "vertexpadding",
35
+ "extend",
36
+ "deep",
37
+ "angular",
38
+ )
39
+
40
+ # Union of all style leaves (rotating and nonrotating)
41
+ style_leaves = tuple(list(rotating_leaves) + list(nonrotating_leaves))
@@ -0,0 +1,230 @@
1
+ style_library = {
2
+ # Hollow style for organization charts et similar
3
+ "hollow": {
4
+ "vertex": {
5
+ "color": None,
6
+ "facecolor": "none",
7
+ "edgecolor": "black",
8
+ "linewidth": 1.5,
9
+ "marker": "r",
10
+ "size": "label",
11
+ "label": {
12
+ "color": "black",
13
+ },
14
+ }
15
+ },
16
+ # Tree style, with zero-size vertices
17
+ "tree": {
18
+ "vertex": {
19
+ "size": 0,
20
+ "label": {
21
+ "color": "black",
22
+ "size": 12,
23
+ "verticalalignment": "center",
24
+ "hmargin": 10,
25
+ "bbox": {
26
+ "boxstyle": "square,pad=0.5",
27
+ "facecolor": "none",
28
+ "edgecolor": "none",
29
+ },
30
+ },
31
+ },
32
+ "edge": {
33
+ "linewidth": 2.5,
34
+ },
35
+ },
36
+ # Cogent3 tree style
37
+ "cogent3": {
38
+ "vertex": {
39
+ "size": 3,
40
+ "label": {
41
+ "color": "black",
42
+ "size": 10,
43
+ "verticalalignment": "center",
44
+ "bbox": {
45
+ "facecolor": "none",
46
+ "edgecolor": "none",
47
+ },
48
+ },
49
+ },
50
+ "edge": {
51
+ "linewidth": 1.5,
52
+ },
53
+ "leaf": {
54
+ "deep": False,
55
+ },
56
+ },
57
+ # Greyscale style
58
+ "greyscale": {
59
+ "vertex": {
60
+ "color": None,
61
+ "facecolor": "lightgrey",
62
+ "edgecolor": "#111",
63
+ "marker": ">",
64
+ "size": 15,
65
+ "linewidth": 0.75,
66
+ "label": {
67
+ "color": "black",
68
+ },
69
+ },
70
+ "edge": {
71
+ "color": "#111",
72
+ "linewidth": 0.75,
73
+ "arrow": {
74
+ "marker": ">",
75
+ },
76
+ "label": {
77
+ "rotate": True,
78
+ "color": "black",
79
+ },
80
+ },
81
+ },
82
+ # Edge highlight
83
+ "rededge": {
84
+ "vertex": {
85
+ "size": 13,
86
+ "color": None,
87
+ "facecolor": "none",
88
+ "edgecolor": "#111",
89
+ "linewidth": 2,
90
+ "label": {
91
+ "color": "#111",
92
+ },
93
+ },
94
+ "edge": {
95
+ "color": "tomato",
96
+ "linewidth": 2.5,
97
+ },
98
+ },
99
+ # Vertex highlight
100
+ "rednode": {
101
+ "vertex": {
102
+ "size": 22,
103
+ "color": None,
104
+ "facecolor": "tomato",
105
+ "edgecolor": "firebrick",
106
+ "linewidth": 2,
107
+ },
108
+ "edge": {
109
+ "color": "#333",
110
+ "linewidth": 1,
111
+ },
112
+ },
113
+ # Eerie style
114
+ "eerie": {
115
+ "vertex": {
116
+ "color": None,
117
+ "facecolor": "white",
118
+ "edgecolor": "#111",
119
+ "linestyle": "--",
120
+ "linewidth": 2,
121
+ },
122
+ "edge": {
123
+ "color": "#111",
124
+ "linestyle": "--",
125
+ "linewidth": 2,
126
+ "arrow": {
127
+ "marker": ")",
128
+ },
129
+ },
130
+ },
131
+ # Emulate a little networkx
132
+ "networkx": {
133
+ "vertex": {
134
+ "color": None,
135
+ "facecolor": "steelblue",
136
+ "edgecolor": "none",
137
+ "label": {
138
+ "color": "black",
139
+ },
140
+ },
141
+ "edge": {
142
+ "color": "black",
143
+ "linewidth": 1.5,
144
+ "arrow": {
145
+ "width": 5,
146
+ },
147
+ },
148
+ },
149
+ "igraph": {
150
+ "vertex": {
151
+ "color": None,
152
+ "facecolor": "lightblue",
153
+ "edgecolor": "black",
154
+ "linewidth": 2,
155
+ "label": {
156
+ "color": "black",
157
+ },
158
+ },
159
+ "edge": {
160
+ "color": "black",
161
+ "linewidth": 2,
162
+ "arrow": {
163
+ "marker": "|>",
164
+ "width": 6.5,
165
+ },
166
+ },
167
+ },
168
+ # Colorful style for general use
169
+ "unicorn": {
170
+ "vertex": {
171
+ "size": 23,
172
+ "color": None,
173
+ "facecolor": [
174
+ "darkorchid",
175
+ "slateblue",
176
+ "seagreen",
177
+ "lime",
178
+ "gold",
179
+ "orange",
180
+ "sandybrown",
181
+ "tomato",
182
+ "deeppink",
183
+ ],
184
+ "edgecolor": "black",
185
+ "linewidth": 1,
186
+ "marker": "*",
187
+ "label": {
188
+ "color": [
189
+ "white",
190
+ "white",
191
+ "white",
192
+ "black",
193
+ "black",
194
+ "black",
195
+ "black",
196
+ "white",
197
+ "white",
198
+ ],
199
+ },
200
+ },
201
+ "edge": {
202
+ "color": [
203
+ "darkorchid",
204
+ "slateblue",
205
+ "seagreen",
206
+ "lime",
207
+ "gold",
208
+ "orange",
209
+ "sandybrown",
210
+ "tomato",
211
+ "deeppink",
212
+ ],
213
+ "linewidth": 1.5,
214
+ "label": {
215
+ "rotate": False,
216
+ "color": [
217
+ "white",
218
+ "white",
219
+ "white",
220
+ "black",
221
+ "black",
222
+ "black",
223
+ "black",
224
+ "white",
225
+ "white",
226
+ ],
227
+ },
228
+ },
229
+ },
230
+ }