1
tank1955
X Basic Graphs
  • 2009/2/8 16:12

  • tank1955

  • Module Developer

  • Posts: 276

  • Since: 2007/9/7 1


I have been experimenting with adding JPGraph functionality into XOOPS sites. I believe I have finally figured out a good approach. At the top of my priority list was to keep it as simple as possible and avoid the need for any hacks.

We have created a module we call X Basic Graphs and we have the module prototype installed and functioning on the CVD site. The module contains the JPGraph library, coding examples and the JPGraph user's manual.

After installing the module you can set the group permissions for the module so only webmasters have access. You can then create graph php files in the module's graphs subdirectory and call these files in an image tag as the source definition from any module or block throughout the site.

Advantages of this approach are (1) No hacks to core code are required which is a good thing (2) JPGraph examples work right out of the box, no special translation to a different format required (3) Webmasters have easy access to all resource information for graph and chart creation.

Looking for feedback to ensure there is user interest before I take the time to prepare this as a downloadable package.

2
Mamba
Re: X Basic Graphs
  • 2009/2/9 9:09

  • Mamba

  • Moderator

  • Posts: 11366

  • Since: 2004/4/23


Great work, as always!!!

This could be interesting to use it in stand-alone modules, but I would be also interested to see how difficult it would be to pass some data from core or from modules to it. For example, to show our users the statistics from our Download modules, or from News. I'm just thinking here loud...
Support XOOPS => DONATE
Use 2.5.10 | Docs | Modules | Bugs

3
tank1955
Re: X Basic Graphs
  • 2009/2/9 18:10

  • tank1955

  • Module Developer

  • Posts: 276

  • Since: 2007/9/7 1


Thanks Mamba for the feedback.

To be honest I began development by just placing the JPGraphs library in the root /class/ directory. But this would then be considered a hack and then I was faced with where should the graph generating php files be placed. Creating X Basic Graphs module provides the advantage of storing the graph files in a central location as well as providing local access to the user's manual and the long list of examples available.

No matter where the data comes from it can easily be coded in the graph file and the image tag to display the graph can be placed anywhere throughout the site.

Plus I am sure after I release the first version there will be lots of feedback for improving it's functionality.

4
trabis
Re: X Basic Graphs
  • 2009/2/9 20:11

  • trabis

  • Core Developer

  • Posts: 2269

  • Since: 2006/9/1 1


I´m very interested on this. I never look inside it but I do want to use it shortly. Your work on this is very welcome. Thanks.

5
tank1955
Re: X Basic Graphs
  • 2009/2/10 2:09

  • tank1955

  • Module Developer

  • Posts: 276

  • Since: 2007/9/7 1


I have proven my theory that data can be extracted from any database table including the core tables within the graph generating php file. In the first example I extracted data from another module's tables and then in the second example I extracted the user registration data from the core's user table.

You can see the examples displayed at X Basic Graphs

Here is what the code looks like for generating the number of new user registrations for the last 6 months:

include ("../../../../mainfile.php");
include (
XOOPS_ROOT_PATH."/modules/basicgraphs/class/xgraphs/jpgraph/jpgraph.php");
include (
XOOPS_ROOT_PATH."/modules/basicgraphs/class/xgraphs/jpgraph/jpgraph_bar.php");

global 
$xoopsDB;

$datay = array();
$datax = array();

// Get the data
$result $xoopsDB->query("SELECT * FROM ".$xoopsDB->prefix("users")." WHERE level > 0 ORDER BY user_regdate");

$regarray = array();

while (
$row $xoopsDB->fetcharray($result)) {
  
$registration_date $row['user_regdate'];
  
  
$tempDate $dateArray=explode(',',strftime("%Y,%m,%d,%I,%M,%p",time()));
  
$currentmonth = (int)$tempDate[1];
  
$currentyear $tempDate[0];

  
$startDate mktime(000date("m")-6date("d"),   date("Y"));
  
$tempDate $dateArray=explode(',',strftime("%Y,%m,%d,%I,%M,%p",$startDate));
  
$startmonth = (int)$tempDate[1];
  
$startyear $tempDate[0];

  
$tempDate $dateArray=explode(',',strftime("%Y,%m,%d,%I,%M,%p",$registration_date));
  
$month = (int)$tempDate[1];
  
$year $tempDate[0];
  if (
$year == $startyear && $month >= $startmonth) {
    
$regarray[$month $startmonth] = $regarray[$month $startmonth] + 1;
  }elseif (
$year $startyear) {
    
$regarray[(12 $startmonth) + $month] = $regarray[(12 $startmonth) + $month] + 1;
  }
}

$datay $regarray;

// Generate the month with year labels for the x axis
while ($count 7) {
  
$count++;
  
$labelDate mktime(000date("m")-(7-$count), date("d"),   date("Y"));
  
$tempDate $dateArray=explode(',',strftime("%Y,%m,%d,%I,%M,%p",$labelDate));
  
$tempDateString date('M Y'mktime(000$tempDate[1], $tempDate[2], $tempDate[0]));
  
$datax[] = $tempDateString;
}

// Create the graph. These two calls are always required
$graph = new Graph(500,300,"auto");    
$graph->SetScale("textlin");
$graph->yaxis->scale->SetGrace(30);

$graph->xaxis->SetTickLabels($datax);
$graph->xaxis->SetLabelAngle(90);

// Add a drop shadow
$graph->SetShadow();

// Adjust the margin a bit to make more room for titles
$graph->img->SetMargin(50,50,40,100);
$graph->SetMarginColor('lightred');

// Create a bar pot
$bplot = new BarPlot($datay);

// Adjust fill color
$bplot->SetFillColor('darkred');
$bplot->value->Show();
$bplot->value->SetFormat('%d');
$graph->Add($bplot);

// Setup the titles
$graph->title->Set("New User Registration at CVD In Last 6 Months");
//$graph->xaxis->title->Set("Month");
$graph->yaxis->title->Set("Number of New Users");

$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();

6
Mamba
Re: X Basic Graphs
  • 2009/2/10 5:57

  • Mamba

  • Moderator

  • Posts: 11366

  • Since: 2004/4/23


That's exactly what I was looking for in my last post. That's FANTASTIC!

Tank, you ROCK!!!!
Support XOOPS => DONATE
Use 2.5.10 | Docs | Modules | Bugs

7
tank1955
Re: X Basic Graphs
  • 2009/2/10 11:56

  • tank1955

  • Module Developer

  • Posts: 276

  • Since: 2007/9/7 1


Thanks Mamba. I am hoping to wrap things up and have a release prepared within the week. One question I have is since the zipped module is pretty large (6.5 Meg) do you think I should also build a package without the JPGraph user's manual included? Without the manual documentation the zipped module is (2.5 Meg).

8
zyspec
Re: X Basic Graphs
  • 2009/2/10 18:36

  • zyspec

  • Module Developer

  • Posts: 1095

  • Since: 2004/9/21


I'd be interested in this too. I quickly modified the code above to provide a "plug in" for MX-Directory to show a pie chart for the number of listings in each Premium Level. I'm looking forward to trying it out. I'll probably create a few others for things like number of listings created by month over the past year, etc.

9
Mamba
Re: X Basic Graphs
  • 2009/2/10 18:43

  • Mamba

  • Moderator

  • Posts: 11366

  • Since: 2004/4/23


I would do it without the manual, but with a clear link in the Admin section to where they could download it, or just view it on demand.
This way users don't have to download it again and again.
Support XOOPS => DONATE
Use 2.5.10 | Docs | Modules | Bugs

10
Mamba
Re: X Basic Graphs
  • 2009/2/10 18:44

  • Mamba

  • Moderator

  • Posts: 11366

  • Since: 2004/4/23


Quote:
a "plug in" for MX-Directory to show a pie chart for the number of listings in each Premium Level.

Those are the things that I'm looking for to offer to our users.

Is there any chance to standardize such a "plugin" architecture, so any module could use it in the future?
Support XOOPS => DONATE
Use 2.5.10 | Docs | Modules | Bugs

Login

Who's Online

137 user(s) are online (102 user(s) are browsing Support Forums)


Members: 0


Guests: 137


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Mar 31
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits