From: <tim...@us...> - 2010-07-22 09:11:24
|
Revision: 3654 http://web-erp.svn.sourceforge.net/web-erp/?rev=3654&view=rev Author: tim_schofield Date: 2010-07-22 09:11:16 +0000 (Thu, 22 Jul 2010) Log Message: ----------- Update to latest phplot, add in choice of graph types layout changes, and sql quoting Modified Paths: -------------- trunk/SalesGraph.php trunk/doc/Change.log.html trunk/includes/phplot/ChangeLog trunk/includes/phplot/NEWS.txt trunk/includes/phplot/README.txt trunk/includes/phplot/phplot.php Added Paths: ----------- trunk/includes/phplot/HorizontalBars.txt trunk/includes/phplot/contrib/ trunk/includes/phplot/contrib/README.txt trunk/includes/phplot/contrib/color_range.example.php trunk/includes/phplot/contrib/color_range.php trunk/includes/phplot/contrib/color_range.test1.php trunk/includes/phplot/contrib/color_range.test2.php trunk/includes/phplot/contrib/prune_labels.example.php trunk/includes/phplot/contrib/prune_labels.php trunk/includes/phplot/contrib/prune_labels.test.php Modified: trunk/SalesGraph.php =================================================================== --- trunk/SalesGraph.php 2010-07-22 09:10:30 UTC (rev 3653) +++ trunk/SalesGraph.php 2010-07-22 09:11:16 UTC (rev 3654) @@ -6,11 +6,11 @@ include('includes/phplot/phplot.php'); $title=_('Sales Report Graph'); include('includes/header.inc'); - + $SelectADifferentPeriod =''; - + if (isset($_POST['FromPeriod']) AND isset($_POST['ToPeriod'])){ - + if ($_POST['FromPeriod'] > $_POST['ToPeriod']){ prnMsg(_('The selected period from is actually after the period to! Please re-select the reporting period'),'error'); $SelectADifferentPeriod =_('Select A Different Period'); @@ -24,14 +24,16 @@ $SelectADifferentPeriod= _('Select A Different Period'); } } - - if ((! isset($_POST['FromPeriod']) OR ! isset($_POST['ToPeriod'])) + + if ((! isset($_POST['FromPeriod']) OR ! isset($_POST['ToPeriod'])) OR $SelectADifferentPeriod==_('Select A Different Period')){ - + echo '<form method="POST" action="' . $_SERVER['PHP_SELF'] . '?' . SID . '">'; + + echo '<p class="page_title_text"><img src="'.$rootpath.'/css/'.$theme.'/images/maintenance.png" title="' . _('Search') . '" alt="">' . ' ' . $title.'</p>'; /*Show a form to allow input of criteria for TB to show */ - echo '<table><tr><td>' . _('Select Period From:') . '</td><td><select Name="FromPeriod">'; - + echo '<table class=selection><tr><td>' . _('Select Period From:') . '</td><td><select Name="FromPeriod">'; + if (Date('m') > $_SESSION['YearEnd']){ /*Dates in SQL format */ $DefaultFromDate = Date ('Y-m-d', Mktime(0,0,0,$_SESSION['YearEnd'] + 2,0,Date('Y'))); @@ -59,11 +61,7 @@ echo '</select></td></tr>'; if (!isset($_POST['ToPeriod']) OR $_POST['ToPeriod']==''){ - $sql = 'SELECT Max(periodno) FROM periods'; - $MaxPrd = DB_query($sql,$db); - $MaxPrdrow = DB_fetch_row($MaxPrd); - - $DefaultToPeriod = (int) ($MaxPrdrow[0]-1); + $DefaultToPeriod = GetPeriod(DateAdd(ConvertSQLDate($DefaultFromDate),'m',11),$db); } else { $DefaultToPeriod = $_POST['ToPeriod']; } @@ -81,9 +79,9 @@ } } echo '</select></td></tr>'; - + $AreasResult = DB_query('SELECT areacode, areadescription FROM areas',$db); - + if (!isset($_POST['SalesArea'])){ $_POST['SalesArea']=''; } @@ -101,9 +99,9 @@ } } echo '</select></td></tr>'; - + $CategoriesResult = DB_query('SELECT categoryid, categorydescription FROM stockcategory',$db); - + if (!isset($_POST['CategoryID'])){ $_POST['CategoryID']=''; } @@ -121,16 +119,16 @@ } } echo '</select></td></tr>'; - + $SalesFolkResult = DB_query('SELECT salesmancode, salesmanname FROM salesman',$db); - - + + if (! isset($_POST['SalesmanCode'])){ $_POST['SalesmanCode'] = ''; } - + echo '<tr><td>' . _('For Sales Person:') .'</td><td><select Name="SalesmanCode">'; - + if($_POST['SalesmanCode']=='All'){ echo '<option selected VALUE="All">' . _('All'); } else { @@ -144,7 +142,21 @@ } } echo '</select></td><td>' . $_POST['SalesmanCode'] . '</td></tr>'; - + + echo '<tr><td>'._('Graph Type').'</td>'; + echo '<td><select name=GraphType>'; + echo '<option value=bars>'._('Bar Graph').'</option>'; + echo '<option value=stackedbars>'._('Stacked Bar Graph').'</option>'; + echo '<option value=lines>'._('Line Graph').'</option>'; + echo '<option value=linepoints>'._('Line Point Graph').'</option>'; + echo '<option value=area>'._('Area Graph').'</option>'; + echo '<option value=points>'._('Points Graph').'</option>'; + echo '<option value=pie>'._('Pie Graph').'</option>'; + echo '<option value=thinbarline>'._('Thin Bar Line Graph').'</option>'; + echo '<option value=squared>'._('Squared Graph').'</option>'; + echo '<option value=stackedarea>'._('Stacked Area Graph').'</option>'; + echo '</select></td></tr>'; + if (!isset($_POST['ValueFrom'])){ $_POST['ValueFrom']=''; } @@ -157,17 +169,18 @@ <input type="RADIO" name="GraphOn" VALUE="StockID">' . _('Item Code') . '</td></tr>'; echo '<tr><td>' . _('From:') . ' <input type=TEXT name="ValueFrom" VALUE=' . $_POST['ValueFrom'] . '></td> <td>' . _('To:') . ' <input type=TEXT name="ValueTo" VALUE=' . $_POST['ValueTo'] . '></td></tr>'; - + echo '<tr><td>' . _('Graph Value:') . '</td><td> <input type="RADIO" name="GraphValue" VALUE="Net" CHECKED>' . _('Net Sales Value') . '<br> <input type="RADIO" name="GraphValue" VALUE="GP">' . _('Gross Profit') . '<br> - <input type="RADIO" name="GraphValue" VALUE="Quantity">' . _('Quantity') . '</td></tr>'; - + <input type="RADIO" name="GraphValue" VALUE="Quantity">' . _('Quantity') . '</td></tr>'; + echo '</table>'; - + echo '<br><div class="centre"><input type=submit Name="ShowGraph" Value="' . _('Show Sales Graph') .'"></div>'; - } else { - + include('includes/footer.inc'); +} else { + $graph =& new PHPlot(950,450); $SelectClause =''; $WhereClause =''; @@ -182,9 +195,9 @@ $GraphTitle = _('Unit Sales'); $SelectClause = 'qty'; } - + $GraphTitle .= ' ' . _('From Period') . ' ' . $_POST['FromPeriod'] . ' ' . _('to') . ' ' . $_POST['ToPeriod'] . "\n\r"; - + if ($_POST['SalesArea']=='All'){ $GraphTitle .= ' ' . _('For All Sales Areas'); } else { @@ -200,7 +213,7 @@ $myrow = DB_fetch_row($result); $GraphTitle .= ' ' . _('For') . ' ' . $myrow[0]; $WhereClause .= " stkcategory='" . $_POST['CategoryID'] . "' AND"; - + } if ($_POST['SalesmanCode']=='All'){ $GraphTitle .= ' ' . _('For All Salespeople'); @@ -209,7 +222,7 @@ $myrow = DB_fetch_row($result); $GraphTitle .= ' ' . _('For Salesperson:') . ' ' . $myrow[0]; $WhereClause .= " salesperson='" . $_POST['SalesmanCode'] . "' AND"; - + } if ($_POST['GraphOn']=='Customer'){ $GraphTitle .= ' ' . _('For Customers from') . ' ' . $_POST['ValueFrom'] . ' ' . _('to') . ' ' . $_POST['ValueTo']; @@ -219,45 +232,44 @@ $GraphTitle .= ' ' . _('For Items from') . ' ' . $_POST['ValueFrom'] . ' ' . _('to') . ' ' . $_POST['ValueTo']; $WhereClause .= " stockid>='" . $_POST['ValueFrom'] . "' AND stockid<='" . $_POST['ValueTo'] . "' AND"; } - + $WhereClause = 'WHERE ' . $WhereClause . ' salesanalysis.periodno>=' . $_POST['FromPeriod'] . ' AND salesanalysis.periodno <= ' . $_POST['ToPeriod']; - - $SQL = 'SELECT salesanalysis.periodno, - periods.lastdate_in_period, + + $SQL = 'SELECT salesanalysis.periodno, + periods.lastdate_in_period, SUM(CASE WHEN budgetoractual=1 THEN ' . $SelectClause . ' ELSE 0 END) AS sales, SUM(CASE WHEN budgetoractual=0 THEN ' . $SelectClause . ' ELSE 0 END) AS budget FROM salesanalysis INNER JOIN periods ON salesanalysis.periodno=periods.periodno ' . $WhereClause . ' GROUP BY salesanalysis.periodno, periods.lastdate_in_period ORDER BY salesanalysis.periodno'; - - + + $graph->SetTitle($GraphTitle); $graph->SetTitleColor('blue'); $graph->SetOutputFile('companies/' .$_SESSION['DatabaseName'] . '/reports/salesgraph.png'); $graph->SetXTitle(_('Month')); - if ($_POST['GraphValue']=='Net'){ + if ($_POST['GraphValue']=='Net'){ $graph->SetYTitle(_('Sales Value')); - } elseif ($_POST['GraphValue']=='GP'){ + } elseif ($_POST['GraphValue']=='GP'){ $graph->SetYTitle(_('Gross Profit')); } else { $graph->SetYTitle(_('Quantity')); } $graph->SetXTickPos('none'); $graph->SetXTickLabelPos('none'); - $graph->SetBackgroundColor("wheat"); + $graph->SetBackgroundColor("selection"); $graph->SetTitleColor("blue"); $graph->SetFileFormat("png"); - $graph->SetPlotType("bars"); + $graph->SetPlotType($_POST['GraphType']); $graph->SetIsInline("1"); $graph->SetShading(5); $graph->SetDrawYGrid(TRUE); - $graph->SetMarginsPixels(80,40,40,40); $graph->SetDataType('text-data'); - + $SalesResult = DB_query($SQL, $db); if (DB_error_no($db) !=0) { - + prnMsg(_('The sales graph data for the selected criteria could not be retrieved because') . ' - ' . DB_error_msg($db),'error'); include('includes/footer.inc'); exit; @@ -267,24 +279,26 @@ include('includes/footer.inc'); exit; } - + $GraphArrays = array(); $i = 0; while ($myrow = DB_fetch_array($SalesResult)){ $GraphArray[$i] = array(MonthAndYearFromSQLDate($myrow['lastdate_in_period']),$myrow['sales'],$myrow['budget']); $i++; } - + $graph->SetDataValues($GraphArray); $graph->SetDataColors( - array('blue','red'), //Data Colors + array('grey','wheat'), //Data Colors array('black') //Border Colors - ); + ); $graph->SetLegend(array(_('Actual'),_('Budget'))); - + //Draw it $graph->DrawGraph(); + echo '<table class=selection><tr><td>'; echo '<p><img src="companies/' .$_SESSION['DatabaseName'] . '/reports/salesgraph.png" alt="Sales Report Graph"></img></p>'; + echo '</td></tr></table>'; include('includes/footer.inc'); } ?> \ No newline at end of file Modified: trunk/doc/Change.log.html =================================================================== --- trunk/doc/Change.log.html 2010-07-22 09:10:30 UTC (rev 3653) +++ trunk/doc/Change.log.html 2010-07-22 09:11:16 UTC (rev 3654) @@ -1,5 +1,6 @@ <p><font SIZE=4 COLOR=BLUE><b>webERP Change Log</b></font></p> <p></p> +<p>20/07/10 Tim: SalesGraph.php - Layout changes, and sql quoting</p> <p>20/07/10 Tim: PcAuthoriseExpenses.php - Layout changes, and sql quoting</p> <p>20/07/10 Tim: FixedAssetRegister.php - Layout changes, correctly export to csv, and sql quoting</p> <p>20/07/10 Tim: StockLocStatus.php - Add a filter to only show stock with available balances</p> Modified: trunk/includes/phplot/ChangeLog =================================================================== --- trunk/includes/phplot/ChangeLog 2010-07-22 09:10:30 UTC (rev 3653) +++ trunk/includes/phplot/ChangeLog 2010-07-22 09:11:16 UTC (rev 3654) @@ -2,6 +2,168 @@ The project home page is http://sourceforge.net/projects/phplot/ ----------------------------------------------------------------------------- +2010-06-29 (lbayuk) ===== Released as 5.1.2 ===== + * phplot.php: Updated version + * README.txt: Updated for new release + * NEWS.txt: Add text for new release + +2010-06-26 + * Feature request 2885930 "Horizontal Bars": + Horizontal bar charts are implemented, as an experimental feature. + A new data type 'text-data-yx' was added, which works with + 'bars' plot type to produce a horizontal bar chart from a data + array with X values for each Y value. Changes were made to + FindDataLimits, CalcMargins, CalcPlotAreaWorld, CalcBarWidths, + and CalcMaxDataLabelSize to handle the new data type. Other + changes were made to handle label position defaults and grid + defaults. New drawing functions were added for horizontal bars. + + * HorizontalBars.txt: new documentation file for experimental feature. + * Makefile: List new documentation file. + +2010-06-25 + * Each plot-type drawing function now checks that it is getting a data + type that it knows how to handle. A new internal function unifies the + checking and error message. (This is associated with an upcoming, + bigger change.) + + Compatibility: If you were using an invalid data type for a plot type + whose function did not check, will now get an error. + + * Removed some dubious code from DrawLines() and DrawSquared() and + rewrote comments there. The code initialized lastx[0] and lasty[0], + but lasty was mapped using the X (rather than Y) function. This was + obviously wrong, but closer inspection showed that the values were + never, used so the code was removed. + +2010-06-13 + * Truecolor.txt: removed + * Makefile, README.txt: Removed reference to Truecolor.txt. Full + documentation for truecolor images is now in the Reference Manual. + +2010-06-02 + * Fix bug 3010116 "Bad rendering of title in multi-plot image + when using TTF": + Make sure the main title is drawn only once. (If drawn multiple + times with TrueType font text, the anti-aliasing effects result + in poor quality text.) + +2010-05-31 + * Improvements to truecolor support (from feature request 2947679): + Truecolor support is now better integrated. The derived class only + has the constructor now, and the base class itself provides the alpha + color component support through the internal functions SetIndexColor(), + SetIndexDarkColor(), and SetRGBColor(). This means alpha channel + works with palette images too (in so far as GD supports this). + + * Truecolor.txt: Updated per changes to truecolor support. + + * Image tiling with mode 'scale' in tile_img(), used with image and + plot area backgrounds, now uses imagecopyresampled() rather than + imagecopyresized(). They are the same with palette images, but the + resampled copy gets better results with truecolor images. + +2010-05-29 + * Feature request 3002606 "Add to plot and image border options": + Added options 'right', 'top', and 'bottom' to SetPlotBorderType() + (existing options are 'left', 'sides', 'none', and 'full'). This + now also accepts an array of the above options, giving complete + control over which sides to draw. + Added option 'solid' to SetImageBorderType() to use the actual + color set with SetImageBorderColor(), rather than the darker + shade as type 'plain' does (for some reason). + New function SetImageBorderWidth() sets the width of the image + border. The image border width is now accounted for in margin + calculations, although existing plots will not change. + +2010-04-04 (lbayuk) ===== Released as 5.1.1 ===== + * phplot.php: Updated version + * README.txt: Updated for new release + * NEWS.txt: Add text for new release + +2010-04-01 + * Remove & from argument in SetDataValues(). The data array is not + modified and does not need to be passed by reference. (There is + no performance advantage, either.) + +2010-03-29 + * Feature request 2947679 "Support for alpha blending/Truecolor": + Implemented truecolor image support with a new class + PHPlot_truecolor, extended color specifications to allow + specification of an alpha value, and added a new optional parameter + to SetDataColors for a default alpha value for all data colors. + This feature is *EXPERIMENTAL* (see next item). + + * Truecolor.txt: New file, documentation for the new truecolor capability. + (The Truecolor feature is experimental, which means it is subject to + change in incompatible ways and the documentation has not yet been + incorporated into the PHPlot Reference Manual.) + + * Makefile: Include new documentation file in release. + +2010-03-26 + Fixed bug 2976735 "Improvements and fixes for 'area' plots": + Rewrote DrawArea() function which handles 'area' plot. + Part 1: This is related to feature request 2947679, Truecolor support + with transparency. The area plot function was filling each area from the X + axis up to the Y value, resulting in area overlaps. This wasn't a problem + with opaque colors, but with transparency, the overlapping areas resulted + in changed colors. The rewritten function fills the area between each line + instead of from each line down to the X axis. Plots with opaque colors + will not change. + Part 2: Area plots now work when the X axis is moved up with + SetXAxisPosition(). + Part 3: Fixed FindDataLimits() for area (and stackedbars too) to + take absolute values of Y values. The drawing function was doing this, + but not FindDataLimits, resulting in incorrect limits if any Y<0. + Part 4: The rewritten DrawArea() also handles a new plot type + 'stackedarea'. This is an area plot where the Y values are stacked, + similar to 'stackedbars'. + Note: As part of the changes, it is now an error to try an area plot + with an unequal number of Y points for each X. + +2010-03-23 + * Feature request 2973995 "Add y-Data to Stackedbars": + Implemented Y Data Labels for Stacked Bar charts (stackedbars). + The labels are enabled with SetYDataLabelPos, same as with bar charts. + There are two types of labels: above the stack with the total, and + within the bars at each segment. 'plotin' turns on the upper ones, and + 'plotstack' turns both on. + + * Other changes: + + Removed unimplemented second argument to SetYDataLabelPos. + + Fixed questionable logic in SetYDataLabelPos when given an argument + that belongs with SetYTickLabelPos. + + Fix comments at top of plot-type Draw functions. + + * Fix for bug 2974639 "Stacked bars plot breaks with X axis != 0": + Stacked bar plots with non-zero X axis position no longer break apart + into segments with gaps. The bars are drawn up from the X axis, and + any segments or partial segments below the X axis are not drawn. + +2010-03-22 + * Change related to feature request 2947679 - Fix 'dot' point shape: + Use imagefilledellipse(), not imagefilledarc(), when drawing the 'dot' + point shape. The fix was needed for future support of truecolor images + with transparency, but filled dots from imagefilledellipse() look + better (rounder) with regular images and opaque colors. + Credit to mvaldez for identifying the problem and providing the fix. + +2010-03-04 + * Fix for bug 2963757 "point_counts undefined error in 5.1.0": + Fixed CheckPointParams so it sets point_counts even when the point shape + and point size arrays are already the same size and do not need padding. + +2010-01-26 + * Fix for bug 2938219 "Bars go in wrong direction": + Fixed CalcAxisPositions() to be consistent in positioning the X axis. + When all Y values are <0 and the Y=0 line is not part of the plot range, + PHPlot will now default the X axis to the top of the plot, not the + bottom. This fixes the problem with bars to negative Y values being + drawn downward if Y=0 is visible, but upward if Y=0 is not visible. + This also affects thinbarline plots. + Credit to lauryn1298 for finding the bug. + 2009-12-24 (lbayuk) ===== Released as 5.1.0 ===== 2009-12-18 Added: trunk/includes/phplot/HorizontalBars.txt =================================================================== --- trunk/includes/phplot/HorizontalBars.txt (rev 0) +++ trunk/includes/phplot/HorizontalBars.txt 2010-07-22 09:11:16 UTC (rev 3654) @@ -0,0 +1,243 @@ +phplot/HorizontalBars - Documentation for an experimental new plot type +Last updated for PHPlot-5.1.2 on 2010-06-26 +The project home page is http://sourceforge.net/projects/phplot/ +----------------------------------------------------------------------------- +Overview: + +This file documents a new plot type, Horizontal Bars. This was added to +PHPlot in version 5.1.2 as an experimental feature. + + NOTICE: + + This new plot type is experimental. This means anything about this + may change in future releases, in ways that might be incompatible + with the current implementation, or the new plot type might even + be removed completely. The new plot type is not yet documented in + the PHPlot Reference Manual. This text file is the only documentation. + +Feedback on this feature is welcome. Please use the "help & discussion" +forum at http://sourceforge.net/projects/phplot/ + +----------------------------------------------------------------------------- +Usage: + +In a horizontal bar chart, the X axis and Y axis are oriented the same as +in other PHPlot plot types: X axis is horizontal, increasing towards the +right, and Y axis is vertical, increasing towards the top. + + Y + ^ + | + |============== + | + |===== + | + |========= + | + +---------------------> X + +To make a horizontal bar chart, use the same plot type as vertical bar +charts ('bars'), but use the new data type 'text-data-yx'. The new data +type indicates your data array has a different representation, mapping Y +values to X values (instead of X values to Y values). + +For a normal (vertical) bar chart, the data array has type 'text-data' and +looks like this: + $data = array( array('Label1', Y11, Y12, ...), + array('Label2', Y21, Y22, ...), + ...); +Each entry (row) in the data array represents one group of bars. Each group +has a label and one or more Y values. The X values are implicit: the first +row has the first X value, the second row has the second X value, etc. + +For the new horizontal bar charts, the data array has the new type +'text-data-yx' and looks like this: + $data = array( array('Label1', X11, X12, ...), + array('Label2', X21, X22, ...), + ...); +Each entry (row) in the data array represents one group of bars. Each group +has a label and one or more X values. The Y values are implicit: the first +row has the first Y value, the second row has the second Y value, etc. + +As you can see, a vertical bar chart can be changed to a horizontal bar +chart simply by changing the data type passed to SetDataType(). The data +array itself does not change. Other issues with horizontal bar charts are +discussed below. + +This complete script makes a very simple horizontal bar chart: + <?php + require 'phplot.php'; + $p = new PHPlot(800, 800); + $p->SetDataValues(array(array('A', 10, 25), array('B', 30, 5))); + $p->SetDataType('text-data-yx'); + $p->SetPlotType('bars'); + $p->DrawGraph(); + +Note that the bars in a horizontal bar chart are ordered from bottom to top +(that is, increasing Y values). In the example above, the "A" label bar +group is drawn below the "B" label bar group. If you need bars ordered from +top to bottom, you will have to change your data array accordingly. + +----------------------------------------------------------------------------- +Ticks and Labels: + +Since the X axis and Y axis do not change positions for horizontal bar +charts, the label and tick controls still refer to the X and Y axis. +However, the independent values are now Y, and the dependent values are +now X. Also, the label strings in your data array are plotted along the Y +axis for horizontal bar charts, rather than along the X axis for regular +bar charts. + +To control the data labels positions, use SetYDataLabelPos(). New option +values have been added to this function, which was previously used only to +position bar chart value labels with the options 'plotin', 'plotstack', or +'none'. With horizontal bar charts, SetYDataLabelPos() positions the +regular data labels that go along the Y axis. The new option values are +'plotleft', 'plotright', or 'both'. + 'plotleft' : Draw data labels along the left side of the plot area. + 'plotright' : Draw data labels along the right side of the plot area. + 'both' : Draw data labels along both left and right sides. + 'none' : Do not draw data labels. + +For bar charts, it makes no sense to have ticks or tick labels along the +independent axis. This is the Y axis for horizontal bar charts. Therefore, +you should use SetYTickPos('none') to turn off the tick marks on the Y +axis. You do not normally need to use SetYTickLabelPos('none') to turn off +the tick labels along the Y axis, since PHPlot will do this automatically +if your data array has labels. + +To control the presentation of the data labels with horizontal bar charts, +use the correct functions that refer to the Y data labels, not X data +labels as with vertical bar charts. + + SetYDataLabelAngle() or SetYLabelAngle() + Set angle of data label text. Default is 0 degrees. + + SetYDataLabelType() or SetYLabelType() + Select the type of formatting for the data labels. + + SetFont(), SetFontGD(), or SetFontTTF() + Use the element name 'y_label' for the data labels. + +Note that the PHPlot Reference Manual currently says the Y Data Label +functions are only for bar chart data value labels (see Data Value Labels +below regarding this term). That information is out of date. These +functions are now also used for data labels in horizontal bar charts. + +----------------------------------------------------------------------------- +Grid: + +For horizontal bar charts, the X grid lines default on, and the Y grid lines +default off. (This is the opposite of normal bar charts, where the X grid +lines default off, and the Y grid lines default on.) + +----------------------------------------------------------------------------- +Y Axis Position: + +PHPlot uses a different default for the X axis and the Y axis positions. +This affects horizontal bar charts if you have any data values which are +less than zero. The X axis is normally positioned at Y=0, and the Y axis +is normally positioned at the left side of the plot. + +If you have both positive and negative values in your data array, both +vertical and horizontal bar charts will draw the bars away from the zero +value. For vertical bar charts, the X axis will be drawn at that zero value +(perhaps in the middle of the plot), with bars going up and down from +there. But for horizontal bar charts, the Y axis will by default remain at +the left edge of the plot; the bars will start from the X=0 value +(somewhere in the middle of the plot area) and go left and right from +there. In this situation, you might want to use SetYAxisPosition(0) to +force the Y axis to be at X=0. + +----------------------------------------------------------------------------- +Scaling: + +You can use SetPlotAreaWorld() to explicitly set any or all of the 4 limits +of the plot area. Any limits you do not provide will be calculated for you. +The algorithm is due for replacement, but it will now apply the same +calculations to Y and X values in horizontal bar charts as it currently +applies to X and Y (respectively) in vertical bar charts. That is, the +range for the independent variable will be calculated to contain and center +the bar groups, and the range for the dependent variable will include and +usually exceed the actual data range. + +The example under Usage above will produce an auto-calculated Y range of 4 +to 33, with the X range set to center the two bar groups. If you change +'text-data-yx' to 'text-data', you will get a vertical bar chart with the +same automatic range. + +----------------------------------------------------------------------------- +Data Value Labels: + +Data Value Labels are not yet available with horizontal bar charts. These +are the text labels within the plot that identify the data value just above +the bars. (See Example 5.19 "Bar Chart with Data Labels" in the manual.) + +Note: Data Value Labels are currently referred to in the manual as Y Data +Labels. If horizontal bars are accepted and documented in the manual, this +will be changed to call them 'Data Value Labels'. This is necessary to +avoid confusion with X Data Labels and Y Data Labels. + +----------------------------------------------------------------------------- +Other Plot Types Not Available: + +There is currently no corresponding horizontal analog for plot type +stackedbars, nor are there any other horizontal plot types at this time. +Using data type 'text-data-yx' with other plot types will fail. +(Starting with 5.1.2, PHPlot always checks that the selected data type +is supported for the selected plot type.) + +----------------------------------------------------------------------------- +Implementation Notes: + +The following is a summary of the changes made to PHPlot to implement +horizontal bar charts. + +1) Do not initialize y_tick_label_pos or y_data_label_pos. The defaults +have to be dynamically calculated for horizontal bar charts, so tick labels +can be suppressed. (This was already being done for X labels.) Existing +internal function CheckLabels() was extended to do this for Y also. + +2) Do not initialize the X and Y grid setting variables. The defaults have +to be dynamically calculated because they differ with swapped data arrays. +New internal function CalcGridSettings() does this. + +3) SetYDataLabelPos() accepts the new arguments plotleft, plotright, and +both. Old compatibility code that passed these values to SetYTickLabelPos() +has been removed. + +4) SetDataType() accepts a new value: 'text-data-yx'. + +5) FindDataLimits() was changed to properly calculate minimum and maximum +values from text-data-yx data arrays. The arrays data_miny and data_maxy +were renamed to just data_min and data_max, since they now describe limits +of either X or Y values, depending on the data type. + +6) Changes were made to CalcMargins() to account for the labels in the data +array being drawn on the Y axis instead of X axis, in the text-data-yx +case. + +7) CalcPlotAreaWorld() is extended to calculate defaulted plot ranges +correctly for the swapped X/Y case. The algorithm is the same (and due for +replacement). It applies a fixed range to Y and an extended range to X. It +is also ready for possible future expansion to include swapped X/Y plots +with explicit Y values. + +8) Changed CalcBarWidths() to use either the plot area width or height, +depending on the bar directions, when calculating the bar widths. + +9) Extended CalcMaxDataLabelSize() to work with both X and Y labels. +Before, it returned the maximum height of the data labels. Now it can +instead return the maximum width of the data labels; this is used for +horizontal bar charts. It also has to pick the proper font, angle, and +format code for X or Y. + +10) New internal function DrawYDataLabel() to draw data labels for +horizontal bar charts. + +11) New internal function DrawHorizBars() draws the horizontal bar chart. + +12) DrawGraph() now decides to draw a bar or horizontal bar chart based on +the data type (text-data or text-data-yx). + +----------------------------------------------------------------------------- Modified: trunk/includes/phplot/NEWS.txt =================================================================== --- trunk/includes/phplot/NEWS.txt 2010-07-22 09:10:30 UTC (rev 3653) +++ trunk/includes/phplot/NEWS.txt 2010-07-22 09:11:16 UTC (rev 3654) @@ -3,7 +3,140 @@ The project home page is http://phplot.sourceforge.net/ Refer the the ChangeLog file for detailed source changes. ----------------------------------------------------------------------------- -/* Id */ + +2010-06-29 Release 5.1.2 + +Overview: + +This is the current stable release of PHPlot. Truecolor image support is no +longer considered 'experimental', and is now documented in the reference +manual. There is a new experimental feature for horizontal bar charts. This +release also contains a bug fix and new feature. + + +Cautions and Important Notes: + +The advisory against using PHP-5.3.2 or PHP-5.2.13 with PHPlot if you use +TrueType fonts (TTF) continues. See the item below for PHPlot-5.1.1. The +good news is that this has been fixed by the PHP Team and will be in the +next releases. + +Compatibility of data type and plot type are now checked completely. If +you used an incorrect data type with certain plot types, your script may no +longer work until you fix the data type. Specifically, the area, squared, +and thinbarline plot types failed to check the data type they received, and +treated anything other than 'data-data' as 'text-data'. If you have a +squared plot with data type 'data-data-error', for example (which is not +supposed to work), it did produce a plot, but will now result in an error. + +The addition of horizontal bar charts should not impact any existing plot, +with one small exception. The function SetYDataLabelPos() used to accept +some additional, undocumented options (plotleft, plotright, both, yaxis) +and pass these through to SetYTickLabelPos() "for compatibility". It no +longer does so, as some of those are now used for horizontal bar chart +labels. To position Y tick labels, use only SetYTickLabelPos(). + + +New features in 5.1.2: + +#3002606 "Add to plot and image border options": + SetPlotBorderType() now accepts 'right', 'top', and 'bottom', as well + as an array of options. So you can now control exactly which of the 4 + border sides will be drawn. + SetImageBorderType() now accepts 'solid' as a choice. This will use the + actual color set with SetImageBorderColor(), rather than the darker + shade as type 'plain' does (which may have been a bug). + SetImageBorderWidth() is a new function that sets the width of the image + border. The defaults are the same as the fixed values used before: 1 + pixel for plain, 2 pixels for raised. The image border width is now + accounted for in margin calculations, if it is greater than 2 (to make + sure existing plots will not change). + +#2885930 "Horizontal Bars": + Horizontal bar charts are implemented, as an experimental feature. + 'Experimental' means they are not yet documented in the reference manual, + and subject to change or removal. + Refer to the text file HorizontalBars.txt for details. + +#2947679 (follow-up) "Support for alpha blending/Truecolor": + Truecolor support is now documented in the Reference Manual. The interim + documentation file Truecolor.txt has been removed. Alpha channel + specification now works with both constructors and both image types. This + fixes an issue if the base constructor was used with a truecolor background + image. (In PHPlot-5.1.1, the result would be a truecolor image, but the + alpha channel features were not available.) + + +Bug Fixed in 5.1.2: + +#3010116 "Bad rendering of title in multi-plot image when using TTF": + Make sure the main title is drawn only once, to avoid bad rendering of + TTF titles with multiple plots due to anti-aliasing. + +----------------------------------------------------------------------------- + +2010-04-04 Release 5.1.1 + +Overview: + +This is the current stable release of PHPlot. This release adds truecolor +image support as an experimental feature, fixes a number of bugs and adds +a few new features. + +The PHPlot reference manual has been updated to match this release. The +manual is available as a separate download from Sourceforge. The manual is +also available for on-line viewing from the project home page. + +See the ChangeLog file in the release for more about changes and bug fixes. + + +Cautions and Important Notes: + +Avoid using PHP-5.3.2 or PHP-5.2.13 with PHPlot if you use TrueType fonts +(TTF). Some new bugs were introduced in those releases that adversely +affects accurate positioning and rendering of TrueType font text. + + +New features in 5.1.1: + +#2947679 "Support for alpha blending/Truecolor": + PHPlot can now produce truecolor images, with alpha blending of colors and + other effects. This is considered an experimental feature, meaning it is + not yet documented in the PHPlot Reference Manual, and subject to change. + Refer to the text file Truecolor.txt included in the PHPlot release for + information on using truecolor. + Two drawing changes were made to improve plot appearance with Truecolor: + + Filled dots (in points & linespoints plots) are now drawn better. This + also makes them look rounder with regular (non-Truecolor) plots. + + Area plots have the areas filled without overlapping each area down to + the Y axis. This was needed to fix problems with alpha blending, and + should have no effect on non-Truecolor plots. + +#2973995 "Add y-Data to Stackedbars": + You can now have Y Data Labels with 'stackedbars' plots. These label the Y + values (incremental and total) for each bar. Refer to the reference manual + page for SetYDataLabelPos(). + + +Bug Fixes in 5.1.1: + +#2976735 "Improvements and fixes for 'area' plots": + Moving X axis works; handle Y<0 better; new 'stackedarea' plot type is a + variation on 'area' with the data represented differently. + +#2974639 "Stacked bars plot breaks with X axis != 0": + Moving X axis works. + +#2963757 "point_counts undefined error in 5.1.0": + Fixed an error introduced in PHPlot-5.1.0 when point size and shape arrays + were set to the same size. + +#2938219 "Bars go in wrong direction": + For bar charts with all Y<0, bars will still be drawn down even if Y=0 is + not in range. + +----------------------------------------------------------------------------- + 2009-12-24 Release 5.1.0 Overview: @@ -651,7 +784,7 @@ Testing: - + Since its output is visual (graphics), and it has so many interconnected modes and options, PHPlot is difficult to test. But at least we are now trying. I have a collection of PHPlot scripts (currently about 60) and a Modified: trunk/includes/phplot/README.txt =================================================================== --- trunk/includes/phplot/README.txt 2010-07-22 09:10:30 UTC (rev 3653) +++ trunk/includes/phplot/README.txt 2010-07-22 09:11:16 UTC (rev 3654) @@ -1,9 +1,9 @@ This is the README file for PHPlot -Last updated for PHPlot-5.1.0 on 2009-12-24 +Last updated for PHPlot-5.1.2 on 2010-06-29 The project web site is http://sourceforge.net/projects/phplot/ The project home page is http://phplot.sourceforge.net/ ----------------------------------------------------------------------------- -/* Id */ + OVERVIEW: PHPlot is a PHP class for creating scientific and business charts. @@ -20,6 +20,7 @@ COPYING . . . . . . . . . . . . LGPL 2.1 License file ChangeLog . . . . . . . . . . . Lists changes to the sources + HorizontalBars.txt . . . . . . . Experimental feature documentation NEWS.txt . . . . . . . . . . . . Highlights changes in releases README.txt . . . . . . . . . . This file contrib . . . . . . . . . . . . "Contributed" directory, add-ons @@ -27,14 +28,20 @@ phplot_data.php . . . . . . . . Auxiliary and extended functions rgb.inc.php . . . . . . . . . . Optional extended color table - REQUIREMENTS: -You need a recent version of PHP5, and you are advised to use the latest -stable release. This version of PHPlot has been tested with PHP-5.3.1 and -PHP-5.2.12 on Linux, and with PHP-5.3.1 on Windows/XP. PHP4 is no longer -supported. +You need a recent version of PHP5. Usually, we recommend you use the latest +stable release, however due to problems with PHP-5.3.2 and PHP-5.2.13 you +are advised to use the previous releases if possible. The problems are +specific to TrueType font (TTF) text. If you are not using TTF text, you +may use PHP-5.3.2 or 5.2.13. (The PHP team already has a fix for this TTF +problem in PHP-5.3.3 development snapshots, so the fix should be in the +next releases PHP-5.3.3 and PHP-5.2.14.) +This version of PHPlot has been tested with PHP-5.3.1 and PHP-5.2.12 on +Linux, and with PHP-5.3.1 on Windows/XP. The PHPlot Test Suite currently +contains 432 test cases. + You need the GD extension to PHP either built in to PHP or loaded as a module. Refer to the PHP documentation for more information - see the Image Functions chapter in the PHP Manual. We test PHPlot only with the @@ -46,7 +53,7 @@ PHPlot supports TrueType fonts, but does not include any TrueType font files. If you want to use TrueType fonts on your charts, you need to have TrueType support in GD, and some TrueType font files. By default, PHPlot -uses a simple font built-in to the GD library. +uses a simple font which is built in to the GD library. INSTALLATION: @@ -60,7 +67,7 @@ phplot_data.php rgb.inc.php (Only phplot.php is necessary for most graphs.) -Make sure the protections on these files allow the web server to read them. +Make sure the permissions on these files allow the web server to read them. The ideal place is a directory outside your web server document area, and on your PHP include path. You can add to the include path in the PHP @@ -72,7 +79,7 @@ Here are some of the problems we know about in PHPlot. See the bug tracker on the PHPlot project web site for more information. -#1795969 The automatic range calculation for Y values needs to be rewritten. +#1795969 The automatic range calculation for Y values needs to be rewritten. This is especially a problem with small offset ranges (e.g. Y=[999:1001]). You can use SetPlotAreaWorld to set a specific range instead. @@ -83,7 +90,10 @@ Tick interval calculations should try for intervals of 1, 2, or 5 times a power of 10. +PHP Bugs #51207, #51094, and others: These are PHP bugs, not PHPlot, +on rendering of TrueType font (TTF) text in PHP-5.3.2 and 5.2.13. + If you think you found a problem with PHPlot, or want to ask questions or provide feedback, please use the Help and Discussion forum at http://sourceforge.net/projects/phplot/ @@ -129,7 +139,7 @@ COPYRIGHT and LICENSE: -PHPlot is Copyright (C) 1998-2009 Afan Ottenheimer +PHPlot is Copyright (C) 1998-2010 Afan Ottenheimer This is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public Added: trunk/includes/phplot/contrib/README.txt =================================================================== --- trunk/includes/phplot/contrib/README.txt (rev 0) +++ trunk/includes/phplot/contrib/README.txt 2010-07-22 09:11:16 UTC (rev 3654) @@ -0,0 +1,31 @@ +This is the README for PHPlot Contributed Code +The project web site is http://sourceforge.net/projects/phplot/ +Last updated on 2009-12-08 +----------------------------------------------------------------------------- + +The PHPlot Contributed Code directory contains code you might find useful +with PHPlot, but that doesn't quite belong as part of PHPlot itself. + +You will have to read the comments in the code files, and see the example +files, to determine what these do and if they are useful to you. None of +these functions is documented in the PHPlot Reference Manual. + +You may include or paste these functions into your own scripts. Check the +files for details, but some of these are considered "public domain" with no +usage or license restrictions. + +----------------------------------------------------------------------------- +Contents: + +prune_labels: Reduce the number of labels along the X axis + prune_labels.php . . . . . . . . . . . . Code + prune_labels.example.php . . . . . . . . Example + prune_labels.test.php . . . . . . . . . Test + +color_range: Create a gradient color map for data colors + color_range.php . . . . . . . . . . . . Code + color_range.example.php . . . . . . . . Example + color_range.test1.php . . . . . . . . . Image creation test + color_range.test2.php . . . . . . . . . Unit test + +----------------------------------------------------------------------------- Added: trunk/includes/phplot/contrib/color_range.example.php =================================================================== --- trunk/includes/phplot/contrib/color_range.example.php (rev 0) +++ trunk/includes/phplot/contrib/color_range.example.php 2010-07-22 09:11:16 UTC (rev 3654) @@ -0,0 +1,35 @@ +<?php +# PHPlot / contrib / color_range : Example +# $Id: color_range.example.php,v 1.1 2009/12/09 03:45:45 lbayuk Exp $ +# This is a bar chart with a color gradient for the bars in each group. + +require_once 'phplot.php'; +require_once 'color_range.php'; + +$bars_per_group = 10; +$x_values = 4; + +mt_srand(1); +$data = array(); +for ($i = 0; $i < $x_values; $i++) { + $row = array($i); + for ($j = 0; $j < $bars_per_group; $j++) $row[] = mt_rand(0, 100); + $data[] = $row; +} + +$p = new PHPlot(800, 600); +$p->SetTitle('Example - Bar Chart with gradient colors'); +$p->SetDataType('text-data'); +$p->SetDataValues($data); +$p->SetPlotAreaWorld(0, 0, $x_values, 100); + +# This isn't necessary, as we do know how many data sets (bars_per_group): +$n_data = count_data_sets($data, 'text-data'); +# Make a gradient color map: +$colors = color_range($p->SetRGBColor('SkyBlue'), + $p->SetRGBColor('DarkGreen'), $n_data); +$p->SetDataColors($colors); +$p->SetXTickLabelPos('none'); +$p->SetXTickPos('none'); +$p->SetPlotType('bars'); +$p->DrawGraph(); Added: trunk/includes/phplot/contrib/color_range.php =================================================================== --- trunk/includes/phplot/contrib/color_range.php (rev 0) +++ trunk/includes/phplot/contrib/color_range.php 2010-07-22 09:11:16 UTC (rev 3654) @@ -0,0 +1,100 @@ +<?php +/* + PHPlot / contrib / color_range + $Id: color_range.php,v 1.1 2009/12/09 03:45:48 lbayuk Exp $ + PHPlot contrib code - public domain - no copyright - use as you wish + + Original contribution from: Josep Sanz <josep dot sans at w3 dot es> + "I wrote this code to calculate the range of colors between 2 colors + to plot using the range from color_a to color_b..." + + I have changed the code and repackaged it, but the idea is the same. + Given 2 colors and number of data sets, computes an array of colors + that make up a gradient between the two provided colors, for use + with SetDataColors(). + + Provides the following functions: + $colors = color_range($color_a, $color_b, $n_intervals) + Returns a color array for SetDataColors. + + $n = count_data_sets($data, $data_type) + Counts the number of data sets in a data array. + This can be used to provide $n_intervals in color_range(). +*/ + + + +/* + Fill a color map with a gradient step between two colors. + Arguments: + $color_a : Starting color for the gradient. Array of (r, g, b) + $color_b : Ending color for the gradient. Array of (r, g, b) + $n_steps : Total number of color steps, including color_a and color_b. + + Returns: A color map array with n_steps colors in the form + $colors[i][3], suitable for SetDataColors(). + + Notes: + You may use the PHPlot internal function $plot->SetRGBColor($color) + to convert a color name or #rrggbb notation into the required array + of 3 values (r, g, b) for color_a and color_b. + +*/ +function color_range($color_a, $color_b, $n_steps) +{ + if ($n_steps < 2) $n_steps = 2; + $nc = $n_steps - 1; + # Note: $delta[] and $current[] are kept as floats. $colors is integers. + for ($i = 0; $i < 3; $i++) + $delta[$i] = ($color_b[$i] - $color_a[$i]) / $nc; + $current = $color_a; + for ($col = 0; $col < $nc; $col++) { + for ($i = 0; $i < 3; $i++) { + $colors[$col][$i] = (int)$current[$i]; + $current[$i] += $delta[$i]; + } + } + $colors[$nc] = $color_b; # Make sure the last color is exact. + return $colors; +} + + +/* + Determine the number of data sets (plot lines, bars per group, pie + segments, etc.) contained in a data array. + This can be used to determine n_steps for $color_range. + + Arguments: + $data : PHPlot data array + $data_type : PHPlot data type, describing $data. (e.g. 'data-data') + Returns: The number of data sets in the data array. + Notes: + This has to scan the entire data array. Don't use this unless you + really don't have a better way to determine the number of data sets. + + This does NOT require that the data array be integer indexed. + +*/ +function count_data_sets($data, $data_type) +{ + + if ($data_type == 'text-data-single') + return count($data); # Pie chart, 1 segment per record + + # Get the longest data record: + $max_row = 0; + foreach ($data as $row) + if (($n = count($row)) > $max_row) $max_row = $n; + + if ($data_type == 'text-data') + return ($max_row - 1); # Each record is (label Y1 Y2...) + + if ($data_type == 'data-data') + return ($max_row - 2); # Each record is (label X Y1 Y2...) + + if ($data_type == 'data-data-error') + return (($max_row - 2) / 3); # Each record is (label X Y1 Y1+ Y1-...) + + # Not a recognized data type... Just return something sane. + return $max_row; +} Property changes on: trunk/includes/phplot/contrib/color_range.php ___________________________________________________________________ Added: svn:executable + * Added: trunk/includes/phplot/contrib/color_range.test1.php =================================================================== --- trunk/includes/phplot/contrib/color_range.test1.php (rev 0) +++ trunk/includes/phplot/contrib/color_range.test1.php 2010-07-22 09:11:16 UTC (rev 3654) @@ -0,0 +1,55 @@ +<?php +# PHPlot / contrib / color_range : Test 1, make a picture +# $Id: color_range.test1.php,v 1.1 2009/12/09 03:45:49 lbayuk Exp $ +# This creates a PNG file on output with a color gradient. + +require_once 'color_range.php'; + +function usage() +{ + fwrite(STDERR, "Usage: color_range.test1.php color1 color2 number_of_colors +Each color is of the form rrggbb with 2 digit hex color components. +"); + exit(1); +} + +# Split color "rrggbb" into separate components. Code is from PHPlot. +function rgb($color) +{ + return array(hexdec(substr($color, 1, 2)), + hexdec(substr($color, 3, 2)), + hexdec(substr($color, 5, 2))); +} + +if ($_SERVER['argc'] != 4) usage(); + +$color1 = rgb($_SERVER['argv'][1]); +$color2 = rgb($_SERVER['argv'][2]); +$n_col = (int)$_SERVER['argv'][3]; +if ($n_col < 2) usage(); + +# Build a color map from colors[0]=color1 to colors[$n_col-1]=color2. +$colors = color_range($color1, $color2, $n_col); + +# Make a picture: +$w = 800; +$h = 800; +$im = imagecreate($w, $h); +$background = imagecolorresolve($im, 0, 0, 0); +for ($col = 0; $col < $n_col; $col++) { + list($r, $g, $b) = $colors[$col]; + $colmap[$col] = imagecolorresolve($im, $r, $g, $b); +} + +$margin = 20; +$bar_width = (int)(($w - 2 * $margin) / $n_col); +$x1 = $margin; +$x2 = $x1 + $bar_width; +$y1 = $margin; +$y2 = $h - $margin; +for ($col = 0; $col < $n_col; $col++) { + imagefilledrectangle($im, $x1, $y1, $x2, $y2, $colmap[$col]); + $x1 = $x2; + $x2 += $bar_width; +} +imagepng($im); Added: trunk/includes/phplot/contrib/color_range.test2.php =================================================================== --- trunk/includes/phplot/contrib/color_range.test2.php (rev 0) +++ trunk/includes/phplot/contrib/color_range.test2.php 2010-07-22 09:11:16 UTC (rev 3654) @@ -0,0 +1,73 @@ +<?php +/* + PHPlot / contrib / color_range : Unit tests + $Id: color_range.test2.php,v 1.1 2009/12/09 03:45:51 lbayuk Exp $ + + Tests color.range.php functions: + color_range($color_a, $color_b, $n_steps) + count_data_sets($data, $data_type) + +*/ +require_once 'color_range.php'; + + +# Testing count_data_sets() +function test_count_data_sets($data, $data_type, $expected) +{ + $n = count_data_sets($data, $data_type); + if ($n == $expected) $result = "Pass"; + else $result = "FAIL: Expected $expected but got"; + echo "$result: $n data sets, $data_type with " . count($data) . " records.\n"; +} + +function test_driver_count_data_sets() +{ + echo "\nTesting count_data_sets():\n"; + $data1 = array(array('a', 1, 2, 3), array('b', 2, 2, 3)); + $data2 = array(array('a', 1, 2, 3, 4, 5, 6, 7), array('b', 2, 4, 5, 6)); + $data3 = array(array('', 1), array('', 2), array('', 3), array('', 4)); + $data4 = array(array('', 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13), + array('', 1, 2, 3, 4, 5, 6, 7), + array('', 1, 2, 3, 4)); + + test_count_data_sets($data1, 'text-data', 3); + test_count_data_sets($data1, 'data-data', 2); + test_count_data_sets($data2, 'data-data-error', 2); + test_count_data_sets($data3, 'text-data-single', 4); + + test_count_data_sets($data4, 'text-data', 13); + test_count_data_sets($data4, 'data-data', 12); + test_count_data_sets($data4, 'data-data-error', 4); + test_count_data_sets($data4, 'text-data-single', 3); +} + +# Testing color_range() +function test_color_range($color1, $color2, $nsteps, $expected) +{ + $info = 'From (' . implode(', ', $color1) + . ') To (' . implode(', ', $color2) . ") with $nsteps steps"; + + $colors = color_range($color1, $color2, $nsteps); + if ($colors == $expected) echo "Pass: $info\n"; + else echo "FAIL: $info\n" . print_r($colors, True) . "\n"; + if (($n = count($colors)) != $nsteps) + echo "FAIL: Bad count $n expecting $nsteps\n"; +} + +function test_driver_color_range() +{ + echo "\nTesting color_range():\n"; + test_color_range(array(0,0,0), array(255,255,255), 3, + array(array(0,0,0), array(127,127,127), array(255,255,255))); + + test_color_range(array(255,0,0), array(0,255,0), 2, + array(array(255,0,0), array(0,255,0))); + + test_color_range(array(100,0,100), array(0,100,0), 6, + array(array(100,0,100), array(80,20,80), array(60,40,60), + array(40,60,40), array(20,80,20), array(0,100,0))); +} + + +test_driver_count_data_sets(); +test_driver_color_range(); Added: trunk/includes/phplot/contrib/prune_labels.example.php =================================================================== --- trunk/includes/phplot/contrib/prune_labels.example.php (rev 0) +++ trunk/includes/phplot/contrib/prune_labels.example.php 2010-07-22 09:11:16 UTC (rev 3654) @@ -0,0 +1,31 @@ +<?php +# PHPlot / contrib / prune_labels : Example +# $Id: prune_labels.example.php,v 1.1 2009/12/09 03:45:53 lbayuk Exp $ +# This produces 250 data points with date-formatted labels, and sets +# a max of 20 labels to display. + +require_once 'phplot.php'; +require_once 'prune_labels.php'; + +$base = mktime(12, 0, 0, 1, 1, 2000); +$data = array(); +for ($i = 0; $i < 250; $i++) { + $data[] = array(86400 * $i + $base, $i, $i * 0.20); +} + +# Show no more than 20 labels: +prune_labels($data, 20); + +$p = new PHPlot(800, 600); +$p->SetTitle('Example - pruned data labels'); +$p->SetDataType('data-data'); +$p->SetDataValues($data); +$p->SetXLabelType('time', '%Y-%m-%d'); +$p->SetXLabelAngle(90); +$p->SetXDataLabelPos('plotdown'); +$p->SetXTickLabelPos('none'); +$p->SetXTickPos('none'); +$p->SetDrawXGrid(False); +$p->SetDrawYGrid(False); +$p->SetPlotType('lines'); +$p->DrawGraph(); Added: trunk/includes/phplot/contrib/prune_labels.php =================================================================== --- trunk/includes/phplot/contrib/prune_labels.php (rev 0) +++ trunk/includes/phplot/contrib/prune_labels.php 2010-07-22 09:11:16 UTC (rev 3654) @@ -0,0 +1,36 @@ +<?php +/* + PHPlot / contrib / prune_labels + $Id: prune_labels.php,v 1.1 2009/12/09 03:45:55 lbayuk Exp $ + PHPlot contrib code - public domain - no copyright - use as you wish + +Reduce the number of data labels along the X axis, when the density is too +high. This simply blanks out M-1 of every M labels in the data array. +There are other ways to do this, but we need to keep the labels uniformly +spaced. You select the target maximum label count (maxlabels), and you will +get no more than maxlabels data labels. + + Arguments: + $data - The PHPlot data array (reference variable) + $maxlabels - The maximum number of data labels you are willing to have, + Returns: Nothing + Modifies the $data array in place to remove some of the labels. + + Notes: + The data array and its rows must be 0-based integer indexed arrays. +*/ +function prune_labels(&$data, $maxlabels) +{ + # Do nothing if there are not already too many labels: + if (($n = count($data)) <= $maxlabels) return; + + # Compute how many labels to erase. Keep 1 of every $m labels. + $m = (int)ceil($n / $maxlabels); + + # Process the data array, zapping M-1 of every M labels: + $k = 0; + for ($i = 0; $i < $n; $i++) { + if ($k > 0) $data[$i][0] = ''; + if (++$k >= $m) $k = 0; + } +} Added: trunk/includes/phplot/contrib/prune_labels.test.php =================================================================== --- trunk/includes/phplot/contrib/prune_labels.test.php (rev 0) +++ trunk/includes/phplot/contrib/prune_labels.test.php 2010-07-22 09:11:16 UTC (rev 3654) @@ -0,0 +1,41 @@ +<?php +# PHPlot / contrib / prune_labels : Test +# $Id: prune_labels.test.php,v 1.1 2009/12/09 03:45:57 lbayuk Exp $ +# Test driver for contrib / prune_labels + +require_once 'prune_labels.php'; + +/* Testing the prune_labels function: */ +function test($count, $maxlabels) +{ + # Make an array of count records, like PHPlot uses, with labels: + $data = array(); + for ($i = 0; $i < $count; $i++) { + $data[] = array("Row $i", $i, 100, 200, 300); + } + + prune_labels($data, $maxlabels); + + # See how many labels are non-blank now: + $line = ''; + $non_blank = 0; + for ($i = 0; $i < $count; $i++) { + if (!empty($data[$i][0])) { + $non_blank++; + $line .= '*'; + } else { + $line .= '_'; + } + } + $status = ($non_blank <= $maxlabels) ? 'PASS' : 'FAIL'; + echo "$status: $count rows, maxlabels=$maxlabels => $non_blank labels\n"; + echo substr($line, 0, 80) . "\n"; # Only show first 80 chars. +} + +/* Test cases for prune_labels */ +for ($n = 7; $n <= 1000; $n *= 2) test($n, 10); +for ($g = 5; $g <= 40; $g++) test(72, $g); +# Edge cases +test(80, 41); +test(80, 40); +test(80, 39); Modified: trunk/includes/phplot/phplot.php =================================================================== --- trunk/includes/phplot/phplot.php 2010-07-22 09:10:30 UTC (rev 3653) +++ trunk/includes/phplot/phplot.php 2010-07-22 09:11:16 UTC (rev 3654) @@ -1,13 +1,13 @@ <?php -/* $Id: phplot.php,v 1.167 2009/12/23 22:37:47 lbayuk Exp $ */ +/* $Id: phplot.php,v 1.182 2010/06/30 00:39:08 lbayuk Exp $ */ /* - * PHPLOT Version 5.1.0 + * PHPLOT Version 5.1.2 * * A PHP class for creating scientific and business charts * Visit http://sourceforge.net/projects/phplot/ * for PHPlot documentation, downloads, and discussions. * --------------------------------------------------------------------- - * Copyright (C) 1998-2009 Afan Ottenheimer + * Copyright (C) 1998-2010 Afan Ottenheimer * * This is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -74,7 +74,7 @@ public $output_file = ''; // For output to a file instead of stdout //Data - public $data_type = 'text-data'; // text-data, data-data-error, data-data, text-data-single + public $data_type = 'text-data'; // Structure of the data array public $plot_type= 'linepoints'; // bars, lines, linepoints, area, points, pie, thinbarline, squared public $label_scale_position = 0.5; // Shifts data labels in pie charts. 1 = top, 0 = bottom @@ -100,15 +100,14 @@ // they are drawn at graph plotting time, by Draw*DataLabel(), called by DrawLines(), etc. // Draw*DataLabel() also draws H/V lines to datapoints depending on draw_*_data_label_lines // Tick Labels - // x_tick_label_pos and x_data_label_pos are not initialized, because PHPlot needs - // to determine if they were defaulted or set by the user. See CheckLabels(). - // public $x_tick_label_pos = 'plotdown'; // plotdown, plotup, both, xaxis, none - public $y_tick_label_pos = 'plotleft'; // plotleft, plotright, both, yaxis, none + // Tick and Data label positions are not initialized, because PHPlot needs to tell if they + // defaulted or are set by the user. See CheckLabels() for details. The variables and + // effective defaults are shown here in comments (but CheckLabe... [truncated message content] |