d3graph 2.8.0__tar.gz → 2.8.2__tar.gz
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.
- {d3graph-2.8.0/d3graph.egg-info → d3graph-2.8.2}/PKG-INFO +1 -1
- {d3graph-2.8.0 → d3graph-2.8.2}/d3graph/__init__.py +1 -1
- {d3graph-2.8.0 → d3graph-2.8.2}/d3graph/d3graph.py +50 -13
- {d3graph-2.8.0 → d3graph-2.8.2}/d3graph/examples.py +25 -0
- {d3graph-2.8.0 → d3graph-2.8.2/d3graph.egg-info}/PKG-INFO +1 -1
- {d3graph-2.8.0 → d3graph-2.8.2}/LICENSE +0 -0
- {d3graph-2.8.0 → d3graph-2.8.2}/MANIFEST.in +0 -0
- {d3graph-2.8.0 → d3graph-2.8.2}/README.md +0 -0
- {d3graph-2.8.0 → d3graph-2.8.2}/d3graph/d3js/d3.v3.js +0 -0
- {d3graph-2.8.0 → d3graph-2.8.2}/d3graph/d3js/d3graphscript.js +0 -0
- {d3graph-2.8.0 → d3graph-2.8.2}/d3graph/d3js/index.html.j2 +0 -0
- {d3graph-2.8.0 → d3graph-2.8.2}/d3graph/d3js/style.css +0 -0
- {d3graph-2.8.0 → d3graph-2.8.2}/d3graph/examples_docs.py +0 -0
- {d3graph-2.8.0 → d3graph-2.8.2}/d3graph.egg-info/SOURCES.txt +0 -0
- {d3graph-2.8.0 → d3graph-2.8.2}/d3graph.egg-info/dependency_links.txt +0 -0
- {d3graph-2.8.0 → d3graph-2.8.2}/d3graph.egg-info/requires.txt +0 -0
- {d3graph-2.8.0 → d3graph-2.8.2}/d3graph.egg-info/top_level.txt +0 -0
- {d3graph-2.8.0 → d3graph-2.8.2}/pyproject.toml +0 -0
- {d3graph-2.8.0 → d3graph-2.8.2}/setup.cfg +0 -0
|
@@ -485,8 +485,10 @@ class d3graph:
|
|
|
485
485
|
node_names = self.adjmat.columns.astype(str)
|
|
486
486
|
nodecount = self.adjmat.shape[0]
|
|
487
487
|
group = np.zeros_like(node_names).astype(int)
|
|
488
|
+
|
|
488
489
|
# Check validity of color.
|
|
489
490
|
color = _check_hex_color(color, nodecount, cmap=cmap)
|
|
491
|
+
|
|
490
492
|
# Store in config
|
|
491
493
|
self.config['cmap'] = 'Paired' if cmap is None else cmap
|
|
492
494
|
self.config['node_scaler'] = scaler
|
|
@@ -1602,20 +1604,55 @@ def adjmat2vec(adjmat, min_weight: float = 1.0) -> pd.DataFrame:
|
|
|
1602
1604
|
return adjmat
|
|
1603
1605
|
|
|
1604
1606
|
|
|
1607
|
+
# def _check_hex_color(color, n=None, cmap='Set1'):
|
|
1608
|
+
# if isinstance(color, str) and len(color) != 7:
|
|
1609
|
+
# logger.warning('Input parameter [color] has wrong format. Must be like color="#000000" <auto-fixing>')
|
|
1610
|
+
# return get_hex_color(color, cmap=cmap)[0]
|
|
1611
|
+
# if isinstance(color, (list, np.ndarray, pd.Series, pd.Series, StringArray)) and len(color) == 0:
|
|
1612
|
+
# logger.warning('Input parameter [color] has wrong format and length. Must be like: color=["#000000", "...", "#000000"] <auto-fixing>')
|
|
1613
|
+
# return get_hex_color(color, cmap=cmap)[0]
|
|
1614
|
+
# if isinstance(color, (list, np.ndarray, pd.Series, pd.Series, StringArray)) and (not np.all(list(map(lambda x: len(x) == 7, color)))):
|
|
1615
|
+
# logger.warning('[color] contains incorrect hex-colors. Hex must be of length 7: ["#000000", "#000000", etc] <auto-fixing>')
|
|
1616
|
+
# return get_hex_color(color, cmap=cmap)[0]
|
|
1617
|
+
# if (n is not None) and isinstance(color, (list, np.ndarray, pd.Series, pd.Series, StringArray)) and len(color) != n:
|
|
1618
|
+
# logger.warning(f'Input parameter [color] has wrong length. Must be of length: {str(n)} <auto-fixing>')
|
|
1619
|
+
# return get_hex_color(color, cmap=cmap)[0]
|
|
1620
|
+
# # Return original input
|
|
1621
|
+
# return color
|
|
1622
|
+
|
|
1605
1623
|
def _check_hex_color(color, n=None, cmap='Set1'):
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
if isinstance(color,
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
#
|
|
1624
|
+
seq_types = (list, np.ndarray, pd.Series, StringArray)
|
|
1625
|
+
|
|
1626
|
+
if isinstance(color, str) and color=='cluster':
|
|
1627
|
+
return 'cluster'
|
|
1628
|
+
|
|
1629
|
+
# Single string
|
|
1630
|
+
if isinstance(color, str):
|
|
1631
|
+
if len(color) != 7 or not color.startswith('#'):
|
|
1632
|
+
logger.warning('1. Invalid [color] format. Expected "#000000" <auto-fixing>')
|
|
1633
|
+
return get_hex_color([color]*n, cmap=cmap)[0]
|
|
1634
|
+
return color
|
|
1635
|
+
|
|
1636
|
+
# Sequence input
|
|
1637
|
+
if isinstance(color, seq_types):
|
|
1638
|
+
|
|
1639
|
+
if len(color) == 0:
|
|
1640
|
+
logger.warning('2. Invalid [color] sequence. Expected ["#000000", ...] <auto-fixing>')
|
|
1641
|
+
return get_hex_color(color, cmap=cmap)[0]
|
|
1642
|
+
|
|
1643
|
+
valid = np.all([
|
|
1644
|
+
isinstance(x, str) and len(x) == 7 and x.startswith('#')
|
|
1645
|
+
for x in color
|
|
1646
|
+
])
|
|
1647
|
+
|
|
1648
|
+
if not valid:
|
|
1649
|
+
logger.warning('3. Invalid hex colors in [color]. Expected ["#000000", ...] <auto-fixing>')
|
|
1650
|
+
return get_hex_color(color, cmap=cmap)[0]
|
|
1651
|
+
|
|
1652
|
+
if (n is not None) and (len(color) != n):
|
|
1653
|
+
logger.warning(f'4. Invalid [color] length. Expected length={n} <auto-fixing>')
|
|
1654
|
+
return get_hex_color(color, cmap=cmap)[0]
|
|
1655
|
+
|
|
1619
1656
|
return color
|
|
1620
1657
|
|
|
1621
1658
|
|
|
@@ -1,3 +1,28 @@
|
|
|
1
|
+
# %% SET PATH ISSUE https://github.com/erdogant/d3graph/issues/42
|
|
2
|
+
from pathlib import Path
|
|
3
|
+
from d3graph import d3graph, vec2adjmat, import_example
|
|
4
|
+
output_path = Path.cwd() / 'd3graph.html'
|
|
5
|
+
|
|
6
|
+
# Load example data
|
|
7
|
+
df = import_example('stormofswords')
|
|
8
|
+
adjmat = vec2adjmat(source=df['source'], target=df['target'], weight=df['weight'])
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
# sticky=True (default) — drag to pin, right-click to release
|
|
12
|
+
d3 = d3graph(sticky=True)
|
|
13
|
+
d3.set_path(output_path)
|
|
14
|
+
d3.config['filepath']
|
|
15
|
+
|
|
16
|
+
d3.graph(adjmat)
|
|
17
|
+
d3.show()
|
|
18
|
+
|
|
19
|
+
# sticky=False — classic spring-back behaviour
|
|
20
|
+
d3 = d3graph(adjmat, sticky=False)
|
|
21
|
+
d3.show()
|
|
22
|
+
|
|
23
|
+
# %%
|
|
24
|
+
|
|
25
|
+
|
|
1
26
|
from d3graph import d3graph, import_example, vec2adjmat
|
|
2
27
|
|
|
3
28
|
d3 = d3graph()
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|