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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: d3graph
3
- Version: 2.8.0
3
+ Version: 2.8.2
4
4
  Summary: Python package to create interactive network based on d3js.
5
5
  Author-email: Erdogan Taskesen <erdogant@gmail.com>
6
6
  License-Expression: BSD-3-Clause
@@ -17,7 +17,7 @@ from d3graph.d3graph import (
17
17
 
18
18
  __author__ = 'Erdogan Tasksen'
19
19
  __email__ = 'erdogant@gmail.com'
20
- __version__ = '2.8.0'
20
+ __version__ = '2.8.2'
21
21
 
22
22
  # Setup root logger
23
23
  _logger = logging.getLogger('d3graph')
@@ -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
- if isinstance(color, str) and len(color) != 7:
1607
- logger.warning('Input parameter [color] has wrong format. Must be like color="#000000" <auto-fixing>')
1608
- return get_hex_color(color, cmap=cmap)[0]
1609
- if isinstance(color, (list, np.ndarray, pd.Series, pd.Series, StringArray)) and len(color) == 0:
1610
- logger.warning('Input parameter [color] has wrong format and length. Must be like: color=["#000000", "...", "#000000"] <auto-fixing>')
1611
- return get_hex_color(color, cmap=cmap)[0]
1612
- if isinstance(color, (list, np.ndarray, pd.Series, pd.Series, StringArray)) and (not np.all(list(map(lambda x: len(x) == 7, color)))):
1613
- logger.warning('[color] contains incorrect hex-colors. Hex must be of length 7: ["#000000", "#000000", etc] <auto-fixing>')
1614
- return get_hex_color(color, cmap=cmap)[0]
1615
- if (n is not None) and isinstance(color, (list, np.ndarray, pd.Series, pd.Series, StringArray)) and len(color) != n:
1616
- logger.warning(f'Input parameter [color] has wrong length. Must be of length: {str(n)} <auto-fixing>')
1617
- return get_hex_color(color, cmap=cmap)[0]
1618
- # Return original input
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()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: d3graph
3
- Version: 2.8.0
3
+ Version: 2.8.2
4
4
  Summary: Python package to create interactive network based on d3js.
5
5
  Author-email: Erdogan Taskesen <erdogant@gmail.com>
6
6
  License-Expression: BSD-3-Clause
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes