<?php # $Id$ # Testing phplot - Default TT font (3b): Set font with file basename only require_once 'phplot.php'; require_once 'config.php'; // TTF setup $data = array(array('A', 3, 6), array('B', 2, 4), array('C', 1, 2)); $p = new PHPlot(800, 800); $p->SetDataType('text-data'); $p->SetDataValues($data); $p->SetPlotType('bars'); $p->SetTitle("SetFontTTF() with file basename only"); $p->SetXTitle('X Axis Title'); $p->SetYTitle('Y Axis Title'); $p->SetFontTTF('title', $phplot_test_ttfonts['serifbold'], 18); $p->SetFontTTF('x_title', $phplot_test_ttfonts['serifitalic'], 14); $p->SetFontTTF('y_title', $phplot_test_ttfonts['serifbolditalic'], 10); $p->DrawGraph(); fwrite(STDERR, "OK defaultfont3b: title font=" . $p->fonts['title']['font'] . "\n");
function guifi_stats_chart07() { include drupal_get_path('module', 'guifi') . '/contrib/phplot/phplot.php'; $gDirTTFfonts = drupal_get_path('module', 'guifi') . '/contrib/fonts/'; if (isset($_GET['width'])) { $gwidth = $_GET['width']; } else { $gwidth = 500; } if (isset($_GET['height'])) { $gheight = $_GET['height']; } else { $gheight = 450; } $today = getdate(); $year = $today[year]; $month = $today[mon]; $month = $month - 12; $n = 0; $tot = 0; if ($month < 1) { $year = $year - 1; $month = 12 + $month; } $datemin = mktime(0, 0, 0, $month, 1, $year); if (isset($_GET['zone'])) { $zone_id = $_GET['zone']; if ($zone_id == "0") { $zone_id = "0"; } //"3671"; } else { $zone_id = "0"; } $avalue = array(); $adata = array(); for ($i = 0; $i < 10; $i++) { $adata[] = array(0, 0); } $vsql = "select sum(if(timestamp_created >= " . $datemin . ",1,0)) as num, count(*) as total, zone_id\n from {guifi_location}\n where status_flag='Working' "; if ($zone_id != "0") { $achilds = guifi_zone_childs($zone_id); $v = ""; foreach ($achilds as $key => $child) { if ($v == "") { $v .= "zone_id=" . $child; } else { $v .= " or zone_id=" . $child; } } $vsql .= "AND (" . $v . ") "; } $vsql .= "GROUP BY zone_id "; $result = db_query($vsql); while ($record = db_fetch_object($result)) { if ($record->total >= 20) { $vn = $record->num / $record->total * 100; $vmin = 0; for ($i = 1; $i < 10; $i++) { if ($adata[$vmin][1] > $adata[$i][1]) { $vmin = $i; } } if ($vn > $adata[$vmin][1]) { $adata[$vmin][0] = $record->zone_id; $adata[$vmin][1] = $vn; } } } for ($i = 0; $i < 10; $i++) { if ($adata[$i][1] != 0) { $avalue[$adata[$i][0]] = $adata[$i][1]; } } arsort($avalue); foreach ($avalue as $key => $value) { if ($value != 0) { $data[] = array(substr(guifi_get_zone_name($key), 0, 20) . " �", $value); } } $shapes = array('none'); $plot = new PHPlot($gwidth, $gheight); $plot->SetPlotAreaWorld(0, 0, NULL, NULL); $plot->SetFileFormat('png'); $plot->SetDataType("text-data"); $plot->SetDataValues($data); $plot->SetPlotType("bars"); $plot->SetXTickIncrement(1); $plot->SetSkipBottomTick(TRUE); $plot->SetSkipLeftTick(TRUE); $plot->SetTickLength(0); //$plot->SetXTickPos('none'); $plot->SetYDataLabelPos('plotin'); $plot->SetYLabelType('data', 0); $plot->SetTickColor('grey'); $plot->SetTTFPath($gDirTTFfonts); $plot->SetFontTTF('title', 'Vera.ttf', 12); $plot->SetFontTTF('x_label', 'Vera.ttf', 8); if (isset($_GET['title'])) { $plot->SetTitle("guifi.net \n" . t($_GET['title'])); } else { if ($zone_id == "0") { $plot->SetTitle("guifi.net \n" . t('Largest annual increase')); } else { $plot->SetTitle("guifi.net " . t('zone') . ": " . guifi_get_zone_name($zone_id) . "\n" . t('Largest annual increase')); } } //$plot->SetXTitle(t('Zones')); $plot->SetYTitle(t('% increase')); $plot->SetXDataLabelPos('plotdown'); //$plot->SetXLabelAngle(45); $plot->SetXDataLabelAngle(75); $plot->SetGridColor('red'); $plot->SetPlotBorderType('left'); $plot->SetDataColors(array('orange')); $plot->SetTextColor('DimGrey'); $plot->SetTitleColor('DimGrey'); $plot->SetLightGridColor('grey'); $plot->SetBackgroundColor('white'); $plot->SetTransparentColor('white'); $plot->SetIsInline(TRUE); $plot->DrawGraph(); }
} $message = 'DrawMessage() test: '; if (empty($text)) { $message .= 'All defaults'; } else { $message .= $text; } if (!empty($extra_chars)) { $message .= str_repeat(' Test', (int) ($extra_chars / 5)); } $p = new PHPlot(800, 600); if (!empty($use_gdfont)) { $p->SetFontGD('generic', 5); } elseif (!empty($use_ttfont)) { $p->SetTTFPath($phplot_test_ttfdir); $p->SetFontTTF('generic', $phplot_test_ttfonts['serifitalic'], 14); } if (!empty($set_bgcolor)) { $p->SetBackgroundColor('yellow'); } if (!empty($set_bgimage)) { $p->SetBgImage('images/bubbles.png', 'tile'); } if (!empty($set_border)) { $p->SetImageBorderWidth(3); $p->SetImageBorderColor('red'); $p->SetImageBorderType('raised'); } if (!empty($noprint)) { $p->SetPrintImage(False); }
<?php # $Id$ # PHPlot Example: Use DrawMessage() to display a message require_once 'phplot.php'; require_once 'config.php'; // Font info $plot = new PHPlot(600, 400); $plot->SetTTFPath($phplot_test_ttfdir); $plot->SetFontTTF('generic', $phplot_test_ttfonts['sansitalic'], 14); $plot->SetBackgroundColor('#ffcc99'); $plot->SetImageBorderWidth(8); $plot->SetImageBorderColor('blue'); $plot->SetImageBorderType('raised'); # # Here you would start to produce the plot, then detect something wrong ... # $message = "I'm sorry, Dave. I'm afraid I can't do that.\n" . "\n" . "You haven't supplied enough data to produce a plot. " . "Please try again at another time."; $plot->DrawMessage($message, array('draw_background' => TRUE, 'draw_border' => TRUE, 'reset_font' => FALSE, 'wrap_width' => 50, 'text_color' => 'navy'));
$p->SetPointShapes($shapes); $p->SetLineStyles('solid'); $p->SetDataColors(array('red', 'blue', 'green')); $p->SetLegend($legend); $p->SetDataType('data-data'); $p->SetDataValues($data); $p->SetPlotType($plottype); $p->SetPlotAreaWorld(0, 0, 5, 10); $p->SetXDataLabelPos('none'); $p->SetXTickIncrement(1.0); $p->SetYTickIncrement(1.0); # Option: Use legend shape markers? $p->SetLegendUseShapes($useshapes); # Option: Use TT Font, set size and optional line spacing scale: if (!empty($fontsize)) { $p->SetFontTTF('legend', $font, $fontsize, $linespacing); } # Option: Varying point shape sizes: if ($setpointsizes) { $p->SetPointSizes(array(2, 4, 8, 10, 16)); } # Turn on backgrounds for visibility. $p->SetBackgroundColor('SkyBlue'); $p->SetDrawPlotAreaBackground(True); $p->SetPlotBgColor('plum'); # Option: Change alignment of lines/color boxes in legend? if (isset($textalign)) { $p->SetLegendStyle($textalign, $colorboxalign); } # Opton: Scale factor for color box width? if (isset($colorboxwidth)) {
function solicitudes_reparacion_por_operario($id_operario, $año) { $this->loadModel('ReparacionSolicitud'); $this->loadModel('Funcionario'); $meses = $this->ReparacionSolicitud->query("SELECT MONTH(archivada) AS mes FROM reparacion_solicitudes WHERE estado='a' AND ejecutada=1 AND YEAR(archivada)=" . $año . " GROUP BY MONTH(archivada)"); if (!empty($meses)) { // Inicializamos el arreglo en ceros (para los meses ke no tienen solicitudes). $total = array(); for ($i = 1; $i <= 12; $i++) { $total[$i][0][0] = array('cuenta' => 0); } foreach ($meses as $mes) { $cant_solicitudes = $this->ReparacionSolicitud->query("SELECT COUNT(*) AS cuenta FROM reparacion_solicitudes WHERE id_funcionario=" . $id_operario . " AND estado='a' AND ejecutada=1 AND YEAR(archivada)=" . $año . " AND MONTH(archivada)=" . $mes[0]['mes']); $total[$mes[0]['mes']] = $cant_solicitudes; } if (!empty($total)) { $operario = $this->Funcionario->find('first', array('conditions' => array('Funcionario.id' => $id_operario), 'fields' => array('Funcionario.nombre'))); foreach ($total as $mes => $arreglo_mes) { $arreglo_plot[] = array($this->meses[$mes], $arreglo_mes[0][0]['cuenta']); } $plot = new PHPlot(890, 450); $plot->SetDataValues($arreglo_plot); $plot->SetDataType('text-data'); // Fuentes $plot->SetUseTTF(true); $plot->SetFontTTF('legend', 'FreeSans.ttf', 9); $plot->SetFontTTF('title', 'FreeSans.ttf', 14); $plot->SetFontTTF('y_label', 'FreeSans.ttf', 10); $plot->SetFontTTF('x_label', 'FreeSans.ttf', 10); $plot->SetFontTTF('y_title', 'FreeSans.ttf', 14); // Titulos $plot->SetTitle("\nSolicitudes de reparación\natendidas por " . mb_convert_case($operario['Funcionario']['nombre'], MB_CASE_TITLE, "UTF-8")); $plot->SetXTitle('AÑO ' . $año); $plot->SetYTitle('# SOLICITUDES'); // Etiquetas $plot->SetXTickLabelPos('none'); $plot->SetXTickPos('none'); $plot->SetYTickLabelPos('none'); $plot->SetYTickPos('none'); $plot->SetYDataLabelPos('plotin'); $plot->SetDrawXGrid(true); // Leyenda $leyenda = array('Solicitudes de Reparación'); $plot->SetLegend($leyenda); $plot->SetLegendPixels(703, 0); $plot->SetPlotType('bars'); $plot->SetShading(7); $plot->DrawGraph(); } } }
<?php # PHPlot Example: Use DrawMessage() to display a message require_once 'phplot.php'; $plot = new PHPlot(600, 400); # Note: This font name is system dependent: $plot->SetFontTTF('generic', 'LiberationSans-Italic.ttf', 14); $plot->SetBackgroundColor('#ffcc99'); $plot->SetImageBorderWidth(8); $plot->SetImageBorderColor('blue'); $plot->SetImageBorderType('raised'); # # Here you would start to produce the plot, then detect something wrong ... # $message = "I'm sorry, Dave. I'm afraid I can't do that.\n" . "\n" . "You haven't supplied enough data to produce a plot. " . "Please try again at another time."; $plot->DrawMessage($message, array('draw_background' => TRUE, 'draw_border' => TRUE, 'reset_font' => FALSE, 'wrap_width' => 50, 'text_color' => 'navy'));
$data = $data1; } elseif ($tp['datasign'] < 0) { $data = $data2; } else { $data = array_merge($data1, $data2); } $p = new PHPlot(800, 800); $p->SetTitle($tp['title'] . $tp['suffix']); $p->SetXTitle('This is the X Axis Title'); $p->SetYTitle('This is the Y Axis Title'); $p->SetDataValues($data); $p->SetDataType('text-data-yx'); $p->SetPlotType('bars'); $p->SetXDataLabelPos('plotin'); if (isset($tp['shade'])) { $p->SetShading($tp['shade']); } if ($tp['ttf']) { $p->SetFontTTF('x_label', $phplot_test_ttfdir . $phplot_test_ttfonts['sans'], 10); } if ($tp['yaxis0']) { $p->SetYAxisPosition(0); } if (isset($tp['labelangle'])) { $p->SetXDataLabelAngle($tp['labelangle']); } if ($tp['labelformat']) { $p->SetXDataLabelType('data', 1, '', '%'); } $p->SetYTickPos('none'); $p->DrawGraph();
} $title = trim($t); # Determine image aspect: 800x800 square, 800x400 landscape, or 400x800 portrait $width = $image_aspect == 'S' || $image_aspect == 'L' ? 800 : 400; $height = $image_aspect == 'S' || $image_aspect == 'P' ? 800 : 400; $plot = new PHPlot($width, $height); $plot->SetPlotType('pie'); $plot->SetDataType($data_type); $plot->SetDataValues($data); if (!empty($plot_margins)) { call_user_func_array(array($plot, 'SetMarginsPixels'), $plot_margins); } # Font setup if (!empty($ttfonts)) { if (isset($font_size)) { $plot->SetFontTTF('generic', $phplot_test_ttfonts['sans'], $font_size); } else { $plot->SetFontTTF('generic', $phplot_test_ttfonts['sans']); } } elseif (isset($font_size)) { $plot->SetFontGD('generic', $font_size); } $plot->SetTitle($title); if (!empty($plot_border)) { $plot->SetPlotBorderType($plot_border); } if (isset($pie_diam_factor)) { $plot->pie_diam_factor = $pie_diam_factor; } if (isset($shading)) { $plot->SetShading($shading);
<?php # $Id$ # Testing phplot - Default TT font (1b): No default path or font, SetFontTTF require_once 'phplot.php'; $data = array(array('A', 3, 6), array('B', 2, 4), array('C', 1, 2)); $p = new PHPlot(800, 800); $p->SetDataType('text-data'); $p->SetDataValues($data); $p->SetPlotType('bars'); $p->SetTitle("TTF default not set, SetFontTTF() with no fontname\nTitles in 3 sizes"); $p->SetXTitle('X Axis Title'); $p->SetYTitle('Y Axis Title'); $p->SetFontTTF('title', '', 18); $p->SetFontTTF('x_title', '', 14); $p->SetFontTTF('y_title', '', 10); $p->DrawGraph(); fwrite(STDERR, "OK defaultfont1b: title font=" . $p->fonts['title']['font'] . "\n");
$p = new PHPlot(800, 600); $p->SetTitle($title . $suffix); $p->SetDataType('data-data'); $p->SetDataValues($data); $p->SetImageBorderType('solid'); $p->SetYDataLabelPos('plotin'); if (isset($yd_angle)) { $p->SetYDataLabelAngle($yd_angle); } if (isset($y_type)) { $p->SetYLabelType($y_type, $y_type_arg); } if (isset($yd_type)) { $p->SetYDataLabelType($yd_type, $yd_type_arg); } if (isset($y_label_font)) { if (isset($y_label_font_ttfsize)) { $p->SetFontTTF('y_label', $y_label_font, $y_label_font_ttfsize); } else { $p->SetFontGD('y_label', $y_label_font); } } $p->SetXLabelType('data', 3); $p->SetPlotType($plot_type); if (isset($dvl_angle)) { $p->data_value_label_angle = $dvl_angle; } if (isset($dvl_dist)) { $p->data_value_label_distance = $dvl_dist; } $p->DrawGraph();
} # Make a data array with equal-size slices: $data = array_fill(0, $pie_slices, array('', 1)); $plot = new PHPlot(800, 600); $plot->SetDataValues($data); $plot->SetDataType('text-data-single'); $plot->SetPlotType('pie'); $plot->SetShading(0); $plot->SetImageBorderType('plain'); $plot->SetPrintImage(False); $plot->SetTitle("Pie Chart - Vary Start Angle and Direction\n" . "(CW = Clockwise, CCW = Counter-clockwise)"); # Configure pie labels: Show sector index, inside the pie, in a large font. $plot->SetPieLabelType('index'); $plot->SetLabelScalePosition(0.25); # Use the default TrueType font at 36 points. $plot->SetFontTTF('generic', '', 36); # This font is used by the callback to label each plot: # Use the default TrueType font at 16 points. $plot->SetFontTTF('x_title', '', 16); // Use the default TTF font at 16 pts # Draw the plot tiles: draw_plot($plot, $base_angle + 0, 'CCW', 0, 50); draw_plot($plot, $base_angle + 90, 'CCW', 200, 50); draw_plot($plot, $base_angle + 180, 'CCW', 400, 50); draw_plot($plot, $base_angle + 270, 'CCW', 600, 50); draw_plot($plot, $base_angle + 0, 'CW', 0, 300); draw_plot($plot, $base_angle + 90, 'CW', 200, 300); draw_plot($plot, $base_angle + 180, 'CW', 400, 300); draw_plot($plot, $base_angle + 270, 'CW', 600, 300); # Done: $plot->PrintImage();
function costo_externo_interno_año($id_oficina, $año) { $this->autoLayout = false; $this->autoRender = false; $this->loadModel('CentroCosto'); $sql_oficina = ''; if ($id_oficina != 0) { $sql_oficina = " AND Cencos_id='" . $id_oficina . "' "; $cenco = $this->CentroCosto->find('first', array('fields' => array('CentroCosto.Cencos_nombre'), 'conditions' => array('CentroCosto.Cencos_id' => $id_oficina))); $subtitulo_oficina = 'la dependencia ' . mb_convert_case($cenco['CentroCosto']['Cencos_nombre'], MB_CASE_TITLE, "UTF-8"); } else { $subtitulo_oficina = 'todas las dependencias'; } $meses = $this->Solicitud->query("SELECT MONTH(solucionada) AS mes FROM solicitudes WHERE estado='s' " . $sql_oficina . " AND YEAR(solucionada)=" . $año . " GROUP BY MONTH(solucionada)"); if (!empty($meses)) { // Inicializamos el arreglo en ceros (para los meses ke no tienen solicitudes). $totales = array(); for ($i = 1; $i <= 12; $i++) { $totales[$i][0][0] = array('costo_i' => 0, 'costo_e' => 0); } foreach ($meses as $mes) { $costos_e_i = $this->Solicitud->query("SELECT SUM(costo_externo) AS costo_e, SUM(costo_interno) AS costo_i FROM solicitudes WHERE estado='s' AND YEAR(solucionada)=" . $año . " AND MONTH(solucionada)=" . $mes[0]['mes']); $totales[$mes[0]['mes']] = $costos_e_i; } if (!empty($totales)) { $total_costo_interno = $total_costo_externo = 0; $i = 0; $arreglo_plot = array(); foreach ($totales as $mes => $arreglo_mes) { // se construye el array para el PHPlot. if (count($arreglo_mes) > 0) { $arreglo_plot[$i] = array($this->meses[$mes], $arreglo_mes[0][0]['costo_i'], $arreglo_mes[0][0]['costo_e']); $total_costo_interno += $arreglo_mes[0][0]['costo_i']; $total_costo_externo += $arreglo_mes[0][0]['costo_e']; } else { $arreglo_plot[$i] = array($this->meses[$mes], 0, 0); } $i++; } $plot = new PHPlot(1790, 500); $plot->SetDataValues($arreglo_plot); $plot->SetDataType('text-data'); // Fuentes $plot->SetUseTTF(true); $plot->SetFontTTF('legend', 'FreeSans.ttf', 9); $plot->SetFontTTF('title', 'FreeSans.ttf', 14); $plot->SetFontTTF('y_label', 'FreeSans.ttf', 9); $plot->SetFontTTF('x_label', 'FreeSans.ttf', 10); $plot->SetFontTTF('y_title', 'FreeSans.ttf', 14); $plot->SetFontTTF('x_title', 'FreeSans.ttf', 12); // Titulos $plot->SetTitle("\nTotal de costos internos/externos\n" . "de " . $subtitulo_oficina . " en el año " . $año . "\n TOTAL Costo Interno = \$" . $total_costo_interno . "\n" . "TOTAL Costo Externo = \$" . $total_costo_externo); $plot->SetYTitle('$ COSTO'); // Etiquetas $plot->SetXTickLabelPos('none'); $plot->SetXTickPos('none'); $plot->SetYTickLabelPos('none'); $plot->SetYTickPos('none'); $plot->SetYDataLabelPos('plotin'); $plot->SetDrawXGrid(true); // Leyenda $leyenda = array('Costo Interno', 'Costo Externo'); $plot->SetLegend($leyenda); $plot->SetLegendPixels(27, 0); $plot->SetDataColors(array('beige', 'YellowGreen')); $plot->SetPlotType('bars'); $plot->SetShading(5); $plot->DrawGraph(); } } }
// Import test parameters $data = array(array('', 0, 0, 0, 0), array('', 1, 1, 2, 3), array('', 2, 2, 4, 6), array('', 3, 3, 6, 9)); $legend = array('Plot Line 1', 'Longer label for Plot Line 2', 'line 3'); $p = new PHPlot(800, 600); if (!empty($title)) { // $title can be set empty for special case if (!empty($suffix)) { $title .= "\n" . $suffix; } $p->SetTitle($title); } // Use smaller window, offset, so legend position is more apparent. $p->SetPlotAreaPixels(100, 80, 700, 480); $p->SetLegend($legend); $p->SetDataType('data-data'); $p->SetDataValues($data); $p->SetPlotType('lines'); $p->SetXDataLabelPos('none'); $p->SetXTickIncrement(1.0); $p->SetYTickIncrement(1.0); $p->SetDrawXGrid(True); if (isset($ttfontsize)) { $p->SetFontTTF('legend', $font, $ttfontsize, $ttlinespace); } if (isset($relto)) { $p->SetLegendPosition($lx, $ly, $relto, $bx, $by, $ox, $oy); } if (isset($callback)) { call_user_func($callback, $p); } $p->DrawGraph();
<?php # $Id$ # Testing phplot - Default TT font (2b): Local path and named font. # This test requires a specific font (see TEST_FONT) be present in the images/ # directory. The listed font is redistributable under the Open Fonts License. require_once 'phplot.php'; define('TEST_FONT', 'FreeUniversal-Regular.ttf'); $data = array(array('A', 3, 6), array('B', 2, 4), array('C', 1, 2)); $p = new PHPlot(800, 800); $p->SetDataType('text-data'); $p->SetDataValues($data); $p->SetPlotType('bars'); $p->SetTitle('Local TTF path and SetFontTTF with file basename only'); $p->SetXTitle('X Axis Title'); $p->SetYTitle('Y Axis Title'); $p->SetTTFPath(getcwd() . DIRECTORY_SEPARATOR . 'images'); $p->SetFontTTF('title', TEST_FONT, 18); $p->SetFontTTF('x_title', TEST_FONT, 14); $p->SetFontTTF('y_title', TEST_FONT, 10); $p->DrawGraph(); fwrite(STDERR, "OK defaultfont2b: title font=" . $p->fonts['title']['font'] . "\n");
$n_plots = 4; $height_of_each_plot = 100; $title_space = 50; $space_below_plots = 60; if ($title_sequence >= $n_plots) { $title_sequence = $n_plots - 1; } // Set title before last plot. # Fake some data: for ($i = 0; $i < $n_plots; $i++) { $report[$i] = array(array('Alpha', $i), array('Beta', 1.5 * $i), array('Gamma', 2 * $i)); } $max_x = 2 * ($n_plots - 1) + 1; $image_height = $n_plots * ($height_of_each_plot + $space_below_plots) + $title_space; $plot = new PHPlot(800, $image_height); $plot->SetFontTTF('title', $font, 14); $plot->SetFontTTF('x_title', $font, 14); $plot->SetFontTTF('y_title', $font, 10); # Disable auto-output: $plot->SetPrintImage(0); $title = "Test {$n_plots} Plots with TTF Title (sequence {$title_sequence})"; $y1 = $title_space; // Top of plot area for ($i = 0; $i < $n_plots; $i++) { if ($i == $title_sequence) { $plot->SetTitle($title); } $y2 = $y1 + $height_of_each_plot; // Bottom of plot area # fwrite(STDERR, "Plot $i area: min=(80, $y1) : max=(740, $y2)\n"); $plot->SetPlotAreaPixels(80, $y1, 740, $y2);
<?php # $Id$ # Dual text types: GD and TTF, default GD, with TTF Title and Y Title # This requires PHPlot > 5.0.5 require_once 'phplot.php'; # TTF Font info is in this configuration file: require 'config.php'; $data = array(array('', 0, 0, 0), array('', 10, 5, 10)); $p = new PHPlot(800, 600); $p->SetTitle("Dual Text Types:\nDefault GD, TTF title and Y title"); $p->SetDataType('data-data'); $p->SetDataValues($data); $p->SetXTitle('Title of X Data, GD Font 5'); $p->SetYTitle('Title of Y Data, TTF Italic Bold'); $p->SetTTFPath($phplot_test_ttfdir); # Must not call SetDefaultTTFont or it makes the default TTF. $p->SetFontTTF('title', $phplot_test_ttfonts['serif'], 24); $p->SetFont('x_title', 5); $p->SetFontTTF('y_title', $phplot_test_ttfonts['serifbolditalic'], 14); $p->SetXDataLabelPos('none'); $p->SetLegend(array("Legend Line 1", "Legend Line 2")); $p->SetXTickIncrement(1.0); $p->SetYTickIncrement(1.0); # Draw both grids: $p->SetDrawXGrid(True); $p->SetDrawYGrid(True); $p->SetPlotType('lines'); $p->DrawGraph();
# Skip the test with older PHPlot versions that do not support the # DrawText() font argment variations. if (!defined('PHPlot::version_id') || PHPlot::version_id < 60000) { echo "Skipping test: missing new DrawText() font argument support\n"; exit(2); } function my_draw($img, $plot) { $black = imagecolorresolve($img, 0, 0, 0); $x = 100; $y = 50; $dy = 30; $plot->DrawText('', 0, $x, $y += $dy, $black, 'Font="" (generic): sans italic 12pt'); $plot->DrawText('generic', 0, $x, $y += $dy, $black, 'Font="generic": sans italic 12pt'); $plot->DrawText('legend', 0, $x, $y += $dy, $black, 'Font="legend": serif bold 14pt'); $plot->DrawText($plot->fonts['title'], 0, $x, $y += $dy, $black, 'Font=fonts["title"]: sans 12pt'); $plot->DrawText('x_title', 0, $x, $y += $dy, $black, 'Font="x_title": mono bold 10pt'); } $data = array(array('', 0, 0), array('', 10, 10)); $plot = new PHPlot(800, 600); $plot->SetTitle("DrawText() Font Argument Test\nTitle is sans 12pt"); $plot->SetDataType('data-data'); $plot->SetDataValues($data); $plot->SetPlotType('lines'); $plot->SetTTFPath($phplot_test_ttfdir); $plot->SetFontTTF('title', $phplot_test_ttfonts['sans'], 12); $plot->SetFontTTF('generic', $phplot_test_ttfonts['sansitalic'], 12); $plot->SetFontTTF('legend', $phplot_test_ttfonts['serifbold'], 14); $plot->SetFontTTF('x_title', $phplot_test_ttfonts['monobold'], 10); $plot->SetCallback('draw_all', 'my_draw', $plot); $plot->DrawGraph();