Commit b38b4df0 authored by Matt Pugh's avatar Matt Pugh

working

parent abe54cec
......@@ -34,6 +34,7 @@ class Graph {
public $data, $data_buffer;
public $user, $type, $renderer, $label_renderer;
public $max_x_axis, $max_y_axis;
public $tick_interval = 20;
public $x_axis_label = "X axis", $y_axis_label = "Y Axis";
/* Multidimensional array to allow for multiple series of data. */
......@@ -87,7 +88,8 @@ class Graph {
protected function setMaxX($raw)
{
$this->max_x_axis = round($raw + ($raw * 0.10), -3);
$this->max_x_axis = round($raw + 100, -2);
$this->tick_interval = ($this->max_x_axis / 10);
}
/**
......@@ -107,7 +109,8 @@ class Graph {
{
foreach ($set as $k => $node)
{
$temp .= "[" . ((! is_numeric($node)) ? "'".$node."'" : $node);
/* @TODO: Need to escape the $node if not numeric! */
$temp .= "[" . ((! is_numeric($node)) ? "'".(addslashes($node))."'" : $node);
/* @TODO: check $node for len > 1, if so tokenise string */
if ($inverse) $temp .= "," . ++$i;
$temp .= "],";
......
......@@ -31,10 +31,10 @@ class GraphTopArtists extends Graph {
parent::__construct($user, "bar_horiz");
$this->number_of_tracks = $num;
$this->buildArtistGraphData();
$this->buildGraphData();
}
private function buildArtistGraphData()
private function buildGraphData()
{
$tmp = Statistic::GeneratePlayStats('Scrobbles', 'artist',
$this->number_of_tracks, $this->user->uniqueid, 300);
......@@ -60,26 +60,68 @@ class GraphTopArtists extends Graph {
class GraphTopTracks extends Graph {
public $tracks, $tracks_data;
public $number_of_tracks;
function __construct($user, $num = 20)
{
parent::__construct($user, "bar_horiz");
$this->number_of_tracks = $num;
$this->buildTrackGraphData();
$this->buildGraphData();
}
private function buildTrackGraphData()
private function buildGraphData()
{
/* @TODO: Remove width column in SQL */
$this->data_buffer = $this->user->getTopTracks($this->number_of_tracks);
$tmp_artists = array();
$tmp_listings = array();
$tracks = array();
$listings = array();
foreach($this->data_buffer as $key => $entry)
{
$tmp_artists[] = $entry['freq'];
$tmp_listings[] = $entry['artist'];
//$tracks[] = $entry['track'];
//$tracks[] = '<a href="'.$entry['artisturl'].'">'.$entry['artist'].'</a> - <a href="'.$entry['trackurl'].'">'.$entry['track'].'</a>';
$listings[] = $entry['freq'];
}
/* @TODO: sort out SQL for orders */
$this->setMaxX($listings[0]);
$tracks = array_reverse($tracks);
$listings = array_reverse($listings);
$this->tracks = $this->buildJsSingleArray($tracks);
$this->data[0][0] = $listings;
$this->tracks_data = $this->buildJsDataArray(true);
}
}
class GraphPlaysByDays extends Graph {
public $plays_by_days;
public $number_of_days;
function __construct($user, $num = 20)
{
parent::__construct($user, "line");
$this->number_of_days = $num;
$this->buildGraphData();
}
private function buildGraphData()
{
$this->data_buffer = Statistic::generatePlayByDays('Scrobbles',
$this->number_of_days, $user->uniqueid, 300);
$date_line = "[";
/* @TODO: Streamline this by simply removing size from SQL... */
foreach ($this->data_buffer as $key => $entry)
{
$date_line .= "['" . $entry['date'] . "', " . $entry['count'] . "],";
}
$this->plays_by_days = rtrim($date_line, ',');
$this->plays_by_days .= "]";
}
}
......
......@@ -69,7 +69,8 @@ if(isset($user->name)) {
$smarty->assign('totaltracks', $user->getTotalTracks());
$smarty->assign('graphtopartists', new GraphTopArtists($user, 20));
$smarty->assign('graphtoptracks', new GraphTopTracks($user));
$smarty->assign('graphtoptracks', new GraphTopTracks($user, 20));
$smarty->assign('graphplaysbydays', new GraphPlaysByDays($user, 20));
$smarty->assign('me', $user);
$smarty->assign('geo', Server::getLocationDetails($user->location_uri));
......@@ -87,7 +88,7 @@ if(isset($user->name)) {
'rel' => 'stylesheet',
'type' => 'text/css',
'title' => 'jqPlot CSS',
'href' => $base_url.'/themes/'.$default_theme.'/css/jquery.jqplot.min.css'
'href' => $base_url.'/themes/'.$default_theme.'/css/jquery.jqplot.css'
)
));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment