-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit d97532c
Showing
19 changed files
with
2,246 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
Copyright (c) 2008-2012 David Negrier | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
StatsGrid: a PHP pivot table | ||
============================ | ||
|
||
StatsGrid is a PHP library that let's you generate HTML pivot tables from any dataset. | ||
You give the data to be rendered as an array to StatsGrid and it will render the HTML. For instance, you can | ||
give this array: | ||
|
||
$data = array( | ||
array("country"=>"US", "city"=>"Chicago", "year"=>2009, "month"=>"February", "CA"=>12, "Benef"=>2), | ||
array("country"=>"US", "city"=>"Chicago", "year"=>2009, "month"=>"April", "CA"=>12, "Benef"=>2), | ||
array("country"=>"US", "city"=>"NY", "year"=>2009, "month"=>"May", "CA"=>15, "Benef"=>5), | ||
array("country"=>"US", "city"=>"Baltimore", "year"=>2009, "month"=>"April", "CA"=>42, "Benef"=>3), | ||
array("country"=>"US", "city"=>"Baltimore", "year"=>2010, "month"=>"April", "CA"=>24, "Benef"=>4), | ||
array("country"=>"FR", "city"=>"Paris", "year"=>2010, "month"=>"May", "CA"=>12, "Benef"=>2), | ||
array("country"=>"FR", "city"=>"Paris", "year"=>2010, "month"=>"June", "CA"=>12, "Benef"=>2), | ||
); | ||
|
||
and StatsGrid can generate this kind of reports: | ||
|
||
<table><tr> | ||
<td></td><td></td><td colspan='6'>2009</td><td colspan='6'>2010</td> | ||
</tr><tr> | ||
<td></td><td></td><td colspan='2'>February</td><td colspan='2'>April</td><td colspan='2'>May</td><td colspan='2'>April</td><td colspan='2'>May</td><td colspan='2'>June</td> | ||
</tr><tr> | ||
<td></td><td></td><td>CA</td><td>Be.</td><td>CA</td><td>Be.</td><td>CA</td><td>Be.</td><td>CA</td><td>Be.</td><td>CA</td><td>Be.</td><td>CA</td><td>Be.</td> | ||
</tr><tr> | ||
<td rowspan='3'>US</td><td>Chicago</td><td>12</td><td>2</td><td>12</td><td>2</td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td> | ||
</tr><tr> | ||
<td>NY</td><td></td><td></td><td></td><td></td><td>15</td><td>5</td><td></td><td></td><td></td><td></td><td></td><td></td> | ||
</tr><tr> | ||
<td>Baltimore</td><td></td><td></td><td>42</td><td>3</td><td></td><td></td><td>24</td><td>4</td><td></td><td></td><td></td><td></td> | ||
</tr><tr> | ||
<td>FR</td><td>Paris</td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td>12</td><td>2</td><td>12</td><td>2</td> | ||
</tr></table> | ||
|
||
Usage sample: | ||
------------- | ||
|
||
To generate a statsgrid, you need several things: | ||
- obviously, a dataset (the raw data that you will render) | ||
- you will also need a set of row and a set of column descriptors (describing what should be in row and what should be in column) | ||
- finally, you need to decide what values are to be displayed in the grid | ||
|
||
Here is a sample code base: | ||
|
||
|
||
// Let's define the data to be displayed (usually, you will get this from a database using GROUP BY statements) | ||
$data = array( | ||
array("country"=>"US", "city"=>"Chicago", "year"=>2009, "month"=>"February", "CA"=>12, "Benef"=>2), | ||
array("country"=>"US", "city"=>"Chicago", "year"=>2009, "month"=>"April", "CA"=>12, "Benef"=>2), | ||
array("country"=>"US", "city"=>"NY", "year"=>2009, "month"=>"May", "CA"=>15, "Benef"=>5), | ||
array("country"=>"US", "city"=>"Baltimore", "year"=>2009, "month"=>"April", "CA"=>42, "Benef"=>3), | ||
array("country"=>"US", "city"=>"Baltimore", "year"=>2010, "month"=>"April", "CA"=>24, "Benef"=>4), | ||
array("country"=>"FR", "city"=>"Paris", "year"=>2010, "month"=>"May", "CA"=>12, "Benef"=>2), | ||
array("country"=>"FR", "city"=>"Paris", "year"=>2010, "month"=>"June", "CA"=>12, "Benef"=>2), | ||
); | ||
|
||
// Let's create the instance | ||
$grid = new StatsGrid(); | ||
// We define 2 rows: COUNTRY and CITY | ||
$grid->setRows(array( | ||
new StatsColumnDescriptor("country"), | ||
new StatsColumnDescriptor("city") | ||
)); | ||
// We define 2 columns: YEAR and MONTHS | ||
$grid->setColumns(array( | ||
new StatsColumnDescriptor("year"), | ||
new StatsColumnDescriptor("month") | ||
)); | ||
// We define 2 values: CA and Benef | ||
$grid->setValues(array( | ||
new StatsValueDescriptor("CA", "CA"), | ||
new StatsValueDescriptor("Benef", "Be."), | ||
)); | ||
// We set the data | ||
$grid->setData($data); | ||
|
||
// We print the table | ||
$grid->toHtml(); | ||
|
||
|
||
Adding aggregation (sums/means...): | ||
----------------------------------- | ||
|
||
Presenting data in a pivot table is nice, but often, you will find out you want to display sums or means of the data at the bottom of the table. | ||
StatsGrid let's you *aggregate* data (performing sums/means...) on any column or any row. This way, you can perform sums / subsums, etc... the way you want. | ||
|
||
In order to aggregate data, you just need to call the | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"name": "mouf/html.widgets.statsgrid", | ||
"description": "This PHP package contains a HTML pivot table. You provide it with a data set and the list of columns and rows and it will display a nice pivot table.", | ||
"keywords": ["html", "statistics", "pivot", "grid"], | ||
"homepage": "https://github.com/thecodingmachine/html.widgets.statsgrid", | ||
"type": "library", | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "David Négrier", | ||
"email": "d.negrier@thecodingmachine.com", | ||
"homepage": "http://mouf-php.com" | ||
} | ||
], | ||
"require": { | ||
"php": ">=5.3.0", | ||
"mouf/html.htmlelement": ">=2.0-dev,<3.0" | ||
}, | ||
"autoload": { | ||
"psr-0": { | ||
"Mouf": "src/" | ||
} | ||
} | ||
} |
Binary file added
BIN
+9.92 KB
css/.sass-cache/abb7d138f71cfe8692af5cf91efab96569406354/baseTable.scssc
Binary file not shown.
Binary file added
BIN
+139 Bytes
css/.sass-cache/abb7d138f71cfe8692af5cf91efab96569406354/blueTable.scssc
Binary file not shown.
Binary file added
BIN
+10.9 KB
css/.sass-cache/abb7d138f71cfe8692af5cf91efab96569406354/statsgrid.scssc
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/bin/bash | ||
|
||
sass --watch src:dist |
Oops, something went wrong.