conceptflow 0.6.1__tar.gz → 0.6.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.
Files changed (153) hide show
  1. {conceptflow-0.6.1/src/conceptflow.egg-info → conceptflow-0.6.2}/PKG-INFO +1 -1
  2. conceptflow-0.6.2/src/conceptflow/_version.py +1 -0
  3. {conceptflow-0.6.1 → conceptflow-0.6.2}/src/conceptflow/metrics/drawing_quality.py +34 -21
  4. conceptflow-0.6.2/src/conceptflow/visualization/_checks.py +168 -0
  5. {conceptflow-0.6.1 → conceptflow-0.6.2}/src/conceptflow/visualization/d3_backend.py +106 -26
  6. {conceptflow-0.6.1 → conceptflow-0.6.2}/src/conceptflow/visualization/html_figure.py +7 -2
  7. {conceptflow-0.6.1 → conceptflow-0.6.2}/src/conceptflow/visualization/lattice_plot.py +12 -5
  8. {conceptflow-0.6.1 → conceptflow-0.6.2}/src/conceptflow/visualization/nested.py +129 -44
  9. {conceptflow-0.6.1 → conceptflow-0.6.2/src/conceptflow.egg-info}/PKG-INFO +1 -1
  10. {conceptflow-0.6.1 → conceptflow-0.6.2}/tests/test_browser.py +202 -0
  11. {conceptflow-0.6.1 → conceptflow-0.6.2}/tests/test_d3_backend.py +17 -6
  12. {conceptflow-0.6.1 → conceptflow-0.6.2}/tests/test_drawing_quality.py +93 -3
  13. {conceptflow-0.6.1 → conceptflow-0.6.2}/tests/test_html_figure.py +7 -0
  14. {conceptflow-0.6.1 → conceptflow-0.6.2}/tests/test_visualization_options.py +63 -6
  15. conceptflow-0.6.1/src/conceptflow/_version.py +0 -1
  16. conceptflow-0.6.1/src/conceptflow/visualization/_checks.py +0 -44
  17. {conceptflow-0.6.1 → conceptflow-0.6.2}/LICENSE +0 -0
  18. {conceptflow-0.6.1 → conceptflow-0.6.2}/README.md +0 -0
  19. {conceptflow-0.6.1 → conceptflow-0.6.2}/pyproject.toml +0 -0
  20. {conceptflow-0.6.1 → conceptflow-0.6.2}/setup.cfg +0 -0
  21. {conceptflow-0.6.1 → conceptflow-0.6.2}/src/conceptflow/__init__.py +0 -0
  22. {conceptflow-0.6.1 → conceptflow-0.6.2}/src/conceptflow/_deprecation.py +0 -0
  23. {conceptflow-0.6.1 → conceptflow-0.6.2}/src/conceptflow/algorithms/__init__.py +0 -0
  24. {conceptflow-0.6.1 → conceptflow-0.6.2}/src/conceptflow/algorithms/_bitset.py +0 -0
  25. {conceptflow-0.6.1 → conceptflow-0.6.2}/src/conceptflow/algorithms/_membership.py +0 -0
  26. {conceptflow-0.6.1 → conceptflow-0.6.2}/src/conceptflow/algorithms/_registry.py +0 -0
  27. {conceptflow-0.6.1 → conceptflow-0.6.2}/src/conceptflow/algorithms/derivation.py +0 -0
  28. {conceptflow-0.6.1 → conceptflow-0.6.2}/src/conceptflow/algorithms/enumeration.py +0 -0
  29. {conceptflow-0.6.1 → conceptflow-0.6.2}/src/conceptflow/algorithms/generators.py +0 -0
  30. {conceptflow-0.6.1 → conceptflow-0.6.2}/src/conceptflow/algorithms/hasse.py +0 -0
  31. {conceptflow-0.6.1 → conceptflow-0.6.2}/src/conceptflow/algorithms/implications.py +0 -0
  32. {conceptflow-0.6.1 → conceptflow-0.6.2}/src/conceptflow/algorithms/order.py +0 -0
  33. {conceptflow-0.6.1 → conceptflow-0.6.2}/src/conceptflow/algorithms/reduction.py +0 -0
  34. {conceptflow-0.6.1 → conceptflow-0.6.2}/src/conceptflow/cluster/__init__.py +0 -0
  35. {conceptflow-0.6.1 → conceptflow-0.6.2}/src/conceptflow/cluster/concept_lattice.py +0 -0
  36. {conceptflow-0.6.1 → conceptflow-0.6.2}/src/conceptflow/core/__init__.py +0 -0
  37. {conceptflow-0.6.1 → conceptflow-0.6.2}/src/conceptflow/core/concept.py +0 -0
  38. {conceptflow-0.6.1 → conceptflow-0.6.2}/src/conceptflow/core/context.py +0 -0
  39. {conceptflow-0.6.1 → conceptflow-0.6.2}/src/conceptflow/core/incomplete_context.py +0 -0
  40. {conceptflow-0.6.1 → conceptflow-0.6.2}/src/conceptflow/core/lattice.py +0 -0
  41. {conceptflow-0.6.1 → conceptflow-0.6.2}/src/conceptflow/core/many_valued_context.py +0 -0
  42. {conceptflow-0.6.1 → conceptflow-0.6.2}/src/conceptflow/core/operations.py +0 -0
  43. {conceptflow-0.6.1 → conceptflow-0.6.2}/src/conceptflow/core/scale_measures.py +0 -0
  44. {conceptflow-0.6.1 → conceptflow-0.6.2}/src/conceptflow/datasets/__init__.py +0 -0
  45. {conceptflow-0.6.1 → conceptflow-0.6.2}/src/conceptflow/datasets/_loaders.py +0 -0
  46. {conceptflow-0.6.1 → conceptflow-0.6.2}/src/conceptflow/datasets/data/fca_repository/README.md +0 -0
  47. {conceptflow-0.6.1 → conceptflow-0.6.2}/src/conceptflow/datasets/data/fca_repository/animals_en.cxt +0 -0
  48. {conceptflow-0.6.1 → conceptflow-0.6.2}/src/conceptflow/datasets/data/fca_repository/binary_relations_en.cxt +0 -0
  49. {conceptflow-0.6.1 → conceptflow-0.6.2}/src/conceptflow/datasets/data/fca_repository/bodiesofwater_de.cxt +0 -0
  50. {conceptflow-0.6.1 → conceptflow-0.6.2}/src/conceptflow/datasets/data/fca_repository/bodiesofwater_en.cxt +0 -0
  51. {conceptflow-0.6.1 → conceptflow-0.6.2}/src/conceptflow/datasets/data/fca_repository/driveconcepts_de.cxt +0 -0
  52. {conceptflow-0.6.1 → conceptflow-0.6.2}/src/conceptflow/datasets/data/fca_repository/driveconcepts_en.cxt +0 -0
  53. {conceptflow-0.6.1 → conceptflow-0.6.2}/src/conceptflow/datasets/data/fca_repository/famous_animals_en.cxt +0 -0
  54. {conceptflow-0.6.1 → conceptflow-0.6.2}/src/conceptflow/datasets/data/fca_repository/forum_romanum_en.cxt +0 -0
  55. {conceptflow-0.6.1 → conceptflow-0.6.2}/src/conceptflow/datasets/data/fca_repository/livingbeings_de.cxt +0 -0
  56. {conceptflow-0.6.1 → conceptflow-0.6.2}/src/conceptflow/datasets/data/fca_repository/livingbeings_en.cxt +0 -0
  57. {conceptflow-0.6.1 → conceptflow-0.6.2}/src/conceptflow/datasets/data/fca_repository/missmarple_de.cxt +0 -0
  58. {conceptflow-0.6.1 → conceptflow-0.6.2}/src/conceptflow/datasets/data/fca_repository/missmarple_en.cxt +0 -0
  59. {conceptflow-0.6.1 → conceptflow-0.6.2}/src/conceptflow/datasets/data/fca_repository/music_en.cxt +0 -0
  60. {conceptflow-0.6.1 → conceptflow-0.6.2}/src/conceptflow/datasets/data/fca_repository/newzealand_en.cxt +0 -0
  61. {conceptflow-0.6.1 → conceptflow-0.6.2}/src/conceptflow/datasets/data/fca_repository/officesupplies_de.cxt +0 -0
  62. {conceptflow-0.6.1 → conceptflow-0.6.2}/src/conceptflow/datasets/data/fca_repository/officesupplies_en.cxt +0 -0
  63. {conceptflow-0.6.1 → conceptflow-0.6.2}/src/conceptflow/datasets/data/fca_repository/planets_en.cxt +0 -0
  64. {conceptflow-0.6.1 → conceptflow-0.6.2}/src/conceptflow/datasets/data/fca_repository/seasoningplanner_de.cxt +0 -0
  65. {conceptflow-0.6.1 → conceptflow-0.6.2}/src/conceptflow/datasets/data/fca_repository/tealady.cxt +0 -0
  66. {conceptflow-0.6.1 → conceptflow-0.6.2}/src/conceptflow/datasets/data/fca_repository/triangles_en.cxt +0 -0
  67. {conceptflow-0.6.1 → conceptflow-0.6.2}/src/conceptflow/datasets/data/fca_repository.json +0 -0
  68. {conceptflow-0.6.1 → conceptflow-0.6.2}/src/conceptflow/decomposition/__init__.py +0 -0
  69. {conceptflow-0.6.1 → conceptflow-0.6.2}/src/conceptflow/decomposition/bipartite.py +0 -0
  70. {conceptflow-0.6.1 → conceptflow-0.6.2}/src/conceptflow/decomposition/boolean_factorization.py +0 -0
  71. {conceptflow-0.6.1 → conceptflow-0.6.2}/src/conceptflow/decomposition/ordinal_factorization.py +0 -0
  72. {conceptflow-0.6.1 → conceptflow-0.6.2}/src/conceptflow/exploration/__init__.py +0 -0
  73. {conceptflow-0.6.1 → conceptflow-0.6.2}/src/conceptflow/exploration/builder.py +0 -0
  74. {conceptflow-0.6.1 → conceptflow-0.6.2}/src/conceptflow/exploration/combinations.py +0 -0
  75. {conceptflow-0.6.1 → conceptflow-0.6.2}/src/conceptflow/exploration/view.py +0 -0
  76. {conceptflow-0.6.1 → conceptflow-0.6.2}/src/conceptflow/feature_extraction/__init__.py +0 -0
  77. {conceptflow-0.6.1 → conceptflow-0.6.2}/src/conceptflow/feature_extraction/concept_encoder.py +0 -0
  78. {conceptflow-0.6.1 → conceptflow-0.6.2}/src/conceptflow/io/__init__.py +0 -0
  79. {conceptflow-0.6.1 → conceptflow-0.6.2}/src/conceptflow/io/cxt.py +0 -0
  80. {conceptflow-0.6.1 → conceptflow-0.6.2}/src/conceptflow/io/formats.py +0 -0
  81. {conceptflow-0.6.1 → conceptflow-0.6.2}/src/conceptflow/metrics/__init__.py +0 -0
  82. {conceptflow-0.6.1 → conceptflow-0.6.2}/src/conceptflow/metrics/measures.py +0 -0
  83. {conceptflow-0.6.1 → conceptflow-0.6.2}/src/conceptflow/metrics/rules.py +0 -0
  84. {conceptflow-0.6.1 → conceptflow-0.6.2}/src/conceptflow/preprocessing/__init__.py +0 -0
  85. {conceptflow-0.6.1 → conceptflow-0.6.2}/src/conceptflow/preprocessing/conceptual_scaler.py +0 -0
  86. {conceptflow-0.6.1 → conceptflow-0.6.2}/src/conceptflow/preprocessing/scales.py +0 -0
  87. {conceptflow-0.6.1 → conceptflow-0.6.2}/src/conceptflow/quality.py +0 -0
  88. {conceptflow-0.6.1 → conceptflow-0.6.2}/src/conceptflow/rules/__init__.py +0 -0
  89. {conceptflow-0.6.1 → conceptflow-0.6.2}/src/conceptflow/rules/implication_basis.py +0 -0
  90. {conceptflow-0.6.1 → conceptflow-0.6.2}/src/conceptflow/rules/outlier_detector.py +0 -0
  91. {conceptflow-0.6.1 → conceptflow-0.6.2}/src/conceptflow/validation/__init__.py +0 -0
  92. {conceptflow-0.6.1 → conceptflow-0.6.2}/src/conceptflow/validation/input.py +0 -0
  93. {conceptflow-0.6.1 → conceptflow-0.6.2}/src/conceptflow/visualization/__init__.py +0 -0
  94. {conceptflow-0.6.1 → conceptflow-0.6.2}/src/conceptflow/visualization/_clearance.py +0 -0
  95. {conceptflow-0.6.1 → conceptflow-0.6.2}/src/conceptflow/visualization/_text.py +0 -0
  96. {conceptflow-0.6.1 → conceptflow-0.6.2}/src/conceptflow/visualization/dimflux_layout.py +0 -0
  97. {conceptflow-0.6.1 → conceptflow-0.6.2}/src/conceptflow/visualization/graph_data.py +0 -0
  98. {conceptflow-0.6.1 → conceptflow-0.6.2}/src/conceptflow/visualization/graphviz.py +0 -0
  99. {conceptflow-0.6.1 → conceptflow-0.6.2}/src/conceptflow/visualization/layered_layout.py +0 -0
  100. {conceptflow-0.6.1 → conceptflow-0.6.2}/src/conceptflow/visualization/static.py +0 -0
  101. {conceptflow-0.6.1 → conceptflow-0.6.2}/src/conceptflow/visualization/tikz.py +0 -0
  102. {conceptflow-0.6.1 → conceptflow-0.6.2}/src/conceptflow.egg-info/SOURCES.txt +0 -0
  103. {conceptflow-0.6.1 → conceptflow-0.6.2}/src/conceptflow.egg-info/dependency_links.txt +0 -0
  104. {conceptflow-0.6.1 → conceptflow-0.6.2}/src/conceptflow.egg-info/requires.txt +0 -0
  105. {conceptflow-0.6.1 → conceptflow-0.6.2}/src/conceptflow.egg-info/top_level.txt +0 -0
  106. {conceptflow-0.6.1 → conceptflow-0.6.2}/tests/test_algorithm_registry.py +0 -0
  107. {conceptflow-0.6.1 → conceptflow-0.6.2}/tests/test_audit_regressions.py +0 -0
  108. {conceptflow-0.6.1 → conceptflow-0.6.2}/tests/test_boolean_factorization.py +0 -0
  109. {conceptflow-0.6.1 → conceptflow-0.6.2}/tests/test_check_estimator.py +0 -0
  110. {conceptflow-0.6.1 → conceptflow-0.6.2}/tests/test_cluster_estimator.py +0 -0
  111. {conceptflow-0.6.1 → conceptflow-0.6.2}/tests/test_concept.py +0 -0
  112. {conceptflow-0.6.1 → conceptflow-0.6.2}/tests/test_concept_encoder.py +0 -0
  113. {conceptflow-0.6.1 → conceptflow-0.6.2}/tests/test_conceptual_scaler.py +0 -0
  114. {conceptflow-0.6.1 → conceptflow-0.6.2}/tests/test_context_handling.py +0 -0
  115. {conceptflow-0.6.1 → conceptflow-0.6.2}/tests/test_context_operations.py +0 -0
  116. {conceptflow-0.6.1 → conceptflow-0.6.2}/tests/test_cxt_io.py +0 -0
  117. {conceptflow-0.6.1 → conceptflow-0.6.2}/tests/test_datasets.py +0 -0
  118. {conceptflow-0.6.1 → conceptflow-0.6.2}/tests/test_derivation.py +0 -0
  119. {conceptflow-0.6.1 → conceptflow-0.6.2}/tests/test_dimflux_layout.py +0 -0
  120. {conceptflow-0.6.1 → conceptflow-0.6.2}/tests/test_docs_examples.py +0 -0
  121. {conceptflow-0.6.1 → conceptflow-0.6.2}/tests/test_enumeration.py +0 -0
  122. {conceptflow-0.6.1 → conceptflow-0.6.2}/tests/test_exploration.py +0 -0
  123. {conceptflow-0.6.1 → conceptflow-0.6.2}/tests/test_formal_context.py +0 -0
  124. {conceptflow-0.6.1 → conceptflow-0.6.2}/tests/test_generators.py +0 -0
  125. {conceptflow-0.6.1 → conceptflow-0.6.2}/tests/test_graph_data.py +0 -0
  126. {conceptflow-0.6.1 → conceptflow-0.6.2}/tests/test_hasse.py +0 -0
  127. {conceptflow-0.6.1 → conceptflow-0.6.2}/tests/test_implication_basis_estimator.py +0 -0
  128. {conceptflow-0.6.1 → conceptflow-0.6.2}/tests/test_implications.py +0 -0
  129. {conceptflow-0.6.1 → conceptflow-0.6.2}/tests/test_incomplete_context.py +0 -0
  130. {conceptflow-0.6.1 → conceptflow-0.6.2}/tests/test_lattice.py +0 -0
  131. {conceptflow-0.6.1 → conceptflow-0.6.2}/tests/test_lattice_navigation.py +0 -0
  132. {conceptflow-0.6.1 → conceptflow-0.6.2}/tests/test_layout_and_graphviz.py +0 -0
  133. {conceptflow-0.6.1 → conceptflow-0.6.2}/tests/test_many_valued_context.py +0 -0
  134. {conceptflow-0.6.1 → conceptflow-0.6.2}/tests/test_measures.py +0 -0
  135. {conceptflow-0.6.1 → conceptflow-0.6.2}/tests/test_metrics.py +0 -0
  136. {conceptflow-0.6.1 → conceptflow-0.6.2}/tests/test_nested_combinations.py +0 -0
  137. {conceptflow-0.6.1 → conceptflow-0.6.2}/tests/test_nested_levels.py +0 -0
  138. {conceptflow-0.6.1 → conceptflow-0.6.2}/tests/test_nested_visualization.py +0 -0
  139. {conceptflow-0.6.1 → conceptflow-0.6.2}/tests/test_oracles.py +0 -0
  140. {conceptflow-0.6.1 → conceptflow-0.6.2}/tests/test_ord2factor.py +0 -0
  141. {conceptflow-0.6.1 → conceptflow-0.6.2}/tests/test_ordinal_factorization.py +0 -0
  142. {conceptflow-0.6.1 → conceptflow-0.6.2}/tests/test_patch_0_3_1.py +0 -0
  143. {conceptflow-0.6.1 → conceptflow-0.6.2}/tests/test_public_api.py +0 -0
  144. {conceptflow-0.6.1 → conceptflow-0.6.2}/tests/test_quality.py +0 -0
  145. {conceptflow-0.6.1 → conceptflow-0.6.2}/tests/test_reduction.py +0 -0
  146. {conceptflow-0.6.1 → conceptflow-0.6.2}/tests/test_review_fixes.py +0 -0
  147. {conceptflow-0.6.1 → conceptflow-0.6.2}/tests/test_scale_measures.py +0 -0
  148. {conceptflow-0.6.1 → conceptflow-0.6.2}/tests/test_scales.py +0 -0
  149. {conceptflow-0.6.1 → conceptflow-0.6.2}/tests/test_sklearn_compatibility.py +0 -0
  150. {conceptflow-0.6.1 → conceptflow-0.6.2}/tests/test_static_figures.py +0 -0
  151. {conceptflow-0.6.1 → conceptflow-0.6.2}/tests/test_tikz.py +0 -0
  152. {conceptflow-0.6.1 → conceptflow-0.6.2}/tests/test_validation_input.py +0 -0
  153. {conceptflow-0.6.1 → conceptflow-0.6.2}/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.2
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
@@ -0,0 +1 @@
1
+ __version__ = "0.6.2"
@@ -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:
@@ -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
  )
