📄 openflashchart.php
字号:
<?php/** * Piwik - Open source web analytics * * @link http://piwik.org * @license http://www.gnu.org/licenses/gpl-3.0.html Gpl v3 or later * @version $Id: OpenFlashChart.php 566 2008-07-21 00:34:43Z matt $ * * @package Piwik_Visualization * @subpackage OFC */require_once "iView.php";/** * Original class provided by Open Flash Chart * * @package Piwik_Visualization */abstract class Piwik_Visualization_OpenFlashChart implements Piwik_iView{ function __construct() { $this->data_sets = array(); $this->data = array(); $this->links = array(); $this->width = 250; $this->height = 200; $this->js_path = 'js/'; $this->swf_path = ''; $this->x_labels = array(); $this->y_min = ''; $this->y_max = ''; $this->x_min = ''; $this->x_max = ''; $this->y_steps = ''; $this->title = ''; $this->title_style = ''; $this->occurence = 0; $this->x_offset = ''; $this->x_tick_size = -1; $this->y2_max = ''; $this->y2_min = ''; // GRID styles: $this->x_axis_colour = ''; $this->x_axis_3d = ''; $this->x_grid_colour = ''; $this->x_axis_steps = 1; $this->y_axis_colour = ''; $this->y_grid_colour = ''; $this->y2_axis_colour = ''; // AXIS LABEL styles: $this->x_label_style = ''; $this->y_label_style = ''; $this->y_label_style_right = ''; // AXIS LEGEND styles: $this->x_legend = ''; $this->x_legend_size = 20; $this->x_legend_colour = '#000000'; $this->y_legend = ''; $this->y_legend_right = ''; //$this->y_legend_size = 20; //$this->y_legend_colour = '#000000'; $this->lines = array(); $this->line_default['type'] = 'line'; $this->line_default['values'] = '3,#87421F'; $this->js_line_default = 'so.addVariable("line","3,#87421F");'; $this->bg_colour = ''; $this->bg_image = ''; $this->inner_bg_colour = ''; $this->inner_bg_colour_2 = ''; $this->inner_bg_angle = ''; // PIE chart ------------ $this->pie = ''; $this->pie_values = ''; $this->pie_colours = ''; $this->pie_labels = ''; $this->tool_tip = ''; // which data lines are attached to the // right Y axis? $this->y2_lines = array(); // Number formatting: $this->y_format=''; $this->num_decimals=''; $this->is_fixed_num_decimals_forced=''; $this->is_decimal_separator_comma=''; $this->is_thousand_separator_disabled=''; $this->output_type = ''; // // set some default value incase the user forgets // to set them, so at least they see *something* // even is it is only the axis and some ticks // $this->set_y_min( 0 ); $this->set_y_max( 20 ); $this->set_x_axis_steps( 1 ); $this->y_label_steps( 5 ); } /** * Set the unique_id to use for the flash object id. */ function set_unique_id() { $this->unique_id = uniqid(rand(), true); } /** * Get the flash object ID for the last rendered object. */ function get_unique_id() { return ($this->unique_id); } /** * Set the base path for the swfobject.js * * @param base_path a string argument. * The path to the swfobject.js file */ function set_js_path($path) { $this->js_path = $path; } /** * Set the base path for the open-flash-chart.swf * * @param path a string argument. * The path to the open-flash-chart.swf file */ function set_swf_path($path) { $this->swf_path = $path; } /** * Set the type of output data. * * @param type a string argument. * The type of data. Currently only type is js, or nothing. */ function set_output_type($type) { $this->output_type = $type; } /** * returns the next line label for multiple lines. */ function next_line() { $line_num = ''; if( count( $this->lines ) > 0 ) $line_num = '_'. (count( $this->lines )+1); return $line_num; } // escape commas (,) static function esc( $text ) { // we replace the comma so it is not URL escaped // if it is, flash just thinks it is a comma // which is no good if we are splitting the // string on commas. $tmp = str_replace( ',', '#comma#', $text ); //$tmp = utf8_encode( $tmp ); // now we urlescape all dodgy characters (like & % $ etc..) return urlencode( $tmp ); } /** * Format the text to the type of output. */ function format_output($function,$values) { if($this->output_type == 'js') { $tmp = 'so.addVariable("'. $function .'","'. $values . '");'; } else { $tmp = '&'. $function .'='. $values .'&'; } return $tmp; } /** * Set the text and style of the title. * * @param title a string argument. * The text of the title. * @param style a string. * CSS styling of the title. */ function set_title( $title, $style='' ) { $this->title = $this->esc( $title ); if( strlen( $style ) > 0 ) $this->title_style = $style; } /** * Set the width of the chart. * * @param width an int argument. * The width of the chart frame. */ function set_width( $width ) { $this->width = $width; } /** * Set the height of the chart. * * @param height an int argument. * The height of the chart frame. */ function set_height( $height ) { $this->height = $height; } /** * Set the base path of the swfobject. * * @param base a string argument. * The base path of the swfobject. */ function set_base( $base='js/' ) { $this->base = $base; } // Number formatting: function set_y_format( $val ) { $this->y_format = $val; } function set_num_decimals( $val ) { $this->num_decimals = $val; } function set_is_fixed_num_decimals_forced( $val ) { $this->is_fixed_num_decimals_forced = $val?'true':'false'; } function set_is_decimal_separator_comma( $val ) { $this->is_decimal_separator_comma = $val?'true':'false'; } function set_is_thousand_separator_disabled( $val ) { $this->is_thousand_separator_disabled = $val?'true':'false'; } /** * Set the data for the chart * @param a an array argument. * An array of the data to add to the chart. */ function set_data( $a ) { $this->data[] = implode(',',$a); } // UGH, these evil functions are making me fell ill function set_links( $links ) { // TO DO escape commas: $this->links[] = implode(',',$links); } // $val is a boolean function set_x_offset( $val ) { $this->x_offset = $val?'true':'false'; } /** * Set the tooltip to be displayed on each chart item.\n * \n * Replaceable tokens that can be used in the string include: \n * #val# - The actual value of whatever the mouse is over. \n * #key# - The key string. \n * \<br> - New line. \n * #x_label# - The X label string. \n * #x_legend# - The X axis legend text. \n * Default string is: "#x_label#<br>#val#" \n * * @param tip a string argument. * A formatted string to show as the tooltip. */ function set_tool_tip( $tip ) { $this->tool_tip = $this->esc( $tip ); } /** * Set the x axis labels * * @param a an array argument. * An array of the x axis labels. */ function set_x_labels( $a ) { $tmp = array(); foreach( $a as $item ) $tmp[] = $this->esc( $item ); $this->x_labels = $tmp; } /** * Set the look and feel of the x axis labels * * @param font_size an int argument. * The font size. * @param colour a string argument. * The hex colour value. * @param orientation an int argument. * The orientation of the x-axis text. * 0 - Horizontal * 1 - Vertical * 2 - 45 degrees * @param step an int argument. * Show the label on every $step label. * @param grid_colour a string argument. */ function set_x_label_style( $size, $colour='', $orientation=0, $step=-1, $grid_colour='' ) { $this->x_label_style = $size; if( strlen( $colour ) > 0 ) $this->x_label_style .= ','. $colour; if( $orientation > -1 ) $this->x_label_style .= ','. $orientation; if( $step > 0 ) $this->x_label_style .= ','. $step; if( strlen( $grid_colour ) > 0 ) $this->x_label_style .= ','. $grid_colour; } /** * Set the background colour. * @param colour a string argument. * The hex colour value. */ function set_bg_colour( $colour ) { $this->bg_colour = $colour; } /** * Set a background image. * @param url a string argument. * The location of the image. * @param x a string argument. * The x location of the image. 'Right', 'Left', 'Center' * @param y a string argument. * The y location of the image. 'Top', 'Bottom', 'Middle' */ function set_bg_image( $url, $x='center', $y='center' ) { $this->bg_image = $url; $this->bg_image_x = $x; $this->bg_image_y = $y; } /** * Attach a set of data (a line, area or bar chart) to the right Y axis. * @param data_number an int argument. * The numbered order the data was attached using set_data. */ function attach_to_y_right_axis( $data_number ) { $this->y2_lines[] = $data_number; } /** * Set the background colour of the grid portion of the chart. * @param col a string argument. * The hex colour value of the background. * @param col2 a string argument. * The hex colour value of the second colour if you want a gradient. * @param angle an int argument. * The angle in degrees to make the gradient. */ function set_inner_background( $col, $col2='', $angle=-1 ) { $this->inner_bg_colour = $col; if( strlen($col2) > 0 ) $this->inner_bg_colour_2 = $col2; if( $angle != -1 ) $this->inner_bg_angle = $angle; } /** * Internal function to build the y label style for y and y2 */ function _set_y_label_style( $size, $colour ) { $tmp = $size; if( strlen( $colour ) > 0 ) $tmp .= ','. $colour; return $tmp; } /** * Set the look and feel of the y axis labels * * @param font_size an int argument. * The font size. * @param colour a string argument. * The hex colour value. */ function set_y_label_style( $size, $colour='' ) { $this->y_label_style = $this->_set_y_label_style( $size, $colour ); } /** * Set the look and feel of the right y axis labels * * @param font_size an int argument. * The font size. * @param colour a string argument. * The hex colour value. */ function set_y_right_label_style( $size, $colour='' ) { $this->y_label_style_right = $this->_set_y_label_style( $size, $colour ); } function set_x_max( $max ) { $this->x_max = floatval( $max ); } function set_x_min( $min ) { $this->x_min = floatval( $min ); } /** * Set the maximum value of the y axis. * * @param max an float argument. * The maximum value. */ function set_y_max( $max ) { $this->y_max = floatval( $max ); } /** * Set the minimum value of the y axis. * * @param min an float argument. * The minimum value. */ function set_y_min( $min ) { $this->y_min = floatval( $min ); } /** * Set the maximum value of the right y axis. * * @param max an float argument. * The maximum value. */ function set_y_right_max( $max ) { $this->y2_max = floatval($max); } /** * Set the minimum value of the right y axis. * * @param min an float argument. * The minimum value. */ function set_y_right_min( $min ) { $this->y2_min = floatval($min); } /** * Show the y label on every $step label. * * @param val an int argument. * Show the label on every $step label. */ function y_label_steps( $val ) { $this->y_steps = intval( $val ); } function title( $title, $style='' ) { $this->title = $this->esc( $title ); if( strlen( $style ) > 0 ) $this->title_style = $style; } /** * Set the parameters of the x legend. * * @param text a string argument. * The text of the x legend. * @param font_size an int argument. * The font size of the x legend text. * @param colour a string argument * The hex value of the font colour.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -