Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalidate the viewport and svg when a new element is added #4

Merged
merged 1 commit into from
Jun 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/SVG/Timeline.pm
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ around 'add_event' => sub {
my $orig = shift;
my $self = shift;

$self->_clear_viewbox;
$self->_clear_svg;

my $index = $self->count_events + 1;
$_[0]->{index} = $index;

Expand Down Expand Up @@ -136,6 +139,7 @@ has viewbox => (
is => 'ro',
isa => 'Str',
lazy_build => 1,
clearer => '_clear_viewbox',
);

sub _build_viewbox {
Expand All @@ -158,6 +162,7 @@ has svg => (
is => 'ro',
isa => 'SVG',
lazy_build => 1,
clearer => '_clear_svg',
handles => [qw[xmlify line text rect cdata]],
);

Expand Down
11 changes: 11 additions & 0 deletions t/01-basic.t
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,17 @@ $tl->add_event({
is($tl->count_events, 1, 'Correct number of events');
is($tl->events->[0]->index, 1, 'Correct index for event');
isa_ok($tl->svg, 'SVG');
my $vb1 = $tl->svg->getChildren->[0]{viewBox};

$tl->add_event({
start => 1991,
end => localtime->year,
text => 'Python',
});
is($tl->count_events, 2, 'Correct number of events');

my $vb2 = $tl->svg->getChildren->[0]{viewBox};
isnt($vb1, $vb2, 'Viewbox changed');

my $diag = $tl->draw;

Expand Down