has
'+additive'
=> (
default
=>
sub
{ 1 } );
override
(
'finalize'
,
sub
{
my
(
$self
) =
@_
;
my
$height
=
$self
->height;
my
$width
=
$self
->width;
my
$clicker
=
$self
->clicker;
my
%accum
;
my
$dses
=
$clicker
->get_datasets_for_context(
$self
->context);
foreach
my
$ds
(@{
$dses
}) {
foreach
my
$series
(@{
$ds
->series }) {
my
$ctx
=
$clicker
->get_context(
$ds
->context);
my
$domain
=
$ctx
->domain_axis;
my
$range
=
$ctx
->range_axis;
my
$lastx
;
my
@vals
= @{
$series
->
values
};
my
@keys
= @{
$series
->
keys
};
my
$startx
;
my
$biggest
;
my
@replays
;
for
(0..(
$series
->key_count - 1)) {
my
$key
=
$keys
[
$_
];
my
$x
=
$domain
->mark(
$width
,
$key
);
next
unless
defined
(
$x
);
my
$val
=
$vals
[
$_
];
if
(
exists
(
$accum
{
$key
})) {
push
(
@replays
, [
$x
,
$accum
{
$key
}]);
$val
=
$accum
{
$key
} +=
$val
;
}
else
{
push
(
@replays
, [
$x
, 0 ]);
$accum
{
$key
} =
$val
;
}
my
$ymark
=
$range
->mark(
$height
,
$val
);
next
unless
defined
(
$ymark
);
my
$y
=
$height
-
$ymark
;
if
(
defined
(
$biggest
)) {
$biggest
=
$y
if
$y
>
$biggest
;
}
else
{
$biggest
=
$y
;
}
if
(
$_
== 0) {
$startx
=
$x
;
$self
->move_to(
$x
,
$y
);
}
else
{
$self
->line_to(
$x
,
$y
);
}
$lastx
=
$x
;
}
my
$color
=
$self
->clicker->color_allocator->
next
;
my
$op
= Graphics::Primitive::Operation::Stroke->new;
$op
->preserve(1);
$op
->brush(
$self
->brush->clone);
$op
->brush->color(
$color
);
$self
->
do
(
$op
);
while
(
my
$pt
=
pop
(
@replays
)) {
$self
->line_to(
$pt
->[0],
$height
-
$range
->mark(
$height
,
$pt
->[1]));
}
$self
->close_path;
my
$paint
;
if
(
$self
->opacity) {
my
$clone
=
$color
->clone;
$clone
->alpha(
$self
->opacity);
$paint
= Graphics::Primitive::Paint::Solid->new(
color
=>
$clone
);
}
elsif
(
$self
->fade) {
my
$clone
=
$color
->clone;
$clone
->alpha(
$self
->opacity);
$paint
= Graphics::Primitive::Paint::Gradient::Linear->new(
line
=> Geometry::Primitive::Line->new(
start
=> Geometry::Primitive::Point->new(
x
=> 0,
y
=> 0),
end
=> Geometry::Primitive::Point->new(
x
=> 1,
y
=>
$biggest
),
),
style
=>
'linear'
);
$paint
->add_stop(1.0,
$color
);
$paint
->add_stop(0,
$clone
);
}
else
{
$paint
= Graphics::Primitive::Paint::Solid->new(
color
=>
$color
->clone
);
}
my
$fillop
= Graphics::Primitive::Operation::Fill->new(
paint
=>
$paint
);
$self
->
do
(
$fillop
);
}
}
return
1;
});
__PACKAGE__->meta->make_immutable;
no
Moose;
1;