|
15 | 15 | import abc |
16 | 16 | import inspect |
17 | 17 | import logging |
| 18 | +from collections import abc as cabc |
18 | 19 | from collections import defaultdict, namedtuple |
19 | 20 | from functools import partial, partialmethod, wraps |
20 | 21 | from typing import Any, Collection, List, Mapping, NamedTuple, Optional, Tuple, Union |
@@ -397,6 +398,7 @@ class PlotArgs(NamedTuple): |
397 | 398 | #: If given, overrides :active plotter`. |
398 | 399 | plotter: "graphtik.plot.Plotter" = None |
399 | 400 | #: If given, overrides :term:`plot theme` plotter will use. |
| 401 | + #: It can be any mapping, in which case it overrite the :term:`current theme`. |
400 | 402 | theme: "graphtik.plot.Theme" = None |
401 | 403 |
|
402 | 404 | ####### |
@@ -509,8 +511,8 @@ def plot( |
509 | 511 |
|
510 | 512 | :seealso: :attr:`.PlotArgs.plotter` |
511 | 513 | :param theme: |
512 | | - Any :term:`plot theme` overrides; if none, the :attr:`.Plotter.default_theme` |
513 | | - of the :term:`active plotter` is used. |
| 514 | + Any :term:`plot theme` or dictionary overrides; if none, |
| 515 | + the :attr:`.Plotter.default_theme` of the :term:`active plotter` is used. |
514 | 516 |
|
515 | 517 | :seealso: :attr:`.PlotArgs.theme` |
516 | 518 | :param name: |
@@ -697,11 +699,21 @@ def plot( |
697 | 699 |
|
698 | 700 | plot_args = PlotArgs(**kw) |
699 | 701 |
|
700 | | - from .plot import Plotter, get_active_plotter |
| 702 | + from .plot import Plotter, Theme, get_active_plotter |
701 | 703 |
|
| 704 | + ## Ensure a valid plotter in the args asap. |
| 705 | + # |
702 | 706 | if plotter and not isinstance(plotter, Plotter): |
703 | 707 | raise TypeError(f"Invalid `plotter` argument given: {plotter}") |
704 | | - plot_args = plot_args._replace(plotter=plotter or get_active_plotter()) |
| 708 | + if not plotter: |
| 709 | + plotter = get_active_plotter() |
| 710 | + plot_args = plot_args._replace(plotter=plotter) |
| 711 | + |
| 712 | + ## Overwrite any dictionaries over active theme asap. |
| 713 | + # |
| 714 | + if isinstance(theme, cabc.Mapping): |
| 715 | + theme = plotter.default_theme.withset(**theme) |
| 716 | + plot_args = plot_args._replace(theme=theme) |
705 | 717 |
|
706 | 718 | plot_args = self.prepare_plot_args(plot_args) |
707 | 719 | assert plot_args.graph, plot_args |
|
0 commit comments