URL: http://metabolomics.jp/ */ require_once( 'graph.inc' ); require_once( $jpgraph . '/jpgraph.php' ); if( !isset( $_GET['graph'] ) || !isset( $_GET['data'] ) ){ exit( "Not enough data. 'graph' and/or 'data' is necessary." ); } $kind = $_GET['graph']; $datas = split( ";", ereg_replace( ";$", "", $_GET['data'] ) ); $data_count = count ( $datas ); if( $data_count <= 4 ){ exit( "Not enough data. 'data' is invalid." ); } $index = 0; $margin = array( 40, 20, 40, 40 ); $size = ereg_replace( "^size=", "", $datas[$index] ); $index ++; if( strncmp( $datas[$index], "margin=", 7 ) == 0 ){ $margins = split( ",", substr( $datas[$index], 7 ) ); array_walk( $margins, 'trimValue' ); for( $i = 0; $i < count( $margins ); $i ++ ) $margin[$i] = ereg_replace( "[^0-9]", "", $margins[$i] ); for( ; $i < 4; $i ++ ){ if( $i == 1 ) $margin[$i] = 20; else $margin[$i] = 40; } for( $i = 0; $i < 4; $i ++){ if( $margin[$i] <= 0 ) $margin[$i] = 1; else if( $margin[$i] > 1000 ) $margin[$i] = 1000; } $index ++; } $title = ereg_replace( "^title=", "", $datas[$index] ); $index ++; $legend = split( "x", ereg_replace( "^legend=", "", $datas[$index] ) ); $index ++; $xlabels = ereg_replace( '\\\\n', "\n", ereg_replace( "^label=", "", $datas[$index] ) ); $index ++; $xlabel_array = split( ",", $xlabels ); array_walk( $xlabel_array, 'trimValue' ); $sep = ','; $data_count = $data_count - $index; for( $i = 0; $i < $data_count; $i ++ ){ $tmp = split( "=", $datas[$i+$index] ); $label[$i] = trim( $tmp[0] ); $data[$i] = ereg_replace( ",*$", "", $tmp[1] ); $data[$i] = ereg_replace( "[^-0-9\.,]*", "", $data[$i] ); } $exh = -1; $exv = -1; if( ( $legend[0] == '0' || ereg( "0.[0-9]+", $legend[0] ) ) ) $exh = $legend[0]; if( ( $legend[1] == '0' || ereg( "0.[0-9]+", $legend[1] ) ) ) $exv = $legend[1]; $size = split( 'x', $size ); if( count( $size ) != 2 ){ exit( "Not enough data. \'size\' contains width and height." ); } $size[0] = ereg_replace( "[^0-9]*", "", $size[0] ); $size[1] = ereg_replace( "[^0-9]*", "", $size[1] ); if( strcmp( $kind, $GRAPH_PIE ) == 0 || strcmp( $kind, $GRAPH_PIE3D ) == 0 ){ if( count( $data ) != count( $label ) ){ exit( "Disaccord with \'data\' number and \'label\' number." ); } require( $jpgraph . '/jpgraph_pie.php' ); $graph = new PieGraph( $size[0], $size[1] ); $graph->title->Set( $title ); if( $exh != -1 && $exv != -1 ) $graph->legend->SetPos( $exh, $exv, "left", "top" ); $pie = ''; if( strcmp( $kind, $GRAPH_PIE ) == 0 ){ $pie = new PiePlot( $data ); } else { require( $jpgraph . '/jpgraph_pie3d.php' ); $pie = new PiePlot3D( $data ); } $pie->SetLegends( $label ); $graph->Add( $pie ); $graph->Stroke(); } else if( strcmp( $kind, $GRAPH_LINE ) == 0 ){ require( $jpgraph . '/jpgraph_line.php' ); # if( strcmp( $sep, '' ) != 0 ) # $data_array = split( $sep, $data ); # else # $data_array[0] = $data; if( count( $data ) != count( $label ) ){ exit( "Disaccord with \'data\' number and \'label\' number." ); } $graph = new Graph( $size[0], $size[1] ); $graph->SetMargin( $margin[0], $margin[1], $margin[2], $margin[3] ); $graph->SetScale( "textlin" ); $graph->title->Set( $title ); if( $exh != -1 && $exv != -1 ) $graph->legend->SetPos( $exh, $exv, "left", "top" ); for( $i = 0; $i < count( $label ); $i ++ ){ $lineplot[$i] = new LinePlot( split( ',', $data[$i] ) ); $lineplot[$i]->SetLegend( $label[$i] ); $lineplot[$i]->SetColor( $colors[$i % count( $colors )] ); $graph->Add( $lineplot[$i] ); } $graph->xaxis->SetTickLabels( $xlabel_array ); $graph->Stroke(); } else if( strcmp( $kind, $GRAPH_HBAR ) == 0 || strcmp( $kind, $GRAPH_VBAR ) == 0 || strcmp( $kind, $GRAPH_HGBAR ) == 0 || strcmp( $kind, $GRAPH_VGBAR ) == 0 ){ require( $jpgraph . '/jpgraph_bar.php' ); # if( strcmp( $sep, '' ) != 0 ) # $data_array = split( $sep, $data ); # else # $data_array[0] = $data; if( count( $data ) != count( $label ) ){ exit( "Disaccord with \'data\' number and \'label\' number." ); } $graph = new Graph( $size[0], $size[1] ); $graph->SetScale( "textlin" ); $graph->title->Set( $title ); if( $exh != -1 && $exv != -1 ) $graph->legend->SetPos( $exh, $exv, "left", "top" ); # horizontal bar, rotate 90 if( strcmp( $kind, $GRAPH_HBAR ) == 0 || strcmp( $kind, $GRAPH_HGBAR ) == 0 ){ # $graph->Set90AndMargin( 50, 50, 50, 50 ); /* $tmp = $margin[2]; $margin[2] = $margin[0]; $margin[0] = $margin[3]; $margin[3] = $margin[1]; $margin[1] = $tmp;*/ $graph->Set90AndMargin( $margin[0], $margin[1], $margin[2], $margin[3] ); /* $tmp = $margin[1]; $margin[1] = $margin[3]; $margin[3] = $tmp; $tmp = $margin[0]; $margin[0] = $margin[2]; $margin[2] = $tmp; */ } else $graph->SetMargin( $margin[0], $margin[1], $margin[2], $margin[3] ); $plot_array = ""; for( $i = 0; $i < count( $label ); $i ++ ){ $barplot[$i] = new BarPlot( split( ',', $data[$i] ) ); $barplot[$i]->SetLegend( $label[$i] ); $barplot[$i]->SetFillColor( $colors[$i % count( $colors )] ); $plot_array[$i] = $barplot[$i]; # $graph->Add( $barplot[$i] ); } if( strcmp( $kind, $GRAPH_VBAR ) == 0 || strcmp( $kind, $GRAPH_HBAR ) == 0 ) $plots = new AccBarPlot( $plot_array ); else $plots = new GroupBarPlot( $plot_array ); $graph->Add( $plots ); $graph->xaxis->SetTickLabels( $xlabel_array ); $graph->Stroke(); } ?>