conceptflow 0.6.1__tar.gz → 0.6.3__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.
Files changed (164) hide show
  1. {conceptflow-0.6.1/src/conceptflow.egg-info → conceptflow-0.6.3}/PKG-INFO +3 -1
  2. {conceptflow-0.6.1 → conceptflow-0.6.3}/pyproject.toml +5 -0
  3. conceptflow-0.6.3/src/conceptflow/_version.py +1 -0
  4. {conceptflow-0.6.1 → conceptflow-0.6.3}/src/conceptflow/core/context.py +14 -2
  5. {conceptflow-0.6.1 → conceptflow-0.6.3}/src/conceptflow/io/formats.py +22 -1
  6. {conceptflow-0.6.1 → conceptflow-0.6.3}/src/conceptflow/metrics/drawing_quality.py +34 -21
  7. {conceptflow-0.6.1 → conceptflow-0.6.3}/src/conceptflow/validation/input.py +22 -14
  8. conceptflow-0.6.3/src/conceptflow/visualization/_checks.py +168 -0
  9. {conceptflow-0.6.1 → conceptflow-0.6.3}/src/conceptflow/visualization/d3_backend.py +106 -26
  10. {conceptflow-0.6.1 → conceptflow-0.6.3}/src/conceptflow/visualization/dimflux_layout.py +2 -2
  11. {conceptflow-0.6.1 → conceptflow-0.6.3}/src/conceptflow/visualization/html_figure.py +7 -2
  12. {conceptflow-0.6.1 → conceptflow-0.6.3}/src/conceptflow/visualization/lattice_plot.py +12 -5
  13. {conceptflow-0.6.1 → conceptflow-0.6.3}/src/conceptflow/visualization/nested.py +159 -50
  14. {conceptflow-0.6.1 → conceptflow-0.6.3/src/conceptflow.egg-info}/PKG-INFO +3 -1
  15. {conceptflow-0.6.1 → conceptflow-0.6.3}/src/conceptflow.egg-info/SOURCES.txt +11 -0
  16. {conceptflow-0.6.1 → conceptflow-0.6.3}/src/conceptflow.egg-info/requires.txt +2 -0
  17. conceptflow-0.6.3/tests/test_backend_consistency.py +270 -0
  18. {conceptflow-0.6.1 → conceptflow-0.6.3}/tests/test_browser.py +291 -0
  19. {conceptflow-0.6.1 → conceptflow-0.6.3}/tests/test_context_handling.py +17 -0
  20. conceptflow-0.6.3/tests/test_cross_library.py +345 -0
  21. {conceptflow-0.6.1 → conceptflow-0.6.3}/tests/test_d3_backend.py +17 -6
  22. {conceptflow-0.6.1 → conceptflow-0.6.3}/tests/test_dimflux_layout.py +16 -0
  23. {conceptflow-0.6.1 → conceptflow-0.6.3}/tests/test_drawing_quality.py +93 -3
  24. conceptflow-0.6.3/tests/test_feature_matrix.py +414 -0
  25. {conceptflow-0.6.1 → conceptflow-0.6.3}/tests/test_html_figure.py +7 -0
  26. conceptflow-0.6.3/tests/test_properties_core.py +934 -0
  27. conceptflow-0.6.3/tests/test_properties_drawing.py +130 -0
  28. conceptflow-0.6.3/tests/test_properties_estimators.py +180 -0
  29. conceptflow-0.6.3/tests/test_properties_input.py +228 -0
  30. conceptflow-0.6.3/tests/test_properties_io_nested.py +370 -0
  31. conceptflow-0.6.3/tests/test_properties_scaling.py +244 -0
  32. conceptflow-0.6.3/tests/test_reproducibility.py +244 -0
  33. conceptflow-0.6.3/tests/test_sklearn_workflows.py +210 -0
  34. {conceptflow-0.6.1 → conceptflow-0.6.3}/tests/test_validation_input.py +37 -0
  35. {conceptflow-0.6.1 → conceptflow-0.6.3}/tests/test_visualization_options.py +63 -6
  36. conceptflow-0.6.1/src/conceptflow/_version.py +0 -1
  37. conceptflow-0.6.1/src/conceptflow/visualization/_checks.py +0 -44
  38. {conceptflow-0.6.1 → conceptflow-0.6.3}/LICENSE +0 -0
  39. {conceptflow-0.6.1 → conceptflow-0.6.3}/README.md +0 -0
  40. {conceptflow-0.6.1 → conceptflow-0.6.3}/setup.cfg +0 -0
  41. {conceptflow-0.6.1 → conceptflow-0.6.3}/src/conceptflow/__init__.py +0 -0
  42. {conceptflow-0.6.1 → conceptflow-0.6.3}/src/conceptflow/_deprecation.py +0 -0
  43. {conceptflow-0.6.1 → conceptflow-0.6.3}/src/conceptflow/algorithms/__init__.py +0 -0
  44. {conceptflow-0.6.1 → conceptflow-0.6.3}/src/conceptflow/algorithms/_bitset.py +0 -0
  45. {conceptflow-0.6.1 → conceptflow-0.6.3}/src/conceptflow/algorithms/_membership.py +0 -0
  46. {conceptflow-0.6.1 → conceptflow-0.6.3}/src/conceptflow/algorithms/_registry.py +0 -0
  47. {conceptflow-0.6.1 → conceptflow-0.6.3}/src/conceptflow/algorithms/derivation.py +0 -0
  48. {conceptflow-0.6.1 → conceptflow-0.6.3}/src/conceptflow/algorithms/enumeration.py +0 -0
  49. {conceptflow-0.6.1 → conceptflow-0.6.3}/src/conceptflow/algorithms/generators.py +0 -0
  50. {conceptflow-0.6.1 → conceptflow-0.6.3}/src/conceptflow/algorithms/hasse.py +0 -0
  51. {conceptflow-0.6.1 → conceptflow-0.6.3}/src/conceptflow/algorithms/implications.py +0 -0
  52. {conceptflow-0.6.1 → conceptflow-0.6.3}/src/conceptflow/algorithms/order.py +0 -0
  53. {conceptflow-0.6.1 → conceptflow-0.6.3}/src/conceptflow/algorithms/reduction.py +0 -0
  54. {conceptflow-0.6.1 → conceptflow-0.6.3}/src/conceptflow/cluster/__init__.py +0 -0
  55. {conceptflow-0.6.1 → conceptflow-0.6.3}/src/conceptflow/cluster/concept_lattice.py +0 -0
  56. {conceptflow-0.6.1 → conceptflow-0.6.3}/src/conceptflow/core/__init__.py +0 -0
  57. {conceptflow-0.6.1 → conceptflow-0.6.3}/src/conceptflow/core/concept.py +0 -0
  58. {conceptflow-0.6.1 → conceptflow-0.6.3}/src/conceptflow/core/incomplete_context.py +0 -0
  59. {conceptflow-0.6.1 → conceptflow-0.6.3}/src/conceptflow/core/lattice.py +0 -0
  60. {conceptflow-0.6.1 → conceptflow-0.6.3}/src/conceptflow/core/many_valued_context.py +0 -0
  61. {conceptflow-0.6.1 → conceptflow-0.6.3}/src/conceptflow/core/operations.py +0 -0
  62. {conceptflow-0.6.1 → conceptflow-0.6.3}/src/conceptflow/core/scale_measures.py +0 -0
  63. {conceptflow-0.6.1 → conceptflow-0.6.3}/src/conceptflow/datasets/__init__.py +0 -0
  64. {conceptflow-0.6.1 → conceptflow-0.6.3}/src/conceptflow/datasets/_loaders.py +0 -0
  65. {conceptflow-0.6.1 → conceptflow-0.6.3}/src/conceptflow/datasets/data/fca_repository/README.md +0 -0
  66. {conceptflow-0.6.1 → conceptflow-0.6.3}/src/conceptflow/datasets/data/fca_repository/animals_en.cxt +0 -0
  67. {conceptflow-0.6.1 → conceptflow-0.6.3}/src/conceptflow/datasets/data/fca_repository/binary_relations_en.cxt +0 -0
  68. {conceptflow-0.6.1 → conceptflow-0.6.3}/src/conceptflow/datasets/data/fca_repository/bodiesofwater_de.cxt +0 -0
  69. {conceptflow-0.6.1 → conceptflow-0.6.3}/src/conceptflow/datasets/data/fca_repository/bodiesofwater_en.cxt +0 -0
  70. {conceptflow-0.6.1 → conceptflow-0.6.3}/src/conceptflow/datasets/data/fca_repository/driveconcepts_de.cxt +0 -0
  71. {conceptflow-0.6.1 → conceptflow-0.6.3}/src/conceptflow/datasets/data/fca_repository/driveconcepts_en.cxt +0 -0
  72. {conceptflow-0.6.1 → conceptflow-0.6.3}/src/conceptflow/datasets/data/fca_repository/famous_animals_en.cxt +0 -0
  73. {conceptflow-0.6.1 → conceptflow-0.6.3}/src/conceptflow/datasets/data/fca_repository/forum_romanum_en.cxt +0 -0
  74. {conceptflow-0.6.1 → conceptflow-0.6.3}/src/conceptflow/datasets/data/fca_repository/livingbeings_de.cxt +0 -0
  75. {conceptflow-0.6.1 → conceptflow-0.6.3}/src/conceptflow/datasets/data/fca_repository/livingbeings_en.cxt +0 -0
  76. {conceptflow-0.6.1 → conceptflow-0.6.3}/src/conceptflow/datasets/data/fca_repository/missmarple_de.cxt +0 -0
  77. {conceptflow-0.6.1 → conceptflow-0.6.3}/src/conceptflow/datasets/data/fca_repository/missmarple_en.cxt +0 -0
  78. {conceptflow-0.6.1 → conceptflow-0.6.3}/src/conceptflow/datasets/data/fca_repository/music_en.cxt +0 -0
  79. {conceptflow-0.6.1 → conceptflow-0.6.3}/src/conceptflow/datasets/data/fca_repository/newzealand_en.cxt +0 -0
  80. {conceptflow-0.6.1 → conceptflow-0.6.3}/src/conceptflow/datasets/data/fca_repository/officesupplies_de.cxt +0 -0
  81. {conceptflow-0.6.1 → conceptflow-0.6.3}/src/conceptflow/datasets/data/fca_repository/officesupplies_en.cxt +0 -0
  82. {conceptflow-0.6.1 → conceptflow-0.6.3}/src/conceptflow/datasets/data/fca_repository/planets_en.cxt +0 -0
  83. {conceptflow-0.6.1 → conceptflow-0.6.3}/src/conceptflow/datasets/data/fca_repository/seasoningplanner_de.cxt +0 -0
  84. {conceptflow-0.6.1 → conceptflow-0.6.3}/src/conceptflow/datasets/data/fca_repository/tealady.cxt +0 -0
  85. {conceptflow-0.6.1 → conceptflow-0.6.3}/src/conceptflow/datasets/data/fca_repository/triangles_en.cxt +0 -0
  86. {conceptflow-0.6.1 → conceptflow-0.6.3}/src/conceptflow/datasets/data/fca_repository.json +0 -0
  87. {conceptflow-0.6.1 → conceptflow-0.6.3}/src/conceptflow/decomposition/__init__.py +0 -0
  88. {conceptflow-0.6.1 → conceptflow-0.6.3}/src/conceptflow/decomposition/bipartite.py +0 -0
  89. {conceptflow-0.6.1 → conceptflow-0.6.3}/src/conceptflow/decomposition/boolean_factorization.py +0 -0
  90. {conceptflow-0.6.1 → conceptflow-0.6.3}/src/conceptflow/decomposition/ordinal_factorization.py +0 -0
  91. {conceptflow-0.6.1 → conceptflow-0.6.3}/src/conceptflow/exploration/__init__.py +0 -0
  92. {conceptflow-0.6.1 → conceptflow-0.6.3}/src/conceptflow/exploration/builder.py +0 -0
  93. {conceptflow-0.6.1 → conceptflow-0.6.3}/src/conceptflow/exploration/combinations.py +0 -0
  94. {conceptflow-0.6.1 → conceptflow-0.6.3}/src/conceptflow/exploration/view.py +0 -0
  95. {conceptflow-0.6.1 → conceptflow-0.6.3}/src/conceptflow/feature_extraction/__init__.py +0 -0
  96. {conceptflow-0.6.1 → conceptflow-0.6.3}/src/conceptflow/feature_extraction/concept_encoder.py +0 -0
  97. {conceptflow-0.6.1 → conceptflow-0.6.3}/src/conceptflow/io/__init__.py +0 -0
  98. {conceptflow-0.6.1 → conceptflow-0.6.3}/src/conceptflow/io/cxt.py +0 -0
  99. {conceptflow-0.6.1 → conceptflow-0.6.3}/src/conceptflow/metrics/__init__.py +0 -0
  100. {conceptflow-0.6.1 → conceptflow-0.6.3}/src/conceptflow/metrics/measures.py +0 -0
  101. {conceptflow-0.6.1 → conceptflow-0.6.3}/src/conceptflow/metrics/rules.py +0 -0
  102. {conceptflow-0.6.1 → conceptflow-0.6.3}/src/conceptflow/preprocessing/__init__.py +0 -0
  103. {conceptflow-0.6.1 → conceptflow-0.6.3}/src/conceptflow/preprocessing/conceptual_scaler.py +0 -0
  104. {conceptflow-0.6.1 → conceptflow-0.6.3}/src/conceptflow/preprocessing/scales.py +0 -0
  105. {conceptflow-0.6.1 → conceptflow-0.6.3}/src/conceptflow/quality.py +0 -0
  106. {conceptflow-0.6.1 → conceptflow-0.6.3}/src/conceptflow/rules/__init__.py +0 -0
  107. {conceptflow-0.6.1 → conceptflow-0.6.3}/src/conceptflow/rules/implication_basis.py +0 -0
  108. {conceptflow-0.6.1 → conceptflow-0.6.3}/src/conceptflow/rules/outlier_detector.py +0 -0
  109. {conceptflow-0.6.1 → conceptflow-0.6.3}/src/conceptflow/validation/__init__.py +0 -0
  110. {conceptflow-0.6.1 → conceptflow-0.6.3}/src/conceptflow/visualization/__init__.py +0 -0
  111. {conceptflow-0.6.1 → conceptflow-0.6.3}/src/conceptflow/visualization/_clearance.py +0 -0
  112. {conceptflow-0.6.1 → conceptflow-0.6.3}/src/conceptflow/visualization/_text.py +0 -0
  113. {conceptflow-0.6.1 → conceptflow-0.6.3}/src/conceptflow/visualization/graph_data.py +0 -0
  114. {conceptflow-0.6.1 → conceptflow-0.6.3}/src/conceptflow/visualization/graphviz.py +0 -0
  115. {conceptflow-0.6.1 → conceptflow-0.6.3}/src/conceptflow/visualization/layered_layout.py +0 -0
  116. {conceptflow-0.6.1 → conceptflow-0.6.3}/src/conceptflow/visualization/static.py +0 -0
  117. {conceptflow-0.6.1 → conceptflow-0.6.3}/src/conceptflow/visualization/tikz.py +0 -0
  118. {conceptflow-0.6.1 → conceptflow-0.6.3}/src/conceptflow.egg-info/dependency_links.txt +0 -0
  119. {conceptflow-0.6.1 → conceptflow-0.6.3}/src/conceptflow.egg-info/top_level.txt +0 -0
  120. {conceptflow-0.6.1 → conceptflow-0.6.3}/tests/test_algorithm_registry.py +0 -0
  121. {conceptflow-0.6.1 → conceptflow-0.6.3}/tests/test_audit_regressions.py +0 -0
  122. {conceptflow-0.6.1 → conceptflow-0.6.3}/tests/test_boolean_factorization.py +0 -0
  123. {conceptflow-0.6.1 → conceptflow-0.6.3}/tests/test_check_estimator.py +0 -0
  124. {conceptflow-0.6.1 → conceptflow-0.6.3}/tests/test_cluster_estimator.py +0 -0
  125. {conceptflow-0.6.1 → conceptflow-0.6.3}/tests/test_concept.py +0 -0
  126. {conceptflow-0.6.1 → conceptflow-0.6.3}/tests/test_concept_encoder.py +0 -0
  127. {conceptflow-0.6.1 → conceptflow-0.6.3}/tests/test_conceptual_scaler.py +0 -0
  128. {conceptflow-0.6.1 → conceptflow-0.6.3}/tests/test_context_operations.py +0 -0
  129. {conceptflow-0.6.1 → conceptflow-0.6.3}/tests/test_cxt_io.py +0 -0
  130. {conceptflow-0.6.1 → conceptflow-0.6.3}/tests/test_datasets.py +0 -0
  131. {conceptflow-0.6.1 → conceptflow-0.6.3}/tests/test_derivation.py +0 -0
  132. {conceptflow-0.6.1 → conceptflow-0.6.3}/tests/test_docs_examples.py +0 -0
  133. {conceptflow-0.6.1 → conceptflow-0.6.3}/tests/test_enumeration.py +0 -0
  134. {conceptflow-0.6.1 → conceptflow-0.6.3}/tests/test_exploration.py +0 -0
  135. {conceptflow-0.6.1 → conceptflow-0.6.3}/tests/test_formal_context.py +0 -0
  136. {conceptflow-0.6.1 → conceptflow-0.6.3}/tests/test_generators.py +0 -0
  137. {conceptflow-0.6.1 → conceptflow-0.6.3}/tests/test_graph_data.py +0 -0
  138. {conceptflow-0.6.1 → conceptflow-0.6.3}/tests/test_hasse.py +0 -0
  139. {conceptflow-0.6.1 → conceptflow-0.6.3}/tests/test_implication_basis_estimator.py +0 -0
  140. {conceptflow-0.6.1 → conceptflow-0.6.3}/tests/test_implications.py +0 -0
  141. {conceptflow-0.6.1 → conceptflow-0.6.3}/tests/test_incomplete_context.py +0 -0
  142. {conceptflow-0.6.1 → conceptflow-0.6.3}/tests/test_lattice.py +0 -0
  143. {conceptflow-0.6.1 → conceptflow-0.6.3}/tests/test_lattice_navigation.py +0 -0
  144. {conceptflow-0.6.1 → conceptflow-0.6.3}/tests/test_layout_and_graphviz.py +0 -0
  145. {conceptflow-0.6.1 → conceptflow-0.6.3}/tests/test_many_valued_context.py +0 -0
  146. {conceptflow-0.6.1 → conceptflow-0.6.3}/tests/test_measures.py +0 -0
  147. {conceptflow-0.6.1 → conceptflow-0.6.3}/tests/test_metrics.py +0 -0
  148. {conceptflow-0.6.1 → conceptflow-0.6.3}/tests/test_nested_combinations.py +0 -0
  149. {conceptflow-0.6.1 → conceptflow-0.6.3}/tests/test_nested_levels.py +0 -0
  150. {conceptflow-0.6.1 → conceptflow-0.6.3}/tests/test_nested_visualization.py +0 -0
  151. {conceptflow-0.6.1 → conceptflow-0.6.3}/tests/test_oracles.py +0 -0
  152. {conceptflow-0.6.1 → conceptflow-0.6.3}/tests/test_ord2factor.py +0 -0
  153. {conceptflow-0.6.1 → conceptflow-0.6.3}/tests/test_ordinal_factorization.py +0 -0
  154. {conceptflow-0.6.1 → conceptflow-0.6.3}/tests/test_patch_0_3_1.py +0 -0
  155. {conceptflow-0.6.1 → conceptflow-0.6.3}/tests/test_public_api.py +0 -0
  156. {conceptflow-0.6.1 → conceptflow-0.6.3}/tests/test_quality.py +0 -0
  157. {conceptflow-0.6.1 → conceptflow-0.6.3}/tests/test_reduction.py +0 -0
  158. {conceptflow-0.6.1 → conceptflow-0.6.3}/tests/test_review_fixes.py +0 -0
  159. {conceptflow-0.6.1 → conceptflow-0.6.3}/tests/test_scale_measures.py +0 -0
  160. {conceptflow-0.6.1 → conceptflow-0.6.3}/tests/test_scales.py +0 -0
  161. {conceptflow-0.6.1 → conceptflow-0.6.3}/tests/test_sklearn_compatibility.py +0 -0
  162. {conceptflow-0.6.1 → conceptflow-0.6.3}/tests/test_static_figures.py +0 -0
  163. {conceptflow-0.6.1 → conceptflow-0.6.3}/tests/test_tikz.py +0 -0
  164. {conceptflow-0.6.1 → conceptflow-0.6.3}/tests/test_workflows.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: conceptflow
3
- Version: 0.6.1
3
+ Version: 0.6.3
4
4
  Summary: A scikit-learn compatible Formal Concept Analysis framework.
5
5
  Author-email: Anurag Sharma <sharma@cs.uni-kassel.de>
6
6
  License-Expression: BSD-3-Clause
@@ -35,6 +35,8 @@ Provides-Extra: dev
35
35
  Requires-Dist: scikit-learn>=1.6; extra == "dev"
36
36
  Requires-Dist: pytest; extra == "dev"
37
37
  Requires-Dist: pytest-cov; extra == "dev"
38
+ Requires-Dist: hypothesis; extra == "dev"
39
+ Requires-Dist: concepts; extra == "dev"
38
40
  Requires-Dist: ruff; extra == "dev"
39
41
  Dynamic: license-file
40
42
 
@@ -54,6 +54,11 @@ dev = [
54
54
  "scikit-learn>=1.6",
55
55
  "pytest",
56
56
  "pytest-cov",
57
+ # Property-based tests (tests/test_properties_*.py).
58
+ "hypothesis",
59
+ # Results compared with another FCA library (tests/test_cross_library.py;
60
+ # fcapy and caspailleur come with DimFlux).
61
+ "concepts",
57
62
  "ruff",
58
63
  ]
59
64
 
