plot3 0.6.6__tar.gz → 0.6.8__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.
- {plot3-0.6.6 → plot3-0.6.8}/PKG-INFO +1 -1
- plot3-0.6.8/plot3/__version__.py +1 -0
- {plot3-0.6.6 → plot3-0.6.8}/plot3/build.py +66 -26
- {plot3-0.6.6 → plot3-0.6.8}/plot3/function.py +10 -0
- {plot3-0.6.6 → plot3-0.6.8}/plot3/geoms.py +8 -5
- {plot3-0.6.6 → plot3-0.6.8}/plot3/ggplot.py +29 -2
- {plot3-0.6.6 → plot3-0.6.8}/plot3/viewer.py +35 -5
- {plot3-0.6.6 → plot3-0.6.8}/plot3.egg-info/PKG-INFO +1 -1
- {plot3-0.6.6 → plot3-0.6.8}/tests/test_animation.py +30 -0
- {plot3-0.6.6 → plot3-0.6.8}/tests/test_math_layers.py +34 -0
- plot3-0.6.6/plot3/__version__.py +0 -1
- {plot3-0.6.6 → plot3-0.6.8}/LICENSE +0 -0
- {plot3-0.6.6 → plot3-0.6.8}/README.md +0 -0
- {plot3-0.6.6 → plot3-0.6.8}/plot3/__init__.py +0 -0
- {plot3-0.6.6 → plot3-0.6.8}/plot3/aesexpr.py +0 -0
- {plot3-0.6.6 → plot3-0.6.8}/plot3/calculus.py +0 -0
- {plot3-0.6.6 → plot3-0.6.8}/plot3/compose.py +0 -0
- {plot3-0.6.6 → plot3-0.6.8}/plot3/contour.py +0 -0
- {plot3-0.6.6 → plot3-0.6.8}/plot3/craft.py +0 -0
- {plot3-0.6.6 → plot3-0.6.8}/plot3/encode.py +0 -0
- {plot3-0.6.6 → plot3-0.6.8}/plot3/expr.py +0 -0
- {plot3-0.6.6 → plot3-0.6.8}/plot3/flip.py +0 -0
- {plot3-0.6.6 → plot3-0.6.8}/plot3/io.py +0 -0
- {plot3-0.6.6 → plot3-0.6.8}/plot3/jupyter.py +0 -0
- {plot3-0.6.6 → plot3-0.6.8}/plot3/latexin.py +0 -0
- {plot3-0.6.6 → plot3-0.6.8}/plot3/masking.py +0 -0
- {plot3-0.6.6 → plot3-0.6.8}/plot3/mathtext.py +0 -0
- {plot3-0.6.6 → plot3-0.6.8}/plot3/payload.py +0 -0
- {plot3-0.6.6 → plot3-0.6.8}/plot3/remote.py +0 -0
- {plot3-0.6.6 → plot3-0.6.8}/plot3/scales.py +0 -0
- {plot3-0.6.6 → plot3-0.6.8}/plot3/scaling.py +0 -0
- {plot3-0.6.6 → plot3-0.6.8}/plot3/special.py +0 -0
- {plot3-0.6.6 → plot3-0.6.8}/plot3/stat2d.py +0 -0
- {plot3-0.6.6 → plot3-0.6.8}/plot3/static.py +0 -0
- {plot3-0.6.6 → plot3-0.6.8}/plot3/stats3d.py +0 -0
- {plot3-0.6.6 → plot3-0.6.8}/plot3/table.py +0 -0
- {plot3-0.6.6 → plot3-0.6.8}/plot3/themes.py +0 -0
- {plot3-0.6.6 → plot3-0.6.8}/plot3.egg-info/SOURCES.txt +0 -0
- {plot3-0.6.6 → plot3-0.6.8}/plot3.egg-info/dependency_links.txt +0 -0
- {plot3-0.6.6 → plot3-0.6.8}/plot3.egg-info/requires.txt +0 -0
- {plot3-0.6.6 → plot3-0.6.8}/plot3.egg-info/top_level.txt +0 -0
- {plot3-0.6.6 → plot3-0.6.8}/pyproject.toml +0 -0
- {plot3-0.6.6 → plot3-0.6.8}/setup.cfg +0 -0
- {plot3-0.6.6 → plot3-0.6.8}/tests/test_2d_density.py +0 -0
- {plot3-0.6.6 → plot3-0.6.8}/tests/test_3d.py +0 -0
- {plot3-0.6.6 → plot3-0.6.8}/tests/test_annotate.py +0 -0
- {plot3-0.6.6 → plot3-0.6.8}/tests/test_api_public.py +0 -0
- {plot3-0.6.6 → plot3-0.6.8}/tests/test_array_backend.py +0 -0
- {plot3-0.6.6 → plot3-0.6.8}/tests/test_arrow.py +0 -0
- {plot3-0.6.6 → plot3-0.6.8}/tests/test_build_contract.py +0 -0
- {plot3-0.6.6 → plot3-0.6.8}/tests/test_contour.py +0 -0
- {plot3-0.6.6 → plot3-0.6.8}/tests/test_everyday_ggplot2.py +0 -0
- {plot3-0.6.6 → plot3-0.6.8}/tests/test_expr.py +0 -0
- {plot3-0.6.6 → plot3-0.6.8}/tests/test_facets_compose.py +0 -0
- {plot3-0.6.6 → plot3-0.6.8}/tests/test_geom_function.py +0 -0
- {plot3-0.6.6 → plot3-0.6.8}/tests/test_geoms_ds.py +0 -0
- {plot3-0.6.6 → plot3-0.6.8}/tests/test_ggplot2_extras2.py +0 -0
- {plot3-0.6.6 → plot3-0.6.8}/tests/test_ggplot2_parity.py +0 -0
- {plot3-0.6.6 → plot3-0.6.8}/tests/test_ggplot_extras.py +0 -0
- {plot3-0.6.6 → plot3-0.6.8}/tests/test_grammar.py +0 -0
- {plot3-0.6.6 → plot3-0.6.8}/tests/test_latex_input.py +0 -0
- {plot3-0.6.6 → plot3-0.6.8}/tests/test_lidar_scene.py +0 -0
- {plot3-0.6.6 → plot3-0.6.8}/tests/test_masking.py +0 -0
- {plot3-0.6.6 → plot3-0.6.8}/tests/test_mathtext.py +0 -0
- {plot3-0.6.6 → plot3-0.6.8}/tests/test_payload.py +0 -0
- {plot3-0.6.6 → plot3-0.6.8}/tests/test_payload_display.py +0 -0
- {plot3-0.6.6 → plot3-0.6.8}/tests/test_point_cloud.py +0 -0
- {plot3-0.6.6 → plot3-0.6.8}/tests/test_r_oracle_parity.py +0 -0
- {plot3-0.6.6 → plot3-0.6.8}/tests/test_readme.py +0 -0
- {plot3-0.6.6 → plot3-0.6.8}/tests/test_remote_bridge.py +0 -0
- {plot3-0.6.6 → plot3-0.6.8}/tests/test_review_fixes.py +0 -0
- {plot3-0.6.6 → plot3-0.6.8}/tests/test_save_menu.py +0 -0
- {plot3-0.6.6 → plot3-0.6.8}/tests/test_scales_api.py +0 -0
- {plot3-0.6.6 → plot3-0.6.8}/tests/test_scales_themes.py +0 -0
- {plot3-0.6.6 → plot3-0.6.8}/tests/test_special.py +0 -0
- {plot3-0.6.6 → plot3-0.6.8}/tests/test_stat2d.py +0 -0
- {plot3-0.6.6 → plot3-0.6.8}/tests/test_static_save.py +0 -0
- {plot3-0.6.6 → plot3-0.6.8}/tests/test_stats_semantic.py +0 -0
- {plot3-0.6.6 → plot3-0.6.8}/tests/test_step3_geoms.py +0 -0
- {plot3-0.6.6 → plot3-0.6.8}/tests/test_table_backends.py +0 -0
- {plot3-0.6.6 → plot3-0.6.8}/tests/test_titles_theme.py +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.6.8"
|
|
@@ -1726,7 +1726,8 @@ def _formula_legend(legend, formula_geoms, has_title: bool):
|
|
|
1726
1726
|
"""Tidy the legend rows that function curves add.
|
|
1727
1727
|
|
|
1728
1728
|
* One curve under a title of your own: the title already names it, so
|
|
1729
|
-
the curve gets no row (ggplot2 draws no legend for an unmapped layer)
|
|
1729
|
+
the curve gets no row (ggplot2 draws no legend for an unmapped layer),
|
|
1730
|
+
unless a tangent, derivative or other row sits beside it.
|
|
1730
1731
|
* Several curves of one formula (a loop over ``a``): the formula moves
|
|
1731
1732
|
to the legend title and each row lists only its values.
|
|
1732
1733
|
|
|
@@ -1744,7 +1745,7 @@ def _formula_legend(legend, formula_geoms, has_title: bool):
|
|
|
1744
1745
|
return legend, None
|
|
1745
1746
|
if has_title and len(formula_geoms) == 1:
|
|
1746
1747
|
kept = [entry for entry in legend if not any(entry is p for p in primary)]
|
|
1747
|
-
return kept
|
|
1748
|
+
return (legend if kept else None), None
|
|
1748
1749
|
if len(primary) < 2 or len(primary) != len(formula_geoms):
|
|
1749
1750
|
return legend, None
|
|
1750
1751
|
geoms = [entry["_geom"] for entry in primary]
|
|
@@ -1970,6 +1971,9 @@ def build_spec(g: ggplot) -> tuple[dict, list[tuple[str, str]]]:
|
|
|
1970
1971
|
"slider() cannot be combined with transition_time() "
|
|
1971
1972
|
"or transition_states()"
|
|
1972
1973
|
)
|
|
1974
|
+
if slider is not None:
|
|
1975
|
+
# Default steps shrink to fit while layers expand; keep that per render.
|
|
1976
|
+
slider = copy.copy(slider)
|
|
1973
1977
|
domains = None
|
|
1974
1978
|
if any(getattr(layer, "kind", None) == "function" for layer in layers_in):
|
|
1975
1979
|
from plot3.function import data_domains
|
|
@@ -1978,27 +1982,35 @@ def build_spec(g: ggplot) -> tuple[dict, list[tuple[str, str]]]:
|
|
|
1978
1982
|
addon_map: dict[int, list] = {}
|
|
1979
1983
|
for index, addon in getattr(g, "_addons", None) or []:
|
|
1980
1984
|
addon_map.setdefault(int(index), []).append(addon)
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
1985
|
+
def expand_all() -> list:
|
|
1986
|
+
out = []
|
|
1987
|
+
for index, geom in enumerate(layers_in):
|
|
1988
|
+
layer_data = getattr(geom, "layer_data", None)
|
|
1989
|
+
if getattr(geom, "kind", None) == "box3d":
|
|
1990
|
+
# Box classes take the figure theme's group colours.
|
|
1991
|
+
geom = copy.copy(geom)
|
|
1992
|
+
geom._palette = list(theme["cat"])
|
|
1993
|
+
result = expand_stat_geom(
|
|
1994
|
+
geom,
|
|
1995
|
+
g.mapping,
|
|
1996
|
+
data if layer_data is None else layer_data,
|
|
1997
|
+
domains,
|
|
1998
|
+
transition,
|
|
1999
|
+
slider,
|
|
2000
|
+
coord,
|
|
2001
|
+
addon_map.get(index),
|
|
2002
|
+
)
|
|
2003
|
+
if isinstance(result, list):
|
|
2004
|
+
out.extend(result)
|
|
2005
|
+
else:
|
|
2006
|
+
out.append(result)
|
|
2007
|
+
return out
|
|
2008
|
+
|
|
2009
|
+
steps_before = getattr(slider, "steps", None)
|
|
2010
|
+
expanded = expand_all()
|
|
2011
|
+
if getattr(slider, "steps", None) != steps_before:
|
|
2012
|
+
# A later layer lowered the default steps: every layer shares one grid.
|
|
2013
|
+
expanded = expand_all()
|
|
2002
2014
|
from plot3.calculus import mark_intersections
|
|
2003
2015
|
|
|
2004
2016
|
expanded = mark_intersections(expanded)
|
|
@@ -2860,6 +2872,28 @@ def build_spec(g: ggplot) -> tuple[dict, list[tuple[str, str]]]:
|
|
|
2860
2872
|
source = getattr(geom, "_inherit_from", None)
|
|
2861
2873
|
if source and source in labeled:
|
|
2862
2874
|
geom.const_color = labeled[source]
|
|
2875
|
+
# Clicking a legend row hides every layer it names: a tangent's line and
|
|
2876
|
+
# its point, a curve and the area shaded under it.
|
|
2877
|
+
legend_keys: dict[int, str] = {}
|
|
2878
|
+
key_of: dict[str, str] = {}
|
|
2879
|
+
for geom, _mapped in resolved:
|
|
2880
|
+
label = getattr(geom, "_legend_label", None)
|
|
2881
|
+
if not label or geom.const_color is None:
|
|
2882
|
+
continue
|
|
2883
|
+
color_key = getattr(geom, "_color_key", None)
|
|
2884
|
+
key = key_of.get(str(label)) or str(color_key or label)
|
|
2885
|
+
legend_keys[id(geom)] = key
|
|
2886
|
+
key_of.setdefault(str(label), key)
|
|
2887
|
+
if color_key:
|
|
2888
|
+
key_of.setdefault(str(color_key), key)
|
|
2889
|
+
for geom, _mapped in resolved:
|
|
2890
|
+
source = getattr(geom, "_inherit_from", None)
|
|
2891
|
+
if id(geom) not in legend_keys and source and str(source) in key_of:
|
|
2892
|
+
legend_keys[id(geom)] = key_of[str(source)]
|
|
2893
|
+
# Stable short keys, so the same figure always builds the same spec.
|
|
2894
|
+
stable: dict[str, str] = {}
|
|
2895
|
+
for gid, key in legend_keys.items():
|
|
2896
|
+
legend_keys[gid] = stable.setdefault(key, f"k{len(stable)}")
|
|
2863
2897
|
|
|
2864
2898
|
payloads: list[tuple[str, str]] = []
|
|
2865
2899
|
layer_specs = []
|
|
@@ -3351,6 +3385,8 @@ def build_spec(g: ggplot) -> tuple[dict, list[tuple[str, str]]]:
|
|
|
3351
3385
|
if tip_latex:
|
|
3352
3386
|
tip["latex"] = str(tip_latex)
|
|
3353
3387
|
spec_l["tip"] = tip
|
|
3388
|
+
if id(geom) in legend_keys:
|
|
3389
|
+
spec_l["lk"] = legend_keys[id(geom)]
|
|
3354
3390
|
layer_specs.append(spec_l)
|
|
3355
3391
|
|
|
3356
3392
|
# color spec + legend
|
|
@@ -3391,6 +3427,8 @@ def build_spec(g: ggplot) -> tuple[dict, list[tuple[str, str]]]:
|
|
|
3391
3427
|
if not label or not geom.const_color:
|
|
3392
3428
|
continue
|
|
3393
3429
|
entry = {"label": str(label), "color": geom.const_color}
|
|
3430
|
+
if id(geom) in legend_keys:
|
|
3431
|
+
entry["lk"] = legend_keys[id(geom)]
|
|
3394
3432
|
if getattr(geom, "_is_formula", False):
|
|
3395
3433
|
entry["formula"] = True
|
|
3396
3434
|
entry["_geom"] = geom
|
|
@@ -3428,7 +3466,9 @@ def build_spec(g: ggplot) -> tuple[dict, list[tuple[str, str]]]:
|
|
|
3428
3466
|
raw_title = g.labs.get("title") or ""
|
|
3429
3467
|
# One function and no title of your own: the formula is the title.
|
|
3430
3468
|
# A shaded area, a tangent, or roots stay in the legend when they
|
|
3431
|
-
# have a label of their own. The curve
|
|
3469
|
+
# have a label of their own. The curve keeps its row beside them, so the
|
|
3470
|
+
# legend says which line is the curve; alone, its row would only repeat
|
|
3471
|
+
# the title.
|
|
3432
3472
|
if not str(raw_title).strip() and len(formula_geoms) == 1:
|
|
3433
3473
|
shown = formula_geoms[0]
|
|
3434
3474
|
# Symbolic formula, not the value list. That list stays in the legend
|
|
@@ -3445,11 +3485,11 @@ def build_spec(g: ggplot) -> tuple[dict, list[tuple[str, str]]]:
|
|
|
3445
3485
|
elif title_latex:
|
|
3446
3486
|
labs_math["title"] = [{"text": title, "latex": str(title_latex)}]
|
|
3447
3487
|
if legend:
|
|
3448
|
-
|
|
3488
|
+
others = [
|
|
3449
3489
|
entry for entry in legend
|
|
3450
3490
|
if not (entry.get("formula") and entry.get("label") == title)
|
|
3451
3491
|
]
|
|
3452
|
-
if not
|
|
3492
|
+
if not others:
|
|
3453
3493
|
legend = None
|
|
3454
3494
|
else:
|
|
3455
3495
|
title = _take("title", raw_title)
|
|
@@ -938,6 +938,16 @@ def _guard_slider(source: Any, n_samples: int, what: str) -> None:
|
|
|
938
938
|
cells = int(n_samples) * n_frames
|
|
939
939
|
if cells <= _SLIDER_CELL_CAP:
|
|
940
940
|
return
|
|
941
|
+
if getattr(source, "auto_steps", False):
|
|
942
|
+
# Default steps: take the largest count that fits. build_spec hands
|
|
943
|
+
# each render its own copy and re-expands if this lowered it.
|
|
944
|
+
count = len(source.ranges)
|
|
945
|
+
steps = int(source.steps)
|
|
946
|
+
while steps > 2 and int(n_samples) * steps**count > _SLIDER_CELL_CAP:
|
|
947
|
+
steps -= 1
|
|
948
|
+
if int(n_samples) * steps**count <= _SLIDER_CELL_CAP:
|
|
949
|
+
source.steps = steps
|
|
950
|
+
return
|
|
941
951
|
raise ValueError(
|
|
942
952
|
f"slider() would sample {n_frames} frames of {n_samples} {what} "
|
|
943
953
|
f"({cells} values). Pass a smaller steps= or n=."
|
|
@@ -2181,20 +2181,23 @@ class slider:
|
|
|
2181
2181
|
|
|
2182
2182
|
ggplot() + geom_function("y = a sin(k x)") + slider(a=(0, 3), k=(1, 5))
|
|
2183
2183
|
|
|
2184
|
-
``steps`` defaults to 25 per parameter
|
|
2185
|
-
|
|
2186
|
-
``steps``
|
|
2184
|
+
``steps`` defaults to 25 per parameter, lowered as far as needed for
|
|
2185
|
+
the whole grid to fit (three parameters on a curve get 9). An explicit
|
|
2186
|
+
``steps`` is kept as given and refused if it is too large; pass a
|
|
2187
|
+
smaller ``steps`` or ``n``. Do not combine with ``transition_time()``.
|
|
2187
2188
|
"""
|
|
2188
2189
|
|
|
2189
2190
|
kind = "slider"
|
|
2190
2191
|
|
|
2191
|
-
def __init__(self, *, steps: int =
|
|
2192
|
+
def __init__(self, *, steps: int | None = None, **ranges):
|
|
2192
2193
|
if not ranges:
|
|
2193
2194
|
raise TypeError(
|
|
2194
2195
|
"slider() needs a parameter range, for example slider(a=(0, 3))"
|
|
2195
2196
|
)
|
|
2197
|
+
# Only the default shrinks to fit; an explicit count is the user's.
|
|
2198
|
+
self.auto_steps = steps is None
|
|
2196
2199
|
try:
|
|
2197
|
-
nsteps = int(steps)
|
|
2200
|
+
nsteps = 25 if steps is None else int(steps)
|
|
2198
2201
|
except (TypeError, ValueError):
|
|
2199
2202
|
raise TypeError(
|
|
2200
2203
|
"slider() steps= must be an integer, for example steps=25"
|
|
@@ -42,6 +42,25 @@ from plot3.table import as_table, detect_backend
|
|
|
42
42
|
from plot3.themes import _THEMES
|
|
43
43
|
|
|
44
44
|
|
|
45
|
+
def _error_text(exc: BaseException) -> str:
|
|
46
|
+
return f"plot3 could not draw this figure.\n{type(exc).__name__}: {exc}"
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def _error_html(exc: BaseException) -> str:
|
|
50
|
+
import traceback
|
|
51
|
+
|
|
52
|
+
trace = "".join(traceback.format_exception(type(exc), exc, exc.__traceback__))
|
|
53
|
+
return (
|
|
54
|
+
'<div class="plot3-error" style="border-left:4px solid #d9534f;'
|
|
55
|
+
"padding:8px 12px;font-family:ui-monospace,Menlo,monospace;"
|
|
56
|
+
'font-size:13px;white-space:pre-wrap">'
|
|
57
|
+
"<strong>plot3 could not draw this figure.</strong>\n"
|
|
58
|
+
f"{_htmlesc.escape(type(exc).__name__)}: {_htmlesc.escape(str(exc))}"
|
|
59
|
+
'<details style="margin-top:6px"><summary>Traceback</summary>'
|
|
60
|
+
f"{_htmlesc.escape(trace)}</details></div>"
|
|
61
|
+
)
|
|
62
|
+
|
|
63
|
+
|
|
45
64
|
def _env_flag(name: str) -> bool | None:
|
|
46
65
|
raw = os.environ.get(name)
|
|
47
66
|
if raw is None or raw == "":
|
|
@@ -422,7 +441,10 @@ class ggplot:
|
|
|
422
441
|
# Used by hosts that only understand HTML reprs (and by tests).
|
|
423
442
|
# Prefer ``display(fig)`` / ``fig.show()`` so VS Code can open a browser.
|
|
424
443
|
self._maybe_hide_from_ai()
|
|
425
|
-
|
|
444
|
+
try:
|
|
445
|
+
return self._iframe()
|
|
446
|
+
except Exception as exc:
|
|
447
|
+
return _error_html(exc)
|
|
426
448
|
|
|
427
449
|
def _repr_mimebundle_(self, include=None, exclude=None):
|
|
428
450
|
"""HTML plus optional PlotPayload mime for CRAFT host handoff.
|
|
@@ -435,7 +457,12 @@ class ggplot:
|
|
|
435
457
|
from plot3.remote import MIME_PLOT3
|
|
436
458
|
|
|
437
459
|
self._maybe_hide_from_ai()
|
|
438
|
-
|
|
460
|
+
try:
|
|
461
|
+
bundle: dict = {"text/html": self._iframe()}
|
|
462
|
+
except Exception as exc:
|
|
463
|
+
# Notebook hosts swallow repr errors and fall back to the bare
|
|
464
|
+
# object repr, so the reason a plot is missing must be the output.
|
|
465
|
+
return {"text/html": _error_html(exc), "text/plain": _error_text(exc)}
|
|
439
466
|
try:
|
|
440
467
|
if self.facet is None and (
|
|
441
468
|
self._payload is not None or self.data is not None or self.layers
|
|
@@ -338,8 +338,14 @@ function regCat(ci, obj) {
|
|
|
338
338
|
if (!catObjs.has(ci)) catObjs.set(ci, []);
|
|
339
339
|
catObjs.get(ci).push(obj);
|
|
340
340
|
}
|
|
341
|
+
// legend click on a formula row (tangent, derivative, curve): row key ->
|
|
342
|
+
// every three.js object its layers drew, e.g. a tangent's line and its point
|
|
343
|
+
const hiddenKeys = new Set();
|
|
344
|
+
const keyObjs = new Map();
|
|
345
|
+
let currentLK = null; // the key of the layer being drawn, while it draws
|
|
346
|
+
function layerHidden(L) { return L.lk != null && hiddenKeys.has(L.lk); }
|
|
341
347
|
let redraw = () => {}; // 2D assigns its draw(); 3D renders continuously
|
|
342
|
-
window.__plot3 = { hiddenCats, catObjs };
|
|
348
|
+
window.__plot3 = { hiddenCats, catObjs, hiddenKeys, keyObjs };
|
|
343
349
|
function showLegendBox() {
|
|
344
350
|
// theme(legend_position="none"), and all but one panel of a facet_grid.
|
|
345
351
|
if (S.legendPosition === 'none') return;
|
|
@@ -414,15 +420,23 @@ if (S.legend) {
|
|
|
414
420
|
legEl.innerHTML = (S.labs.color ? '<b style="color:'+T.ink+'">' +
|
|
415
421
|
richLabel('color', S.labs.color) + '</b>' : '') +
|
|
416
422
|
S.legend.map((e, i) => '<div class="lg-e" data-ci="' + (e.ci != null ? e.ci : i) +
|
|
423
|
+
(e.lk != null ? '" data-lk="' + plot3Esc(e.lk) : '') +
|
|
417
424
|
'">' + keyHTML(e, e.color) +
|
|
418
425
|
legendLabel(e) + '</div>').join('') + barHTML() + szHTML;
|
|
419
426
|
legEl.addEventListener('click', ev => {
|
|
420
427
|
const row = ev.target.closest('.lg-e');
|
|
421
428
|
if (!row) return;
|
|
422
|
-
const
|
|
423
|
-
if (
|
|
424
|
-
|
|
425
|
-
|
|
429
|
+
const lk = row.dataset.lk;
|
|
430
|
+
if (lk != null) {
|
|
431
|
+
if (hiddenKeys.has(lk)) hiddenKeys.delete(lk); else hiddenKeys.add(lk);
|
|
432
|
+
row.style.opacity = hiddenKeys.has(lk) ? 0.35 : 1;
|
|
433
|
+
for (const o of (keyObjs.get(lk) || [])) o.visible = !hiddenKeys.has(lk);
|
|
434
|
+
} else {
|
|
435
|
+
const ci = +row.dataset.ci;
|
|
436
|
+
if (hiddenCats.has(ci)) hiddenCats.delete(ci); else hiddenCats.add(ci);
|
|
437
|
+
row.style.opacity = hiddenCats.has(ci) ? 0.35 : 1;
|
|
438
|
+
for (const o of (catObjs.get(ci) || [])) o.visible = !hiddenCats.has(ci);
|
|
439
|
+
}
|
|
426
440
|
if (window.__plot3.afterLegend) window.__plot3.afterLegend();
|
|
427
441
|
tip.style.display = 'none';
|
|
428
442
|
redraw();
|
|
@@ -607,6 +621,16 @@ renderer.setPixelRatio(window.devicePixelRatio);
|
|
|
607
621
|
renderer.setClearColor(0x000000, 0);
|
|
608
622
|
host.appendChild(renderer.domElement);
|
|
609
623
|
const scene = new THREE.Scene();
|
|
624
|
+
{
|
|
625
|
+
const add0 = scene.add.bind(scene);
|
|
626
|
+
scene.add = (...objs) => {
|
|
627
|
+
if (currentLK != null) {
|
|
628
|
+
if (!keyObjs.has(currentLK)) keyObjs.set(currentLK, []);
|
|
629
|
+
keyObjs.get(currentLK).push(...objs);
|
|
630
|
+
}
|
|
631
|
+
return add0(...objs);
|
|
632
|
+
};
|
|
633
|
+
}
|
|
610
634
|
const lineMats = [];
|
|
611
635
|
|
|
612
636
|
// Point symbols (aes(shape=) / geom_point(shape=)) as white sprites tinted
|
|
@@ -1614,6 +1638,7 @@ if (!S.is3d) {
|
|
|
1614
1638
|
return addToScene(...objs);
|
|
1615
1639
|
};
|
|
1616
1640
|
for (const L of S.layers) {
|
|
1641
|
+
currentLK = L.lk != null ? L.lk : null;
|
|
1617
1642
|
if (L.blank) continue; // geom_blank: on the scales only
|
|
1618
1643
|
paintOrder += 1;
|
|
1619
1644
|
const n = L.n;
|
|
@@ -1937,6 +1962,7 @@ if (!S.is3d) {
|
|
|
1937
1962
|
});
|
|
1938
1963
|
}
|
|
1939
1964
|
}
|
|
1965
|
+
currentLK = null;
|
|
1940
1966
|
scene.add = addToScene;
|
|
1941
1967
|
|
|
1942
1968
|
function drawAxes() {
|
|
@@ -2267,6 +2293,7 @@ if (!S.is3d) {
|
|
|
2267
2293
|
if (!best || score < best.score) best = { score, sx, sy, html, hold: !!hold };
|
|
2268
2294
|
}
|
|
2269
2295
|
for (const L of S.layers) {
|
|
2296
|
+
if (layerHidden(L)) continue;
|
|
2270
2297
|
if (L.kind === 'col') {
|
|
2271
2298
|
// Full bar rectangle (not just the top-center point).
|
|
2272
2299
|
const hw = (L.width || 0.08) * 0.5;
|
|
@@ -2445,6 +2472,7 @@ if (!S.is3d) {
|
|
|
2445
2472
|
}
|
|
2446
2473
|
|
|
2447
2474
|
for (const L of S.layers) {
|
|
2475
|
+
currentLK = L.lk != null ? L.lk : null;
|
|
2448
2476
|
if (L.blank) continue; // geom_blank: on the scales only
|
|
2449
2477
|
const n = L.n;
|
|
2450
2478
|
const cols = layerColors(L, hex2rgb(T.cat[0]));
|
|
@@ -2528,6 +2556,7 @@ if (!S.is3d) {
|
|
|
2528
2556
|
}
|
|
2529
2557
|
}
|
|
2530
2558
|
}
|
|
2559
|
+
currentLK = null;
|
|
2531
2560
|
|
|
2532
2561
|
// Axes box as matplotlib and plotly draw it: the three far walls with
|
|
2533
2562
|
// grid lines, refreshed as the camera orbits. The edges at the near
|
|
@@ -2706,6 +2735,7 @@ if (!S.is3d) {
|
|
|
2706
2735
|
let best = null, bestD = Infinity;
|
|
2707
2736
|
const maxScan = 80000;
|
|
2708
2737
|
for (const { L } of pickLayers) {
|
|
2738
|
+
if (layerHidden(L)) continue;
|
|
2709
2739
|
const n = L._stepN != null ? L._stepN : L.n;
|
|
2710
2740
|
const step = n > maxScan ? Math.ceil(n / maxScan) : 1;
|
|
2711
2741
|
const xs = L._x || L.x.data;
|
|
@@ -671,3 +671,33 @@ def test_swept_parameter_is_not_frozen_into_labels():
|
|
|
671
671
|
)
|
|
672
672
|
assert "t = 0" not in spec
|
|
673
673
|
assert "(a = 2)" in spec # fixed coefficients still show their value
|
|
674
|
+
|
|
675
|
+
|
|
676
|
+
def test_default_slider_steps_shrink_to_fit():
|
|
677
|
+
from plot3 import geom_function
|
|
678
|
+
|
|
679
|
+
g = (
|
|
680
|
+
ggplot()
|
|
681
|
+
+ geom_function("y = a*(x-h)^2 + k", xlim=(-5, 5))
|
|
682
|
+
+ slider(a=(0.2, 3), h=(-3, 3), k=(-3, 3))
|
|
683
|
+
)
|
|
684
|
+
spec, _ = build_spec(g)
|
|
685
|
+
assert [p["n"] for p in spec["slider"]["params"]] == [9, 9, 9]
|
|
686
|
+
assert spec["slider"]["nFrames"] == 729
|
|
687
|
+
# The figure's own slider keeps its default for later renders.
|
|
688
|
+
assert g.slider.steps == 25
|
|
689
|
+
|
|
690
|
+
|
|
691
|
+
def test_render_error_is_shown_instead_of_the_bare_repr():
|
|
692
|
+
from plot3 import geom_function
|
|
693
|
+
|
|
694
|
+
g = (
|
|
695
|
+
ggplot()
|
|
696
|
+
+ geom_function("y = a x + k")
|
|
697
|
+
+ slider(a=(0, 1), k=(0, 1), steps=2000)
|
|
698
|
+
)
|
|
699
|
+
bundle = g._repr_mimebundle_()
|
|
700
|
+
assert "plot3-error" in bundle["text/html"]
|
|
701
|
+
assert "smaller steps" in bundle["text/html"]
|
|
702
|
+
assert "ValueError" in bundle["text/plain"]
|
|
703
|
+
assert "smaller steps" in g._repr_html_()
|
|
@@ -13,6 +13,7 @@ from plot3 import (
|
|
|
13
13
|
geom_vector_field,
|
|
14
14
|
ggplot,
|
|
15
15
|
ggsave,
|
|
16
|
+
labs,
|
|
16
17
|
slider,
|
|
17
18
|
tangent,
|
|
18
19
|
)
|
|
@@ -134,6 +135,39 @@ def test_tangent_at_one_has_slope_two():
|
|
|
134
135
|
assert any(entry["label"] == "tangent" for entry in spec["legend"])
|
|
135
136
|
|
|
136
137
|
|
|
138
|
+
def test_legend_rows_name_the_layers_a_click_hides():
|
|
139
|
+
# The viewer hides every layer whose key matches the clicked row: the
|
|
140
|
+
# tangent row covers its line and the point at x = 1.
|
|
141
|
+
spec, _payloads = build_spec(
|
|
142
|
+
ggplot() + geom_function("y = x^3 - 3x") + tangent(at=1) + derivative()
|
|
143
|
+
)
|
|
144
|
+
keys = {entry["label"]: entry["lk"] for entry in spec["legend"]}
|
|
145
|
+
tangent_layers = [layer for layer in spec["layers"] if layer.get("lk") == keys["tangent"]]
|
|
146
|
+
assert sorted(layer["kind"] for layer in tangent_layers) == ["line", "point"]
|
|
147
|
+
assert len(set(keys.values())) == 3
|
|
148
|
+
# Stable keys: the same figure builds the same spec.
|
|
149
|
+
again, _payloads = build_spec(
|
|
150
|
+
ggplot() + geom_function("y = x^3 - 3x") + tangent(at=1) + derivative()
|
|
151
|
+
)
|
|
152
|
+
assert [entry["lk"] for entry in again["legend"]] == list(keys.values())
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
def test_curve_keeps_its_row_beside_a_tangent_and_derivative():
|
|
156
|
+
spec, _payloads = build_spec(
|
|
157
|
+
ggplot() + geom_function("y = x^3 - 3x") + tangent(at=1) + derivative()
|
|
158
|
+
)
|
|
159
|
+
labels = [entry["label"] for entry in spec["legend"]]
|
|
160
|
+
assert labels[0] == spec["labs"]["title"]
|
|
161
|
+
assert "tangent" in labels and len(labels) == 3
|
|
162
|
+
titled, _payloads = build_spec(
|
|
163
|
+
ggplot() + geom_function("y = x^2") + tangent(at=1) + labs(title="Slope")
|
|
164
|
+
)
|
|
165
|
+
assert len(titled["legend"]) == 2
|
|
166
|
+
# Alone, the curve's row would only repeat the title.
|
|
167
|
+
alone, _payloads = build_spec(ggplot() + geom_function("y = x^2"))
|
|
168
|
+
assert alone["legend"] is None
|
|
169
|
+
|
|
170
|
+
|
|
137
171
|
def test_derivative_is_the_slope_curve():
|
|
138
172
|
layers = _layers(ggplot() + geom_function("y = x^2", xlim=(-2, 2), n=11) + derivative())
|
|
139
173
|
curve = next(
|
plot3-0.6.6/plot3/__version__.py
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__ = "0.6.6"
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|