ONO::Lib::PDF::Elements::Bar

package ONO::Lib::PDF::Elements::Bar;
################################################################################
# COPYRIGHT / LICENSE #
################################################################################
#
# This file is part of the ONO Software Project.
#
# Copyright (C) 2000-2025 Jos KIRPS [ www.kirps.com | jos_AT_kirps_DOT_com ]
# and The Joopita Project [ www.joopita.org | contact_AT_joopita_DOT_com ]
#
# This file, as well as other parts of the ONO Software Project or related
# elements, are FREE SOFTWARE available under the ARTISTIC LICENSE 2.0.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#
# For the full license, see /ono/osr/license/LICENSE.txt, or write to
# jos_AT_kirps_DOT_com or contact_AT_joopita_DOT_com.
#
################################################################################
# END OF COPYRIGHT / LICENSE, HERE COMES THE CODE ... #
################################################################################

use strict;

use ONO::Lib::PDF::Draw;
use ONO::Lib::Image::Canvas::Draw;

#: This module generates specific PDF content.

sub bar {

#: Not implemented (yet)

}

sub percent_box {

my (
$self,
$canvas,
$x,
$y,
$width,
$height,
$weight,
$percent,
) = @_;

#: This generates a percentage display box.

eval "use PDF::Reuse";
if (!$@) {

ONO::Lib::PDF::Draw->rect($canvas,$x,$y,$x+$width,$y+$height,$weight,"","",2);

ONO::Lib::PDF::Draw->line($canvas,$x+$height,$y,$x+$height,$y+$height,1);

ONO::Lib::PDF::Draw->text($canvas,$x+$height/2,$y+$height/2+1.5,"$percent\%","c");

&percent("",$canvas,$x+$height+2,$y+3,$width-$height-4,$height-6,$percent,"bt");

}

}

sub percent {

my (
$self,
$canvas,
$x,
$y,
$width,
$height,
$percent,
$switches,
$fontsize,
) = @_;

#: This generates a percentage display bar.
#:
#: Height is the height of the main bar, optional elements may be place above
#: y or below y+height.
#:
#: Switches:
#:
#: -b line over bottom
#: -B display percent below
#: -t line over top
#: -T display percent on top

eval "use PDF::Reuse";
if (!$@) {

if ($fontsize) {
ONO::Lib::PDF::Draw->font("",$fontsize);
}

ONO::Lib::PDF::Draw->line($canvas,$x,$y,$x+$width,$y);
ONO::Lib::PDF::Draw->line($canvas,$x,$y+$height,$x+$width,$y+$height);

my $wsplit = $width/10;
my ($over_top,$over_bot);

if ($switches =~ /t/) {
$over_top = $height/4;
}
if ($switches =~ /b/) {
$over_bot = $height/4;
}

for (my $i = 0; $i < 11; $i++) {

my $p = 0;
if ($i) {
$p = "${i}0";
}

ONO::Lib::PDF::Draw->line($canvas,$x+$i*$wsplit,$y-$over_top,$x+$i*$wsplit,$y+$height+$over_bot);

if ($switches =~ /T/) {
ONO::Lib::PDF::Draw->text($canvas,$x+0.5+$i*$wsplit,$y-$over_top-1,"$p\%","c");
}
if ($switches =~ /B/) {
ONO::Lib::PDF::Draw->text($canvas,$x+0.5+$i*$wsplit,$y+$height+$over_bot+$fontsize/2.75,"$p\%","c");
}
}

if ($percent) {
ONO::Lib::PDF::Draw->line($canvas,$x,$y+$height/2,$x+($width/100*$percent),$y+$height/2,$height);
}

}

}

###############################################################################
# end of script
###############################################################################

1;

__END__