@@ -0,0 +1 @@
1
+ __version__ = "0.6.3"
@@ -88,6 +88,18 @@ def _check_unique_names(names: tuple[str, ...], kind: str) -> None:
88
88
  )
89
89
 
90
90
 
91
+ def as_cell_array(data) -> np.ndarray:
92
+ """
93
+ ``np.asarray(data)``, except that a list mixing numbers and strings keeps
94
+ each cell as it is: NumPy would turn it into strings ([2, "x"] becomes
95
+ ["2", "x"]), and the string "2" is not a cross while the number 2 is.
96
+ """
97
+ array = np.asarray(data)
98
+ if array.dtype.kind in "US" and not isinstance(data, np.ndarray):
99
+ array = np.asarray(data, dtype=object)
100
+ return array
101
+
102
+
91
103
  def _cross_table(data) -> np.ndarray:
92
104
  """
93
105
  Convert incidence data to a boolean cross table, cell by cell:
@@ -105,7 +117,7 @@ def _cross_table(data) -> np.ndarray:
105
117
  """
106
118
  if scipy.sparse.issparse(data):
107
119
  data = data.toarray()
108
- raw = np.asarray(data)
120
+ raw = as_cell_array(data)
109
121
 
110
122
  if raw.dtype == bool:
111
123
  # Copy, so later changes to the caller's array cannot alter a frozen
@@ -240,7 +252,7 @@ class FormalContext:
240
252
  """
241
253
  if scipy.sparse.issparse(data):
242
254
  data = data.toarray()
243
- array = np.asarray(data)
255
+ array = as_cell_array(data)
244
256
 
245
257
  if array.ndim != 2:
246
258
  raise ValueError("Formal context data must be two-dimensional.")
@@ -39,6 +39,17 @@ def context_to_json(context: FormalContext) -> str:
39
39
  return json.dumps(data, ensure_ascii=False)
40
40
 
41
41
 
42
+ def _json_names(value, what: str) -> list:
43
+ """Object or attribute names from JSON: a list of strings or numbers."""
44
+ if not isinstance(value, list) or not all(
45
+ isinstance(name, (str, int, float)) and not isinstance(name, bool) for name in value
46
+ ):
47
+ raise ValueError(
48
+ f"The JSON context's {what} must be a list of names, got {str(value)[:60]}."
49
+ )
50
+ return value
51
+
52
+
42
53
  def context_from_json(text: str) -> FormalContext:
43
54
  """Parse a context from FCART/fcapy JSON or the plain dict layout."""
44
55
  data = json.loads(text)
@@ -53,7 +64,15 @@ def context_from_json(text: str) -> FormalContext:
53
64
  f"The JSON context has no {exc.args[0]!r} entry: expected the "
54
65
  'FCART/fcapy layout or {"objects", "attributes", "incidence"}.'
55
66
  ) from None
56
- return FormalContext(objects=objects, attributes=attributes, incidence=incidence)
67
+ if not isinstance(incidence, list):
68
+ raise ValueError(
69
+ f"The JSON context's incidence must be a list of rows, got {str(incidence)[:60]}."
70
+ )
71
+ return FormalContext(
72
+ objects=_json_names(objects, "objects"),
73
+ attributes=_json_names(attributes, "attributes"),
74
+ incidence=incidence,
75
+ )
57
76
 
58
77
  try:
59
78
  header, body = data
@@ -66,6 +85,8 @@ def context_from_json(text: str) -> FormalContext:
66
85
  '{"objects", "attributes", "incidence"}.'
67
86
  ) from exc
68
87
 
88
+ objects = _json_names(objects, "objects")
89
+ attributes = _json_names(attributes, "attributes")
69
90
  if len(rows) != len(objects):
70
91
  raise ValueError(
71
92
  f"The JSON context names {len(objects)} objects but has {len(rows)} rows."
@@ -511,11 +511,24 @@ def edge_crossing_score(drawing) -> float:
511
511
  """
