Skip to content
Browse files

Got callback plottypes working!

  • Loading branch information...
1 parent 72e71d2 commit 8828977300983deff966a4dd99b439ac07854afe @run4flat committed Feb 24, 2012
Showing with 19 additions and 18 deletions.
  1. +3 −1 lib/PDL/Graphics/Prima/DataSet.pm
  2. +14 −13 lib/PDL/Graphics/Prima/PlotType.pm
  3. +2 −4 test/test-callback.pl
View
4 lib/PDL/Graphics/Prima/DataSet.pm
@@ -241,7 +241,9 @@ sub check_plot_types {
my $expected_plot_class = $self->expected_plot_class;
foreach (@plotTypes) {
croak("Plottype should be of type $expected_plot_class, but it is of type "
- . ref($_)) unless eval{$_->isa($expected_plot_class)};
+ . ref($_)) unless eval{$_->isa($expected_plot_class)}
+ or eval{$_->isa('PDL::Graphics::Prima::PlotType::CallBack')}
+ and eval{$_->{base_class}->isa($expected_plot_class)};
}
}
View
27 lib/PDL/Graphics/Prima/PlotType.pm
@@ -1986,12 +1986,12 @@ have properly converted the points you are trying to plot.
=cut
-sub draw {
- my $invocant = shift;
- my $class = ref($invocant) ? ref($invocant) : $invocant;
- croak("Plot type $class does not define its own drawing function. Please "
- . 'report this bug to the author');
-}
+#sub draw {
+# my $invocant = shift;
+# my $class = ref($invocant) ? ref($invocant) : $invocant;
+# croak("Plot type $class does not define its own drawing function. Please "
+# . 'report this bug to the author');
+#}
############################################
@@ -2023,7 +2023,7 @@ If you like the way that a class operates but want to use your own drawing
routines, you can specify a base class and a drawing callback like so:
my $smiley_plot_type = pt::CallBack(
- base_class => 'PDL::Graphics::Prima::PlotType::Blobs',
+ base_class => 'PDL::Graphics::Prima::PlotType::Pair::Blobs',
draw => sub {
my ($self, $dataset, $widget) = @_;
@@ -2058,14 +2058,16 @@ sub initialize {
PDL::Graphics::Prima::PlotType::initialize($self, @_);
# Default the base class to the most basic one:
- $self->{base_class} ||= 'PDL::Graphics::Prima::PlotType';
+ croak("You must supply a base class") unless $self->{base_class};
+ croak('Base class must be a valid PlotType')
+ unless eval{$self->{base_class}->isa('PDL::Graphics::Prima::PlotType')};
# Call the superclass initialization:
my $init = $self->{base_class}->can('initialize');
&$init($self, @_);
# Make sure that we have a valid draw function:
- if ($self->{base_class} eq 'PDL::Graphics::Prima::PlotType') {
+ unless ($self->{base_class}->can('draw')) {
croak('You must supply a draw function or a drawable base class to the CallBack plot class')
unless exists $self->{draw} and ref ($self->{draw})
and ref ($self->{draw}) eq 'CODE';
@@ -2079,10 +2081,9 @@ sub draw {
if (not exists $self->{draw}) {
# Didn't supply a draw function, so call the base class's draw function:
- if ($self->{base_class} eq 'PDL::Graphics::Prima::PlotType') {
- croak('CallBack plot type must supply a drawing function or '
- . 'a base class that can draw itself.');
- }
+ croak('CallBack plot type must supply a drawing function or '
+ . 'a base class that can draw itself.')
+ unless $self->{base_class}->can('draw');
# Masquerade as the base class:
my $class = ref($self);
View
6 test/test-callback.pl
@@ -15,7 +15,7 @@
);
my $smiley_plot_type = pt::CallBack(
- base_class => 'PDL::Graphics::Prima::PlotType::Blobs',
+ base_class => 'PDL::Graphics::Prima::PlotType::Pair::Blobs',
draw => sub {
my ($self) = @_;
@@ -34,10 +34,8 @@
$wDisplay->insert('Plot',
-# -data => [$t_series, $heights],
- -data => [$t_series, $heights, plotType => $smiley_plot_type],
+ -data => ds::Pair($t_series, $heights, plotType => $smiley_plot_type),
pack => { fill => 'both', expand => 1},
-# y => {scaling => sc::Log},
);
run Prima;

0 comments on commit 8828977

Please sign in to comment.
Something went wrong with that request. Please try again.