Source for file Utils.php
Documentation is available at Utils.php
* Description: Chart utility procedures
* @copyright (c) 1995-2008 by Steema Software SL. All Rights Reserved. <info@steema.com>
* @link http://www.steema.com
private $TicksPerMillisecond = 10000;
// Number of milliseconds per time unit
private $MillisPerSecond = 1000;
private $MillisPerMinute;
private $DaysPerYear = 365;
// Number of days in 4 years
// Number of days in 100 years
private $DaysPer100Years;
// Number of days in 400 years
private $DaysPer400Years;
// Number of days from 1/1/0001 to 12/31/1600
//static final int DaysTo1601 = DaysPer400Years * 4;
// Number of days from 1/1/0001 to 12/30/1899
private $DoubleDateOffset;
// The minimum OA date is 0100/01/01 (Note it's year 100).
// The maximum OA date is 9999/12/31
private $OADateMinAsTicks;
// Converts RGB color to Hex
static function rgbhex($red,$green,$blue) {
return new Color($r,$g,$b);
* Evaluates and returns a steema.<!-- -->teechart.<!-- -->DateTimeStep
* value as an Axis double scale that may be used to set the
* steema.<!-- -->teechart.<!-- -->Axis.<!-- -->Increment.
* @param value DateTimeStep
return (int) $tmpDateTimeStep->STEP[$value];
public function Utils() {
$this->TicksPerSecond = $this->TicksPerMillisecond * 1000;
$this->TicksPerMinute = $this->TicksPerSecond * 60;
$this->TicksPerHour = $this->TicksPerMinute * 60;
$this->TicksPerDay = $this->TicksPerHour * 24;
$this->MillisPerMinute = $this->MillisPerSecond * 60;
$this->MillisPerHour = $this->MillisPerMinute * 60;
$this->MillisPerDay = $this->MillisPerHour * 24;
$this->DaysPer4Years = $this->DaysPerYear * 4 + 1;
$this->DaysPer100Years = $this->DaysPer4Years * 25 - 1;
$this->DaysPer400Years = $this->DaysPer100Years * 4 + 1;
$this->DaysTo1899 = $this->DaysPer400Years * 4 + $this->DaysPer100Years * 3 - 367;
$this->DoubleDateOffset = $this->DaysTo1899 * $this->TicksPerDay;
$this->OADateMinAsTicks = ($this->DaysPer100Years - $this->DaysPerYear) * $this->TicksPerDay;
* Recursively delete a directory
* @param string $dir Directory name
* @param boolean $deleteRootToo Delete specified top-level directory as well
while (false !== ($obj = readdir($dh)))
if($obj == '.' || $obj == '..')
if (!@unlink($dir . '/' . $obj))
// Copied from Microsoft's SSCLI sources.
static private function ticksToOADate($value) /* todo throws Exception*/ {
return 0.0; // Returns OleAut's zero'ed date value.
if ($value < $this->TicksPerDay) { // This is a fix for VB. They want the default day to be 1/1/0001 rathar then 12/30/1899.
$value += $this->DoubleDateOffset; // We could have moved this fix down but we would like to keep the bounds check.
if ($value < $this->OADateMinAsTicks) {
throw new Exception("Arg_OleAutDateInvalid");
// Currently, our max date == OA's max date (12/31/9999), so we don't
// need an overflow check in that direction.
$millis = ($value - $this->DoubleDateOffset) / $this->TicksPerMillisecond;
$frac = $millis % $this->MillisPerDay;
$millis -= ($this->MillisPerDay + $frac) * 2;
return (double) $millis / $this->MillisPerDay;
} catch (NumberFormatException $e) {
// } catch (FormatException e) {
// } catch (OverflowException e) {
static private function privateSort($l, $r, $c, $s) {
$x = round(($i + $j) / 2);
while ($c->compare($i, $x) < 0) {
} while ($c->compare($x, $j) < 0) {
$this->privateSort($l, $j, $c, $s);
$this->privateSort($i, $r, $c, $s);
static public function sort($startIndex, $endIndex, $c, $s) {
self::privateSort($startIndex, $endIndex, $c, $s);
/* TODO static public void sort(final int[] x, int startIndex, int endIndex,
sort(startIndex, endIndex, c, new Swapper() {
public void swap(int a, int b) {
* Make a recursive copy of an array
* @return array copy of source array
// check if input is really an array
throw new Exception("Input is not an Array");
// initialize return array
// loop through array and assign keys+values to new return array
for ($x= 0;$x< count($aKeys);$x++ ) {
$aRetAr[$aKeys[$x]]= clone $aVals[$x];
// assign just a plain scalar value
$aRetAr[$aKeys[$x]]= $aVals[$x];
* Number of chart Tool types.
public static $TOOLTYPESCOUNT = 19; //CDI ExtraLegend + GridBand (+2)
* List of chart Tool classes.
/* TODO final static public Class[] toolTypesOf = {
// AxisScrollEditor.class,
// LightToolEditor.class,
// ScrollBarEditor.class,
// SurfaceNearestToolEditor.class,
// ToolSeriesEditor.class,
* Returns the index in ToolTypesOf list of a given tool instance.
* @param tool Tool to search its type in list
/* tODO static public int toolTypeIndex(Tool tool) {
for (int t = 0; t < Utils.TOOLTYPESCOUNT; t++) {
if (Utils.toolTypesOf[t] == tool.getClass()) {
* Number of chart Function types.
public static $FUNCTIONTYPESCOUNT = 37;
* List of chart Function types.
/* tODO final static public Class[] functionTypesOf = {
MomentumDivision.class, //2
RootMeanSquare.class, //1
final static public int[] functionGalleryPage = {
0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 1,
1, 3, 3, 1, 1, 2, 2, 2, 3, 2, 2,
static public int seriesTypesIndex(ISeries s) {
return seriesTypesIndex(s.getClass());
static public int seriesTypesIndex(Class seriesType) {
for (int t = 0; t < SERIESTYPESCOUNT; t++) {
if (seriesTypesOf[t] == seriesType) {
public static $SERIESTYPESCOUNT = 46;
final static public int[] seriesGalleryCount = {
2, 2, 2, 2, 2, 2, 2, 1, 3
1, 1, 1, 1, 1, 2, 2, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 2, 2, 1, 1, 1,
1, 1, 1, 2, 1, 1, 1, 1, 1, 1
final static public int[] seriesGalleryPage = {
0, 0, 0, 0, 0, 0, 0, 0, 0,
2, 3, 2, 4, 4, 3, 3, 5, 5, 3, 4, 5,
5, 4, 4, 1, 1, 1, 4, 3, 5, 1, 4, 1,
1, 1, 0, 4, 2, 3, 4, 3, 3, 5
/*final*/ static public /*Class[]*/ $seriesTypesOf = Array(
public static InputStream downloadURLStream(String url) throws
MalformedURLException, IOException {
return new URL(url).openStream();
public static String downloadURLString(String url) throws IOException {
Reader reader = new InputStreamReader(downloadURLStream(url), "UTF-8");
StringBuffer sb = new StringBuffer();
while ((c = reader.read()) != -1) {
static public function MulDiv($a, $b, $c) {
if (nMod >= c / 2) { // Round up if >= 0.5
static public String dateTimeToStr(double datetime) {
return new DateTime(datetime).toShortDateString();
static public String dateTimeToStr(DateTime datetime) {
return datetime.toShortDateString();
static public String dateTimeToDateTimeStr(DateTime datetime) {
return datetime.toShortDateString() + " " + datetime.toShortTimeString();
static public String timeToStr(double datetime) {
return new com.steema.teechart.DateTime(datetime).toShortTimeString();
static public String timeToStr(DateTime datetime) {
return datetime.toShortTimeString();
static public String arrayToString(String[] a) {
return arrayToString(a, '\n');
static public String arrayToString(String[] a, char separator) {
StringBuffer result = new StringBuffer();
for (int i = 1; i < a.length; i++) {
result.append(separator);
return result.toString();
static public void drawCheckBox(int x, int y, IGraphics3D g,
boolean drawChecked, boolean CheckBox,
java.awt.Color backColor) {
int TeeCheckBoxSize = 11;
g.getPen().setStyle(DashStyle.SOLID);
g.getPen().setColor(Color.GRAY);
g.line(x + TeeCheckBoxSize, y, x, y);
g.line(x, y, x, y + TeeCheckBoxSize + 1);
g.getPen().setColor(Color.lightGray);
g.line(x, y + TeeCheckBoxSize + 1, x + TeeCheckBoxSize + 1,
y + TeeCheckBoxSize + 1);
g.line(x + TeeCheckBoxSize + 1, y + TeeCheckBoxSize + 1,
x + TeeCheckBoxSize + 1, y);
g.getPen().setColor(Color.BLACK);
g.line(x + 1, y + 1, x + TeeCheckBoxSize, y + 1);
g.line(x + 1, y + 1, x + 1, y + TeeCheckBoxSize);
g.getPen().setStyle(DashStyle.SOLID);
g.getPen().setColor(Color.BLACK);
for (int t = 1; t < 4; t++) {
g.line(x + 2 + t, y + 4 + t, x + 2 + t, y + 7 + t);
for (int t = 1; t < 5; t++) {
g.line(x + 5 + t, y + 7 - t, x + 5 + t, y + 10 - t);
|