| 1 | package Chart::GGPlot::Theme::Functions; | ||
| 2 | |||
| 3 | # ABSTRACT: Function interface of Chart::GGPlot::Theme | ||
| 4 | |||
| 5 | use Chart::GGPlot::Setup; | ||
| 6 | |||
| 7 | our $VERSION = '0.002003'; # VERSION | ||
| 8 | |||
| 9 | use Chart::GGPlot::Theme; | ||
| 10 | use Chart::GGPlot::Types qw(:all); | ||
| 11 | use Chart::GGPlot::Util qw(:all); | ||
| 12 | |||
| 13 | use parent qw(Exporter::Tiny); | ||
| 14 | |||
| 15 | our @EXPORT_OK = qw(theme update_theme); | ||
| 16 | |||
| 17 | sub theme { | ||
| 18 | return Chart::GGPlot::Theme->new(@_); | ||
| 19 | } | ||
| 20 | |||
| 21 | fun update_theme(Theme $old_theme, Theme $new_theme) { | ||
| 22 | # If newtheme is a "complete" theme, then it is meant to replace | ||
| 23 | # oldtheme; this function just returns newtheme. | ||
| 24 | return $new_theme if ($new_theme->complete); | ||
| 25 | |||
| 26 | # These are elements in newtheme that aren't already set in oldtheme. | ||
| 27 | # They will be pulled from the default theme. | ||
| 28 | my $new_items = aref_diff($old_theme->names, $new_theme->names); | ||
| 29 | for my $name (@$new_items) { | ||
| 30 | $old_theme->set($name, $ggplot_global->theme_current->at($name)); | ||
| 31 | } | ||
| 32 | |||
| 33 | my $old_validate = $old_theme->validate; | ||
| 34 | my $new_validate = $new_theme->validate; | ||
| 35 | $old_theme->validate = ($old_validate and $new_validate); | ||
| 36 | |||
| 37 | return $old_theme->add_theme($new_theme); | ||
| 38 | } | ||
| 39 | |||
| 40 | 1; | ||
| 41 | |||
| 42 | __END__ |