$Chart::Clicker::Renderer::Pie::VERSION
=
'2.90'
;
has
'border_color'
=> (
is
=>
'rw'
,
isa
=>
'Graphics::Color::RGB'
,
default
=>
sub
{ Graphics::Color::RGB->new },
);
has
'brush'
=> (
is
=>
'rw'
,
isa
=>
'Graphics::Primitive::Brush'
,
default
=>
sub
{ Graphics::Primitive::Brush->new }
);
has
'gradient_color'
=> (
is
=>
'rw'
,
isa
=>
'Graphics::Color::RGB'
,
predicate
=>
'has_gradient_color'
);
has
'gradient_reverse'
=> (
is
=>
'rw'
,
isa
=>
'Bool'
,
default
=> 0,
);
has
'starting_angle'
=> (
is
=>
'rw'
,
isa
=>
'Int'
,
default
=> -90,
);
my
$TO_RAD
= (4 *
atan2
(1, 1)) / 180;
override
(
'prepare'
,
sub
{
my
$self
=
shift
;
super;
my
$clicker
=
$self
->clicker;
my
$dses
=
$clicker
->get_datasets_for_context(
$self
->context);
foreach
my
$ds
(@{
$dses
}) {
foreach
my
$series
(@{
$ds
->series }) {
foreach
my
$val
(@{
$series
->
values
}) {
$self
->{ACCUM}->{refaddr(
$series
)} +=
$val
;
$self
->{TOTAL} +=
$val
;
}
}
}
});
override
(
'finalize'
,
sub
{
my
$self
=
shift
;
my
$clicker
=
$self
->clicker;
my
$radius
=
$self
->height;
if
(
$self
->width <
$self
->height) {
$radius
=
$self
->width;
}
$radius
=
$radius
/ 2;
$radius
-=
$self
->brush->width;
my
$height
=
$self
->height;
my
$linewidth
= 1;
my
$midx
=
$self
->width / 2;
my
$midy
=
$height
/ 2;
my
$pos
=
$self
->starting_angle;
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
$avg
=
$self
->{ACCUM}->{refaddr(
$series
)} /
$self
->{TOTAL};
my
$degs
= (
$avg
* 360) +
$pos
;
$self
->move_to(
$midx
,
$midy
);
$self
->arc(
$radius
,
$degs
*
$TO_RAD
,
$pos
*
$TO_RAD
);
$self
->close_path;
my
$color
=
$clicker
->color_allocator->
next
;
my
$paint
;
if
(
$self
->has_gradient_color) {
my
$gc
=
$self
->gradient_color;
my
$start_radius
= 0;
my
$end_radius
=
$radius
;
if
(
$self
->gradient_reverse) {
$start_radius
=
$radius
;
$end_radius
= 0;
}
$paint
= Graphics::Primitive::Paint::Gradient::Radial->new(
start
=> Geometry::Primitive::Circle->new(
origin
=> [
$midx
,
$midy
],
radius
=>
$start_radius
),
end
=> Geometry::Primitive::Circle->new(
origin
=> [
$midx
,
$midy
],
radius
=>
$end_radius
)
);
$paint
->add_stop(0,
$color
);
$paint
->add_stop(1,
$color
->clone(
red
=>
$color
->red + (
$gc
->red -
$color
->red) *
$gc
->alpha,
green
=>
$color
->green + (
$gc
->green -
$color
->green) *
$gc
->alpha,
blue
=>
$color
->blue + (
$gc
->blue -
$color
->blue) *
$gc
->alpha,
));
}
else
{
$paint
= Graphics::Primitive::Paint::Solid->new(
color
=>
$color
,
);
}
my
$fop
= Graphics::Primitive::Operation::Fill->new(
preserve
=> 1,
paint
=>
$paint
);
$self
->
do
(
$fop
);
my
$op
= Graphics::Primitive::Operation::Stroke->new;
$op
->brush(
$self
->brush->clone);
$op
->brush->color(
$self
->border_color);
$self
->
do
(
$op
);
$pos
=
$degs
;
}
}
return
1;
});
__PACKAGE__->meta->make_immutable;
no
Moose;
1;