App-Chart
view release on metacpan or search on metacpan
lib/App/Chart/Gtk2/HAxis.pm view on Meta::CPAN
Glib::ParamSpec->scalar
('timebase',
'timebase',
'A perl App::Chart::Timebase object.',
Glib::G_PARAM_READWRITE),
];
App::Chart::Gtk2::GUI::chart_style_class (__PACKAGE__);
use constant {
# height of small and medium tick marks, as a fraction of line_height, and
# then the gap between the medium tick and the labels similarly
SMALL_TICK_LINE_FRAC => 0.2,
MEDIUM_TICK_LINE_FRAC => 0.4,
MEDIUM_GAP_LINE_FRAC => 0.1,
# space at the left and right of the labels, in "em"s
LABEL_LEFT_SPACE_EMS => 0.7,
LABEL_RIGHT_SPACE_EMS => 1.2,
};
# strftime() is a bit slow, so do this with some private functions just
# concatenating bits. Each function is called like B_Y($year,$month,$day)
# and returns a string.
#
my @fullmonth;
my @shortmonth;
sub B_Y { return $fullmonth[$_[1]] . ' ' . $_[0]; }
sub b_Y { return $shortmonth[$_[1]] . ' ' . $_[0]; }
sub b_y { return sprintf '%s %02d', $shortmonth[$_[1]], $_[0] % 100; }
sub by { return sprintf '%s%02d', $shortmonth[$_[1]], $_[0] % 100; }
sub Y { return $_[0]; }
sub y { return sprintf '%02d', $_[0] % 100; }
# Possible format string func and timebase interval. The first one whose
# string output fits in the display in those timebase interval steps is
# used.
my @format_list = ([ \&B_Y, 'App::Chart::Timebase::Months' ], # "March 2007"
[ \&b_Y, 'App::Chart::Timebase::Months' ], # "Mar 2007"
[ \&b_y, 'App::Chart::Timebase::Months' ], # "Mar 07"
[ \&by, 'App::Chart::Timebase::Months' ], # "Mar07"
[ \&B_Y, 'App::Chart::Timebase::Quarters' ], # "March 2007"
[ \&b_Y, 'App::Chart::Timebase::Quarters' ], # "Mar 2007"
[ \&b_y, 'App::Chart::Timebase::Quarters' ], # "Mar 07"
[ \&by, 'App::Chart::Timebase::Quarters' ], # "Mar07"
[ \&Y, 'App::Chart::Timebase::Years' ], # "2007"
[ \&y, 'App::Chart::Timebase::Years' ], # "07"
[ \&Y, 'App::Chart::Timebase::Decades' ], # "2007"
[ \&y, 'App::Chart::Timebase::Decades' ]);# "07"
# possible timebases to use for drawing the marks
# the base $timebase is expected to be among these, then the medium marks
# are drawn in the one after that
my @marks_timebase_list = qw(App::Chart::Timebase::Days
App::Chart::Timebase::Weeks
App::Chart::Timebase::Months
App::Chart::Timebase::Quarters
App::Chart::Timebase::Years
App::Chart::Timebase::Decades);
Gtk2::Rc->parse_string (<<'HERE');
binding "App__Chart__Gtk2__HAxis_keys" {
bind "Pointer_Button1" { "start_drag" (1) }
}
# priority level "gtk" treating this as widget level default, for overriding
# by application or user RC
class "App__Chart__Gtk2__HAxis" binding:gtk "App__Chart__Gtk2__HAxis_keys"
HERE
sub INIT_INSTANCE {
my ($self) = @_;
$self->add_events (['button-press-mask',
'button-motion-mask',
'button-release-mask']);
$self->{'layout'} = $self->create_pango_layout ('');
if (! @fullmonth) {
my $fill = sub {
my ($fmt, $aref) = @_;
foreach my $mon (0 .. 11) {
$aref->[$mon+1]
= POSIX::Wide::strftime ($fmt,
0,0,0, # midnight
1,$mon,80, # 1st $mon 1980
0,0,0);
}
};
$fill->('%B', \@fullmonth);
$fill->('%b', \@shortmonth);
}
}
sub SET_PROPERTY {
my ($self, $pspec, $newval) = @_;
my $pname = $pspec->get_name;
$self->{$pname} = $newval; # per default GET_PROPERTY
if ($pname eq 'adjustment') {
my $adj = $newval;
my $ref_weak_self = App::Chart::Glib::Ex::MoreUtils::ref_weak ($self);
$self->{'adjustment_ids'} = $adj && Glib::Ex::SignalIds->new
($adj,
$adj->signal_connect (value_changed => \&_do_adj_value_changed,
$ref_weak_self),
$adj->signal_connect (changed => \&_do_adj_other_changed,
$ref_weak_self));
}
_reset_scale ($self);
$self->queue_draw;
}
# 'set-scroll-adjustments' class closure
sub _do_set_scroll_adjustments {
my ($self, $hadj, $vadj) = @_;
$self->set (adjustment => $hadj);
}
# mark that the scale has somehow changed, so the label_timebase and format
# should be recalculated (on the next draw)
sub _reset_scale {
my ($self) = @_;
$self->{'sizes'} = undef;
}
sub _establish_bases {
my ($self) = @_;
$self->{'sizes'} = undef; # if no adj etc
( run in 0.785 second using v1.01-cache-2.11-cpan-2398b32b56e )