512
512
  ``1 - crossings / possible crossings``.
513
513
 
514
- Two edges can cross in some upward drawing only if all four endpoints are
515
- pairwise incomparable; other pairs are joined by monotone paths and never
516
- need to cross. Only those pairs are counted, so the score measures how
517
- much of the avoidable crossing budget the drawing spends. 1.0 if no pair
518
- of edges could cross (a chain, for example).
514
+ Following Purchase's crossing score with a bound tightened for order
515
+ diagrams, ``1 - |X| / X_max`` with
516
+ ``X_max = C(|E|, 2) - X_deg - X_comp``:
517
+
518
+ - ``|X|`` is the number of pairs of edges that cross (also touching or
519
+ overlapping) without sharing an endpoint;
520
+ - ``X_deg`` is the number of pairs of edges that share an endpoint;
521
+ - ``X_comp`` is the number of the other pairs whose four endpoints are
522
+ pairwise comparable. For cover edges these are the pairs with one edge
523
+ entirely below the other, which cannot cross in an upward drawing.
524
+
525
+ Pairs of edges with only some endpoints comparable can cross and are
526
+ counted. An edge of (almost) zero length, between two nodes drawn at one
527
+ point, crosses nothing; ``node_node_conflict_score`` measures such
528
+ overlaps. 1.0 if no pair of edges could cross (a chain, for example). A
529
+ drawing that is not upward can also have crossings between pairs counted
530
+ in ``X_comp``; they count as crossings too, and the score is then clipped
531
+ at 0.
519
532
  """
520
533
  drawing = _check_drawing(drawing)
521
534
  edges = drawing.edges
@@ -532,28 +545,28 @@ def edge_crossing_score(drawing) -> float:
532
545
  chunk = max(1, _CHUNK_CELLS // len(edges))
533
546
  for first in range(0, len(edges), chunk):
534
547
  block = slice(first, first + chunk)
535
- # Comparability is reflexive, so this also blocks shared endpoints.
536
- blocked = (
548
+ shared = (
549
+ (lower[block, None] == lower[None, :])
550
+ | (lower[block, None] == upper[None, :])
551
+ | (upper[block, None] == lower[None, :])
552
+ | (upper[block, None] == upper[None, :])
553
+ )
554
+ # The endpoints of one edge are comparable (u < v), so all four are
555
+ # pairwise comparable iff every endpoint of one edge is comparable
556
+ # with every endpoint of the other.
557
+ all_comparable = (
537
558
  comparable[np.ix_(lower[block], lower)]
538
- | comparable[np.ix_(lower[block], upper)]
539
- | comparable[np.ix_(upper[block], lower)]
540
- | comparable[np.ix_(upper[block], upper)]
559
+ & comparable[np.ix_(lower[block], upper)]
560
+ & comparable[np.ix_(upper[block], lower)]
561
+ & comparable[np.ix_(upper[block], upper)]
541
562
  )
542
563
  # Count each unordered pair once: row k of the block is edge first + k.
543
- possible += int(np.triu(~blocked, k=first + 1).sum())
564
+ possible += int(np.triu(~(shared | all_comparable), k=first + 1).sum())
544
565
  if possible == 0:
545
566
  return 1.0
546
567
 
547
- # Crossings between comparable edges are not valid upward drawings at
548
- # all; they are left out of both counts.
549
- i, j, _ = drawing.crossings
550
- free = ~(
551
- comparable[lower[i], lower[j]]
552
- | comparable[lower[i], upper[j]]
553
- | comparable[upper[i], lower[j]]
554
- | comparable[upper[i], upper[j]]
555
- )
556
- return float(1.0 - int(free.sum()) / possible)
568
+ crossings = len(drawing.crossings[0])
569
+ return float(max(0.0, 1.0 - crossings / possible))
557
570
 
558
571
 
559
572
  def _crossing_angles(drawing: _Drawing) -> np.ndarray:
@@ -9,7 +9,7 @@ import pandas as pd
9
9
  from scipy import sparse
10
10
 
11
11
  from conceptflow.core import FormalContext, IncompleteContext
12
- from conceptflow.core.context import _cross_table
12
+ from conceptflow.core.context import _cross_table, as_cell_array
13
13
 
14
14
  _UNKNOWN_HINT = (
15
15
  "Binary-context estimators need complete data. Choose a completion with "
@@ -52,7 +52,7 @@ def check_binary_context_input(X) -> FormalContext:
52
52
  if sparse.issparse(X):
53
53
  array = X.toarray()
54
54
  else:
55
- array = np.asarray(X)
55
+ array = as_cell_array(X)
56
56
 
57
57
  if np.iscomplexobj(array):
58
58
  raise ValueError("Complex data not supported")
@@ -61,20 +61,28 @@ def check_binary_context_input(X) -> FormalContext:
61
61
  array = array.astype(object)
62
62
 
63
63
  if array.dtype == object:
64
- # Try to coerce to numeric — raises TypeError with sklearn-compatible
65
- # message if elements cannot be converted (e.g. dicts, arbitrary objects).
66
- try:
67
- array = array.astype(float)
68
- except ValueError:
64
+ cells = array.ravel().tolist()
65
+ if any(cell is pd.NA for cell in cells) or pd.isna(array).any():
66
+ raise ValueError(
67
+ "Input contains NaN: missing entries. If empty cells mean "
68
+ '"no cross", pass FormalContext.from_array(X) instead.'
69
+ )
70
+ if any(isinstance(cell, complex) for cell in cells):
71
+ raise ValueError("Complex data not supported")
72
+ if any(
73
+ isinstance(cell, (float, np.floating)) and not np.isfinite(cell) for cell in cells
74
+ ):
75
+ raise ValueError("Input contains infinity or a value too large.")
76
+ if any(isinstance(cell, (str, bytes)) for cell in cells):
69
77
  # Strings such as "x" / ".": read cell by cell, as FormalContext
70
- # does (unknown spellings raise a ValueError naming the value).
71
- # Empty cells are still rejected, as for numeric input.
72
- if pd.isna(array).any():
73
- raise ValueError(
74
- "Input contains NaN: missing entries. If empty cells mean "
75
- '"no cross", pass FormalContext.from_array(X) instead.'
76
- ) from None
78
+ # and DataFrames are, so "2" or "1.5" are refused whatever the
79
+ # other cells hold (unknown spellings raise a ValueError naming
80
+ # the value).
77
81
  array = _cross_table(array)
82
+ else:
83
+ # Numbers: raises TypeError with scikit-learn's message for
84
+ # anything else (e.g. dicts, arbitrary objects).
85
+ array = array.astype(float)
78
86
 
79
87
  if array.ndim != 2:
80
88
  raise ValueError(
@@ -0,0 +1,168 @@
1
+ """
2
+ Argument checks and page layout shared by the renderers.
3
+ """
4
+
5
+ from __future__ import annotations
6
+
7
+ import math
8
+ from collections.abc import Callable
9
+ from numbers import Integral, Real
10
+
11
+ from sklearn.utils import check_scalar
12
+
13
+ # Width of the details panel in the interactive pages; it sits beside the
14
+ # drawing from PANEL_BESIDE_FROM pixels on, below it in narrower pages.
15
+ DETAILS_PANEL_WIDTH = 280
16
+ PANEL_BESIDE_FROM = 560
17
+
18
+ # Height of the drawing with height="auto" in a notebook, whose frame grows to
19
+ # the page (so the page cannot fill the frame), and the least height of a
20
+ # drawing that fills a small window.
21
+ NOTEBOOK_DRAWING_HEIGHT = 700
22
+ MIN_DRAWING_HEIGHT = 300
23
+
24
+ # Attribute on <html> that HTMLFigure._repr_html_ sets: the page is notebook
25
+ # output. Saved pages fill the window, also in previews that show them in a
26
+ # frame (VS Code, JupyterLab).
27
+ NOTEBOOK_MARKER = "data-conceptflow-notebook"
28
+
29
+ _BESIDE = (
30
+ ".conceptflow-body {{ grid-template-columns: minmax(0, 1fr) {panel}px; "
31
+ "height: var(--drawing-height); }}\n"
32
+ " .conceptflow-details {{ border-left: 1px solid #ddd; }}"
33
+ ).format(panel=DETAILS_PANEL_WIDTH)
34
+
35
+ _BELOW = (
36
+ ".conceptflow-body { grid-template-columns: minmax(0, 1fr); "
37
+ "grid-template-rows: var(--drawing-height) auto; height: auto; }\n"
38
+ " .conceptflow-details { border-left: none; border-top: 1px solid #ddd; }"
39
+ )
40
+
41
+ # Keeps the drawing at the size of its area: with height="auto" in a window
42
+ # (not in a notebook), the drawing fills the window below the header. The
43
+ # page's draw(size) is called when the area has a size, and again when it
44
+ # changes, unless the reader has zoomed or panned (sizer.held): then their
45
+ # view is kept until they reset the zoom.
46
+ SIZE_SCRIPT = """
47
+ function conceptflowSizer(svgNode, autoHeight, draw) {
48
+ const container = svgNode.closest(".conceptflow-container");
49
+ const header = container.querySelector(".conceptflow-header");
50
+ const notebook = document.documentElement.hasAttribute("%(marker)s");
51
+ const fillWindow = autoHeight && !notebook;
52
+ let drawnSize = null;
53
+ let timer = null;
54
+
55
+ function fitHeight() {
56
+ if (!fillWindow) return;
57
+ const borders = container.offsetHeight - container.clientHeight;
58
+ const height = Math.max(
59
+ %(min_height)d, Math.floor(window.innerHeight - header.offsetHeight - borders)
60
+ );
61
+ container.style.setProperty("--drawing-height", height + "px");
62
+ }
63
+
64
+ function measure() {
65
+ const box = svgNode.getBoundingClientRect();
66
+ return { width: box.width, height: box.height };
67
+ }
68
+
69
+ const sizer = {
70
+ held: false,
71
+ // Draw the current view now, fitted to the drawing area.
72
+ draw() {
73
+ fitHeight();
74
+ const size = measure();
75
+ if (size.width < 1 || size.height < 1) {
76
+ drawnSize = null; // hidden: drawn once it has a size
77
+ return;
78
+ }
79
+ drawnSize = size;
80
+ svgNode.setAttribute("width", Math.round(size.width));
81
+ svgNode.setAttribute("height", Math.round(size.height));
82
+ draw(size);
83
+ },
84
+ // Draw again if the area has changed and the reader has not moved the view.
85
+ resized() {
86
+ fitHeight();
87
+ const size = measure();
88
+ if (sizer.held || size.width < 1 || size.height < 1) return;
89
+ if (drawnSize && Math.abs(size.width - drawnSize.width) < 0.5
90
+ && Math.abs(size.height - drawnSize.height) < 0.5) return;
91
+ sizer.draw();
92
+ },
93
+ size() {
94
+ return drawnSize || measure();
95
+ },
96
+ };
97
+
98
+ window.addEventListener("resize", fitHeight);
99
+ if (window.ResizeObserver) {
100
+ new ResizeObserver(() => {
101
+ clearTimeout(timer);
102
+ timer = setTimeout(sizer.resized, 100);
103
+ }).observe(svgNode);
104
+ }
105
+ return sizer;
106
+ }
107
+ """ % {"marker": NOTEBOOK_MARKER, "min_height": MIN_DRAWING_HEIGHT}
108
+
109
+
110
+ def check_page_size(value, name: str) -> None:
111
+ """``"auto"`` or a positive, finite number of pixels."""
112
+ if isinstance(value, str):
113
+ if value != "auto":
114
+ raise TypeError(f'{name} must be "auto" or a number of pixels, got {value!r}.')
115
+ return
116
+ if isinstance(value, bool):
117
+ raise TypeError(f'{name} must be "auto" or a number of pixels, got {value!r}.')
118
+ check_scalar(value, name, Real, min_val=0, include_boundaries="neither")
119
+ if not math.isfinite(value):
120
+ raise ValueError(f"{name} must be a finite number of pixels, got {value!r}.")
121
+
122
+
123
+ def html_page_layout(width, height) -> dict:
124
+ """
125
+ Check the size of an interactive page and return its CSS.
126
+
127
+ ``width="auto"`` fills the window or notebook cell; ``height="auto"``
128
+ fills the window below the header (the page's script sets it), and is
129
+ 700 px in a notebook. A number fixes that size in pixels; a fixed width
130
+ includes the details panel, which moves below the drawing in pages
131
+ narrower than 560 px. Returns ``css``, ``auto_height`` and
132
+ ``figure_height`` (the drawing height a notebook frame starts with).
133
+ """
134
+ check_page_size(width, "width")
135
+ check_page_size(height, "height")
136
+ auto_height = isinstance(height, str)
137
+ drawing_height = NOTEBOOK_DRAWING_HEIGHT if auto_height else height
138
+
139
+ if isinstance(width, str):
140
+ container = "width: 100%;"
141
+ layout = (
142
+ f"{_BESIDE}\n"
143
+ f" @media (max-width: {PANEL_BESIDE_FROM - 0.02}px) {{\n {_BELOW}\n }}"
144
+ )
145
+ else:
146
+ container = f"width: {width}px; max-width: 100%; margin: 0 auto;"
147
+ layout = _BESIDE if width >= PANEL_BESIDE_FROM else _BELOW
148
+
149
+ css = (
150
+ f".conceptflow-container {{ {container} box-sizing: border-box; "
151
+ f"--drawing-height: {drawing_height}px; }}\n"
152
+ f" .conceptflow-drawing {{ display: block; width: 100%; height: 100%; }}\n"
153
+ f" {layout}"
154
+ )
155
+ return {"css": css, "auto_height": auto_height, "figure_height": drawing_height}
156
+
157
+
158
+ def check_max_label_items(max_label_items) -> None:
159
+ """``None`` (show every label) or how many to show before "+n"."""
160
+ if max_label_items is not None:
161
+ check_scalar(max_label_items, "max_label_items", Integral, min_val=0)
162
+
163
+
164
+ def object_formatter(object_label: Callable | None) -> Callable[[str], str]:
165
+ """``object_label`` with its result turned into text, as every backend needs."""
166
+ if object_label is None:
167
+ return str
168
+ return lambda name: str(object_label(name))
@@ -5,10 +5,12 @@ D3 backend for ordinary ConceptFlow lattice diagrams.
5
5
  from __future__ import annotations
6
6
 
7
7
  import html
8
+ import json
8
9
  from collections.abc import Callable
9
10
  from typing import Any
10
11
 
11
12
  from conceptflow.visualization._checks import (
13
+ SIZE_SCRIPT,
12
14
  check_max_label_items,
13
15
  html_page_layout,
14
16
  object_formatter,
@@ -48,8 +50,8 @@ def graph_data_to_d3_data(graph_data: GraphData) -> dict[str, Any]:
48
50
 
49
51
  def render_graph_data_html(
50
52
  graph_data: GraphData,
51
- width: int = 900,
52
- height: int = 700,
53
+ width: int | str = "auto",
54
+ height: int | str = "auto",
53
55
  title: str = "Concept lattice",
54
56
  show_attribute_labels: bool = True,
55
57
  show_object_labels: bool = True,
@@ -59,13 +61,20 @@ def render_graph_data_html(
59
61
  """
60
62
  Render GraphData as a standalone D3 HTML string.
61
63
 
62
- ``width`` includes the 280 px details panel, which moves below the
63
- drawing in pages narrower than 560 px.
64
+ ``width="auto"`` fills the window (or the notebook cell) and
65
+ ``height="auto"`` the window below the header; in a notebook the drawing
66
+ is 700 px high. The drawing fits itself again when the window is
67
+ resized. Numbers fix the size in pixels; ``width`` then includes the
68
+ 280 px details panel, which moves below the drawing in pages narrower
69
+ than 560 px.
64
70
 
65
71
  Labels follow reduced labelling, as in the other backends: attributes
66
- above the node that introduces them, objects below. The full extent and
67
- intent of a concept appear in its tooltip and, on click, in the details
68
- panel.
72
+ above the node that introduces them, objects below, each shortened to
73
+ ``max_label_items`` names and "+n" (``None`` shows all). The full extent
74
+ and intent of a concept appear in its tooltip and, on click, in the
75
+ details panel. ``show_attribute_labels`` and ``show_object_labels`` set
76
+ whether the labels are shown when the page opens; buttons on the page
77
+ turn them on and off.
69
78
  """
70
79
  from conceptflow.visualization.static import _join_labels, _reduced_labels
71
80
 
@@ -75,11 +84,16 @@ def render_graph_data_html(
75
84
  attributes_at, objects_at = _reduced_labels(graph_data)
76
85
  format_object = object_formatter(object_label)
77
86
  for node in data["nodes"]:
78
- attributes = sorted(attributes_at[node["id"]]) if show_attribute_labels else []
79
- objects = sorted(map(format_object, objects_at[node["id"]])) if show_object_labels else []
87
+ attributes = sorted(attributes_at[node["id"]])
88
+ objects = sorted(map(format_object, objects_at[node["id"]]))
80
89
  node["attribute_text"] = _join_labels(attributes, max_label_items)
81
90
  node["object_text"] = _join_labels(objects, max_label_items)
82
91
  data_json = script_json(data)
92
+ settings_json = json.dumps({
93
+ "autoHeight": page["auto_height"],
94
+ "showAttributeLabels": bool(show_attribute_labels),
95
+ "showObjectLabels": bool(show_object_labels),
96
+ })
83
97
 
84
98
  return f"""
85
99
  <!DOCTYPE html>
@@ -95,8 +109,6 @@ def render_graph_data_html(
95
109
  }}
