Generate images for translation status dynamically (#54)

This commit is contained in:
Jim Winstead
2024-10-23 10:24:10 -07:00
committed by GitHub
parent 749433d218
commit ff776cad3a
6 changed files with 80 additions and 101 deletions

1
.gitignore vendored
View File

@ -5,6 +5,5 @@ sqlite
git
log
shared
www/images
www/robots.txt
www/doc

View File

@ -103,7 +103,7 @@ function nav_tools($lang)
$out .= '<li><a href="revcheck.php?p=misstags&amp;lang='.$lang.'">Missing revision numbers</a></li>';
$out .= '<li><a href="revcheck.php?p=missfiles&amp;lang='.$lang.'">Untranslated files</a></li>';
$out .= '<li><a href="revcheck.php?p=oldfiles&amp;lang='.$lang.'">Not in EN tree</a></li>';
$out .= '<li><a href="revcheck.php?p=graph&amp;lang='.$lang.'">Graph</a></li>';
$out .= '</ul></div></div>';
$out .= '</ul>';
$out .= '</div></div>';
return $out;
}

View File

@ -1,75 +0,0 @@
<?php
include '../include/jpgraph/src/jpgraph.php';
include '../include/jpgraph/src/jpgraph_bar.php';
include '../include/init.inc.php';
include '../include/lib_revcheck.inc.php';
$idx = new SQLite3(SQLITE_DIR . 'rev.php.sqlite');
$language = revcheck_available_languages($idx);
sort($language);
$files_EN = count_en_files($idx);
foreach ($language as $lang) {
$tmp = get_stats($idx, $lang, 'uptodate');
$percent_tmp[] = round($tmp[0] * 100 / $files_EN);
$legend_tmp[] = $lang;
}
$percent = array_values($percent_tmp);
$legend = array_values($legend_tmp);
echo "Generating PHP graphic for all languages...";
generate_image();
echo " Done.\n";
function generate_image() {
global $percent, $legend;
// Create the graph. These two calls are always required
$graph = new Graph(600,262);
$graph->SetScale("textlin");
$graph->yaxis->scale->SetGrace(20);
$graph->xaxis->SetLabelmargin(5);
$graph->xaxis->SetTickLabels($legend);
$graph->ygrid->SetFill(true,'#EFEFEF@0.5','#BBCCFF@0.5');
// Add a drop shadow
$graph->SetShadow();
// Adjust the margin a bit to make more room for titles
$graph->img->SetMargin(50,30,20,40);
// Create a bar pot
$bplot = new BarPlot($percent);
// Adjust fill color
$bplot->SetFillColor('#9999CC');
$bplot->SetShadow();
$bplot->value->Show();
$bplot->value->SetFont(FF_ARIAL,FS_BOLD,10);
$bplot->value->SetAngle(45);
$bplot->value->SetFormat('%0.0f');
// Width
$bplot->SetWidth(0.6);
$graph->Add($bplot);
// Setup the titles
$graph->title->Set("PHP documentation");
$graph->xaxis->title->Set("Language");
$graph->yaxis->title->Set("Files up to date (%)");
$graph->title->SetFont(FF_FONT1,FS_BOLD);
$graph->yaxis->title->SetFont(FF_FONT1,FS_BOLD);
$graph->xaxis->title->SetFont(FF_FONT1,FS_BOLD);
// Display the graph
$graph->Stroke('../www/images/revcheck/info_revcheck_php_all_lang.png');
}

67
www/img-status-all.php Normal file
View File

