require_api('compress_api.php'); require_api('config_api.php'); require_api('graphviz_api.php'); require_api('workflow_api.php'); auth_ensure_user_authenticated(); if (!config_get('relationship_graph_enable')) { access_denied(); } compress_enable(); $t_status_arr = MantisEnum::getAssocArrayIndexedByValues(config_get('status_enum_string')); $t_graph_fontname = config_get('relationship_graph_fontname'); $t_graph_fontsize = config_get('relationship_graph_fontsize'); $t_graph_fontpath = get_font_path(); $t_dot_tool = config_get('dot_tool'); $t_graph_attributes = array(); if (!empty($t_graph_fontpath)) { $t_graph_attributes['fontpath'] = $t_graph_fontpath; } $t_graph = new Graph('workflow', $t_graph_attributes, $t_dot_tool); $t_graph->set_default_node_attr(array('fontname' => $t_graph_fontname, 'fontsize' => $t_graph_fontsize, 'shape' => 'record', 'style' => 'filled', 'height' => '0.2', 'width' => '0.4')); $t_graph->set_default_edge_attr(array('style' => 'solid', 'color' => '#0000C0', 'dir' => 'forward')); foreach ($t_status_arr as $t_from_status => $t_from_label) { $t_enum_status = MantisEnum::getAssocArrayIndexedByValues(config_get('status_enum_string')); foreach ($t_enum_status as $t_to_status_id => $t_to_status_label) { if (workflow_transition_edge_exists($t_from_status, $t_to_status_id)) { $t_graph->add_edge(string_no_break(MantisEnum::getLabel(lang_get('status_enum_string'), $t_from_status)), string_no_break(MantisEnum::getLabel(lang_get('status_enum_string'), $t_to_status_id)), array()); } } } $t_graph->output('png', true);
/** * Outputs an image map in XHTML format using the <map> element for the given * relationship graph. * @param Graph $p_graph Relationship graph object generated from relgraph_generate_graph_for_bug() * @param string $p_name The XHTML name attribute to apply to the containing <map> element * @return null */ function relgraph_output_map($p_graph, $p_name) { echo '<map name="' . $p_name . '">' . "\n"; $p_graph->output('cmapx'); echo '</map>' . "\n"; }
function create_graph($type, $range = null) { global $db; // Do we have date range criteria? if ($range['end'] || $range['start']) { $start = (int) $range['start']; $end = (int) $range['end']; } else { $start = TIME_NOW - 60 * 60 * 24 * 30; $end = TIME_NOW; } $allowed_types = array('users', 'threads', 'posts'); if (!in_array($type, $allowed_types)) { die; } require_once MYBB_ROOT . 'inc/class_graph.php'; $points = $stats = $datelines = array(); if ($start == 0) { $query = $db->simple_select("stats", "dateline,num{$type}", "dateline <= '" . (int) $end . "'", array('order_by' => 'dateline', 'order_dir' => 'desc', 'limit' => 2)); while ($stat = $db->fetch_array($query)) { $stats[] = $stat['num' . $type]; $datelines[] = $stat['dateline']; $x_labels[] = date("m/j", $stat['dateline']); } $points[$datelines[0]] = 0; $points[$datelines[1]] = $stats[0] - $stats[1]; ksort($points, SORT_NUMERIC); } elseif ($end == 0) { $query = $db->simple_select("stats", "dateline,num{$type}", "dateline >= '" . (int) $start . "'", array('order_by' => 'dateline', 'order_dir' => 'asc', 'limit' => 2)); while ($stat = $db->fetch_array($query)) { $stats[] = $stat['num' . $type]; $datelines[] = $stat['dateline']; $x_labels[] = date("m/j", $stat['dateline']); } $points[$datelines[0]] = 0; $points[$datelines[1]] = $stats[1] - $stats[0]; ksort($points, SORT_NUMERIC); } else { $query = $db->simple_select("stats", "dateline,num{$type}", "dateline >= '" . (int) $start . "' AND dateline <= '" . (int) $end . "'", array('order_by' => 'dateline', 'order_dir' => 'asc')); while ($stat = $db->fetch_array($query)) { $points[$stat['dateline']] = $stat['num' . $type]; $datelines[] = $stat['dateline']; $x_labels[] = date("m/j", $stat['dateline']); } } sort($datelines, SORT_NUMERIC); // Find our year(s) label $start_year = date('Y', $datelines[0]); $last_year = date('Y', $datelines[count($datelines) - 1]); if ($last_year - $start_year == 0) { $bottom_label = $start_year; } else { $bottom_label = $start_year . " - " . $last_year; } // Create the graph outline $graph = new Graph(); $graph->add_points(array_values($points)); $graph->add_x_labels($x_labels); $graph->set_bottom_label($bottom_label); $graph->render(); $graph->output(); }
$graph->output($png); $graph->terminal = "epslatex linewidth 3"; $graph->output($eps); // echo $graph; } $generators = array('simple' => 'Populate/Clear (high)'); $algorithms = array($lrpair, $pairs, $preev); foreach ($generators as $generator => $generatorName) { $png = "graphs/{$generator}_high.png"; $eps = "graphs/{$generator}_high.eps"; if (file_exists($png) && file_exists($eps)) { if (filemtime($file) < filemtime($png) && filemtime(__FILE__) < filemtime($png)) { continue; } } $graph = new Graph(); $graph->xrange = '[0:2000000]'; $graph->title = "\"{$generatorName} benchmark\""; foreach ($algorithms as $algo) { $plot = new Plot(); $plot->datafile = "< grep \"{$algo->selector}_{$generator}\" {$file}"; $plot->datamodifiers = "using 2:5"; $plot->style = "{$stdline} '{$algo->color}'"; $plot->title = $algo->name; $graph->addPlot($plot); } $graph->output($png); $graph->terminal = "epslatex linewidth 3"; $graph->output($eps); // echo $graph; }