96
110
 
97
111
  .conceptflow-container {{
98
- width: {width}px;
99
- max-width: 100%;
100
112
  border: 1px solid #ddd;
101
113
  border-radius: 10px;
102
114
  overflow: hidden;
@@ -104,11 +116,41 @@ def render_graph_data_html(
104
116
  }}
105
117
 
106
118
  .conceptflow-header {{
119
+ display: flex;
120
+ flex-wrap: wrap;
121
+ justify-content: space-between;
122
+ align-items: center;
123
+ gap: 8px 12px;
107
124
  padding: 10px 14px;
108
125
  background: #f2f2f2;
109
126
  border-bottom: 1px solid #ddd;
110
127
  }}
111
128
 
129
+ .conceptflow-controls {{
130
+ display: flex;
131
+ flex-wrap: wrap;
132
+ gap: 6px;
133
+ }}
134
+
135
+ .conceptflow-button {{
136
+ border: 1px solid #aaa;
137
+ background: white;
138
+ border-radius: 6px;
139
+ padding: 5px 10px;
140
+ cursor: pointer;
141
+ font-size: 12px;
142
+ }}
143
+
144
+ .conceptflow-button:hover {{
145
+ background: #f7f7f7;
146
+ }}
147
+
148
+ /* Label buttons: pressed while their labels are shown. */
149
+ .conceptflow-button[aria-pressed="true"] {{
150
+ background: #e8eef5;
151
+ border-color: #1f4e79;
152
+ }}
153
+
112
154
  .conceptflow-title {{
113
155
  font-size: 16px;
114
156
  font-weight: 600;
@@ -122,12 +164,9 @@ def render_graph_data_html(
122
164
 
123
165
  .conceptflow-body {{
124
166
  display: grid;
125
- grid-template-columns: {page['columns']};
126
- min-height: {height}px;
127
167
  }}
128
168
 
129
169
  .conceptflow-details {{
130
- {page['panel_border']}: 1px solid #ddd;
131
170
  background: #fafafa;
132
171
  padding: 12px;
133
172
  font-size: 12px;
@@ -211,17 +250,26 @@ def render_graph_data_html(
211
250
  fill: #444;
212
251
  font-style: italic;
213
252
  }}
253
+
254
+ {page['css']}
214
255
  </style>
215
256
  </head>
216
257
  <body>
217
258
  <div class="conceptflow-container">
218
259
  <div class="conceptflow-header">
219
- <div class="conceptflow-title">{html.escape(title)}</div>
220
- <div id="conceptflow-subtitle" class="conceptflow-subtitle"></div>
260
+ <div>
261
+ <div class="conceptflow-title">{html.escape(title)}</div>
262
+ <div id="conceptflow-subtitle" class="conceptflow-subtitle"></div>
263
+ </div>
264
+ <div class="conceptflow-controls">
265
+ <button id="conceptflow-attribute-labels" class="conceptflow-button">Attribute labels</button>
266
+ <button id="conceptflow-object-labels" class="conceptflow-button">Object labels</button>
267
+ <button id="conceptflow-reset-zoom" class="conceptflow-button">Reset zoom</button>
268
+ </div>
221
269
  </div>
222
270
 
223
271
  <div class="conceptflow-body">
224
- <svg id="conceptflow-svg" width="{page['drawing_width']}" height="{height}"></svg>
272
+ <svg id="conceptflow-svg" class="conceptflow-drawing"></svg>
225
273
 
226
274
  <div id="conceptflow-details" class="conceptflow-details">
227
275
  <div class="details-title">Details</div>
@@ -232,9 +280,8 @@ def render_graph_data_html(
232
280
 
233
281
  <script>
234
282
  const graphData = {data_json};
235
- const svgWidth = {page['drawing_width']};
236
- const svgHeight = {height};
237
-
283
+ const settings = {settings_json};
284
+ {SIZE_SCRIPT}
238
285
  const svg = d3.select("#conceptflow-svg");
239
286
  const details = d3.select("#conceptflow-details");
240
287
  const subtitle = d3.select("#conceptflow-subtitle");
@@ -252,10 +299,22 @@ const zoom = d3.zoom()
252
299
  .scaleExtent([0.3, 8])
253
300
  .on("zoom", (event) => {{
254
301
  rootLayer.attr("transform", event.transform);
302
+ // Zoomed or panned by the reader: keep their view when the page resizes.
303
+ if (event.sourceEvent) sizer.held = true;
255
304
  }});
256
305
 
257
306
  svg.call(zoom);
258
307
 
308
+ let showAttributeLabels = settings.showAttributeLabels;
309
+ let showObjectLabels = settings.showObjectLabels;
310
+
311
+ function applyLabelVisibility() {{
312
+ svg.selectAll(".attr-label").attr("display", showAttributeLabels ? null : "none");
313
+ svg.selectAll(".obj-label").attr("display", showObjectLabels ? null : "none");
314
+ d3.select("#conceptflow-attribute-labels").attr("aria-pressed", showAttributeLabels);
315
+ d3.select("#conceptflow-object-labels").attr("aria-pressed", showObjectLabels);
316
+ }}
317
+
259
318
  function escapeHtml(text) {{
260
319
  return String(text).replace(/[&<>"']/g, c => ({{
261
320
  "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;", "'": "&#39;"
@@ -383,11 +442,12 @@ function computeTransform(nodes, targetWidth, targetHeight, padding, rotate) {{
383
442
  }};
384
443
  }}
385
444
 
386
- function render() {{
445
+ function render(size) {{
387
446
  rootLayer.selectAll("*").remove();
388
447
 
389
448
  const transform = computeTransform(
390
- graphData.nodes, svgWidth, svgHeight, Math.min(80, svgWidth / 6, svgHeight / 6),
449
+ graphData.nodes, size.width, size.height,
450
+ Math.min(80, size.width / 6, size.height / 6),
391
451
  graphData.rotate !== false
392
452
  );
393
453
  const nodeById = new Map(graphData.nodes.map(d => [d.id, d]));
@@ -459,9 +519,29 @@ function render() {{
459
519
  .attr("class", "obj-label")
460
520
  .attr("y", radius * 1.3)
461
521
  .text(d => d.object_text);
522
+
523
+ applyLabelVisibility();
462
524
  }}
463
525
 
464
- render();
526
+ const sizer = conceptflowSizer(
527
+ document.getElementById("conceptflow-svg"), settings.autoHeight, render
528
+ );
529
+
530
+ d3.select("#conceptflow-attribute-labels").on("click", () => {{
531
+ showAttributeLabels = !showAttributeLabels;
532
+ applyLabelVisibility();
533
+ }});
534
+ d3.select("#conceptflow-object-labels").on("click", () => {{
535
+ showObjectLabels = !showObjectLabels;
536
+ applyLabelVisibility();
537
+ }});
538
+ d3.select("#conceptflow-reset-zoom").on("click", () => {{
539
+ sizer.held = false;
540
+ svg.transition().duration(500).call(zoom.transform, d3.zoomIdentity);
541
+ sizer.resized();
542
+ }});
543
+
544
+ sizer.draw();
465
545
  </script>
466
546
  </body>
467
547
  </html>
@@ -470,8 +550,8 @@ render();
470
550
 
471
551
  def render_with_d3(
472
552
  graph_data: GraphData,
473
- width: int = 900,
474
- height: int = 700,
553
+ width: int | str = "auto",
554
+ height: int | str = "auto",
475
555
  title: str = "Concept lattice",
476
556
  **label_options,
477
557
  ) -> HTMLFigure:
@@ -495,5 +575,5 @@ def render_with_d3(
495
575
  title=title,
496
576
  **label_options,
497
577
  ),
498
- height=height,
578
+ height=html_page_layout(width, height)["figure_height"],
499
579
  )