dropped flot and adopted chart.js in code_folder.php and code_file.php

This commit is contained in:
hyung-hwan 2021-09-12 08:22:54 +00:00
parent f11910ca46
commit 277af9bb4a
4 changed files with 116 additions and 71 deletions

View File

@ -34,7 +34,7 @@ class Graph extends CI_Controller
$this->load->model ('ProjectModel', 'projects'); $this->load->model ('ProjectModel', 'projects');
$this->load->model ('SubversionModel', 'subversion'); $this->load->model ('SubversionModel', 'subversion');
$login = $this->login->getUser (); $login = $this->login->getUser();
if (CODEPOT_SIGNIN_COMPULSORY && $login['id'] == '') if (CODEPOT_SIGNIN_COMPULSORY && $login['id'] == '')
redirect (CODEPOT_SIGNIN_REDIR_PATH . $this->converter->AsciiTohex(current_url())); redirect (CODEPOT_SIGNIN_REDIR_PATH . $this->converter->AsciiTohex(current_url()));
$data['login'] = $login; $data['login'] = $login;
@ -73,7 +73,7 @@ class Graph extends CI_Controller
{ {
$this->load->model ('ProjectModel', 'projects'); $this->load->model ('ProjectModel', 'projects');
$login = $this->login->getUser (); $login = $this->login->getUser();
if (CODEPOT_SIGNIN_COMPULSORY && $login['id'] == '') if (CODEPOT_SIGNIN_COMPULSORY && $login['id'] == '')
{ {
header($_SERVER['SERVER_PROTOCOL'].' 404 Not Found'); header($_SERVER['SERVER_PROTOCOL'].' 404 Not Found');
@ -116,7 +116,7 @@ class Graph extends CI_Controller
{ {
$this->load->model ('ProjectModel', 'projects'); $this->load->model ('ProjectModel', 'projects');
$login = $this->login->getUser (); $login = $this->login->getUser();
if (CODEPOT_SIGNIN_COMPULSORY && $login['id'] == '') if (CODEPOT_SIGNIN_COMPULSORY && $login['id'] == '')
{ {
header($_SERVER['SERVER_PROTOCOL'].' 404 Not Found'); header($_SERVER['SERVER_PROTOCOL'].' 404 Not Found');
@ -144,7 +144,7 @@ class Graph extends CI_Controller
{ {
$this->load->model ('ProjectModel', 'projects'); $this->load->model ('ProjectModel', 'projects');
$login = $this->login->getUser (); $login = $this->login->getUser();
if (CODEPOT_SIGNIN_COMPULSORY && $login['id'] == '') if (CODEPOT_SIGNIN_COMPULSORY && $login['id'] == '')
{ {
header($_SERVER['SERVER_PROTOCOL'].' 404 Not Found'); header($_SERVER['SERVER_PROTOCOL'].' 404 Not Found');
@ -172,7 +172,7 @@ class Graph extends CI_Controller
{ {
$this->load->model ('ProjectModel', 'projects'); $this->load->model ('ProjectModel', 'projects');
$login = $this->login->getUser (); $login = $this->login->getUser();
if (CODEPOT_SIGNIN_COMPULSORY && $login['id'] == '') if (CODEPOT_SIGNIN_COMPULSORY && $login['id'] == '')
{ {
header($_SERVER['SERVER_PROTOCOL'].' 404 Not Found'); header($_SERVER['SERVER_PROTOCOL'].' 404 Not Found');
@ -200,7 +200,7 @@ class Graph extends CI_Controller
{ {
$this->load->model ('ProjectModel', 'projects'); $this->load->model ('ProjectModel', 'projects');
$login = $this->login->getUser (); $login = $this->login->getUser();
if (CODEPOT_SIGNIN_COMPULSORY && $login['id'] == '') if (CODEPOT_SIGNIN_COMPULSORY && $login['id'] == '')
{ {
header($_SERVER['SERVER_PROTOCOL'].' 404 Not Found'); header($_SERVER['SERVER_PROTOCOL'].' 404 Not Found');

View File

@ -1596,10 +1596,9 @@ class SubversionModel extends CodeRepoModel
if ($info === FALSE || $info === NULL || count($info) != 1) continue; if ($info === FALSE || $info === NULL || count($info) != 1) continue;
} }
if ($info[0]['kind'] == SVN_NODE_FILE) return FALSE; if ($info[0]['kind'] == SVN_NODE_FILE) continue;
$info0 = &$info[0];
$list = @svn_ls ($workurl, $rev, FALSE, TRUE); $list = @svn_ls($workurl, $rev, FALSE, TRUE);
if ($list === FALSE) return FALSE; if ($list === FALSE) return FALSE;
foreach ($list as $key => $value) foreach ($list as $key => $value)
@ -1609,21 +1608,26 @@ class SubversionModel extends CodeRepoModel
{ {
$obj = new stdClass(); $obj = new stdClass();
//$obj->name = $key; //$obj->name = $key;
$obj->name = $full_path; //$obj->name = $full_path;
$obj->name = substr($full_path, strlen($path) + 1); // relative path
$text = @svn_cat ("{$orgurl}/{$key}{$trailer}", $rev); $text = @svn_cat("{$orgurl}/{$key}{$trailer}", $rev);
if ($text === FALSE) $obj->size = 0; if ($text === FALSE)
{
$obj->lines = 0;
$obj->bytes = 0;
}
else else
{ {
$text_len = strlen($text); $text_len = strlen($text);
$obj->size = substr_count($text, "\n"); $obj->lines = substr_count($text, "\n");
if ($text_len > 0 && $text[$text_len - 1] != "\n") $obj->size++; if ($text_len > 0 && $text[$text_len - 1] != "\n") $obj->lines++;
$obj->bytes = $text_len;
} }
$obj->language = substr(strrchr($key, '.'), 1); // file extension $obj->language = substr(strrchr($key, '.'), 1); // file extension
if ($obj->language === FALSE) $obj->language = ''; if ($obj->language === FALSE) $obj->language = '';
array_push ($current_cloc->children, $obj); array_push ($current_cloc->children, $obj);
} }
else else
@ -1634,11 +1638,11 @@ class SubversionModel extends CodeRepoModel
// other same base name in a different directory. // other same base name in a different directory.
// let's use a full path. it's anyway clearer. // let's use a full path. it's anyway clearer.
//$obj->name = $key; //$obj->name = $key;
$obj->name = $full_path; //$obj->name = $full_path;
$obj->name = substr($full_path, strlen($path) + 1); // relativte path
$obj->children = array(); $obj->children = array();
array_push ($current_cloc->children, $obj); array_push ($current_cloc->children, $obj);
array_push ($stack, $full_path); array_push ($stack, $full_path);
array_push ($stack, $obj); array_push ($stack, $obj);
} }

View File

@ -102,9 +102,7 @@
<script type="text/javascript" src="<?php print base_url_make('/js/jquery-ui.min.js')?>"></script> <script type="text/javascript" src="<?php print base_url_make('/js/jquery-ui.min.js')?>"></script>
<link type="text/css" rel="stylesheet" href="<?php print base_url_make('/css/jquery-ui.css')?>" /> <link type="text/css" rel="stylesheet" href="<?php print base_url_make('/css/jquery-ui.css')?>" />
<!--[if lte IE 8]><script type="text/javascript" src="<?php print base_url_make('/js/excanvas.min.js')?>"></script><![endif]--> <script type="text/javascript" src="<?php print base_url_make('/js/chart.min.js')?>"></script>
<script type="text/javascript" src="<?php print base_url_make('/js/jquery.flot.min.js')?>"></script>
<script type="text/javascript" src="<?php print base_url_make('/js/jquery.flot.pie.min.js')?>"></script>
<script type="text/javascript" src="<?php print base_url_make('/js/vis.min.js')?>"></script> <script type="text/javascript" src="<?php print base_url_make('/js/vis.min.js')?>"></script>
<link type="text/css" rel="stylesheet" href="<?php print base_url_make('/css/vis.min.css')?>" /> <link type="text/css" rel="stylesheet" href="<?php print base_url_make('/css/vis.min.css')?>" />
@ -404,6 +402,10 @@ var GraphApp = (function ()
self.resizeGraph (); self.resizeGraph ();
}); });
this.graph_container.on ("dialogclose", function (evt, ui) {
self.closeGraph ();
});
this.graph_button.button().click (function () this.graph_button.button().click (function ()
{ {
open_graph.call (self); open_graph.call (self);
@ -441,6 +443,11 @@ var GraphApp = (function ()
/* SHOULD BE IMPLEMENTED BY INHERITER */ /* SHOULD BE IMPLEMENTED BY INHERITER */
} }
App.prototype.closeGraph = function ()
{
/* SHOULD BE IMPLEMENTED BY INHERITER */
}
return App; return App;
})(); })();
@ -558,15 +565,18 @@ var LocGraphApp = (function ()
function App (top_container, graph_container, graph_msgdiv, graph_canvas, graph_button, graph_spin, graph_url, graph_title) function App (top_container, graph_container, graph_msgdiv, graph_canvas, graph_button, graph_spin, graph_url, graph_title)
{ {
GraphApp.call (this, top_container, graph_container, graph_msgdiv, graph_canvas, graph_button, graph_spin, graph_url, graph_title); GraphApp.call (this, top_container, graph_container, graph_msgdiv, graph_canvas, graph_button, graph_spin, graph_url, graph_title);
this.chart = null;
this.plot_dataset = null; this.plot_dataset = null;
this.plot_options = null; this.plot_options = null;
return this; return this;
} }
App.prototype = Object.create(GraphApp.prototype); App.prototype = Object.create(GraphApp.prototype);
App.prototype.constructor = App; App.prototype.constructor = App;
App.prototype.renderGraph = function (data) App.prototype.renderGraph = function (data)
{ {
if (!data.hasOwnProperty('SUM')) if (!("SUM" in data))
{ {
this.showMessage ('No data to show'); this.showMessage ('No data to show');
return; return;
@ -579,36 +589,38 @@ var LocGraphApp = (function ()
this.clearMessage (); this.clearMessage ();
// files, blank, comment, code var labels = [
// files is always 1. "<?php print $this->lang->line('Blank')?>",
this.plot_dataset = [ "<?php print $this->lang->line('Comment')?>",
{ label: "<?php print $this->lang->line('Blank')?>", data: data.SUM[1] }, "<?php print $this->lang->line('Code')?>"
{ label: "<?php print $this->lang->line('Comment')?>", data: data.SUM[2] },
{ label: "<?php print $this->lang->line('Code')?>", data: data.SUM[3] }
]; ];
this.plot_options = // data.SUM[] => files, blank, comment, code
// files is always 1.
this.plot_dataset = {
labels: labels,
datasets: [
{ {
series: { data: [data.SUM[1], data.SUM[2], data.SUM[3]],
shadowSize: 0, backgroundColor: [
pie: { 'rgb(255, 99, 132)',
show: true, 'rgb(54, 162, 235)',
innerRadius: 0.1, 'rgb(255, 205, 86)'
label: { ]
show: true,
radius: 0.9,
formatter: function labelFormatter(label, series)
{
return "<div style='font-size:8pt; text-align:center; padding:2px; '>" + label + "<br/>" + series.data[0][1] + "(" + Math.round(series.percent) + "%)</div>";
},
backgraound: { opacity: 0.8 }
}
}
},
legend: {
show: false
} }
]
}; };
this.plot_options = {
responsive: true,
maintainAspectRatio: false
};
this.chart = new Chart(this.graph_canvas[0].getContext('2d'), {
type: 'doughnut',
data: this.plot_dataset,
options: this.plot_options
});
} }
App.prototype.resizeGraph = function () App.prototype.resizeGraph = function ()
@ -617,7 +629,15 @@ var LocGraphApp = (function ()
{ {
this.graph_canvas.width (this.graph_container.width() - 5); this.graph_canvas.width (this.graph_container.width() - 5);
this.graph_canvas.height (this.graph_container.height() - 10); this.graph_canvas.height (this.graph_container.height() - 10);
$.plot(this.graph_canvas, this.plot_dataset, this.plot_options); }
}
App.prototype.closeGraph = function ()
{
if (this.chart != null)
{
this.chart.destroy();
this.chart = null;
} }
} }
@ -982,7 +1002,8 @@ $this->load->view (
</div> </div>
<div id="code_file_loc_graph_container"> <div id="code_file_loc_graph_container">
<div id="code_file_loc_graph"></div> <!-- <div id="code_file_loc_graph"></div> -->
<canvas id="code_file_loc_graph"></canvas>
<div id="code_file_loc_graph_error"></div> <div id="code_file_loc_graph_error"></div>
</div> </div>
</div> </div>

View File

@ -28,8 +28,6 @@
<script type="text/javascript" src="<?php print base_url_make('/js/jqueryui-editable.min.js')?>"></script> <script type="text/javascript" src="<?php print base_url_make('/js/jqueryui-editable.min.js')?>"></script>
<link type="text/css" rel="stylesheet" href="<?php print base_url_make('/css/jqueryui-editable.css')?>" /> <link type="text/css" rel="stylesheet" href="<?php print base_url_make('/css/jqueryui-editable.css')?>" />
<!--[if lte IE 8]><script type="text/javascript" src="<?php print base_url_make('/js/excanvas.min.js')?>"></script><![endif]-->
<script type="text/javascript" src="<?php print base_url_make('/js/chart.min.js')?>"></script> <script type="text/javascript" src="<?php print base_url_make('/js/chart.min.js')?>"></script>
<script type="text/javascript" src="<?php print base_url_make('/js/vis.min.js')?>"></script> <script type="text/javascript" src="<?php print base_url_make('/js/vis.min.js')?>"></script>
@ -448,6 +446,7 @@ var LocLangApp = (function ()
this.chart = null; this.chart = null;
} }
} }
return App; return App;
})(); })();
@ -472,35 +471,55 @@ var LocFileApp = (function ()
this.clearMessage (); this.clearMessage ();
var gen_color = function() { //var gen_color = function() {
var letters = '0123456789ABCDEF'.split(''); // var letters = '0123456789ABCDEF'.split('');
var color = '#'; // var color = '#';
for (var i = 0; i < 6; i++) color += letters[Math.floor(Math.random() * 16)]; // for (var i = 0; i < 6; i++) color += letters[Math.floor(Math.random() * 16)];
return color; // return color;
}; //};
var labels = []; var labels = [];
var dataset = []; var dataset_lines = [];
var dataset_bytes = [];
var bgcolors = []; var bgcolors = [];
for (var key in loc.children) {
var size = loc.children[key].size;
if (size == null) size = 0;
var name = loc.children[key].name; var add_items = function(items)
name = name.split('/').reverse()[0]; {
labels.push (name); for (var key in items) {
dataset.push (size); var item = items[key];
if ('children' in item)
{
// directory item.
add_items (item.children);
}
else
{
// plain file item
var lines = item.lines;
if (lines == null) lines = 0;
var size = item.size;
if (size == null) lines = 0;
labels.push (item.name);
dataset_lines.push (item.lines == null? 0: item.lines);
dataset_bytes.push (item.bytes == null? 0: item.bytes);
//bgcolors.push(gen_color()); //bgcolors.push(gen_color());
} }
}
};
add_items (loc.children);
this.plot_dataset = { this.plot_dataset = {
labels: labels, labels: labels,
datasets: [ datasets: [
{ {
label: 'LOC', label: 'Lines',
data: dataset, data: dataset_lines
//backgroundColor: bgcolors //backgroundColor: bgcolors
} }/*,
{
label: 'Bytes',
data: dataset_bytes
}*/
] ]
}; };
this.plot_options = { this.plot_options = {
@ -508,7 +527,8 @@ var LocFileApp = (function ()
maintainAspectRatio: false, maintainAspectRatio: false,
scales: { scales: {
x: { x: {
grid: { display: false } grid: { display: false },
stacked: true
}, },
y: { y: {
beginAtZero: true, beginAtZero: true,