kenken999/php
0
1<?php2class Chart3{4 protected $header;5 protected $footer;6 7 protected $y_axis_label;8 9 protected $strLabel;10 11 protected $arrDataLabels = array();12 protected $arrDataSeries = array();13 14 protected $chrt_array = array();15 public $webchart;16 protected $cname;17 18 protected $table_type;19 20 protected $cipherer = null;21 protected $pSet = null;22 protected $searchClauseObj = null;23 24 protected $sessionPrefix = "";25 26 protected $detailTablesData = array();27 28 protected $pageId;29 30 /**31 * A flag helping to detect if to apply32 * 'details' functionality to the chart33 */34 protected $showDetails = true;35 36 /**37 * Flag if the chart in master or details preview mode38 * @type Boolean39 */40 protected $chartPreview = false;41 42 /**43 * It indicates if chart is shown on a dashboard44 */45 protected $dashChart = false;46 47 /**48 * It indicates if first point selected49 */50 protected $dashChartFirstPointSelected = false;51 52 protected $detailMasterKeys = "";53 54 /**55 * Dashboard table name56 * It's set up if chart is shown on a dashboard only57 */58 protected $dashTName = "";59 60 /**61 * Dashboard element name62 * It's set up if chart is shown on a dashboard only63 */64 protected $dashElementName = "";65 66 /**67 * @type Connection68 */69 protected $connection;70 71 /**72 *73 */74 protected $_2d;75 76 /**77 *78 */79 protected $noRecordsFound = false;80 81 /**82 *83 */84 protected $singleSeries = false;85 86 protected $masterKeysReq;87 protected $masterTable;88 89 /**90 * DataSource91 */92 protected $dataSource = null;93 protected $tName = "";94 95 96 function __construct( &$ch_array, $param )97 {98 global $strTableName;99 100 $this->webchart = $param["webchart"];101 102 if( $this->webchart )103 $this->chrt_array = Convert_Old_Chart($ch_array);104 else105 $this->chrt_array = $ch_array;106 107 $this->tName = $this->chrt_array['tables'][0];108 109 // #10461, $this->setConnection(); needs to be called after value is assigned to $this->webchart110 $this->setConnection();111 112 $this->pSet = new ProjectSettings( $this->tName, PAGE_CHART );113 $this->showDetails = $param['showDetails'];114 if( $this->showDetails )115 {116 $this->detailTablesData = $this->pSet->getDetailTablesArr();117 for($i = 0; $i < count($this->detailTablesData); $i ++)118 {119 $strPerm = GetUserPermissions($this->detailTablesData[$i]['dDataSourceTable']);120 if ( strpos($strPerm, "S") === false )121 unset($this->detailTablesData[$i]);122 }123 }124 125 $this->table_type = $this->chrt_array["table_type"];126 if( !$this->table_type )127 $this->table_type = "project";128 129 if( $this->table_type == "project" ) {130 // project table131 $this->dataSource = getDataSource( $this->tName, $this->pSet, $this->connection );132 } else {133 // db-table-based webchart134 $this->dataSource = getWebDataSource( $this->chrt_array );135 }136 137 $this->pageId = $param["pageId"];138 $this->chrt_array["appearance"]["autoupdate"] = false;139 140 141 $this->cname = $param["cname"];142 143 $this->sessionPrefix = $this->chrt_array['tables'][0];144 145 $this->masterTable = $param["masterTable"];146 $this->masterKeysReq = $param["masterKeysReq"];147 148 // true if chart has master149 $this->chartPreview = $param["chartPreview"];150 $this->dashChart = $param["dashChart"];151 152 if( $this->dashChart )153 {154 $this->dashTName = $param["dashTName"];155 $this->dashElementName = $param["dashElementName"];156 $this->sessionPrefix = $this->dashTName."_".$this->sessionPrefix;157 }158 159 if( !$this->webchart && !$this->chartPreview && isset( $_SESSION[ $this->sessionPrefix.'_advsearch' ] ) )160 $this->searchClauseObj = SearchClause::UnserializeObject( $_SESSION[ $this->sessionPrefix.'_advsearch' ] );161 162 if( $this->searchClauseObj )163 RunnerContext::pushSearchContext( $this->searchClauseObj );164 165 if( $this->isProjectDB() ) {166 $this->cipherer = new RunnerCipherer( $this->tName ); 167 }168 169 $this->setBasicChartProp();170 171 if( tableEventExists("UpdateChartSettings", $strTableName) )172 {173 $eventObj = getEventObject( $strTableName );174 $eventObj->UpdateChartSettings( $this );175 }176 }177 178 /**179 * @param Array params180 */181 protected function setSpecParams( $params )182 {183 if( $params['name'] == "" )184 return;185 186 if( $this->table_type != "db" )187 $this->arrDataSeries[] = $params['agr_func'] ? $params['label'] : $params['name'];188 else {189 $this->arrDataSeries[] = $params['table']."_".$params['name'];190// $this->arrDataSeries[] = $params['name'];191 }192 }193 194 /**195 * @param Array params196 * @param String gTableName197 */198 protected function setDataLabels( $params, $gTableName )199 {200 $chartType = $this->chrt_array["chart_type"]["type"];201 if( $this->table_type == "project" && !$this->webchart )202 {203 if( $chartType != "candlestick" && $chartType != "ohlc" )204 $this->arrDataLabels[] = GetFieldLabel( $gTableName, GoodFieldName($params['name']) );205 else206 $this->arrDataLabels[] = GetFieldLabel( $gTableName, GoodFieldName($params['ohlcOpen']) ) ;207 }208 else209 {210 if( !$params['label'] )211 {212 if( $chartType != "candlestick" && $chartType != "ohlc" )213 $this->arrDataLabels[] = $params['name'];214 else215 $this->arrDataLabels[] = $params['ohlcOpen'];216 }217 else218 $this->arrDataLabels[] = $params['label'];219 }220 }221 222 /**223 *224 */225 protected function setBasicChartProp()226 {227 $this->header = $this->chrt_array['appearance']['head'];228 $this->header = $this->header ? $this->header : '';229 230 $this->footer = $this->chrt_array['appearance']['foot'];231 $this->footer = $this->footer ? $this->footer : '';232 233 for ( $i = 0; $i<count($this->chrt_array['parameters']) - 1; $i++)234 {235 $this->setSpecParams( $this->chrt_array['parameters'][$i] );236 $this->setDataLabels( $this->chrt_array['parameters'][$i], GoodFieldName( $this->chrt_array['tables'][0] ) );237 }238 239 if( $this->chrt_array["chart_type"]["type"] != "gauge" )240 {241 $chartParams = $this->chrt_array['parameters'];242 $params = $chartParams[ count($chartParams) - 1 ];243 244 if( $this->table_type != "db" )245 $this->strLabel = $params['name'];246 else {247// $this->strLabel = $params['name'];248 $this->strLabel = $params['agr_func'] ? $params['agr_func']."_".$params['table']."_".$params['name']: $params['table']."_".$params['name'];249 }250 }251 252 if( count( $this->arrDataLabels ) == 1 )253 $this->y_axis_label = $this->arrDataLabels[0];254 else255 $this->y_axis_label = $this->chrt_array['appearance']['y_axis_label'];256 }257 258 259 protected function getMasterCondition() {260 if( $this->dashChart )261 return null;262 263 $detailKeysByM = $this->pSet->getDetailKeysByMasterTable( $this->masterTable );264 if( !$detailKeysByM )265 return null;266 267 $conditions = array();268 for( $i = 0; $i < count( $detailKeysByM ); ++$i ) {269 $conditions[] = DataCondition::FieldEquals( $detailKeysByM[ $i ], $this->masterKeysReq[ $i + 1 ] );270 }271 272 return DataCondition::_And( $conditions );273 }274 275 /**276 * Get datasource command277 */278 public function getSubsetDataCommand( $ignoreFilterField = "" ) {279 $dc = new DsCommand();280 281 $dc->filter = DataCondition::_And( array(282 Security::SelectCondition( "S", $this->pSet ),283 $this->getMasterCondition()284 ));285 286 if( !$this->chartPreview && $this->searchClauseObj ) {287 $search = $this->searchClauseObj->getSearchDataCondition();288 $filter = $this->searchClauseObj->getFilterCondition( $this->pSet );289 290 $dc->filter = DataCondition::_And( array( $dc->filter, $search, $filter ) );291 }292 293 // where tabs294 if( $_SESSION[ $this->sessionPrefix . "_chartTabWhere" ] ) {295 $dc->filter = DataCondition::_And( array(296 $dc->filter,297 DataCondition::SQLCondition( $_SESSION[ $this->sessionPrefix . "_chartTabWhere" ] )298 ));299 }300 301 require_once( getabspath('classes/orderclause.php') );302 $orderObject = new OrderClause( $this->pSet, $this->cipherer, $this->sessionPrefix, $this->connection );303 $dc->order = $orderObject->getOrderFields();304 305 if( $this->pSet->getRecordsLimit() )306 $dc->reccount = $this->pSet->getRecordsLimit();307 308 if( $this->pSet->groupChart() )309 $dc->totals = $this->getGroupChartCommandTotals();310 311 return $dc;312 }313 314 /**315 * Get ds command totals316 * total fields appear in the same order317 they do in an original orderby clause318 * @return array319 */320 protected function getGroupChartCommandTotals() {321 $totals = array();322 // label field323 $totals[] = array(324 "alias" => $this->pSet->chartLabelField(),325 "field" => $this->pSet->chartLabelField(),326 "modifier" => $this->pSet->chartLabelInterval()327 );328 329 $series = $this->pSet->chartSeries();330 foreach( $series as $s ) {331 $totals[] = array(332 "alias" => $s["field"],333 "field" => $s["field"],334 "total" => strtolower( $s["total"] )335 );336 }337 338 $orderInfo = $this->pSet->getOrderIndexes();339 if( !$orderInfo )340 return $totals;341 342 $fields = array();343 foreach( $orderInfo as $o ) {344 $fields[] = $this->pSet->GetFieldByIndex( $o[0] );345 }346 347 foreach( $totals as $idx => $t ) {348 if( !in_array( $t["field"], $fields ) )349 $fields[] = $t["field"];350 351 foreach( $orderInfo as $o ) {352 $fieldIdx = $this->pSet->getFieldIndex( $t["field"] );353 if( $fieldIdx == $o[0] ) {354 $totals[ $idx ]["direction"] = $o[1];355 break;356 }357 }358 }359 360 $_totals = array();361 foreach( $fields as $field ) {362 foreach( $totals as $t ) {363 if( $t["field"] == $field ) {364 $_totals[] = $t;365 }366 }367 }368 369 return $_totals;370 }371 372 /**373 * Check for a web chart if it's based on the project table374 * @return Boolean375 */376 protected function isProjectDB()377 {378 if( !$this->webchart )379 return true;380 381 if("chat_history" == $this->chrt_array['tables'][0])382 return true;383 if("chat_users" == $this->chrt_array['tables'][0])384 return true;385 if("chat_settings" == $this->chrt_array['tables'][0])386 return true;387 if("chat_files" == $this->chrt_array['tables'][0])388 return true;389 if("chat_groups" == $this->chrt_array['tables'][0])390 return true;391 if("chat_peopletype" == $this->chrt_array['tables'][0])392 return true;393 if("chat_timezone" == $this->chrt_array['tables'][0])394 return true;395 if("chat126_users1" == $this->chrt_array['tables'][0])396 return true;397 if("Chat2ugrights" == $this->chrt_array['tables'][0])398 return true;399 if("Chat2ugmembers" == $this->chrt_array['tables'][0])400 return true;401 if("chat126_users1" == $this->chrt_array['tables'][0])402 return true;403 if("chat_agent" == $this->chrt_array['tables'][0])404 return true;405 if("chat_external" == $this->chrt_array['tables'][0])406 return true;407 if("agett_prompt" == $this->chrt_array['tables'][0])408 return true;409 return false;410 }411 412 /**413 * Set the 'connection' property #9875414 */415 protected function setConnection()416 {417 global $cman;418 419 if($this->isProjectDB())420 $this->connection = $cman->byTable( $this->tName );421 else422 $this->connection = $cman->getDefault();423 }424 425 public function setFooter($name)426 {427 $this->footer = $name;428 }429 430 public function getFooter()431 {432 return $this->footer;433 }434 435 public function setHeader($name)436 {437 $this->header = $name;438 }439 440 public function getHeader()441 {442 return $this->header;443 }444 445 public function setLabelField($name)446 {447 $this->strLabel = $name;448 }449 450 public function getLabelField()451 {452 return $this->strLabel;453 }454 455 /**456 * @return String457 */458 protected function getDetailedTooltipMessage()459 {460 if( !$this->showDetails || !$this->detailTablesData )461 return "";462 463 $showClickHere = true;464 465 if( $this->dashChart )466 {467 $showClickHere = false;468 469 $pDSet = new ProjectSettings( $this->dashTName );470 $arrDElem = $pDSet->getDashboardElements();471 foreach($arrDElem as $elem)472 {473 if( $elem["table"] == $this->chrt_array['tables'][0] && !!$elem["details"] )474 $showClickHere = true;475 }476 }477 478 if( $showClickHere )479 {480 $tableCaption = GetTableCaption( $this->detailTablesData[0]['dDataSourceTable'] );481 $tableCaption = $tableCaption ? $tableCaption : $this->detailTablesData[0]['dDataSourceTable'];482 483 return "\nClick here to see ".$tableCaption." details";484 }485 486 return "";487 }488 489 /**490 * @return String491 */492 protected function getNoDataMessage()493 {494 if( !$this->noRecordsFound )495 return "";496 497 if( !$this->searchClauseObj )498 return "No data yet.";499 500 if( $this->searchClauseObj->isSearchFunctionalityActivated() )501 return "No results found.";502 503 return "No data yet.";504 }505 506 /**507 *508 */509 public function write()510 {511 $data = array();512 $chart = array();513 514 $this->setTypeSpecChartSettings( $chart );515 if ( @$this->chrt_array["appearance"]["color71"] != "" || @$this->chrt_array["appearance"]["color91"] != "" )516 $chart["background"] = array();517 if ( @$this->chrt_array["appearance"]["color71"] != "" )518 $chart["background"]["fill"] = "#".$this->chrt_array["appearance"]["color71"];519 520 if ( @$this->chrt_array["appearance"]["color91"] != "" )521 $chart["background"]["stroke"] = "#".$this->chrt_array["appearance"]["color91"];522 523 if( $this->noRecordsFound )524 {525 $data["noDataMessage"] = $this->getNoDataMessage();526 echo my_json_encode( $data );527 return;528 }529 530 // animation531 if( $this->chrt_array["appearance"]["sanim"] == "true" && $this->chrt_array["appearance"]["autoupdate"] != "true" ) // update?532 $chart["animation"] = array("enabled" => "true", "duration" => 1000);533 534 // legend535 if( $this->chrt_array['appearance']['slegend'] == "true" && !$this->chartPreview )536 $chart["legend"] = array("enabled" => "true");537 else538 $chart["legend"] = array("enabled" => false);539 540 $chart["credits"] = false;541 // title/header542 $chart["title"] = array("enabled" => "true", "text" => $this->header);543 if ( @$this->chrt_array["appearance"]["color101"] != "" )544 $chart["title"]["fontColor"] = "#".$this->chrt_array["appearance"]["color101"];545 546 // assign and display547 $data["chart"] = $chart;548 echo my_json_encode( $data );549 }550 551 /**552 * A stub553 * @param &Array chart554 */555 protected function setTypeSpecChartSettings( &$chart )556 {557 }558 559 /**560 * @return Array561 */562 protected function getGrids()563 {564 $grids = array();565 566 if($this->chrt_array["appearance"]["sgrid"] == "true")567 {568 $stroke = @$this->chrt_array["appearance"]["color121"] != "" ? "#" . $this->chrt_array["appearance"]["color121"] : "#ddd";569 570 $grid0 = array(571 "enabled" => true,572 "drawLastLine" => false,573 "stroke" => $stroke,574 "scale" => 0,575 "axis" => 0576 );577 578 if ( @$this->chrt_array["appearance"]["color81"] != "" )579 {580 $dataPlotBackgroundColor = "#" . $this->chrt_array["appearance"]["color81"];581 $grid0["oddFill"] = $dataPlotBackgroundColor;582 $grid0["evenFill"] = $dataPlotBackgroundColor;583 }584 585 $grids[] = $grid0;586 587 $grids[] = array(588 "enabled" => true,589 "drawLastLine" => false,590 "stroke" => $stroke,591 "axis" => 1592 );593 }594 595 return $grids;596 }597 598 /**599 * @param String fieldName600 * @param Array data601 * @return String602 */603 protected function labelFormat($fieldName, $data, $truncated = true)604 {605 if( !$fieldName )606 return "";607 608 if( $this->table_type == "db" && !!$this->chrt_array['customLabels'] )609 $fieldName = $this->chrt_array['customLabels'][ $fieldName ];610 611 include_once getabspath('classes/controls/ViewControlsContainer.php');612 $viewControls = new ViewControlsContainer( $this->pSet, PAGE_CHART );613 if( $this->pSet->groupChart() ) {614 $interval = $this->pSet->chartLabelInterval();615 if( $interval ) {616 $fType = $this->pSet->getFieldType( $fieldName );617 return RunnerPage::formatGroupValueStatic( $fieldName, $interval, $data[ $fieldName ], $this->pSet, $viewControls, false );618 }619 }620 $value = $viewControls->showDBValue( $fieldName, $data, "", "", false );621 622 if( $truncated && strlen($value) > 50 )623 $value = runner_substr($value, 0, 47)."...";624 625 return $value;626 }627 628 protected function beforeQueryEvent( &$dc ) {629 $eventsObject = getEventObject( $this->pSet->getTableName() );630 631 // ASP conversion requires these checks be separate632 if( !$eventsObject )633 return;634 if( !$eventsObject->exists("BeforeQueryChart") ) {635 return;636 }637 638 $prep = $this->dataSource->prepareSQL( $dc );639 $where = $prep["where"];640 $sql = $prep["sql"];641 $order = $prep["order"];642 643 // call Before Query event644 $eventsObject->BeforeQueryChart( $sql, $where, $order );645 646 if( $sql != $prep["sql"] )647 $this->dataSource->overrideSQL( $dc, $sql );648 else {649 if( $where != $prep["where"] )650 $this->dataSource->overrideWhere( $dc, $where );651 if( $order != $prep["order"] )652 $this->dataSource->overrideOrder( $dc, $order );653 }654 }655 656 /**657 * @return Array658 */659 public function get_data()660 {661 $data = array();662 $clickdata = array();663 for ( $i = 0; $i < count($this->arrDataSeries); $i++ )664 {665 $data[$i] = array();666 $clickdata[$i] = array();667 }668 669 $dc = $this->getSubsetDataCommand();670 $this->beforeQueryEvent( $dc );671 672 if( $this->pSet->groupChart() ) {673 $rs = $this->dataSource->getTotals( $dc );674 } else {675 $rs = $this->dataSource->getList( $dc );676 }677 if( !$rs ) {678 showError( $this->dataSource->lastError() );679 }680 681 $row = $rs->fetchAssoc();682 if( $this->cipherer )683 $row = $this->cipherer->DecryptFetchedArray( $row );684 685 if( !$row )686 $this->noRecordsFound = true;687 688 while ($row)689 {690 for ( $i = 0; $i < count($this->arrDataSeries); $i++ )691 {692 $data[$i][] = $this->getPoint($i, $row);693 694 $strLabelFormat = $this->labelFormat( $this->strLabel, $row );695 $clickdata[$i][] = $this->getActions( $row , $this->arrDataSeries[$i], $strLabelFormat );696 }697 698 $row = $rs->fetchAssoc();699 if( $this->cipherer )700 $row = $this->cipherer->DecryptFetchedArray( $row );701 }702 703 $series = array();704 for ( $i = 0; $i < count($this->arrDataSeries); $i++ )705 {706 $series[] = $this->getSeriesData( $this->arrDataLabels[$i], $data[$i], $clickdata[$i], $i, count($this->arrDataSeries) > 1 );707 }708 709 return $series;710 }711 712 /**713 * @param Number seriesNumber714 * @param Array row715 * @return Array716 */717 protected function getPoint( $seriesNumber, $row ) {718 $strLabelFormat = $this->labelFormat( $this->strLabel, $row );719 720 include_once getabspath('classes/controls/ViewControlsContainer.php');721 $viewControls = new ViewControlsContainer( $this->pSet, PAGE_CHART ); 722 723 if( $this->table_type != "db" || !$this->chrt_array['customLabels'] ) {724 $strDataSeries = $row[ $this->arrDataSeries[ $seriesNumber ] ];725 $fieldName = $this->arrDataSeries[ $seriesNumber ];726 $formattedValue = $viewControls->showDBValue( $fieldName, $row, "", "", false );727 } else {728 $strDataSeries = $row[ $this->chrt_array['customLabels'][ $this->arrDataSeries[ $seriesNumber ] ] ];729 $fieldName = $this->chrt_array['customLabels'][ $this->arrDataSeries[ $seriesNumber ] ];730 $formattedValue = $viewControls->showDBValue( $fieldName, $row, "", "", false );731 }732 733 return array( 734 "x" => $strLabelFormat, 735 "value" => (double)str_replace(",", ".", $strDataSeries),736 "viewAsValue" => $formattedValue737 );738 }739 740 /**741 * @param String name742 * @param Array pointsData743 * @param Array clickData744 * @param Number seriesNumber745 * @param Boolean multiSeries (optional)746 * @return Array747 */748 protected function getSeriesData( $name, $pointsData, $clickData, $seriesNumber, $multiSeries = true )749 {750 $data = array(751 "name" => $name,752 "data" => $pointsData,753 "xScale" => "0",754 "yScale" => "1",755 "seriesType" => $this->getSeriesType($seriesNumber)756 );757 758 $data["labels"] = array( 759 "enabled" => $this->chrt_array["appearance"]["sval"] == "true", 760 "format" => "{%viewAsValue}" 761 );762 763 if ( @$this->chrt_array["appearance"]["color61"] != "" )764 $data["labels"]["fontColor"] = "#".$this->chrt_array["appearance"]["color61"];765 766 if( $clickData && $this->detailTablesData )767 $data["clickData"] = $clickData;768 769 $data["tooltip"] = $this->getSeriesTooltip( $multiSeries );770 771 return $data;772 }773 774 /**775 * @param Boolean $multiSeries776 * @return Array777 */778 protected function getSeriesTooltip( $multiSeries ) { 779 return array(780 "enabled" => true,781 "format" => "{%seriesName}: {%viewAsValue}". $this->getDetailedTooltipMessage(),782 );783 }784 785 /**786 * @return String787 */788 protected function getSeriesType($seriesNumber)789 {790 return "column";791 }792 793 /**794 * @deprecated795 * @param String str796 * @return String797 */798 protected function chart_xmlencode($str)799 {800 return str_replace(array("&","<",">","\""),array("&","<",">","""),$str);801 }802 803 /**804 * Get a 'point click' action data805 * @param Array data806 * @param Number seriesId807 * @param Number pointId808 * @return Array809 */810 protected function getActions( $data, $seriesId, $pointId )811 {812 global $strTableName;813 814 if( !$this->detailTablesData )815 return null;816 817 if ( $this->dashChart )818 {819 $masterKeysArr = array();820 foreach ( $this->detailTablesData as $detailId => $detail )821 {822 foreach( $detail['masterKeys'] as $idx => $mk )823 {824 $masterKeysArr[ $detail['dDataSourceTable'] ] = array( 'masterkey'.($idx + 1) => $data[ $mk ] );825 }826 }827 828 if (!$this->dashChartFirstPointSelected)829 {830 $this->dashChartFirstPointSelected = true;831 $this->detailMasterKeys = my_json_encode( $masterKeysArr );832 }833 834 return array( "masterKeys" => $masterKeysArr, "seriesId" => $seriesId, "pointId" => $pointId );835 }836 837 // The one detail table is allowed for a chart page only838 $detailTableData = $this->detailTablesData[0];839 $masterquery = "mastertable=".rawurlencode( $strTableName );840 foreach( $detailTableData['masterKeys'] as $idx => $mk )841 {842 $masterquery.= "&masterkey".($idx + 1)."=".rawurlencode( $data[ $mk ] );843 }844 845 return array( "url" => GetTableLink( $detailTableData['dShortTable'], $detailTableData['dType'], $masterquery ) );846 }847 848 protected function getLogarithm()849 {850 if( $this->chrt_array["appearance"]["slog"] == "true" )851 return true;852 return false;853 }854}855 856 857class Chart_Bar extends Chart858{859 protected $stacked;860 protected $bar;861 862 function __construct( &$ch_array, $param )863 {864 parent::__construct( $ch_array, $param );865 866 $this->stacked = $param["stacked"];867 $this->_2d = $param["2d"];868 $this->bar = $param["bar"];869 }870 871 /**872 * @return String873 */874 protected function getSeriesType($seriesNumber)875 {876 if($this->bar)877 return "bar";878 else879 return "column";880 }881 882 /**883 * @param &Array chart884 */885 protected function setTypeSpecChartSettings( &$chart )886 {887 $chart["series"] = $this->get_data();888 889 $chart["scales"] = $this->getScales();890 $chart["logarithm"] = parent::getLogarithm();891 892 if( $this->bar )893 $chart["type"] = "bar";894 else895 $chart["type"] = "column";896 897 if( !$this->_2d )898 $chart["type"] .= "-3d";899 900 $chart["xScale"] = 0;901 $chart["yScale"] = 1;902 903 // grid904 $chart["grids"] = $this->getGrids();905 906 907 // Y-axis label908 $chart["yAxes"] = array(909 array(910 "enabled" => "true",911 "title" => $this->y_axis_label912 ));913 914 // X-axis label915 $chart["xAxes"] = array(916 array(917 "enabled" => "true",918 "title" => array( 'text' => $this->footer ),919 "labels" => array( "enabled" => $this->chrt_array["appearance"]["sname"] == "true" )920 ));921 922 if ( @$this->chrt_array["appearance"]["color51"] != "" )923 $chart["xAxes"][0]["labels"]["fontColor"] = "#".$this->chrt_array["appearance"]["color51"];924 925 if ( @$this->chrt_array["appearance"]["color111"] != "" )926 $chart["xAxes"][0]["title"]["fontColor"] = "#".$this->chrt_array["appearance"]["color111"];927 928 if ( @$this->chrt_array["appearance"]["color131"] != "" )929 $chart["xAxes"][0]["stroke"] = "#".$this->chrt_array["appearance"]["color131"];930 931 if ( @$this->chrt_array["appearance"]["color141"] != "" )932 $chart["yAxes"][0]["stroke"] = "#".$this->chrt_array["appearance"]["color141"];933 }934 935 /**936 * "scales"937 * @return Array938 */939 protected function getScales()940 {941 if($this->stacked || $this->chrt_array["appearance"]["slog"] == "true")942 {943 $arr = array();944 if( $this->stacked )945 $arr["stackMode"] = "value";946 947 if( $this->chrt_array["appearance"]["slog"] == "true" )948 {949 $arr["logBase"] = 10;950 $arr["type"] = "log";951 };952 953 return array(954 array("names" => array()),955 $arr956 );957 }958 959 return array();960 }961}962 963class Chart_Line extends Chart964{965 protected $type_line;966 967 968 function __construct( &$ch_array, $param )969 {970 parent::__construct( $ch_array, $param );971 972 $this->type_line = $param["type_line"];973 }974 975 /**976 * @param &Array chart977 */978 protected function setTypeSpecChartSettings( &$chart )979 {980 $chart["series"] = $this->get_data();981 $chart["type"] = "line";982 983 $chart["xScale"] = 0;984 $chart["yScale"] = 1;985 $chart["grids"] = $this->getGrids();986 $chart["logarithm"] = parent::getLogarithm();987 $chart["tooltip"] = array("displayMode" => "single");988 989 $chart["yAxes"] = array(990 array( "enabled" => "true", "title" => $this->y_axis_label )991 );992 993 $chart["xAxes"] = array(994 array(995 "enabled" => "true",996 "title" => array( 'text' => $this->footer ),997 "labels" => array( "enabled" => $this->chrt_array["appearance"]["sname"] == "true" )998 ));999 1000 if ( @$this->chrt_array["appearance"]["color51"] != "" )1001 $chart["xAxes"][0]["labels"]["fontColor"] = "#".$this->chrt_array["appearance"]["color51"];1002 1003 if ( @$this->chrt_array["appearance"]["color111"] != "" )1004 $chart["xAxes"][0]["title"]["fontColor"] = "#".$this->chrt_array["appearance"]["color111"];1005 1006 if ( @$this->chrt_array["appearance"]["color131"] != "" )1007 $chart["xAxes"][0]["stroke"] = "#".$this->chrt_array["appearance"]["color131"];1008 1009 if ( @$this->chrt_array["appearance"]["color141"] != "" )1010 $chart["yAxes"][0]["stroke"] = "#".$this->chrt_array["appearance"]["color141"];1011 }1012 1013 /**1014 * @return String1015 */1016 protected function getSeriesType($seriesNumber)1017 {1018 switch( $this->type_line )1019 {1020 case "line":1021 return "line";1022 case "spline":1023 return "spline";1024 case "step_line":1025 return "stepLine";1026 default:1027 return "line";1028 }1029 }1030}1031 1032class Chart_Area extends Chart1033{1034 protected $stacked;1035 1036 1037 function __construct( &$ch_array, $param )1038 {1039 parent::__construct( $ch_array, $param );1040 1041 $this->stacked = $param["stacked"];1042 }1043 1044 /**1045 * @param &Array chart1046 */1047 protected function setTypeSpecChartSettings( &$chart )1048 {1049 $chart["series"] = $this->get_data();1050 1051 if( $this->stacked )1052 $chart["scales"] = $this->getScales();1053 $chart["type"] = "area";1054 $chart["xScale"] = 0;1055 $chart["yScale"] = 1;1056 $chart["logarithm"] = parent::getLogarithm();1057 $chart["grids"] = $this->getGrids();1058 1059 $chart["tooltip"] = array("displayMode" => "single");1060 1061 $chart["yAxes"] = array(1062 array( "enabled" => "true", "title" => $this->y_axis_label )1063 );1064 1065 $chart["xAxes"] = array(1066 array(1067 "enabled" => "true",1068 "title" => array( 'text' => $this->footer ),1069 "labels" => array( "enabled" => $this->chrt_array["appearance"]["sname"] == "true" )1070 ));1071 1072 if ( @$this->chrt_array["appearance"]["color51"] != "" )1073 $chart["xAxes"][0]["labels"]["fontColor"] = "#".$this->chrt_array["appearance"]["color51"];1074 1075 if ( @$this->chrt_array["appearance"]["color111"] != "" )1076 $chart["xAxes"][0]["title"]["fontColor"] = "#".$this->chrt_array["appearance"]["color111"];1077 1078 if ( @$this->chrt_array["appearance"]["color131"] != "" )1079 $chart["xAxes"][0]["stroke"] = "#".$this->chrt_array["appearance"]["color131"];1080 1081 if ( @$this->chrt_array["appearance"]["color141"] != "" )1082 $chart["yAxes"][0]["stroke"] = "#".$this->chrt_array["appearance"]["color141"];1083 }1084 1085 /**1086 * @return String1087 */1088 protected function getSeriesType($seriesNumber)1089 {1090 return "area";1091 }1092 1093 /**1094 * "scales"1095 * @return Array1096 */1097 protected function getScales()1098 {1099 if( $this->stacked )1100 {1101 $arr = array();1102 $arr["stackMode"] = "value";1103 1104 if( $this->chrt_array["appearance"]["sstacked"] == "true" )1105 {1106 $arr["stackMode"] = "percent";1107 $arr["maximumGap"] = "10";1108 $arr["maximum"] = "100";1109 };1110 1111 return array(1112 array( "names"=> array() ),1113 $arr1114 );1115 }1116 1117 return array();1118 }1119}1120 1121/**1122 * A single series chart1123 */1124class Chart_Pie extends Chart1125{1126 protected $pie;1127 1128 1129 function __construct( &$ch_array, $param )1130 {1131 parent::__construct( $ch_array, $param );1132 1133 $this->pie = $param["pie"];1134 $this->_2d = $param["2d"];1135 $this->singleSeries = true;1136 }1137 1138 /**1139 * @param &Array chart1140 */1141 protected function setTypeSpecChartSettings( &$chart )1142 {1143 $series = $this->get_data();1144 1145 $chart["data"] = $series[0]["data"];1146 $chart["clickData"] = $series[0]["clickData"];1147 $chart["singleSeries"] = true;1148 $chart["tooltip"] = $series[0]["tooltip"];1149 $chart["logarithm"] = false;1150 if( $this->_2d )1151 $chart["type"] = "pie";1152 else1153 $chart["type"] = "pie-3d";1154 1155 if( !$this->pie )1156 $chart["innerRadius"] = "30%";1157 1158 if( $this->chrt_array['appearance']['slegend'] == "true" && !$this->chartPreview )1159 {1160 $chart["legend"] = array("enabled" => "true");1161 }1162 1163 $chart["labels"] = array( "enabled" => $this->chrt_array["appearance"]["sval"] == "true" || $this->chrt_array["appearance"]["sname"] == "true" );1164 1165 if ( @$this->chrt_array["appearance"]["color51"] != "" )1166 {1167 if ( $this->chrt_array["appearance"]["sval"] )1168 {1169 $chart["labels"]["fontColor"] = "#".$this->chrt_array["appearance"]["color61"];1170 }1171 else if ( $this->chrt_array["appearance"]["sname"] )1172 {1173 $chart["labels"]["fontColor"] = "#".$this->chrt_array["appearance"]["color51"];1174 }1175 }1176 1177 }1178}1179 1180class Chart_Combined extends Chart1181{1182 function __construct( &$ch_array, $param )1183 {1184 parent::__construct( $ch_array, $param );1185 }1186 1187 /**1188 * @param &Array chart1189 */1190 protected function setTypeSpecChartSettings( &$chart )1191 {1192 $chart["series"] = $this->get_data();1193 $chart["type"] = "column";1194 $chart["logarithm"] = parent::getLogarithm();1195 $chart["xScale"] = 0;1196 $chart["yScale"] = 1;1197 $chart["grids"] = $this->getGrids();1198 $chart["yAxes"] = array(1199 array( "enabled" => "true", "title" => $this->y_axis_label )1200 );