$graphrows = array(); $specialrows = array(); $gC = 0;
$gDefs = ''; $gGraphs = ''; $addSpecial = '';
+ // the default size for the graph area has a width of 400px, so use 400 slices by default
if ($timeframe == 'day') {
- $duration = isset($gconf['duration'])?$gconf['duration']:30*3600; // 30 hours
$slice = isset($gconf['slice'])?$gconf['slice']:300; // 5 minutes
+ $duration = isset($gconf['duration'])?$gconf['duration']:400*$slice; // 33.33 hours
// vertical lines at day borders
$addSpecial .= ' VRULE:'.strtotime(date('Y-m-d')).'#FF0000';
$addSpecial .= ' VRULE:'.strtotime(date('Y-m-d').' -1 day').'#FF0000';
if (!isset($gconf['grid_x'])) { $gconf['grid_x'] = 'HOUR:1:HOUR:6:HOUR:2:0:%-H'; }
}
elseif ($timeframe == 'week') {
- $duration = isset($gconf['duration'])?$gconf['duration']:8*86400; // 8 days
$slice = isset($gconf['slice'])?$gconf['slice']:1800; // 30 minutes
+ $duration = isset($gconf['duration'])?$gconf['duration']:400*$slice; // 8.33 days
// vertical lines at week borders
$addSpecial .= ' VRULE:'.strtotime(date('Y-m-d').' '.(-date('w')+1).' day').'#FF0000';
$addSpecial .= ' VRULE:'.strtotime(date('Y-m-d').' '.(-date('w')-6).' day').'#FF0000';
}
elseif ($timeframe == 'month') {
- $duration = isset($gconf['duration'])?$gconf['duration']:36*86400; // 36 days
$slice = isset($gconf['slice'])?$gconf['slice']:7200; // 2 hours
+ $duration = isset($gconf['duration'])?$gconf['duration']:400*$slice; // 33.33 days
// vertical lines at month borders
$addSpecial .= ' VRULE:'.strtotime(date('Y-m-01')).'#FF0000';
$addSpecial .= ' VRULE:'.strtotime(date('Y-m-01').' -1 month').'#FF0000';
}
elseif ($timeframe == 'year') {
- $duration = isset($gconf['duration'])?$gconf['duration']:396*86400; // 365+31 days
$slice = isset($gconf['slice'])?$gconf['slice']:86400; // 1 day
+ $duration = isset($gconf['duration'])?$gconf['duration']:400*$slice; // 400 days
// vertical lines at month borders
$addSpecial .= ' VRULE:'.strtotime(date('Y-01-01 12:00:00')).'#FF0000';
$addSpecial .= ' VRULE:'.strtotime(date('Y-01-01 12:00:00').' -1 year').'#FF0000';
$slice = isset($gconf['slice'])?$gconf['slice']:$this->rrd_step; // whatever our step is
}
- if (isset($gconf['rows']) && count($gconf['rows'])) {
- foreach ($gconf['rows'] as $erow) {
- if (isset($erow['name']) && strlen($erow['name'])) {
- if (!isset($erow['scale']) && isset($gconf['scale'])) { $erow['scale'] = $gconf['scale']; }
- $grow = array();
- $grow['dType'] = isset($erow['dType'])?$erow['dType']:'DEF';
- $grow['name'] = $erow['name'].(isset($erow['scale'])?'_tmp':'');
- if ($grow['dType'] == 'DEF') {
- $grow['dsname'] = isset($erow['dsname'])?$erow['dsname']:$erow['name'];
- if (isset($erow['dsfile'])) { $grow['dsfile'] = $erow['dsfile']; }
- $grow['cf'] = isset($erow['cf'])?$erow['cf']:'AVERAGE';
- }
- else {
- $grow['rpn_expr'] = isset($erow['rpn_expr'])?$erow['rpn_expr']:'0';
- }
- if (isset($erow['scale'])) {
- $graphrows[] = $grow;
- $grow = array();
- $grow['dType'] = 'CDEF';
- $grow['name'] = $erow['name'];
- $grow['rpn_expr'] = $erow['name'].'_tmp,'.$erow['scale'].',*';
- }
- $grow['gType'] = isset($erow['gType'])?$erow['gType']:'LINE1';
- $grow['color'] = isset($erow['color'])?$erow['color']:$gColors[$gC++];
- $grow['color_bg'] = isset($erow['color_bg'])?$erow['color_bg']:'';
- if ($gC >= count($gColors)) { $gC = 0; }
- if (isset($erow['legend'])) {
- $grow['legend'] = $erow['legend'];
- if (!isset($gconf['show_legend'])) { $gconf['show_legend'] = true; }
+ $use_gcrows = (isset($gconf['rows']) && count($gconf['rows']));
+ if ($use_gcrows) { $grow_def =& $gconf['rows']; }
+ else { $grow_def =& $this->rrd_fields; }
+ foreach ($grow_def as $key=>$erow) {
+ if (isset($erow['name']) && strlen($erow['name'])) {
+ if (!isset($erow['scale']) && isset($gconf['scale'])) { $erow['scale'] = $gconf['scale']; }
+ if (!isset($erow['scale_time_src']) && isset($gconf['scale_time_src'])) { $erow['scale_time_src'] = $gconf['scale_time_src']; }
+ if (!isset($erow['scale_time_tgt']) && isset($gconf['scale_time_tgt'])) { $erow['scale_time_tgt'] = $gconf['scale_time_tgt']; }
+ foreach (array('scale_time_src','scale_time_tgt') as $st) {
+ if (!isset($erow[$st]) || !is_numeric($erow[$st])) {
+ switch (@$erow[$st]) {
+ case 'dyn':
+ case 'auto':
+ $erow[$st] = $slice;
+ break;
+ case 'day':
+ $erow[$st] = 24*3600;
+ break;
+ case '2hr':
+ case '2hours':
+ $erow[$st] = 7200;
+ break;
+ case 'hr':
+ case 'hour':
+ $erow[$st] = 3600;
+ break;
+ case '30min':
+ $erow[$st] = 1800;
+ break;
+ case '5min':
+ $erow[$st] = 300;
+ break;
+ case 'min':
+ $erow[$st] = 60;
+ break;
+ case 's':
+ case 'sec':
+ default:
+ $erow[$st] = 1;
+ break;
+ }
}
- if (isset($erow['stack'])) { $grow['stack'] = ($erow['stack'] == true); }
- if (isset($erow['desc'])) { $grow['desc'] = $erow['desc']; }
- if (isset($erow['legend_long'])) { $grow['legend_long'] = $erow['legend_long']; }
- $graphrows[] = $grow;
}
- }
- }
- else {
- foreach ($this->rrd_fields as $key=>$ds) {
+ $scale_time_factor = $erow['scale_time_tgt']/$erow['scale_time_src'];
+ if ($scale_time_factor != 1) { $erow['scale'] = (isset($erow['scale'])?$erow['scale']:1)*$scale_time_factor; }
$grow = array();
- $grow['dType'] = 'DEF';
- $grow['name'] = $ds['name'].(isset($gconf['scale'])?'_tmp':'');
- $grow['dsname'] = $ds['name'];
- $grow['cf'] = 'AVERAGE';
- if (isset($gconf['scale'])) {
+ $grow['dType'] = ($use_gcrows && isset($erow['dType']))?$erow['dType']:'DEF';
+ $grow['name'] = $erow['name'].(isset($erow['scale'])?'_tmp':'');
+ if ($grow['dType'] == 'DEF') {
+ $grow['dsname'] = ($use_gcrows && isset($erow['dsname']))?$erow['dsname']:$erow['name'];
+ if ($use_gcrows && isset($erow['dsfile'])) { $grow['dsfile'] = $erow['dsfile']; }
+ $grow['cf'] = ($use_gcrows && isset($erow['cf']))?$erow['cf']:'AVERAGE';
+ }
+ else {
+ $grow['rpn_expr'] = isset($erow['rpn_expr'])?$erow['rpn_expr']:'0';
+ }
+ if (isset($erow['scale'])) {
$graphrows[] = $grow;
$grow = array();
$grow['dType'] = 'CDEF';
- $grow['name'] = $ds['name'];
- $grow['rpn_expr'] = $ds['name'].'_tmp,'.$gconf['scale'].',*';
+ $grow['name'] = $erow['name'];
+ $grow['rpn_expr'] = $erow['name'].'_tmp,'.$erow['scale'].',*';
}
- $grow['gType'] = ((count($this->rrd_fields)==2) && ($key==0))?'AREA':'LINE1';
- $grow['color'] = $gColors[$gC++]; if ($gC >= count($gColors)) { $gC = 0; }
- if (isset($ds['legend'])) {
- $grow['legend'] = $ds['legend'];
+ if ($use_gcrows) { $grow['gType'] = isset($erow['gType'])?$erow['gType']:'LINE1'; }
+ else { $grow['gType'] = ((count($grow_def)==2) && ($key==0))?'AREA':'LINE1'; }
+ $grow['color'] = isset($erow['color'])?$erow['color']:$gColors[$gC++];
+ $grow['color_bg'] = isset($erow['color_bg'])?$erow['color_bg']:'';
+ if ($gC >= count($gColors)) { $gC = 0; }
+ if (isset($erow['legend'])) {
+ $grow['legend'] = $erow['legend'];
if (!isset($gconf['show_legend'])) { $gconf['show_legend'] = true; }
}
- if (isset($ds['desc'])) { $grow['desc'] = $ds['desc']; }
- if (isset($ds['legend_long'])) { $grow['legend_long'] = $ds['legend_long']; }
+ if (isset($erow['stack'])) { $grow['stack'] = ($erow['stack'] == true); }
+ if (isset($erow['desc'])) { $grow['desc'] = $erow['desc']; }
+ if (isset($erow['legend_long'])) { $grow['legend_long'] = $erow['legend_long']; }
$graphrows[] = $grow;
}
}
$legendlines = '';
foreach ($graphrows as $grow) {
$legendline = isset($grow['desc'])?$grow['desc']:(isset($grow['legend'])?$grow['legend']:$grow['name']);
- $legendline .= '|'.$grow['color'];
+ $legendline .= '|'.@$grow['color'];
$legendline .= '|'.(isset($grow['color_bg'])?$grow['color_bg']:'');
$legendline .= '|'.(isset($grow['legend_long'])?$grow['legend_long']:'');
$legendlines .= 'legend:'.$legendline."\n";
if (preg_match('/^file:(.+)$/', $gline, $regs)) {
$gmeta['filename'] = $regs[1];
}
- elseif (preg_match('/^legend:([^\|]+)\|([^|]+)\|([^\|]*)\|(.*)$/', $gline, $regs)) {
+ elseif (preg_match('/^legend:([^\|]+)\|([^|]*)\|([^\|]*)\|(.*)$/', $gline, $regs)) {
$gmeta['legend'][$regs[1]] = array('color'=>$regs[2], 'color_bg'=>$regs[3], 'desc_long'=>$regs[4]);
if (strlen($regs[4])) { $gmeta['legends_long'] = true; }
if (strlen($regs[3]) || strlen($regs[4])) { $gmeta['default_colorize'] = true; }
$idx = $col * $num_rows + $row;
$out .= '<td>';
if ($idx < count($stats)) {
- list($sname, $s_psub) = explode('|', $stats[$idx]['name'], 2);
+ @list($sname, $s_psub) = explode('|', $stats[$idx]['name'], 2);
$s_psname = 'page'.(isset($s_psub)?'.'.$s_psub:'');
- $g_sub = $this->config_all[$sname][$s_psname]['graph_sub'];
+ $g_sub = @$this->config_all[$sname][$s_psname]['graph_sub'];
if (isset($this->config_all[$sname][$s_psname]['title_page'])) {
$s_ptitle = $this->config_all[$sname][$s_psname]['title_page'];