@ -0,0 +1,67 @@
<?php
require_once __DIR__ . '/../include/jpgraph/src/jpgraph.php';
require_once __DIR__ . '/../include/jpgraph/src/jpgraph_bar.php';
require_once __DIR__ . '/../include/init.inc.php';
require_once __DIR__ . '/../include/lib_revcheck.inc.php';
$idx = new SQLite3(SQLITE_DIR . 'rev.php.sqlite');
$language = revcheck_available_languages($idx);
sort($language);
$files_EN = count_en_files($idx);
foreach ($language as $lang) {
$tmp = get_stats($idx, $lang, 'uptodate');
$percent_tmp[] = round($tmp[0] * 100 / $files_EN);
$legend_tmp[] = $lang;
}
$percent = array_values($percent_tmp);
$legend = array_values($legend_tmp);
// Create the graph. These two calls are always required
$graph = new Graph(600,262);
$graph->SetScale("textlin");
$graph->yaxis->scale->SetGrace(20);
$graph->xaxis->SetLabelmargin(5);
$graph->xaxis->SetTickLabels($legend);
$graph->ygrid->SetFill(true,'#EFEFEF@0.5','#BBCCFF@0.5');
// Add a drop shadow
$graph->SetShadow();
// Adjust the margin a bit to make more room for titles
$graph->img->SetMargin(50,30,20,40);
// Create a bar pot
$bplot = new BarPlot($percent);
// Adjust fill color
$bplot->SetFillColor('#9999CC');
$bplot->SetShadow();
$bplot->value->Show();
$bplot->value->SetFont(FF_ARIAL,FS_BOLD,10);
$bplot->value->SetAngle(45);
$bplot->value->SetFormat('%0.0f');
// Width
$bplot->SetWidth(0.6);
$graph->Add($bplot);
// Setup the titles
$graph->title->Set("PHP Translation Status");
$graph->xaxis->title->Set("Language");
$graph->yaxis->title->Set("Files up to date (%)");
$graph->title->SetFont(FF_FONT1,FS_BOLD);
$graph->yaxis->title->SetFont(FF_FONT1,FS_BOLD);
$graph->xaxis->title->SetFont(FF_FONT1,FS_BOLD);
// Display the graph
$graph->Stroke();

View File

@ -1,13 +1,12 @@
<?php
$time_start = microtime(true);
include '../include/jpgraph/src/jpgraph.php';
include '../include/jpgraph/src/jpgraph_pie.php';
include '../include/jpgraph/src/jpgraph_pie3d.php';
require_once __DIR__ . '/../include/jpgraph/src/jpgraph.php';
require_once __DIR__ . '/../include/jpgraph/src/jpgraph_pie.php';
require_once __DIR__ . '/../include/jpgraph/src/jpgraph_pie3d.php';
include '../include/init.inc.php';
include '../include/lib_revcheck.inc.php';
include '../include/lib_proj_lang.inc.php';
require_once __DIR__ . '/../include/init.inc.php';
require_once __DIR__ . '/../include/lib_revcheck.inc.php';
require_once __DIR__ . '/../include/lib_proj_lang.inc.php';
$idx = new SQLite3(SQLITE_DIR . 'rev.php.sqlite');
@ -16,16 +15,12 @@ $available_langs = revcheck_available_languages($idx);
$langs = array_keys($LANGUAGES);
foreach ($langs as $lang) {
if (!in_array($lang, $available_langs)) {
echo "Documentation for $lang language does not exist.\n";
die("Information for $lang language does not exist.");
} else {
generate_image($lang, $idx);
echo "Generated images/revcheck/info_revcheck_php_$lang.png\n";
}
}
$time = round(microtime(true) - $time_start, 3);
echo "Graphs generated in {$time}s\n";
function generate_image($lang, $idx) {
global $LANGUAGES;
@ -90,5 +85,5 @@ function generate_image($lang, $idx) {
$p1->SetLegends($legend);
$graph->Add($p1);
$graph->Stroke("../www/images/revcheck/info_revcheck_php_$lang.png");
$graph->Stroke();
}

View File

@ -428,18 +428,9 @@ END_OF_MULTILINE;
break;
case 'graph':
$path = "images/revcheck/info_revcheck_php_$lang.png";
if (is_readable(__DIR__ . "/" . $path)) {
echo '<img src="'.$path.'" alt="info">';
echo gen_date($DBLANG);
} else {
echo "<p>Can't find graph.</p>";
}
break;
default:
if ($lang == 'en') {
echo '<img src="images/revcheck/info_revcheck_php_all_lang.png" alt="Info" class="chart">';
echo '<img src="img-status-all.php" width="662" height="262" alt="Info" class="chart">';
echo '<p>This is all what we can show for original manual. To get more tools, please select translation language.</p>';
echo gen_date($DBLANG);
$sidebar = nav_languages();
@ -449,6 +440,8 @@ END_OF_MULTILINE;
$intro = $intro_result->fetchArray();
echo '<h2>Intro for language</h2>';
echo '<p>'.$intro[0].'</p>';
echo '<img src="img-status-lang.php?lang=', $lang, '" width="680" height="300" alt="info">';
echo gen_date($DBLANG);
echo '<p>Links to available tools are placed on the right sidebar.</p>';
}
break;