Skip to content

Commit

Permalink
rector
Browse files Browse the repository at this point in the history
  • Loading branch information
marco76tv committed Sep 5, 2023
1 parent 96efb75 commit 3bc4476
Show file tree
Hide file tree
Showing 19 changed files with 190 additions and 182 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/rector.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Inspiration https://github.com/symplify/symplify/blob/main/.github/workflows/rector.yaml
name: Rector

on:
pull_request: null

jobs:
rector:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
with:
token: "${{ secrets.ACCESS_TOKEN || secrets.GITHUB_TOKEN }}"

- uses: shivammathur/setup-php@v2
with:
php-version: 8.1

- uses: "ramsey/composer-install@v2"

- run: vendor/bin/rector --ansi

- uses: EndBug/[email protected]
with:
add: .
message: "[ci-review] Rector Rectify"
author_name: "GitHub Action"
author_email: "[email protected]"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2 changes: 1 addition & 1 deletion Actions/Chart/GetTypeOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,6 @@ public function execute(): array
$data[$k1] = 'mixed:' . $v;
}

return array_merge($options, $data);
return [...$options, ...$data];
}
}
32 changes: 16 additions & 16 deletions Actions/JpGraph/ApplyGraphStyleAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,51 +13,51 @@ class ApplyGraphStyleAction
{
use QueueableAction;

public function execute(Graph &$graph, ChartData $chart): Graph
public function execute(Graph &$graph, ChartData $chartData): Graph
{
// Nice shadow
$graph->SetShadow();

$graph->SetBox($chart->show_box);
$graph->SetBox($chartData->show_box);

$graph->footer->right->SetFont($chart->font_family, $chart->font_style);
$graph->footer->right->SetFont($chartData->font_family, $chartData->font_style);
// $graph->footer->right->Set('Totale Risposte '.$this->vars['tot']);
if (null !== $graph->xaxis) {
$this->applyGraphXStyle($graph->xaxis, $chart);
$this->applyGraphXStyle($graph->xaxis, $chartData);
}
if (null !== $graph->yaxis) {
$this->applyGraphYStyle($graph->yaxis, $chart);
$this->applyGraphYStyle($graph->yaxis, $chartData);
}

return $graph;
}

public function applyGraphXStyle(Axis &$xaxis, ChartData $data): void
public function applyGraphXStyle(Axis &$axis, ChartData $chartData): void
{
$xaxis->SetFont($data->font_family, $data->font_style, $data->font_size);
$xaxis->SetLabelAngle($data->x_label_angle);
$axis->SetFont($chartData->font_family, $chartData->font_style, $chartData->font_size);
$axis->SetLabelAngle($chartData->x_label_angle);
// Some extra margin looks nicer
$xaxis->SetLabelMargin($data->x_label_margin);
$axis->SetLabelMargin($chartData->x_label_margin);
// Label align for X-axis
// $graph->xaxis->SetLabelAlign('right', 'center');
}

public function applyGraphYStyle(Axis &$yaxis, ChartData $data): void
public function applyGraphYStyle(Axis &$axis, ChartData $chartData): void
{
// Add some grace to y-axis so the bars doesn't go
// all the way to the end of the plot area
// "restringe" la visualizzazione delle barre
$yaxis->scale->SetGrace($data->y_grace);
$axis->scale->SetGrace($chartData->y_grace);
// dddx($style['yaxis_hide']);
// We don't want to display Y-axis
// visualizza delle colonne verticali "in sottofondo/di riferimento"
// if (null == $data->yaxis_hide || 0 == $data->yaxis_hide) {
if ($data->yaxis_hide) {
$yaxis->Hide();
if ($chartData->yaxis_hide) {
$axis->Hide();
}

$yaxis->HideZeroLabel();
$yaxis->HideLine(false);
$yaxis->HideTicks(false, false);
$axis->HideZeroLabel();
$axis->HideLine(false);
$axis->HideTicks(false, false);
}
}
42 changes: 20 additions & 22 deletions Actions/JpGraph/ApplyPlotStyleAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,68 +12,66 @@ class ApplyPlotStyleAction
{
use QueueableAction;

public function execute(BarPlot $plot, ChartData $data): BarPlot
public function execute(BarPlot $barPlot, ChartData $chartData): BarPlot
{
$colors = [];

// $plot->SetFillColor($colors); // trasparenza, da 0 a 1

// $plot->SetFillColor($this->data[5]['color'].'@'.$this->vars['transparency']); // trasparenza, da 0 a 1
$plot->SetFillColor($data->list_color ?? 'red@' . $data->transparency); // trasparenza, da 0 a 1
$barPlot->SetFillColor($chartData->list_color ?? 'red@' . $chartData->transparency); // trasparenza, da 0 a 1

// $bplot->SetShadow('darkgreen', 1, 1);
// dddx([get_defined_vars(), $this->vars]);

$plot->SetColor($data->list_color ?? 'red');
$barPlot->SetColor($chartData->list_color ?? 'red');

// You can change the width of the bars if you like
$plot->SetWidth($data->plot_perc_width / 100);
$barPlot->SetWidth($chartData->plot_perc_width / 100);
// $plot->SetWidth(10);

// We want to display the value of each bar at the top
// se tolto non mostra i valori
// Right side of || is always false.
// if (null == $data->plot_value_show || 0 == $data->plot_value_show) {
if ($data->plot_value_show) {
$plot->value->Show();
if ($chartData->plot_value_show) {
$barPlot->value->Show();
}

$plot->value->SetFont($data->font_family, $data->font_style, $data->font_size);
$barPlot->value->SetFont($chartData->font_family, $chartData->font_style, $chartData->font_size);

$plot->value->SetAlign('left', 'center');
$barPlot->value->SetAlign('left', 'center');
// colore del font che scrivi
if (null !== $data->plot_value_color) {
$plot->value->SetColor($data->plot_value_color);
if (null !== $chartData->plot_value_color) {
$barPlot->value->SetColor($chartData->plot_value_color);
} else {
$plot->value->SetColor('black', 'darkred');
$barPlot->value->SetColor('black', 'darkred');
}

// visualizza il risultato con % oppure no
// $plot->value->SetFormat('%.2f %');
// 2f significa 2 cifre decimali, 1f solo una cifra decimale
switch ($data->plot_value_format) {
switch ($chartData->plot_value_format) {
case 1:
$plot->value->SetFormat('%.1f %');
$barPlot->value->SetFormat('%.1f %');
break;
case 2:
$plot->value->SetFormat('%.1f');
$barPlot->value->SetFormat('%.1f');
break;
case 3:
$plot->value->SetFormat('%.0f');
$barPlot->value->SetFormat('%.0f');
break;
default:
$plot->value->SetFormat('%.1f %');
$barPlot->value->SetFormat('%.1f %');
}

// Center the values in the bar
// if (null == $data->plot_value_pos || 0 == $data->plot_value_pos) {
if (0 === $data->plot_value_pos) {
$plot->SetValuePos('center');
if (0 === $chartData->plot_value_pos) {
$barPlot->SetValuePos('center');
}

$plot->value->setAngle($data->x_label_angle);
$barPlot->value->setAngle($chartData->x_label_angle);
// $plot->value->setAngle(50);

return $plot;
return $barPlot;
}
}
64 changes: 32 additions & 32 deletions Actions/JpGraph/GetGraphAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,71 +14,71 @@ class GetGraphAction
{
use QueueableAction;

public function execute(ChartData $data): Graph
public function execute(ChartData $chartData): Graph
{
$graph = new Graph($data->width, $data->height, 'auto');
$graph = new Graph($chartData->width, $chartData->height, 'auto');
$graph->SetScale('textlin');
$graph->SetShadow();
$theme_class = new UniversalTheme;
$universalTheme = new UniversalTheme;

$graph->SetTheme($theme_class);
$graph->SetTheme($universalTheme);

if (isset($data->min)) {
$graph->yscale->SetAutoMin($data->min);
if (isset($chartData->min)) {
$graph->yscale->SetAutoMin($chartData->min);
}
if (isset($data->max)) {
$graph->yscale->SetAutoMax($data->max);
if (isset($chartData->max)) {
$graph->yscale->SetAutoMax($chartData->max);
}

if (isset($data->title)) {
$graph->title->Set($data->title);
$graph->title->SetFont($data->font_family, $data->font_style, 11);
if ($chartData->title !== null) {
$graph->title->Set($chartData->title);
$graph->title->SetFont($chartData->font_family, $chartData->font_style, 11);
}
if (isset($data->subtitle)) {
$graph->subtitle->Set($data->subtitle);
$graph->subtitle->SetFont($data->font_family, $data->font_style, 11);
if ($chartData->subtitle !== null) {
$graph->subtitle->Set($chartData->subtitle);
$graph->subtitle->SetFont($chartData->font_family, $chartData->font_style, 11);
}
if (isset($data->footer)) {
$graph->footer->center->Set($data->footer);
$graph->footer->center->SetFont($data->font_family, $data->font_style, 10);
if ($chartData->footer !== null) {
$graph->footer->center->Set($chartData->footer);
$graph->footer->center->SetFont($chartData->font_family, $chartData->font_style, 10);
}

$graph->SetBox($data->show_box);
$graph->SetBox($chartData->show_box);

$graph->footer->right->SetFont($data->font_family, $data->font_style);
$graph->footer->right->SetFont($chartData->font_family, $chartData->font_style);

$this->applyGraphXStyle($graph->xaxis, $data);
$this->applyGraphYStyle($graph->yaxis, $data);
$this->applyGraphXStyle($graph->xaxis, $chartData);
$this->applyGraphYStyle($graph->yaxis, $chartData);

return $graph;
}

public function applyGraphXStyle(Axis &$xaxis, ChartData $data): void
public function applyGraphXStyle(Axis &$axis, ChartData $chartData): void
{
$xaxis->SetFont($data->font_family, $data->font_style, $data->font_size);
$xaxis->SetLabelAngle($data->x_label_angle);
$axis->SetFont($chartData->font_family, $chartData->font_style, $chartData->font_size);
$axis->SetLabelAngle($chartData->x_label_angle);
// Some extra margin looks nicer
$xaxis->SetLabelMargin($data->x_label_margin);
$axis->SetLabelMargin($chartData->x_label_margin);
// Label align for X-axis
// $graph->xaxis->SetLabelAlign('right', 'center');
}

public function applyGraphYStyle(Axis &$yaxis, ChartData $data): void
public function applyGraphYStyle(Axis &$axis, ChartData $chartData): void
{
// Add some grace to y-axis so the bars doesn't go
// all the way to the end of the plot area
// "restringe" la visualizzazione delle barre
$yaxis->scale->SetGrace($data->y_grace);
$axis->scale->SetGrace($chartData->y_grace);
// dddx($style['yaxis_hide']);
// We don't want to display Y-axis
// visualizza delle colonne verticali "in sottofondo/di riferimento"
// if (null == $data->yaxis_hide || 0 == $data->yaxis_hide) {
if ($data->yaxis_hide) {
$yaxis->Hide();
if ($chartData->yaxis_hide) {
$axis->Hide();
}

$yaxis->HideZeroLabel();
$yaxis->HideLine(false);
$yaxis->HideTicks(false, false);
$axis->HideZeroLabel();
$axis->HideLine(false);
$axis->HideTicks(false, false);
}
}
26 changes: 11 additions & 15 deletions Actions/JpGraph/V1/Bar2Action.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,19 @@ class Bar2Action
{
use QueueableAction;

public function execute(AnswersChartData $answerChartData): Graph
public function execute(AnswersChartData $answersChartData): Graph
{
$data = $answerChartData->answers->toCollection()->pluck('avg')->all();
$data1 = $answerChartData->answers->toCollection()->pluck('value')->all();
$data = $answersChartData->answers->toCollection()->pluck('avg')->all();
$data1 = $answersChartData->answers->toCollection()->pluck('value')->all();
$legends = [0];
if (isset($data1[0]) && is_array($data1[0])) { // questionario multiplo
$legends = array_keys($data1[0]);
$data = $answerChartData->answers->toCollection()->pluck('value')->all();
$data1 = $answerChartData->answers->toCollection()->pluck('avg')->all();
$data = $answersChartData->answers->toCollection()->pluck('value')->all();
$data1 = $answersChartData->answers->toCollection()->pluck('avg')->all();
}

$labels = $answerChartData->answers->toCollection()->pluck('label')->all();
$chart = $answerChartData->chart;
$labels = $answersChartData->answers->toCollection()->pluck('label')->all();
$chart = $answersChartData->chart;
$graph = app(GetGraphAction::class)->execute($chart);
$graph->img->SetMargin(50, 50, 50, 100);
$graph->ygrid->SetFill(false);
Expand All @@ -41,7 +41,7 @@ public function execute(AnswersChartData $answerChartData): Graph
$graph->yaxis->HideTicks(false, false);
$graph->yscale->ticks->SupressZeroLabel(false);

$graph->xaxis->SetTickLabels($labels) + 10;
$graph->xaxis->SetTickLabels($labels);

/*
$bplot = new BarPlot($data);
Expand All @@ -63,11 +63,7 @@ public function execute(AnswersChartData $answerChartData): Graph
$bplot = [];

foreach ($legends as $i => $legend) {
if (0 === $legend) {
$tmp_data = $data;
} else {
$tmp_data = array_column($data, $legend);
}
$tmp_data = 0 === $legend ? $data : array_column($data, $legend);

// dddx(['data' => $data, 'tmp_data' => $tmp_data]);
$tmp = new BarPlot($tmp_data);
Expand All @@ -91,9 +87,9 @@ public function execute(AnswersChartData $answerChartData): Graph
}

// Create the grouped bar plot
$gbplot = new GroupBarPlot($bplot);
$groupBarPlot = new GroupBarPlot($bplot);
// ...and add it to the graPH
$graph->Add($gbplot);
$graph->Add($groupBarPlot);

// $graph->Add($bplot);

Expand Down
14 changes: 7 additions & 7 deletions Actions/JpGraph/V1/Bar3Action.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ class Bar3Action
{
use QueueableAction;

public function execute(AnswersChartData $answerChartData): Graph
public function execute(AnswersChartData $answersChartData): Graph
{
$chart = $answerChartData->chart;
$answers = $answerChartData->answers;
$chart = $answersChartData->chart;
$answers = $answersChartData->answers;
$graph = app(GetGraphAction::class)->execute($chart);
$graph->img->SetMargin(50, 50, 50, 100);
$labels = $answers->toCollection()->pluck('label')->all();
Expand Down Expand Up @@ -67,10 +67,10 @@ public function execute(AnswersChartData $answerChartData): Graph
}

// Create the grouped bar plot
$gbplot = new AccBarPlot($bplot);
$gbplot->SetWidth($chart->plot_perc_width / 100);
$accBarPlot = new AccBarPlot($bplot);
$accBarPlot->SetWidth($chart->plot_perc_width / 100);
// ...and add it to the graPH
$graph->Add($gbplot);
$graph->Add($accBarPlot);

if (count($datay) > 1) {
// dddx($this->data->first()['title_type']);
Expand All @@ -82,7 +82,7 @@ public function execute(AnswersChartData $answerChartData): Graph
$graph->title->SetFont($chart->font_family, $chart->font_style, 11);
}

if (isset($chart->totali)) {
if (property_exists($chart, 'totali') && $chart->totali !== null) {
$str = '';
foreach ($chart->totali as $k => $v) {
$str .= $k . ' ' . $v . ' - ';
Expand Down
Loading

0 comments on commit 3bc4476

Please sign in to comment.