@@ -44,11 +44,16 @@ class HTMLFigure:
44
44
  """
45
45
  The page in its own ``<iframe>``, so that several figures in one
46
46
  notebook do not share ids, scripts or styles with each other or with
47
- the notebook. The frame grows to the page's height once loaded.
47
+ the notebook. The frame grows to the page's height once loaded, so
48
+ the page is marked as notebook output: a page that fills its window
49
+ keeps a fixed height here instead.
48
50
  """
51
+ from conceptflow.visualization._checks import NOTEBOOK_MARKER
52
+
49
53
  height = (self.height or 700) + 100
54
+ page = self.html.replace("<html>", f"<html {NOTEBOOK_MARKER}>", 1)
50
55
  return (
51
- f'<iframe srcdoc="{html.escape(self.html, quote=True)}" '
56
+ f'<iframe srcdoc="{html.escape(page, quote=True)}" '
52
57
  f'style="width: 100%; height: {height}px; border: none;" '
53
58
  'onload="this.style.height = '
54
59
  "(this.contentDocument.documentElement.scrollHeight + 4) + 'px';\"></iframe>"
@@ -5,6 +5,7 @@ Public plotting entry points for ConceptFlow lattice visualization.
5
5
  from __future__ import annotations
6
6
 
7
7
  from conceptflow.core import ConceptLattice
8
+ from conceptflow.visualization._checks import check_page_size
8
9
  from conceptflow.visualization.d3_backend import render_with_d3
9
10
  from conceptflow.visualization.dimflux_layout import lattice_to_graph_data_dimflux
10
11
  from conceptflow.visualization.graph_data import lattice_to_graph_data
@@ -18,8 +19,8 @@ def plot_lattice(
18
19
  backend: str = "d3",
19
20
  layout: str = "dimflux",
20
21
  stable_ids: bool = False,
21
- width: int = 900,
22
- height: int = 700,
22
+ width: int | str = "auto",
23
+ height: int | str = "auto",
23
24
  title: str | None = None,
24
25
  timeout_ms: int | None = 1000,
25
26
  **kwargs,
@@ -62,8 +63,10 @@ def plot_lattice(
62
63
  instead of local node ids c0, c1, ...
63
64
 
64
65
  width, height:
65
- Figure size in pixels. For the matplotlib backend they set
66
- ``figsize`` at 100 dpi unless ``figsize`` is passed explicitly.
66
+ Figure size in pixels. For the d3 backend, "auto" (the default)
67
+ fills the browser window, or the notebook cell with a 700 px high
68
+ drawing. For the matplotlib backend they set ``figsize`` at 100 dpi
69
+ unless ``figsize`` is passed explicitly; "auto" is 900 x 700.
67
70
 
68
71
  title:
69
72
  Figure title. Defaults to "Concept lattice" for the d3 backend and
@@ -127,7 +130,11 @@ def plot_lattice(
127
130
  if backend == "matplotlib":
128
131
  from conceptflow.visualization.static import render_lattice_matplotlib
129
132
 
130
- kwargs.setdefault("figsize", (width / 100, height / 100))
133
+ check_page_size(width, "width")
134
+ check_page_size(height, "height")
135
+ figure_width = 900 if width == "auto" else width
136
+ figure_height = 700 if height == "auto" else height
137
+ kwargs.setdefault("figsize", (figure_width / 100, figure_height / 100))
131
138
  return render_lattice_matplotlib(graph_data, title=title, **kwargs)
132
139
 
133
140
  return render_with_d3(