<commit_before><?php
/**
 * $Id$
 *
 * Renders a Yahoo UI chart (flash object)
 *
 * @author <NAME>, 2010 <<EMAIL>>
 */

//STATUS: WIP

class yui_chart
{
	private $data_source = '';

	function setDataSource($arr) { $this->data_source = $arr; }

	private $x_field_name, $x_field_title;

	function setXField($name, $title) { $this->x_field_name = $name; $this->x_field_title = $title; }

	private $t_title; ///< display title for Y dimension
	function setYTitle($title) { $this->y_title = $title; }

	private $y_fields = array();
	function addYField($name, $title) { $this->y_fields[] = array('name'=>$name, 'title'=>$title); }

	function render()
	{
		echo '<script type="text/javascript" src="http://yui.yahooapis.com/combo?2.8.0r4/build/yahoo/yahoo-min.js&2.8.0r4/build/dom/dom-min.js&2.8.0r4/build/event/event-min.js&2.8.0r4/build/element/element-min.js&2.8.0r4/build/json/json-min.js&2.8.0r4/build/datasource/datasource-min.js&2.8.0r4/build/swf/swf-min.js&2.8.0r4/build/charts/charts-min.js"></script>';

		echo
		'<style type="text/css">'.
		'#chart { width: 500px; height: 350px; }'.
		'</style>';

		echo
		'<div id="chart">'.
		'Unable to load Flash content. The YUI Charts Control requires Flash Player 9.0.45 or higher. '.
		'You can download the latest version of Flash Player from the <a href="http://www.adobe.com/go/getflashplayer">Adobe Flash Player Download Center</a>.'.
		'</div>';

		echo
		'<script type="text/javascript">'.
		'YAHOO.widget.Chart.SWFURL = "http://yui.yahooapis.com/2.8.0r4/build/charts/assets/charts.swf";';

		//--- data
		echo 'YAHOO.example.DataSource = '.jsArray2D($this->data_source).';'."\n";
		echo 'var myDataSource = new YAHOO.util.DataSource( YAHOO.example.DataSource);'."\n";

		echo 'myDataSource.responseType = YAHOO.util.DataSource.TYPE_JSARRAY;'."\n";
		echo 'myDataSource.responseSchema = { fields: [ ';

		echo '"'.$this->x_field_name.'",';
		for ($i=0; $i < count($this->y_fields); $i++)
			echo '"'.$this->y_fields[$i]['name'].'",';

		echo '] };'."\n";

		//--- chart
		echo 'var seriesDef = [';
		echo '{ displayName: "'.$this->x_field_title.'", yField: "'.$this->x_field_name.'" }, ';

		for ($i=0; $i < count($this->y_fields); $i++)
			echo '{ displayName: "'.$this->y_fields[$i]['title'].'", yField: "'.$this->y_fields[$i]['name'].'" }, ';

		echo ' ];';

		echo
		'YAHOO.example.getDataTipText = function( item, index, series )
		{
			var toolTipText = series.displayName + " at " + item.'.$this->x_field_name.';
			toolTipText += "\n" + item[series.yField];
			return toolTipText;
		}'."\n";

		//Style object for chart
		echo
		'var styleDef ='.
		'{'.
			'xAxis: { labelRotation:-90 },'.
			'yAxis: { titleRotation:-90 }'.
		'}'."\n";

		echo
		'var yAxisWidget = new YAHOO.widget.NumericAxis();'.
		'yAxisWidget.minimum = 0;'.
		'yAxisWidget.title = "'.$this->y_title.'";';

		echo
		'var xAxisWidget = new YAHOO.widget.CategoryAxis();'.
		'xAxisWidget.minimum = 0;'.
		'xAxisWidget.title = "'.$this->x_field_title.'";';

		echo 'var mychart = new YAHOO.widget.LineChart( "chart", myDataSource, {';
		echo 'series: seriesDef,';
		echo 'xField: "'.$this->x_field_name.'",';
		echo 'yAxis: yAxisWidget,';
		echo 'xAxis: xAxisWidget,';
		echo 'style: styleDef,';
		echo 'dataTipFunction: YAHOO.example.getDataTipText,';
		//only needed for flash player express install
		echo 'expressInstall: "assets/expressinstall.swf"';
		echo '});'."\n";

		echo '</script>';
	}<commit_msg>yui_chart: made render() return text instead of echo:ing it<commit_after><?php
/**
 * $Id$
 *
 * Renders a Yahoo UI chart (flash object)
 *
 * @author <NAME>, 2010 <<EMAIL>>
 */

//STATUS: WIP

//TODO: include external yui files in a smarter way
//TODO: use jsArray-functions more

class yui_chart
{
	private $data_source = '';

