Merge branch 'bootstrap' of https://github.com/PrestaShop/PrestaShop into bootstrap
@@ -23,7 +23,7 @@
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*}
|
||||
|
||||
<div class="blocEngine panel">
|
||||
{*
|
||||
<form action="{$smarty.server.REQUEST_URI|escape}" method="post" id="settings_form" name="settings_form" class="form-horizontal">
|
||||
<h3><i class="icon-cog"></i> {l s='Settings'}</h3>
|
||||
|
||||
@@ -66,5 +66,4 @@
|
||||
<input type="submit" value="{l s='Save'}" name="submitSettings" id="submitSettings" class="btn btn-default" />
|
||||
</p>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
*}
|
||||
@@ -34,4 +34,5 @@
|
||||
{else}
|
||||
{l s='No module has been installed.'}
|
||||
{/if}
|
||||
</nav>
|
||||
</nav>
|
||||
</div>
|
||||
@@ -51,7 +51,6 @@ abstract class AdminStatsTabControllerCore extends AdminPreferencesControllerCor
|
||||
}
|
||||
|
||||
$this->content .= $this->displayMenu();
|
||||
$this->content .= $this->displayEngines();
|
||||
$this->content .= $this->displayCalendar();
|
||||
$this->content .= $this->displayStats();
|
||||
|
||||
@@ -110,6 +109,7 @@ abstract class AdminStatsTabControllerCore extends AdminPreferencesControllerCor
|
||||
return $tpl->fetch();
|
||||
}
|
||||
|
||||
/* Not used anymore, but still work */
|
||||
protected function displayEngines()
|
||||
{
|
||||
$tpl = $this->createTemplate('engines.tpl');
|
||||
@@ -143,8 +143,13 @@ abstract class AdminStatsTabControllerCore extends AdminPreferencesControllerCor
|
||||
$module_instance = array();
|
||||
foreach ($modules as $m => $module)
|
||||
{
|
||||
$module_instance[$module['name']] = Module::getInstanceByName($module['name']);
|
||||
$modules[$m]['displayName'] = $module_instance[$module['name']]->displayName;
|
||||
if ($module_instance[$module['name']] = Module::getInstanceByName($module['name']))
|
||||
$modules[$m]['displayName'] = $module_instance[$module['name']]->displayName;
|
||||
else
|
||||
{
|
||||
unset($module_instance[$module['name']]);
|
||||
unset($modules[$m]);
|
||||
}
|
||||
}
|
||||
|
||||
uasort($modules, array($this, 'checkModulesNames'));
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
SET NAMES 'utf8';
|
||||
|
||||
INSERT INTO `PREFIX_configuration` (`name`, `value`, `date_add`, `date_upd`) VALUES('PS_DASHBOARD_USE_PUSH', '0', NOW(), NOW());
|
||||
UPDATE `PREFIX_configuration` SET `value` = 'graphnvd3' WHERE `name` = 'PS_STATS_RENDER';
|
||||
|
||||
ALTER TABLE `PREFIX_employee` CHANGE `bo_show_screencast` `bo_menu` TINYINT(1) NOT NULL DEFAULT '0';
|
||||
UPDATE `PREFIX_employee` SET bo_menu = 0;
|
||||
|
||||
@@ -551,7 +551,7 @@ class Blocknewsletter extends Module
|
||||
'type' => 'text',
|
||||
'label' => $this->l('Welcome voucher code'),
|
||||
'name' => 'NW_VOUCHER_CODE',
|
||||
'class' => '.fixed-width-md',
|
||||
'class' => 'fixed-width-md',
|
||||
'desc' => $this->l('Leave blank to disable by default.')
|
||||
),
|
||||
),
|
||||
|
||||
@@ -63,14 +63,14 @@ class Blockrss extends Module
|
||||
|
||||
public function getContent()
|
||||
{
|
||||
$output = '<h2>'.$this->displayName.'</h2>';
|
||||
$output = '';
|
||||
|
||||
if (Tools::isSubmit('submitBlockRss'))
|
||||
{
|
||||
$errors = array();
|
||||
$urlfeed = Tools::getValue('urlfeed');
|
||||
$title = Tools::getValue('title');
|
||||
$nbr = (int)Tools::getValue('nbr');
|
||||
$urlfeed = Tools::getValue('RSS_FEED_URL');
|
||||
$title = Tools::getValue('RSS_FEED_TITLE');
|
||||
$nbr = (int)Tools::getValue('RSS_FEED_NBR');
|
||||
|
||||
if ($urlfeed AND !Validate::isAbsoluteUrl($urlfeed))
|
||||
$errors[] = $this->l('Invalid feed URL');
|
||||
@@ -113,36 +113,7 @@ class Blockrss extends Module
|
||||
$output .= $this->displayError(implode('<br />', $errors));
|
||||
}
|
||||
|
||||
return $output.$this->displayForm();
|
||||
}
|
||||
|
||||
public function displayForm()
|
||||
{
|
||||
$output = '
|
||||
<form action="'.Tools::safeOutput($_SERVER['REQUEST_URI']).'" method="post">
|
||||
<fieldset><legend><img src="'.$this->_path.'logo.gif" alt="" title="" />'.$this->l('Settings').'</legend>
|
||||
<label>'.$this->l('Block title').'</label>
|
||||
<div class="margin-form">
|
||||
<input type="text" name="title" value="'.Tools::safeOutput(Tools::getValue('title', Configuration::get('RSS_FEED_TITLE'))).'" />
|
||||
<p class="clear">'.$this->l('Create a title for the block (default: \'RSS feed\')').'</p>
|
||||
|
||||
</div>
|
||||
<label>'.$this->l('Add a feed URL').'</label>
|
||||
<div class="margin-form">
|
||||
<input type="text" size="85" name="urlfeed" value="'.Tools::safeOutput(Tools::getValue('urlfeed', Configuration::get('RSS_FEED_URL'))).'" />
|
||||
<p class="clear">'.$this->l('Add the URL of the feed you want to use (sample: http://news.google.com/?output=rss)').'</p>
|
||||
|
||||
</div>
|
||||
<label>'.$this->l('Number of threads displayed').'</label>
|
||||
<div class="margin-form">
|
||||
<input type="text" size="5" name="nbr" value="'.(int)Tools::getValue('nbr', Configuration::get('RSS_FEED_NBR')).'" />
|
||||
<p class="clear">'.$this->l('Number of threads displayed by the block (default value: 5)').'</p>
|
||||
|
||||
</div>
|
||||
<center><input type="submit" name="submitBlockRss" value="'.$this->l('Save').'" class="button" /></center>
|
||||
</fieldset>
|
||||
</form>';
|
||||
return $output;
|
||||
return $output.$this->renderForm();
|
||||
}
|
||||
|
||||
function hookLeftColumn($params)
|
||||
@@ -193,4 +164,67 @@ class Blockrss extends Module
|
||||
{
|
||||
$this->context->controller->addCSS(($this->_path).'blockrss.css', 'all');
|
||||
}
|
||||
|
||||
public function renderForm()
|
||||
{
|
||||
$fields_form = array(
|
||||
'form' => array(
|
||||
'legend' => array(
|
||||
'title' => $this->l('Settings'),
|
||||
'icon' => 'icon-cogs'
|
||||
),
|
||||
'input' => array(
|
||||
array(
|
||||
'type' => 'text',
|
||||
'label' => $this->l('Block title'),
|
||||
'name' => 'RSS_FEED_TITLE',
|
||||
'desc' => $this->l('Create a title for the block (default: \'RSS feed\')'),
|
||||
),
|
||||
array(
|
||||
'type' => 'text',
|
||||
'label' => $this->l('Add a feed URL'),
|
||||
'name' => 'RSS_FEED_URL',
|
||||
'desc' => $this->l('Add the URL of the feed you want to use (sample: http://news.google.com/?output=rss)'),
|
||||
),
|
||||
array(
|
||||
'type' => 'text',
|
||||
'label' => $this->l('Number of threads displayed'),
|
||||
'name' => 'RSS_FEED_NBR',
|
||||
'class' => 'fixed-width-sm',
|
||||
'desc' => $this->l('Number of threads displayed by the block (default value: 5)'),
|
||||
),
|
||||
),
|
||||
'submit' => array(
|
||||
'title' => $this->l('Save'),
|
||||
'class' => 'btn btn-primary')
|
||||
),
|
||||
);
|
||||
|
||||
$helper = new HelperForm();
|
||||
$helper->show_toolbar = false;
|
||||
$helper->table = $this->table;
|
||||
$lang = new Language((int)Configuration::get('PS_LANG_DEFAULT'));
|
||||
$helper->default_form_language = $lang->id;
|
||||
$helper->allow_employee_form_lang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') ? Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') : 0;
|
||||
$helper->identifier = $this->identifier;
|
||||
$helper->submit_action = 'submitBlockRss';
|
||||
$helper->currentIndex = $this->context->link->getAdminLink('AdminModules', false).'&configure='.$this->name.'&tab_module='.$this->tab.'&module_name='.$this->name;
|
||||
$helper->token = Tools::getAdminTokenLite('AdminModules');
|
||||
$helper->tpl_vars = array(
|
||||
'fields_value' => $this->getConfigFieldsValues(),
|
||||
'languages' => $this->context->controller->getLanguages(),
|
||||
'id_language' => $this->context->language->id
|
||||
);
|
||||
|
||||
return $helper->generateForm(array($fields_form));
|
||||
}
|
||||
|
||||
public function getConfigFieldsValues()
|
||||
{
|
||||
return array(
|
||||
'RSS_FEED_TITLE' => Tools::getValue('RSS_FEED_TITLE', Configuration::get('RSS_FEED_TITLE')),
|
||||
'RSS_FEED_URL' => Tools::getValue('RSS_FEED_URL', Configuration::get('RSS_FEED_URL')),
|
||||
'RSS_FEED_NBR' => Tools::getValue('RSS_FEED_NBR', Configuration::get('RSS_FEED_NBR')),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,32 +56,16 @@ class blocksocial extends Module
|
||||
{
|
||||
// If we try to update the settings
|
||||
$output = '';
|
||||
if (isset($_POST['submitModule']))
|
||||
if (Tools::isSubmit('submitModule'))
|
||||
{
|
||||
Configuration::updateValue('blocksocial_facebook', (($_POST['facebook_url'] != '') ? $_POST['facebook_url']: ''));
|
||||
Configuration::updateValue('blocksocial_twitter', (($_POST['twitter_url'] != '') ? $_POST['twitter_url']: ''));
|
||||
Configuration::updateValue('blocksocial_rss', (($_POST['rss_url'] != '') ? $_POST['rss_url']: ''));
|
||||
Configuration::updateValue('blocksocial_facebook', (($_POST['blocksocial_facebook'] != '') ? $_POST['blocksocial_facebook']: ''));
|
||||
Configuration::updateValue('blocksocial_twitter', (($_POST['blocksocial_twitter'] != '') ? $_POST['blocksocial_twitter']: ''));
|
||||
Configuration::updateValue('blocksocial_rss', (($_POST['blocksocial_rss'] != '') ? $_POST['blocksocial_rss']: ''));
|
||||
$this->_clearCache('blocksocial.tpl');
|
||||
$output = '<div class="conf confirm">'.$this->l('Configuration updated').'</div>';
|
||||
$output .= $this->displayConfirmation($this->l('Configuration updated'));
|
||||
}
|
||||
|
||||
return '
|
||||
<h2>'.$this->displayName.'</h2>
|
||||
'.$output.'
|
||||
<form action="'.Tools::htmlentitiesutf8($_SERVER['REQUEST_URI']).'" method="post">
|
||||
<fieldset class="width2">
|
||||
<label for="facebook_url">'.$this->l('Facebook URL: ').'</label>
|
||||
<input type="text" id="facebook_url" name="facebook_url" value="'.Tools::safeOutput((Configuration::get('blocksocial_facebook') != "") ? Configuration::get('blocksocial_facebook') : "").'" />
|
||||
<div class="clear"> </div>
|
||||
<label for="twitter_url">'.$this->l('Twitter URL: ').'</label>
|
||||
<input type="text" id="twitter_url" name="twitter_url" value="'.Tools::safeOutput((Configuration::get('blocksocial_twitter') != "") ? Configuration::get('blocksocial_twitter') : "").'" />
|
||||
<div class="clear"> </div>
|
||||
<label for="rss_url">'.$this->l('RSS URL: ').'</label>
|
||||
<input type="text" id="rss_url" name="rss_url" value="'.Tools::safeOutput((Configuration::get('blocksocial_rss') != "") ? Configuration::get('blocksocial_rss') : "").'" />
|
||||
<div class="clear"> </div>
|
||||
<br /><center><input type="submit" name="submitModule" value="'.$this->l('Update settings').'" class="button" /></center>
|
||||
</fieldset>
|
||||
</form>';
|
||||
return $output.$this->renderForm();
|
||||
}
|
||||
|
||||
public function hookDisplayHeader()
|
||||
@@ -100,5 +84,67 @@ class blocksocial extends Module
|
||||
|
||||
return $this->display(__FILE__, 'blocksocial.tpl', $this->getCacheId());
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
public function renderForm()
|
||||
{
|
||||
$fields_form = array(
|
||||
'form' => array(
|
||||
'legend' => array(
|
||||
'title' => $this->l('Settings'),
|
||||
'icon' => 'icon-cogs'
|
||||
),
|
||||
'input' => array(
|
||||
array(
|
||||
'type' => 'text',
|
||||
'label' => $this->l('Facebook URL:'),
|
||||
'name' => 'blocksocial_facebook',
|
||||
'desc' => $this->l('Create a title for the block (default: \'RSS feed\')'),
|
||||
),
|
||||
array(
|
||||
'type' => 'text',
|
||||
'label' => $this->l('Twitter URL:'),
|
||||
'name' => 'blocksocial_twitter',
|
||||
'desc' => $this->l('Add the URL of the feed you want to use (sample: http://news.google.com/?output=rss)'),
|
||||
),
|
||||
array(
|
||||
'type' => 'text',
|
||||
'label' => $this->l('RSS URL:'),
|
||||
'name' => 'blocksocial_rss',
|
||||
'desc' => $this->l('Number of threads displayed by the block (default value: 5)'),
|
||||
),
|
||||
),
|
||||
'submit' => array(
|
||||
'title' => $this->l('Save'),
|
||||
'class' => 'btn btn-primary')
|
||||
),
|
||||
);
|
||||
|
||||
$helper = new HelperForm();
|
||||
$helper->show_toolbar = false;
|
||||
$helper->table = $this->table;
|
||||
$lang = new Language((int)Configuration::get('PS_LANG_DEFAULT'));
|
||||
$helper->default_form_language = $lang->id;
|
||||
$helper->allow_employee_form_lang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') ? Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') : 0;
|
||||
$helper->identifier = $this->identifier;
|
||||
$helper->submit_action = 'submitModule';
|
||||
$helper->currentIndex = $this->context->link->getAdminLink('AdminModules', false).'&configure='.$this->name.'&tab_module='.$this->tab.'&module_name='.$this->name;
|
||||
$helper->token = Tools::getAdminTokenLite('AdminModules');
|
||||
$helper->tpl_vars = array(
|
||||
'fields_value' => $this->getConfigFieldsValues(),
|
||||
'languages' => $this->context->controller->getLanguages(),
|
||||
'id_language' => $this->context->language->id
|
||||
);
|
||||
|
||||
return $helper->generateForm(array($fields_form));
|
||||
}
|
||||
|
||||
public function getConfigFieldsValues()
|
||||
{
|
||||
return array(
|
||||
'blocksocial_facebook' => Tools::getValue('blocksocial_facebook', Configuration::get('blocksocial_facebook')),
|
||||
'blocksocial_twitter' => Tools::getValue('blocksocial_twitter', Configuration::get('blocksocial_twitter')),
|
||||
'blocksocial_rss' => Tools::getValue('blocksocial_rss', Configuration::get('blocksocial_rss')),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -69,38 +69,14 @@ class BlockSpecials extends Module
|
||||
|
||||
public function getContent()
|
||||
{
|
||||
$output = '<h2>'.$this->displayName.'</h2>';
|
||||
$output = '';
|
||||
if (Tools::isSubmit('submitSpecials'))
|
||||
{
|
||||
Configuration::updateValue('PS_BLOCK_SPECIALS_DISPLAY', (int)Tools::getValue('always_display'));
|
||||
Configuration::updateValue('PS_BLOCK_SPECIALS_DISPLAY', (int)Tools::getValue('PS_BLOCK_SPECIALS_DISPLAY'));
|
||||
Configuration::updateValue('BLOCKSPECIALS_NB_CACHES', (int)Tools::getValue('BLOCKSPECIALS_NB_CACHES'));
|
||||
$output .= '<div class="conf confirm">'.$this->l('Settings updated').'</div>';
|
||||
$output .= $this->displayConfirmation($this->l('Settings updated'));
|
||||
}
|
||||
return $output.$this->displayForm();
|
||||
}
|
||||
|
||||
public function displayForm()
|
||||
{
|
||||
return '
|
||||
<form action="'.Tools::safeOutput($_SERVER['REQUEST_URI']).'" method="post">
|
||||
<fieldset>
|
||||
<legend><img src="'.$this->_path.'logo.gif" alt="" title="" />'.$this->l('Settings').'</legend>
|
||||
<label>'.$this->l('Always display this block.').'</label>
|
||||
<div class="margin-form">
|
||||
<input type="radio" name="always_display" id="display_on" value="1" '.(Tools::getValue('always_display', Configuration::get('PS_BLOCK_SPECIALS_DISPLAY')) ? 'checked="checked" ' : '').'/>
|
||||
<label class="t" for="display_on"> <img src="../img/admin/enabled.gif" alt="'.$this->l('Enabled').'" title="'.$this->l('Enabled').'" /></label>
|
||||
<input type="radio" name="always_display" id="display_off" value="0" '.(!Tools::getValue('always_display', Configuration::get('PS_BLOCK_SPECIALS_DISPLAY')) ? 'checked="checked" ' : '').'/>
|
||||
<label class="t" for="display_off"> <img src="../img/admin/disabled.gif" alt="'.$this->l('Disabled').'" title="'.$this->l('Disabled').'" /></label>
|
||||
<p class="clear">'.$this->l('Show the block even if no product is available.').'</p>
|
||||
</div>
|
||||
<label>'.$this->l('Number of cache files.').'</label>
|
||||
<div class="margin-form">
|
||||
<input type="text" name="BLOCKSPECIALS_NB_CACHES" value="'.(int)Configuration::get('BLOCKSPECIALS_NB_CACHES').'" />
|
||||
<p class="clear">'.$this->l('Specials are displayed randomly on the front end, but since it takes a lot of ressources, it is better to cache the results. Cache is reset everyday. 0 will disable the cache.').'</p>
|
||||
</div>
|
||||
<center><input type="submit" name="submitSpecials" value="'.$this->l('Save').'" class="button" /></center>
|
||||
</fieldset>
|
||||
</form>';
|
||||
return $output.$this->renderForm();
|
||||
}
|
||||
|
||||
public function hookRightColumn($params)
|
||||
@@ -152,4 +128,71 @@ class BlockSpecials extends Module
|
||||
{
|
||||
$this->_clearCache('blockspecials.tpl');
|
||||
}
|
||||
|
||||
public function renderForm()
|
||||
{
|
||||
$fields_form = array(
|
||||
'form' => array(
|
||||
'legend' => array(
|
||||
'title' => $this->l('Settings'),
|
||||
'icon' => 'icon-cogs'
|
||||
),
|
||||
'input' => array(
|
||||
array(
|
||||
'type' => 'switch',
|
||||
'label' => $this->l('Always display this block.'),
|
||||
'name' => 'PS_BLOCK_SPECIALS_DISPLAY',
|
||||
'desc' => $this->l('Show the block even if no products are available.'),
|
||||
'values' => array(
|
||||
array(
|
||||
'id' => 'active_on',
|
||||
'value' => 1,
|
||||
'label' => $this->l('Enabled')
|
||||
),
|
||||
array(
|
||||
'id' => 'active_off',
|
||||
'value' => 0,
|
||||
'label' => $this->l('Disabled')
|
||||
)
|
||||
),
|
||||
),
|
||||
array(
|
||||
'type' => 'text',
|
||||
'label' => $this->l('Number of cache files.'),
|
||||
'name' => 'BLOCKSPECIALS_NB_CACHES',
|
||||
'desc' => $this->l('Specials are displayed randomly on the front end, but since it takes a lot of ressources, it is better to cache the results. Cache is reset everyday. 0 will disable the cache.'),
|
||||
),
|
||||
),
|
||||
'submit' => array(
|
||||
'title' => $this->l('Save'),
|
||||
'class' => 'btn btn-primary')
|
||||
),
|
||||
);
|
||||
|
||||
$helper = new HelperForm();
|
||||
$helper->show_toolbar = false;
|
||||
$helper->table = $this->table;
|
||||
$lang = new Language((int)Configuration::get('PS_LANG_DEFAULT'));
|
||||
$helper->default_form_language = $lang->id;
|
||||
$helper->allow_employee_form_lang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') ? Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') : 0;
|
||||
$helper->identifier = $this->identifier;
|
||||
$helper->submit_action = 'submitSpecials';
|
||||
$helper->currentIndex = $this->context->link->getAdminLink('AdminModules', false).'&configure='.$this->name.'&tab_module='.$this->tab.'&module_name='.$this->name;
|
||||
$helper->token = Tools::getAdminTokenLite('AdminModules');
|
||||
$helper->tpl_vars = array(
|
||||
'fields_value' => $this->getConfigFieldsValues(),
|
||||
'languages' => $this->context->controller->getLanguages(),
|
||||
'id_language' => $this->context->language->id
|
||||
);
|
||||
|
||||
return $helper->generateForm(array($fields_form));
|
||||
}
|
||||
|
||||
public function getConfigFieldsValues()
|
||||
{
|
||||
return array(
|
||||
'PS_BLOCK_SPECIALS_DISPLAY' => Tools::getValue('PS_BLOCK_SPECIALS_DISPLAY', Configuration::get('PS_BLOCK_SPECIALS_DISPLAY')),
|
||||
'BLOCKSPECIALS_NB_CACHES' => Tools::getValue('BLOCKSPECIALS_NB_CACHES', Configuration::get('BLOCKSPECIALS_NB_CACHES')),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,224 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* This work is hereby released into the Public Domain.
|
||||
* To view a copy of the public domain dedication,
|
||||
* visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
|
||||
* Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__)."/Image.class.php";
|
||||
|
||||
/**
|
||||
* AntiSpam
|
||||
* String printed on the images are case insensitive.
|
||||
*
|
||||
* @package Artichow
|
||||
*/
|
||||
class awAntiSpam extends awImage {
|
||||
|
||||
/**
|
||||
* Anti-spam string
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $string;
|
||||
|
||||
/**
|
||||
* Noise intensity
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $noise = 0;
|
||||
|
||||
/**
|
||||
* Construct a new awAntiSpam image
|
||||
*
|
||||
* @param string $string A string to display
|
||||
*/
|
||||
public function __construct($string = '') {
|
||||
|
||||
parent::__construct();
|
||||
|
||||
$this->string = (string)$string;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a random string
|
||||
*
|
||||
* @param int $length String length
|
||||
* @return string String created
|
||||
*/
|
||||
public function setRand($length) {
|
||||
|
||||
$length = (int)$length;
|
||||
|
||||
$this->string = '';
|
||||
|
||||
$letters = 'aAbBCDeEFgGhHJKLmMnNpPqQRsStTuVwWXYZz2345679';
|
||||
$number = strlen($letters);
|
||||
|
||||
for($i = 0; $i < $length; $i++) {
|
||||
$this->string .= $letters{mt_rand(0, $number - 1)};
|
||||
}
|
||||
|
||||
return $this->string;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Set noise on image
|
||||
*
|
||||
* @param int $nois Noise intensity (from 0 to 10)
|
||||
*/
|
||||
public function setNoise($noise) {
|
||||
if($noise < 0) {
|
||||
$noise = 0;
|
||||
}
|
||||
if($noise > 10) {
|
||||
$noise = 10;
|
||||
}
|
||||
$this->noise = (int)$noise;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save string value in session
|
||||
* You can use check() to verify the value later
|
||||
*
|
||||
* @param string $qName A name that identify the anti-spam image
|
||||
*/
|
||||
public function save($qName) {
|
||||
$this->session();
|
||||
$session = 'artichow_'.(string)$qName;
|
||||
$_SESSION[$session] = $this->string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify user entry
|
||||
*
|
||||
* @param string $qName A name that identify the anti-spam image
|
||||
* @param string $value User-defined value
|
||||
* @param bool $case TRUE for case insensitive check, FALSE for case sensitive check ? (default to TRUE)
|
||||
* @return bool TRUE if the value is correct, FALSE otherwise
|
||||
*/
|
||||
public function check($qName, $value, $case = TRUE) {
|
||||
|
||||
$this->session();
|
||||
|
||||
$session = 'artichow_'.(string)$qName;
|
||||
|
||||
return (
|
||||
array_key_exists($session, $_SESSION) === TRUE and
|
||||
$case ?
|
||||
(strtolower($_SESSION[$session]) === strtolower((string)$value)) :
|
||||
($_SESSION[$session] === (string)$value)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw image
|
||||
*/
|
||||
public function draw() {
|
||||
|
||||
$fonts = array(
|
||||
'Tuffy',
|
||||
'TuffyBold',
|
||||
'TuffyItalic',
|
||||
'TuffyBoldItalic'
|
||||
);
|
||||
|
||||
$sizes = array(12, 12.5, 13, 13.5, 14, 15, 16, 17, 18, 19);
|
||||
|
||||
$widths = array();
|
||||
$heights = array();
|
||||
$texts = array();
|
||||
|
||||
// Set up a temporary driver to allow font size calculations...
|
||||
$this->setSize(10, 10);
|
||||
$driver = $this->getDriver();
|
||||
|
||||
for($i = 0; $i < strlen($this->string); $i++) {
|
||||
|
||||
$fontKey = array_rand($fonts);
|
||||
$sizeKey = array_rand($sizes);
|
||||
|
||||
$font = new awTTFFont(
|
||||
$fonts[$fontKey], $sizes[$sizeKey]
|
||||
);
|
||||
|
||||
$text = new awText(
|
||||
$this->string{$i},
|
||||
$font,
|
||||
NULL,
|
||||
mt_rand(-15, 15)
|
||||
);
|
||||
|
||||
$widths[] = $driver->getTextWidth($text);
|
||||
$heights[] = $driver->getTextHeight($text);
|
||||
$texts[] = $text;
|
||||
|
||||
}
|
||||
|
||||
// ... and get rid of it.
|
||||
$this->driver = NULL;
|
||||
|
||||
$width = array_sum($widths);
|
||||
$height = array_max($heights);
|
||||
|
||||
$totalWidth = $width + 10 + count($texts) * 10;
|
||||
$totalHeight = $height + 20;
|
||||
|
||||
$this->setSize($totalWidth, $totalHeight);
|
||||
|
||||
$this->create();
|
||||
|
||||
for($i = 0; $i < strlen($this->string); $i++) {
|
||||
|
||||
$this->driver->string(
|
||||
$texts[$i],
|
||||
new awPoint(
|
||||
5 + array_sum(array_slice($widths, 0, $i)) + $widths[$i] / 2 + $i * 10,
|
||||
10 + ($height - $heights[$i]) / 2
|
||||
)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
$this->drawNoise($totalWidth, $totalHeight);
|
||||
|
||||
$this->send();
|
||||
|
||||
}
|
||||
|
||||
protected function drawNoise($width, $height) {
|
||||
|
||||
$points = $this->noise * 30;
|
||||
$color = new awColor(0, 0, 0);
|
||||
|
||||
for($i = 0; $i < $points; $i++) {
|
||||
$this->driver->point(
|
||||
$color,
|
||||
new awPoint(
|
||||
mt_rand(0, $width),
|
||||
mt_rand(0, $height)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected function session() {
|
||||
|
||||
// Start session if needed
|
||||
if(!session_id()) {
|
||||
session_start();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
registerClass('AntiSpam');
|
||||
|
||||
@@ -1,84 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* This work is hereby released into the Public Domain.
|
||||
* To view a copy of the public domain dedication,
|
||||
* visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
|
||||
* Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Path to Artichow
|
||||
*/
|
||||
|
||||
define('ARTICHOW', dirname(__FILE__));
|
||||
|
||||
|
||||
/*
|
||||
* Path to TrueType fonts
|
||||
* DO NOT USE FONT PATH WITH SPACE CHARACTER (" ") WITH GD <= 2.0.18
|
||||
*/
|
||||
if(!defined('ARTICHOW_FONT')) {
|
||||
|
||||
define('ARTICHOW_FONT', ARTICHOW.DIRECTORY_SEPARATOR.'font');
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* Patterns directory
|
||||
*/
|
||||
if(!defined('ARTICHOW_PATTERN')) {
|
||||
|
||||
define('ARTICHOW_PATTERN', ARTICHOW.DIRECTORY_SEPARATOR.'patterns');
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* Images directory
|
||||
*/
|
||||
if(!defined('ARTICHOW_IMAGE')) {
|
||||
|
||||
define('ARTICHOW_IMAGE', ARTICHOW.DIRECTORY_SEPARATOR.'images');
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* Enable/disable cache support
|
||||
*/
|
||||
define('ARTICHOW_CACHE', TRUE);
|
||||
|
||||
/*
|
||||
* Cache directory
|
||||
*/
|
||||
if(!defined('ARTICHOW_CACHE_DIRECTORY')) {
|
||||
|
||||
define('ARTICHOW_CACHE_DIRECTORY', ARTICHOW.DIRECTORY_SEPARATOR.'cache');
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* Prefix for class names
|
||||
* No prefix by default
|
||||
*/
|
||||
define('ARTICHOW_PREFIX', '');
|
||||
|
||||
/*
|
||||
* Trigger errors when use of a deprecated feature
|
||||
*/
|
||||
define('ARTICHOW_DEPRECATED', TRUE);
|
||||
|
||||
/*
|
||||
* Defines the default driver
|
||||
*/
|
||||
define('ARTICHOW_DRIVER', 'gd');
|
||||
|
||||
/*
|
||||
* Fonts to use
|
||||
*/
|
||||
$fonts = array(
|
||||
'Tuffy',
|
||||
'TuffyBold',
|
||||
'TuffyBoldItalic',
|
||||
'TuffyItalic'
|
||||
);
|
||||
|
||||
@@ -1,364 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* This work is hereby released into the Public Domain.
|
||||
* To view a copy of the public domain dedication,
|
||||
* visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
|
||||
* Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__)."/Plot.class.php";
|
||||
|
||||
/**
|
||||
* BarPlot
|
||||
*
|
||||
* @package Artichow
|
||||
*/
|
||||
class awBarPlot extends awPlot implements awLegendable {
|
||||
|
||||
/**
|
||||
* Labels on your bar plot
|
||||
*
|
||||
* @var Label
|
||||
*/
|
||||
public $label;
|
||||
|
||||
/**
|
||||
* Bar plot identifier
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $identifier;
|
||||
|
||||
/**
|
||||
* Bar plot number
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $number;
|
||||
|
||||
/**
|
||||
* Bar plot depth
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $depth;
|
||||
|
||||
/**
|
||||
* For moving bars
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $move;
|
||||
|
||||
/**
|
||||
* Bars shadow
|
||||
*
|
||||
* @var Shadow
|
||||
*/
|
||||
public $barShadow;
|
||||
|
||||
/**
|
||||
* Bars border
|
||||
*
|
||||
* @var Border
|
||||
*/
|
||||
public $barBorder;
|
||||
|
||||
/**
|
||||
* Bars padding
|
||||
*
|
||||
* @var Side
|
||||
*/
|
||||
protected $barPadding;
|
||||
|
||||
/**
|
||||
* Bars space
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $barSpace = 0;
|
||||
|
||||
/**
|
||||
* Bars background
|
||||
*
|
||||
* @var Color, Gradient
|
||||
*/
|
||||
protected $barBackground;
|
||||
|
||||
/**
|
||||
* Construct a new awBarPlot
|
||||
*
|
||||
* @param array $values Some numeric values for Y axis
|
||||
* @param int $identifier Plot identifier
|
||||
* @param int $number Bar plot number
|
||||
* @param int $depth Bar plot depth in pixels
|
||||
*/
|
||||
public function __construct($values, $identifier = 1, $number = 1, $depth = 0) {
|
||||
|
||||
parent::__construct();
|
||||
|
||||
$this->label = new awLabel;
|
||||
|
||||
$this->barPadding = new awSide(0.08, 0.08, 0, 0);
|
||||
$this->barShadow = new awShadow(awShadow::RIGHT_TOP);
|
||||
$this->barBorder = new awBorder;
|
||||
|
||||
$this->setValues($values);
|
||||
|
||||
$this->identifier = (int)$identifier;
|
||||
$this->number = (int)$number;
|
||||
$this->depth = (int)$depth;
|
||||
|
||||
$this->move = new awSide;
|
||||
|
||||
// Hide vertical grid
|
||||
$this->grid->hideVertical(TRUE);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Change bars padding
|
||||
* This method is not compatible with awBarPlot::setBarPadding()
|
||||
*
|
||||
* @param float $left Left padding (between 0 and 1)
|
||||
* @param float $right Right padding (between 0 and 1)
|
||||
*/
|
||||
public function setBarPadding($left = NULL, $right = NULL) {
|
||||
$this->barPadding->set($left, $right);
|
||||
}
|
||||
|
||||
/**
|
||||
* Change bars size
|
||||
* This method is not compatible with awBarPlot::setBarPadding()
|
||||
*
|
||||
* @param int $width Bars size (between 0 and 1)
|
||||
*/
|
||||
public function setBarSize($size) {
|
||||
$padding = (1 - $size) / 2;
|
||||
$this->barPadding->set($padding, $padding);
|
||||
}
|
||||
|
||||
/**
|
||||
* Move bars
|
||||
*
|
||||
* @param int $x
|
||||
* @param int $y
|
||||
*/
|
||||
public function move($x, $y) {
|
||||
$this->move->set($x, NULL, $y, NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
* Change bars space
|
||||
*
|
||||
* @param int $space Space in pixels
|
||||
*/
|
||||
public function setBarSpace($space) {
|
||||
$this->barSpace = (int)$space;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change line background color
|
||||
*
|
||||
* @param awColor $color
|
||||
*/
|
||||
public function setBarColor(awColor $color) {
|
||||
$this->barBackground = $color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change line background gradient
|
||||
*
|
||||
* @param awGradient $gradient
|
||||
*/
|
||||
public function setBarGradient(awGradient $gradient) {
|
||||
$this->barBackground = $gradient;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the line thickness
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getLegendLineThickness() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the line type
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getLegendLineStyle() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the color of line
|
||||
*
|
||||
* @return Color
|
||||
*/
|
||||
public function getLegendLineColor() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the background color or gradient of an element of the component
|
||||
*
|
||||
* @return Color, Gradient
|
||||
*/
|
||||
public function getLegendBackground() {
|
||||
return $this->barBackground;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a mark object
|
||||
*
|
||||
* @return Mark
|
||||
*/
|
||||
public function getLegendMark() {
|
||||
}
|
||||
|
||||
public function drawComponent(awDriver $driver, $x1, $y1, $x2, $y2, $aliasing) {
|
||||
|
||||
$count = count($this->datay);
|
||||
$max = $this->getRealYMax(NULL);
|
||||
$min = $this->getRealYMin(NULL);
|
||||
|
||||
// Find zero for bars
|
||||
if($this->xAxisZero and $min <= 0 and $max >= 0) {
|
||||
$zero = 0;
|
||||
} else if($max < 0) {
|
||||
$zero = $max;
|
||||
} else {
|
||||
$zero = $min;
|
||||
}
|
||||
|
||||
// Get base position
|
||||
$zero = awAxis::toPosition($this->xAxis, $this->yAxis, new awPoint(0, $zero));
|
||||
|
||||
// Distance between two values on the graph
|
||||
$distance = $this->xAxis->getDistance(0, 1);
|
||||
|
||||
// Compute paddings
|
||||
$leftPadding = $this->barPadding->left * $distance;
|
||||
$rightPadding = $this->barPadding->right * $distance;
|
||||
|
||||
$padding = $leftPadding + $rightPadding;
|
||||
$space = $this->barSpace * ($this->number - 1);
|
||||
|
||||
$barSize = ($distance - $padding - $space) / $this->number;
|
||||
$barPosition = $leftPadding + $barSize * ($this->identifier - 1);
|
||||
|
||||
for($key = 0; $key < $count; $key++) {
|
||||
|
||||
$value = $this->datay[$key];
|
||||
|
||||
if($value !== NULL) {
|
||||
|
||||
$position = awAxis::toPosition(
|
||||
$this->xAxis,
|
||||
$this->yAxis,
|
||||
new awPoint($key, $value)
|
||||
);
|
||||
|
||||
$barStart = $barPosition + ($this->identifier - 1) * $this->barSpace + $position->x;
|
||||
$barStop = $barStart + $barSize;
|
||||
|
||||
$t1 = min($zero->y, $position->y);
|
||||
$t2 = max($zero->y, $position->y);
|
||||
|
||||
if(round($t2 - $t1) == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$p1 = new awPoint(
|
||||
round($barStart) + $this->depth + $this->move->left,
|
||||
round($t1) - $this->depth + $this->move->top
|
||||
);
|
||||
|
||||
$p2 = new awPoint(
|
||||
round($barStop) + $this->depth + $this->move->left,
|
||||
round($t2) - $this->depth + $this->move->top
|
||||
);
|
||||
|
||||
$this->drawBar($driver, $p1, $p2);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Draw labels
|
||||
foreach($this->datay as $key => $value) {
|
||||
|
||||
if($value !== NULL) {
|
||||
|
||||
$position = awAxis::toPosition(
|
||||
$this->xAxis,
|
||||
$this->yAxis,
|
||||
new awPoint($key, $value)
|
||||
);
|
||||
|
||||
$point = new awPoint(
|
||||
$barPosition + ($this->identifier - 1) * $this->barSpace + $position->x + $barSize / 2 + 1 + $this->depth,
|
||||
$position->y - $this->depth
|
||||
);
|
||||
|
||||
$this->label->draw($driver, $point, $key);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function getXAxisNumber() {
|
||||
return count($this->datay) + 1;
|
||||
}
|
||||
// ça bidouille à fond ici !
|
||||
public function getXMax() {
|
||||
return array_max($this->datax) + 1;
|
||||
}
|
||||
|
||||
public function getXCenter() {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
protected function drawBar(awDriver $driver, awPoint $p1, awPoint $p2) {
|
||||
|
||||
// Draw shadow
|
||||
$this->barShadow->draw(
|
||||
$driver,
|
||||
$p1,
|
||||
$p2,
|
||||
awShadow::OUT
|
||||
);
|
||||
|
||||
if(abs($p2->y - $p1->y) > 1) {
|
||||
|
||||
$this->barBorder->rectangle(
|
||||
$driver,
|
||||
$p1,
|
||||
$p2
|
||||
);
|
||||
|
||||
if($this->barBackground !== NULL) {
|
||||
|
||||
$size = $this->barBorder->visible() ? 1 : 0;
|
||||
|
||||
$b1 = $p1->move($size, $size);
|
||||
$b2 = $p2->move(-1 * $size, -1 * $size);
|
||||
|
||||
// Draw background
|
||||
$driver->filledRectangle(
|
||||
$this->barBackground,
|
||||
new awLine($b1, $b2)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
registerClass('BarPlot');
|
||||
|
||||
@@ -1,415 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* This work is hereby released into the Public Domain.
|
||||
* To view a copy of the public domain dedication,
|
||||
* visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
|
||||
* Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__)."/Graph.class.php";
|
||||
|
||||
|
||||
/**
|
||||
* A graph can contain some groups of components
|
||||
*
|
||||
* @package Artichow
|
||||
*/
|
||||
abstract class awComponentGroup extends awComponent {
|
||||
|
||||
/**
|
||||
* Components of this group
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $components;
|
||||
|
||||
/**
|
||||
* Build the component group
|
||||
*/
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
$this->components = array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a component to the group
|
||||
*
|
||||
* @param awComponent $component A component
|
||||
*/
|
||||
public function add(awComponent $component) {
|
||||
$this->components[] = $component;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
registerClass('ComponentGroup', TRUE);
|
||||
|
||||
abstract class awComponent {
|
||||
|
||||
/**
|
||||
* Component driver
|
||||
*
|
||||
* @var Driver
|
||||
*/
|
||||
protected $driver;
|
||||
|
||||
/**
|
||||
* Component width
|
||||
*
|
||||
* @var float
|
||||
*/
|
||||
public $width = 1.0;
|
||||
|
||||
/**
|
||||
* Component height
|
||||
*
|
||||
* @var float
|
||||
*/
|
||||
public $height = 1.0;
|
||||
|
||||
/**
|
||||
* Position X of the center the graph (from 0 to 1)
|
||||
*
|
||||
* @var float
|
||||
*/
|
||||
public $x = 0.5;
|
||||
|
||||
/**
|
||||
* Position Y of the center the graph (from 0 to 1)
|
||||
*
|
||||
* @var float
|
||||
*/
|
||||
public $y = 0.5;
|
||||
|
||||
/**
|
||||
* Component absolute width (in pixels)
|
||||
*
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $w;
|
||||
|
||||
/**
|
||||
* Component absolute height (in pixels)
|
||||
*
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $h;
|
||||
|
||||
/**
|
||||
* Left-top corner Y position
|
||||
*
|
||||
* @var float
|
||||
*/
|
||||
public $top;
|
||||
|
||||
/**
|
||||
* Left-top corner X position
|
||||
*
|
||||
* @var float
|
||||
*/
|
||||
public $left;
|
||||
|
||||
/**
|
||||
* Component background color
|
||||
*
|
||||
* @var Color
|
||||
*/
|
||||
protected $background;
|
||||
|
||||
/**
|
||||
* Component padding
|
||||
*
|
||||
* @var Side
|
||||
*/
|
||||
protected $padding;
|
||||
|
||||
/**
|
||||
* Component space
|
||||
*
|
||||
* @var Side
|
||||
*/
|
||||
protected $space;
|
||||
|
||||
/**
|
||||
* Component title
|
||||
*
|
||||
* @var Label
|
||||
*/
|
||||
public $title;
|
||||
|
||||
/**
|
||||
* Adjust automatically the component ?
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $auto = TRUE;
|
||||
|
||||
/**
|
||||
* Legend
|
||||
*
|
||||
* @var Legend
|
||||
*/
|
||||
public $legend;
|
||||
|
||||
/**
|
||||
* Build the component
|
||||
*/
|
||||
public function __construct() {
|
||||
|
||||
// Component legend
|
||||
$this->legend = new awLegend();
|
||||
|
||||
$this->padding = new awSide(25, 25, 25, 25);
|
||||
$this->space = new awSide(0, 0, 0, 0);
|
||||
|
||||
// Component title
|
||||
$this->title = new awLabel(
|
||||
NULL,
|
||||
new awTuffy(10),
|
||||
NULL,
|
||||
0
|
||||
);
|
||||
$this->title->setAlign(awLabel::CENTER, awLabel::TOP);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Adjust automatically the component ?
|
||||
*
|
||||
* @param bool $auto
|
||||
*/
|
||||
public function auto($auto) {
|
||||
$this->auto = (bool)$auto;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the size of the component
|
||||
*
|
||||
* @param int $width Component width (from 0 to 1)
|
||||
* @param int $height Component height (from 0 to 1)
|
||||
*/
|
||||
public function setSize($width, $height) {
|
||||
|
||||
$this->width = (float)$width;
|
||||
$this->height = (float)$height;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the absolute size of the component
|
||||
*
|
||||
* @param int $w Component width (in pixels)
|
||||
* @param int $h Component height (in pixels)
|
||||
*/
|
||||
public function setAbsSize($w, $h) {
|
||||
|
||||
$this->w = (int)$w;
|
||||
$this->h = (int)$h;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Change component background color
|
||||
*
|
||||
* @param awColor $color (can be null)
|
||||
*/
|
||||
public function setBackgroundColor($color) {
|
||||
if($color === NULL or $color instanceof awColor) {
|
||||
$this->background = $color;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Change component background gradient
|
||||
*
|
||||
* @param awGradient $gradient (can be null)
|
||||
*/
|
||||
public function setBackgroundGradient($gradient) {
|
||||
if($gradient === NULL or $gradient instanceof awGradient) {
|
||||
$this->background = $gradient;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Change component background image
|
||||
*
|
||||
* @param awImage $image (can be null)
|
||||
*/
|
||||
public function setBackgroundImage($image) {
|
||||
if($image === NULL or $image instanceof awImage) {
|
||||
$this->background = $image;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the component background
|
||||
*
|
||||
* @return Color, Gradient
|
||||
*/
|
||||
public function getBackground() {
|
||||
return $this->background;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change component padding
|
||||
*
|
||||
* @param int $left Padding in pixels (NULL to keep old value)
|
||||
* @param int $right Padding in pixels (NULL to keep old value)
|
||||
* @param int $top Padding in pixels (NULL to keep old value)
|
||||
* @param int $bottom Padding in pixels (NULL to keep old value)
|
||||
*/
|
||||
public function setPadding($left = NULL, $right = NULL, $top = NULL, $bottom = NULL) {
|
||||
$this->padding->set($left, $right, $top, $bottom);
|
||||
}
|
||||
|
||||
/**
|
||||
* Change component space
|
||||
*
|
||||
* @param float $left Space in % (NULL to keep old value)
|
||||
* @param float $right Space in % (NULL to keep old value)
|
||||
* @param float $bottom Space in % (NULL to keep old value)
|
||||
* @param float $top Space in % (NULL to keep old value)
|
||||
*/
|
||||
public function setSpace($left = NULL, $right = NULL, $bottom = NULL, $top = NULL) {
|
||||
$this->space->set($left, $right, $bottom, $top);
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the absolute position of the component on the graph
|
||||
*
|
||||
* @var int $x Left-top corner X position
|
||||
* @var int $y Left-top corner Y position
|
||||
*/
|
||||
public function setAbsPosition($left, $top) {
|
||||
|
||||
$this->left = (int)$left;
|
||||
$this->top = (int)$top;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the center of the component
|
||||
*
|
||||
* @param int $x Position X of the center of the component
|
||||
* @param int $y Position Y of the center of the component
|
||||
*/
|
||||
public function setCenter($x, $y) {
|
||||
|
||||
$this->x = (float)$x;
|
||||
$this->y = (float)$y;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get component coords with its padding
|
||||
*
|
||||
* @return array Coords of the component
|
||||
*/
|
||||
public function getPosition() {
|
||||
|
||||
// Get component coords
|
||||
$x1 = $this->padding->left;
|
||||
$y1 = $this->padding->top;
|
||||
$x2 = $this->w - $this->padding->right;
|
||||
$y2 = $this->h - $this->padding->bottom;
|
||||
|
||||
return array($x1, $y1, $x2, $y2);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Init the drawing of the component
|
||||
*/
|
||||
public function init(awDriver $driver) {
|
||||
|
||||
// Set component background
|
||||
$background = $this->getBackground();
|
||||
|
||||
if($background !== NULL) {
|
||||
|
||||
$p1 = new awPoint(0, 0);
|
||||
$p2 = new awPoint($this->w - 1, $this->h - 1);
|
||||
|
||||
if($background instanceof awImage) {
|
||||
|
||||
$driver->copyImage(
|
||||
$background,
|
||||
$p1,
|
||||
$p2
|
||||
);
|
||||
|
||||
} else {
|
||||
|
||||
$driver->filledRectangle(
|
||||
$background,
|
||||
new awLine($p1, $p2)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Finalize the drawing of the component
|
||||
*/
|
||||
public function finalize(awDriver $driver) {
|
||||
|
||||
// Draw component title
|
||||
$point = new awPoint(
|
||||
$this->w / 2,
|
||||
$this->padding->top - 8
|
||||
);
|
||||
$this->title->draw($driver, $point);
|
||||
|
||||
// Draw legend
|
||||
$this->legend->draw($driver);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw the grid around your component
|
||||
*
|
||||
* @param Driver A driver
|
||||
* @return array Coords for the component
|
||||
*/
|
||||
abstract public function drawEnvelope(awDriver $driver);
|
||||
|
||||
/**
|
||||
* Draw the component on the graph
|
||||
* Component should be drawed into specified coords
|
||||
*
|
||||
* @param Driver A driver
|
||||
* @param int $x1
|
||||
* @param int $y1
|
||||
* @param int $x2
|
||||
* @param int $y2
|
||||
* @param bool $aliasing Use anti-aliasing to draw the component ?
|
||||
*/
|
||||
abstract public function drawComponent(awDriver $driver, $x1, $y1, $x2, $y2, $aliasing);
|
||||
|
||||
/**
|
||||
* Get space width in pixels
|
||||
*
|
||||
* @param int $width Component width
|
||||
* @param int $height Component height
|
||||
* @return array
|
||||
*/
|
||||
protected function getSpace($width, $height) {
|
||||
|
||||
$left = (int)($width * $this->space->left / 100);
|
||||
$right = (int)($width * $this->space->right / 100);
|
||||
$top = (int)($height * $this->space->top / 100);
|
||||
$bottom = (int)($height * $this->space->bottom / 100);
|
||||
|
||||
return array($left, $right, $top, $bottom);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
registerClass('Component', TRUE);
|
||||
|
||||
@@ -1,412 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* This work is hereby released into the Public Domain.
|
||||
* To view a copy of the public domain dedication,
|
||||
* visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
|
||||
* Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__)."/Image.class.php";
|
||||
|
||||
|
||||
/**
|
||||
* A graph
|
||||
*
|
||||
* @package Artichow
|
||||
*/
|
||||
class awGraph extends awImage {
|
||||
|
||||
/**
|
||||
* Graph name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name;
|
||||
|
||||
/**
|
||||
* Cache timeout
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $timeout = 0;
|
||||
|
||||
/**
|
||||
* Graph timing ?
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $timing;
|
||||
|
||||
/**
|
||||
* Components
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $components = array();
|
||||
|
||||
/**
|
||||
* Some labels to add to the component
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $labels = array();
|
||||
|
||||
/**
|
||||
* Graph title
|
||||
*
|
||||
* @var Label
|
||||
*/
|
||||
public $title;
|
||||
|
||||
/**
|
||||
* File cache location
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $fileCache;
|
||||
|
||||
/**
|
||||
* Time file cache location
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $fileCacheTime;
|
||||
|
||||
/**
|
||||
* Drawing mode to return the graph
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const DRAW_RETURN = 1;
|
||||
|
||||
/**
|
||||
* Drawing mode to display the graph
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const DRAW_DISPLAY = 2;
|
||||
|
||||
/**
|
||||
* Construct a new graph
|
||||
*
|
||||
* @param int $width Graph width
|
||||
* @param int $height Graph height
|
||||
* @param string $name Graph name for the cache (must be unique). Let it null to not use the cache.
|
||||
* @param int $timeout Cache timeout (unix timestamp)
|
||||
*/
|
||||
public function __construct($width = NULL, $height = NULL, $name = NULL, $timeout = 0) {
|
||||
|
||||
parent::__construct();
|
||||
|
||||
$this->setSize($width, $height);
|
||||
|
||||
if(ARTICHOW_CACHE) {
|
||||
|
||||
$this->name = $name;
|
||||
$this->timeout = $timeout;
|
||||
|
||||
// Clean sometimes all the cache
|
||||
if(mt_rand(0, 5000) === 0) {
|
||||
awGraph::cleanCache();
|
||||
}
|
||||
|
||||
// Take the graph from the cache if possible
|
||||
if($this->name !== NULL) {
|
||||
|
||||
$this->fileCache = ARTICHOW_CACHE_DIRECTORY."/".$this->name;
|
||||
$this->fileCacheTime = $this->fileCache."-time";
|
||||
|
||||
if(is_file($this->fileCache)) {
|
||||
|
||||
$type = awGraph::cleanGraphCache($this->fileCacheTime);
|
||||
|
||||
if($type === NULL) {
|
||||
awGraph::deleteFromCache($this->name);
|
||||
} else {
|
||||
header("Content-Type: image/".$type);
|
||||
echo file_get_contents($this->fileCache);
|
||||
exit;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$this->title = new awLabel(
|
||||
NULL,
|
||||
new awTuffy(16),
|
||||
NULL,
|
||||
0
|
||||
);
|
||||
$this->title->setAlign(awLabel::CENTER, awLabel::BOTTOM);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a graph from the cache
|
||||
*
|
||||
* @param string $name Graph name
|
||||
* @return bool TRUE on success, FALSE on failure
|
||||
*/
|
||||
public static function deleteFromCache($name) {
|
||||
|
||||
if(ARTICHOW_CACHE) {
|
||||
|
||||
if(is_file(ARTICHOW_CACHE_DIRECTORY."/".$name."-time")) {
|
||||
unlink(ARTICHOW_CACHE_DIRECTORY."/".$name."");
|
||||
unlink(ARTICHOW_CACHE_DIRECTORY."/".$name."-time");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete all graphs from the cache
|
||||
*/
|
||||
public static function deleteAllCache() {
|
||||
|
||||
if(ARTICHOW_CACHE) {
|
||||
|
||||
$dp = opendir(ARTICHOW_CACHE_DIRECTORY);
|
||||
|
||||
while($file = readdir($dp)) {
|
||||
if($file !== '.' and $file != '..') {
|
||||
unlink(ARTICHOW_CACHE_DIRECTORY."/".$file);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Clean cache
|
||||
*/
|
||||
public static function cleanCache() {
|
||||
|
||||
if(ARTICHOW_CACHE) {
|
||||
|
||||
$glob = glob(ARTICHOW_CACHE_DIRECTORY."/*-time");
|
||||
|
||||
foreach($glob as $file) {
|
||||
|
||||
$type = awGraph::cleanGraphCache($file);
|
||||
|
||||
if($type === NULL) {
|
||||
$name = preg_replace('!.*/(.*)\-time!', "\\1", $file);
|
||||
awGraph::deleteFromCache($name);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable/Disable Graph timing
|
||||
*
|
||||
* @param bool $timing
|
||||
*/
|
||||
public function setTiming($timing) {
|
||||
$this->timing = (bool)$timing;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a component to the graph
|
||||
*
|
||||
* @param awComponent $component
|
||||
*/
|
||||
public function add(awComponent $component) {
|
||||
|
||||
$this->components[] = $component;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a label to the component
|
||||
*
|
||||
* @param awLabel $label
|
||||
* @param int $x Position on X axis of the center of the text
|
||||
* @param int $y Position on Y axis of the center of the text
|
||||
*/
|
||||
public function addLabel(awLabel $label, $x, $y) {
|
||||
|
||||
$this->labels[] = array(
|
||||
$label, $x, $y
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a label to the component with absolute position
|
||||
*
|
||||
* @param awLabel $label
|
||||
* @param awPoint $point Text position
|
||||
*/
|
||||
public function addAbsLabel(awLabel $label, awPoint $point) {
|
||||
|
||||
$this->labels[] = array(
|
||||
$label, $point
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the graph and draw component on it
|
||||
*
|
||||
* @param string $mode Display mode (can be a file name)
|
||||
*/
|
||||
public function draw($mode = Graph::DRAW_DISPLAY) {
|
||||
|
||||
if($this->timing) {
|
||||
$time = microtimeFloat();
|
||||
}
|
||||
|
||||
$this->create();
|
||||
|
||||
foreach($this->components as $component) {
|
||||
|
||||
$this->drawComponent($component);
|
||||
|
||||
}
|
||||
|
||||
$this->drawTitle();
|
||||
$this->drawShadow();
|
||||
$this->drawLabels();
|
||||
|
||||
if($this->timing) {
|
||||
$this->drawTiming(microtimeFloat() - $time);
|
||||
}
|
||||
|
||||
// Create graph
|
||||
$data = $this->get();
|
||||
|
||||
// Put the graph in the cache if needed
|
||||
$this->cache($data);
|
||||
|
||||
switch($mode) {
|
||||
|
||||
case Graph::DRAW_DISPLAY :
|
||||
$this->sendHeaders();
|
||||
echo $data;
|
||||
break;
|
||||
|
||||
case Graph::DRAW_RETURN :
|
||||
return $data;
|
||||
|
||||
default :
|
||||
if(is_string($mode)) {
|
||||
file_put_contents($mode, $data);
|
||||
} else {
|
||||
awImage::drawError("Class Graph: Unable to draw the graph.");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private function drawLabels() {
|
||||
|
||||
$driver = $this->getDriver();
|
||||
|
||||
foreach($this->labels as $array) {
|
||||
|
||||
if(count($array) === 3) {
|
||||
|
||||
// Text in relative position
|
||||
list($label, $x, $y) = $array;
|
||||
|
||||
$point = new awPoint(
|
||||
$x * $this->width,
|
||||
$y * $this->height
|
||||
);
|
||||
|
||||
} else {
|
||||
|
||||
// Text in absolute position
|
||||
list($label, $point) = $array;
|
||||
|
||||
}
|
||||
|
||||
$label->draw($driver, $point);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private function drawTitle() {
|
||||
|
||||
$driver = $this->getDriver();
|
||||
|
||||
$point = new awPoint(
|
||||
$this->width / 2,
|
||||
10
|
||||
);
|
||||
|
||||
$this->title->draw($driver, $point);
|
||||
|
||||
}
|
||||
|
||||
private function drawTiming($time) {
|
||||
|
||||
$driver = $this->getDriver();
|
||||
|
||||
$label = new awLabel;
|
||||
$label->set("(".sprintf("%.3f", $time)." s)");
|
||||
$label->setAlign(awLabel::LEFT, awLabel::TOP);
|
||||
$label->border->show();
|
||||
$label->setPadding(1, 0, 0, 0);
|
||||
$label->setBackgroundColor(new awColor(230, 230, 230, 25));
|
||||
|
||||
$label->draw($driver, new awPoint(5, $driver->imageHeight - 5));
|
||||
|
||||
}
|
||||
|
||||
private function cache($data) {
|
||||
if(ARTICHOW_CACHE and $this->name !== NULL) {
|
||||
|
||||
if(is_writable(ARTICHOW_CACHE_DIRECTORY) === FALSE) {
|
||||
awImage::drawError("Class Graph: Cache directory is not writable.");
|
||||
}
|
||||
|
||||
file_put_contents($this->fileCache, $data);
|
||||
file_put_contents($this->fileCacheTime, $this->timeout."\n".$this->getFormatString());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private static function cleanGraphCache($file) {
|
||||
|
||||
list(
|
||||
$time,
|
||||
$type
|
||||
) = explode("\n", file_get_contents($file));
|
||||
|
||||
$time = (int)$time;
|
||||
|
||||
if($time !== 0 and $time < time()) {
|
||||
return NULL;
|
||||
} else {
|
||||
return $type;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
registerClass('Graph');
|
||||
|
||||
/*
|
||||
* To preserve PHP 4 compatibility
|
||||
*/
|
||||
function microtimeFloat() {
|
||||
list($usec, $sec) = explode(" ", microtime());
|
||||
return (float)$usec + (float)$sec;
|
||||
}
|
||||
|
||||
@@ -1,606 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* This work is hereby released into the Public Domain.
|
||||
* To view a copy of the public domain dedication,
|
||||
* visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
|
||||
* Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
if(is_file(dirname(__FILE__)."/Artichow.cfg.php")) { // For PHP 4+5 version
|
||||
require_once dirname(__FILE__)."/Artichow.cfg.php";
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Register a class with the prefix in configuration file
|
||||
*/
|
||||
function registerClass($class, $abstract = FALSE) {
|
||||
|
||||
if(ARTICHOW_PREFIX === 'aw') {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if($abstract) {
|
||||
$abstract = 'abstract';
|
||||
} else {
|
||||
$abstract = '';
|
||||
}
|
||||
|
||||
|
||||
eval($abstract." class ".ARTICHOW_PREFIX.$class." extends aw".$class." { }");
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* Register an interface with the prefix in configuration file
|
||||
*/
|
||||
function registerInterface($interface) {
|
||||
|
||||
if(ARTICHOW_PREFIX === 'aw') {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
eval("interface ".ARTICHOW_PREFIX.$interface." extends aw".$interface." { }");
|
||||
|
||||
|
||||
}
|
||||
|
||||
// Some useful files
|
||||
require_once ARTICHOW."/Component.class.php";
|
||||
|
||||
require_once ARTICHOW."/inc/Grid.class.php";
|
||||
require_once ARTICHOW."/inc/Tools.class.php";
|
||||
require_once ARTICHOW."/inc/Driver.class.php";
|
||||
require_once ARTICHOW."/inc/Math.class.php";
|
||||
require_once ARTICHOW."/inc/Tick.class.php";
|
||||
require_once ARTICHOW."/inc/Axis.class.php";
|
||||
require_once ARTICHOW."/inc/Legend.class.php";
|
||||
require_once ARTICHOW."/inc/Mark.class.php";
|
||||
require_once ARTICHOW."/inc/Label.class.php";
|
||||
require_once ARTICHOW."/inc/Text.class.php";
|
||||
require_once ARTICHOW."/inc/Color.class.php";
|
||||
require_once ARTICHOW."/inc/Font.class.php";
|
||||
require_once ARTICHOW."/inc/Gradient.class.php";
|
||||
require_once ARTICHOW."/inc/Shadow.class.php";
|
||||
require_once ARTICHOW."/inc/Border.class.php";
|
||||
|
||||
require_once ARTICHOW."/common.php";
|
||||
|
||||
/**
|
||||
* An image for a graph
|
||||
*
|
||||
* @package Artichow
|
||||
*/
|
||||
class awImage {
|
||||
|
||||
/**
|
||||
* Graph width
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $width;
|
||||
|
||||
/**
|
||||
* Graph height
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $height;
|
||||
|
||||
/**
|
||||
* Use anti-aliasing ?
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $antiAliasing = FALSE;
|
||||
|
||||
/**
|
||||
* Image format
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $format = awImage::PNG;
|
||||
|
||||
/**
|
||||
* Image background color
|
||||
*
|
||||
* @var Color
|
||||
*/
|
||||
protected $background;
|
||||
|
||||
/**
|
||||
* GD resource
|
||||
*
|
||||
* @var resource
|
||||
*/
|
||||
protected $resource;
|
||||
|
||||
/**
|
||||
* A Driver object
|
||||
*
|
||||
* @var Driver
|
||||
*/
|
||||
protected $driver;
|
||||
|
||||
/**
|
||||
* Driver string
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $driverString;
|
||||
|
||||
/**
|
||||
* Shadow
|
||||
*
|
||||
* @var Shadow
|
||||
*/
|
||||
public $shadow;
|
||||
|
||||
/**
|
||||
* Image border
|
||||
*
|
||||
* @var Border
|
||||
*/
|
||||
public $border;
|
||||
|
||||
/**
|
||||
* Use JPEG for image
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const JPEG = IMG_JPG;
|
||||
|
||||
/**
|
||||
* Use PNG for image
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const PNG = IMG_PNG;
|
||||
|
||||
/**
|
||||
* Use GIF for image
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const GIF = IMG_GIF;
|
||||
|
||||
/**
|
||||
* Build the image
|
||||
*/
|
||||
public function __construct() {
|
||||
|
||||
$this->background = new awColor(255, 255, 255);
|
||||
$this->shadow = new awShadow(awShadow::RIGHT_BOTTOM);
|
||||
$this->border = new awBorder;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get driver of the image
|
||||
*
|
||||
* @param int $w Driver width (from 0 to 1) (default to 1)
|
||||
* @param int $h Driver height (from 0 to 1) (default to 1)
|
||||
* @param float $x Position on X axis of the center of the driver (default to 0.5)
|
||||
* @param float $y Position on Y axis of the center of the driver (default to 0.5)
|
||||
* @return Driver
|
||||
*/
|
||||
public function getDriver($w = 1, $h = 1, $x = 0.5, $y = 0.5) {
|
||||
$this->create();
|
||||
$this->driver->setSize($w, $h);
|
||||
$this->driver->setPosition($x, $y);
|
||||
return $this->driver;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the driver that will be used to draw the graph
|
||||
*
|
||||
* @param string $driverString
|
||||
*/
|
||||
public function setDriver($driverString) {
|
||||
$this->driver = $this->selectDriver($driverString);
|
||||
|
||||
$this->driver->init($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the image size
|
||||
*
|
||||
* @var int $width Image width
|
||||
* @var int $height Image height
|
||||
*/
|
||||
public function setSize($width, $height) {
|
||||
|
||||
if($width !== NULL) {
|
||||
$this->width = (int)$width;
|
||||
}
|
||||
if($height !== NULL) {
|
||||
$this->height = (int)$height;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Change image background
|
||||
*
|
||||
* @param mixed $background
|
||||
*/
|
||||
public function setBackground($background) {
|
||||
if($background instanceof awColor) {
|
||||
$this->setBackgroundColor($background);
|
||||
} elseif($background instanceof awGradient) {
|
||||
$this->setBackgroundGradient($background);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Change image background color
|
||||
*
|
||||
* @param awColor $color
|
||||
*/
|
||||
public function setBackgroundColor(awColor $color) {
|
||||
$this->background = $color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change image background gradient
|
||||
*
|
||||
* @param awGradient $gradient
|
||||
*/
|
||||
public function setBackgroundGradient(awGradient $gradient) {
|
||||
$this->background = $gradient;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return image background, whether a Color or a Gradient
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getBackground() {
|
||||
return $this->background;
|
||||
}
|
||||
|
||||
/**
|
||||
* Turn antialiasing on or off
|
||||
*
|
||||
* @var bool $bool
|
||||
*/
|
||||
public function setAntiAliasing($bool) {
|
||||
$this->antiAliasing = (bool)$bool;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the antialiasing setting
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function getAntiAliasing() {
|
||||
return $this->antiAliasing;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change image format
|
||||
*
|
||||
* @var int $format New image format
|
||||
*/
|
||||
public function setFormat($format) {
|
||||
if($format === awImage::JPEG or $format === awImage::PNG or $format === awImage::GIF) {
|
||||
$this->format = $format;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the image format as an integer
|
||||
*
|
||||
* @return unknown
|
||||
*/
|
||||
public function getFormat() {
|
||||
return $this->format;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the image format as a string
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getFormatString() {
|
||||
|
||||
switch($this->format) {
|
||||
case awImage::JPEG :
|
||||
return 'jpeg';
|
||||
case awImage::PNG :
|
||||
return 'png';
|
||||
case awImage::GIF :
|
||||
return 'gif';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new awimage
|
||||
*/
|
||||
public function create() {
|
||||
|
||||
if($this->driver === NULL) {
|
||||
$driver = $this->selectDriver($this->driverString);
|
||||
|
||||
$driver->init($this);
|
||||
|
||||
$this->driver = $driver;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Select the correct driver
|
||||
*
|
||||
* @param string $driver The desired driver
|
||||
* @return mixed
|
||||
*/
|
||||
protected function selectDriver($driver) {
|
||||
$drivers = array('gd');
|
||||
$driver = strtolower((string)$driver);
|
||||
|
||||
if(in_array($driver, $drivers, TRUE)) {
|
||||
$string = $driver;
|
||||
} else {
|
||||
$string = ARTICHOW_DRIVER;
|
||||
}
|
||||
|
||||
switch ($string) {
|
||||
case 'gd':
|
||||
require_once ARTICHOW.'/inc/drivers/gd.class.php';
|
||||
$this->driverString = $string;
|
||||
return new awGDDriver();
|
||||
|
||||
default:
|
||||
// We should never get here, unless the wrong string is used AND the ARTICHOW_DRIVER
|
||||
// global has been messed with.
|
||||
awImage::drawError('Class Image: Unknown driver type (\''.$string.'\')');
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw a component on the image
|
||||
*
|
||||
* @var awComponent $component A component
|
||||
*/
|
||||
public function drawComponent(awComponent $component) {
|
||||
|
||||
$shadow = $this->shadow->getSpace(); // Image shadow
|
||||
$border = $this->border->visible() ? 1 : 0; // Image border size
|
||||
|
||||
$driver = clone $this->driver;
|
||||
$driver->setImageSize(
|
||||
$this->width - $shadow->left - $shadow->right - $border * 2,
|
||||
$this->height - $shadow->top - $shadow->bottom - $border * 2
|
||||
);
|
||||
|
||||
// No absolute size specified
|
||||
if($component->w === NULL and $component->h === NULL) {
|
||||
|
||||
list($width, $height) = $driver->setSize($component->width, $component->height);
|
||||
|
||||
// Set component size in pixels
|
||||
$component->setAbsSize($width, $height);
|
||||
|
||||
} else {
|
||||
|
||||
$driver->setAbsSize($component->w, $component->h);
|
||||
|
||||
}
|
||||
|
||||
if($component->top !== NULL and $component->left !== NULL) {
|
||||
$driver->setAbsPosition(
|
||||
$border + $shadow->left + $component->left,
|
||||
$border + $shadow->top + $component->top
|
||||
);
|
||||
} else {
|
||||
$driver->setPosition($component->x, $component->y);
|
||||
}
|
||||
|
||||
$driver->movePosition($border + $shadow->left, $border + $shadow->top);
|
||||
|
||||
list($x1, $y1, $x2, $y2) = $component->getPosition();
|
||||
|
||||
$component->init($driver);
|
||||
|
||||
$component->drawComponent($driver, $x1, $y1, $x2, $y2, $this->antiAliasing);
|
||||
$component->drawEnvelope($driver, $x1, $y1, $x2, $y2);
|
||||
|
||||
$component->finalize($driver);
|
||||
|
||||
}
|
||||
|
||||
protected function drawShadow() {
|
||||
|
||||
$driver = $this->getDriver();
|
||||
|
||||
$this->shadow->draw(
|
||||
$driver,
|
||||
new awPoint(0, 0),
|
||||
new awPoint($this->width, $this->height),
|
||||
awShadow::IN
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Send the image into a file or to the user browser
|
||||
*
|
||||
*/
|
||||
public function send() {
|
||||
$this->driver->send($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the image content as binary data
|
||||
*
|
||||
*/
|
||||
public function get() {
|
||||
return $this->driver->get($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send the correct HTTP header according to the image type
|
||||
*
|
||||
*/
|
||||
public function sendHeaders() {
|
||||
|
||||
if(headers_sent() === FALSE) {
|
||||
|
||||
switch ($this->driverString) {
|
||||
case 'gd' :
|
||||
header('Content-type: image/'.$this->getFormatString());
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
private static $errorWriting = FALSE;
|
||||
|
||||
|
||||
/*
|
||||
* Display an error image and exit
|
||||
*
|
||||
* @param string $message Error message
|
||||
*/
|
||||
public static function drawError($message) {
|
||||
|
||||
|
||||
if(self::$errorWriting) {
|
||||
return;
|
||||
}
|
||||
|
||||
self::$errorWriting = TRUE;
|
||||
|
||||
$message = wordwrap($message, 40, "\n", TRUE);
|
||||
|
||||
$width = 400;
|
||||
$height = max(100, 40 + 22.5 * (substr_count($message, "\n") + 1));
|
||||
|
||||
$image = new awImage();
|
||||
$image->setSize($width, $height);
|
||||
$image->setDriver('gd');
|
||||
|
||||
$driver = $image->getDriver();
|
||||
$driver->init($image);
|
||||
|
||||
// Display title
|
||||
$driver->filledRectangle(
|
||||
new awWhite,
|
||||
new awLine(
|
||||
new awPoint(0, 0),
|
||||
new awPoint($width, $height)
|
||||
)
|
||||
);
|
||||
|
||||
$driver->filledRectangle(
|
||||
new awRed,
|
||||
new awLine(
|
||||
new awPoint(0, 0),
|
||||
new awPoint(110, 25)
|
||||
)
|
||||
);
|
||||
|
||||
$text = new awText(
|
||||
"Artichow error",
|
||||
new awFont3,
|
||||
new awWhite,
|
||||
0
|
||||
);
|
||||
|
||||
$driver->string($text, new awPoint(5, 6));
|
||||
|
||||
// Display red box
|
||||
$driver->rectangle(
|
||||
new awRed,
|
||||
new awLine(
|
||||
new awPoint(0, 25),
|
||||
new awPoint($width - 90, $height - 1)
|
||||
)
|
||||
);
|
||||
|
||||
// Display error image
|
||||
$file = ARTICHOW_IMAGE.DIRECTORY_SEPARATOR.'error.png';
|
||||
|
||||
$imageError = new awFileImage($file);
|
||||
$driver->copyImage(
|
||||
$imageError,
|
||||
new awPoint($width - 81, $height - 81),
|
||||
new awPoint($width - 1, $height - 1)
|
||||
);
|
||||
|
||||
// Draw message
|
||||
$text = new awText(
|
||||
strip_tags($message),
|
||||
new awFont2,
|
||||
new awBlack,
|
||||
0
|
||||
);
|
||||
|
||||
$driver->string($text, new awPoint(10, 40));
|
||||
|
||||
$image->send();
|
||||
|
||||
exit;
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* Display an error image located in a file and exit
|
||||
*
|
||||
* @param string $error Error name
|
||||
*/
|
||||
public static function drawErrorFile($error) {
|
||||
|
||||
$file = ARTICHOW_IMAGE.DIRECTORY_SEPARATOR.'errors'.DIRECTORY_SEPARATOR.$error.'.png';
|
||||
|
||||
header("Content-Type: image/png");
|
||||
readfile($file);
|
||||
exit;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
registerClass('Image');
|
||||
|
||||
|
||||
/**
|
||||
* Load an image from a file
|
||||
*
|
||||
* @package Artichow
|
||||
*/
|
||||
class awFileImage extends awImage {
|
||||
|
||||
/**
|
||||
* Build a new awimage
|
||||
*
|
||||
* @param string $file Image file name
|
||||
*/
|
||||
public function __construct($file) {
|
||||
|
||||
$driver = $this->selectDriver($this->driverString);
|
||||
|
||||
$driver->initFromFile($this, $file);
|
||||
|
||||
$this->driver = $driver;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
registerClass('FileImage');
|
||||
|
||||
|
||||
@@ -1,585 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* This work is hereby released into the Public Domain.
|
||||
* To view a copy of the public domain dedication,
|
||||
* visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
|
||||
* Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__)."/Plot.class.php";
|
||||
|
||||
|
||||
/**
|
||||
* LinePlot
|
||||
*
|
||||
* @package Artichow
|
||||
*/
|
||||
class awLinePlot extends awPlot implements awLegendable {
|
||||
|
||||
/**
|
||||
* Add marks to your line plot
|
||||
*
|
||||
* @var Mark
|
||||
*/
|
||||
public $mark;
|
||||
|
||||
/**
|
||||
* Labels on your line plot
|
||||
*
|
||||
* @var Label
|
||||
*/
|
||||
public $label;
|
||||
|
||||
/**
|
||||
* Filled areas
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $areas = array();
|
||||
|
||||
/**
|
||||
* Is the line hidden
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $lineHide = FALSE;
|
||||
|
||||
/**
|
||||
* Line color
|
||||
*
|
||||
* @var Color
|
||||
*/
|
||||
protected $lineColor;
|
||||
|
||||
/**
|
||||
* Line mode
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $lineMode = awLinePlot::LINE;
|
||||
|
||||
/**
|
||||
* Line type
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $lineStyle = awLine::SOLID;
|
||||
|
||||
/**
|
||||
* Line thickness
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $lineThickness = 1;
|
||||
|
||||
/**
|
||||
* Line background
|
||||
*
|
||||
* @var Color, Gradient
|
||||
*/
|
||||
protected $lineBackground;
|
||||
|
||||
/**
|
||||
* Line mode
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const LINE = 0;
|
||||
|
||||
/**
|
||||
* Line in the middle
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const MIDDLE = 1;
|
||||
|
||||
/**
|
||||
* Construct a new awLinePlot
|
||||
*
|
||||
* @param array $values Some numeric values for Y axis
|
||||
* @param int $mode
|
||||
*/
|
||||
public function __construct($values, $mode = awLinePlot::LINE) {
|
||||
|
||||
parent::__construct();
|
||||
|
||||
$this->mark = new awMark;
|
||||
$this->label = new awLabel;
|
||||
|
||||
$this->lineMode = (int)$mode;
|
||||
|
||||
$this->setValues($values);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Hide line
|
||||
*
|
||||
* @param bool $hide
|
||||
*/
|
||||
public function hideLine($hide) {
|
||||
$this->lineHide = (bool)$hide;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a filled area
|
||||
*
|
||||
* @param int $start Begining of the area
|
||||
* @param int $end End of the area
|
||||
* @param mixed $background Background color or gradient of the area
|
||||
*/
|
||||
public function setFilledArea($start, $stop, $background) {
|
||||
|
||||
if($stop <= $start) {
|
||||
awImage::drawError("Class LinePlot: End position can not be greater than begin position in setFilledArea().");
|
||||
}
|
||||
|
||||
$this->areas[] = array((int)$start, (int)$stop, $background);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Change line color
|
||||
*
|
||||
* @param awColor $color
|
||||
*/
|
||||
public function setColor(awColor $color) {
|
||||
$this->lineColor = $color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change line style
|
||||
*
|
||||
* @param int $style
|
||||
*/
|
||||
public function setStyle($style) {
|
||||
$this->lineStyle = (int)$style;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change line tickness
|
||||
*
|
||||
* @param int $tickness
|
||||
*/
|
||||
public function setThickness($tickness) {
|
||||
$this->lineThickness = (int)$tickness;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change line background color
|
||||
*
|
||||
* @param awColor $color
|
||||
*/
|
||||
public function setFillColor(awColor $color) {
|
||||
$this->lineBackground = $color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change line background gradient
|
||||
*
|
||||
* @param awGradient $gradient
|
||||
*/
|
||||
public function setFillGradient(awGradient $gradient) {
|
||||
$this->lineBackground = $gradient;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the line thickness
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getLegendLineThickness() {
|
||||
return $this->lineThickness;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the line type
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getLegendLineStyle() {
|
||||
return $this->lineStyle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the color of line
|
||||
*
|
||||
* @return Color
|
||||
*/
|
||||
public function getLegendLineColor() {
|
||||
return $this->lineColor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the background color or gradient of an element of the component
|
||||
*
|
||||
* @return Color, Gradient
|
||||
*/
|
||||
public function getLegendBackground() {
|
||||
return $this->lineBackground;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a mark object
|
||||
*
|
||||
* @return Mark
|
||||
*/
|
||||
public function getLegendMark() {
|
||||
return $this->mark;
|
||||
}
|
||||
|
||||
public function drawComponent(awDriver $driver, $x1, $y1, $x2, $y2, $aliasing) {
|
||||
|
||||
$max = $this->getRealYMax();
|
||||
$min = $this->getRealYMin();
|
||||
|
||||
// Get start and stop values
|
||||
list($start, $stop) = $this->getLimit();
|
||||
|
||||
if($this->lineMode === awLinePlot::MIDDLE) {
|
||||
$inc = $this->xAxis->getDistance(0, 1) / 2;
|
||||
} else {
|
||||
$inc = 0;
|
||||
}
|
||||
|
||||
// Build the polygon
|
||||
$polygon = new awPolygon;
|
||||
|
||||
for($key = $start; $key <= $stop; $key++) {
|
||||
|
||||
$value = $this->datay[$key];
|
||||
|
||||
if($value !== NULL) {
|
||||
|
||||
$p = awAxis::toPosition($this->xAxis, $this->yAxis, new awPoint($key, $value));
|
||||
$p = $p->move($inc, 0);
|
||||
$polygon->set($key, $p);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Draw backgrounds
|
||||
if($this->lineBackground instanceof awColor or $this->lineBackground instanceof awGradient) {
|
||||
|
||||
$backgroundPolygon = new awPolygon;
|
||||
|
||||
$p = $this->xAxisPoint($start);
|
||||
$p = $p->move($inc, 0);
|
||||
$backgroundPolygon->append($p);
|
||||
|
||||
// Add others points
|
||||
foreach($polygon->all() as $point) {
|
||||
$backgroundPolygon->append(clone $point);
|
||||
}
|
||||
|
||||
$p = $this->xAxisPoint($stop);
|
||||
$p = $p->move($inc, 0);
|
||||
$backgroundPolygon->append($p);
|
||||
|
||||
// Draw polygon background
|
||||
$driver->filledPolygon($this->lineBackground, $backgroundPolygon);
|
||||
|
||||
}
|
||||
|
||||
$this->drawArea($driver, $polygon);
|
||||
|
||||
// Draw line
|
||||
$prev = NULL;
|
||||
|
||||
// Line color
|
||||
if($this->lineHide === FALSE) {
|
||||
|
||||
if($this->lineColor === NULL) {
|
||||
$this->lineColor = new awColor(0, 0, 0);
|
||||
}
|
||||
|
||||
foreach($polygon->all() as $point) {
|
||||
|
||||
if($prev !== NULL) {
|
||||
$driver->line(
|
||||
$this->lineColor,
|
||||
new awLine(
|
||||
$prev,
|
||||
$point,
|
||||
$this->lineStyle,
|
||||
$this->lineThickness
|
||||
)
|
||||
);
|
||||
}
|
||||
$prev = $point;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Draw marks and labels
|
||||
foreach($polygon->all() as $key => $point) {
|
||||
|
||||
$this->mark->draw($driver, $point);
|
||||
$this->label->draw($driver, $point, $key);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected function drawArea(awDriver $driver, awPolygon $polygon) {
|
||||
|
||||
$starts = array();
|
||||
foreach($this->areas as $area) {
|
||||
list($start) = $area;
|
||||
$starts[$start] = TRUE;
|
||||
}
|
||||
|
||||
// Draw filled areas
|
||||
foreach($this->areas as $area) {
|
||||
|
||||
list($start, $stop, $background) = $area;
|
||||
|
||||
$polygonArea = new awPolygon;
|
||||
|
||||
$p = $this->xAxisPoint($start);
|
||||
$polygonArea->append($p);
|
||||
|
||||
for($i = $start; $i <= $stop; $i++) {
|
||||
$p = clone $polygon->get($i);
|
||||
if($i === $stop and array_key_exists($stop, $starts)) {
|
||||
$p = $p->move(-1, 0);
|
||||
}
|
||||
$polygonArea->append($p);
|
||||
}
|
||||
|
||||
$p = $this->xAxisPoint($stop);
|
||||
if(array_key_exists($stop, $starts)) {
|
||||
$p = $p->move(-1, 0);
|
||||
}
|
||||
$polygonArea->append($p);
|
||||
|
||||
// Draw area
|
||||
$driver->filledPolygon($background, $polygonArea);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function getXAxisNumber() {
|
||||
if($this->lineMode === awLinePlot::MIDDLE) {
|
||||
return count($this->datay) + 1;
|
||||
} else {
|
||||
return count($this->datay);
|
||||
}
|
||||
}
|
||||
|
||||
protected function xAxisPoint($position) {
|
||||
$y = $this->xAxisZero ? 0 : $this->getRealYMin();
|
||||
return awAxis::toPosition($this->xAxis, $this->yAxis, new awPoint($position, $y));
|
||||
}
|
||||
|
||||
public function getXCenter() {
|
||||
return ($this->lineMode === awLinePlot::MIDDLE);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
registerClass('LinePlot');
|
||||
|
||||
|
||||
/**
|
||||
* Simple LinePlot
|
||||
* Useful to draw simple horizontal lines
|
||||
*
|
||||
* @package Artichow
|
||||
*/
|
||||
class awSimpleLinePlot extends awPlot implements awLegendable {
|
||||
|
||||
/**
|
||||
* Line color
|
||||
*
|
||||
* @var Color
|
||||
*/
|
||||
protected $lineColor;
|
||||
|
||||
/**
|
||||
* Line start
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $lineStart;
|
||||
|
||||
/**
|
||||
* Line stop
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $lineStop;
|
||||
|
||||
/**
|
||||
* Line value
|
||||
*
|
||||
* @var flaot
|
||||
*/
|
||||
protected $lineValue;
|
||||
|
||||
/**
|
||||
* Line mode
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $lineMode = awLinePlot::LINE;
|
||||
|
||||
/**
|
||||
* Line type
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $lineStyle = awLine::SOLID;
|
||||
|
||||
/**
|
||||
* Line thickness
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $lineThickness = 1;
|
||||
|
||||
/**
|
||||
* Line mode
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const LINE = 0;
|
||||
|
||||
/**
|
||||
* Line in the middle
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const MIDDLE = 1;
|
||||
|
||||
/**
|
||||
* Construct a new awLinePlot
|
||||
*
|
||||
* @param float $value A Y value
|
||||
* @param int $start Line start index
|
||||
* @param int $stop Line stop index
|
||||
* @param int $mode Line mode
|
||||
*/
|
||||
public function __construct($value, $start, $stop, $mode = awLinePlot::LINE) {
|
||||
|
||||
parent::__construct();
|
||||
|
||||
$this->lineMode = (int)$mode;
|
||||
|
||||
$this->lineStart = (int)$start;
|
||||
$this->lineStop = (int)$stop;
|
||||
$this->lineValue = (float)$value;
|
||||
|
||||
$this->lineColor = new awColor(0, 0, 0);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Change line color
|
||||
*
|
||||
* @param awColor $color
|
||||
*/
|
||||
public function setColor(awColor $color) {
|
||||
$this->lineColor = $color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change line style
|
||||
*
|
||||
* @param int $style
|
||||
*/
|
||||
public function setStyle($style) {
|
||||
$this->lineStyle = (int)$style;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change line tickness
|
||||
*
|
||||
* @param int $tickness
|
||||
*/
|
||||
public function setThickness($tickness) {
|
||||
$this->lineThickness = (int)$tickness;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the line thickness
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getLegendLineThickness() {
|
||||
return $this->lineThickness;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the line type
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getLegendLineStyle() {
|
||||
return $this->lineStyle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the color of line
|
||||
*
|
||||
* @return Color
|
||||
*/
|
||||
public function getLegendLineColor() {
|
||||
return $this->lineColor;
|
||||
}
|
||||
|
||||
public function getLegendBackground() {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
public function getLegendMark() {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
public function drawComponent(awDriver $driver, $x1, $y1, $x2, $y2, $aliasing) {
|
||||
|
||||
if($this->lineMode === awLinePlot::MIDDLE) {
|
||||
$inc = $this->xAxis->getDistance(0, 1) / 2;
|
||||
} else {
|
||||
$inc = 0;
|
||||
}
|
||||
|
||||
$p1 = awAxis::toPosition($this->xAxis, $this->yAxis, new awPoint($this->lineStart, $this->lineValue));
|
||||
$p2 = awAxis::toPosition($this->xAxis, $this->yAxis, new awPoint($this->lineStop, $this->lineValue));
|
||||
|
||||
$driver->line(
|
||||
$this->lineColor,
|
||||
new awLine(
|
||||
$p1->move($inc, 0),
|
||||
$p2->move($inc, 0),
|
||||
$this->lineStyle,
|
||||
$this->lineThickness
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function getXAxisNumber() {
|
||||
if($this->lineMode === awLinePlot::MIDDLE) {
|
||||
return count($this->datay) + 1;
|
||||
} else {
|
||||
return count($this->datay);
|
||||
}
|
||||
}
|
||||
|
||||
protected function xAxisPoint($position) {
|
||||
$y = $this->xAxisZero ? 0 : $this->getRealYMin();
|
||||
return awAxis::toPosition($this->xAxis, $this->yAxis, new awPoint($position, $y));
|
||||
}
|
||||
|
||||
public function getXCenter() {
|
||||
return ($this->lineMode === awLinePlot::MIDDLE);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
registerClass('SimpleLinePlot');
|
||||
|
||||
@@ -1,438 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* This work is hereby released into the Public Domain.
|
||||
* To view a copy of the public domain dedication,
|
||||
* visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
|
||||
* Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__)."/Component.class.php";
|
||||
|
||||
/**
|
||||
* A mathematic function
|
||||
*
|
||||
* @package Artichow
|
||||
*/
|
||||
class awMathFunction implements awLegendable {
|
||||
|
||||
/**
|
||||
* Function line
|
||||
*
|
||||
* @var Line
|
||||
*/
|
||||
public $line;
|
||||
|
||||
/**
|
||||
* Marks for your plot
|
||||
*
|
||||
* @var Mark
|
||||
*/
|
||||
public $mark;
|
||||
|
||||
/**
|
||||
* Callback function
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $f;
|
||||
|
||||
/**
|
||||
* Start the drawing from this value
|
||||
*
|
||||
* @var float
|
||||
*/
|
||||
public $fromX;
|
||||
|
||||
/**
|
||||
* Stop the drawing at this value
|
||||
*
|
||||
* @var float
|
||||
*/
|
||||
public $toX;
|
||||
|
||||
/**
|
||||
* Line color
|
||||
*
|
||||
* @var Color
|
||||
*/
|
||||
protected $color;
|
||||
|
||||
/**
|
||||
* Construct the function
|
||||
*
|
||||
* @param string $f Callback function
|
||||
* @param float $fromX
|
||||
* @param float $toX
|
||||
*/
|
||||
public function __construct($f, $fromX = NULL, $toX = NULL) {
|
||||
|
||||
$this->f = (string)$f;
|
||||
$this->fromX = is_null($fromX) ? NULL : (float)$fromX;
|
||||
$this->toX = is_null($toX) ? NULL : (float)$toX;
|
||||
|
||||
$this->line = new awLine;
|
||||
$this->mark = new awMark;
|
||||
$this->color = new awBlack;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Change line color
|
||||
*
|
||||
* @param awColor $color A new awcolor
|
||||
*/
|
||||
public function setColor(awColor $color) {
|
||||
$this->color = $color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get line color
|
||||
*
|
||||
* @return Color
|
||||
*/
|
||||
public function getColor() {
|
||||
return $this->color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the background color or gradient of an element of the component
|
||||
*
|
||||
* @return Color, Gradient
|
||||
*/
|
||||
public function getLegendBackground() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the line thickness
|
||||
*
|
||||
* @return NULL
|
||||
*/
|
||||
public function getLegendLineThickness() {
|
||||
return $this->line->getThickness();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the line type
|
||||
*
|
||||
* @return NULL
|
||||
*/
|
||||
public function getLegendLineStyle() {
|
||||
return $this->line->getStyle();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the color of line
|
||||
*
|
||||
* @return NULL
|
||||
*/
|
||||
public function getLegendLineColor() {
|
||||
return $this->color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a mark object
|
||||
*
|
||||
* @return NULL
|
||||
*/
|
||||
public function getLegendMark() {
|
||||
return $this->mark;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
registerClass('MathFunction');
|
||||
|
||||
/**
|
||||
* For mathematics functions
|
||||
*
|
||||
* @package Artichow
|
||||
*/
|
||||
class awMathPlot extends awComponent {
|
||||
|
||||
/**
|
||||
* Functions
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $functions = array();
|
||||
|
||||
/**
|
||||
* Grid properties
|
||||
*
|
||||
* @var Grid
|
||||
*/
|
||||
public $grid;
|
||||
|
||||
/**
|
||||
* X axis
|
||||
*
|
||||
* @var Axis
|
||||
*/
|
||||
public $xAxis;
|
||||
|
||||
/**
|
||||
* Y axis
|
||||
*
|
||||
* @var Axis
|
||||
*/
|
||||
public $yAxis;
|
||||
|
||||
/**
|
||||
* Extremum
|
||||
*
|
||||
* @var Side
|
||||
*/
|
||||
private $extremum = NULL;
|
||||
|
||||
/**
|
||||
* Interval
|
||||
*
|
||||
* @var float
|
||||
*/
|
||||
private $interval = 1;
|
||||
|
||||
/**
|
||||
* Build the plot
|
||||
*
|
||||
* @param int $xMin Minimum X value
|
||||
* @param int $xMax Maximum X value
|
||||
* @param int $yMax Maximum Y value
|
||||
* @param int $yMin Minimum Y value
|
||||
*/
|
||||
public function __construct($xMin, $xMax, $yMax, $yMin) {
|
||||
|
||||
parent::__construct();
|
||||
|
||||
$this->setPadding(8, 8, 8, 8);
|
||||
|
||||
$this->grid = new awGrid;
|
||||
|
||||
// Hide grid by default
|
||||
$this->grid->hide(TRUE);
|
||||
|
||||
// Set extremum
|
||||
$this->extremum = new awSide($xMin, $xMax, $yMax, $yMin);
|
||||
|
||||
// Create axis
|
||||
$this->xAxis = new awAxis;
|
||||
$this->xAxis->setTickStyle(awTick::IN);
|
||||
$this->xAxis->label->hideValue(0);
|
||||
$this->initAxis($this->xAxis);
|
||||
|
||||
$this->yAxis = new awAxis;
|
||||
$this->yAxis->setTickStyle(awTick::IN);
|
||||
$this->yAxis->label->hideValue(0);
|
||||
$this->initAxis($this->yAxis);
|
||||
|
||||
}
|
||||
|
||||
protected function initAxis(awAxis $axis) {
|
||||
|
||||
$axis->setLabelPrecision(1);
|
||||
$axis->addTick('major', new awTick(0, 5));
|
||||
$axis->addTick('minor', new awTick(0, 3));
|
||||
$axis->addTick('micro', new awTick(0, 1));
|
||||
$axis->setNumberByTick('minor', 'major', 1);
|
||||
$axis->setNumberByTick('micro', 'minor', 4);
|
||||
$axis->label->setFont(new awTuffy(7));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Interval to calculate values
|
||||
*
|
||||
* @param float $interval
|
||||
*/
|
||||
public function setInterval($interval) {
|
||||
$this->interval = (float)$interval;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a formula f(x)
|
||||
*
|
||||
* @param awMathFunction $function
|
||||
* @param string $name Name for the legend (can be NULL if you don't want to set a legend)
|
||||
* @param int $type Type for the legend
|
||||
*/
|
||||
public function add(awMathFunction $function, $name = NULL, $type = awLegend::LINE) {
|
||||
|
||||
$this->functions[] = $function;
|
||||
|
||||
if($name !== NULL) {
|
||||
$this->legend->add($function, $name, $type);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function init(awDriver $driver) {
|
||||
|
||||
list($x1, $y1, $x2, $y2) = $this->getPosition();
|
||||
|
||||
$this->xAxis->line->setX($x1, $x2);
|
||||
$this->xAxis->label->setAlign(NULL, awLabel::BOTTOM);
|
||||
$this->xAxis->label->move(0, 3);
|
||||
$this->xAxis->setRange($this->extremum->left, $this->extremum->right);
|
||||
|
||||
$this->yAxis->line->setY($y2, $y1);
|
||||
$this->yAxis->label->setAlign(awLabel::RIGHT);
|
||||
$this->yAxis->label->move(-6, 0);
|
||||
$this->yAxis->reverseTickStyle();
|
||||
$this->yAxis->setRange($this->extremum->bottom, $this->extremum->top);
|
||||
|
||||
|
||||
$this->xAxis->setYCenter($this->yAxis, 0);
|
||||
$this->yAxis->setXCenter($this->xAxis, 0);
|
||||
|
||||
if($this->yAxis->getLabelNumber() === NULL) {
|
||||
$number = $this->extremum->top - $this->extremum->bottom + 1;
|
||||
$this->yAxis->setLabelNumber($number);
|
||||
}
|
||||
|
||||
if($this->xAxis->getLabelNumber() === NULL) {
|
||||
$number = $this->extremum->right - $this->extremum->left + 1;
|
||||
$this->xAxis->setLabelNumber($number);
|
||||
}
|
||||
|
||||
// Set ticks
|
||||
|
||||
$this->xAxis->tick('major')->setNumber($this->xAxis->getLabelNumber());
|
||||
$this->yAxis->tick('major')->setNumber($this->yAxis->getLabelNumber());
|
||||
|
||||
|
||||
// Set axis labels
|
||||
$labels = array();
|
||||
for($i = 0, $count = $this->xAxis->getLabelNumber(); $i < $count; $i++) {
|
||||
$labels[] = $i;
|
||||
}
|
||||
$this->xAxis->label->set($labels);
|
||||
|
||||
$labels = array();
|
||||
for($i = 0, $count = $this->yAxis->getLabelNumber(); $i < $count; $i++) {
|
||||
$labels[] = $i;
|
||||
}
|
||||
$this->yAxis->label->set($labels);
|
||||
|
||||
parent::init($driver);
|
||||
|
||||
// Create the grid
|
||||
$this->createGrid();
|
||||
|
||||
// Draw the grid
|
||||
$this->grid->draw($driver, $x1, $y1, $x2, $y2);
|
||||
|
||||
}
|
||||
|
||||
public function drawEnvelope(awDriver $driver) {
|
||||
|
||||
// Draw axis
|
||||
$this->xAxis->draw($driver);
|
||||
$this->yAxis->draw($driver);
|
||||
|
||||
}
|
||||
|
||||
public function drawComponent(awDriver $driver, $x1, $y1, $x2, $y2, $aliasing) {
|
||||
|
||||
foreach($this->functions as $function) {
|
||||
|
||||
$f = $function->f;
|
||||
$fromX = is_null($function->fromX) ? $this->extremum->left : $function->fromX;
|
||||
$toX = is_null($function->toX) ? $this->extremum->right : $function->toX;
|
||||
|
||||
$old = NULL;
|
||||
|
||||
for($i = $fromX; $i <= $toX; $i += $this->interval) {
|
||||
|
||||
$p = awAxis::toPosition($this->xAxis, $this->yAxis, new awPoint($i, $f($i)));
|
||||
|
||||
if($p->y >= $y1 and $p->y <= $y2) {
|
||||
$function->mark->draw($driver, $p);
|
||||
}
|
||||
|
||||
if($old !== NULL) {
|
||||
|
||||
$line = $function->line;
|
||||
$line->setLocation($old, $p);
|
||||
|
||||
if(
|
||||
($line->p1->y >= $y1 and $line->p1->y <= $y2) or
|
||||
($line->p2->y >= $y1 and $line->p2->y <= $y2)
|
||||
) {
|
||||
$driver->line(
|
||||
$function->getColor(),
|
||||
$line
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$old = $p;
|
||||
|
||||
}
|
||||
|
||||
// Draw last point if needed
|
||||
if($old !== NULL and $i - $this->interval != $toX) {
|
||||
|
||||
$p = awAxis::toPosition($this->xAxis, $this->yAxis, new awPoint($toX, $f($toX)));
|
||||
|
||||
if($p->y >= $y1 and $p->y <= $y2) {
|
||||
$function->mark->draw($driver, $p);
|
||||
}
|
||||
|
||||
|
||||
$line = $function->line;
|
||||
$line->setLocation($old, $p);
|
||||
|
||||
if(
|
||||
($line->p1->y >= $y1 and $line->p1->y <= $y2) or
|
||||
($line->p2->y >= $y1 and $line->p2->y <= $y2)
|
||||
) {
|
||||
$driver->line(
|
||||
$function->getColor(),
|
||||
$line
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected function createGrid() {
|
||||
|
||||
// Horizontal lines of the grid
|
||||
|
||||
$major = $this->yAxis->tick('major');
|
||||
$interval = $major->getInterval();
|
||||
$number = $this->yAxis->getLabelNumber() - 1;
|
||||
|
||||
$h = array();
|
||||
if($number > 0) {
|
||||
for($i = 0; $i <= $number; $i++) {
|
||||
$h[] = $i / $number;
|
||||
}
|
||||
}
|
||||
|
||||
// Vertical lines
|
||||
|
||||
$major = $this->xAxis->tick('major');
|
||||
$interval = $major->getInterval();
|
||||
$number = $this->xAxis->getLabelNumber() - 1;
|
||||
|
||||
$w = array();
|
||||
if($number > 0) {
|
||||
for($i = 0; $i <= $number; $i++) {
|
||||
if($i%$interval === 0) {
|
||||
$w[] = $i / $number;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->grid->setGrid($w, $h);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
registerClass('MathPlot');
|
||||
@@ -1,96 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* This work is hereby released into the Public Domain.
|
||||
* To view a copy of the public domain dedication,
|
||||
* visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
|
||||
* Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__)."/Graph.class.php";
|
||||
|
||||
/**
|
||||
* All patterns must derivate from this class
|
||||
*
|
||||
* @package Artichow
|
||||
*/
|
||||
abstract class awPattern {
|
||||
|
||||
/**
|
||||
* Pattern arguments
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $args = array();
|
||||
|
||||
/**
|
||||
* Load a pattern
|
||||
*
|
||||
* @param string $pattern Pattern name
|
||||
* @return Component
|
||||
*/
|
||||
public static function get($pattern) {
|
||||
|
||||
$file = ARTICHOW_PATTERN.DIRECTORY_SEPARATOR.$pattern.'.php';
|
||||
|
||||
if(is_file($file)) {
|
||||
|
||||
require_once $file;
|
||||
|
||||
$class = $pattern.'Pattern';
|
||||
|
||||
if(class_exists($class)) {
|
||||
return new $class;
|
||||
} else {
|
||||
awImage::drawError("Class Pattern: Class '".$class."' does not exist.");
|
||||
}
|
||||
|
||||
} else {
|
||||
awImage::drawError("Class Pattern: Pattern '".$pattern."' does not exist.");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Change pattern argument
|
||||
*
|
||||
* @param string $name Argument name
|
||||
* @param mixed $value Argument value
|
||||
*/
|
||||
public function setArg($name, $value) {
|
||||
if(is_string($name)) {
|
||||
$this->args[$name] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an argument
|
||||
*
|
||||
* @param string $name
|
||||
* @param mixed $default Default value if the argument does not exist (default to NULL)
|
||||
* @return mixed Argument value
|
||||
*/
|
||||
protected function getArg($name, $default = NULL) {
|
||||
if(array_key_exists($name, $this->args)) {
|
||||
return $this->args[$name];
|
||||
} else {
|
||||
return $default;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Change several arguments
|
||||
*
|
||||
* @param array $args New arguments
|
||||
*/
|
||||
public function setArgs($args) {
|
||||
if(is_array($args)) {
|
||||
foreach($args as $name => $value) {
|
||||
$this->setArg($name, $value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
registerClass('Pattern', TRUE);
|
||||
@@ -1,694 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* This work is hereby released into the Public Domain.
|
||||
* To view a copy of the public domain dedication,
|
||||
* visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
|
||||
* Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__)."/Component.class.php";
|
||||
|
||||
|
||||
/**
|
||||
* Pie
|
||||
*
|
||||
* @package Artichow
|
||||
*/
|
||||
class awPie extends awComponent {
|
||||
|
||||
/**
|
||||
* A dark theme for pies
|
||||
*
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const DARK = 1;
|
||||
|
||||
/**
|
||||
* A colored theme for pies
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const COLORED = 2;
|
||||
|
||||
/**
|
||||
* A water theme for pies
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const AQUA = 3;
|
||||
|
||||
/**
|
||||
* A earth theme for pies
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const EARTH = 4;
|
||||
|
||||
/**
|
||||
* Pie values
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $values;
|
||||
|
||||
/**
|
||||
* Pie colors
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $colors;
|
||||
|
||||
/**
|
||||
* Pie legend
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $legendValues = array();
|
||||
|
||||
/**
|
||||
* Intensity of the 3D effect
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $size;
|
||||
|
||||
/**
|
||||
* Border color
|
||||
*
|
||||
* @var Color
|
||||
*/
|
||||
protected $border;
|
||||
|
||||
/**
|
||||
* Pie explode
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $explode = array();
|
||||
|
||||
/**
|
||||
* Initial angle
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $angle = 0;
|
||||
|
||||
/**
|
||||
* Labels precision
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $precision;
|
||||
|
||||
/**
|
||||
* Labels number
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $number;
|
||||
|
||||
/**
|
||||
* Labels minimum
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $minimum;
|
||||
|
||||
/**
|
||||
* Labels position
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $position = 15;
|
||||
|
||||
/**
|
||||
* Labels of your pie
|
||||
*
|
||||
* @var Label
|
||||
*/
|
||||
public $label;
|
||||
|
||||
/**
|
||||
* Build the plot
|
||||
*
|
||||
* @param array $values Pie values
|
||||
*/
|
||||
public function __construct($values, $colors = awPie::COLORED) {
|
||||
|
||||
$this->setValues($values);
|
||||
|
||||
if(is_array($colors)) {
|
||||
$this->colors = $colors;
|
||||
} else {
|
||||
|
||||
switch($colors) {
|
||||
|
||||
case awPie::AQUA :
|
||||
$this->colors = array(
|
||||
new awColor(131, 220, 215),
|
||||
new awColor(131, 190, 215),
|
||||
new awColor(131, 160, 215),
|
||||
new awColor(160, 140, 215),
|
||||
new awColor(190, 131, 215),
|
||||
new awColor(220, 131, 215)
|
||||
);
|
||||
break;
|
||||
|
||||
case awPie::EARTH :
|
||||
$this->colors = array(
|
||||
new awColor(97, 179, 110),
|
||||
new awColor(130, 179, 97),
|
||||
new awColor(168, 179, 97),
|
||||
new awColor(179, 147, 97),
|
||||
new awColor(179, 108, 97),
|
||||
new awColor(99, 107, 189),
|
||||
new awColor(99, 165, 189)
|
||||
);
|
||||
break;
|
||||
|
||||
case awPie::DARK :
|
||||
$this->colors = array(
|
||||
new awColor(140, 100, 170),
|
||||
new awColor(130, 170, 100),
|
||||
new awColor(160, 160, 120),
|
||||
new awColor(150, 110, 140),
|
||||
new awColor(130, 150, 160),
|
||||
new awColor(90, 170, 140)
|
||||
);
|
||||
break;
|
||||
|
||||
default :
|
||||
$this->colors = array(
|
||||
new awColor(187, 213, 151),
|
||||
new awColor(223, 177, 151),
|
||||
new awColor(111, 186, 132),
|
||||
new awColor(197, 160, 230),
|
||||
new awColor(165, 169, 63),
|
||||
new awColor(218, 177, 89),
|
||||
new awColor(116, 205, 121),
|
||||
new awColor(200, 201, 78),
|
||||
new awColor(127, 205, 177),
|
||||
new awColor(205, 160, 160),
|
||||
new awColor(190, 190, 190)
|
||||
);
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
parent::__construct();
|
||||
|
||||
$this->label = new awLabel;
|
||||
$this->label->setCallbackFunction('callbackPerCent');
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Change legend values
|
||||
*
|
||||
* @param array $legend An array of values for each part of the pie
|
||||
*/
|
||||
public function setLegend($legend) {
|
||||
|
||||
$this->legendValues = (array)$legend;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a border all around the pie
|
||||
*
|
||||
* @param awColor $color A color for the border
|
||||
*/
|
||||
public function setBorderColor(awColor $color) {
|
||||
$this->border = $color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a border all around the pie
|
||||
*
|
||||
* @param awColor $color A color for the border
|
||||
*/
|
||||
public function setBorder(awColor $color) {
|
||||
if(ARTICHOW_DEPRECATED === TRUE) {
|
||||
awImage::drawError('Class Pie: Method setBorder() has been deprecated since Artichow 1.0.9. Please use setBorderColor() instead.');
|
||||
} else {
|
||||
$this->setBorderColor($color);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Change 3D effect intensity
|
||||
*
|
||||
* @param int $size Effect size
|
||||
*/
|
||||
public function set3D($size) {
|
||||
$this->size = (int)$size;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change initial angle
|
||||
*
|
||||
* @param int $angle New angle in degrees
|
||||
*/
|
||||
public function setStartAngle($angle) {
|
||||
$this->angle = (int)$angle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change label precision
|
||||
*
|
||||
* @param int $precision New precision
|
||||
*/
|
||||
public function setLabelPrecision($precision) {
|
||||
$this->precision = (int)$precision;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change label position
|
||||
*
|
||||
* @param int $position New position in pixels
|
||||
*/
|
||||
public function setLabelPosition($position) {
|
||||
$this->position = (int)$position;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change label number
|
||||
*
|
||||
* @param int $number New number
|
||||
*/
|
||||
public function setLabelNumber($number) {
|
||||
$this->number = is_null($number) ? $number : (int)$number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change label minimum
|
||||
*
|
||||
* @param int $minimum New minimum
|
||||
*/
|
||||
public function setLabelMinimum($minimum) {
|
||||
$this->minimum = is_null($minimum) ? $minimum : (int)$minimum;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change Pie explode
|
||||
*
|
||||
* @param array $explode
|
||||
*/
|
||||
public function explode($explode) {
|
||||
$this->explode = (array)$explode;
|
||||
}
|
||||
|
||||
public function drawEnvelope(awDriver $driver) {
|
||||
|
||||
}
|
||||
|
||||
public function drawComponent(awDriver $driver, $x1, $y1, $x2, $y2, $aliasing) {
|
||||
|
||||
$count = count($this->values);
|
||||
$sum = array_sum($this->values);
|
||||
|
||||
$width = $x2 - $x1;
|
||||
$height = $y2 - $y1;
|
||||
|
||||
if($aliasing) {
|
||||
$x = $width / 2;
|
||||
$y = $height / 2;
|
||||
} else {
|
||||
$x = $width / 2 + $x1;
|
||||
$y = $height / 2 + $y1;
|
||||
}
|
||||
|
||||
$position = $this->angle;
|
||||
$values = array();
|
||||
$parts = array();
|
||||
$angles = 0;
|
||||
|
||||
if($aliasing) {
|
||||
$side = new awSide(0, 0, 0, 0);
|
||||
}
|
||||
|
||||
foreach($this->values as $key => $value) {
|
||||
|
||||
$angle = ($value / $sum * 360);
|
||||
|
||||
if($key === $count - 1) {
|
||||
$angle = 360 - $angles;
|
||||
}
|
||||
|
||||
$angles += $angle;
|
||||
|
||||
if(array_key_exists($key, $this->explode)) {
|
||||
$middle = 360 - ($position + $angle / 2);
|
||||
$posX = $this->explode[$key] * cos($middle * M_PI / 180);
|
||||
$posY = $this->explode[$key] * sin($middle * M_PI / 180) * -1;
|
||||
|
||||
if($aliasing) {
|
||||
$explode = new awPoint(
|
||||
$posX * 2,
|
||||
$posY * 2
|
||||
);
|
||||
$side->set(
|
||||
max($side->left, $posX * -2),
|
||||
max($side->right, $posX * 2),
|
||||
max($side->top, $posY * -2),
|
||||
max($side->bottom, $posY * 2)
|
||||
);
|
||||
} else {
|
||||
$explode = new awPoint(
|
||||
$posX,
|
||||
$posY
|
||||
);
|
||||
}
|
||||
|
||||
} else {
|
||||
$explode = new awPoint(0, 0);
|
||||
}
|
||||
|
||||
$values[$key] = array(
|
||||
$position, ($position + $angle), $explode
|
||||
);
|
||||
|
||||
$color = $this->colors[$key % count($this->colors)];
|
||||
$parts[$key] = new awPiePart($color);
|
||||
|
||||
// Add part to the legend
|
||||
$legend = array_key_exists($key, $this->legendValues) ? $this->legendValues[$key] : $key;
|
||||
$this->legend->add($parts[$key], $legend, awLegend::BACKGROUND);
|
||||
|
||||
$position += $angle;
|
||||
|
||||
}
|
||||
|
||||
if($aliasing) {
|
||||
|
||||
$mainDriver = $driver;
|
||||
|
||||
$x *= 2;
|
||||
$y *= 2;
|
||||
$width *= 2;
|
||||
$height *= 2;
|
||||
$this->size *= 2;
|
||||
|
||||
$image = new awImage;
|
||||
$image->border->hide();
|
||||
|
||||
// Adds support for antialiased pies on non-white background
|
||||
$background = $this->getBackground();
|
||||
|
||||
if($background instanceof awColor) {
|
||||
$image->setBackgroundColor($background);
|
||||
}
|
||||
// elseif($background instanceof awGradient) {
|
||||
// $image->setBackgroundColor(new White(100));
|
||||
// }
|
||||
|
||||
$image->setSize(
|
||||
$width + $side->left + $side->right,
|
||||
$height + $side->top + $side->bottom + $this->size + 1 /* bugs.php.net ! */
|
||||
);
|
||||
|
||||
$driver = $image->getDriver(
|
||||
$width / $image->width,
|
||||
$height / $image->height,
|
||||
($width / 2 + $side->left) / $image->width,
|
||||
($height / 2 + $side->top) / $image->height
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
// Draw 3D effect
|
||||
for($i = $this->size; $i > 0; $i--) {
|
||||
|
||||
foreach($values as $key => $value) {
|
||||
|
||||
$color = clone $this->colors[$key % count($this->colors)];
|
||||
$color->brightness(-50);
|
||||
|
||||
list($from, $to, $explode) = $value;
|
||||
|
||||
$driver->filledArc($color, $explode->move($x, $y + $i), $width, $height, $from, $to);
|
||||
|
||||
unset($color);
|
||||
|
||||
if($this->border instanceof awColor) {
|
||||
|
||||
$point = $explode->move($x, $y);
|
||||
|
||||
if($i === $this->size) {
|
||||
|
||||
$driver->arc($this->border, $point->move(0, $this->size), $width, $height, $from, $to);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
foreach($values as $key => $value) {
|
||||
|
||||
$color = $this->colors[$key % count($this->colors)];
|
||||
|
||||
list($from, $to, $explode) = $value;
|
||||
|
||||
$driver->filledArc($color, $explode->move($x, $y), $width, $height, $from, $to);
|
||||
|
||||
if($this->border instanceof awColor) {
|
||||
|
||||
$point = $explode->move($x, $y);
|
||||
$driver->arc($this->border, $point, $width, $height, $from, $to);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if($aliasing) {
|
||||
|
||||
$x = $x / 2 + $x1;
|
||||
$y = $y / 2 + $y1;
|
||||
$width /= 2;
|
||||
$height /= 2;
|
||||
$this->size /= 2;
|
||||
|
||||
foreach($values as $key => $value) {
|
||||
$old = $values[$key][2];
|
||||
$values[$key][2] = new awPoint(
|
||||
$old->x / 2, $old->y / 2
|
||||
);
|
||||
}
|
||||
|
||||
$mainDriver->copyResizeImage(
|
||||
$image,
|
||||
new awPoint($x1 - $side->left / 2, $y1 - $side->top / 2),
|
||||
new awPoint($x1 - $side->left / 2 + $image->width / 2, $y1 - $side->top / 2 + $image->height/ 2),
|
||||
new awPoint(0, 0),
|
||||
new awPoint($image->width, $image->height),
|
||||
TRUE
|
||||
);
|
||||
|
||||
$driver = $mainDriver;
|
||||
|
||||
}
|
||||
|
||||
// Get labels values
|
||||
$pc = array();
|
||||
foreach($this->values as $key => $value) {
|
||||
$pc[$key] = round($value / $sum * 100, $this->precision);
|
||||
}
|
||||
if($this->label->count() === 0) { // Check that there is no user defined values
|
||||
$this->label->set($pc);
|
||||
}
|
||||
|
||||
$position = 0;
|
||||
|
||||
foreach($pc as $key => $value) {
|
||||
|
||||
// Limit number of labels to display
|
||||
if($position === $this->number) {
|
||||
break;
|
||||
}
|
||||
|
||||
if(is_null($this->minimum) === FALSE and $value < $this->minimum) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$position++;
|
||||
|
||||
list($from, $to, $explode) = $values[$key];
|
||||
|
||||
$angle = $from + ($to - $from) / 2;
|
||||
$angleRad = (360 - $angle) * M_PI / 180;
|
||||
|
||||
$point = new awPoint(
|
||||
$x + $explode->x + cos($angleRad) * ($width / 2 + $this->position),
|
||||
$y + $explode->y - sin($angleRad) * ($height / 2 + $this->position)
|
||||
);
|
||||
|
||||
$angle %= 360;
|
||||
|
||||
// We don't display labels on the 3D effect
|
||||
if($angle > 0 and $angle < 180) {
|
||||
$point = $point->move(0, -1 * sin($angleRad) * $this->size);
|
||||
}
|
||||
|
||||
if($angle >= 45 and $angle < 135) {
|
||||
$this->label->setAlign(awLabel::CENTER, awLabel::BOTTOM);
|
||||
} else if($angle >= 135 and $angle < 225) {
|
||||
$this->label->setAlign(awLabel::RIGHT, awLabel::MIDDLE);
|
||||
} else if($angle >= 225 and $angle < 315) {
|
||||
$this->label->setAlign(awLabel::CENTER, awLabel::TOP);
|
||||
} else {
|
||||
$this->label->setAlign(awLabel::LEFT, awLabel::MIDDLE);
|
||||
}
|
||||
|
||||
$this->label->draw(
|
||||
$driver,
|
||||
$point,
|
||||
$key
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Return margins around the component
|
||||
*
|
||||
* @return array Left, right, top and bottom margins
|
||||
*/
|
||||
public function getMargin() {
|
||||
|
||||
// Get axis informations
|
||||
|
||||
$leftAxis = $this->padding->left;
|
||||
$rightAxis = $this->padding->right;
|
||||
$topAxis = $this->padding->top;
|
||||
$bottomAxis = $this->padding->bottom;
|
||||
|
||||
return array($leftAxis, $rightAxis, $topAxis, $bottomAxis);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Change values of Y axis
|
||||
* This method ignores not numeric values
|
||||
*
|
||||
* @param array $values
|
||||
*/
|
||||
public function setValues($values) {
|
||||
|
||||
$this->checkArray($values);
|
||||
$this->values = $values;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return values of Y axis
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getValues() {
|
||||
return $this->values;
|
||||
}
|
||||
|
||||
private function checkArray(&$array) {
|
||||
|
||||
if(is_array($array) === FALSE) {
|
||||
awImage::drawError("Class Pie: You tried to set values that are not an array.");
|
||||
}
|
||||
|
||||
foreach($array as $key => $value) {
|
||||
if(is_numeric($value) === FALSE) {
|
||||
unset($array[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
if(count($array) < 1) {
|
||||
awImage::drawError("Class Pie: Your graph must have at least 1 value.");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
registerClass('Pie');
|
||||
|
||||
/**
|
||||
* Pie
|
||||
*
|
||||
* @package Artichow
|
||||
*/
|
||||
class awPiePart implements awLegendable {
|
||||
|
||||
/**
|
||||
* Pie part color
|
||||
*
|
||||
* @var Color
|
||||
*/
|
||||
protected $color;
|
||||
|
||||
/**
|
||||
* Build a new awPiePart
|
||||
*
|
||||
* @param awColor $color Pie part color
|
||||
*/
|
||||
public function __construct(awColor $color) {
|
||||
|
||||
$this->color = $color;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the background color or gradient of an element of the component
|
||||
*
|
||||
* @return Color, Gradient
|
||||
*/
|
||||
public function getLegendBackground() {
|
||||
return $this->color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the line thickness
|
||||
*
|
||||
* @return NULL
|
||||
*/
|
||||
public function getLegendLineThickness() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the line type
|
||||
*
|
||||
* @return NULL
|
||||
*/
|
||||
public function getLegendLineStyle() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the color of line
|
||||
*
|
||||
* @return NULL
|
||||
*/
|
||||
public function getLegendLineColor() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a mark object
|
||||
*
|
||||
* @return NULL
|
||||
*/
|
||||
public function getLegendMark() {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
registerClass('PiePart');
|
||||
|
||||
function callbackPerCent($value) {
|
||||
return $value.'%';
|
||||
}
|
||||
@@ -1,300 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* This work is hereby released into the Public Domain.
|
||||
* To view a copy of the public domain dedication,
|
||||
* visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
|
||||
* Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__)."/Plot.class.php";
|
||||
|
||||
/**
|
||||
* ScatterPlot
|
||||
*
|
||||
* @package Artichow
|
||||
*/
|
||||
class awScatterPlot extends awPlot implements awLegendable {
|
||||
|
||||
/**
|
||||
* Add marks to the scatter plot
|
||||
*
|
||||
* @var Mark
|
||||
*/
|
||||
public $mark;
|
||||
|
||||
/**
|
||||
* Labels on the plot
|
||||
*
|
||||
* @var Label
|
||||
*/
|
||||
public $label;
|
||||
|
||||
/**
|
||||
* Link points ?
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $link = FALSE;
|
||||
|
||||
/**
|
||||
* Display impulses
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $impulse = NULL;
|
||||
|
||||
/**
|
||||
* Link NULL points ?
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $linkNull = FALSE;
|
||||
|
||||
/**
|
||||
* Line color
|
||||
*
|
||||
* @var Color
|
||||
*/
|
||||
protected $lineColor;
|
||||
|
||||
/**
|
||||
* Line type
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $lineStyle = awLine::SOLID;
|
||||
|
||||
/**
|
||||
* Line thickness
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $lineThickness = 1;
|
||||
|
||||
/**
|
||||
* Construct a new awScatterPlot
|
||||
*
|
||||
* @param array $datay Numeric values for Y axis
|
||||
* @param array $datax Numeric values for X axis
|
||||
* @param int $mode
|
||||
*/
|
||||
public function __construct($datay, $datax = NULL) {
|
||||
|
||||
parent::__construct();
|
||||
|
||||
// Defaults marks
|
||||
$this->mark = new awMark;
|
||||
$this->mark->setType(awMark::CIRCLE);
|
||||
$this->mark->setSize(7);
|
||||
$this->mark->border->show();
|
||||
|
||||
$this->label = new awLabel;
|
||||
|
||||
$this->setValues($datay, $datax);
|
||||
$this->setColor(new awBlack);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Display plot as impulses
|
||||
*
|
||||
* @param awColor $impulse Impulses color (or NULL to disable impulses)
|
||||
*/
|
||||
public function setImpulse($color) {
|
||||
$this->impulse = $color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Link scatter plot points
|
||||
*
|
||||
* @param bool $link
|
||||
* @param awColor $color Line color (default to black)
|
||||
*/
|
||||
public function link($link, $color = NULL) {
|
||||
$this->link = (bool)$link;
|
||||
if($color instanceof awColor) {
|
||||
$this->setColor($color);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Ignore null values for Y data and continue linking
|
||||
*
|
||||
* @param bool $link
|
||||
*/
|
||||
public function linkNull($link) {
|
||||
$this->linkNull = (bool)$link;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change line color
|
||||
*
|
||||
* @param awColor $color
|
||||
*/
|
||||
public function setColor(awColor $color) {
|
||||
$this->lineColor = $color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change line style
|
||||
*
|
||||
* @param int $style
|
||||
*/
|
||||
public function setStyle($style) {
|
||||
$this->lineStyle = (int)$style;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change line tickness
|
||||
*
|
||||
* @param int $tickness
|
||||
*/
|
||||
public function setThickness($tickness) {
|
||||
$this->lineThickness = (int)$tickness;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the line thickness
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getLegendLineThickness() {
|
||||
return $this->lineThickness;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the line type
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getLegendLineStyle() {
|
||||
return $this->lineStyle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the color of line
|
||||
*
|
||||
* @return Color
|
||||
*/
|
||||
public function getLegendLineColor() {
|
||||
return $this->lineColor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the background color or gradient of an element of the component
|
||||
*
|
||||
* @return Color, Gradient
|
||||
*/
|
||||
public function getLegendBackground() {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a mark object
|
||||
*
|
||||
* @return Mark
|
||||
*/
|
||||
public function getLegendMark() {
|
||||
return $this->mark;
|
||||
}
|
||||
|
||||
public function drawComponent(awDriver $driver, $x1, $y1, $x2, $y2, $aliasing) {
|
||||
|
||||
$count = count($this->datay);
|
||||
|
||||
// Get start and stop values
|
||||
list($start, $stop) = $this->getLimit();
|
||||
|
||||
// Build the polygon
|
||||
$polygon = new awPolygon;
|
||||
|
||||
for($key = 0; $key < $count; $key++) {
|
||||
|
||||
$x = $this->datax[$key];
|
||||
$y = $this->datay[$key];
|
||||
|
||||
if($y !== NULL) {
|
||||
$p = awAxis::toPosition($this->xAxis, $this->yAxis, new awPoint($x, $y));
|
||||
$polygon->set($key, $p);
|
||||
} else if($this->linkNull === FALSE) {
|
||||
$polygon->set($key, NULL);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Link points if needed
|
||||
if($this->link) {
|
||||
|
||||
$prev = NULL;
|
||||
|
||||
foreach($polygon->all() as $point) {
|
||||
|
||||
if($prev !== NULL and $point !== NULL) {
|
||||
$driver->line(
|
||||
$this->lineColor,
|
||||
new awLine(
|
||||
$prev,
|
||||
$point,
|
||||
$this->lineStyle,
|
||||
$this->lineThickness
|
||||
)
|
||||
);
|
||||
}
|
||||
$prev = $point;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// Draw impulses
|
||||
if($this->impulse instanceof awColor) {
|
||||
|
||||
foreach($polygon->all() as $key => $point) {
|
||||
|
||||
if($point !== NULL) {
|
||||
|
||||
$zero = awAxis::toPosition(
|
||||
$this->xAxis,
|
||||
$this->yAxis,
|
||||
new awPoint($key, 0)
|
||||
);
|
||||
|
||||
$driver->line(
|
||||
$this->impulse,
|
||||
new awLine(
|
||||
$zero,
|
||||
$point,
|
||||
awLine::SOLID,
|
||||
1
|
||||
)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Draw marks and labels
|
||||
foreach($polygon->all() as $key => $point) {
|
||||
|
||||
$this->mark->draw($driver, $point);
|
||||
$this->label->draw($driver, $point, $key);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected function xAxisPoint($position) {
|
||||
$y = $this->xAxisZero ? 0 : $this->getRealYMin();
|
||||
return awAxis::toPosition($this->xAxis, $this->yAxis, new awPoint($position, $y));
|
||||
}
|
||||
|
||||
public function getXCenter() {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
registerClass('ScatterPlot');
|
||||
|
||||
|
Before Width: | Height: | Size: 15 KiB |
@@ -1,2 +0,0 @@
|
||||
1166203484
|
||||
png
|
||||
|
Before Width: | Height: | Size: 14 KiB |
@@ -1,2 +0,0 @@
|
||||
1166203480
|
||||
png
|
||||
|
Before Width: | Height: | Size: 13 KiB |
@@ -1,2 +0,0 @@
|
||||
1204776421
|
||||
png
|
||||
@@ -1,35 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* 2007-2013 PrestaShop
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License (AFL 3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://opensource.org/licenses/afl-3.0.php
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
|
||||
* versions in the future. If you wish to customize PrestaShop for your
|
||||
* needs please refer to http://www.prestashop.com for more information.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2013 PrestaShop SA
|
||||
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
|
||||
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
|
||||
|
||||
header("Cache-Control: no-store, no-cache, must-revalidate");
|
||||
header("Cache-Control: post-check=0, pre-check=0", false);
|
||||
header("Pragma: no-cache");
|
||||
|
||||
header("Location: ../");
|
||||
exit;
|
||||
@@ -1,96 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* This work is hereby released into the Public Domain.
|
||||
* To view a copy of the public domain dedication,
|
||||
* visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
|
||||
* Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Get the minimum of an array and ignore non numeric values
|
||||
*/
|
||||
function array_min($array) {
|
||||
|
||||
if(is_array($array) and count($array) > 0) {
|
||||
|
||||
do {
|
||||
$min = array_pop($array);
|
||||
if(is_numeric($min) === FALSE) {
|
||||
$min = NULL;
|
||||
}
|
||||
} while(count($array) > 0 and $min === NULL);
|
||||
|
||||
if($min !== NULL) {
|
||||
$min = (float)$min;
|
||||
}
|
||||
|
||||
foreach($array as $value) {
|
||||
if(is_numeric($value) and (float)$value < $min) {
|
||||
$min = (float)$value;
|
||||
}
|
||||
}
|
||||
|
||||
return $min;
|
||||
|
||||
}
|
||||
|
||||
return NULL;
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* Get the maximum of an array and ignore non numeric values
|
||||
*/
|
||||
function array_max($array) {
|
||||
|
||||
if(is_array($array) and count($array) > 0) {
|
||||
|
||||
do {
|
||||
$max = array_pop($array);
|
||||
if(is_numeric($max) === FALSE) {
|
||||
$max = NULL;
|
||||
}
|
||||
} while(count($array) > 0 and $max === NULL);
|
||||
|
||||
if($max !== NULL) {
|
||||
$max = (float)$max;
|
||||
}
|
||||
|
||||
foreach($array as $value) {
|
||||
if(is_numeric($value) and (float)$value > $max) {
|
||||
$max = (float)$value;
|
||||
}
|
||||
}
|
||||
|
||||
return $max;
|
||||
|
||||
}
|
||||
|
||||
return NULL;
|
||||
|
||||
}
|
||||
/*
|
||||
* Define file_put_contents() if needed
|
||||
*/
|
||||
if(function_exists('file_put_contents') === FALSE) {
|
||||
|
||||
function file_put_contents($file, $content) {
|
||||
$fp = fopen($file, 'w');
|
||||
if($fp) {
|
||||
fwrite($fp, $content);
|
||||
fclose($fp);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* Change error handler
|
||||
*/
|
||||
set_error_handler('errorHandlerArtichow');
|
||||
|
||||
function errorHandlerArtichow($level, $message, $file, $line) {
|
||||
awImage::drawError($message.' in '.$file.' on line '.$line.'.');
|
||||
}
|
||||
|
||||
@@ -1,35 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* 2007-2013 PrestaShop
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License (AFL 3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://opensource.org/licenses/afl-3.0.php
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
|
||||
* versions in the future. If you wish to customize PrestaShop for your
|
||||
* needs please refer to http://www.prestashop.com for more information.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2013 PrestaShop SA
|
||||
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
|
||||
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
|
||||
|
||||
header("Cache-Control: no-store, no-cache, must-revalidate");
|
||||
header("Cache-Control: post-check=0, pre-check=0", false);
|
||||
header("Pragma: no-cache");
|
||||
|
||||
header("Location: ../");
|
||||
exit;
|
||||
|
Before Width: | Height: | Size: 797 B |
|
Before Width: | Height: | Size: 5.9 KiB |
@@ -1,35 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* 2007-2013 PrestaShop
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License (AFL 3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://opensource.org/licenses/afl-3.0.php
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
|
||||
* versions in the future. If you wish to customize PrestaShop for your
|
||||
* needs please refer to http://www.prestashop.com for more information.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2013 PrestaShop SA
|
||||
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
|
||||
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
|
||||
|
||||
header("Cache-Control: no-store, no-cache, must-revalidate");
|
||||
header("Cache-Control: post-check=0, pre-check=0", false);
|
||||
header("Pragma: no-cache");
|
||||
|
||||
header("Location: ../");
|
||||
exit;
|
||||
|
Before Width: | Height: | Size: 7.5 KiB |
|
Before Width: | Height: | Size: 7.3 KiB |
@@ -1,35 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* 2007-2013 PrestaShop
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License (AFL 3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://opensource.org/licenses/afl-3.0.php
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
|
||||
* versions in the future. If you wish to customize PrestaShop for your
|
||||
* needs please refer to http://www.prestashop.com for more information.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2013 PrestaShop SA
|
||||
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
|
||||
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
|
||||
|
||||
header("Cache-Control: no-store, no-cache, must-revalidate");
|
||||
header("Cache-Control: post-check=0, pre-check=0", false);
|
||||
header("Pragma: no-cache");
|
||||
|
||||
header("Location: ../");
|
||||
exit;
|
||||
|
Before Width: | Height: | Size: 452 B |
|
Before Width: | Height: | Size: 748 B |
@@ -1,768 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* This work is hereby released into the Public Domain.
|
||||
* To view a copy of the public domain dedication,
|
||||
* visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
|
||||
* Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__)."/../Graph.class.php";
|
||||
|
||||
/**
|
||||
* Handle axis
|
||||
*
|
||||
* @package Artichow
|
||||
*/
|
||||
class awAxis {
|
||||
|
||||
/**
|
||||
* Axis line
|
||||
*
|
||||
* @var Line
|
||||
*/
|
||||
public $line;
|
||||
|
||||
/**
|
||||
* Axis labels
|
||||
*
|
||||
* @var Label
|
||||
*/
|
||||
public $label;
|
||||
|
||||
/**
|
||||
* Axis title
|
||||
*
|
||||
* @var Label
|
||||
*/
|
||||
public $title;
|
||||
|
||||
/**
|
||||
* Title position
|
||||
*
|
||||
* @var float
|
||||
*/
|
||||
protected $titlePosition = 0.5;
|
||||
|
||||
/**
|
||||
* Labels number
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $labelNumber;
|
||||
|
||||
/**
|
||||
* Axis ticks
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $ticks = array();
|
||||
|
||||
/**
|
||||
* Axis and ticks color
|
||||
*
|
||||
* @var Color
|
||||
*/
|
||||
protected $color;
|
||||
|
||||
/**
|
||||
* Axis left and right padding
|
||||
*
|
||||
* @var Side
|
||||
*/
|
||||
protected $padding;
|
||||
|
||||
/**
|
||||
* Axis range
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $range;
|
||||
|
||||
/**
|
||||
* Hide axis
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $hide = FALSE;
|
||||
|
||||
/**
|
||||
* Auto-scaling mode
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $auto = TRUE;
|
||||
|
||||
/**
|
||||
* Axis range callback function
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $rangeCallback = array(
|
||||
'toValue' => 'toProportionalValue',
|
||||
'toPosition' => 'toProportionalPosition'
|
||||
);
|
||||
|
||||
/**
|
||||
* Build the axis
|
||||
*
|
||||
* @param float $min Begin of the range of the axis
|
||||
* @param float $max End of the range of the axis
|
||||
*/
|
||||
public function __construct($min = NULL, $max = NULL) {
|
||||
|
||||
$this->line = new awVector(
|
||||
new awPoint(0, 0),
|
||||
new awPoint(0, 0)
|
||||
);
|
||||
|
||||
$this->label = new awLabel;
|
||||
$this->padding = new awSide;
|
||||
|
||||
$this->title = new awLabel(
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
0
|
||||
);
|
||||
|
||||
$this->setColor(new awBlack);
|
||||
|
||||
if($min !== NULL and $max !== NULL) {
|
||||
$this->setRange($min, $max);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable/disable auto-scaling mode
|
||||
*
|
||||
* @param bool $auto
|
||||
*/
|
||||
public function auto($auto) {
|
||||
$this->auto = (bool)$auto;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get auto-scaling mode status
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isAuto() {
|
||||
return $this->auto;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hide axis
|
||||
*
|
||||
* @param bool $hide
|
||||
*/
|
||||
public function hide($hide = TRUE) {
|
||||
$this->hide = (bool)$hide;
|
||||
}
|
||||
|
||||
/**
|
||||
* Show axis
|
||||
*
|
||||
* @param bool $show
|
||||
*/
|
||||
public function show($show = TRUE) {
|
||||
$this->hide = !(bool)$show;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a tick object from its name
|
||||
*
|
||||
* @param string $name Tick object name
|
||||
* @return Tick
|
||||
*/
|
||||
public function tick($name) {
|
||||
|
||||
return array_key_exists($name, $this->ticks) ? $this->ticks[$name] : NULL;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a tick object
|
||||
*
|
||||
* @param string $name Tick object name
|
||||
* @param awTick $tick Tick object
|
||||
*/
|
||||
public function addTick($name, awTick $tick) {
|
||||
|
||||
$this->ticks[$name] = $tick;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a tick object
|
||||
*
|
||||
* @param string $name Tick object name
|
||||
*/
|
||||
public function deleteTick($name) {
|
||||
if(array_key_exists($name, $this->ticks)) {
|
||||
unset($this->ticks[$name]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Hide all ticks
|
||||
*
|
||||
* @param bool $hide Hide or not ?
|
||||
*/
|
||||
public function hideTicks($hide = TRUE) {
|
||||
|
||||
foreach($this->ticks as $tick) {
|
||||
$tick->hide($hide);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Change ticks style
|
||||
*
|
||||
* @param int $style Ticks style
|
||||
*/
|
||||
public function setTickStyle($style) {
|
||||
|
||||
foreach($this->ticks as $tick) {
|
||||
$tick->setStyle($style);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Change ticks interval
|
||||
*
|
||||
* @param int $interval Ticks interval
|
||||
*/
|
||||
public function setTickInterval($interval) {
|
||||
|
||||
foreach($this->ticks as $tick) {
|
||||
$tick->setInterval($interval);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Change number of ticks relative to others ticks
|
||||
*
|
||||
* @param awTick $to Change number of theses ticks
|
||||
* @param awTick $from Ticks reference
|
||||
* @param float $number Number of ticks by the reference
|
||||
*/
|
||||
public function setNumberByTick($to, $from, $number) {
|
||||
$this->ticks[$to]->setNumberByTick($this->ticks[$from], $number);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse ticks style
|
||||
*/
|
||||
public function reverseTickStyle() {
|
||||
|
||||
foreach($this->ticks as $tick) {
|
||||
if($tick->getStyle() === awTick::IN) {
|
||||
$tick->setStyle(awTick::OUT);
|
||||
} else if($tick->getStyle() === awTick::OUT) {
|
||||
$tick->setStyle(awTick::IN);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Change interval of labels
|
||||
*
|
||||
* @param int $interval Interval
|
||||
*/
|
||||
public function setLabelInterval($interval) {
|
||||
$this->auto(FALSE);
|
||||
$this->setTickInterval($interval);
|
||||
$this->label->setInterval($interval);
|
||||
}
|
||||
|
||||
/**
|
||||
* Change number of labels
|
||||
*
|
||||
* @param int $number Number of labels to display (can be NULL)
|
||||
*/
|
||||
public function setLabelNumber($number) {
|
||||
$this->auto(FALSE);
|
||||
$this->labelNumber = is_null($number) ? NULL : (int)$number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get number of labels
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getLabelNumber() {
|
||||
return $this->labelNumber;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change precision of labels
|
||||
*
|
||||
* @param int $precision Precision
|
||||
*/
|
||||
public function setLabelPrecision($precision) {
|
||||
$this->auto(FALSE);
|
||||
$function = 'axis'.time().'_'.(microtime() * 1000000);
|
||||
eval('function '.$function.'($value) {
|
||||
return sprintf("%.'.(int)$precision.'f", $value);
|
||||
}');
|
||||
$this->label->setCallbackFunction($function);
|
||||
}
|
||||
|
||||
/**
|
||||
* Change text of labels
|
||||
*
|
||||
* @param array $texts Some texts
|
||||
*/
|
||||
public function setLabelText($texts) {
|
||||
if(is_array($texts)) {
|
||||
$this->auto(FALSE);
|
||||
$function = 'axis'.time().'_'.(microtime() * 1000000);
|
||||
eval('function '.$function.'($value) {
|
||||
$texts = '.var_export($texts, TRUE).';
|
||||
return isset($texts[$value]) ? $texts[$value] : \'?\';
|
||||
}');
|
||||
$this->label->setCallbackFunction($function);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the position of a point
|
||||
*
|
||||
* @param awAxis $xAxis X axis
|
||||
* @param awAxis $yAxis Y axis
|
||||
* @param awPoint $p Position of the point
|
||||
* @return Point Position on the axis
|
||||
*/
|
||||
public static function toPosition(awAxis $xAxis, awAxis $yAxis, awPoint $p) {
|
||||
|
||||
$p1 = $xAxis->getPointFromValue($p->x);
|
||||
$p2 = $yAxis->getPointFromValue($p->y);
|
||||
|
||||
return new awPoint(
|
||||
round($p1->x),
|
||||
round($p2->y)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Change title alignment
|
||||
*
|
||||
* @param int $alignment New Alignment
|
||||
*/
|
||||
public function setTitleAlignment($alignment) {
|
||||
|
||||
switch($alignment) {
|
||||
|
||||
case awLabel::TOP :
|
||||
$this->setTitlePosition(1);
|
||||
$this->title->setAlign(NULL, awLabel::BOTTOM);
|
||||
break;
|
||||
|
||||
case awLabel::BOTTOM :
|
||||
$this->setTitlePosition(0);
|
||||
$this->title->setAlign(NULL, awLabel::TOP);
|
||||
break;
|
||||
|
||||
case awLabel::LEFT :
|
||||
$this->setTitlePosition(0);
|
||||
$this->title->setAlign(awLabel::LEFT);
|
||||
break;
|
||||
|
||||
case awLabel::RIGHT :
|
||||
$this->setTitlePosition(1);
|
||||
$this->title->setAlign(awLabel::RIGHT);
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Change title position on the axis
|
||||
*
|
||||
* @param float $position A new awposition between 0 and 1
|
||||
*/
|
||||
public function setTitlePosition($position) {
|
||||
$this->titlePosition = (float)$position;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change axis and axis title color
|
||||
*
|
||||
* @param awColor $color
|
||||
*/
|
||||
public function setColor(awColor $color) {
|
||||
$this->color = $color;
|
||||
$this->title->setColor($color);
|
||||
}
|
||||
|
||||
/**
|
||||
* Change axis padding
|
||||
*
|
||||
* @param int $left Left padding in pixels
|
||||
* @param int $right Right padding in pixels
|
||||
*/
|
||||
public function setPadding($left, $right) {
|
||||
$this->padding->set($left, $right);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get axis padding
|
||||
*
|
||||
* @return Side
|
||||
*/
|
||||
public function getPadding() {
|
||||
return $this->padding;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change axis range
|
||||
*
|
||||
* @param float $min
|
||||
* @param float $max
|
||||
*/
|
||||
public function setRange($min, $max) {
|
||||
if($min !== NULL) {
|
||||
$this->range[0] = (float)$min;
|
||||
}
|
||||
if($max !== NULL) {
|
||||
$this->range[1] = (float)$max;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get axis range
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getRange() {
|
||||
return $this->range;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change axis range callback function
|
||||
*
|
||||
* @param string $toValue Transform a position between 0 and 1 to a value
|
||||
* @param string $toPosition Transform a value to a position between 0 and 1 on the axis
|
||||
*/
|
||||
public function setRangeCallback($toValue, $toPosition) {
|
||||
$this->rangeCallback = array(
|
||||
'toValue' => (string)$toValue,
|
||||
'toPosition' => (string)$toPosition
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Center X values of the axis
|
||||
*
|
||||
* @param awAxis $axis An axis
|
||||
* @param float $value The reference value on the axis
|
||||
*/
|
||||
public function setXCenter(awAxis $axis, $value) {
|
||||
|
||||
// Check vector angle
|
||||
if($this->line->isVertical() === FALSE) {
|
||||
awImage::drawError("Class Axis: setXCenter() can only be used on vertical axes.");
|
||||
}
|
||||
|
||||
$p = $axis->getPointFromValue($value);
|
||||
|
||||
$this->line->setX(
|
||||
$p->x,
|
||||
$p->x
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Center Y values of the axis
|
||||
*
|
||||
* @param awAxis $axis An axis
|
||||
* @param float $value The reference value on the axis
|
||||
*/
|
||||
public function setYCenter(awAxis $axis, $value) {
|
||||
|
||||
// Check vector angle
|
||||
if($this->line->isHorizontal() === FALSE) {
|
||||
awImage::drawError("Class Axis: setYCenter() can only be used on horizontal axes.");
|
||||
}
|
||||
|
||||
$p = $axis->getPointFromValue($value);
|
||||
|
||||
$this->line->setY(
|
||||
$p->y,
|
||||
$p->y
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the distance between to values on the axis
|
||||
*
|
||||
* @param float $from The first value
|
||||
* @param float $to The last value
|
||||
* @return Point
|
||||
*/
|
||||
public function getDistance($from, $to) {
|
||||
|
||||
$p1 = $this->getPointFromValue($from);
|
||||
$p2 = $this->getPointFromValue($to);
|
||||
|
||||
return $p1->getDistance($p2);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a point on the axis from a value
|
||||
*
|
||||
* @param float $value
|
||||
* @return Point
|
||||
*/
|
||||
protected function getPointFromValue($value) {
|
||||
|
||||
$callback = $this->rangeCallback['toPosition'];
|
||||
|
||||
list($min, $max) = $this->range;
|
||||
$position = $callback($value, $min, $max);
|
||||
|
||||
return $this->getPointFromPosition($position);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a point on the axis from a position
|
||||
*
|
||||
* @param float $position A position between 0 and 1
|
||||
* @return Point
|
||||
*/
|
||||
protected function getPointFromPosition($position) {
|
||||
|
||||
$vector = $this->getVector();
|
||||
|
||||
$angle = $vector->getAngle();
|
||||
$size = $vector->getSize();
|
||||
|
||||
return $vector->p1->move(
|
||||
cos($angle) * $size * $position,
|
||||
-1 * sin($angle) * $size * $position
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw axis
|
||||
*
|
||||
* @param awDriver $driver A driver
|
||||
*/
|
||||
public function draw(awDriver $driver) {
|
||||
|
||||
if($this->hide) {
|
||||
return;
|
||||
}
|
||||
|
||||
$vector = $this->getVector();
|
||||
|
||||
// Draw axis ticks
|
||||
$this->drawTicks($driver, $vector);
|
||||
|
||||
// Draw axis line
|
||||
$this->line($driver);
|
||||
|
||||
// Draw labels
|
||||
$this->drawLabels($driver);
|
||||
|
||||
// Draw axis title
|
||||
$p = $this->getPointFromPosition($this->titlePosition);
|
||||
$this->title->draw($driver, $p);
|
||||
|
||||
}
|
||||
|
||||
public function autoScale() {
|
||||
|
||||
if($this->isAuto() === FALSE) {
|
||||
return;
|
||||
}
|
||||
|
||||
list($min, $max) = $this->getRange();
|
||||
$interval = $max - $min;
|
||||
|
||||
if($interval > 0) {
|
||||
$partMax = $max / $interval;
|
||||
$partMin = $min / $interval;
|
||||
} else {
|
||||
$partMax = 0;
|
||||
$partMin = 0;
|
||||
}
|
||||
|
||||
$difference = log($interval) / log(10);
|
||||
$difference = floor($difference);
|
||||
|
||||
$pow = pow(10, $difference);
|
||||
|
||||
if($pow > 0) {
|
||||
$intervalNormalize = $interval / $pow;
|
||||
} else {
|
||||
$intervalNormalize = 0;
|
||||
}
|
||||
|
||||
if($difference <= 0) {
|
||||
|
||||
$precision = $difference * -1 + 1;
|
||||
|
||||
if($intervalNormalize > 2) {
|
||||
$precision--;
|
||||
}
|
||||
|
||||
} else {
|
||||
$precision = 0;
|
||||
}
|
||||
|
||||
if($min != 0 and $max != 0) {
|
||||
$precision++;
|
||||
}
|
||||
|
||||
if($this->label->getCallbackFunction() === NULL) {
|
||||
$this->setLabelPrecision($precision);
|
||||
}
|
||||
|
||||
if($intervalNormalize <= 1.5) {
|
||||
$intervalReal = 1.5;
|
||||
$labelNumber = 4;
|
||||
} else if($intervalNormalize <= 2) {
|
||||
$intervalReal = 2;
|
||||
$labelNumber = 5;
|
||||
} else if($intervalNormalize <= 3) {
|
||||
$intervalReal = 3;
|
||||
$labelNumber = 4;
|
||||
} else if($intervalNormalize <= 4) {
|
||||
$intervalReal = 4;
|
||||
$labelNumber = 5;
|
||||
} else if($intervalNormalize <= 5) {
|
||||
$intervalReal = 5;
|
||||
$labelNumber = 6;
|
||||
} else if($intervalNormalize <= 8) {
|
||||
$intervalReal = 8;
|
||||
$labelNumber = 5;
|
||||
} else if($intervalNormalize <= 10) {
|
||||
$intervalReal = 10;
|
||||
$labelNumber = 6;
|
||||
}
|
||||
|
||||
if($min == 0) {
|
||||
|
||||
$this->setRange(
|
||||
$min,
|
||||
$intervalReal * $pow
|
||||
);
|
||||
|
||||
} else if($max == 0) {
|
||||
|
||||
$this->setRange(
|
||||
$intervalReal * $pow * -1,
|
||||
0
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
$this->setLabelNumber($labelNumber);
|
||||
|
||||
}
|
||||
|
||||
protected function line(awDriver $driver) {
|
||||
|
||||
$driver->line(
|
||||
$this->color,
|
||||
$this->line
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
protected function drawTicks(awDriver $driver, awVector $vector) {
|
||||
|
||||
foreach($this->ticks as $tick) {
|
||||
$tick->setColor($this->color);
|
||||
$tick->draw($driver, $vector);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected function drawLabels($driver) {
|
||||
|
||||
if($this->labelNumber !== NULL) {
|
||||
list($min, $max) = $this->range;
|
||||
$number = $this->labelNumber - 1;
|
||||
if($number < 1) {
|
||||
return;
|
||||
}
|
||||
$function = $this->rangeCallback['toValue'];
|
||||
$labels = array();
|
||||
for($i = 0; $i <= $number; $i++) {
|
||||
$labels[] = $function($i / $number, $min, $max);
|
||||
}
|
||||
$this->label->set($labels);
|
||||
}
|
||||
|
||||
$labels = $this->label->count();
|
||||
|
||||
for($i = 0; $i < $labels; $i++) {
|
||||
|
||||
$p = $this->getPointFromValue($this->label->get($i));
|
||||
$this->label->draw($driver, $p, $i);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected function getVector() {
|
||||
|
||||
$angle = $this->line->getAngle();
|
||||
|
||||
// Compute paddings
|
||||
$vector = new awVector(
|
||||
$this->line->p1->move(
|
||||
cos($angle) * $this->padding->left,
|
||||
-1 * sin($angle) * $this->padding->left
|
||||
),
|
||||
$this->line->p2->move(
|
||||
-1 * cos($angle) * $this->padding->right,
|
||||
-1 * -1 * sin($angle) * $this->padding->right
|
||||
)
|
||||
);
|
||||
|
||||
return $vector;
|
||||
|
||||
}
|
||||
|
||||
public function __clone() {
|
||||
|
||||
$this->label = clone $this->label;
|
||||
$this->line = clone $this->line;
|
||||
$this->title = clone $this->title;
|
||||
|
||||
foreach($this->ticks as $name => $tick) {
|
||||
$this->ticks[$name] = clone $tick;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
registerClass('Axis');
|
||||
|
||||
function toProportionalValue($position, $min, $max) {
|
||||
return $min + ($max - $min) * $position;
|
||||
}
|
||||
|
||||
function toProportionalPosition($value, $min, $max) {
|
||||
if($max - $min == 0) {
|
||||
return 0;
|
||||
}
|
||||
return ($value - $min) / ($max - $min);
|
||||
}
|
||||
@@ -1,197 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* This work is hereby released into the Public Domain.
|
||||
* To view a copy of the public domain dedication,
|
||||
* visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
|
||||
* Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__)."/../Graph.class.php";
|
||||
|
||||
/**
|
||||
* Draw border
|
||||
*
|
||||
* @package Artichow
|
||||
*/
|
||||
class awBorder {
|
||||
|
||||
/**
|
||||
* Border color
|
||||
*
|
||||
* @var Color
|
||||
*/
|
||||
protected $color;
|
||||
|
||||
/**
|
||||
* Hide border ?
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $hide = FALSE;
|
||||
|
||||
/**
|
||||
* Border line style
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $style;
|
||||
|
||||
/**
|
||||
* Build the border
|
||||
*
|
||||
* @param awColor $color Border color
|
||||
* @param int $style Border style
|
||||
*/
|
||||
public function __construct($color = NULL, $style = awLine::SOLID) {
|
||||
|
||||
$this->setStyle($style);
|
||||
|
||||
if($color instanceof awColor) {
|
||||
$this->setColor($color);
|
||||
} else {
|
||||
$this->setColor(new awBlack);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Change border color
|
||||
* This method automatically shows the border if it is hidden
|
||||
*
|
||||
* @param awColor $color
|
||||
*/
|
||||
public function setColor(awColor $color) {
|
||||
$this->color = $color;
|
||||
$this->show();
|
||||
}
|
||||
|
||||
/**
|
||||
* Change border style
|
||||
*
|
||||
* @param int $style
|
||||
*/
|
||||
public function setStyle($style) {
|
||||
$this->style = (int)$style;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hide border ?
|
||||
*
|
||||
* @param bool $hide
|
||||
*/
|
||||
public function hide($hide = TRUE) {
|
||||
$this->hide = (bool)$hide;
|
||||
}
|
||||
|
||||
/**
|
||||
* Show border ?
|
||||
*
|
||||
* @param bool $show
|
||||
*/
|
||||
public function show($show = TRUE) {
|
||||
$this->hide = (bool)!$show;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the border visible ?
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function visible() {
|
||||
return !$this->hide;
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw border as a rectangle
|
||||
*
|
||||
* @param awDriver $driver
|
||||
* @param awPoint $p1 Top-left corner
|
||||
* @param awPoint $p2 Bottom-right corner
|
||||
*/
|
||||
public function rectangle(awDriver $driver, awPoint $p1, awPoint $p2) {
|
||||
|
||||
// Border is hidden
|
||||
if($this->hide) {
|
||||
return;
|
||||
}
|
||||
|
||||
$line = new awLine;
|
||||
$line->setStyle($this->style);
|
||||
$line->setLocation($p1, $p2);
|
||||
|
||||
$driver->rectangle($this->color, $line);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw border as an ellipse
|
||||
*
|
||||
* @param awDriver $driver
|
||||
* @param awPoint $center Ellipse center
|
||||
* @param int $width Ellipse width
|
||||
* @param int $height Ellipse height
|
||||
*/
|
||||
public function ellipse(awDriver $driver, awPoint $center, $width, $height) {
|
||||
|
||||
// Border is hidden
|
||||
if($this->hide) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch($this->style) {
|
||||
|
||||
case awLine::SOLID :
|
||||
$driver->ellipse($this->color, $center, $width, $height);
|
||||
break;
|
||||
|
||||
default :
|
||||
awImage::drawError("Class Border: Dashed and dotted borders and not yet implemented on ellipses.");
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw border as a polygon
|
||||
*
|
||||
* @param awDriver $driver A Driver object
|
||||
* @param awPolygon $polygon A Polygon object
|
||||
*/
|
||||
public function polygon(awDriver $driver, awPolygon $polygon) {
|
||||
|
||||
// Border is hidden
|
||||
if($this->hide) {
|
||||
return;
|
||||
}
|
||||
|
||||
$polygon->setStyle($this->style);
|
||||
$driver->polygon($this->color, $polygon);
|
||||
|
||||
// In case of Line::SOLID, Driver::polygon() uses imagepolygon()
|
||||
// which automatically closes the shape. In any other case,
|
||||
// we have to do it manually here.
|
||||
if($this->style !== Line::SOLID) {
|
||||
$this->closePolygon($driver, $polygon);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws the last line of a Polygon, between the first and last point
|
||||
*
|
||||
* @param awDriver $driver A Driver object
|
||||
* @param awPolygon $polygon The polygon object to close
|
||||
*/
|
||||
private function closePolygon(awDriver $driver, awPolygon $polygon) {
|
||||
$first = $polygon->get(0);
|
||||
$last = $polygon->get($polygon->count() - 1);
|
||||
|
||||
$line = new awLine($first, $last, $this->style, $polygon->getThickness());
|
||||
$driver->line($this->color, $line);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
registerClass('Border');
|
||||
@@ -1,165 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* This work is hereby released into the Public Domain.
|
||||
* To view a copy of the public domain dedication,
|
||||
* visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
|
||||
* Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__)."/../Graph.class.php";
|
||||
|
||||
/**
|
||||
* Create your colors
|
||||
*
|
||||
* @package Artichow
|
||||
*/
|
||||
class awColor {
|
||||
|
||||
public $red;
|
||||
public $green;
|
||||
public $blue;
|
||||
public $alpha;
|
||||
|
||||
/**
|
||||
* Build your color
|
||||
*
|
||||
* @var int $red Red intensity (from 0 to 255)
|
||||
* @var int $green Green intensity (from 0 to 255)
|
||||
* @var int $blue Blue intensity (from 0 to 255)
|
||||
* @var int $alpha Alpha channel (from 0 to 100)
|
||||
*/
|
||||
public function __construct($red, $green, $blue, $alpha = 0) {
|
||||
|
||||
$this->red = (int)$red;
|
||||
$this->green = (int)$green;
|
||||
$this->blue = (int)$blue;
|
||||
$this->alpha = (int)round($alpha * 127 / 100);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get RGB and alpha values of your color
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getColor() {
|
||||
return $this->rgba();
|
||||
}
|
||||
|
||||
/**
|
||||
* Change color brightness
|
||||
*
|
||||
* @param int $brightness Add this intensity to the color (betweeen -255 and +255)
|
||||
*/
|
||||
public function brightness($brightness) {
|
||||
|
||||
$brightness = (int)$brightness;
|
||||
|
||||
$this->red = min(255, max(0, $this->red + $brightness));
|
||||
$this->green = min(255, max(0, $this->green + $brightness));
|
||||
$this->blue = min(255, max(0, $this->blue + $brightness));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get RGB and alpha values of your color
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rgba() {
|
||||
|
||||
return array($this->red, $this->green, $this->blue, $this->alpha);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
registerClass('Color');
|
||||
|
||||
$colors = array(
|
||||
'Black' => array(0, 0, 0),
|
||||
'AlmostBlack' => array(48, 48, 48),
|
||||
'VeryDarkGray' => array(88, 88, 88),
|
||||
'DarkGray' => array(128, 128, 128),
|
||||
'MidGray' => array(160, 160, 160),
|
||||
'LightGray' => array(195, 195, 195),
|
||||
'VeryLightGray' => array(220, 220, 220),
|
||||
'White' => array(255, 255, 255),
|
||||
'VeryDarkRed' => array(64, 0, 0),
|
||||
'DarkRed' => array(128, 0, 0),
|
||||
'MidRed' => array(192, 0, 0),
|
||||
'Red' => array(255, 0, 0),
|
||||
'LightRed' => array(255, 192, 192),
|
||||
'VeryDarkGreen' => array(0, 64, 0),
|
||||
'DarkGreen' => array(0, 128, 0),
|
||||
'MidGreen' => array(0, 192, 0),
|
||||
'Green' => array(0, 255, 0),
|
||||
'LightGreen' => array(192, 255, 192),
|
||||
'VeryDarkBlue' => array(0, 0, 64),
|
||||
'DarkBlue' => array(0, 0, 128),
|
||||
'MidBlue' => array(0, 0, 192),
|
||||
'Blue' => array(0, 0, 255),
|
||||
'LightBlue' => array(192, 192, 255),
|
||||
'VeryDarkYellow' => array(64, 64, 0),
|
||||
'DarkYellow' => array(128, 128, 0),
|
||||
'MidYellow' => array(192, 192, 0),
|
||||
'Yellow' => array(255, 255, 2),
|
||||
'LightYellow' => array(255, 255, 192),
|
||||
'VeryDarkCyan' => array(0, 64, 64),
|
||||
'DarkCyan' => array(0, 128, 128),
|
||||
'MidCyan' => array(0, 192, 192),
|
||||
'Cyan' => array(0, 255, 255),
|
||||
'LightCyan' => array(192, 255, 255),
|
||||
'VeryDarkMagenta' => array(64, 0, 64),
|
||||
'DarkMagenta' => array(128, 0, 128),
|
||||
'MidMagenta' => array(192, 0, 192),
|
||||
'Magenta' => array(255, 0, 255),
|
||||
'LightMagenta' => array(255, 192, 255),
|
||||
'DarkOrange' => array(192, 88, 0),
|
||||
'Orange' => array(255, 128, 0),
|
||||
'LightOrange' => array(255, 168, 88),
|
||||
'VeryLightOrange' => array(255, 220, 168),
|
||||
'DarkPink' => array(192, 0, 88),
|
||||
'Pink' => array(255, 0, 128),
|
||||
'LightPink' => array(255, 88, 168),
|
||||
'VeryLightPink' => array(255, 168, 220),
|
||||
'DarkPurple' => array(88, 0, 192),
|
||||
'Purple' => array(128, 0, 255),
|
||||
'LightPurple' => array(168, 88, 255),
|
||||
'VeryLightPurple' => array(220, 168, 255),
|
||||
);
|
||||
|
||||
|
||||
|
||||
$php = '';
|
||||
|
||||
foreach($colors as $name => $color) {
|
||||
|
||||
list($red, $green, $blue) = $color;
|
||||
|
||||
$php .= '
|
||||
class aw'.$name.' extends awColor {
|
||||
|
||||
public function __construct($alpha = 0) {
|
||||
parent::__construct('.$red.', '.$green.', '.$blue.', $alpha);
|
||||
}
|
||||
|
||||
}
|
||||
';
|
||||
|
||||
if(ARTICHOW_PREFIX !== 'aw') {
|
||||
$php .= '
|
||||
class '.ARTICHOW_PREFIX.$name.' extends aw'.$name.' {
|
||||
|
||||
}
|
||||
';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
eval($php);
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,724 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* This work is hereby released into the Public Domain.
|
||||
* To view a copy of the public domain dedication,
|
||||
* visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
|
||||
* Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__)."/../Graph.class.php";
|
||||
|
||||
/**
|
||||
* Draw your objects
|
||||
*
|
||||
* @package Artichow
|
||||
*/
|
||||
abstract class awDriver {
|
||||
|
||||
/**
|
||||
* Image width
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $imageWidth;
|
||||
|
||||
/**
|
||||
* Image height
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $imageHeight;
|
||||
|
||||
/**
|
||||
* Driver X position
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $x;
|
||||
|
||||
/**
|
||||
* Driver Y position
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $y;
|
||||
|
||||
/**
|
||||
* Use anti-aliasing ?
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $antiAliasing = FALSE;
|
||||
|
||||
/**
|
||||
* The FontDriver object that will be used to draw text
|
||||
* with PHP fonts.
|
||||
*
|
||||
* @var awPHPFontDriver
|
||||
*/
|
||||
protected $phpFontDriver;
|
||||
|
||||
/**
|
||||
* The FontDriver object that will be used to draw text
|
||||
* with TTF or FDB fonts.
|
||||
*
|
||||
* @var awFileFontDriver
|
||||
*/
|
||||
protected $fileFontDriver;
|
||||
|
||||
/**
|
||||
* A string representing the type of the driver
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $driverString;
|
||||
|
||||
private $w;
|
||||
private $h;
|
||||
|
||||
public function __construct() {
|
||||
$this->phpFontDriver = new awPHPFontDriver();
|
||||
$this->fileFontDriver = new awFileFontDriver();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the driver for a particular awImage object
|
||||
*
|
||||
* @param awImage $image
|
||||
*/
|
||||
abstract public function init(awImage $image);
|
||||
|
||||
/**
|
||||
* Initialize the Driver for a particular FileImage object
|
||||
*
|
||||
* @param awFileImage $fileImage The FileImage object to work on
|
||||
* @param string $file Image filename
|
||||
*/
|
||||
abstract public function initFromFile(awFileImage $fileImage, $file);
|
||||
|
||||
/**
|
||||
* Change the image size
|
||||
*
|
||||
* @param int $width Image width
|
||||
* @param int $height Image height
|
||||
*/
|
||||
abstract public function setImageSize($width, $height);
|
||||
|
||||
/**
|
||||
* Inform the driver of the position of your image
|
||||
*
|
||||
* @param float $x Position on X axis of the center of the component
|
||||
* @param float $y Position on Y axis of the center of the component
|
||||
*/
|
||||
abstract public function setPosition($x, $y);
|
||||
|
||||
/**
|
||||
* Inform the driver of the position of your image
|
||||
* This method need absolutes values
|
||||
*
|
||||
* @param int $x Left-top corner X position
|
||||
* @param int $y Left-top corner Y position
|
||||
*/
|
||||
abstract public function setAbsPosition($x, $y);
|
||||
|
||||
/**
|
||||
* Move the position of the image
|
||||
*
|
||||
* @param int $x Add this value to X axis
|
||||
* @param int $y Add this value to Y axis
|
||||
*/
|
||||
abstract public function movePosition($x, $y);
|
||||
|
||||
/**
|
||||
* Inform the driver of the size of your image
|
||||
* Height and width must be between 0 and 1.
|
||||
*
|
||||
* @param int $w Image width
|
||||
* @param int $h Image height
|
||||
* @return array Absolute width and height of the image
|
||||
*/
|
||||
abstract public function setSize($w, $h);
|
||||
|
||||
/**
|
||||
* Inform the driver of the size of your image
|
||||
* You can set absolute size with this method.
|
||||
*
|
||||
* @param int $w Image width
|
||||
* @param int $h Image height
|
||||
*/
|
||||
abstract public function setAbsSize($w, $h);
|
||||
|
||||
/**
|
||||
* Get the size of the component handled by the driver
|
||||
*
|
||||
* @return array Absolute width and height of the component
|
||||
*/
|
||||
abstract public function getSize();
|
||||
|
||||
/**
|
||||
* Turn antialiasing on or off
|
||||
*
|
||||
* @var bool $bool
|
||||
*/
|
||||
abstract public function setAntiAliasing($bool);
|
||||
|
||||
/**
|
||||
* When passed a Color object, returns the corresponding
|
||||
* color identifier (driver dependant).
|
||||
*
|
||||
* @param awColor $color A Color object
|
||||
* @return int $rgb A color identifier representing the color composed of the given RGB components
|
||||
*/
|
||||
abstract public function getColor(awColor $color);
|
||||
|
||||
/**
|
||||
* Draw an image here
|
||||
*
|
||||
* @param awImage $image Image
|
||||
* @param int $p1 Image top-left point
|
||||
* @param int $p2 Image bottom-right point
|
||||
*/
|
||||
abstract public function copyImage(awImage $image, awPoint $p1, awPoint $p2);
|
||||
|
||||
/**
|
||||
* Draw an image here
|
||||
*
|
||||
* @param awImage $image Image
|
||||
* @param int $d1 Destination top-left position
|
||||
* @param int $d2 Destination bottom-right position
|
||||
* @param int $s1 Source top-left position
|
||||
* @param int $s2 Source bottom-right position
|
||||
* @param bool $resample Resample image ? (default to TRUE)
|
||||
*/
|
||||
abstract public function copyResizeImage(awImage $image, awPoint $d1, awPoint $d2, awPoint $s1, awPoint $s2, $resample = TRUE);
|
||||
|
||||
/**
|
||||
* Draw a string
|
||||
*
|
||||
* @var awText $text Text to print
|
||||
* @param awPoint $point Draw the text at this point
|
||||
* @param int $width Text max width
|
||||
*/
|
||||
abstract public function string(awText $text, awPoint $point, $width = NULL);
|
||||
|
||||
/**
|
||||
* Draw a pixel
|
||||
*
|
||||
* @param awColor $color Pixel color
|
||||
* @param awPoint $p
|
||||
*/
|
||||
abstract public function point(awColor $color, awPoint $p);
|
||||
|
||||
/**
|
||||
* Draw a colored line
|
||||
*
|
||||
* @param awColor $color Line color
|
||||
* @param awLine $line
|
||||
* @param int $thickness Line tickness
|
||||
*/
|
||||
abstract public function line(awColor $color, awLine $line);
|
||||
|
||||
/**
|
||||
* Draw a color arc
|
||||
|
||||
* @param awColor $color Arc color
|
||||
* @param awPoint $center Point center
|
||||
* @param int $width Ellipse width
|
||||
* @param int $height Ellipse height
|
||||
* @param int $from Start angle
|
||||
* @param int $to End angle
|
||||
*/
|
||||
abstract public function arc(awColor $color, awPoint $center, $width, $height, $from, $to);
|
||||
|
||||
/**
|
||||
* Draw an arc with a background color
|
||||
*
|
||||
* @param awColor $color Arc background color
|
||||
* @param awPoint $center Point center
|
||||
* @param int $width Ellipse width
|
||||
* @param int $height Ellipse height
|
||||
* @param int $from Start angle
|
||||
* @param int $to End angle
|
||||
*/
|
||||
abstract public function filledArc(awColor $color, awPoint $center, $width, $height, $from, $to);
|
||||
|
||||
/**
|
||||
* Draw a colored ellipse
|
||||
*
|
||||
* @param awColor $color Ellipse color
|
||||
* @param awPoint $center Ellipse center
|
||||
* @param int $width Ellipse width
|
||||
* @param int $height Ellipse height
|
||||
*/
|
||||
abstract public function ellipse(awColor $color, awPoint $center, $width, $height);
|
||||
|
||||
/**
|
||||
* Draw an ellipse with a background
|
||||
*
|
||||
* @param mixed $background Background (can be a color or a gradient)
|
||||
* @param awPoint $center Ellipse center
|
||||
* @param int $width Ellipse width
|
||||
* @param int $height Ellipse height
|
||||
*/
|
||||
abstract public function filledEllipse($background, awPoint $center, $width, $height);
|
||||
|
||||
/**
|
||||
* Draw a colored rectangle
|
||||
*
|
||||
* @param awColor $color Rectangle color
|
||||
* @param awLine $line Rectangle diagonale
|
||||
* @param awPoint $p2
|
||||
*/
|
||||
abstract public function rectangle(awColor $color, awLine $line);
|
||||
|
||||
/**
|
||||
* Draw a rectangle with a background
|
||||
*
|
||||
* @param mixed $background Background (can be a color or a gradient)
|
||||
* @param awLine $line Rectangle diagonale
|
||||
*/
|
||||
abstract public function filledRectangle($background, awLine $line);
|
||||
|
||||
/**
|
||||
* Draw a polygon
|
||||
*
|
||||
* @param awColor $color Polygon color
|
||||
* @param Polygon A polygon
|
||||
*/
|
||||
abstract public function polygon(awColor $color, awPolygon $polygon);
|
||||
|
||||
/**
|
||||
* Draw a polygon with a background
|
||||
*
|
||||
* @param mixed $background Background (can be a color or a gradient)
|
||||
* @param Polygon A polygon
|
||||
*/
|
||||
abstract public function filledPolygon($background, awPolygon $polygon);
|
||||
|
||||
/**
|
||||
* Sends the image, as well as the correct HTTP headers, to the browser
|
||||
*
|
||||
* @param awImage $image The Image object to send
|
||||
*/
|
||||
abstract public function send(awImage $image);
|
||||
|
||||
/**
|
||||
* Get the image as binary data
|
||||
*
|
||||
* @param awImage $image
|
||||
*/
|
||||
abstract public function get(awImage $image);
|
||||
|
||||
/**
|
||||
* Return the width of some text
|
||||
*
|
||||
* @param awText $text
|
||||
*/
|
||||
abstract public function getTextWidth(awText $text);
|
||||
|
||||
/**
|
||||
* Return the height of some text
|
||||
*
|
||||
* @param awText $text
|
||||
*/
|
||||
abstract public function getTextHeight(awText $text);
|
||||
|
||||
/**
|
||||
* Return the string representing the type of driver
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDriverString() {
|
||||
return $this->driverString;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether or not the driver is compatible with the given font type
|
||||
*
|
||||
* @param awFont $font
|
||||
* @return bool
|
||||
*/
|
||||
abstract protected function isCompatibleWithFont(awFont $font);
|
||||
|
||||
// abstract private function drawImage(awImage $image, $return = FALSE, $header = TRUE);
|
||||
|
||||
}
|
||||
|
||||
registerClass('Driver', TRUE);
|
||||
|
||||
/**
|
||||
* Abstract class for font drivers.
|
||||
* Those are used to do all the grunt work on fonts.
|
||||
*
|
||||
* @package Artichow
|
||||
*/
|
||||
|
||||
abstract class awFontDriver {
|
||||
|
||||
public function __construct() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw the actual text.
|
||||
*
|
||||
* @param awDriver $driver The Driver object to draw upon
|
||||
* @param awText $text The Text object
|
||||
* @param awPoint $point Where to draw the text
|
||||
* @param float $width The width of the area containing the text
|
||||
*/
|
||||
abstract public function string(awDriver $driver, awText $text, awPoint $point, $width = NULL);
|
||||
|
||||
/**
|
||||
* Calculate the width of a given Text.
|
||||
*
|
||||
* @param awText $text The Text object
|
||||
* @param awDriver $driver The awDriver object used to draw the graph
|
||||
*/
|
||||
abstract public function getTextWidth(awText $text, awDriver $driver);
|
||||
|
||||
/**
|
||||
* Calculate the height of a given Text.
|
||||
*
|
||||
* @param awText $text The Text object
|
||||
* @param awDriver $driver The awDriver object used to draw the graph
|
||||
*/
|
||||
abstract public function getTextHeight(awText $text, awDriver $driver);
|
||||
|
||||
}
|
||||
|
||||
registerClass('FontDriver', TRUE);
|
||||
|
||||
/**
|
||||
* Class to handle calculations on PHPFont objects
|
||||
*
|
||||
* @package Artichow
|
||||
*/
|
||||
class awPHPFontDriver extends awFontDriver {
|
||||
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function string(awDriver $driver, awText $text, awPoint $point, $width = NULL) {
|
||||
|
||||
switch ($driver->getDriverString()) {
|
||||
case 'gd':
|
||||
$this->gdString($driver, $text, $point, $width);
|
||||
break;
|
||||
|
||||
default:
|
||||
awImage::drawError('Class PHPFontDriver: Incompatibility between driver and font - You should never see this error message: have you called awDriver::isCompatibleWithFont() properly?');
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw a string onto a GDDriver object
|
||||
*
|
||||
* @param awGDDriver $driver The GDDriver to draw the text upon
|
||||
* @param awText $text The awText object containing the string to draw
|
||||
* @param awPoint $point Where to draw the text
|
||||
* @param float $width The width of the text
|
||||
*/
|
||||
private function gdString(awGDDriver $driver, awText $text, awPoint $point, $width = NULL) {
|
||||
|
||||
$angle = $text->getAngle();
|
||||
if($angle !== 90 and $angle !== 0) {
|
||||
awImage::drawError("Class PHPFontDriver: You can only use 0° and 90° angles.");
|
||||
}
|
||||
|
||||
if($angle === 90) {
|
||||
$function = 'imagestringup';
|
||||
$addAngle = $this->getGDTextHeight($text);
|
||||
} else {
|
||||
$function = 'imagestring';
|
||||
$addAngle = 0;
|
||||
}
|
||||
|
||||
$color = $text->getColor();
|
||||
$rgb = $driver->getColor($color);
|
||||
|
||||
$textString = $text->getText();
|
||||
$textString = str_replace("\r", "", $textString);
|
||||
|
||||
$textHeight = $this->getGDTextHeight($text);
|
||||
|
||||
// Split text if needed
|
||||
if($width !== NULL) {
|
||||
|
||||
$characters = floor($width / ($this->getGDTextWidth($text) / strlen($textString)));
|
||||
|
||||
if($characters > 0) {
|
||||
$textString = wordwrap($textString, $characters, "\n", TRUE);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$font = $text->getFont();
|
||||
$lines = explode("\n", $textString);
|
||||
|
||||
foreach($lines as $i => $line) {
|
||||
|
||||
// Line position handling
|
||||
if($angle === 90) {
|
||||
$addX = $i * $textHeight;
|
||||
$addY = 0;
|
||||
} else {
|
||||
$addX = 0;
|
||||
$addY = $i * $textHeight;
|
||||
}
|
||||
|
||||
$function(
|
||||
$driver->resource,
|
||||
$font->font,
|
||||
$driver->x + $point->x + $addX,
|
||||
$driver->y + $point->y + $addY + $addAngle,
|
||||
$line,
|
||||
$rgb
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public function getTextWidth(awText $text, awDriver $driver) {
|
||||
|
||||
switch ($driver->getDriverString()) {
|
||||
case 'gd':
|
||||
return $this->getGDTextWidth($text);
|
||||
|
||||
default:
|
||||
awImage::drawError('Class PHPFontDriver: Cannot get text width - incompatibility between driver and font');
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function getTextHeight(awText $text, awDriver $driver) {
|
||||
|
||||
switch ($driver->getDriverString()) {
|
||||
case 'gd':
|
||||
return $this->getGDTextHeight($text);
|
||||
|
||||
default:
|
||||
awImage::drawError('Class PHPFontDriver: Cannot get text height - incompatibility between driver and font');
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the width of a text for a GDDriver
|
||||
*
|
||||
* @param awText $text
|
||||
* @return int $fontWidth
|
||||
*/
|
||||
private function getGDTextWidth(awText $text) {
|
||||
$font = $text->getFont();
|
||||
|
||||
if($text->getAngle() === 90) {
|
||||
$text->setAngle(45);
|
||||
return $this->getGDTextHeight($text);
|
||||
} else if($text->getAngle() === 45) {
|
||||
$text->setAngle(90);
|
||||
}
|
||||
|
||||
$fontWidth = imagefontwidth($font->font);
|
||||
|
||||
if($fontWidth === FALSE) {
|
||||
awImage::drawError("Class PHPFontDriver: Unable to get font size.");
|
||||
}
|
||||
|
||||
return (int)$fontWidth * strlen($text->getText());
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the height of a text for a GDDriver
|
||||
*
|
||||
* @param awText $text
|
||||
* @return int $fontHeight
|
||||
*/
|
||||
private function getGDTextHeight(awText $text) {
|
||||
$font = $text->getFont();
|
||||
|
||||
if($text->getAngle() === 90) {
|
||||
$text->setAngle(45);
|
||||
return $this->getGDTextWidth($text);
|
||||
} else if($text->getAngle() === 45) {
|
||||
$text->setAngle(90);
|
||||
}
|
||||
|
||||
$fontHeight = imagefontheight($font->font);
|
||||
|
||||
if($fontHeight === FALSE) {
|
||||
awImage::drawError("Class PHPFontDriver: Unable to get font size.");
|
||||
}
|
||||
|
||||
return (int)$fontHeight;
|
||||
}
|
||||
}
|
||||
|
||||
registerClass('PHPFontDriver');
|
||||
|
||||
/**
|
||||
* Class to handle calculations on FileFont objects
|
||||
*
|
||||
* @package Artichow
|
||||
*/
|
||||
class awFileFontDriver extends awFontDriver {
|
||||
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function string(awDriver $driver, awText $text, awPoint $point, $width = NULL) {
|
||||
|
||||
switch ($driver->getDriverString()) {
|
||||
case 'gd':
|
||||
$this->gdString($driver, $text, $point, $width);
|
||||
break;
|
||||
|
||||
default:
|
||||
awImage::drawError('Class fileFontDriver: Incompatibility between driver and font - You should never see this error message: have you called awDriver::isCompatibleWithFont() properly?');
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw an awFileFont object on a GD ressource
|
||||
*
|
||||
* @param awGDDriver $driver The awGDDriver object containing the ressource to draw upon
|
||||
* @param awText $text The awText object containing the string to draw
|
||||
* @param awPoint $point Where to draw the string from
|
||||
* @param float $width The width of the area containing the text
|
||||
*/
|
||||
private function gdString(awGDDriver $driver, awText $text, awPoint $point, $width = NULL) {
|
||||
// Make easier font positionment
|
||||
$text->setText($text->getText()." ");
|
||||
|
||||
$font = $text->getFont();
|
||||
if($font instanceof awTTFFont === FALSE and $font->getExtension() === NULL) {
|
||||
$font->setExtension('ttf');
|
||||
}
|
||||
|
||||
$filePath = $font->getName().'.'.$font->getExtension();
|
||||
|
||||
$box = imagettfbbox($font->getSize(), $text->getAngle(), $filePath, $text->getText());
|
||||
$textHeight = - $box[5];
|
||||
|
||||
$box = imagettfbbox($font->getSize(), 90, $filePath, $text->getText());
|
||||
$textWidth = abs($box[6] - $box[2]);
|
||||
|
||||
// Restore old text
|
||||
$text->setText(substr($text->getText(), 0, strlen($text->getText()) - 1));
|
||||
|
||||
$textString = $text->getText();
|
||||
|
||||
// Split text if needed
|
||||
if($width !== NULL) {
|
||||
|
||||
$characters = floor($width / $this->getGDAverageWidth($font));
|
||||
$textString = wordwrap($textString, $characters, "\n", TRUE);
|
||||
|
||||
}
|
||||
|
||||
$color = $text->getColor();
|
||||
$rgb = $driver->getColor($color);
|
||||
|
||||
imagettftext(
|
||||
$driver->resource,
|
||||
$font->getSize(),
|
||||
$text->getAngle(),
|
||||
$driver->x + $point->x + $textWidth * sin($text->getAngle() / 180 * M_PI),
|
||||
$driver->y + $point->y + $textHeight,
|
||||
$rgb,
|
||||
$filePath,
|
||||
$textString
|
||||
);
|
||||
}
|
||||
|
||||
public function getTextWidth(awText $text, awDriver $driver) {
|
||||
switch ($driver->getDriverString()) {
|
||||
case 'gd':
|
||||
return $this->getGDTextWidth($text);
|
||||
|
||||
default:
|
||||
awImage::drawError('Class FileFontDriver: Cannot get text width - incompatibility between driver and font');
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public function getTextHeight(awText $text, awDriver $driver) {
|
||||
switch ($driver->getDriverString()) {
|
||||
case 'gd':
|
||||
return $this->getGDTextHeight($text);
|
||||
|
||||
default:
|
||||
awImage::drawError('Class FileFontDriver: Cannot get text height - incompatibility between driver and font');
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private function getGDTextWidth(awText $text) {
|
||||
$font = $text->getFont();
|
||||
if($font->getExtension() === NULL) {
|
||||
$font->setExtension('ttf');
|
||||
}
|
||||
|
||||
$filePath = $font->getName().'.'.$font->getExtension();
|
||||
|
||||
$box = imagettfbbox($font->getSize(), $text->getAngle(), $filePath, $text->getText());
|
||||
|
||||
if($box === FALSE) {
|
||||
awImage::drawError("Class FileFontDriver: Unable to get font width (GD).");
|
||||
}
|
||||
|
||||
list(, , $x2, , , , $x1, ) = $box;
|
||||
|
||||
return abs($x2 - $x1);
|
||||
}
|
||||
|
||||
private function getGDTextHeight(awText $text) {
|
||||
$font = $text->getFont();
|
||||
if($font->getExtension() === NULL) {
|
||||
$font->setExtension('ttf');
|
||||
}
|
||||
|
||||
$filePath = $font->getName().'.'.$font->getExtension();
|
||||
|
||||
$box = imagettfbbox($font->getSize(), $text->getAngle(), $filePath, $text->getText());
|
||||
|
||||
if($box === FALSE) {
|
||||
awImage::drawError("Class FileFontDriver: Unable to get font height (GD).");
|
||||
}
|
||||
|
||||
list(, , , $y2, , , , $y1) = $box;
|
||||
|
||||
return abs($y2 - $y1);
|
||||
}
|
||||
|
||||
private function getGDAverageWidth(awFileFont $font) {
|
||||
|
||||
$text = "azertyuiopqsdfghjklmmmmmmmwxcvbbbn,;:!?.";
|
||||
|
||||
$box = imagettfbbox($font->getSize(), 0, $font->getName().'.'.$font->getExtension(), $text);
|
||||
|
||||
if($box === FALSE) {
|
||||
awImage::drawError("Class FileFontDriver: Unable to get font average width.");
|
||||
}
|
||||
|
||||
list(, , $x2, $y2, , , $x1, $y1) = $box;
|
||||
|
||||
return abs($x2 - $x1) / strlen($text);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
registerClass('FileFontDriver');
|
||||
|
||||
// Include ARTICHOW_DRIVER by default to preserve backward compatibility.
|
||||
require_once dirname(__FILE__).'/drivers/'.ARTICHOW_DRIVER.'.class.php';
|
||||
|
||||
@@ -1,262 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* This work is hereby released into the Public Domain.
|
||||
* To view a copy of the public domain dedication,
|
||||
* visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
|
||||
* Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__)."/../Graph.class.php";
|
||||
|
||||
/**
|
||||
* Common font characteristics and methods.
|
||||
* Declared abstract only so that it can't be instanciated.
|
||||
* Users have to call 'new awPHPFont' or 'new awFileFont',
|
||||
* or any of their inherited classes (awFont1, awTuffy, awTTFFont, etc.)
|
||||
*
|
||||
* @package Artichow
|
||||
*/
|
||||
abstract class awFont {
|
||||
|
||||
/**
|
||||
* Build the font
|
||||
*
|
||||
*/
|
||||
public function __construct() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw a text
|
||||
*
|
||||
* @param awDriver $driver
|
||||
* @param awPoint $p Draw text at this point
|
||||
* @param awText $text The text
|
||||
* @param int $width Text box width
|
||||
*/
|
||||
public function draw(awDriver $driver, awPoint $point, awText $text, $width = NULL) {
|
||||
|
||||
$driver->string($this, $text, $point, $width);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
registerClass('Font', TRUE);
|
||||
|
||||
/**
|
||||
* Class for fonts that cannot be transformed,
|
||||
* like the built-in PHP fonts for example.
|
||||
*
|
||||
* @package Artichow
|
||||
*/
|
||||
class awPHPFont extends awFont {
|
||||
|
||||
/**
|
||||
* The used font identifier
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $font;
|
||||
|
||||
public function __construct($font = NULL) {
|
||||
parent::__construct();
|
||||
|
||||
if($font !== NULL) {
|
||||
$this->font = (int)$font;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
registerClass('PHPFont');
|
||||
|
||||
/**
|
||||
* Class for fonts that can be transformed (rotated, skewed, etc.),
|
||||
* like TTF or FDB fonts for example.
|
||||
*
|
||||
* @package Artichow
|
||||
*/
|
||||
class awFileFont extends awFont {
|
||||
|
||||
/**
|
||||
* The name of the font, without the extension
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name;
|
||||
|
||||
/**
|
||||
* The size of the font
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $size;
|
||||
|
||||
/**
|
||||
* The font filename extension
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $extension;
|
||||
|
||||
public function __construct($name, $size) {
|
||||
parent::__construct();
|
||||
|
||||
$this->setName($name);
|
||||
$this->setSize($size);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the name of the font. The $name variable can contain the full path,
|
||||
* or just the filename. Artichow will try to do The Right Thing,
|
||||
* as well as set the extension property correctly if possible.
|
||||
*
|
||||
* @param string $name
|
||||
*/
|
||||
public function setName($name) {
|
||||
$fontInfo = pathinfo((string)$name);
|
||||
|
||||
if(strpos($fontInfo['dirname'], '/') !== 0) {
|
||||
// Path is not absolute, use ARTICHOW_FONT
|
||||
$name = ARTICHOW_FONT.DIRECTORY_SEPARATOR.$fontInfo['basename'];
|
||||
$fontInfo = pathinfo($name);
|
||||
}
|
||||
|
||||
$this->name = $fontInfo['dirname'].DIRECTORY_SEPARATOR.$fontInfo['basename'];
|
||||
|
||||
if(array_key_exists('extension', $fontInfo) and $fontInfo['extension'] !== '') {
|
||||
$this->setExtension($fontInfo['extension']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the name of the font, i.e. the absolute path and the filename, without the extension.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getName() {
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the size of the font, in pixels
|
||||
*
|
||||
* @param int $size
|
||||
*/
|
||||
public function setSize($size) {
|
||||
$this->size = (int)$size;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the size of the font, in pixels
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getSize() {
|
||||
return $this->size;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the extension, without the dot
|
||||
*
|
||||
* @param string $extension
|
||||
*/
|
||||
public function setExtension($extension) {
|
||||
$this->extension = (string)$extension;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the filename extension for that font
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getExtension() {
|
||||
return $this->extension;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
registerClass('FileFont');
|
||||
|
||||
/**
|
||||
* Class representing TTF fonts
|
||||
*
|
||||
* @package Artichow
|
||||
*/
|
||||
class awTTFFont extends awFileFont {
|
||||
|
||||
public function __construct($name, $size) {
|
||||
parent::__construct($name, $size);
|
||||
|
||||
if($this->getExtension() === NULL) {
|
||||
$this->setExtension('ttf');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
registerClass('TTFFont');
|
||||
|
||||
|
||||
|
||||
$php = '';
|
||||
|
||||
for($i = 1; $i <= 5; $i++) {
|
||||
|
||||
$php .= '
|
||||
class awFont'.$i.' extends awPHPFont {
|
||||
|
||||
public function __construct() {
|
||||
parent::__construct('.$i.');
|
||||
}
|
||||
|
||||
}
|
||||
';
|
||||
|
||||
if(ARTICHOW_PREFIX !== 'aw') {
|
||||
$php .= '
|
||||
class '.ARTICHOW_PREFIX.'Font'.$i.' extends awFont'.$i.' {
|
||||
}
|
||||
';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
eval($php);
|
||||
|
||||
$php = '';
|
||||
|
||||
foreach($fonts as $font) {
|
||||
|
||||
$php .= '
|
||||
class aw'.$font.' extends awFileFont {
|
||||
|
||||
public function __construct($size) {
|
||||
parent::__construct(\''.$font.'\', $size);
|
||||
}
|
||||
|
||||
}
|
||||
';
|
||||
|
||||
if(ARTICHOW_PREFIX !== 'aw') {
|
||||
$php .= '
|
||||
class '.ARTICHOW_PREFIX.$font.' extends aw'.$font.' {
|
||||
}
|
||||
';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
eval($php);
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Environment modification for GD2 and TTF fonts
|
||||
*/
|
||||
if(function_exists('putenv')) {
|
||||
putenv('GDFONTPATH='.ARTICHOW_FONT);
|
||||
}
|
||||
|
||||
@@ -1,135 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* This work is hereby released into the Public Domain.
|
||||
* To view a copy of the public domain dedication,
|
||||
* visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
|
||||
* Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
require_once dirname(__FILE__)."/../Graph.class.php";
|
||||
|
||||
|
||||
/**
|
||||
* Create your gradients
|
||||
*
|
||||
* @package Artichow
|
||||
*/
|
||||
abstract class awGradient {
|
||||
|
||||
/**
|
||||
* From color
|
||||
*
|
||||
* @var Color
|
||||
*/
|
||||
public $from;
|
||||
|
||||
/**
|
||||
* To color
|
||||
*
|
||||
* @var Color
|
||||
*/
|
||||
public $to;
|
||||
|
||||
/**
|
||||
* Build the gradient
|
||||
*
|
||||
* @param awColor $from From color
|
||||
* @param awColor $to To color
|
||||
*/
|
||||
public function __construct(awColor $from, awColor $to) {
|
||||
|
||||
$this->from = $from;
|
||||
$this->to = $to;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
registerClass('Gradient', TRUE);
|
||||
|
||||
|
||||
/**
|
||||
* Create a linear gradient
|
||||
*
|
||||
* @package Artichow
|
||||
*/
|
||||
class awLinearGradient extends awGradient {
|
||||
|
||||
/**
|
||||
* Gradient angle
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $angle;
|
||||
|
||||
/**
|
||||
* Build the linear gradient
|
||||
*
|
||||
* @param awColor $from From color
|
||||
* @param awColor $to To color
|
||||
* @param int $angle Gradient angle
|
||||
*/
|
||||
public function __construct($from, $to, $angle) {
|
||||
|
||||
parent::__construct(
|
||||
$from, $to
|
||||
);
|
||||
|
||||
$this->angle = (int)$angle;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
registerClass('LinearGradient');
|
||||
|
||||
|
||||
/**
|
||||
* Create a bilinear gradient
|
||||
*
|
||||
* @package Artichow
|
||||
*/
|
||||
class awBilinearGradient extends awLinearGradient {
|
||||
|
||||
/**
|
||||
* Gradient center
|
||||
*
|
||||
* @var float Center between 0 and 1
|
||||
*/
|
||||
public $center;
|
||||
|
||||
/**
|
||||
* Build the bilinear gradient
|
||||
*
|
||||
* @param awColor $from From color
|
||||
* @param awColor $to To color
|
||||
* @param int $angle Gradient angle
|
||||
* @param int $center Gradient center
|
||||
*/
|
||||
public function __construct($from, $to, $angle, $center = 0.5) {
|
||||
|
||||
parent::__construct(
|
||||
$from, $to, $angle
|
||||
);
|
||||
|
||||
$this->center = (float)$center;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
registerClass('BilinearGradient');
|
||||
|
||||
/**
|
||||
* Create a radial gradient
|
||||
*
|
||||
* @package Artichow
|
||||
*/
|
||||
class awRadialGradient extends awGradient {
|
||||
|
||||
}
|
||||
|
||||
registerClass('RadialGradient');
|
||||
|
||||
@@ -1,290 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* This work is hereby released into the Public Domain.
|
||||
* To view a copy of the public domain dedication,
|
||||
* visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
|
||||
* Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__)."/../Graph.class.php";
|
||||
|
||||
/**
|
||||
* Grid
|
||||
*
|
||||
* @package Artichow
|
||||
*/
|
||||
class awGrid {
|
||||
|
||||
/**
|
||||
* Vertical lines of the grid
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $xgrid = array();
|
||||
|
||||
/**
|
||||
* Horizontal lines of the grid
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $ygrid = array();
|
||||
|
||||
/**
|
||||
* Is the component grid hidden ?
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
private $hide = FALSE;
|
||||
|
||||
/**
|
||||
* Are horizontal lines hidden ?
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
private $hideHorizontal = FALSE;
|
||||
|
||||
/**
|
||||
* Are vertical lines hidden ?
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
private $hideVertical = FALSE;
|
||||
|
||||
/**
|
||||
* Grid color
|
||||
*
|
||||
* @var Color
|
||||
*/
|
||||
private $color;
|
||||
|
||||
/**
|
||||
* Grid space
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $space;
|
||||
|
||||
/**
|
||||
* Line type
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $type = awLine::SOLID;
|
||||
|
||||
/**
|
||||
* Grid interval
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $interval = array(1, 1);
|
||||
|
||||
/**
|
||||
* Grid background color
|
||||
*
|
||||
* @var Color
|
||||
*/
|
||||
private $background;
|
||||
|
||||
/**
|
||||
* Build the factory
|
||||
*/
|
||||
public function __construct() {
|
||||
|
||||
// Set a grid default color
|
||||
$this->color = new awColor(210, 210, 210);
|
||||
$this->background = new awColor(255, 255, 255, 100);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Hide grid ?
|
||||
*
|
||||
* @param bool $hide
|
||||
*/
|
||||
public function hide($hide = TRUE) {
|
||||
$this->hide = (bool)$hide;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hide horizontal lines ?
|
||||
*
|
||||
* @param bool $hideHorizontal
|
||||
*/
|
||||
public function hideHorizontal($hide = TRUE) {
|
||||
$this->hideHorizontal = (bool)$hide;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hide vertical lines ?
|
||||
*
|
||||
* @param bool $hideVertical
|
||||
*/
|
||||
public function hideVertical($hide = TRUE) {
|
||||
$this->hideVertical = (bool)$hide;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change grid color
|
||||
*
|
||||
* @param awColor $color
|
||||
*/
|
||||
public function setColor(awColor $color) {
|
||||
$this->color = $color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove grid background
|
||||
*/
|
||||
public function setNoBackground() {
|
||||
$this->background = NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change grid background color
|
||||
*
|
||||
* @param awColor $color
|
||||
*/
|
||||
public function setBackgroundColor(awColor $color) {
|
||||
$this->background = $color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change line type
|
||||
*
|
||||
* @param int $type
|
||||
*/
|
||||
public function setType($type) {
|
||||
$this->type = (int)$type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change grid interval
|
||||
*
|
||||
* @param int $hInterval
|
||||
* @param int $vInterval
|
||||
*/
|
||||
public function setInterval($hInterval, $vInterval) {
|
||||
$this->interval = array((int)$hInterval, (int)$vInterval);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set grid space
|
||||
*
|
||||
* @param int $left Left space in pixels
|
||||
* @param int $right Right space in pixels
|
||||
* @param int $top Top space in pixels
|
||||
* @param int $bottom Bottom space in pixels
|
||||
*/
|
||||
public function setSpace($left, $right, $top, $bottom) {
|
||||
$this->space = array((int)$left, (int)$right, (int)$top, (int)$bottom);
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the current grid
|
||||
*
|
||||
* @param array $xgrid Vertical lines
|
||||
* @param array $ygrid Horizontal lines
|
||||
*/
|
||||
public function setGrid($xgrid, $ygrid) {
|
||||
|
||||
if(empty($this->xgrid)) {
|
||||
$this->xgrid = $xgrid;
|
||||
}
|
||||
if(empty($this->ygrid)) {
|
||||
$this->ygrid = $ygrid;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw grids
|
||||
*
|
||||
* @param awDriver $driver A driver object
|
||||
* @param int $x1
|
||||
* @param int $y1
|
||||
* @param int $x2
|
||||
* @param int $y2
|
||||
*/
|
||||
public function draw(awDriver $driver, $x1, $y1, $x2, $y2) {
|
||||
|
||||
if($this->background instanceof awColor) {
|
||||
|
||||
// Draw background color
|
||||
$driver->filledRectangle(
|
||||
$this->background,
|
||||
awLine::build($x1, $y1, $x2, $y2)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
if($this->hide === FALSE) {
|
||||
|
||||
$this->drawGrid(
|
||||
$driver,
|
||||
$this->color,
|
||||
$this->hideVertical ? array() : $this->xgrid,
|
||||
$this->hideHorizontal ? array() : $this->ygrid,
|
||||
$x1, $y1, $x2, $y2,
|
||||
$this->type,
|
||||
$this->space,
|
||||
$this->interval[0],
|
||||
$this->interval[1]
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private function drawGrid(
|
||||
awDriver $driver, awColor $color,
|
||||
$nx, $ny, $x1, $y1, $x2, $y2,
|
||||
$type, $space, $hInterval, $vInterval
|
||||
) {
|
||||
|
||||
list($left, $right, $top, $bottom) = $space;
|
||||
|
||||
$width = $x2 - $x1 - $left - $right;
|
||||
$height = $y2 - $y1 - $top - $bottom;
|
||||
|
||||
foreach($nx as $key => $n) {
|
||||
|
||||
if(($key % $vInterval) === 0) {
|
||||
|
||||
$pos = (int)round($x1 + $left + $n * $width);
|
||||
$driver->line(
|
||||
$color,
|
||||
new awLine(
|
||||
new awPoint($pos, $y1),
|
||||
new awPoint($pos, $y2),
|
||||
$type
|
||||
)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
foreach($ny as $key => $n) {
|
||||
|
||||
if(($key % $hInterval) === 0) {
|
||||
|
||||
$pos = (int)round($y1 + $top + $n * $height);
|
||||
$driver->line(
|
||||
$color,
|
||||
new awLine(
|
||||
new awPoint($x1, $pos),
|
||||
new awPoint($x2, $pos),
|
||||
$type
|
||||
)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
registerClass('Grid');
|
||||
@@ -1,587 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* This work is hereby released into the Public Domain.
|
||||
* To view a copy of the public domain dedication,
|
||||
* visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
|
||||
* Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__)."/../Graph.class.php";
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Draw labels
|
||||
*
|
||||
* @package Artichow
|
||||
*/
|
||||
class awLabel implements awPositionable {
|
||||
|
||||
/**
|
||||
* Label border
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $border;
|
||||
|
||||
/**
|
||||
* Label texts
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $texts;
|
||||
|
||||
/**
|
||||
* Text font
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $font;
|
||||
|
||||
/**
|
||||
* Text angle
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $angle = 0;
|
||||
|
||||
/**
|
||||
* Text color
|
||||
*
|
||||
* @var Color
|
||||
*/
|
||||
protected $color;
|
||||
|
||||
/**
|
||||
* Text background
|
||||
*
|
||||
* @var Color, Gradient
|
||||
*/
|
||||
private $background;
|
||||
|
||||
/**
|
||||
* Callback function
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $function;
|
||||
|
||||
/**
|
||||
* Padding
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $padding;
|
||||
|
||||
/**
|
||||
* Move position from this vector
|
||||
*
|
||||
* @var Point
|
||||
*/
|
||||
protected $move;
|
||||
|
||||
/**
|
||||
* Label interval
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $interval = 1;
|
||||
|
||||
/**
|
||||
* Horizontal align
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $hAlign = awLabel::CENTER;
|
||||
|
||||
/**
|
||||
* Vertical align
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $vAlign = awLabel::MIDDLE;
|
||||
|
||||
/**
|
||||
* Hide all labels ?
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $hide = FALSE;
|
||||
|
||||
/**
|
||||
* Keys to hide
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $hideKey = array();
|
||||
|
||||
/**
|
||||
* Values to hide
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $hideValue = array();
|
||||
|
||||
/**
|
||||
* Hide first label
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $hideFirst = FALSE;
|
||||
|
||||
/**
|
||||
* Hide last label
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $hideLast = FALSE;
|
||||
|
||||
/**
|
||||
* Build the label
|
||||
*
|
||||
* @param string $label First label
|
||||
*/
|
||||
public function __construct($label = NULL, $font = NULL, $color = NULL, $angle = 0) {
|
||||
|
||||
if(is_array($label)) {
|
||||
$this->set($label);
|
||||
} else if(is_string($label)) {
|
||||
$this->set(array($label));
|
||||
}
|
||||
|
||||
if($font === NULL) {
|
||||
$font = new awFont2;
|
||||
}
|
||||
|
||||
$this->setFont($font);
|
||||
$this->setAngle($angle);
|
||||
|
||||
if($color instanceof awColor) {
|
||||
$this->setColor($color);
|
||||
} else {
|
||||
$this->setColor(new awColor(0, 0, 0));
|
||||
}
|
||||
|
||||
$this->move = new awPoint(0, 0);
|
||||
|
||||
$this->border = new awBorder;
|
||||
$this->border->hide();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an element of the label from its key
|
||||
*
|
||||
* @param int $key Element key
|
||||
* @return string A value
|
||||
*/
|
||||
public function get($key) {
|
||||
return array_key_exists($key, $this->texts) ? $this->texts[$key] : NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all labels
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function all() {
|
||||
return $this->texts;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set one or several labels
|
||||
*
|
||||
* @param array $labels Array of string or a string
|
||||
*/
|
||||
public function set($labels) {
|
||||
|
||||
if(is_array($labels)) {
|
||||
$this->texts = $labels;
|
||||
} else {
|
||||
$this->texts = array((string)$labels);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Count number of texts in the label
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function count() {
|
||||
return is_array($this->texts) ? count($this->texts) : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a callback function for labels
|
||||
*
|
||||
* @param string $function
|
||||
*/
|
||||
public function setCallbackFunction($function) {
|
||||
$this->function = is_null($function) ? $function : (string)$function;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the callback function for labels
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getCallbackFunction() {
|
||||
return $this->function;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change labels format
|
||||
*
|
||||
* @param string $format New format (printf style: %.2f for example)
|
||||
*/
|
||||
public function setFormat($format) {
|
||||
$function = 'label'.time().'_'.(microtime() * 1000000);
|
||||
eval('function '.$function.'($value) {
|
||||
return sprintf("'.addcslashes($format, '"').'", $value);
|
||||
}');
|
||||
$this->setCallbackFunction($function);
|
||||
}
|
||||
|
||||
/**
|
||||
* Change font for label
|
||||
*
|
||||
* @param awFont $font New font
|
||||
* @param awColor $color Font color (can be NULL)
|
||||
*/
|
||||
public function setFont(awFont $font, $color = NULL) {
|
||||
$this->font = $font;
|
||||
if($color instanceof awColor) {
|
||||
$this->setColor($color);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Change font angle
|
||||
*
|
||||
* @param int $angle New angle
|
||||
*/
|
||||
public function setAngle($angle) {
|
||||
$this->angle = (int)$angle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change font color
|
||||
*
|
||||
* @param awColor $color
|
||||
*/
|
||||
public function setColor(awColor $color) {
|
||||
$this->color = $color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change text background
|
||||
*
|
||||
* @param mixed $background
|
||||
*/
|
||||
public function setBackground($background) {
|
||||
$this->background = $background;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change text background color
|
||||
*
|
||||
* @param Color
|
||||
*/
|
||||
public function setBackgroundColor(awColor $color) {
|
||||
$this->background = $color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change text background gradient
|
||||
*
|
||||
* @param Gradient
|
||||
*/
|
||||
public function setBackgroundGradient(awGradient $gradient) {
|
||||
$this->background = $gradient;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change padding
|
||||
*
|
||||
* @param int $left Left padding
|
||||
* @param int $right Right padding
|
||||
* @param int $top Top padding
|
||||
* @param int $bottom Bottom padding
|
||||
*/
|
||||
public function setPadding($left, $right, $top, $bottom) {
|
||||
$this->padding = array((int)$left, (int)$right, (int)$top, (int)$bottom);
|
||||
}
|
||||
|
||||
/**
|
||||
* Hide all labels ?
|
||||
*
|
||||
* @param bool $hide
|
||||
*/
|
||||
public function hide($hide = TRUE) {
|
||||
$this->hide = (bool)$hide;
|
||||
}
|
||||
|
||||
/**
|
||||
* Show all labels ?
|
||||
*
|
||||
* @param bool $show
|
||||
*/
|
||||
public function show($show = TRUE) {
|
||||
$this->hide = (bool)!$show;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hide a key
|
||||
*
|
||||
* @param int $key The key to hide
|
||||
*/
|
||||
public function hideKey($key) {
|
||||
$this->hideKey[$key] = TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hide a value
|
||||
*
|
||||
* @param int $value The value to hide
|
||||
*/
|
||||
public function hideValue($value) {
|
||||
$this->hideValue[] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hide first label
|
||||
*
|
||||
* @param bool $hide
|
||||
*/
|
||||
public function hideFirst($hide) {
|
||||
$this->hideFirst = (bool)$hide;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hide last label
|
||||
*
|
||||
* @param bool $hide
|
||||
*/
|
||||
public function hideLast($hide) {
|
||||
$this->hideLast = (bool)$hide;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set label interval
|
||||
*
|
||||
* @param int
|
||||
*/
|
||||
public function setInterval($interval) {
|
||||
|
||||
$this->interval = (int)$interval;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Change label position
|
||||
*
|
||||
* @param int $x Add this interval to X coord
|
||||
* @param int $y Add this interval to Y coord
|
||||
*/
|
||||
public function move($x, $y) {
|
||||
|
||||
$this->move = $this->move->move($x, $y);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Change alignment
|
||||
*
|
||||
* @param int $h Horizontal alignment
|
||||
* @param int $v Vertical alignment
|
||||
*/
|
||||
public function setAlign($h = NULL, $v = NULL) {
|
||||
if($h !== NULL) {
|
||||
$this->hAlign = (int)$h;
|
||||
}
|
||||
if($v !== NULL) {
|
||||
$this->vAlign = (int)$v;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a text from the labele
|
||||
*
|
||||
* @param mixed $key Key in the array text
|
||||
* @return Text
|
||||
*/
|
||||
public function getText($key) {
|
||||
|
||||
if(is_array($this->texts) and array_key_exists($key, $this->texts)) {
|
||||
|
||||
$value = $this->texts[$key];
|
||||
|
||||
if(is_string($this->function)) {
|
||||
$value = call_user_func($this->function, $value);
|
||||
}
|
||||
|
||||
$text = new awText($value);
|
||||
$text->setFont($this->font);
|
||||
$text->setAngle($this->angle);
|
||||
$text->setColor($this->color);
|
||||
|
||||
if($this->background instanceof awColor) {
|
||||
$text->setBackgroundColor($this->background);
|
||||
} else if($this->background instanceof awGradient) {
|
||||
$text->setBackgroundGradient($this->background);
|
||||
}
|
||||
|
||||
$text->border = $this->border;
|
||||
|
||||
if($this->padding !== NULL) {
|
||||
call_user_func_array(array($text, 'setPadding'), $this->padding);
|
||||
}
|
||||
|
||||
return $text;
|
||||
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get max width of all texts
|
||||
*
|
||||
* @param awDriver $driver A driver
|
||||
* @return int
|
||||
*/
|
||||
public function getMaxWidth(awDriver $driver) {
|
||||
|
||||
return $this->getMax($driver, 'getTextWidth');
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get max height of all texts
|
||||
*
|
||||
* @param awDriver $driver A driver
|
||||
* @return int
|
||||
*/
|
||||
public function getMaxHeight(awDriver $driver) {
|
||||
|
||||
return $this->getMax($driver, 'getTextHeight');
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw the label
|
||||
*
|
||||
* @param awDriver $driver
|
||||
* @param awPoint $p Label center
|
||||
* @param int $key Text position in the array of texts (default to zero)
|
||||
*/
|
||||
public function draw(awDriver $driver, awPoint $p, $key = 0) {
|
||||
|
||||
if(($key % $this->interval) !== 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Hide all labels
|
||||
if($this->hide) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Key is hidden
|
||||
if(array_key_exists($key, $this->hideKey)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Hide first label
|
||||
if($key === 0 and $this->hideFirst) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Hide last label
|
||||
if($key === count($this->texts) - 1 and $this->hideLast) {
|
||||
return;
|
||||
}
|
||||
|
||||
$text = $this->getText($key);
|
||||
|
||||
if($text !== NULL) {
|
||||
|
||||
// Value must be hidden
|
||||
if(in_array($text->getText(), $this->hideValue)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$x = $p->x;
|
||||
$y = $p->y;
|
||||
|
||||
// Get padding
|
||||
list($left, $right, $top, $bottom) = $text->getPadding();
|
||||
|
||||
// $font = $text->getFont();
|
||||
$width = $driver->getTextWidth($text);
|
||||
$height = $driver->getTextHeight($text);
|
||||
|
||||
switch($this->hAlign) {
|
||||
|
||||
case awLabel::RIGHT :
|
||||
$x -= ($width + $right);
|
||||
break;
|
||||
|
||||
case awLabel::CENTER :
|
||||
$x -= ($width - $left + $right) / 2;
|
||||
break;
|
||||
|
||||
case awLabel::LEFT :
|
||||
$x += $left;
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
switch($this->vAlign) {
|
||||
|
||||
case awLabel::TOP :
|
||||
$y -= ($height + $bottom);
|
||||
break;
|
||||
|
||||
case awLabel::MIDDLE :
|
||||
$y -= ($height - $top + $bottom) / 2;
|
||||
break;
|
||||
|
||||
case awLabel::BOTTOM :
|
||||
$y += $top;
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
$driver->string($text, $this->move->move($x, $y));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected function getMax(awDriver $driver, $function) {
|
||||
|
||||
$max = NULL;
|
||||
|
||||
foreach($this->texts as $key => $text) {
|
||||
|
||||
$text = $this->getText($key);
|
||||
$font = $text->getFont();
|
||||
|
||||
if(is_null($max)) {
|
||||
$max = $font->{$function}($text);
|
||||
} else {
|
||||
$max = max($max, $font->{$function}($text));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $max;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
registerClass('Label');
|
||||
@@ -1,709 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* This work is hereby released into the Public Domain.
|
||||
* To view a copy of the public domain dedication,
|
||||
* visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
|
||||
* Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__)."/../Graph.class.php";
|
||||
|
||||
|
||||
/**
|
||||
* Some legends
|
||||
*
|
||||
* @package Artichow
|
||||
*/
|
||||
class awLegend implements awPositionable {
|
||||
|
||||
/**
|
||||
* Legends added
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $legends = array();
|
||||
|
||||
/**
|
||||
* The current component
|
||||
*
|
||||
* @var Component
|
||||
*/
|
||||
protected $component;
|
||||
|
||||
/**
|
||||
* Background color or gradient
|
||||
*
|
||||
* @var Color, Gradient
|
||||
*/
|
||||
protected $background;
|
||||
|
||||
/**
|
||||
* Text color
|
||||
*
|
||||
* @var Color
|
||||
*/
|
||||
protected $textColor;
|
||||
|
||||
/**
|
||||
* Text font
|
||||
*
|
||||
* @var Font
|
||||
*/
|
||||
protected $textFont;
|
||||
|
||||
/**
|
||||
* Text margin
|
||||
*
|
||||
* @var Side
|
||||
*/
|
||||
protected $textMargin;
|
||||
|
||||
/**
|
||||
* Number of columns
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $columns = NULL;
|
||||
|
||||
/**
|
||||
* Number of rows
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $rows = NULL;
|
||||
|
||||
/**
|
||||
* Legend position
|
||||
*
|
||||
* @var Point
|
||||
*/
|
||||
protected $position;
|
||||
|
||||
/**
|
||||
* Hide legend ?
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $hide = FALSE;
|
||||
|
||||
/**
|
||||
* Space between each legend
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $space = 4;
|
||||
|
||||
/**
|
||||
* Horizontal alignment
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $hAlign;
|
||||
|
||||
/**
|
||||
* Vertical alignment
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $vAlign;
|
||||
|
||||
/**
|
||||
* Margin
|
||||
*
|
||||
* @var array Array for left, right, top and bottom margins
|
||||
*/
|
||||
private $margin;
|
||||
|
||||
/**
|
||||
* Legend shadow
|
||||
*
|
||||
* @var Shadow
|
||||
*/
|
||||
public $shadow;
|
||||
|
||||
/**
|
||||
* Legend border
|
||||
*
|
||||
* @var Border
|
||||
*/
|
||||
public $border;
|
||||
|
||||
/**
|
||||
* Line legend
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const LINE = 1;
|
||||
|
||||
/**
|
||||
* Color/Gradient background legend
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const BACKGROUND = 2;
|
||||
|
||||
/**
|
||||
* Use marks and line as legend
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const MARK = 3;
|
||||
|
||||
/**
|
||||
* Use marks as legend
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const MARKONLY = 4;
|
||||
|
||||
/**
|
||||
* Right side model
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const MODEL_RIGHT = 1;
|
||||
|
||||
/**
|
||||
* Bottom side model
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const MODEL_BOTTOM = 2;
|
||||
|
||||
/**
|
||||
* Build the legend
|
||||
*
|
||||
* @param int $model Legend model
|
||||
*/
|
||||
public function __construct($model = awLegend::MODEL_RIGHT) {
|
||||
|
||||
$this->shadow = new awShadow(awShadow::LEFT_BOTTOM);
|
||||
$this->border = new awBorder;
|
||||
|
||||
$this->textMargin = new awSide(4);
|
||||
$this->setModel($model);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a predefined model for the legend
|
||||
*
|
||||
* @param int $model
|
||||
*/
|
||||
public function setModel($model) {
|
||||
|
||||
$this->setBackgroundColor(new awColor(255, 255, 255, 15));
|
||||
$this->setPadding(8, 8, 8, 8);
|
||||
$this->setTextFont(new awFont2);
|
||||
$this->shadow->setSize(3);
|
||||
|
||||
switch($model) {
|
||||
|
||||
case awLegend::MODEL_RIGHT :
|
||||
|
||||
$this->setColumns(1);
|
||||
$this->setAlign(awLegend::RIGHT, awLegend::MIDDLE);
|
||||
$this->setPosition(0.96, 0.50);
|
||||
|
||||
break;
|
||||
|
||||
case awLegend::MODEL_BOTTOM :
|
||||
|
||||
$this->setRows(1);
|
||||
$this->setAlign(awLegend::CENTER, awLegend::TOP);
|
||||
$this->setPosition(0.50, 0.92);
|
||||
|
||||
break;
|
||||
|
||||
default :
|
||||
|
||||
$this->setPosition(0.5, 0.5);
|
||||
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Hide legend ?
|
||||
*
|
||||
* @param bool $hide TRUE to hide legend, FALSE otherwise
|
||||
*/
|
||||
public function hide($hide = TRUE) {
|
||||
$this->hide = (bool)$hide;
|
||||
}
|
||||
|
||||
/**
|
||||
* Show legend ?
|
||||
*
|
||||
* @param bool $show
|
||||
*/
|
||||
public function show($show = TRUE) {
|
||||
$this->hide = (bool)!$show;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add a Legendable object to the legend
|
||||
*
|
||||
* @param awLegendable $legendable
|
||||
* @param string $title Legend title
|
||||
* @param int $type Legend type (default to awLegend::LINE)
|
||||
*/
|
||||
public function add(awLegendable $legendable, $title, $type = awLegend::LINE) {
|
||||
|
||||
$legend = array($legendable, $title, $type);
|
||||
|
||||
$this->legends[] = $legend;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Change legend padding
|
||||
*
|
||||
* @param int $left
|
||||
* @param int $right
|
||||
* @param int $top
|
||||
* @param int $bottom
|
||||
*/
|
||||
public function setPadding($left, $right, $top, $bottom) {
|
||||
$this->padding = array((int)$left, (int)$right, (int)$top, (int)$bottom);
|
||||
}
|
||||
|
||||
/**
|
||||
* Change space between each legend
|
||||
*
|
||||
* @param int $space
|
||||
*/
|
||||
public function setSpace($space) {
|
||||
$this->space = (int)$space;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change alignment
|
||||
*
|
||||
* @param int $h Horizontal alignment
|
||||
* @param int $v Vertical alignment
|
||||
*/
|
||||
public function setAlign($h = NULL, $v = NULL) {
|
||||
if($h !== NULL) {
|
||||
$this->hAlign = (int)$h;
|
||||
}
|
||||
if($v !== NULL) {
|
||||
$this->vAlign = (int)$v;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Change number of columns
|
||||
*
|
||||
* @param int $columns
|
||||
*/
|
||||
public function setColumns($columns) {
|
||||
$this->rows = NULL;
|
||||
$this->columns = (int)$columns;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change number of rows
|
||||
*
|
||||
* @param int $rows
|
||||
*/
|
||||
public function setRows($rows) {
|
||||
$this->columns = NULL;
|
||||
$this->rows = (int)$rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change legend position
|
||||
* X and Y positions must be between 0 and 1.
|
||||
*
|
||||
* @param float $x
|
||||
* @param float $y
|
||||
*/
|
||||
public function setPosition($x = NULL, $y = NULL) {
|
||||
$x = (is_null($x) and !is_null($this->position)) ? $this->position->x : $x;
|
||||
$y = (is_null($y) and !is_null($this->position)) ? $this->position->y : $y;
|
||||
|
||||
$this->position = new awPoint($x, $y);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get legend position
|
||||
*
|
||||
* @return Point
|
||||
*/
|
||||
public function getPosition() {
|
||||
return $this->position;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change text font
|
||||
*
|
||||
* @param awFont $font
|
||||
*/
|
||||
public function setTextFont(awFont $font) {
|
||||
$this->textFont = $font;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change text margin
|
||||
*
|
||||
* @param int $left
|
||||
* @param int $right
|
||||
*/
|
||||
public function setTextMargin($left, $right) {
|
||||
$this->textMargin->set($left, $right);
|
||||
}
|
||||
|
||||
/**
|
||||
* Change text color
|
||||
*
|
||||
* @param awColor $color
|
||||
*/
|
||||
public function setTextColor(awColor $color) {
|
||||
$this->textColor = $color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change background
|
||||
*
|
||||
* @param mixed $background
|
||||
*/
|
||||
public function setBackground($background) {
|
||||
$this->background = $background;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change background color
|
||||
*
|
||||
* @param awColor $color
|
||||
*/
|
||||
public function setBackgroundColor(awColor $color) {
|
||||
$this->background = $color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change background gradient
|
||||
*
|
||||
* @param awGradient $gradient
|
||||
*/
|
||||
public function setBackgroundGradient(awGradient $gradient) {
|
||||
$this->background = $gradient;
|
||||
}
|
||||
|
||||
/**
|
||||
* Count the number of Legendable objects in the legend
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function count() {
|
||||
return count($this->legends);
|
||||
}
|
||||
|
||||
public function draw(awDriver $driver) {
|
||||
|
||||
if($this->hide) {
|
||||
return;
|
||||
}
|
||||
|
||||
$count = $this->count();
|
||||
|
||||
// No legend to print
|
||||
if($count === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Get text widths and heights of each element of the legend
|
||||
$widths = array();
|
||||
$heights = array();
|
||||
$texts = array();
|
||||
for($i = 0; $i < $count; $i++) {
|
||||
list(, $title, ) = $this->legends[$i];
|
||||
$text = new awText(
|
||||
$title,
|
||||
$this->textFont,
|
||||
$this->textColor,
|
||||
0
|
||||
);
|
||||
// $font = $text->getFont();
|
||||
$widths[$i] = $driver->getTextWidth($text) + $this->textMargin->left + $this->textMargin->right;
|
||||
$heights[$i] = $driver->getTextHeight($text);
|
||||
$texts[$i] = $text;
|
||||
}
|
||||
|
||||
// Maximum height of the font used
|
||||
$heightMax = array_max($heights);
|
||||
|
||||
// Get number of columns
|
||||
if($this->columns !== NULL) {
|
||||
$columns = $this->columns;
|
||||
} else if($this->rows !== NULL) {
|
||||
$columns = ceil($count / $this->rows);
|
||||
} else {
|
||||
$columns = $count;
|
||||
}
|
||||
|
||||
// Number of rows
|
||||
$rows = (int)ceil($count / $columns);
|
||||
|
||||
// Get maximum with of each column
|
||||
$widthMax = array();
|
||||
for($i = 0; $i < $count; $i++) {
|
||||
// Get column width
|
||||
$column = $i % $columns;
|
||||
if(array_key_exists($column, $widthMax) === FALSE) {
|
||||
$widthMax[$column] = $widths[$i];
|
||||
} else {
|
||||
$widthMax[$column] = max($widthMax[$column], $widths[$i]);
|
||||
}
|
||||
}
|
||||
|
||||
$width = $this->padding[0] + $this->padding[1] - $this->space;
|
||||
for($i = 0; $i < $columns; $i++) {
|
||||
$width += $this->space + 5 + 10 + $widthMax[$i];
|
||||
}
|
||||
|
||||
$height = ($heightMax + $this->space) * $rows - $this->space + $this->padding[2] + $this->padding[3];
|
||||
|
||||
// Look for legends position
|
||||
list($x, $y) = $driver->getSize();
|
||||
|
||||
$p = new awPoint(
|
||||
$this->position->x * $x,
|
||||
$this->position->y * $y
|
||||
);
|
||||
|
||||
switch($this->hAlign) {
|
||||
|
||||
case awLegend::CENTER :
|
||||
$p->x -= $width / 2;
|
||||
break;
|
||||
|
||||
case awLegend::RIGHT :
|
||||
$p->x -= $width;
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
switch($this->vAlign) {
|
||||
|
||||
case awLegend::MIDDLE :
|
||||
$p->y -= $height / 2;
|
||||
break;
|
||||
|
||||
case awLegend::BOTTOM :
|
||||
$p->y -= $height;
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
// Draw legend shadow
|
||||
$this->shadow->draw(
|
||||
$driver,
|
||||
$p,
|
||||
$p->move($width, $height),
|
||||
awShadow::OUT
|
||||
);
|
||||
|
||||
// Draw legends base
|
||||
$this->drawBase($driver, $p, $width, $height);
|
||||
|
||||
// Draw each legend
|
||||
for($i = 0; $i < $count; $i++) {
|
||||
|
||||
list($component, $title, $type) = $this->legends[$i];
|
||||
|
||||
$column = $i % $columns;
|
||||
$row = (int)floor($i / $columns);
|
||||
|
||||
// Get width of all previous columns
|
||||
$previousColumns = 0;
|
||||
for($j = 0; $j < $column; $j++) {
|
||||
$previousColumns += $this->space + 10 + 5 + $widthMax[$j];
|
||||
}
|
||||
|
||||
// Draw legend text
|
||||
$driver->string(
|
||||
$texts[$i],
|
||||
$p->move(
|
||||
$this->padding[0] + $previousColumns + 10 + 5 + $this->textMargin->left,
|
||||
$this->padding[2] + $row * ($heightMax + $this->space) + $heightMax / 2 - $heights[$i] / 2
|
||||
)
|
||||
);
|
||||
|
||||
// Draw legend icon
|
||||
switch($type) {
|
||||
|
||||
case awLegend::LINE :
|
||||
case awLegend::MARK :
|
||||
case awLegend::MARKONLY :
|
||||
|
||||
// Get vertical position
|
||||
$x = $this->padding[0] + $previousColumns;
|
||||
$y = $this->padding[2] + $row * ($heightMax + $this->space) + $heightMax / 2 - $component->getLegendLineThickness();
|
||||
|
||||
// Draw two lines
|
||||
if($component->getLegendLineColor() !== NULL) {
|
||||
|
||||
$color = $component->getLegendLineColor();
|
||||
|
||||
if($color instanceof awColor and $type !== awLegend::MARKONLY) {
|
||||
|
||||
$driver->line(
|
||||
$color,
|
||||
new awLine(
|
||||
$p->move(
|
||||
$x, // YaPB ??
|
||||
$y + $component->getLegendLineThickness() / 2
|
||||
),
|
||||
$p->move(
|
||||
$x + 10,
|
||||
$y + $component->getLegendLineThickness() / 2
|
||||
),
|
||||
$component->getLegendLineStyle(),
|
||||
$component->getLegendLineThickness()
|
||||
)
|
||||
);
|
||||
|
||||
unset($color);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if($type === awLegend::MARK or $type === awLegend::MARKONLY) {
|
||||
|
||||
$mark = $component->getLegendMark();
|
||||
|
||||
if($mark !== NULL) {
|
||||
$mark->draw(
|
||||
$driver,
|
||||
$p->move(
|
||||
$x + 5.5,
|
||||
$y + $component->getLegendLineThickness() / 2
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
unset($mark);
|
||||
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case awLegend::BACKGROUND :
|
||||
|
||||
// Get vertical position
|
||||
$x = $this->padding[0] + $previousColumns;
|
||||
$y = $this->padding[2] + $row * ($heightMax + $this->space) + $heightMax / 2 - 5;
|
||||
|
||||
$from = $p->move(
|
||||
$x,
|
||||
$y
|
||||
);
|
||||
|
||||
$to = $p->move(
|
||||
$x + 10,
|
||||
$y + 10
|
||||
);
|
||||
|
||||
$background = $component->getLegendBackground();
|
||||
|
||||
if($background !== NULL) {
|
||||
|
||||
$driver->filledRectangle(
|
||||
$component->getLegendBackground(),
|
||||
new awLine($from, $to)
|
||||
);
|
||||
|
||||
// Draw rectangle border
|
||||
$this->border->rectangle(
|
||||
$driver,
|
||||
$from->move(0, 0),
|
||||
$to->move(0, 0)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
unset($background, $from, $to);
|
||||
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private function drawBase(awDriver $driver, awPoint $p, $width, $height) {
|
||||
|
||||
$this->border->rectangle(
|
||||
$driver,
|
||||
$p,
|
||||
$p->move($width, $height)
|
||||
);
|
||||
|
||||
$size = $this->border->visible() ? 1 : 0;
|
||||
|
||||
$driver->filledRectangle(
|
||||
$this->background,
|
||||
new awLine(
|
||||
$p->move($size, $size),
|
||||
$p->move($width - $size, $height - $size)
|
||||
)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
registerClass('Legend');
|
||||
|
||||
/**
|
||||
* You can add a legend to components which implements this interface
|
||||
*
|
||||
* @package Artichow
|
||||
*/
|
||||
interface awLegendable {
|
||||
|
||||
/**
|
||||
* Get the line type
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getLegendLineStyle();
|
||||
|
||||
/**
|
||||
* Get the line thickness
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getLegendLineThickness();
|
||||
|
||||
/**
|
||||
* Get the color of line
|
||||
*
|
||||
* @return Color
|
||||
*/
|
||||
public function getLegendLineColor();
|
||||
|
||||
/**
|
||||
* Get the background color or gradient of an element of the component
|
||||
*
|
||||
* @return Color, Gradient
|
||||
*/
|
||||
public function getLegendBackground();
|
||||
|
||||
/**
|
||||
* Get a Mark object
|
||||
*
|
||||
* @return Mark
|
||||
*/
|
||||
public function getLegendMark();
|
||||
|
||||
}
|
||||
|
||||
registerInterface('Legendable');
|
||||
@@ -1,489 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* This work is hereby released into the Public Domain.
|
||||
* To view a copy of the public domain dedication,
|
||||
* visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
|
||||
* Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__)."/../Graph.class.php";
|
||||
|
||||
|
||||
/**
|
||||
* Draw marks
|
||||
*
|
||||
* @package Artichow
|
||||
*/
|
||||
class awMark {
|
||||
|
||||
/**
|
||||
* Circle mark
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const CIRCLE = 1;
|
||||
|
||||
/**
|
||||
* Square mark
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const SQUARE = 2;
|
||||
|
||||
/**
|
||||
* Triangle mark
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const TRIANGLE = 3;
|
||||
|
||||
/**
|
||||
* Inverted triangle mark
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const INVERTED_TRIANGLE = 4;
|
||||
|
||||
/**
|
||||
* Rhombus mark
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const RHOMBUS = 5;
|
||||
|
||||
/**
|
||||
* Cross (X) mark
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const CROSS = 6;
|
||||
|
||||
/**
|
||||
* Plus mark
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const PLUS = 7;
|
||||
|
||||
/**
|
||||
* Image mark
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const IMAGE = 8;
|
||||
|
||||
/**
|
||||
* Star mark
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const STAR = 9;
|
||||
|
||||
/**
|
||||
* Paperclip mark
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const PAPERCLIP = 10;
|
||||
|
||||
/**
|
||||
* Book mark
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const BOOK = 11;
|
||||
|
||||
/**
|
||||
* Must marks be hidden ?
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $hide;
|
||||
|
||||
/**
|
||||
* Mark type
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $type;
|
||||
|
||||
/**
|
||||
* Mark size
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $size = 8;
|
||||
|
||||
/**
|
||||
* Fill mark
|
||||
*
|
||||
* @var Color, Gradient
|
||||
*/
|
||||
protected $fill;
|
||||
|
||||
/**
|
||||
* Mark image
|
||||
*
|
||||
* @var Image
|
||||
*/
|
||||
protected $image;
|
||||
|
||||
/**
|
||||
* To draw marks
|
||||
*
|
||||
* @var Driver
|
||||
*/
|
||||
protected $driver;
|
||||
|
||||
/**
|
||||
* Move position from this vector
|
||||
*
|
||||
* @var Point
|
||||
*/
|
||||
protected $move;
|
||||
|
||||
/**
|
||||
* Marks border
|
||||
*
|
||||
* @var Border
|
||||
*/
|
||||
public $border;
|
||||
|
||||
/**
|
||||
* Build the mark
|
||||
*/
|
||||
public function __construct() {
|
||||
|
||||
$this->fill = new awColor(255, 0, 0, 0);
|
||||
$this->border = new awBorder;
|
||||
$this->border->hide();
|
||||
|
||||
$this->move = new awPoint(0, 0);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Change mark position
|
||||
*
|
||||
* @param int $x Add this interval to X coord
|
||||
* @param int $y Add this interval to Y coord
|
||||
*/
|
||||
public function move($x, $y) {
|
||||
|
||||
$this->move = $this->move->move($x, $y);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Hide marks ?
|
||||
*
|
||||
* @param bool $hide TRUE to hide marks, FALSE otherwise
|
||||
*/
|
||||
public function hide($hide = TRUE) {
|
||||
$this->hide = (bool)$hide;
|
||||
}
|
||||
|
||||
/**
|
||||
* Show marks ?
|
||||
*
|
||||
* @param bool $show
|
||||
*/
|
||||
public function show($show = TRUE) {
|
||||
$this->hide = (bool)!$show;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change mark type
|
||||
*
|
||||
* @param int $size Size in pixels
|
||||
*/
|
||||
public function setSize($size) {
|
||||
$this->size = (int)$size;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change mark type
|
||||
*
|
||||
* @param int $type New mark type
|
||||
* @param int $size Mark size (can be NULL)
|
||||
*/
|
||||
public function setType($type, $size = NULL) {
|
||||
$this->type = (int)$type;
|
||||
if($size !== NULL) {
|
||||
$this->setSize($size);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fill the mark with a color or a gradient
|
||||
*
|
||||
* @param mixed $fill A color or a gradient
|
||||
*/
|
||||
public function setFill($fill) {
|
||||
if($fill instanceof awColor or $fill instanceof awGradient) {
|
||||
$this->fill = $fill;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set an image
|
||||
* Only for awMark::IMAGE type.
|
||||
*
|
||||
* @param Image An image
|
||||
*/
|
||||
public function setImage(awImage $image) {
|
||||
$this->image = $image;
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw the mark
|
||||
*
|
||||
* @param awDriver $driver
|
||||
* @param awPoint $point Mark center
|
||||
*/
|
||||
public function draw(awDriver $driver, awPoint $point) {
|
||||
|
||||
// Hide marks ?
|
||||
if($this->hide) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if we can print marks
|
||||
if($this->type !== NULL) {
|
||||
|
||||
$this->driver = $driver;
|
||||
$realPoint = $this->move->move($point->x, $point->y);
|
||||
|
||||
switch($this->type) {
|
||||
|
||||
case awMark::CIRCLE :
|
||||
$this->drawCircle($realPoint);
|
||||
break;
|
||||
|
||||
case awMark::SQUARE :
|
||||
$this->drawSquare($realPoint);
|
||||
break;
|
||||
|
||||
case awMark::TRIANGLE :
|
||||
$this->drawTriangle($realPoint);
|
||||
break;
|
||||
|
||||
case awMark::INVERTED_TRIANGLE :
|
||||
$this->drawTriangle($realPoint, TRUE);
|
||||
break;
|
||||
|
||||
case awMark::RHOMBUS :
|
||||
$this->drawRhombus($realPoint);
|
||||
break;
|
||||
|
||||
case awMark::CROSS :
|
||||
$this->drawCross($realPoint);
|
||||
break;
|
||||
|
||||
case awMark::PLUS :
|
||||
$this->drawCross($realPoint, TRUE);
|
||||
break;
|
||||
|
||||
case awMark::IMAGE :
|
||||
$this->drawImage($realPoint);
|
||||
break;
|
||||
|
||||
case awMark::STAR :
|
||||
$this->changeType('star');
|
||||
$this->draw($driver, $point);
|
||||
break;
|
||||
|
||||
case awMark::PAPERCLIP :
|
||||
$this->changeType('paperclip');
|
||||
$this->draw($driver, $point);
|
||||
break;
|
||||
|
||||
case awMark::BOOK :
|
||||
$this->changeType('book');
|
||||
$this->draw($driver, $point);
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected function changeType($image) {
|
||||
$this->setType(awMARK::IMAGE);
|
||||
$this->setImage(new awFileImage(ARTICHOW_IMAGE.DIRECTORY_SEPARATOR.$image.'.png'));
|
||||
}
|
||||
|
||||
protected function drawCircle(awPoint $point) {
|
||||
|
||||
$this->driver->filledEllipse(
|
||||
$this->fill,
|
||||
$point,
|
||||
$this->size, $this->size
|
||||
);
|
||||
|
||||
$this->border->ellipse(
|
||||
$this->driver,
|
||||
$point,
|
||||
$this->size, $this->size
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
protected function drawSquare(awPoint $point) {
|
||||
|
||||
list($x, $y) = $point->getLocation();
|
||||
|
||||
$x1 = (int)($x - $this->size / 2);
|
||||
$x2 = $x1 + $this->size;
|
||||
$y1 = (int)($y - $this->size / 2);
|
||||
$y2 = $y1 + $this->size;
|
||||
|
||||
$this->border->rectangle($this->driver, new awPoint($x1, $y1), new awPoint($x2, $y2));
|
||||
|
||||
$size = $this->border->visible() ? 1 : 0;
|
||||
|
||||
$this->driver->filledRectangle(
|
||||
$this->fill,
|
||||
new awLine(
|
||||
new awPoint($x1 + $size, $y1 + $size),
|
||||
new awPoint($x2 - $size, $y2 - $size)
|
||||
)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
protected function drawTriangle(awPoint $point, $inverted = FALSE) {
|
||||
|
||||
list($x, $y) = $point->getLocation();
|
||||
|
||||
$size = $this->size;
|
||||
|
||||
$triangle = new awPolygon;
|
||||
// Set default style and thickness
|
||||
$triangle->setStyle(awPolygon::SOLID);
|
||||
$triangle->setThickness(1);
|
||||
|
||||
if($inverted === TRUE) {
|
||||
// Bottom of the triangle
|
||||
$triangle->append(new awPoint($x, $y + $size / sqrt(3)));
|
||||
|
||||
// Upper left corner
|
||||
$triangle->append(new awPoint($x - $size / 2, $y - $size / (2 * sqrt(3))));
|
||||
|
||||
// Upper right corner
|
||||
$triangle->append(new awPoint($x + $size / 2, $y - $size / (2 * sqrt(3))));
|
||||
} else {
|
||||
// Top of the triangle
|
||||
$triangle->append(new awPoint($x, $y - $size / sqrt(3)));
|
||||
|
||||
// Lower left corner
|
||||
$triangle->append(new awPoint($x - $size / 2, $y + $size / (2 * sqrt(3))));
|
||||
|
||||
// Lower right corner
|
||||
$triangle->append(new awPoint($x + $size / 2, $y + $size / (2 * sqrt(3))));
|
||||
}
|
||||
|
||||
$this->driver->filledPolygon($this->fill, $triangle);
|
||||
|
||||
if($this->border->visible()) {
|
||||
$this->border->polygon($this->driver, $triangle);
|
||||
}
|
||||
}
|
||||
|
||||
protected function drawRhombus(awPoint $point) {
|
||||
|
||||
list($x, $y) = $point->getLocation();
|
||||
|
||||
$rhombus = new awPolygon;
|
||||
// Set default style and thickness
|
||||
$rhombus->setStyle(awPolygon::SOLID);
|
||||
$rhombus->setThickness(1);
|
||||
|
||||
// Top of the rhombus
|
||||
$rhombus->append(new awPoint($x, $y - $this->size / 2));
|
||||
|
||||
// Right of the rhombus
|
||||
$rhombus->append(new awPoint($x + $this->size / 2, $y));
|
||||
|
||||
// Bottom of the rhombus
|
||||
$rhombus->append(new awPoint($x, $y + $this->size / 2));
|
||||
|
||||
// Left of the rhombus
|
||||
$rhombus->append(new awPoint($x - $this->size / 2, $y));
|
||||
|
||||
$this->driver->filledPolygon($this->fill, $rhombus);
|
||||
|
||||
if($this->border->visible()) {
|
||||
$this->border->polygon($this->driver, $rhombus);
|
||||
}
|
||||
}
|
||||
|
||||
protected function drawCross(awPoint $point, $upright = FALSE) {
|
||||
|
||||
list($x, $y) = $point->getLocation();
|
||||
|
||||
if($upright === TRUE) {
|
||||
$x11 = (int)($x);
|
||||
$y11 = (int)($y - $this->size / 2);
|
||||
$x12 = (int)($x);
|
||||
$y12 = (int)($y + $this->size / 2);
|
||||
|
||||
$y21 = (int)($y);
|
||||
$y22 = (int)($y);
|
||||
} else {
|
||||
$x11 = (int)($x - $this->size / 2);
|
||||
$y11 = (int)($y + $this->size / 2);
|
||||
$x12 = (int)($x + $this->size / 2);
|
||||
$y12 = (int)($y - $this->size / 2);
|
||||
|
||||
$y21 = (int)($y - $this->size / 2);
|
||||
$y22 = (int)($y + $this->size / 2);
|
||||
}
|
||||
|
||||
$x21 = (int)($x - $this->size / 2);
|
||||
$x22 = (int)($x + $this->size / 2);
|
||||
|
||||
$this->driver->line(
|
||||
$this->fill,
|
||||
new awLine(
|
||||
new awPoint($x11, $y11),
|
||||
new awPoint($x12, $y12)
|
||||
)
|
||||
);
|
||||
|
||||
$this->driver->line(
|
||||
$this->fill,
|
||||
new awLine(
|
||||
new awPoint($x21, $y21),
|
||||
new awPoint($x22, $y22)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
protected function drawImage(awPoint $point) {
|
||||
|
||||
if($this->image instanceof awImage) {
|
||||
|
||||
$width = $this->image->width;
|
||||
$height = $this->image->height;
|
||||
|
||||
list($x, $y) = $point->getLocation();
|
||||
|
||||
$x1 = (int)($x - $width / 2);
|
||||
$x2 = $x1 + $width;
|
||||
$y1 = (int)($y - $width / 2);
|
||||
$y2 = $y1 + $height;
|
||||
|
||||
$this->border->rectangle($this->driver, new awPoint($x1 - 1, $y1 - 1), new awPoint($x2 + 1, $y2 + 1));
|
||||
|
||||
$this->driver->copyImage($this->image, new awPoint($x1, $y1), new awPoint($x2, $y2));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
registerClass('Mark');
|
||||
@@ -1,831 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* This work is hereby released into the Public Domain.
|
||||
* To view a copy of the public domain dedication,
|
||||
* visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
|
||||
* Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__)."/../Graph.class.php";
|
||||
|
||||
abstract class awShape {
|
||||
|
||||
/**
|
||||
* Is the shape hidden ?
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $hide = FALSE;
|
||||
|
||||
/**
|
||||
* Shape style
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $style;
|
||||
|
||||
/**
|
||||
* Shape thickness
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $thickness;
|
||||
|
||||
/**
|
||||
* Solid shape
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const SOLID = 1;
|
||||
|
||||
/**
|
||||
* Dotted shape
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const DOTTED = 2;
|
||||
|
||||
/**
|
||||
* Dashed shape
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const DASHED = 3;
|
||||
|
||||
/**
|
||||
* Change shape style
|
||||
*
|
||||
* @param int $style Line style
|
||||
*/
|
||||
public function setStyle($style) {
|
||||
$this->style = (int)$style;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return shape style
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getStyle() {
|
||||
return $this->style;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change shape thickness
|
||||
*
|
||||
* @param int $thickness Shape thickness in pixels
|
||||
*/
|
||||
public function setThickness($thickness) {
|
||||
$this->thickness = (int)$thickness;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return shape thickness
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getThickness() {
|
||||
return $this->thickness;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hide the shape
|
||||
*
|
||||
* @param bool $hide
|
||||
*/
|
||||
public function hide($hide) {
|
||||
$this->hide = (bool)$hide;
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the shape
|
||||
*
|
||||
* @param bool $shape
|
||||
*/
|
||||
public function show($shape) {
|
||||
$this->hide = (bool)!$shape;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the line hidden ?
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isHidden() {
|
||||
return $this->hide;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
registerClass('Shape', TRUE);
|
||||
|
||||
/**
|
||||
* Describe a point
|
||||
*
|
||||
* @package Artichow
|
||||
*/
|
||||
class awPoint extends awShape {
|
||||
|
||||
/**
|
||||
* X coord
|
||||
*
|
||||
* @var float
|
||||
*/
|
||||
public $x;
|
||||
|
||||
/**
|
||||
* Y coord
|
||||
*
|
||||
* @var float
|
||||
*/
|
||||
public $y;
|
||||
|
||||
/**
|
||||
* Build a new awpoint
|
||||
*
|
||||
* @param float $x
|
||||
* @param float $y
|
||||
*/
|
||||
public function __construct($x, $y) {
|
||||
|
||||
$this->setLocation($x, $y);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Change X value
|
||||
*
|
||||
* @param float $x
|
||||
*/
|
||||
public function setX($x) {
|
||||
$this->x = (float)$x;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change Y value
|
||||
*
|
||||
* @param float $y
|
||||
*/
|
||||
public function setY($y) {
|
||||
$this->y = (float)$y;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change point location
|
||||
*
|
||||
* @param float $x
|
||||
* @param float $y
|
||||
*/
|
||||
public function setLocation($x, $y) {
|
||||
$this->setX($x);
|
||||
$this->setY($y);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get point location
|
||||
*
|
||||
* @param array Point location
|
||||
*/
|
||||
public function getLocation() {
|
||||
return array($this->x, $this->y);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get distance to another point
|
||||
*
|
||||
* @param awPoint $p A point
|
||||
* @return float
|
||||
*/
|
||||
public function getDistance(awPoint $p) {
|
||||
|
||||
return sqrt(pow($p->x - $this->x, 2) + pow($p->y - $this->y, 2));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Move the point to another location
|
||||
*
|
||||
* @param Point A Point with the new awlocation
|
||||
*/
|
||||
public function move($x, $y) {
|
||||
|
||||
return new awPoint(
|
||||
$this->x + $x,
|
||||
$this->y + $y
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
registerClass('Point');
|
||||
|
||||
|
||||
/**
|
||||
* Describe a line
|
||||
*
|
||||
* @package Artichow
|
||||
*/
|
||||
class awLine extends awShape {
|
||||
|
||||
/**
|
||||
* Line first point
|
||||
*
|
||||
* @param Point
|
||||
*/
|
||||
public $p1;
|
||||
|
||||
/**
|
||||
* Line second point
|
||||
*
|
||||
* @param Point
|
||||
*/
|
||||
public $p2;
|
||||
|
||||
/**
|
||||
* The line slope (the m in y = mx + p)
|
||||
*
|
||||
* @param float
|
||||
*/
|
||||
private $slope;
|
||||
|
||||
/**
|
||||
* The y-intercept value of the line (the p in y = mx + p)
|
||||
*
|
||||
* @param float
|
||||
*/
|
||||
private $origin;
|
||||
|
||||
/**
|
||||
* Build a new awline
|
||||
*
|
||||
* @param awPoint $p1 First point
|
||||
* @param awPoint $p2 Second point
|
||||
* @param int $type Style of line (default to solid)
|
||||
* @param int $thickness Line thickness (default to 1)
|
||||
*/
|
||||
public function __construct($p1 = NULL, $p2 = NULL, $type = awLine::SOLID, $thickness = 1) {
|
||||
|
||||
$this->setLocation($p1, $p2);
|
||||
$this->setStyle($type);
|
||||
$this->setThickness($thickness);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a line from 4 coords
|
||||
*
|
||||
* @param int $x1 Left position
|
||||
* @param int $y1 Top position
|
||||
* @param int $x2 Right position
|
||||
* @param int $y2 Bottom position
|
||||
*/
|
||||
public static function build($x1, $y1, $x2, $y2) {
|
||||
|
||||
return new awLine(
|
||||
new awPoint($x1, $y1),
|
||||
new awPoint($x2, $y2)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Change X values of the line
|
||||
*
|
||||
* @param int $x1 Begin value
|
||||
* @param int $x2 End value
|
||||
*/
|
||||
public function setX($x1, $x2) {
|
||||
$this->p1->setX($x1);
|
||||
$this->p2->setX($x2);
|
||||
|
||||
// Resets slope and origin values so they are
|
||||
// recalculated when and if needed.
|
||||
$this->slope = NULL;
|
||||
$this->origin = NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change Y values of the line
|
||||
*
|
||||
* @param int $y1 Begin value
|
||||
* @param int $y2 End value
|
||||
*/
|
||||
public function setY($y1, $y2) {
|
||||
$this->p1->setY($y1);
|
||||
$this->p2->setY($y2);
|
||||
|
||||
// Resets slope and origin values so they are
|
||||
// recalculated when and if needed.
|
||||
$this->slope = NULL;
|
||||
$this->origin = NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change line location
|
||||
*
|
||||
* @param awPoint $p1 First point
|
||||
* @param awPoint $p2 Second point
|
||||
*/
|
||||
public function setLocation($p1, $p2) {
|
||||
if(is_null($p1) or $p1 instanceof awPoint) {
|
||||
$this->p1 = $p1;
|
||||
}
|
||||
if(is_null($p2) or $p2 instanceof awPoint) {
|
||||
$this->p2 = $p2;
|
||||
}
|
||||
|
||||
// Resets slope and origin values so they are
|
||||
// recalculated when and if needed.
|
||||
$this->slope = NULL;
|
||||
$this->origin = NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get line location
|
||||
*
|
||||
* @param array Line location
|
||||
*/
|
||||
public function getLocation() {
|
||||
return array($this->p1, $this->p2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the line size
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public function getSize() {
|
||||
|
||||
$square = pow($this->p2->x - $this->p1->x, 2) + pow($this->p2->y - $this->p1->y, 2);
|
||||
return sqrt($square);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate the line slope
|
||||
*
|
||||
*/
|
||||
private function calculateSlope() {
|
||||
if($this->isHorizontal()) {
|
||||
$this->slope = 0;
|
||||
} else {
|
||||
$slope = ($this->p1->y - $this->p2->y) / ($this->p1->x - $this->p2->x);
|
||||
|
||||
$this->slope = $slope;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate the y-intercept value of the line
|
||||
*
|
||||
*/
|
||||
private function calculateOrigin() {
|
||||
if($this->isHorizontal()) {
|
||||
$this->origin = $this->p1->y; // Or p2->y
|
||||
} else {
|
||||
$y1 = $this->p1->y;
|
||||
$y2 = $this->p2->y;
|
||||
$x1 = $this->p1->x;
|
||||
$x2 = $this->p2->x;
|
||||
|
||||
$origin = ($y2 * $x1 - $y1 * $x2) / ($x1 - $x2);
|
||||
|
||||
$this->origin = $origin;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate the slope and y-intercept value of the line
|
||||
*
|
||||
*/
|
||||
private function calculateEquation() {
|
||||
$this->calculateSlope();
|
||||
$this->calculateOrigin();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the line slope value
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public function getSlope() {
|
||||
if($this->isVertical()) {
|
||||
return NULL;
|
||||
} elseif($this->slope !== NULL) {
|
||||
return $this->slope;
|
||||
} else {
|
||||
$this->calculateSlope();
|
||||
return $this->slope;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the line y-intercept value
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public function getOrigin() {
|
||||
if($this->isVertical()) {
|
||||
return NULL;
|
||||
} elseif($this->origin !== NULL) {
|
||||
return $this->origin;
|
||||
} else {
|
||||
$this->calculateOrigin();
|
||||
return $this->origin;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the line equation
|
||||
*
|
||||
* @return array An array containing the slope and y-intercept value of the line
|
||||
*/
|
||||
public function getEquation() {
|
||||
$slope = $this->getSlope();
|
||||
$origin = $this->getOrigin();
|
||||
|
||||
return array($slope, $origin);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the x coordinate of a point on the line
|
||||
* given its y coordinate.
|
||||
*
|
||||
* @param float $y The y coordinate of the Point
|
||||
* @return float $x The corresponding x coordinate
|
||||
*/
|
||||
public function getXFrom($y) {
|
||||
$x = NULL;
|
||||
|
||||
if($this->isVertical()) {
|
||||
list($p, ) = $this->getLocation();
|
||||
$x = $p->x;
|
||||
} else {
|
||||
list($slope, $origin) = $this->getEquation();
|
||||
|
||||
if($slope !== 0) {
|
||||
$y = (float)$y;
|
||||
$x = ($y - $origin) / $slope;
|
||||
}
|
||||
}
|
||||
|
||||
return $x;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the y coordinate of a point on the line
|
||||
* given its x coordinate.
|
||||
*
|
||||
* @param float $x The x coordinate of the Point
|
||||
* @return float $y The corresponding y coordinate
|
||||
*/
|
||||
public function getYFrom($x) {
|
||||
$y = NULL;
|
||||
|
||||
if($this->isHorizontal()) {
|
||||
list($p, ) = $this->getLocation();
|
||||
$y = $p->y;
|
||||
} else {
|
||||
list($slope, $origin) = $this->getEquation();
|
||||
|
||||
if($slope !== NULL) {
|
||||
$x = (float)$x;
|
||||
$y = $slope * $x + $origin;
|
||||
}
|
||||
}
|
||||
|
||||
return $y;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if the line can be considered as a point
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isPoint() {
|
||||
return ($this->p1->x === $this->p2->x and $this->p1->y === $this->p2->y);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if the line is a vertical line
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isVertical() {
|
||||
return ($this->p1->x === $this->p2->x);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if the line is an horizontal line
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isHorizontal() {
|
||||
return ($this->p1->y === $this->p2->y);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns TRUE if the line is going all the way from the top
|
||||
* to the bottom of the polygon surrounding box.
|
||||
*
|
||||
* @param $polygon Polygon A Polygon object
|
||||
* @return bool
|
||||
*/
|
||||
public function isTopToBottom(awPolygon $polygon) {
|
||||
list($xMin, $xMax) = $polygon->getBoxXRange();
|
||||
list($yMin, $yMax) = $polygon->getBoxYRange();
|
||||
|
||||
if($this->isHorizontal()) {
|
||||
return FALSE;
|
||||
} else {
|
||||
if($this->p1->y < $this->p2->y) {
|
||||
$top = $this->p1;
|
||||
$bottom = $this->p2;
|
||||
} else {
|
||||
$top = $this->p2;
|
||||
$bottom = $this->p1;
|
||||
}
|
||||
|
||||
return (
|
||||
$this->isOnBoxTopSide($top, $xMin, $xMax, $yMin)
|
||||
and
|
||||
$this->isOnBoxBottomSide($bottom, $xMin, $xMax, $yMax)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns TRUE if the line is going all the way from the left side
|
||||
* to the right side of the polygon surrounding box.
|
||||
*
|
||||
* @param $polygon Polygon A Polygon object
|
||||
* @return bool
|
||||
*/
|
||||
public function isLeftToRight(awPolygon $polygon) {
|
||||
list($xMin, $xMax) = $polygon->getBoxXRange();
|
||||
list($yMin, $yMax) = $polygon->getBoxYRange();
|
||||
|
||||
if($this->isVertical()) {
|
||||
return FALSE;
|
||||
} else {
|
||||
if($this->p1->x < $this->p2->x) {
|
||||
$left = $this->p1;
|
||||
$right = $this->p2;
|
||||
} else {
|
||||
$left = $this->p2;
|
||||
$right = $this->p1;
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
$this->isOnBoxLeftSide($left, $yMin, $yMax, $xMin)
|
||||
and
|
||||
$this->isOnBoxRightSide($right, $yMin, $yMax, $xMax)
|
||||
);
|
||||
}
|
||||
|
||||
private function isOnBoxTopSide(awPoint $point, $xMin, $xMax, $yMin) {
|
||||
if(
|
||||
$point->y === $yMin
|
||||
and
|
||||
$point->x >= $xMin
|
||||
and
|
||||
$point->x <= $xMax
|
||||
) {
|
||||
return TRUE;
|
||||
} else {
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
private function isOnBoxBottomSide(awPoint $point, $xMin, $xMax, $yMax) {
|
||||
if(
|
||||
$point->y === $yMax
|
||||
and
|
||||
$point->x >= $xMin
|
||||
and
|
||||
$point->x <= $xMax
|
||||
) {
|
||||
return TRUE;
|
||||
} else {
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
private function isOnBoxLeftSide(awPoint $point, $yMin, $yMax, $xMin) {
|
||||
if(
|
||||
$point->x === $xMin
|
||||
and
|
||||
$point->y >= $yMin
|
||||
and
|
||||
$point->y <= $yMax
|
||||
) {
|
||||
return TRUE;
|
||||
} else {
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
private function isOnBoxRightSide(awPoint $point, $yMin, $yMax, $xMax) {
|
||||
if(
|
||||
$point->x === $xMax
|
||||
and
|
||||
$point->y >= $yMin
|
||||
and
|
||||
$point->y <= $yMax
|
||||
) {
|
||||
return TRUE;
|
||||
} else {
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
registerClass('Line');
|
||||
|
||||
/**
|
||||
* A vector is a type of line
|
||||
* The sense of the vector goes from $p1 to $p2.
|
||||
*
|
||||
* @package Artichow
|
||||
*/
|
||||
class awVector extends awLine {
|
||||
|
||||
/**
|
||||
* Get vector angle in radians
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public function getAngle() {
|
||||
|
||||
if($this->isPoint()) {
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
$size = $this->getSize();
|
||||
|
||||
$width = ($this->p2->x - $this->p1->x);
|
||||
$height = ($this->p2->y - $this->p1->y) * -1;
|
||||
|
||||
if($width >= 0 and $height >= 0) {
|
||||
return acos($width / $size);
|
||||
} else if($width <= 0 and $height >= 0) {
|
||||
return acos($width / $size);
|
||||
} else {
|
||||
$height *= -1;
|
||||
if($width >= 0 and $height >= 0) {
|
||||
return 2 * M_PI - acos($width / $size);
|
||||
} else if($width <= 0 and $height >= 0) {
|
||||
return 2 * M_PI - acos($width / $size);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
registerClass('Vector');
|
||||
|
||||
|
||||
/**
|
||||
* Describe a polygon
|
||||
*
|
||||
* @package Artichow
|
||||
*/
|
||||
class awPolygon extends awShape {
|
||||
|
||||
/**
|
||||
* Polygon points
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $points = array();
|
||||
|
||||
/**
|
||||
* Set a point in the polygon
|
||||
*
|
||||
* @param int $pos Point position
|
||||
* @param awPoint $point
|
||||
*/
|
||||
public function set($pos, $point) {
|
||||
if(is_null($point) or $point instanceof awPoint) {
|
||||
$this->points[$pos] = $point;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a point at the end of the polygon
|
||||
*
|
||||
* @param awPoint $point
|
||||
*/
|
||||
public function append($point) {
|
||||
if(is_null($point) or $point instanceof awPoint) {
|
||||
$this->points[] = $point;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a point at a position in the polygon
|
||||
*
|
||||
* @param int $pos Point position
|
||||
* @return Point
|
||||
*/
|
||||
public function get($pos) {
|
||||
return $this->points[$pos];
|
||||
}
|
||||
|
||||
/**
|
||||
* Count number of points in the polygon
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function count() {
|
||||
return count($this->points);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all points in the polygon
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function all() {
|
||||
return $this->points;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the different lines formed by the polygon vertices
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getLines() {
|
||||
$lines = array();
|
||||
$count = $this->count();
|
||||
|
||||
for($i = 0; $i < $count - 1; $i++) {
|
||||
$lines[] = new Line($this->get($i), $this->get($i + 1));
|
||||
}
|
||||
|
||||
// "Close" the polygon
|
||||
$lines[] = new Line($this->get($count - 1), $this->get(0));
|
||||
|
||||
return $lines;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the upper-left and lower-right points
|
||||
* of the bounding box around the polygon
|
||||
*
|
||||
* @return array An array of two Point objects
|
||||
*/
|
||||
public function getBoxPoints() {
|
||||
$count = $this->count();
|
||||
$x = $y = array();
|
||||
|
||||
for($i = 0; $i < $count; $i++) {
|
||||
$point = $this->get($i);
|
||||
|
||||
list($x[], $y[]) = $point->getLocation();
|
||||
}
|
||||
|
||||
$upperLeft = new Point(min($x), min($y));
|
||||
$lowerRight = new Point(max($x), max($y));
|
||||
|
||||
return array($upperLeft, $lowerRight);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the range of the polygon on the y axis,
|
||||
* i.e. the minimum and maximum y value of any point in the polygon
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getBoxYRange() {
|
||||
list($p1, $p2) = $this->getBoxPoints();
|
||||
|
||||
list(, $yMin) = $p1->getLocation();
|
||||
list(, $yMax) = $p2->getLocation();
|
||||
|
||||
return array($yMin, $yMax);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the range of the polygon on the x axis,
|
||||
* i.e. the minimum and maximum x value of any point in the polygon
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getBoxXRange() {
|
||||
list($p1, $p2) = $this->getBoxPoints();
|
||||
|
||||
list($xMin, ) = $p1->getLocation();
|
||||
list($xMax, ) = $p2->getLocation();
|
||||
|
||||
return array($xMin, $xMax);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
registerClass('Polygon');
|
||||
@@ -1,405 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* This work is hereby released into the Public Domain.
|
||||
* To view a copy of the public domain dedication,
|
||||
* visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
|
||||
* Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__)."/../Graph.class.php";
|
||||
|
||||
|
||||
/**
|
||||
* Draw shadows
|
||||
*
|
||||
*/
|
||||
class awShadow {
|
||||
|
||||
/**
|
||||
* Shadow on left and top sides
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const LEFT_TOP = 1;
|
||||
|
||||
/**
|
||||
* Shadow on left and bottom sides
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const LEFT_BOTTOM = 2;
|
||||
|
||||
|
||||
/**
|
||||
* Shadow on right and top sides
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const RIGHT_TOP = 3;
|
||||
|
||||
/**
|
||||
* Shadow on right and bottom sides
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const RIGHT_BOTTOM = 4;
|
||||
|
||||
/**
|
||||
* In mode
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const IN = 1;
|
||||
|
||||
/**
|
||||
* Out mode
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const OUT = 2;
|
||||
|
||||
/**
|
||||
* Shadow size
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $size = 0;
|
||||
|
||||
/**
|
||||
* Hide shadow ?
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $hide = FALSE;
|
||||
|
||||
/**
|
||||
* Shadow color
|
||||
*
|
||||
* @var Color
|
||||
*/
|
||||
private $color;
|
||||
|
||||
/**
|
||||
* Shadow position
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $position;
|
||||
|
||||
/**
|
||||
* Smooth shadow ?
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
private $smooth = FALSE;
|
||||
|
||||
/**
|
||||
* Shadow constructor
|
||||
*
|
||||
* @param int $position Shadow position
|
||||
*/
|
||||
public function __construct($position) {
|
||||
$this->setPosition($position);
|
||||
}
|
||||
|
||||
/**
|
||||
* Hide shadow ?
|
||||
*
|
||||
* @param bool $hide
|
||||
*/
|
||||
public function hide($hide = TRUE) {
|
||||
$this->hide = (bool)$hide;
|
||||
}
|
||||
|
||||
/**
|
||||
* Show shadow ?
|
||||
*
|
||||
* @param bool $show
|
||||
*/
|
||||
public function show($show = TRUE) {
|
||||
$this->hide = (bool)!$show;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change shadow size
|
||||
*
|
||||
* @param int $size
|
||||
* @param bool $smooth Smooth the shadow (facultative argument)
|
||||
*/
|
||||
public function setSize($size, $smooth = NULL) {
|
||||
$this->size = (int)$size;
|
||||
if($smooth !== NULL) {
|
||||
$this->smooth($smooth);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Change shadow color
|
||||
*
|
||||
* @param awColor $color
|
||||
*/
|
||||
public function setColor(awColor $color) {
|
||||
$this->color = $color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change shadow position
|
||||
*
|
||||
* @param int $position
|
||||
*/
|
||||
public function setPosition($position) {
|
||||
$this->position = (int)$position;
|
||||
}
|
||||
|
||||
/**
|
||||
* Smooth shadow ?
|
||||
*
|
||||
* @param bool $smooth
|
||||
*/
|
||||
public function smooth($smooth) {
|
||||
$this->smooth = (bool)$smooth;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the space taken by the shadow
|
||||
*
|
||||
* @return Side
|
||||
*/
|
||||
public function getSpace() {
|
||||
|
||||
return new awSide(
|
||||
($this->position === awShadow::LEFT_TOP or $this->position === awShadow::LEFT_BOTTOM) ? $this->size : 0,
|
||||
($this->position === awShadow::RIGHT_TOP or $this->position === awShadow::RIGHT_BOTTOM) ? $this->size : 0,
|
||||
($this->position === awShadow::LEFT_TOP or $this->position === awShadow::RIGHT_TOP) ? $this->size : 0,
|
||||
($this->position === awShadow::LEFT_BOTTOM or $this->position === awShadow::RIGHT_BOTTOM) ? $this->size : 0
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw shadow
|
||||
*
|
||||
* @param awDriver $driver
|
||||
* @param awPoint $p1 Top-left point
|
||||
* @param awPoint $p2 Right-bottom point
|
||||
* @param int Drawing mode
|
||||
*/
|
||||
public function draw(awDriver $driver, awPoint $p1, awPoint $p2, $mode) {
|
||||
|
||||
if($this->hide) {
|
||||
return;
|
||||
}
|
||||
|
||||
if($this->size <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
$driver = clone $driver;
|
||||
|
||||
$color = ($this->color instanceof awColor) ? $this->color : new awColor(125, 125, 125);
|
||||
|
||||
switch($this->position) {
|
||||
|
||||
case awShadow::RIGHT_BOTTOM :
|
||||
|
||||
if($mode === awShadow::OUT) {
|
||||
$t1 = $p1->move(0, 0);
|
||||
$t2 = $p2->move($this->size + 1, $this->size + 1);
|
||||
} else { // PHP 4 compatibility
|
||||
$t1 = $p1->move(0, 0);
|
||||
$t2 = $p2->move(0, 0);
|
||||
}
|
||||
|
||||
$width = $t2->x - $t1->x;
|
||||
$height = $t2->y - $t1->y;
|
||||
|
||||
$driver->setAbsPosition($t1->x + $driver->x, $t1->y + $driver->y);
|
||||
|
||||
$driver->filledRectangle(
|
||||
$color,
|
||||
new awLine(
|
||||
new awPoint($width - $this->size, $this->size),
|
||||
new awPoint($width - 1, $height - 1)
|
||||
)
|
||||
);
|
||||
|
||||
$driver->filledRectangle(
|
||||
$color,
|
||||
new awLine(
|
||||
new awPoint($this->size, $height - $this->size),
|
||||
new awPoint($width - $this->size - 1, $height - 1)
|
||||
)
|
||||
);
|
||||
|
||||
$this->smoothPast($driver, $color, $width, $height);
|
||||
|
||||
break;
|
||||
|
||||
case awShadow::LEFT_TOP :
|
||||
|
||||
if($mode === awShadow::OUT) {
|
||||
$t1 = $p1->move(- $this->size, - $this->size);
|
||||
$t2 = $p2->move(0, 0);
|
||||
} else { // PHP 4 compatibility
|
||||
$t1 = $p1->move(0, 0);
|
||||
$t2 = $p2->move(0, 0);
|
||||
}
|
||||
|
||||
$width = $t2->x - $t1->x;
|
||||
$height = $t2->y - $t1->y;
|
||||
|
||||
$driver->setAbsPosition($t1->x + $driver->x, $t1->y + $driver->y);
|
||||
|
||||
$height = max($height + 1, $this->size);
|
||||
|
||||
$driver->filledRectangle(
|
||||
$color,
|
||||
new awLine(
|
||||
new awPoint(0, 0),
|
||||
new awPoint($this->size - 1, $height - $this->size - 1)
|
||||
)
|
||||
);
|
||||
|
||||
$driver->filledRectangle(
|
||||
$color,
|
||||
new awLine(
|
||||
new awPoint($this->size, 0),
|
||||
new awPoint($width - $this->size - 1, $this->size - 1)
|
||||
)
|
||||
);
|
||||
|
||||
$this->smoothPast($driver, $color, $width, $height);
|
||||
|
||||
break;
|
||||
|
||||
case awShadow::RIGHT_TOP :
|
||||
|
||||
if($mode === awShadow::OUT) {
|
||||
$t1 = $p1->move(0, - $this->size);
|
||||
$t2 = $p2->move($this->size + 1, 0);
|
||||
} else { // PHP 4 compatibility
|
||||
$t1 = $p1->move(0, 0);
|
||||
$t2 = $p2->move(0, 0);
|
||||
}
|
||||
|
||||
$width = $t2->x - $t1->x;
|
||||
$height = $t2->y - $t1->y;
|
||||
|
||||
$driver->setAbsPosition($t1->x + $driver->x, $t1->y + $driver->y);
|
||||
|
||||
$height = max($height + 1, $this->size);
|
||||
|
||||
$driver->filledRectangle(
|
||||
$color,
|
||||
new awLine(
|
||||
new awPoint($width - $this->size, 0),
|
||||
new awPoint($width - 1, $height - $this->size - 1)
|
||||
)
|
||||
);
|
||||
|
||||
$driver->filledRectangle(
|
||||
$color,
|
||||
new awLine(
|
||||
new awPoint($this->size, 0),
|
||||
new awPoint($width - $this->size - 1, $this->size - 1)
|
||||
)
|
||||
);
|
||||
|
||||
$this->smoothFuture($driver, $color, $width, $height);
|
||||
|
||||
break;
|
||||
|
||||
case awShadow::LEFT_BOTTOM :
|
||||
|
||||
if($mode === awShadow::OUT) {
|
||||
$t1 = $p1->move(- $this->size, 0);
|
||||
$t2 = $p2->move(0, $this->size + 1);
|
||||
} else { // PHP 4 compatibility
|
||||
$t1 = $p1->move(0, 0);
|
||||
$t2 = $p2->move(0, 0);
|
||||
}
|
||||
|
||||
$width = $t2->x - $t1->x;
|
||||
$height = $t2->y - $t1->y;
|
||||
|
||||
$driver->setAbsPosition($t1->x + $driver->x, $t1->y + $driver->y);
|
||||
|
||||
$driver->filledRectangle(
|
||||
$color,
|
||||
new awLine(
|
||||
new awPoint(0, $this->size),
|
||||
new awPoint($this->size - 1, $height - 1)
|
||||
)
|
||||
);
|
||||
|
||||
$driver->filledRectangle(
|
||||
$color,
|
||||
new awLine(
|
||||
new awPoint($this->size, $height - $this->size),
|
||||
new awPoint($width - $this->size - 1, $height - 1)
|
||||
)
|
||||
);
|
||||
|
||||
$this->smoothFuture($driver, $color, $width, $height);
|
||||
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private function smoothPast(awDriver $driver, awColor $color, $width, $height) {
|
||||
|
||||
if($this->smooth) {
|
||||
|
||||
for($i = 0; $i < $this->size; $i++) {
|
||||
for($j = 0; $j <= $i; $j++) {
|
||||
$driver->point(
|
||||
$color,
|
||||
new awPoint($i, $j + $height - $this->size)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
for($i = 0; $i < $this->size; $i++) {
|
||||
for($j = 0; $j <= $i; $j++) {
|
||||
$driver->point(
|
||||
$color,
|
||||
new awPoint($width - $this->size + $j, $i)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private function smoothFuture(awDriver $driver, awColor $color, $width, $height) {
|
||||
|
||||
if($this->smooth) {
|
||||
|
||||
for($i = 0; $i < $this->size; $i++) {
|
||||
for($j = 0; $j <= $i; $j++) {
|
||||
$driver->point(
|
||||
$color,
|
||||
new awPoint($i, $this->size - $j - 1)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
for($i = 0; $i < $this->size; $i++) {
|
||||
for($j = 0; $j <= $i; $j++) {
|
||||
$driver->point(
|
||||
$color,
|
||||
new awPoint($width - $this->size + $j, $height - $i - 1)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
registerClass('Shadow');
|
||||
@@ -1,233 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* This work is hereby released into the Public Domain.
|
||||
* To view a copy of the public domain dedication,
|
||||
* visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
|
||||
* Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__)."/../Graph.class.php";
|
||||
|
||||
/**
|
||||
* To handle text
|
||||
*
|
||||
* @package Artichow
|
||||
*/
|
||||
class awText {
|
||||
|
||||
/**
|
||||
* Your text
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $text;
|
||||
|
||||
/**
|
||||
* Text font
|
||||
*
|
||||
* @var Font
|
||||
*/
|
||||
private $font;
|
||||
|
||||
/**
|
||||
* Text angle
|
||||
* Can be 0 or 90
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $angle;
|
||||
|
||||
/**
|
||||
* Text color
|
||||
*
|
||||
* @var Color
|
||||
*/
|
||||
private $color;
|
||||
|
||||
/**
|
||||
* Text background
|
||||
*
|
||||
* @var Color, Gradient
|
||||
*/
|
||||
private $background;
|
||||
|
||||
/**
|
||||
* Padding
|
||||
*
|
||||
* @var array Array for left, right, top and bottom paddings
|
||||
*/
|
||||
private $padding;
|
||||
|
||||
/**
|
||||
* Text border
|
||||
*
|
||||
* @var Border
|
||||
*/
|
||||
public $border;
|
||||
|
||||
/**
|
||||
* Build a new awtext
|
||||
*
|
||||
* @param string $text Your text
|
||||
*/
|
||||
public function __construct($text, $font = NULL, $color = NULL, $angle = 0) {
|
||||
|
||||
if(is_null($font)) {
|
||||
$font = new awFont2;
|
||||
}
|
||||
|
||||
$this->setText($text);
|
||||
$this->setFont($font);
|
||||
|
||||
// Set default color to black
|
||||
if($color === NULL) {
|
||||
$color = new awColor(0, 0, 0);
|
||||
}
|
||||
|
||||
$this->setColor($color);
|
||||
$this->setAngle($angle);
|
||||
|
||||
$this->border = new awBorder;
|
||||
$this->border->hide();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get text
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getText() {
|
||||
return $this->text;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change text
|
||||
*
|
||||
* @param string $text New text
|
||||
*/
|
||||
public function setText($text) {
|
||||
$this->text = (string)$text;
|
||||
$this->text = str_replace("\r", "", $text);
|
||||
}
|
||||
|
||||
/**
|
||||
* Change text font
|
||||
*
|
||||
* @param Font
|
||||
*/
|
||||
public function setFont(awFont $font) {
|
||||
$this->font = $font;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get text font
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getFont() {
|
||||
return $this->font;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change text angle
|
||||
*
|
||||
* @param int
|
||||
*/
|
||||
public function setAngle($angle) {
|
||||
$this->angle = (int)$angle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get text angle
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getAngle() {
|
||||
return $this->angle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change text color
|
||||
*
|
||||
* @param Color
|
||||
*/
|
||||
public function setColor(awColor $color) {
|
||||
$this->color = $color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get text color
|
||||
*
|
||||
* @return Color
|
||||
*/
|
||||
public function getColor() {
|
||||
return $this->color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change text background
|
||||
*
|
||||
* @param mixed $background
|
||||
*/
|
||||
public function setBackground($background) {
|
||||
if($background instanceof awColor) {
|
||||
$this->setBackgroundColor($background);
|
||||
} elseif($background instanceof awGradient) {
|
||||
$this->setBackgroundGradient($background);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Change text background color
|
||||
*
|
||||
* @param awColor $color
|
||||
*/
|
||||
public function setBackgroundColor(awColor $color) {
|
||||
$this->background = $color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change text background gradient
|
||||
*
|
||||
* @param awGradient $gradient
|
||||
*/
|
||||
public function setBackgroundGradient(awGradient $gradient) {
|
||||
$this->background = $gradient;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get text background
|
||||
*
|
||||
* @return Color, Gradient
|
||||
*/
|
||||
public function getBackground() {
|
||||
return $this->background;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change padding
|
||||
*
|
||||
* @param int $left Left padding
|
||||
* @param int $right Right padding
|
||||
* @param int $top Top padding
|
||||
* @param int $bottom Bottom padding
|
||||
*/
|
||||
public function setPadding($left, $right, $top, $bottom) {
|
||||
$this->padding = array((int)$left, (int)$right, (int)$top, (int)$bottom);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get current padding
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getPadding() {
|
||||
return $this->padding;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
registerClass('Text');
|
||||
|
||||
@@ -1,343 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* This work is hereby released into the Public Domain.
|
||||
* To view a copy of the public domain dedication,
|
||||
* visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
|
||||
* Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__)."/../Graph.class.php";
|
||||
|
||||
|
||||
/**
|
||||
* Handle ticks
|
||||
*
|
||||
* @package Artichow
|
||||
*/
|
||||
class awTick {
|
||||
|
||||
/**
|
||||
* Ticks style
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $style = awTick::IN;
|
||||
|
||||
/**
|
||||
* Ticks size
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $size;
|
||||
|
||||
/**
|
||||
* Ticks color
|
||||
*
|
||||
* @var Color
|
||||
*/
|
||||
protected $color;
|
||||
|
||||
/**
|
||||
* Ticks number
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $number;
|
||||
|
||||
/**
|
||||
* Ticks number by other tick
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $numberByTick;
|
||||
|
||||
/**
|
||||
* Ticks interval
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $interval = 1;
|
||||
|
||||
/**
|
||||
* Hide ticks
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $hide = FALSE;
|
||||
|
||||
/**
|
||||
* Hide first tick
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $hideFirst = FALSE;
|
||||
|
||||
/**
|
||||
* Hide last tick
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $hideLast = FALSE;
|
||||
|
||||
/**
|
||||
* In mode
|
||||
*
|
||||
* @param int
|
||||
*/
|
||||
const IN = 0;
|
||||
|
||||
/**
|
||||
* Out mode
|
||||
*
|
||||
* @param int
|
||||
*/
|
||||
const OUT = 1;
|
||||
|
||||
/**
|
||||
* In and out mode
|
||||
*
|
||||
* @param int
|
||||
*/
|
||||
const IN_OUT = 2;
|
||||
|
||||
/**
|
||||
* Build the ticks
|
||||
*
|
||||
* @param int $number Number of ticks
|
||||
* @param int $size Ticks size
|
||||
*/
|
||||
public function __construct($number, $size) {
|
||||
|
||||
$this->setSize($size);
|
||||
$this->setNumber($number);
|
||||
$this->setColor(new awBlack);
|
||||
$this->style = awTick::IN;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Change ticks style
|
||||
*
|
||||
* @param int $style
|
||||
*/
|
||||
public function setStyle($style) {
|
||||
$this->style = (int)$style;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get ticks style
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getStyle() {
|
||||
return $this->style;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change ticks color
|
||||
*
|
||||
* @param awColor $color
|
||||
*/
|
||||
public function setColor(awColor $color) {
|
||||
$this->color = $color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change ticks size
|
||||
*
|
||||
* @param int $size
|
||||
*/
|
||||
public function setSize($size) {
|
||||
$this->size = (int)$size;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change interval of ticks
|
||||
*
|
||||
* @param int $interval
|
||||
*/
|
||||
public function setInterval($interval) {
|
||||
$this->interval = (int)$interval;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get interval between each tick
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getInterval() {
|
||||
return $this->interval;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change number of ticks
|
||||
*
|
||||
* @param int $number
|
||||
*/
|
||||
public function setNumber($number) {
|
||||
$this->number = (int)$number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get number of ticks
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getNumber() {
|
||||
return $this->number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change number of ticks relative to others ticks
|
||||
*
|
||||
* @param awTick $tick Ticks reference
|
||||
* @param int $number Number of ticks
|
||||
*/
|
||||
public function setNumberByTick(awTick $tick, $number) {
|
||||
|
||||
$this->numberByTick = array($tick, (int)$number);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Hide ticks
|
||||
*
|
||||
* @param bool $hide
|
||||
*/
|
||||
public function hide($hide) {
|
||||
$this->hide = (bool)$hide;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hide first tick
|
||||
*
|
||||
* @param bool $hide
|
||||
*/
|
||||
public function hideFirst($hide) {
|
||||
$this->hideFirst = (bool)$hide;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hide last tick
|
||||
*
|
||||
* @param bool $hide
|
||||
*/
|
||||
public function hideLast($hide) {
|
||||
$this->hideLast = (bool)$hide;
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw ticks on a vector
|
||||
*
|
||||
* @param awDriver $driver A driver
|
||||
* @param awVector $vector A vector
|
||||
*/
|
||||
public function draw(awDriver $driver, awVector $vector) {
|
||||
|
||||
if($this->numberByTick !== NULL) {
|
||||
list($tick, $number) = $this->numberByTick;
|
||||
$this->number = 1 + ($tick->getNumber() - 1) * ($number + 1);
|
||||
$this->interval = $tick->getInterval();
|
||||
}
|
||||
|
||||
if($this->number < 2 or $this->hide) {
|
||||
return;
|
||||
}
|
||||
|
||||
$angle = $vector->getAngle();
|
||||
// echo "INIT:".$angle."<br>";
|
||||
switch($this->style) {
|
||||
|
||||
case awTick::IN :
|
||||
$this->drawTicks($driver, $vector, NULL, $angle + M_PI / 2);
|
||||
break;
|
||||
|
||||
case awTick::OUT :
|
||||
$this->drawTicks($driver, $vector, $angle + 3 * M_PI / 2, NULL);
|
||||
break;
|
||||
|
||||
default :
|
||||
$this->drawTicks($driver, $vector, $angle + M_PI / 2, $angle + 3 * M_PI / 2);
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected function drawTicks(awDriver $driver, awVector $vector, $from, $to) {
|
||||
|
||||
// Draw last tick
|
||||
if($this->hideLast === FALSE) {
|
||||
|
||||
//echo '<b>';
|
||||
if(($this->number - 1) % $this->interval === 0) {
|
||||
$this->drawTick($driver, $vector->p2, $from, $to);
|
||||
}
|
||||
//echo '</b>';
|
||||
|
||||
}
|
||||
|
||||
$number = $this->number - 1;
|
||||
$size = $vector->getSize();
|
||||
|
||||
// Get tick increment in pixels
|
||||
$inc = $size / $number;
|
||||
|
||||
// Check if we must hide the first tick
|
||||
$start = $this->hideFirst ? $inc : 0;
|
||||
$stop = $inc * $number;
|
||||
|
||||
$position = 0;
|
||||
|
||||
for($i = $start; round($i, 6) < $stop; $i += $inc) {
|
||||
|
||||
if($position % $this->interval === 0) {
|
||||
$p = $vector->p1->move(
|
||||
round($i * cos($vector->getAngle()), 6),
|
||||
round($i * sin($vector->getAngle() * -1), 6)
|
||||
);
|
||||
$this->drawTick($driver, $p, $from, $to);
|
||||
}
|
||||
|
||||
$position++;
|
||||
|
||||
}
|
||||
//echo '<br><br>';
|
||||
}
|
||||
|
||||
protected function drawTick(awDriver $driver, awPoint $p, $from, $to) {
|
||||
// echo $this->size.':'.$angle.'|<b>'.cos($angle).'</b>/';
|
||||
// The round avoid some errors in the calcul
|
||||
// For example, 12.00000008575245 becomes 12
|
||||
$p1 = $p;
|
||||
$p2 = $p;
|
||||
|
||||
if($from !== NULL) {
|
||||
$p1 = $p1->move(
|
||||
round($this->size * cos($from), 6),
|
||||
round($this->size * sin($from) * -1, 6)
|
||||
);
|
||||
}
|
||||
|
||||
if($to !== NULL) {
|
||||
$p2 = $p2->move(
|
||||
round($this->size * cos($to), 6),
|
||||
round($this->size * sin($to) * -1, 6)
|
||||
);
|
||||
}
|
||||
//echo $p1->x.':'.$p2->x.'('.$p1->y.':'.$p2->y.')'.'/';
|
||||
$vector = new awVector(
|
||||
$p1, $p2
|
||||
);
|
||||
|
||||
$driver->line(
|
||||
$this->color,
|
||||
$vector
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
registerClass('Tick');
|
||||
@@ -1,174 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* This work is hereby released into the Public Domain.
|
||||
* To view a copy of the public domain dedication,
|
||||
* visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
|
||||
* Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__)."/../Graph.class.php";
|
||||
|
||||
/**
|
||||
* Objects capable of being positioned
|
||||
*
|
||||
* @package Artichow
|
||||
*/
|
||||
interface awPositionable {
|
||||
|
||||
/**
|
||||
* Left align
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const LEFT = 1;
|
||||
|
||||
/**
|
||||
* Right align
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const RIGHT = 2;
|
||||
|
||||
/**
|
||||
* Center align
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const CENTER = 3;
|
||||
|
||||
/**
|
||||
* Top align
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const TOP = 4;
|
||||
|
||||
/**
|
||||
* Bottom align
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const BOTTOM = 5;
|
||||
|
||||
/**
|
||||
* Middle align
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const MIDDLE = 6;
|
||||
|
||||
/**
|
||||
* Change alignment
|
||||
*
|
||||
* @param int $h Horizontal alignment
|
||||
* @param int $v Vertical alignment
|
||||
*/
|
||||
public function setAlign($h = NULL, $v = NULL);
|
||||
|
||||
}
|
||||
|
||||
registerInterface('Positionable');
|
||||
|
||||
/**
|
||||
* Manage left, right, top and bottom sides
|
||||
*
|
||||
* @package Artichow
|
||||
*/
|
||||
class awSide {
|
||||
|
||||
/**
|
||||
* Left side
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $left = 0;
|
||||
|
||||
/**
|
||||
* Right side
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $right = 0;
|
||||
|
||||
/**
|
||||
* Top side
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $top = 0;
|
||||
|
||||
/**
|
||||
* Bottom side
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $bottom = 0;
|
||||
|
||||
/**
|
||||
* Build the side
|
||||
*
|
||||
* @param mixed $left
|
||||
* @param mixed $right
|
||||
* @param mixed $top
|
||||
* @param mixed $bottom
|
||||
*/
|
||||
public function __construct($left = NULL, $right = NULL, $top = NULL, $bottom = NULL) {
|
||||
$this->set($left, $right, $top, $bottom);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Change side values
|
||||
*
|
||||
* @param mixed $left
|
||||
* @param mixed $right
|
||||
* @param mixed $top
|
||||
* @param mixed $bottom
|
||||
*/
|
||||
public function set($left = NULL, $right = NULL, $top = NULL, $bottom = NULL) {
|
||||
|
||||
if($left !== NULL) {
|
||||
$this->left = (float)$left;
|
||||
}
|
||||
if($right !== NULL) {
|
||||
$this->right = (float)$right;
|
||||
}
|
||||
if($top !== NULL) {
|
||||
$this->top = (float)$top;
|
||||
}
|
||||
if($bottom !== NULL) {
|
||||
$this->bottom = (float)$bottom;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add values to each side
|
||||
*
|
||||
* @param mixed $left
|
||||
* @param mixed $right
|
||||
* @param mixed $top
|
||||
* @param mixed $bottom
|
||||
*/
|
||||
public function add($left = NULL, $right = NULL, $top = NULL, $bottom = NULL) {
|
||||
|
||||
if($left !== NULL) {
|
||||
$this->left += (float)$left;
|
||||
}
|
||||
if($right !== NULL) {
|
||||
$this->right += (float)$right;
|
||||
}
|
||||
if($top !== NULL) {
|
||||
$this->top += (float)$top;
|
||||
}
|
||||
if($bottom !== NULL) {
|
||||
$this->bottom += (float)$bottom;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
registerClass('Side');
|
||||
@@ -1,35 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* 2007-2013 PrestaShop
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License (AFL 3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://opensource.org/licenses/afl-3.0.php
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
|
||||
* versions in the future. If you wish to customize PrestaShop for your
|
||||
* needs please refer to http://www.prestashop.com for more information.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2013 PrestaShop SA
|
||||
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
|
||||
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
|
||||
|
||||
header("Cache-Control: no-store, no-cache, must-revalidate");
|
||||
header("Cache-Control: post-check=0, pre-check=0", false);
|
||||
header("Pragma: no-cache");
|
||||
|
||||
header("Location: ../");
|
||||
exit;
|
||||
@@ -1,773 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* This work is hereby released into the Public Domain.
|
||||
* To view a copy of the public domain dedication,
|
||||
* visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
|
||||
* Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__)."/../Driver.class.php";
|
||||
|
||||
/**
|
||||
* Draw your objects
|
||||
*
|
||||
* @package Artichow
|
||||
*/
|
||||
class awMingDriver extends awDriver {
|
||||
|
||||
/**
|
||||
* The Flash movie
|
||||
*
|
||||
* @var $movie
|
||||
*/
|
||||
public $movie;
|
||||
|
||||
public function __construct() {
|
||||
|
||||
parent::__construct();
|
||||
|
||||
$this->driverString = 'ming';
|
||||
|
||||
// Nice defaults
|
||||
ming_setScale(20.0);
|
||||
ming_useswfversion(6);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the driver for a particular awImage object
|
||||
*
|
||||
* @param awImage $image
|
||||
*/
|
||||
public function init(awImage $image) {
|
||||
|
||||
if($this->movie === NULL) {
|
||||
$this->setImageSize($image->width, $image->height);
|
||||
|
||||
// Create movie
|
||||
$this->movie = new SWFMovie();
|
||||
if(!$this->movie) {
|
||||
awImage::drawError("Class Image: Unable to create a graph.");
|
||||
}
|
||||
|
||||
$this->movie->setDimension($image->width, $image->height);
|
||||
|
||||
$this->setAntiAliasing($image->getAntiAliasing());
|
||||
|
||||
// Original color
|
||||
$this->filledRectangle(
|
||||
new awWhite,
|
||||
new awLine(
|
||||
new awPoint(0, 0),
|
||||
new awPoint($this->imageWidth, $this->imageHeight)
|
||||
)
|
||||
);
|
||||
|
||||
$shadow = $image->shadow;
|
||||
if($shadow !== NULL) {
|
||||
$shadow = $shadow->getSpace();
|
||||
$p1 = new awPoint($shadow->left, $shadow->top);
|
||||
$p2 = new awPoint($this->imageWidth - $shadow->right - 1, $this->imageHeight - $shadow->bottom - 1);
|
||||
|
||||
// Draw image background
|
||||
$this->filledRectangle($image->getBackground(), new awLine($p1, $p2));
|
||||
|
||||
// Draw image border
|
||||
$image->border->rectangle($this, $p1, $p2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the Driver for a particular FileImage object
|
||||
*
|
||||
* @param awFileImage $fileImage The FileImage object to work on
|
||||
* @param string $file Image filename
|
||||
*/
|
||||
public function initFromFile(awFileImage $fileImage, $file) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the image size
|
||||
*
|
||||
* @param int $width Image width
|
||||
* @param int $height Image height
|
||||
*/
|
||||
public function setImageSize($width, $height) {
|
||||
$this->imageWidth = $width;
|
||||
$this->imageHeight = $height;
|
||||
}
|
||||
|
||||
/**
|
||||
* Inform the driver of the position of your image
|
||||
*
|
||||
* @param float $x Position on X axis of the center of the component
|
||||
* @param float $y Position on Y axis of the center of the component
|
||||
*/
|
||||
public function setPosition($x, $y) {
|
||||
// Calculate absolute position
|
||||
$this->x = round($x * $this->imageWidth - $this->w / 2);
|
||||
$this->y = round($y * $this->imageHeight - $this->h / 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Inform the driver of the position of your image
|
||||
* This method need absolutes values
|
||||
*
|
||||
* @param int $x Left-top corner X position
|
||||
* @param int $y Left-top corner Y position
|
||||
*/
|
||||
public function setAbsPosition($x, $y) {
|
||||
$this->x = $x;
|
||||
$this->y = $y;
|
||||
}
|
||||
|
||||
/**
|
||||
* Move the position of the image
|
||||
*
|
||||
* @param int $x Add this value to X axis
|
||||
* @param int $y Add this value to Y axis
|
||||
*/
|
||||
public function movePosition($x, $y) {
|
||||
$this->x += (int)$x;
|
||||
$this->y += (int)$y;
|
||||
}
|
||||
|
||||
/**
|
||||
* Inform the driver of the size of your image
|
||||
* Height and width must be between 0 and 1.
|
||||
*
|
||||
* @param int $w Image width
|
||||
* @param int $h Image height
|
||||
* @return array Absolute width and height of the image
|
||||
*/
|
||||
public function setSize($w, $h) {
|
||||
|
||||
// Calcul absolute size
|
||||
$this->w = round($w * $this->imageWidth);
|
||||
$this->h = round($h * $this->imageHeight);
|
||||
|
||||
return $this->getSize();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Inform the driver of the size of your image
|
||||
* You can set absolute size with this method.
|
||||
*
|
||||
* @param int $w Image width
|
||||
* @param int $h Image height
|
||||
*/
|
||||
public function setAbsSize($w, $h) {
|
||||
$this->w = $w;
|
||||
$this->h = $h;
|
||||
|
||||
return $this->getSize();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the size of the component handled by the driver
|
||||
*
|
||||
* @return array Absolute width and height of the component
|
||||
*/
|
||||
public function getSize() {
|
||||
return array($this->w, $this->h);
|
||||
}
|
||||
|
||||
/**
|
||||
* Turn antialiasing on or off
|
||||
*
|
||||
* @var bool $bool
|
||||
*/
|
||||
public function setAntiAliasing($bool) {
|
||||
if($this->movie !== NULL) {
|
||||
|
||||
$actionscript = '
|
||||
_quality = "%s";
|
||||
';
|
||||
|
||||
if((bool)$bool) {
|
||||
$actionscript = sprintf($actionscript, 'high');
|
||||
} else {
|
||||
$actionscript = sprintf($actionscript, 'low');
|
||||
}
|
||||
|
||||
$this->movie->add(new SWFAction(str_replace("\r", "", $actionscript)));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* When passed a Color object, returns the corresponding
|
||||
* color identifier (driver dependant).
|
||||
*
|
||||
* @param awColor $color A Color object
|
||||
* @return array $rgba A color identifier representing the color composed of the given RGB components
|
||||
*/
|
||||
public function getColor(awColor $color) {
|
||||
|
||||
// Ming simply works with R, G, B and Alpha values.
|
||||
list($red, $green, $blue, $alpha) = $color->rgba();
|
||||
|
||||
// However, the Ming alpha channel ranges from 255 (opaque) to 0 (transparent),
|
||||
// while the awColor alpha channel ranges from 0 (opaque) to 100 (transparent).
|
||||
// First, we convert from 0-100 to 0-255.
|
||||
$alpha = (int)($alpha * 255 / 100);
|
||||
|
||||
// Then from 0-255 to 255-0.
|
||||
$alpha = abs($alpha - 255);
|
||||
|
||||
return array($red, $green, $blue, $alpha);
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw an image here
|
||||
*
|
||||
* @param awImage $image Image
|
||||
* @param int $p1 Image top-left point
|
||||
* @param int $p2 Image bottom-right point
|
||||
*/
|
||||
public function copyImage(awImage $image, awPoint $p1, awPoint $p2) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw an image here
|
||||
*
|
||||
* @param awImage $image Image
|
||||
* @param int $d1 Destination top-left position
|
||||
* @param int $d2 Destination bottom-right position
|
||||
* @param int $s1 Source top-left position
|
||||
* @param int $s2 Source bottom-right position
|
||||
* @param bool $resample Resample image ? (default to TRUE)
|
||||
*/
|
||||
public function copyResizeImage(awImage $image, awPoint $d1, awPoint $d2, awPoint $s1, awPoint $s2, $resample = TRUE) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw a string
|
||||
*
|
||||
* @var awText $text Text to print
|
||||
* @param awPoint $point Draw the text at this point
|
||||
* @param int $width Text max width
|
||||
*/
|
||||
public function string(awText $text, awPoint $point, $width = NULL) {
|
||||
$font = $text->getFont();
|
||||
|
||||
// Can we deal with that font?
|
||||
if($this->isCompatibleWithFont($font) === FALSE) {
|
||||
awImage::drawError('Class MingDriver: Incompatible font type (\''.get_class($font).'\')');
|
||||
}
|
||||
|
||||
// Ming can only work with awFileFont objects for now
|
||||
// (i.e. awFDBFont, or awTuffy et al.)
|
||||
$fontDriver = $this->fileFontDriver;
|
||||
|
||||
if($text->getBackground() !== NULL or $text->border->visible()) {
|
||||
|
||||
list($left, $right, $top, $bottom) = $text->getPadding();
|
||||
|
||||
$textWidth = $fontDriver->getTextWidth($text, $this);
|
||||
$textHeight = $fontDriver->getTextHeight($text, $this);
|
||||
|
||||
$x1 = floor($point->x - $left);
|
||||
$y1 = floor($point->y - $top);
|
||||
$x2 = $x1 + $textWidth + $left + $right;
|
||||
$y2 = $y1 + $textHeight + $top + $bottom;
|
||||
|
||||
$this->filledRectangle(
|
||||
$text->getBackground(),
|
||||
awLine::build($x1, $y1, $x2, $y2)
|
||||
);
|
||||
|
||||
$text->border->rectangle(
|
||||
$this,
|
||||
new awPoint($x1 - 1, $y1 - 1),
|
||||
new awPoint($x2 + 1, $y2 + 1)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
$fontDriver->string($this, $text, $point, $width);
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw a pixel
|
||||
*
|
||||
* @param awColor $color Pixel color
|
||||
* @param awPoint $p
|
||||
*/
|
||||
public function point(awColor $color, awPoint $p) {
|
||||
if($p->isHidden() === FALSE) {
|
||||
list($red, $green, $blue, $alpha) = $this->getColor($color);
|
||||
|
||||
$point = new SWFShape();
|
||||
$point->setLine(1, $red, $green, $blue, $alpha);
|
||||
$point->movePenTo($this->x + round($p->x), $this->y + round($p->y));
|
||||
$point->drawLine(0.5, 0.5);
|
||||
$point->movePen(-0.5, 0);
|
||||
$point->drawLine(0.5, -0.5);
|
||||
|
||||
$this->movie->add($point);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw a colored line
|
||||
*
|
||||
* @param awColor $color Line color
|
||||
* @param awLine $line
|
||||
* @param int $thickness Line tickness
|
||||
*/
|
||||
public function line(awColor $color, awLine $line) {
|
||||
if($line->getThickness() > 0 and $line->isHidden() === FALSE) {
|
||||
|
||||
list($red, $green, $blue, $alpha) = $this->getColor($color);
|
||||
|
||||
$mingLine = new SWFShape();
|
||||
$mingLine->setLine($line->getThickness(), $red, $green, $blue, $alpha);
|
||||
|
||||
list($p1, $p2) = $line->getLocation();
|
||||
|
||||
$mingLine->movePenTo($this->x + round($p1->x), $this->y + round($p1->y));
|
||||
|
||||
switch($line->getStyle()) {
|
||||
|
||||
case awLine::SOLID :
|
||||
$mingLine->drawLineTo($this->x + round($p2->x), $this->y + round($p2->y));
|
||||
$this->movie->add($mingLine);
|
||||
break;
|
||||
|
||||
case awLine::DOTTED :
|
||||
$size = sqrt(pow($p2->y - $p1->y, 2) + pow($p2->x - $p1->x, 2));
|
||||
$cos = ($p2->x - $p1->x) / $size;
|
||||
$sin = ($p2->y - $p1->y) / $size;
|
||||
|
||||
for($i = 0; $i <= $size; $i += 2) {
|
||||
$p = new awPoint(
|
||||
round($i * $cos + $p1->x),
|
||||
round($i * $sin + $p1->y)
|
||||
);
|
||||
$this->point($color, $p);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case awLine::DASHED :
|
||||
$width = $p2->x - $p1->x;
|
||||
$height = $p2->y - $p1->y;
|
||||
$size = sqrt(pow($height, 2) + pow($width, 2));
|
||||
|
||||
if($size == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
$cos = $width / $size;
|
||||
$sin = $height / $size;
|
||||
|
||||
$functionX = ($width > 0) ? 'min' : 'max';
|
||||
$functionY = ($height > 0) ? 'min' : 'max';
|
||||
|
||||
for($i = 0; $i <= $size; $i += 6) {
|
||||
|
||||
$t1 = new awPoint(
|
||||
round($i * $cos + $p1->x),
|
||||
round($i * $sin + $p1->y)
|
||||
);
|
||||
|
||||
$t2 = new awPoint(
|
||||
round($functionX(($i + 3) * $cos, $width) + $p1->x),
|
||||
round($functionY(($i + 3) * $sin, $height) + $p1->y)
|
||||
);
|
||||
|
||||
$this->line($color, new awLine($t1, $t2));
|
||||
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw a color arc
|
||||
|
||||
* @param awColor $color Arc color
|
||||
* @param awPoint $center Point center
|
||||
* @param int $width Ellipse width
|
||||
* @param int $height Ellipse height
|
||||
* @param int $from Start angle
|
||||
* @param int $to End angle
|
||||
*/
|
||||
public function arc(awColor $color, awPoint $center, $width, $height, $from, $to) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw an arc with a background color
|
||||
*
|
||||
* @param awColor $color Arc background color
|
||||
* @param awPoint $center Point center
|
||||
* @param int $width Ellipse width
|
||||
* @param int $height Ellipse height
|
||||
* @param int $from Start angle
|
||||
* @param int $to End angle
|
||||
*/
|
||||
public function filledArc(awColor $color, awPoint $center, $width, $height, $from, $to) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw a colored ellipse
|
||||
*
|
||||
* @param awColor $color Ellipse color
|
||||
* @param awPoint $center Ellipse center
|
||||
* @param int $width Ellipse width
|
||||
* @param int $height Ellipse height
|
||||
*/
|
||||
public function ellipse(awColor $color, awPoint $center, $width, $height) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw an ellipse with a background
|
||||
*
|
||||
* @param mixed $background Background (can be a color or a gradient)
|
||||
* @param awPoint $center Ellipse center
|
||||
* @param int $width Ellipse width
|
||||
* @param int $height Ellipse height
|
||||
*/
|
||||
public function filledEllipse($background, awPoint $center, $width, $height) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw a colored rectangle
|
||||
*
|
||||
* @param awColor $color Rectangle color
|
||||
* @param awLine $line Rectangle diagonale
|
||||
* @param awPoint $p2
|
||||
*/
|
||||
public function rectangle(awColor $color, awLine $line) {
|
||||
list($p1, $p2) = $line->getLocation();
|
||||
|
||||
// Get Red, Green, Blue and Alpha values for the line
|
||||
list($r, $g, $b, $a) = $this->getColor($color);
|
||||
|
||||
// Calculate the coordinates of the two other points of the rectangle
|
||||
$p3 = new Point($p1->x, $p2->y);
|
||||
$p4 = new Point($p2->x, $p1->y);
|
||||
|
||||
|
||||
$side = clone $line;
|
||||
|
||||
|
||||
|
||||
// Draw the four sides of the rectangle, clockwise
|
||||
if(
|
||||
($p1->x <= $p2->x and $p1->y <= $p2->y)
|
||||
or
|
||||
($p1->x >= $p2->x and $p1->y >= $p2->y)
|
||||
) {
|
||||
$side->setLocation($p1, $p4);
|
||||
$this->line($color, $side);
|
||||
|
||||
$side->setLocation($p4, $p2);
|
||||
$this->line($color, $side);
|
||||
|
||||
$side->setLocation($p2, $p3);
|
||||
$this->line($color, $side);
|
||||
|
||||
$side->setLocation($p3, $p1);
|
||||
$this->line($color, $side);
|
||||
} else {
|
||||
$side->setLocation($p1, $p3);
|
||||
$this->line($color, $side);
|
||||
|
||||
$side->setLocation($p3, $p2);
|
||||
$this->line($color, $side);
|
||||
|
||||
$side->setLocation($p2, $p4);
|
||||
$this->line($color, $side);
|
||||
|
||||
$side->setLocation($p4, $p1);
|
||||
$this->line($color, $side);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw a rectangle with a background
|
||||
*
|
||||
* @param mixed $background Background (can be a color or a gradient)
|
||||
* @param awLine $line Rectangle diagonale
|
||||
*/
|
||||
public function filledRectangle($background, awLine $line) {
|
||||
list($p1, $p2) = $line->getLocation();
|
||||
|
||||
// Common shape settings
|
||||
$shape = new SWFShape();
|
||||
$shape->setLine(0);
|
||||
|
||||
if($background instanceof awColor) {
|
||||
|
||||
// Get the Red, Green, Blue and Alpha values
|
||||
list($r, $g, $b, $a) = $this->getColor($background);
|
||||
$shape->setRightFill($r, $g, $b, $a);
|
||||
|
||||
} else if($background instanceof awGradient) {
|
||||
|
||||
// Get the Gradient object as an SWFGradient one
|
||||
list($flashGradient, $style) = $this->getGradient($background);
|
||||
|
||||
$fill = $shape->addFill($flashGradient, $style);
|
||||
|
||||
// Angles between Artichow and Ming don't match.
|
||||
// Don't use abs() or vertical gradients get inverted.
|
||||
$angle = $background->angle - 90;
|
||||
$fill->rotateTo($angle);
|
||||
|
||||
// Move the gradient based on the position of the rectangle we're drawing
|
||||
$centerX = min($p1->x, $p2->y) + abs($p1->x - $p2->x) / 2;
|
||||
$centerY = min($p1->y, $p2->y) + abs($p1->y - $p2->y) / 2;
|
||||
$fill->moveTo($centerX, $centerY);
|
||||
|
||||
// Ming draws its gradients on a 1600x1600 image,
|
||||
// so we have to resize it.
|
||||
if($angle === -90) {
|
||||
$ratio = abs($p1->y - $p2->y) / 1600;
|
||||
} else {
|
||||
$ratio = abs($p1->x - $p2->x) / 1600;
|
||||
}
|
||||
$fill->scaleTo($ratio);
|
||||
|
||||
$shape->setRightFill($fill);
|
||||
|
||||
}
|
||||
|
||||
// Set starting position
|
||||
$shape->movePenTo($this->x + round($p1->x), $this->y + round($p1->y));
|
||||
|
||||
// Depending on the points' relative positions,
|
||||
// we have two drawing possibilities
|
||||
if(
|
||||
($p1->x <= $p2->x and $p1->y <= $p2->y)
|
||||
or
|
||||
($p1->x >= $p2->x and $p1->y >= $p2->y)
|
||||
) {
|
||||
$shape->drawLineTo($this->x + round($p2->x), $this->y + round($p1->y));
|
||||
$shape->drawLineTo($this->x + round($p2->x), $this->y + round($p2->y));
|
||||
$shape->drawLineTo($this->x + round($p1->x), $this->y + round($p2->y));
|
||||
$shape->drawLineTo($this->x + round($p1->x), $this->y + round($p1->y));
|
||||
} else {
|
||||
$shape->drawLineTo($this->x + round($p1->x), $this->y + round($p2->y));
|
||||
$shape->drawLineTo($this->x + round($p2->x), $this->y + round($p2->y));
|
||||
$shape->drawLineTo($this->x + round($p2->x), $this->y + round($p1->y));
|
||||
$shape->drawLineTo($this->x + round($p1->x), $this->y + round($p1->y));
|
||||
}
|
||||
|
||||
$this->movie->add($shape);
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw a polygon
|
||||
*
|
||||
* @param awColor $color Polygon color
|
||||
* @param Polygon A polygon
|
||||
*/
|
||||
public function polygon(awColor $color, awPolygon $polygon) {
|
||||
$points = $polygon->all();
|
||||
$count = count($points);
|
||||
|
||||
if($count > 1) {
|
||||
|
||||
$side = new awLine;
|
||||
$side->setStyle($polygon->getStyle());
|
||||
$side->setThickness($polygon->getThickness());
|
||||
|
||||
$prev = $points[0];
|
||||
|
||||
for($i = 1; $i < $count; $i++) {
|
||||
$current = $points[$i];
|
||||
$side->setLocation($prev, $current);
|
||||
$this->line($color, $side);
|
||||
$prev = $current;
|
||||
}
|
||||
|
||||
// Close the polygon
|
||||
$side->setLocation($prev, $points[0]);
|
||||
$this->line($color, $side);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw a polygon with a background
|
||||
*
|
||||
* @param mixed $background Background (can be a color or a gradient)
|
||||
* @param Polygon A polygon
|
||||
*/
|
||||
public function filledPolygon($background, awPolygon $polygon) {
|
||||
$shape = new SWFShape();
|
||||
|
||||
if($background instanceof awColor) {
|
||||
list($red, $green, $blue, $alpha) = $this->getColor($background);
|
||||
|
||||
$shape->setRightFill($red, $green, $blue, $alpha);
|
||||
} elseif($background instanceof awGradient) {
|
||||
list($flashGradient, $style) = $this->getGradient($background);
|
||||
|
||||
$fill = $shape->addFill($flashGradient, $style);
|
||||
|
||||
list($xMin, $xMax) = $polygon->getBoxXRange();
|
||||
list($yMin, $yMax) = $polygon->getBoxYRange();
|
||||
|
||||
if($background->angle === 0) {
|
||||
$fill->scaleTo(($yMax - $yMin) / 1600);
|
||||
} else {
|
||||
$fill->scaleTo(($xMax - $xMin) / 1600);
|
||||
}
|
||||
$fill->moveTo($xMin + ($xMax - $xMin) / 2, $yMin + ($yMax - $yMin) / 2);
|
||||
|
||||
$shape->setRightFill($fill);
|
||||
}
|
||||
|
||||
$points = $polygon->all();
|
||||
$count = count($points);
|
||||
|
||||
if($count > 1) {
|
||||
|
||||
$prev = $points[0];
|
||||
|
||||
$shape->movePenTo($prev->x, $prev->y);
|
||||
|
||||
for($i = 1; $i < $count; $i++) {
|
||||
$current = $points[$i];
|
||||
$shape->drawLineTo($current->x, $current->y);
|
||||
}
|
||||
|
||||
// Close the polygon
|
||||
$shape->drawLineTo($prev->x, $prev->y);
|
||||
|
||||
$this->movie->add($shape);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends the image, as well as the correct HTTP headers, to the browser
|
||||
*
|
||||
* @param awImage $image The Image object to send
|
||||
*/
|
||||
public function send(awImage $image) {
|
||||
$this->drawImage($image);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the image as binary data
|
||||
*
|
||||
* @param awImage $image
|
||||
*/
|
||||
public function get(awImage $image) {
|
||||
return $this->drawImage($image, TRUE, FALSE);
|
||||
}
|
||||
|
||||
public function getTextWidth(awText $text) {
|
||||
$font = $text->getFont();
|
||||
if($this->isCompatibleWithFont($font) === FALSE) {
|
||||
awImage::drawError('Class MingDriver: Incompatible font type (\''.get_class($font).'\')');
|
||||
}
|
||||
|
||||
// Ming only supports FileFont
|
||||
$fontDriver = $this->fileFontDriver;
|
||||
|
||||
return $fontDriver->getTextWidth($text, $this);
|
||||
}
|
||||
|
||||
public function getTextHeight(awText $text) {
|
||||
$font = $text->getFont();
|
||||
if($this->isCompatibleWithFont($font) === FALSE) {
|
||||
awImage::drawError('Class MingDriver: Incompatible font type (\''.get_class($font).'\')');
|
||||
}
|
||||
|
||||
// Ming only supports FileFont
|
||||
$fontDriver = $this->fileFontDriver;
|
||||
|
||||
return $fontDriver->getTextHeight($text, $this);
|
||||
}
|
||||
|
||||
protected function isCompatibleWithFont(awFont $font) {
|
||||
if($font instanceof awTTFFont or $font instanceof awPHPFont) {
|
||||
return FALSE;
|
||||
} else {
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
private function drawImage(awImage $image, $return = FALSE, $header = TRUE) {
|
||||
|
||||
// Send headers to the browser
|
||||
if($header === TRUE) {
|
||||
$image->sendHeaders();
|
||||
}
|
||||
|
||||
if($return) {
|
||||
ob_start();
|
||||
}
|
||||
|
||||
$this->movie->output();
|
||||
|
||||
if($return) {
|
||||
return ob_get_clean();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert an awGradient object to an SWFGradient one.
|
||||
* Returns an object as well as the style of the Flash gradient.
|
||||
*
|
||||
* @param awGradient $gradient The awGradient object to convert
|
||||
* @return array
|
||||
*/
|
||||
private function getGradient(awGradient $gradient) {
|
||||
$flashGradient = new SWFGradient();
|
||||
|
||||
// Get RGBA values for the gradient boundaries
|
||||
list($r1, $g1, $b1, $a1) = $this->getColor($gradient->from);
|
||||
list($r2, $g2, $b2, $a2) = $this->getColor($gradient->to);
|
||||
|
||||
$flashGradient->addEntry(0, $r1, $g1, $b1, $a1);
|
||||
|
||||
if($gradient instanceof awBilinearGradient) {
|
||||
|
||||
$flashGradient->addEntry($gradient->center, $r2, $g2, $b2, $a2);
|
||||
$flashGradient->addEntry(1, $r1, $g1, $b1, $a1);
|
||||
|
||||
return array($flashGradient, SWFFILL_LINEAR_GRADIENT);
|
||||
} else {
|
||||
|
||||
$flashGradient->addEntry(1, $r2, $g2, $b2, $a2);
|
||||
|
||||
if($gradient instanceof awLinearGradient) {
|
||||
return array($flashGradient, SWFFILL_LINEAR_GRADIENT);
|
||||
} else {
|
||||
return array($flashGradient, SWFFILL_RADIAL_GRADIENT);
|
||||
}
|
||||
}
|
||||
}
|
||||
// abstract private function getPolygonPoints(awPolygon $polygon);
|
||||
|
||||
}
|
||||
|
||||
registerClass('MingDriver');
|
||||
|
||||
/*
|
||||
* Check for ming presence
|
||||
*/
|
||||
if(function_exists('ming_useswfversion') === FALSE) {
|
||||
awImage::drawErrorFile('missing-ming');
|
||||
}
|
||||
|
||||
@@ -1,35 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* 2007-2013 PrestaShop
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License (AFL 3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://opensource.org/licenses/afl-3.0.php
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
|
||||
* versions in the future. If you wish to customize PrestaShop for your
|
||||
* needs please refer to http://www.prestashop.com for more information.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2013 PrestaShop SA
|
||||
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
|
||||
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
|
||||
|
||||
header("Cache-Control: no-store, no-cache, must-revalidate");
|
||||
header("Cache-Control: post-check=0, pre-check=0", false);
|
||||
header("Pragma: no-cache");
|
||||
|
||||
header("Location: ../");
|
||||
exit;
|
||||
@@ -1,35 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* 2007-2013 PrestaShop
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License (AFL 3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://opensource.org/licenses/afl-3.0.php
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
|
||||
* versions in the future. If you wish to customize PrestaShop for your
|
||||
* needs please refer to http://www.prestashop.com for more information.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2013 PrestaShop SA
|
||||
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
|
||||
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
|
||||
|
||||
header("Cache-Control: no-store, no-cache, must-revalidate");
|
||||
header("Cache-Control: post-check=0, pre-check=0", false);
|
||||
header("Pragma: no-cache");
|
||||
|
||||
header("Location: ../");
|
||||
exit;
|
||||
@@ -1,84 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* This work is hereby released into the Public Domain.
|
||||
* To view a copy of the public domain dedication,
|
||||
* visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
|
||||
* Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
require_once ARTICHOW."/BarPlot.class.php";
|
||||
|
||||
class BarDepthPattern extends Pattern {
|
||||
|
||||
protected function getPlot($y, $depth) {
|
||||
|
||||
$plot = new BarPlot($y, 1, 1, $depth);
|
||||
|
||||
$plot->barShadow->setSize(2);
|
||||
$plot->barShadow->smooth(TRUE);
|
||||
$plot->barShadow->setColor(new Color(160, 160, 160, 10));
|
||||
|
||||
return $plot;
|
||||
|
||||
}
|
||||
|
||||
public function create() {
|
||||
|
||||
$group = new PlotGroup;
|
||||
$group->setSpace(2, 2, 2, 0);
|
||||
$group->setPadding(30, 10, NULL, NULL);
|
||||
|
||||
$group->grid->hideVertical(TRUE);
|
||||
$group->grid->setType(Line::DASHED);
|
||||
|
||||
$yForeground = $this->getArg('yForeground');
|
||||
$yBackground = $this->getArg('yBackground');
|
||||
|
||||
$legendForeground = $this->getArg('legendForeground');
|
||||
$legendBackground = $this->getArg('legendBackground');
|
||||
|
||||
$colorForeground = $this->getArg('colorForeground', new LightBlue(10));
|
||||
$colorBackground = $this->getArg('colorBackground', new Orange(25));
|
||||
|
||||
if($yForeground === NULL) {
|
||||
awImage::drawError("Class BarDepthPattern: Argument 'yForeground' must not be NULL.");
|
||||
}
|
||||
|
||||
// Background
|
||||
if($yBackground !== NULL) {
|
||||
|
||||
$plot = $this->getPlot($yBackground, 6);
|
||||
$plot->setBarColor($colorBackground);
|
||||
|
||||
$group->add($plot);
|
||||
if($legendBackground !== NULL) {
|
||||
$group->legend->add($plot, $legendBackground, Legend::BACKGROUND);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Foreground
|
||||
$plot = $this->getPlot($yForeground, 0);
|
||||
$plot->setBarColor($colorForeground);
|
||||
|
||||
$group->add($plot);
|
||||
if($legendForeground !== NULL) {
|
||||
$group->legend->add($plot, $legendForeground, Legend::BACKGROUND);
|
||||
}
|
||||
|
||||
$group->axis->bottom->hideTicks(TRUE);
|
||||
|
||||
$group->legend->shadow->setSize(0);
|
||||
$group->legend->setAlign(Legend::CENTER);
|
||||
$group->legend->setSpace(6);
|
||||
$group->legend->setTextFont(new Tuffy(8));
|
||||
$group->legend->setPosition(0.50, 0.10);
|
||||
$group->legend->setBackgroundColor(new Color(255, 255, 255, 10));
|
||||
$group->legend->setColumns(2);
|
||||
|
||||
return $group;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* This work is hereby released into the Public Domain.
|
||||
* To view a copy of the public domain dedication,
|
||||
* visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
|
||||
* Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
require_once ARTICHOW."/LinePlot.class.php";
|
||||
|
||||
class LightLinePattern extends Pattern {
|
||||
|
||||
public function create() {
|
||||
|
||||
$legend = $this->getArg('legend');
|
||||
|
||||
$y = $this->getArg('y');
|
||||
|
||||
if($y === NULL) {
|
||||
awImage::drawError("Class LightLinePattern: Argument 'y' must not be NULL.");
|
||||
}
|
||||
|
||||
$plot = new LinePlot($y);
|
||||
$plot->setSize(0.7, 1);
|
||||
$plot->setCenter(0.35, 0.5);
|
||||
$plot->setPadding(35, 15, 35, 30);
|
||||
$plot->setColor(new Orange());
|
||||
$plot->setFillColor(new LightOrange(80));
|
||||
|
||||
$plot->grid->setType(Line::DASHED);
|
||||
|
||||
$plot->mark->setType(Mark::CIRCLE);
|
||||
$plot->mark->setFill(new MidRed);
|
||||
$plot->mark->setSize(6);
|
||||
|
||||
$plot->legend->setPosition(1, 0.5);
|
||||
$plot->legend->setAlign(Legend::LEFT);
|
||||
$plot->legend->shadow->smooth(TRUE);
|
||||
|
||||
if($legend !== NULL) {
|
||||
$plot->legend->add($plot, $legend, Legend::MARK);
|
||||
}
|
||||
|
||||
return $plot;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* 2007-2013 PrestaShop
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License (AFL 3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://opensource.org/licenses/afl-3.0.php
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
|
||||
* versions in the future. If you wish to customize PrestaShop for your
|
||||
* needs please refer to http://www.prestashop.com for more information.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2013 PrestaShop SA
|
||||
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
|
||||
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
|
||||
|
||||
header("Cache-Control: no-store, no-cache, must-revalidate");
|
||||
header("Cache-Control: post-check=0, pre-check=0", false);
|
||||
header("Pragma: no-cache");
|
||||
|
||||
header("Location: ../");
|
||||
exit;
|
||||
@@ -1,12 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<module>
|
||||
<name>graphartichow</name>
|
||||
<displayName><![CDATA[Artichow]]></displayName>
|
||||
<version><![CDATA[1]]></version>
|
||||
<description><![CDATA[Artichow is a library that enables the display of simple picture-based graphs using PHP and GD.]]></description>
|
||||
<author><![CDATA[PrestaShop]]></author>
|
||||
<tab><![CDATA[administration]]></tab>
|
||||
<is_configurable>0</is_configurable>
|
||||
<need_instance>0</need_instance>
|
||||
<limited_countries></limited_countries>
|
||||
</module>
|
||||
@@ -1,369 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* 2007-2013 PrestaShop
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License (AFL 3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://opensource.org/licenses/afl-3.0.php
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
|
||||
* versions in the future. If you wish to customize PrestaShop for your
|
||||
* needs please refer to http://www.prestashop.com for more information.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2013 PrestaShop SA
|
||||
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
if (!defined('_PS_VERSION_'))
|
||||
exit;
|
||||
|
||||
class GraphArtichow extends ModuleGraphEngine
|
||||
{
|
||||
private $_graph;
|
||||
private $_plot = array(); //for simple-layer graphics
|
||||
private $_group = NULL; //for multi-layer graphics
|
||||
private $_error = 0;
|
||||
|
||||
function __construct($type = null)
|
||||
{
|
||||
if ($type != null)
|
||||
{
|
||||
require_once(dirname(__FILE__).'/artichow/Graph.class.php');
|
||||
$this->_graph = new Graph();
|
||||
$this->_graph->setAntiAliasing(function_exists('imageantialias'));
|
||||
parent::__construct($type);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->name = 'graphartichow';
|
||||
$this->tab = 'administration';
|
||||
$this->version = 1.0;
|
||||
$this->author = 'PrestaShop';
|
||||
$this->need_instance = 0;
|
||||
|
||||
Module::__construct();
|
||||
|
||||
$this->displayName = $this->l('Artichow');
|
||||
$this->description = $this->l('Artichow is a library that enables the display of simple picture-based graphs using PHP and GD.');
|
||||
}
|
||||
}
|
||||
|
||||
function install()
|
||||
{
|
||||
return (parent::install() AND $this->registerHook('GraphEngine'));
|
||||
}
|
||||
|
||||
public static function hookGraphEngine($params, $drawer)
|
||||
{
|
||||
return '<img src="'.$drawer.'&width='.$params['width'].'&height='.$params['height'].'" />';
|
||||
}
|
||||
|
||||
private function drawLine($values)
|
||||
{
|
||||
require_once(dirname(__FILE__).'/artichow/LinePlot.class.php');
|
||||
// Single layer
|
||||
if (!isset($values[0]) OR !is_array($values[0]))
|
||||
{
|
||||
$this->_plot = new LinePlot(array_values($values));
|
||||
$this->_plot->setFillGradient(new LinearGradient(new Color(255, 246, 211, 20), new Color(240, 225, 160, 50), 90));
|
||||
$this->_plot->setColor(new Color(80, 50, 0, 0));
|
||||
}
|
||||
// Multiple layers
|
||||
else
|
||||
{
|
||||
$tabColors = array(new Color(120, 120, 30, 10), new Color(66, 127, 195, 10), new Color(195, 65, 60, 10), new Color(85, 163, 57, 10), new Color(255, 35, 152, 10));
|
||||
$tabFilledColors = array(new Color(120, 120, 30, 90), new Color(66, 127, 195, 90), new Color(195, 65, 60, 90), new Color(85, 163, 57, 90), new Color(255, 35, 152, 90));
|
||||
|
||||
$this->_group = new PlotGroup;
|
||||
$i = 0;
|
||||
foreach ($values as $val)
|
||||
{
|
||||
$this->_plot[$i] = new LinePlot(array_values($val));
|
||||
$this->_plot[$i]->setColor($tabColors[$i % 5]);
|
||||
$this->_plot[$i]->setFillColor($tabFilledColors[$i % 5]);
|
||||
$this->_group->add($this->_plot[$i]);
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function drawColumn($values)
|
||||
{
|
||||
require_once(dirname(__FILE__).'/artichow/BarPlot.class.php');
|
||||
|
||||
if (!is_array($values[0])) //simpleline
|
||||
{
|
||||
$this->_plot = new BarPlot(array_values($values));
|
||||
$this->_plot->label->set(array_values($values));
|
||||
$this->_plot->label->setColor(new Color(110, 110, 110));
|
||||
$this->_plot->label->move(0, -7);
|
||||
$this->_plot->label->setAlign(Positionable::CENTER, NULL);
|
||||
$this->_plot->setBarGradient(new LinearGradient(new Color(254, 255, 216), new Color(233, 231, 218), 90));
|
||||
$this->_plot->barBorder->setColor(new Color(115, 115, 150));
|
||||
$this->_plot->barShadow->setSize(1);
|
||||
$this->_plot->barShadow->setColor(new Color(215, 215, 215));
|
||||
$this->_plot->barShadow->setPosition(Shadow::RIGHT_TOP);
|
||||
$this->_plot->barShadow->smooth(TRUE);
|
||||
}
|
||||
else
|
||||
{
|
||||
$tabColors = array(new Color(120, 120, 30, 10), new Color(66, 127, 195, 10), new Color(195, 65, 60, 10), new Color(85, 163, 57, 10), new Color(255, 35, 152, 10));
|
||||
$tabFilledColors = array(new Color(120, 120, 30, 90), new Color(66, 127, 195, 90), new Color(195, 65, 60, 90), new Color(85, 163, 57, 90), new Color(255, 35, 152, 90));
|
||||
|
||||
$this->_group = new PlotGroup;
|
||||
$i = 0;
|
||||
foreach ($values as $val)
|
||||
{
|
||||
$this->_plot[$i] = new BarPlot(array_values($val));
|
||||
$this->_plot[$i]->label->set(array_values($val));
|
||||
$this->_plot[$i]->label->setColor($tabColors[$i % 5]);
|
||||
$this->_plot[$i]->label->move(0, -7);
|
||||
$this->_plot[$i]->label->setAlign(Positionable::CENTER, NULL);
|
||||
$this->_plot[$i]->setBarColor($tabFilledColors[$i % 5]);
|
||||
$this->_plot[$i]->barBorder->setColor($tabColors[$i % 5]);
|
||||
$this->_plot[$i]->barShadow->setSize(1);
|
||||
$this->_plot[$i]->barShadow->setColor(new Color(215, 215, 215));
|
||||
$this->_plot[$i]->barShadow->setPosition(Shadow::RIGHT_TOP);
|
||||
$this->_plot[$i]->barShadow->smooth(TRUE);
|
||||
$this->_group->add($this->_plot[$i]);
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function setErrorImage()
|
||||
{
|
||||
require_once(dirname(__FILE__).'/artichow/BarPlot.class.php');
|
||||
|
||||
$this->_plot = new BarPlot(array(0));
|
||||
$this->_type = 'column';
|
||||
$this->_plot->setSize(0, 0);
|
||||
$this->_plot->setCenter(-20, -20);
|
||||
}
|
||||
|
||||
private function drawPie($values)
|
||||
{
|
||||
require_once(dirname(__FILE__).'/artichow/Pie.class.php');
|
||||
$exploder = array();
|
||||
$counter = sizeof($values);
|
||||
|
||||
$this->_plot = new Pie(array_values($values), Pie::COLORED);
|
||||
$this->_plot->set3D(10);
|
||||
$this->_plot->setLabelPrecision(2);
|
||||
$this->_plot->setLabelPosition(2);
|
||||
$this->_plot->legend->shadow->setSize(1);
|
||||
$this->_plot->legend->setModel(Legend::MODEL_BOTTOM);
|
||||
$this->_plot->legend->setPosition(NULL, 0.87);
|
||||
$this->_plot->setSize(0.90, 0.90);
|
||||
for ($i = 0; $i < $counter; $i++)
|
||||
$exploder[$i] = 8;
|
||||
$this->_plot->explode($exploder);
|
||||
}
|
||||
|
||||
private function drawLineColumn($y_max)
|
||||
{
|
||||
if ($this->_group == NULL)
|
||||
{
|
||||
$this->_plot->setYMax($y_max);
|
||||
$this->_plot->setSize(1, 1);
|
||||
$this->_plot->setCenter(0.508, 0.53);
|
||||
$this->_plot->setPadding(28, 10, NULL, 40);
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach ($this->_plot as $plot)
|
||||
$plot->setYMax($y_max);
|
||||
$this->_group->setYMax($y_max);
|
||||
$this->_group->setSize(1, 1);
|
||||
$this->_group->setCenter(0.508, 0.53);
|
||||
$this->_group->setPadding(28, 10, NULL, 40);
|
||||
}
|
||||
}
|
||||
|
||||
public function createValues($values)
|
||||
{
|
||||
// $this->_values = array();
|
||||
// if (!isset($this->_values[0]) || !is_array($this->_values[0]))
|
||||
// foreach ($values as $value)
|
||||
// $this->_values[] = $value;
|
||||
// else
|
||||
// {
|
||||
// foreach ($values as $i => $layerValue)
|
||||
// {
|
||||
// $this->_values[$i] = array();
|
||||
// foreach ($values[$i] as $value)
|
||||
// $this->_values[$i][] = $value;
|
||||
// }
|
||||
// }
|
||||
// $values = $this->_values;
|
||||
|
||||
if (sizeof($values) == 0)
|
||||
{
|
||||
$this->setErrorImage();
|
||||
return;
|
||||
}
|
||||
switch ($this->_type)
|
||||
{
|
||||
case 'pie':
|
||||
$this->drawPie($values);
|
||||
break;
|
||||
case 'line':
|
||||
$this->drawLine($values);
|
||||
$this->drawLineColumn($this->getYMax($values));
|
||||
break;
|
||||
case 'column':
|
||||
default:
|
||||
$this->drawColumn($values);
|
||||
$this->drawLineColumn($this->getYMax($values));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public function setSize($width, $height)
|
||||
{
|
||||
if (Validate::isUnsignedInt($width) AND Validate::isUnsignedInt($height))
|
||||
$this->_graph->setSize($width, $height);
|
||||
}
|
||||
|
||||
public function setLegend($legend)
|
||||
{
|
||||
$this->_legend = array();
|
||||
if (!isset($this->_legend[0]) || !is_array($this->_legend[0]))
|
||||
foreach ($legend as $label)
|
||||
$this->_legend[] = $label;
|
||||
else
|
||||
{
|
||||
foreach ($legend as $i => $layerlabel)
|
||||
{
|
||||
$this->_legend[$i] = array();
|
||||
foreach ($legend[$i] as $label)
|
||||
$this->_legend[$i][] = $label;
|
||||
}
|
||||
}
|
||||
$legend = $this->_legend;
|
||||
|
||||
if ($this->_plot == NULL && $this->_group == NULL)
|
||||
return;
|
||||
foreach ($legend as $k => $val)
|
||||
$legend[$k] = html_entity_decode(htmlentities(html_entity_decode($val), ENT_NOQUOTES, 'utf-8'));
|
||||
switch ($this->_type)
|
||||
{
|
||||
case 'pie':
|
||||
$this->_plot->setLegend($legend);
|
||||
break;
|
||||
case 'column':
|
||||
default:
|
||||
if ($this->_group == NULL)
|
||||
{
|
||||
if (isset($this->_plot->xAxis, $this->_plot->yAxis, $this->_plot->grid))
|
||||
{
|
||||
$this->_plot->xAxis->setLabelText($legend);
|
||||
$this->_plot->xAxis->label->setFont(new Tuffy(7));
|
||||
$this->_plot->yAxis->setLabelPrecision(0);
|
||||
$this->_plot->grid->setType(Line::DASHED);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (isset($this->_group->axis->bottom, $this->_group->axis->left, $this->_group->grid))
|
||||
{
|
||||
$this->_group->axis->bottom->setLabelText($legend);
|
||||
$this->_group->axis->bottom->label->setFont(new Tuffy(7));
|
||||
$this->_group->axis->left->setLabelPrecision(0);
|
||||
$this->_group->grid->setType(Line::DASHED);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public function setTitles($titles)
|
||||
{
|
||||
if ($this->_plot == NULL && $this->_group == NULL)
|
||||
return;
|
||||
if (isset($titles['main']))
|
||||
{
|
||||
if (is_array($titles['main']) && $this->_group != NULL)
|
||||
{
|
||||
$i = 0;
|
||||
foreach ($titles['main'] as $key => $val)
|
||||
if ($key != 0)
|
||||
$this->_group->legend->add($this->_plot[$i++], $val, ($this->_type == 'line') ? Legend::LINE : Legend::BACKGROUND);
|
||||
$titles['main'] = $titles['main'][0];
|
||||
}
|
||||
$this->_graph->title->set($titles['main']);
|
||||
$this->_graph->title->setFont(new Tuffy(10));
|
||||
$this->_graph->title->setAlign(Positionable::CENTER, Positionable::MIDDLE);
|
||||
}
|
||||
if (isset($titles['x']))
|
||||
{
|
||||
if ($this->_plot != NULL && !is_array($this->_plot))
|
||||
{
|
||||
$this->_plot->xAxis->title->set($titles['x']);
|
||||
$this->_plot->xAxis->title->setFont(new Tuffy(10));
|
||||
$this->_plot->xAxis->setTitleAlignment(Label::RIGHT);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->_group->axis->bottom->title->set($titles['x']);
|
||||
$this->_group->axis->bottom->title->setFont(new Tuffy(10));
|
||||
$this->_group->axis->bottom->setTitleAlignment(Label::RIGHT);
|
||||
}
|
||||
}
|
||||
if (isset($titles['y']))
|
||||
{
|
||||
if ($this->_plot != NULL && !is_array($this->_plot))
|
||||
{
|
||||
$this->_plot->yAxis->title->set($titles['y']);
|
||||
$this->_plot->yAxis->title->setFont(new Tuffy(10));
|
||||
$this->_plot->yAxis->setTitleAlignment(Label::TOP);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->_group->axis->left->title->set($titles['y']);
|
||||
$this->_group->axis->left->title->setFont(new Tuffy(10));
|
||||
$this->_group->axis->left->setTitleAlignment(Label::TOP);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function draw()
|
||||
{
|
||||
if ($this->_plot != NULL && !is_array($this->_plot))
|
||||
$this->_graph->add($this->_plot);
|
||||
if ($this->_group != NULL)
|
||||
$this->_graph->add($this->_group);
|
||||
$this->_graph->draw();
|
||||
}
|
||||
|
||||
private function getYMax($values)
|
||||
{
|
||||
$max = 0;
|
||||
if (isset($values[0]) && is_array($values[0]))
|
||||
{
|
||||
foreach ($values as $val)
|
||||
foreach ($val as $k => $nb)
|
||||
if ($nb > $max)
|
||||
$max = $nb;
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach ($values as $k => $val)
|
||||
if ($val > $max)
|
||||
$max = $val;
|
||||
}
|
||||
return ($max < 4) ? 4 : (round($max, 0));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,35 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* 2007-2013 PrestaShop
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License (AFL 3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://opensource.org/licenses/afl-3.0.php
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
|
||||
* versions in the future. If you wish to customize PrestaShop for your
|
||||
* needs please refer to http://www.prestashop.com for more information.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2013 PrestaShop SA
|
||||
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
|
||||
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
|
||||
|
||||
header("Cache-Control: no-store, no-cache, must-revalidate");
|
||||
header("Cache-Control: post-check=0, pre-check=0", false);
|
||||
header("Pragma: no-cache");
|
||||
|
||||
header("Location: ../");
|
||||
exit;
|
||||
|
Before Width: | Height: | Size: 1.0 KiB |
|
Before Width: | Height: | Size: 1.9 KiB |
@@ -1,35 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* 2007-2013 PrestaShop
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License (AFL 3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://opensource.org/licenses/afl-3.0.php
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
|
||||
* versions in the future. If you wish to customize PrestaShop for your
|
||||
* needs please refer to http://www.prestashop.com for more information.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2013 PrestaShop SA
|
||||
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
|
||||
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
|
||||
|
||||
header("Cache-Control: no-store, no-cache, must-revalidate");
|
||||
header("Cache-Control: post-check=0, pre-check=0", false);
|
||||
header("Pragma: no-cache");
|
||||
|
||||
header("Location: ../");
|
||||
exit;
|
||||
@@ -1,12 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<module>
|
||||
<name>graphgooglechart</name>
|
||||
<displayName><![CDATA[Google Chart]]></displayName>
|
||||
<version><![CDATA[1]]></version>
|
||||
<description><![CDATA[The Google Chart API lets you dynamically generate charts.]]></description>
|
||||
<author><![CDATA[PrestaShop]]></author>
|
||||
<tab><![CDATA[administration]]></tab>
|
||||
<is_configurable>0</is_configurable>
|
||||
<need_instance>0</need_instance>
|
||||
<limited_countries></limited_countries>
|
||||
</module>
|
||||
@@ -1,247 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* 2007-2013 PrestaShop
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License (AFL 3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://opensource.org/licenses/afl-3.0.php
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
|
||||
* versions in the future. If you wish to customize PrestaShop for your
|
||||
* needs please refer to http://www.prestashop.com for more information.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2013 PrestaShop SA
|
||||
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
if (!defined('_PS_VERSION_'))
|
||||
exit;
|
||||
|
||||
class GraphGoogleChart extends ModuleGraphEngine
|
||||
{
|
||||
private $_width;
|
||||
private $_height;
|
||||
private $_values;
|
||||
private $_legend;
|
||||
private $_titles;
|
||||
|
||||
function __construct($type = null)
|
||||
{
|
||||
if ($type != null)
|
||||
{
|
||||
parent::__construct($type);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->name = 'graphgooglechart';
|
||||
$this->tab = 'administration';
|
||||
$this->version = 1.0;
|
||||
$this->author = 'PrestaShop';
|
||||
$this->need_instance = 0;
|
||||
|
||||
Module::__construct();
|
||||
|
||||
$this->displayName = $this->l('Google Chart');
|
||||
$this->description = $this->l('The Google Chart API lets you dynamically generate charts.');
|
||||
}
|
||||
}
|
||||
|
||||
function install()
|
||||
{
|
||||
return (parent::install() AND $this->registerHook('GraphEngine'));
|
||||
}
|
||||
|
||||
public static function hookGraphEngine($params, $drawer)
|
||||
{
|
||||
return '<img src="'.$drawer.'&width='.$params['width'].'&height='.$params['height'].'" />';
|
||||
}
|
||||
|
||||
|
||||
public function createValues($values)
|
||||
{
|
||||
$this->_values = $values;
|
||||
}
|
||||
|
||||
public function setSize($width, $height)
|
||||
{
|
||||
$this->_width = $width;
|
||||
$this->_height = $height;
|
||||
}
|
||||
|
||||
public function setLegend($legend)
|
||||
{
|
||||
$this->_legend = $legend;
|
||||
}
|
||||
|
||||
public function setTitles($titles)
|
||||
{
|
||||
$this->_titles = $titles;
|
||||
}
|
||||
|
||||
private function getChbh($sizeof_values)
|
||||
{
|
||||
$chbh = 12;
|
||||
|
||||
if ($sizeof_values < 25)
|
||||
$chbh += 4;
|
||||
if ($sizeof_values < 20)
|
||||
$chbh += 4;
|
||||
if ($sizeof_values < 15)
|
||||
$chbh += 8;
|
||||
if ($sizeof_values < 10)
|
||||
$chbh += 14;
|
||||
return ($chbh);
|
||||
}
|
||||
|
||||
private function drawColumn($max_y)
|
||||
{
|
||||
if (!isset($this->_values[0]) || !is_array($this->_values[0]))
|
||||
$sizeof_values = sizeof($this->_values);
|
||||
else
|
||||
$sizeof_values = sizeof($this->_values[0]);
|
||||
$url = 'bvs&chxt=x,y&chxr=1,0,'.$max_y.'&chbh='.$this->getChbh($sizeof_values).'&chg=0,12.5&chxl=0:|';
|
||||
for ($i = 0; $i < $sizeof_values; $i++)
|
||||
if (!isset($this->_values[0]) || !is_array($this->_values[0]))
|
||||
{
|
||||
if (isset($this->_values[$i]))
|
||||
$this->_values[$i] = ($this->_values[$i] * 100) / $max_y;
|
||||
else
|
||||
$this->_values[$i] = 0;
|
||||
}
|
||||
else
|
||||
foreach ($this->_values as $k => $value)
|
||||
{
|
||||
if (!isset($this->_values[$k][$i]))
|
||||
$this->_values[$k][$i] = 0;
|
||||
$this->_values[$k][$i] = ($this->_values[$k][$i] * 100) / $max_y;
|
||||
}
|
||||
return ($url);
|
||||
}
|
||||
|
||||
private function drawLine($max_y)
|
||||
{
|
||||
return ('lc'./*&chxt=x,y*/'&chbh='.$this->getChbh(sizeof($this->_values)).'&chg=0,12.5&chxl=0:|');
|
||||
}
|
||||
|
||||
private function drawPie()
|
||||
{
|
||||
return ('p3&chl=');
|
||||
}
|
||||
|
||||
public function draw()
|
||||
{
|
||||
$url = 'http://chart.apis.google.com/chart?cht=';
|
||||
$legend = '';
|
||||
$values = '';
|
||||
$scale = '';
|
||||
|
||||
switch ($this->_type)
|
||||
{
|
||||
case 'pie':
|
||||
$url .= $this->drawPie();
|
||||
break;
|
||||
case 'line':
|
||||
$url .= $this->drawLine($this->getYMax($this->_values));
|
||||
case 'column':
|
||||
default:
|
||||
$url .= $this->drawColumn($this->getYMax($this->_values));
|
||||
break;
|
||||
}
|
||||
|
||||
foreach ($this->_legend as $label)
|
||||
$legend .= $label.'|';
|
||||
$url .= htmlentities(urlencode(html_entity_decode(rtrim($legend, '|'))));
|
||||
|
||||
if (!isset($this->_values[0]) || !is_array($this->_values[0]))
|
||||
{
|
||||
foreach ($this->_values as $label)
|
||||
$values .= ($label ? $label : '0').',';
|
||||
$url .= '&chd=t:'.urlencode(rtrim($values, ','));
|
||||
}
|
||||
else
|
||||
{
|
||||
$i = 0;
|
||||
$url .= '&chd=t:';
|
||||
foreach ($this->_values as $val)
|
||||
{
|
||||
$values = '';
|
||||
if ($i++ > 0)
|
||||
$url .= '|';
|
||||
foreach ($val as $label)
|
||||
$values .= ($label ? $label : '0').',';
|
||||
$url .= urlencode(rtrim($values, ','));
|
||||
}
|
||||
}
|
||||
|
||||
$url .= '&chs='.(int)($this->_width).'x'.(int)($this->_height);
|
||||
if (!isset($this->_values[0]) || !is_array($this->_values[0]))
|
||||
$url .= (isset($this->_titles['main'])) ? '&chtt='.urlencode($this->_titles['main']) : '';
|
||||
else
|
||||
{
|
||||
$url .= $this->getStringColor(sizeof($this->_values));
|
||||
$i = 0;
|
||||
foreach ($this->_titles['main'] as $val)
|
||||
{
|
||||
if ($i == 0 && !empty($this->_titles['main']))
|
||||
$url .= '&chtt='.urlencode($this->_titles['main'][$i]);
|
||||
else if ($i == 1)
|
||||
$url .= '&chdl=';
|
||||
else if ($i > 1)
|
||||
$url .= '|';
|
||||
if ($i != 0)
|
||||
$url .= urlencode($this->_titles['main'][$i]);
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
header("Content-type: image/png");
|
||||
readfile($url);
|
||||
}
|
||||
|
||||
private function getYMax($values)
|
||||
{
|
||||
$max = 0;
|
||||
if (!isset($this->_values[0]) || !is_array($this->_values[0]))
|
||||
{
|
||||
foreach ($values as $k => $val)
|
||||
if ($val > $max)
|
||||
$max = $val;
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach ($values as $value)
|
||||
foreach ($value as $val)
|
||||
if ($val > $max)
|
||||
$max = $val;
|
||||
}
|
||||
return ($max < 4) ? 4 : (round($max, 0));
|
||||
}
|
||||
|
||||
private function getStringColor($nb_colors)
|
||||
{
|
||||
$tabColors = array('ffb649', '427fc3', 'ff0000', '55a339', 'ff2398');
|
||||
$color = '';
|
||||
if ($nb_colors > 1)
|
||||
{
|
||||
$color = '&chco=';
|
||||
for ($i = 0; $i < $nb_colors; $i++)
|
||||
{
|
||||
if ($i > 0)
|
||||
$color .= ',';
|
||||
$color .= $tabColors[$i % 5];
|
||||
}
|
||||
}
|
||||
return $color;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,35 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* 2007-2013 PrestaShop
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License (AFL 3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://opensource.org/licenses/afl-3.0.php
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
|
||||
* versions in the future. If you wish to customize PrestaShop for your
|
||||
* needs please refer to http://www.prestashop.com for more information.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2013 PrestaShop SA
|
||||
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
|
||||
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
|
||||
|
||||
header("Cache-Control: no-store, no-cache, must-revalidate");
|
||||
header("Cache-Control: post-check=0, pre-check=0", false);
|
||||
header("Pragma: no-cache");
|
||||
|
||||
header("Location: ../");
|
||||
exit;
|
||||
|
Before Width: | Height: | Size: 953 B |
|
Before Width: | Height: | Size: 1.9 KiB |
@@ -1,35 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* 2007-2013 PrestaShop
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License (AFL 3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://opensource.org/licenses/afl-3.0.php
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
|
||||
* versions in the future. If you wish to customize PrestaShop for your
|
||||
* needs please refer to http://www.prestashop.com for more information.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2013 PrestaShop SA
|
||||
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
|
||||
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
|
||||
|
||||
header("Cache-Control: no-store, no-cache, must-revalidate");
|
||||
header("Cache-Control: post-check=0, pre-check=0", false);
|
||||
header("Pragma: no-cache");
|
||||
|
||||
header("Location: ../");
|
||||
exit;
|
||||
@@ -78,8 +78,8 @@ class GraphNvD3 extends ModuleGraphEngine
|
||||
nv.models.lineChart()',
|
||||
'pie' => '
|
||||
nv.models.pieChart()
|
||||
.x(function(d) {return d.label})
|
||||
.y(function(d) {return d.value})
|
||||
.x(function(d) { return d.label; })
|
||||
.y(function(d) { return d.value; })
|
||||
.showLabels(true)
|
||||
.showLegend(false)'
|
||||
);
|
||||
@@ -150,12 +150,17 @@ class GraphNvD3 extends ModuleGraphEngine
|
||||
{
|
||||
$nvd3_values = array();
|
||||
if (Tools::getValue('type') == 'pie')
|
||||
{
|
||||
foreach ($this->_values as $x => $y)
|
||||
$nvd3_values[] = array('label' => $this->_legend[$x], 'value' => $y);
|
||||
$array['data'] = $nvd3_values;
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach ($this->_values as $x => $y)
|
||||
$nvd3_values[] = array('x' => $x, 'y' => $y);
|
||||
$array['data'][] = array('values' => $nvd3_values, 'key' => $this->_titles['main']);
|
||||
$array['data'][] = array('values' => $nvd3_values, 'key' => $this->_titles['main']);
|
||||
}
|
||||
}
|
||||
else
|
||||
foreach ($this->_values as $layer => $gross_values)
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<module>
|
||||
<name>graphvisifire</name>
|
||||
<displayName><![CDATA[Visifire]]></displayName>
|
||||
<version><![CDATA[1]]></version>
|
||||
<description><![CDATA[Visifire is a set of open-source data visualization components -- Powered by Microsoft Silverlight 2 (beta 2).]]></description>
|
||||
<author><![CDATA[PrestaShop]]></author>
|
||||
<tab><![CDATA[administration]]></tab>
|
||||
<is_configurable>0</is_configurable>
|
||||
<need_instance>0</need_instance>
|
||||
<limited_countries></limited_countries>
|
||||
</module>
|
||||
@@ -1,186 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* 2007-2013 PrestaShop
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License (AFL 3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://opensource.org/licenses/afl-3.0.php
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
|
||||
* versions in the future. If you wish to customize PrestaShop for your
|
||||
* needs please refer to http://www.prestashop.com for more information.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2013 PrestaShop SA
|
||||
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
if (!defined('_PS_VERSION_'))
|
||||
exit;
|
||||
|
||||
class GraphVisifire extends ModuleGraphEngine
|
||||
{
|
||||
private $_xml;
|
||||
private $_values = NULL;
|
||||
private $_legend = NULL;
|
||||
private $_titles = NULL;
|
||||
|
||||
function __construct($type = null)
|
||||
{
|
||||
if ($type != null)
|
||||
{
|
||||
$this->_xml = '<vc:Chart xmlns:vc="clr-namespace:Visifire.Charts;assembly=Visifire.Charts" BorderThickness="0" AnimationEnabled="True" AnimationType="Type5"';
|
||||
if ($type == 'pie' || $type == 'line')
|
||||
$this->_xml .= ' Theme="Theme1" View3D="True"';
|
||||
else
|
||||
$this->_xml .= ' Theme="Theme2" ColorSet="Visifire2" UniqueColors="True"';
|
||||
$this->_xml .= '>';
|
||||
parent::__construct($type);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->name = 'graphvisifire';
|
||||
$this->tab = 'administration';
|
||||
$this->version = 1.0;
|
||||
$this->author = 'PrestaShop';
|
||||
$this->need_instance = 0;
|
||||
|
||||
Module::__construct();
|
||||
|
||||
$this->displayName = $this->l('Visifire');
|
||||
$this->description = $this->l('Visifire is a set of open-source data visualization components -- Powered by Microsoft Silverlight 2 (beta 2).');
|
||||
}
|
||||
}
|
||||
|
||||
function install()
|
||||
{
|
||||
return (parent::install() AND $this->registerHook('GraphEngine'));
|
||||
}
|
||||
|
||||
public static function hookGraphEngine($params, $drawer)
|
||||
{
|
||||
static $divid = 1;
|
||||
return '<script type="text/javascript" src="../modules/graphvisifire/visifire/Visifire.js"></script>
|
||||
<div id="VisifireChart'.$divid.'">
|
||||
<script language="javascript" type="text/javascript">
|
||||
var vChart = new Visifire("../modules/graphvisifire/visifire/Visifire.xap", '.$params['width'].', '.$params['height'].');
|
||||
vChart.setLogLevel(0);
|
||||
vChart.setDataUri(\''.$drawer.'\');
|
||||
vChart.render("VisifireChart'.$divid++.'");
|
||||
</script>
|
||||
</div>';
|
||||
}
|
||||
|
||||
public function createValues($values)
|
||||
{
|
||||
$this->_values = array();
|
||||
if (!is_array($values[array_rand($values)]))
|
||||
foreach ($values as $value)
|
||||
$this->_values[] = $value;
|
||||
else
|
||||
{
|
||||
foreach ($values as $i => $layerValue)
|
||||
{
|
||||
$this->_values[$i] = array();
|
||||
foreach ($layerValue as $value)
|
||||
$this->_values[$i][] = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function setSize($width, $height)
|
||||
{
|
||||
// Unavailable
|
||||
}
|
||||
|
||||
public function setLegend($legend)
|
||||
{
|
||||
$this->_legend = array();
|
||||
if (!is_array($legend[array_rand($legend)]))
|
||||
foreach ($legend as $label)
|
||||
$this->_legend[] = $label;
|
||||
else
|
||||
{
|
||||
foreach ($legend as $i => $layerlabel)
|
||||
{
|
||||
$this->_legend[$i] = array();
|
||||
foreach ($layerlabel as $label)
|
||||
$this->_legend[$i][] = $label;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function setTitles($titles)
|
||||
{
|
||||
$this->_titles = $titles;
|
||||
if (isset($titles['main']) && !is_array($titles['main']))
|
||||
$this->_xml .= '<vc:Title Text="'.$titles['main'].'"/>';
|
||||
if (is_array($titles['main']) && isset($titles['main'][0]))
|
||||
$this->_xml .= '<vc:Title Text="'.$titles['main'][0].'"/>';
|
||||
if (isset($titles['x']))
|
||||
$this->_xml .= '<vc:AxisX Title="'.$titles['x'].'" />';
|
||||
if (isset($titles['y']))
|
||||
$this->_xml .= '<vc:AxisY Title="'.$titles['y'].'" />';
|
||||
}
|
||||
|
||||
public function draw()
|
||||
{
|
||||
header('content-type: text/xml');
|
||||
if ($this->_values != NULL && $this->_legend != NULL)
|
||||
{
|
||||
if (!isset($this->_values[0]) || !is_array($this->_values[0]))
|
||||
$size = sizeof($this->_values);
|
||||
else
|
||||
$size = sizeof($this->_values[0]);
|
||||
if ($size == sizeof($this->_legend))
|
||||
{
|
||||
if (!is_array($this->_values[array_rand($this->_values)]))
|
||||
{
|
||||
$this->_xml .= '<vc:DataSeries RenderAs="'.$this->_type.'">';
|
||||
for ($i = 0; $i < $size; $i++)
|
||||
{
|
||||
$this->_xml .= '<vc:DataPoint ';
|
||||
$this->_xml .= 'AxisLabel=" '.str_replace('<', '<', str_replace('>', '>', str_replace('&', '&', str_replace('"', "'", $this->_legend[$i])))).'" ';
|
||||
$this->_xml .= 'YValue="'.$this->_values[$i].'"';
|
||||
if ($this->_type == 'pie')
|
||||
$this->_xml .= ' ExplodeOffset="0.2"';
|
||||
$this->_xml .= '/>';
|
||||
}
|
||||
$this->_xml .= '</vc:DataSeries>';
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach ($this->_values as $layer => $values)
|
||||
{
|
||||
$this->_xml .= '<vc:DataSeries Name="'.(isset($this->_titles['main'][$layer+1]) ? $this->_titles['main'][$layer+1] : '').'" RenderAs="'.$this->_type.'">';
|
||||
foreach ($values as $i => $value)
|
||||
{
|
||||
$this->_xml .= '<vc:DataPoint ';
|
||||
if ($layer == 0)
|
||||
$this->_xml .= 'AxisLabel=" '.str_replace('<', '<', str_replace('>', '>', str_replace('&', '&', str_replace('"', "'", $this->_legend[$i])))).'" ';
|
||||
$this->_xml .= 'YValue="'.$value.'"';
|
||||
if ($this->_type == 'pie')
|
||||
$this->_xml .= ' ExplodeOffset="0.2"';
|
||||
$this->_xml .= '/>';
|
||||
}
|
||||
$this->_xml .= '</vc:DataSeries>';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->_xml .= '</vc:Chart>';
|
||||
echo $this->_xml;
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,35 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* 2007-2013 PrestaShop
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License (AFL 3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://opensource.org/licenses/afl-3.0.php
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
|
||||
* versions in the future. If you wish to customize PrestaShop for your
|
||||
* needs please refer to http://www.prestashop.com for more information.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2013 PrestaShop SA
|
||||
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
|
||||
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
|
||||
|
||||
header("Cache-Control: no-store, no-cache, must-revalidate");
|
||||
header("Cache-Control: post-check=0, pre-check=0", false);
|
||||
header("Pragma: no-cache");
|
||||
|
||||
header("Location: ../");
|
||||
exit;
|
||||
|
Before Width: | Height: | Size: 1012 B |
|
Before Width: | Height: | Size: 2.0 KiB |
@@ -1,35 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* 2007-2013 PrestaShop
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License (AFL 3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://opensource.org/licenses/afl-3.0.php
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
|
||||
* versions in the future. If you wish to customize PrestaShop for your
|
||||
* needs please refer to http://www.prestashop.com for more information.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2013 PrestaShop SA
|
||||
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
|
||||
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
|
||||
|
||||
header("Cache-Control: no-store, no-cache, must-revalidate");
|
||||
header("Cache-Control: post-check=0, pre-check=0", false);
|
||||
header("Pragma: no-cache");
|
||||
|
||||
header("Location: ../");
|
||||
exit;
|
||||
@@ -1,353 +0,0 @@
|
||||
/*
|
||||
Copyright (C) 2008 Webyog Softworks Private Limited
|
||||
|
||||
This file is a part of Visifire Charts.
|
||||
|
||||
Visifire is a free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Visifire Charts. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
If GPL is not suitable for your products or company, Webyog provides Visifire
|
||||
under a flexible commercial license designed to meet your specific usage and
|
||||
distribution requirements. If you have already obtained a commercial license
|
||||
from Webyog, you can use this file under those license terms.
|
||||
*/
|
||||
|
||||
if(!window.Visifire)
|
||||
{
|
||||
// Visifire class
|
||||
window.Visifire = function(pXapPath, pId, pWidth, pHeight, pBackground)
|
||||
{
|
||||
this.id = null;
|
||||
this.logLevel = 1; // Determines whether to log or not.
|
||||
this.xapPath = "Visifire.xap"; // Default is taken as Visifire.xap in the same directory.
|
||||
this.targetElement = null;
|
||||
this.dataXml = null;
|
||||
this.dataUri = null;
|
||||
this.listeners = null;
|
||||
this.elements = new Array("Chart", "DataPoint", "Title", "AxisX", "AxisY", "Legend");
|
||||
this.events = new Array("MouseLeftButtonDown", "MouseLeftButtonUp", "MouseMove", "MouseEnter", "MouseLeave");
|
||||
this.windowless = false;
|
||||
this.width = null;
|
||||
this.height = null;
|
||||
this.background = null;
|
||||
|
||||
// pId not present
|
||||
if(Number(pId))
|
||||
{
|
||||
if(pHeight)
|
||||
this.background = pHeight;
|
||||
|
||||
pHeight = pWidth;
|
||||
pWidth = pId;
|
||||
}
|
||||
else // pId present
|
||||
{
|
||||
this.id = pId;
|
||||
|
||||
if(pBackground)
|
||||
this.background = pBackground;
|
||||
}
|
||||
|
||||
if(pXapPath)
|
||||
this.xapPath = pXapPath;
|
||||
|
||||
if(pWidth)
|
||||
this.width = pWidth;
|
||||
|
||||
if(pHeight)
|
||||
this.height = pHeight;
|
||||
|
||||
this._uThisObject = this;
|
||||
|
||||
this.index = ++Visifire._slCount;
|
||||
}
|
||||
|
||||
window.Visifire._slCount = 0;
|
||||
|
||||
Visifire.prototype.setWindowlessState = function(pWindowless)
|
||||
{
|
||||
if(pWindowless != null)
|
||||
{
|
||||
this.windowless = Boolean(pWindowless);
|
||||
}
|
||||
}
|
||||
|
||||
Visifire.prototype._getSlControl = function ()
|
||||
{
|
||||
var _uThisObject = this;
|
||||
if(_uThisObject.id != null)
|
||||
{
|
||||
var slControl = document.getElementById(_uThisObject.id);
|
||||
return slControl;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
Visifire.prototype.isLoaded = function()
|
||||
{
|
||||
var slControl = this._getSlControl();
|
||||
try
|
||||
{
|
||||
if(slControl.Content.wrapper != null)
|
||||
return true;
|
||||
}
|
||||
catch(ex)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Visifire.prototype.isDataLoaded = function()
|
||||
{
|
||||
var slControl = this._getSlControl();
|
||||
|
||||
return slControl.Content.wrapper.IsDataLoaded;
|
||||
}
|
||||
Visifire.prototype.setSize = function(pWidth,pHeight)
|
||||
{
|
||||
var slControl = this._getSlControl();
|
||||
if(slControl != null)
|
||||
{
|
||||
slControl.width = pWidth;
|
||||
slControl.height = pHeight;
|
||||
slControl.Content.wrapper.Resize(pWidth,pHeight);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.width = pWidth;
|
||||
this.height = pHeight;
|
||||
}
|
||||
}
|
||||
|
||||
Visifire.prototype.setDataXml = function(pDataXml)
|
||||
{
|
||||
var slControl = this._getSlControl();
|
||||
|
||||
if(slControl != null && this.dataXml != null)
|
||||
{
|
||||
slControl.Content.wrapper.AddDataXML(pDataXml);
|
||||
}
|
||||
|
||||
this.dataXml = pDataXml;
|
||||
}
|
||||
|
||||
|
||||
Visifire.prototype.setDataUri = function(pDataUri)
|
||||
{
|
||||
var slControl = this._getSlControl();
|
||||
|
||||
if(slControl != null && this.dataUri != null)
|
||||
{
|
||||
slControl.Content.wrapper.AddDataUri(pDataUri);
|
||||
}
|
||||
|
||||
this.dataUri = pDataUri;
|
||||
}
|
||||
|
||||
Visifire.prototype.setLogLevel = function(level)
|
||||
{
|
||||
if(level != null)
|
||||
{
|
||||
this.logLevel = level;
|
||||
}
|
||||
}
|
||||
|
||||
Visifire.prototype._isString = function()
|
||||
{
|
||||
if (typeof arguments[0] == 'string') return true;
|
||||
|
||||
if (typeof arguments[0] == 'object')
|
||||
{
|
||||
var criterion = arguments[0].constructor.toString().match(/string/i);
|
||||
return (criterion != null);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
Visifire.prototype._validateChartElement = function(pElement)
|
||||
{
|
||||
if(this.logLevel != 0)
|
||||
{
|
||||
for(var i = 0; i < this.elements.length; i++)
|
||||
if(this.elements[i] == pElement)
|
||||
return;
|
||||
|
||||
alert('Error occurred while attaching event.\nUnknown element "' + pElement + '".');
|
||||
}
|
||||
}
|
||||
|
||||
Visifire.prototype._validateEvent = function(pEvent)
|
||||
{
|
||||
if(this.logLevel != 0)
|
||||
{
|
||||
for(var i = 0; i < this.events.length; i++)
|
||||
if(this.events[i] == pEvent)
|
||||
return;
|
||||
|
||||
alert('Error occurred while attaching event.\nUnsupported event type "' + pEvent + '".');
|
||||
}
|
||||
}
|
||||
|
||||
Visifire.prototype.attachEvent = function(pElement, pEvent, pCallBack)
|
||||
{
|
||||
var _uThisObject = this;
|
||||
|
||||
_uThisObject._validateChartElement(pElement);
|
||||
_uThisObject._validateEvent(pEvent);
|
||||
|
||||
if(pEvent && pElement && pCallBack)
|
||||
{
|
||||
if(_uThisObject.listeners == null)
|
||||
_uThisObject.listeners = {};
|
||||
|
||||
if(_uThisObject.listeners[pEvent] == null)
|
||||
_uThisObject.listeners[pEvent] = new Array();
|
||||
|
||||
if(!window["dispatchEvent" + _uThisObject.index])
|
||||
window["dispatchEvent" + _uThisObject.index] = function(args)
|
||||
{
|
||||
if(_uThisObject.listeners[args.Event] != null)
|
||||
{
|
||||
var listener = _uThisObject.listeners[args.Event];
|
||||
if(listener.length != 0)
|
||||
{
|
||||
for (var i = 0; i < listener.length; i++)
|
||||
{
|
||||
if ((listener[i].event == args.Event) && (listener[i].element == args.Element))
|
||||
{
|
||||
args.ControlId = _uThisObject.id;
|
||||
|
||||
if(_uThisObject._isString(listener[i].fire))
|
||||
eval(listener[i].fire + "(args)");
|
||||
else
|
||||
listener[i].fire(args);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
_uThisObject.listeners[pEvent].push({element: pElement, event: pEvent, fire: pCallBack});
|
||||
}
|
||||
}
|
||||
|
||||
Visifire.prototype._render = function(pTargetElement)
|
||||
{
|
||||
var _uThisObject = this;
|
||||
var width;
|
||||
var height;
|
||||
|
||||
_uThisObject.targerElement = (typeof(pTargetElement) == "string")?document.getElementById(pTargetElement):pTargetElement;
|
||||
|
||||
if(_uThisObject.width != null)
|
||||
width = _uThisObject.width;
|
||||
else if(_uThisObject.targerElement.offsetWidth != 0)
|
||||
width = _uThisObject.targerElement.offsetWidth;
|
||||
else
|
||||
width = 500;
|
||||
|
||||
if(_uThisObject.height != null)
|
||||
height = _uThisObject.height;
|
||||
else if(_uThisObject.targerElement.offsetHeight != 0)
|
||||
height = _uThisObject.targerElement.offsetHeight;
|
||||
else
|
||||
height = 300;
|
||||
|
||||
if(!_uThisObject.id)
|
||||
{
|
||||
_uThisObject.id = 'VisifireControl' + _uThisObject.index;
|
||||
}
|
||||
|
||||
var html = '<object id="' + _uThisObject.id + '" data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="' + width + '" height="' + height + '">';
|
||||
|
||||
html += '<param name="source" value="' + _uThisObject.xapPath +'"/>'
|
||||
+ '<param name="onLoad" value="slLoaded' + _uThisObject.index +'"/>'
|
||||
+ '<param name="onResize" value="slResized' + _uThisObject.index +'"/>';
|
||||
html += '<param name="initParams" value="';
|
||||
|
||||
html += "logLevel=" + _uThisObject.logLevel + ",";
|
||||
|
||||
if(_uThisObject.dataXml != null)
|
||||
{
|
||||
window["getDataXml"+_uThisObject.index] = function(sender, args)
|
||||
{
|
||||
var _uThisObj = _uThisObject;
|
||||
return _uThisObj.dataXml;
|
||||
};
|
||||
|
||||
html += 'dataXml=getDataXml'+ _uThisObject.index +',';
|
||||
}
|
||||
else if(_uThisObject.dataUri != null)
|
||||
{
|
||||
html += 'dataUri='+ _uThisObject.dataUri +',';
|
||||
}
|
||||
|
||||
if(_uThisObject.listeners != null)
|
||||
{
|
||||
html += 'EventDispatcher=dispatchEvent' + _uThisObject.index + ',';
|
||||
|
||||
html += 'jsEvents=';
|
||||
|
||||
var events = _uThisObject.events;
|
||||
|
||||
for(var i=0; i< events.length; i++)
|
||||
{
|
||||
var listener = _uThisObject.listeners[events[i]];
|
||||
|
||||
if(listener != null)
|
||||
{
|
||||
for (var j = 0; j < listener.length; j++)
|
||||
{
|
||||
html += listener[j].element + ' ' + listener[j].event + ';';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
html += ','
|
||||
}
|
||||
|
||||
|
||||
if(_uThisObject.background == null)
|
||||
_uThisObject.background = "White";
|
||||
|
||||
html += 'width=' + width + ',' + 'height=' + height + '';
|
||||
html += "\"/>";
|
||||
html += '<param name="enableHtmlAccess" value="true" />'
|
||||
+ '<param name="background" value="' + _uThisObject.background + '" />'
|
||||
+ '<param name="windowless" value="' + this.windowless + '" />'
|
||||
+ '<a href="http://go.microsoft.com/fwlink/?LinkID=124807" style="text-decoration: none;">'
|
||||
+ '<img src="http://go.microsoft.com/fwlink/?LinkId=108181" alt="Get Microsoft Silverlight" style="border-style: none"/>'
|
||||
+ '<br/>You need Microsoft Silverlight to view Visifire Charts.'
|
||||
+ '<br/> You can install it by clicking on this link.'
|
||||
+ '<br/>Please restart the browser after installation.'
|
||||
+ '</a>'
|
||||
+ '</object>';
|
||||
|
||||
this.targerElement.innerHTML = html;
|
||||
}
|
||||
|
||||
Visifire.prototype._reRender = function(pSlControl)
|
||||
{
|
||||
pSlControl.Content.wrapper.ReRenderChart();
|
||||
}
|
||||
|
||||
Visifire.prototype.render = function(pTargetElement)
|
||||
{
|
||||
var slControl = this._getSlControl();
|
||||
|
||||
if(slControl == null)
|
||||
{
|
||||
this._render(pTargetElement);
|
||||
}
|
||||
else
|
||||
{
|
||||
this._reRender(slControl);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* 2007-2013 PrestaShop
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License (AFL 3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://opensource.org/licenses/afl-3.0.php
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
|
||||
* versions in the future. If you wish to customize PrestaShop for your
|
||||
* needs please refer to http://www.prestashop.com for more information.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2013 PrestaShop SA
|
||||
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
|
||||
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
|
||||
|
||||
header("Cache-Control: no-store, no-cache, must-revalidate");
|
||||
header("Cache-Control: post-check=0, pre-check=0", false);
|
||||
header("Pragma: no-cache");
|
||||
|
||||
header("Location: ../");
|
||||
exit;
|
||||
@@ -1,12 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<module>
|
||||
<name>graphxmlswfcharts</name>
|
||||
<displayName><![CDATA[XML/SWF Charts]]></displayName>
|
||||
<version><![CDATA[1]]></version>
|
||||
<description><![CDATA[XML/SWF Charts are simple, yet powerful tools using Adobe Flash to create attractive web charts and graphs from dynamic data.]]></description>
|
||||
<author><![CDATA[PrestaShop]]></author>
|
||||
<tab><![CDATA[administration]]></tab>
|
||||
<is_configurable>0</is_configurable>
|
||||
<need_instance>0</need_instance>
|
||||
<limited_countries></limited_countries>
|
||||
</module>
|
||||
@@ -1,258 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* 2007-2013 PrestaShop
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License (AFL 3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://opensource.org/licenses/afl-3.0.php
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
|
||||
* versions in the future. If you wish to customize PrestaShop for your
|
||||
* needs please refer to http://www.prestashop.com for more information.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2013 PrestaShop SA
|
||||
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
/**
|
||||
* Statistics
|
||||
* @category stats
|
||||
*
|
||||
* @author PrestaShop
|
||||
* @copyright PrestaShop
|
||||
* @license http://www.opensource.org/licenses/afl-3.0.php Open-source licence 3.0
|
||||
* @version 1.4
|
||||
*/
|
||||
|
||||
if (!defined('_PS_VERSION_'))
|
||||
exit;
|
||||
|
||||
class GraphXmlSwfCharts extends ModuleGraphEngine
|
||||
{
|
||||
private $_xml;
|
||||
private $_values = NULL;
|
||||
private $_legend = NULL;
|
||||
private $_legend_more = '';
|
||||
private $_titles = '';
|
||||
|
||||
function __construct($type = null)
|
||||
{
|
||||
if ($type != null)
|
||||
{
|
||||
$this->_xml = '<chart>';
|
||||
parent::__construct($type);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->name = 'graphxmlswfcharts';
|
||||
$this->tab = 'administration';
|
||||
$this->version = 1.0;
|
||||
$this->author = 'PrestaShop';
|
||||
$this->need_instance = 0;
|
||||
|
||||
Module::__construct();
|
||||
|
||||
$this->displayName = $this->l('XML/SWF Charts');
|
||||
$this->description = $this->l('XML/SWF Charts are simple, yet powerful tools using Adobe Flash to create attractive web charts and graphs from dynamic data.');
|
||||
}
|
||||
}
|
||||
|
||||
function install()
|
||||
{
|
||||
return (parent::install() AND $this->registerHook('GraphEngine'));
|
||||
}
|
||||
|
||||
public static function hookGraphEngine($params, $drawer)
|
||||
{
|
||||
return '<script language="javascript" type="text/javascript">AC_FL_RunContent = 0;</script>
|
||||
<script language="javascript" type="text/javascript"> DetectFlashVer = 0; </script>
|
||||
<script src="../modules/graphxmlswfcharts/xml_swf_charts/AC_RunActiveContent.js" language="javascript"></script>
|
||||
<script language="JavaScript" type="text/javascript">
|
||||
<!--
|
||||
var requiredMajorVersion = 9;
|
||||
var requiredMinorVersion = 0;
|
||||
var requiredRevision = 45;
|
||||
-->
|
||||
</script>
|
||||
|
||||
<script language="JavaScript" type="text/javascript">
|
||||
<!--
|
||||
if (AC_FL_RunContent == 0 || DetectFlashVer == 0) {
|
||||
alert("This page requires AC_RunActiveContent.js.");
|
||||
} else {
|
||||
var hasRightVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);
|
||||
if(hasRightVersion) {
|
||||
AC_FL_RunContent(
|
||||
\'codebase\', \'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,45,0\',
|
||||
\'width\', \''.$params['width'].'\',
|
||||
\'height\', \''.$params['height'].'\',
|
||||
\'bgcolor\', \'#EFEFEF\',
|
||||
\'movie\', \'charts\',
|
||||
\'src\', \'../modules/graphxmlswfcharts/xml_swf_charts/charts\',
|
||||
\'FlashVars\', \'library_path=../modules/graphxmlswfcharts/xml_swf_charts/charts_library&xml_source='.urlencode($drawer).'\',
|
||||
\'wmode\', \'opaque\',
|
||||
\'scale\', \'noScale\',
|
||||
\'id\', \'charts\',
|
||||
\'name\', \'charts\',
|
||||
\'menu\', \'true\',
|
||||
\'allowFullScreen\', \'true\',
|
||||
\'allowScriptAccess\',\'sameDomain\',
|
||||
\'quality\', \'high\',
|
||||
\'pluginspage\', \'http://www.macromedia.com/go/getflashplayer\',
|
||||
\'align\', \'middle\',
|
||||
\'play\', \'true\',
|
||||
\'devicefont\', \'false\',
|
||||
\'salign\', \'TL\'
|
||||
);
|
||||
} else {
|
||||
var alternateContent = \'This content requires the Adobe Flash Player. \'
|
||||
+ \'<u><a href=http://www.macromedia.com/go/getflash/>Get Flash</a></u>.\';
|
||||
document.write(alternateContent);
|
||||
}
|
||||
}
|
||||
// -->
|
||||
</script>
|
||||
<noscript>
|
||||
<P>This content requires JavaScript.</P>
|
||||
</noscript>';
|
||||
}
|
||||
|
||||
private function drawColumn()
|
||||
{
|
||||
$this->_xml .= '<axis_category font="arial" bold="true" size="10" color="000000" />
|
||||
<axis_ticks value_ticks="true" position="inside" />
|
||||
<axis_value font="arial" bold="true" size="11" color="000000" show_min="true" />
|
||||
<chart_border color="000000" top_thickness="0" bottom_thickness="1" left_thickness="1" right_thickness="0" />
|
||||
<chart_transition type="scale" delay="0.5" duration="0.5" order="series" />
|
||||
<chart_label color="000000" size="12" position="cursor" background_color="E2EBEE" alpha="80" />
|
||||
<chart_guide horizontal="true" vertical="true" thickness="1" alpha="25" type="dashed" text_h_alpha="0" text_v_alpha="0" />';
|
||||
}
|
||||
|
||||
private function drawLine()
|
||||
{
|
||||
$this->drawColumn();
|
||||
$this->_xml .= '<series_color><color>A3B6DA</color><color>C3413C</color><color>5A6C83</color><color>CA9A51</color><color>5B7751</color><color>55AA26</color><color>FF2398</color><color>427FC3</color></series_color>
|
||||
<chart_pref line_thickness="2" point_shape="none" fill_shape="false" />';
|
||||
}
|
||||
|
||||
private function drawPie($counter)
|
||||
{
|
||||
$this->_xml .= '<chart_rect positive_color="ffffff" positive_alpha="20" negative_color="ff0000" negative_alpha="10" />
|
||||
<chart_label color="ffffff" alpha="90" font="arial" bold="true" size="10" position="inside" prefix="" suffix="" decimals="0" separator="" as_percentage="true" />
|
||||
<series_color>
|
||||
<color>427FC3</color>
|
||||
<color>C3413C</color>
|
||||
<color>5A6C83</color>
|
||||
<color>CA9A51</color>
|
||||
<color>5B7751</color>
|
||||
<color>55AA26</color>
|
||||
<color>FF2398</color>
|
||||
</series_color>
|
||||
<series_explode>';
|
||||
for ($i = 0; $i < $counter; $i++)
|
||||
$this->_xml .= '<number>9</number>';
|
||||
$this->_xml .= '</series_explode>';
|
||||
$this->_legend_more = ' bullet="circle"';
|
||||
}
|
||||
|
||||
public function createValues($values)
|
||||
{
|
||||
$this->_values = $values;
|
||||
$this->_xml .= '<chart_type>'.$this->_type.'</chart_type><chart_grid_h alpha="20" color="000000" thickness="1" type="dashed" />';
|
||||
|
||||
switch ($this->_type)
|
||||
{
|
||||
case 'pie':
|
||||
$this->drawPie(sizeof($values));
|
||||
break;
|
||||
case 'line':
|
||||
$this->drawLine();
|
||||
break;
|
||||
case 'column':
|
||||
default:
|
||||
$this->drawColumn();
|
||||
$this->_xml .= '<series_color><color>A3B6DA</color><color>C3413C</color><color>5A6C83</color><color>CA9A51</color><color>5B7751</color><color>55AA26</color><color>FF2398</color><color>427FC3</color></series_color>';
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public function setSize($width, $height)
|
||||
{
|
||||
if (isset($width) && !empty($width))
|
||||
$this->_width = $width;
|
||||
else
|
||||
$this->_width = 550;
|
||||
if (isset($height) && !empty($height))
|
||||
$this->_height = $height;
|
||||
else
|
||||
$this->_height = 270;
|
||||
}
|
||||
|
||||
public function setLegend($legend)
|
||||
{
|
||||
$this->_legend = $legend;
|
||||
$this->_xml .= '<legend'.$this->_legend_more.' layout="horizontal" font="arial" bold="true" size="13" color="000000" alpha="85" shadow="low" transition="dissolve" delay="0.5" duration="0.25" fill_color="D4D4D4" fill_alpha="0" line_color="D4D4D4" line_alpha="0" line_thickness="0" />';
|
||||
}
|
||||
|
||||
public function setTitles($titles)
|
||||
{
|
||||
$this->_titles = $titles;
|
||||
$this->_xml .= '<draw>';
|
||||
if (isset($titles['main']))
|
||||
{
|
||||
if ($this->_type == 'pie')
|
||||
$this->_xml .= '<text color="000033" alpha="50" font="arial" rotation="0" bold="true" x="0" y="0" width="'.$this->_width.'" height="'.$this->_height.'" h_align="center" v_align="top">'.$titles['main'].'</text>';
|
||||
}
|
||||
if ($this->_type != 'pie' AND isset($titles['x']) AND isset($titles['y']))
|
||||
{
|
||||
$this->_xml .= '<text color="000033" alpha="50" font="arial" rotation="0" bold="true" size="15" x="0" y="'.($this->_height - 30).'" width="'.$this->_width.'" height="30" h_align="right" v_align="middle">'.$titles['x'].'</text>';
|
||||
$this->_xml .= '<text color="000033" alpha="50" font="arial" rotation="-90" bold="true" size="15" x="0" y="'.$this->_height.'" width="'.$this->_height.'" height="30" h_align="center" v_align="middle">'.$titles['y'].'</text>';
|
||||
}
|
||||
$this->_xml .= '</draw>';
|
||||
}
|
||||
|
||||
public function draw()
|
||||
{
|
||||
header('content-type: text/xml');
|
||||
|
||||
$this->_xml .= '<chart_data><row><null/>';
|
||||
foreach ($this->_legend as $value)
|
||||
$this->_xml .= '<string>'.$value.'</string>';
|
||||
$this->_xml .= '</row>';
|
||||
|
||||
if (!isset($this->_values[0]) || !is_array($this->_values[0]))
|
||||
{
|
||||
$this->_xml .= '<row><string>'.$this->_titles['main'].'</string>';
|
||||
foreach ($this->_values as $value)
|
||||
$this->_xml .= '<number>'. (($value > 0) ? $value : -$value) .'</number>'; //si jamais la valeur est n�gative... logiquement ne devrait jamais arriver
|
||||
$this->_xml .= '</row>';
|
||||
}
|
||||
else
|
||||
{
|
||||
$i = 1;
|
||||
foreach ($this->_values as $value)
|
||||
{
|
||||
$this->_xml .= '<row>';
|
||||
if (isset($this->_titles['main'][$i]))
|
||||
$this->_xml .= '<string>'.$this->_titles['main'][$i].'</string>';
|
||||
foreach ($value as $val)
|
||||
$this->_xml .= '<number>'.$val.'</number>';
|
||||
$this->_xml .= '</row>';
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
$this->_xml .= '</chart_data>';
|
||||
$this->_xml .= '</chart>';
|
||||
echo $this->_xml;
|
||||
}
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* 2007-2013 PrestaShop
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License (AFL 3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://opensource.org/licenses/afl-3.0.php
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
|
||||
* versions in the future. If you wish to customize PrestaShop for your
|
||||
* needs please refer to http://www.prestashop.com for more information.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2013 PrestaShop SA
|
||||
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
|
||||
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
|
||||
|
||||
header("Cache-Control: no-store, no-cache, must-revalidate");
|
||||
header("Cache-Control: post-check=0, pre-check=0", false);
|
||||
header("Pragma: no-cache");
|
||||
|
||||
header("Location: ../");
|
||||
exit;
|
||||
|
Before Width: | Height: | Size: 979 B |
|
Before Width: | Height: | Size: 1.3 KiB |
@@ -1,35 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* 2007-2013 PrestaShop
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License (AFL 3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://opensource.org/licenses/afl-3.0.php
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
|
||||
* versions in the future. If you wish to customize PrestaShop for your
|
||||
* needs please refer to http://www.prestashop.com for more information.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2013 PrestaShop SA
|
||||
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
|
||||
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
|
||||
|
||||
header("Cache-Control: no-store, no-cache, must-revalidate");
|
||||
header("Cache-Control: post-check=0, pre-check=0", false);
|
||||
header("Pragma: no-cache");
|
||||
|
||||
header("Location: ../");
|
||||
exit;
|
||||
@@ -1,292 +0,0 @@
|
||||
//v1.7
|
||||
// Flash Player Version Detection
|
||||
// Detect Client Browser type
|
||||
// Copyright 2005-2007 Adobe Systems Incorporated. All rights reserved.
|
||||
var isIE = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
|
||||
var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;
|
||||
var isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;
|
||||
|
||||
function ControlVersion()
|
||||
{
|
||||
var version;
|
||||
var axo;
|
||||
var e;
|
||||
|
||||
// NOTE : new ActiveXObject(strFoo) throws an exception if strFoo isn't in the registry
|
||||
|
||||
try {
|
||||
// version will be set for 7.X or greater players
|
||||
axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");
|
||||
version = axo.GetVariable("$version");
|
||||
} catch (e) {
|
||||
}
|
||||
|
||||
if (!version)
|
||||
{
|
||||
try {
|
||||
// version will be set for 6.X players only
|
||||
axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");
|
||||
|
||||
// installed player is some revision of 6.0
|
||||
// GetVariable("$version") crashes for versions 6.0.22 through 6.0.29,
|
||||
// so we have to be careful.
|
||||
|
||||
// default to the first public version
|
||||
version = "WIN 6,0,21,0";
|
||||
|
||||
// throws if AllowScripAccess does not exist (introduced in 6.0r47)
|
||||
axo.AllowScriptAccess = "always";
|
||||
|
||||
// safe to call for 6.0r47 or greater
|
||||
version = axo.GetVariable("$version");
|
||||
|
||||
} catch (e) {
|
||||
}
|
||||
}
|
||||
|
||||
if (!version)
|
||||
{
|
||||
try {
|
||||
// version will be set for 4.X or 5.X player
|
||||
axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3");
|
||||
version = axo.GetVariable("$version");
|
||||
} catch (e) {
|
||||
}
|
||||
}
|
||||
|
||||
if (!version)
|
||||
{
|
||||
try {
|
||||
// version will be set for 3.X player
|
||||
axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3");
|
||||
version = "WIN 3,0,18,0";
|
||||
} catch (e) {
|
||||
}
|
||||
}
|
||||
|
||||
if (!version)
|
||||
{
|
||||
try {
|
||||
// version will be set for 2.X player
|
||||
axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
|
||||
version = "WIN 2,0,0,11";
|
||||
} catch (e) {
|
||||
version = -1;
|
||||
}
|
||||
}
|
||||
|
||||
return version;
|
||||
}
|
||||
|
||||
// JavaScript helper required to detect Flash Player PlugIn version information
|
||||
function GetSwfVer(){
|
||||
// NS/Opera version >= 3 check for Flash plugin in plugin array
|
||||
var flashVer = -1;
|
||||
|
||||
if (navigator.plugins != null && navigator.plugins.length > 0) {
|
||||
if (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]) {
|
||||
var swVer2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
|
||||
var flashDescription = navigator.plugins["Shockwave Flash" + swVer2].description;
|
||||
var descArray = flashDescription.split(" ");
|
||||
var tempArrayMajor = descArray[2].split(".");
|
||||
var versionMajor = tempArrayMajor[0];
|
||||
var versionMinor = tempArrayMajor[1];
|
||||
var versionRevision = descArray[3];
|
||||
if (versionRevision == "") {
|
||||
versionRevision = descArray[4];
|
||||
}
|
||||
if (versionRevision[0] == "d") {
|
||||
versionRevision = versionRevision.substring(1);
|
||||
} else if (versionRevision[0] == "r") {
|
||||
versionRevision = versionRevision.substring(1);
|
||||
if (versionRevision.indexOf("d") > 0) {
|
||||
versionRevision = versionRevision.substring(0, versionRevision.indexOf("d"));
|
||||
}
|
||||
}
|
||||
var flashVer = versionMajor + "." + versionMinor + "." + versionRevision;
|
||||
}
|
||||
}
|
||||
// MSN/WebTV 2.6 supports Flash 4
|
||||
else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.6") != -1) flashVer = 4;
|
||||
// WebTV 2.5 supports Flash 3
|
||||
else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.5") != -1) flashVer = 3;
|
||||
// older WebTV supports Flash 2
|
||||
else if (navigator.userAgent.toLowerCase().indexOf("webtv") != -1) flashVer = 2;
|
||||
else if ( isIE && isWin && !isOpera ) {
|
||||
flashVer = ControlVersion();
|
||||
}
|
||||
return flashVer;
|
||||
}
|
||||
|
||||
// When called with reqMajorVer, reqMinorVer, reqRevision returns true if that version or greater is available
|
||||
function DetectFlashVer(reqMajorVer, reqMinorVer, reqRevision)
|
||||
{
|
||||
versionStr = GetSwfVer();
|
||||
if (versionStr == -1 ) {
|
||||
return false;
|
||||
} else if (versionStr != 0) {
|
||||
if(isIE && isWin && !isOpera) {
|
||||
// Given "WIN 2,0,0,11"
|
||||
tempArray = versionStr.split(" "); // ["WIN", "2,0,0,11"]
|
||||
tempString = tempArray[1]; // "2,0,0,11"
|
||||
versionArray = tempString.split(","); // ['2', '0', '0', '11']
|
||||
} else {
|
||||
versionArray = versionStr.split(".");
|
||||
}
|
||||
var versionMajor = versionArray[0];
|
||||
var versionMinor = versionArray[1];
|
||||
var versionRevision = versionArray[2];
|
||||
|
||||
// is the major.revision >= requested major.revision AND the minor version >= requested minor
|
||||
if (versionMajor > parseFloat(reqMajorVer)) {
|
||||
return true;
|
||||
} else if (versionMajor == parseFloat(reqMajorVer)) {
|
||||
if (versionMinor > parseFloat(reqMinorVer))
|
||||
return true;
|
||||
else if (versionMinor == parseFloat(reqMinorVer)) {
|
||||
if (versionRevision >= parseFloat(reqRevision))
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function AC_AddExtension(src, ext)
|
||||
{
|
||||
if (src.indexOf('?') != -1)
|
||||
return src.replace(/\?/, ext+'?');
|
||||
else
|
||||
return src + ext;
|
||||
}
|
||||
|
||||
function AC_Generateobj(objAttrs, params, embedAttrs)
|
||||
{
|
||||
var str = '';
|
||||
if (isIE && isWin && !isOpera)
|
||||
{
|
||||
str += '<object ';
|
||||
for (var i in objAttrs)
|
||||
{
|
||||
str += i + '="' + objAttrs[i] + '" ';
|
||||
}
|
||||
str += '>';
|
||||
for (var i in params)
|
||||
{
|
||||
str += '<param name="' + i + '" value="' + params[i] + '" /> ';
|
||||
}
|
||||
str += '</object>';
|
||||
}
|
||||
else
|
||||
{
|
||||
str += '<embed ';
|
||||
for (var i in embedAttrs)
|
||||
{
|
||||
str += i + '="' + embedAttrs[i] + '" ';
|
||||
}
|
||||
str += '> </embed>';
|
||||
}
|
||||
|
||||
document.write(str);
|
||||
}
|
||||
|
||||
function AC_FL_RunContent(){
|
||||
var ret =
|
||||
AC_GetArgs
|
||||
( arguments, ".swf", "movie", "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
|
||||
, "application/x-shockwave-flash"
|
||||
);
|
||||
AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
|
||||
}
|
||||
|
||||
function AC_SW_RunContent(){
|
||||
var ret =
|
||||
AC_GetArgs
|
||||
( arguments, ".dcr", "src", "clsid:166B1BCA-3F9C-11CF-8075-444553540000"
|
||||
, null
|
||||
);
|
||||
AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
|
||||
}
|
||||
|
||||
function AC_GetArgs(args, ext, srcParamName, classid, mimeType){
|
||||
var ret = new Object();
|
||||
ret.embedAttrs = new Object();
|
||||
ret.params = new Object();
|
||||
ret.objAttrs = new Object();
|
||||
for (var i=0; i < args.length; i=i+2){
|
||||
var currArg = args[i].toLowerCase();
|
||||
|
||||
switch (currArg){
|
||||
case "classid":
|
||||
break;
|
||||
case "pluginspage":
|
||||
ret.embedAttrs[args[i]] = args[i+1];
|
||||
break;
|
||||
case "src":
|
||||
case "movie":
|
||||
args[i+1] = AC_AddExtension(args[i+1], ext);
|
||||
ret.embedAttrs["src"] = args[i+1];
|
||||
ret.params[srcParamName] = args[i+1];
|
||||
break;
|
||||
case "onafterupdate":
|
||||
case "onbeforeupdate":
|
||||
case "onblur":
|
||||
case "oncellchange":
|
||||
case "onclick":
|
||||
case "ondblclick":
|
||||
case "ondrag":
|
||||
case "ondragend":
|
||||
case "ondragenter":
|
||||
case "ondragleave":
|
||||
case "ondragover":
|
||||
case "ondrop":
|
||||
case "onfinish":
|
||||
case "onfocus":
|
||||
case "onhelp":
|
||||
case "onmousedown":
|
||||
case "onmouseup":
|
||||
case "onmouseover":
|
||||
case "onmousemove":
|
||||
case "onmouseout":
|
||||
case "onkeypress":
|
||||
case "onkeydown":
|
||||
case "onkeyup":
|
||||
case "onload":
|
||||
case "onlosecapture":
|
||||
case "onpropertychange":
|
||||
case "onreadystatechange":
|
||||
case "onrowsdelete":
|
||||
case "onrowenter":
|
||||
case "onrowexit":
|
||||
case "onrowsinserted":
|
||||
case "onstart":
|
||||
case "onscroll":
|
||||
case "onbeforeeditfocus":
|
||||
case "onactivate":
|
||||
case "onbeforedeactivate":
|
||||
case "ondeactivate":
|
||||
case "type":
|
||||
case "codebase":
|
||||
case "id":
|
||||
ret.objAttrs[args[i]] = args[i+1];
|
||||
break;
|
||||
case "width":
|
||||
case "height":
|
||||
case "align":
|
||||
case "vspace":
|
||||
case "hspace":
|
||||
case "class":
|
||||
case "title":
|
||||
case "accesskey":
|
||||
case "name":
|
||||
case "tabindex":
|
||||
ret.embedAttrs[args[i]] = ret.objAttrs[args[i]] = args[i+1];
|
||||
break;
|
||||
default:
|
||||
ret.embedAttrs[args[i]] = ret.params[args[i]] = args[i+1];
|
||||
}
|
||||
}
|
||||
ret.objAttrs["classid"] = classid;
|
||||
if (mimeType) ret.embedAttrs["type"] = mimeType;
|
||||
return ret;
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
XML/SWF Charts.php V5
|
||||