	function setDataSource($arr) { $this->data_source = $arr; }

	private $x_field_name, $x_field_title;

	function setXField($name, $title) { $this->x_field_name = $name; $this->x_field_title = $title; }

	private $t_title; ///< display title for Y dimension
	function setYTitle($title) { $this->y_title = $title; }

	private $y_fields = array();
	function addYField($name, $title) { $this->y_fields[] = array('name'=>$name, 'title'=>$title); }

	function render()
	{
		$res = '<script type="text/javascript" src="http://yui.yahooapis.com/combo?2.8.0r4/build/yahoo/yahoo-min.js&2.8.0r4/build/dom/dom-min.js&2.8.0r4/build/event/event-min.js&2.8.0r4/build/element/element-min.js&2.8.0r4/build/json/json-min.js&2.8.0r4/build/datasource/datasource-min.js&2.8.0r4/build/swf/swf-min.js&2.8.0r4/build/charts/charts-min.js"></script>';

		$res .=
		'<style type="text/css">'.
		'#chart { width: 500px; height: 350px; }'.
		'</style>';

		$res .=
		'<div id="chart">'.
		'Unable to load Flash content. The YUI Charts Control requires Flash Player 9.0.45 or higher. '.
		'You can download the latest version of Flash Player from the <a href="http://www.adobe.com/go/getflashplayer">Adobe Flash Player Download Center</a>.'.
		'</div>';

		$res .=
		'<script type="text/javascript">'.
		'YAHOO.widget.Chart.SWFURL = "http://yui.yahooapis.com/2.8.0r4/build/charts/assets/charts.swf";';

		//--- data
		$res .=
		'YAHOO.example.DataSource = '.jsArray2D($this->data_source).';'."\n".
		'var myDataSource = new YAHOO.util.DataSource( YAHOO.example.DataSource);'."\n".
		'myDataSource.responseType = YAHOO.util.DataSource.TYPE_JSARRAY;'."\n";

		$res .=
		'myDataSource.responseSchema = { fields: [ ';
		$res .= '"'.$this->x_field_name.'",';
		for ($i=0; $i < count($this->y_fields); $i++)
			$res .= '"'.$this->y_fields[$i]['name'].'",';

		$res .= '] };'."\n";

		//--- chart
		$res .= 'var seriesDef = [';
		$res .= '{ displayName: "'.$this->x_field_title.'", yField: "'.$this->x_field_name.'" }, ';

		for ($i=0; $i < count($this->y_fields); $i++)
			$res .= '{ displayName: "'.$this->y_fields[$i]['title'].'", yField: "'.$this->y_fields[$i]['name'].'" }, ';

		$res .= ' ];';

		$res .=
		'YAHOO.example.getDataTipText = function( item, index, series )
		{
			var toolTipText = series.displayName + " at " + item.'.$this->x_field_name.';
			toolTipText += "\n" + item[series.yField];
			return toolTipText;
		}'."\n";

		//Style object for chart
		$res .=
		'var styleDef ='.
		'{'.
			'xAxis: { labelRotation:-90 },'.
			'yAxis: { titleRotation:-90 }'.
		'}'."\n";

		$res .=
		'var yAxisWidget = new YAHOO.widget.NumericAxis();'.
		'yAxisWidget.minimum = 0;'.
		'yAxisWidget.title = "'.$this->y_title.'";';

		$res .=
		'var xAxisWidget = new YAHOO.widget.CategoryAxis();'.
		'xAxisWidget.minimum = 0;'.
		'xAxisWidget.title = "'.$this->x_field_title.'";';

		$res .=
		'var mychart = new YAHOO.widget.LineChart( "chart", myDataSource, {'.
		'series: seriesDef,'.
		'xField: "'.$this->x_field_name.'",'.
		'yAxis: yAxisWidget,'.
		'xAxis: xAxisWidget,'.
		'style: styleDef,'.
		'dataTipFunction: YAHOO.example.getDataTipText,'.
		//only needed for flash player express install
		'expressInstall: "assets/expressinstall.swf"'.
		'});'."\n";

		$res .= '</script>';

		return $res;
	}
{'fraction_non_alphanumeric': 0.22005966756641568, 'fraction_numerical': 0.016763744850120756, 'mean_word_length': 3.740740740740741, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 69, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6592111', 'n_tokens_mistral': 2943, 'n_tokens_neox': 2688, 'n_words': 497}