<commit_before><?php
/**
 *
 */
 // function customError($errno, $errstr, $errfile, $errline){
 //  echo "<b>Custom error:</b> [$errno] $errstr<br />";
 //  echo " Error on line $errline in $errfile<br />";
 //  echo "Ending Script";
 //  die();
 // }
 // set_error_handler("customError");

class EasyChart
{
  protected $typename;
  public $data=false;
  public $option=false;
  public $config;


  function __construct($type=""){
    global $EC_config;

    $this->config=(empty($EC_config))?array():$EC_config;

    if (!empty($this->config['debug'])){
      if ($this->config['debug']){
        set_error_handler("EasyChart::customError");
      }
    }
    if (empty($type)){
      if (empty($this->config['type'])){
        $type="none";
      }else{
        $type=$this->config['type'];
      }
    }
    $this->type($type);

    if (!empty($this->config['default'])){
      foreach ($this->config['default'] as $key => $value) {
        $this->option->set($key,$value);
      }
    }

  }
  function title($title='',$subtitle='',$x="left"){
    $this->option->set("title","
    {
            text: '$title',
            subtext: '$subtitle',
            x: '$x',
            align: 'left'
        }
     ");
  }
  function zoom($enable=true){
    $en=($enable)?"true":"false";
    $this->option->set("dataZoom","
    {
        show: $en,
        start : 0
    }
     ");
  }
  function fullsize($left="60",$right="60",$top="60",$bottom="60"){
    $this->option->set("grid","
    {
        left: '$left',
        right: '$right',
        top: '$top',
        bottom: '$bottom',
        containLabel: true
    }
     ");
  }
  function toolbox($conf=""){
    $this->option->set("toolbox","
    {
          show : true,
          feature : {
              mark : {show: true},
              dataView : {show: true, readOnly: false},
            //  magicType : {show: true, type: ['line', 'bar']},
              restore : {show: true},
              saveAsImage : {show: true},
              $conf
          }
      }
     ");
  }
  function type($type='none'){
    $this->typename=ucfirst($type);
    if (!empty($this->typename)){
      $classname='Chart_'.$this->typename;
      $this->option=new ECOption();
      $this->data=new $classname($this->option);
    }

  }

  function add(){
    $args = func_get_args();
    $this->data->add($args);
  }
  function add_data($data){
    $this->data->add_data($data);
  }
  function clean($d){
    $this->data->clean();
  }
  function right2left(){
    $this->data->right2left();
  }
  static function error($msg){
    self::apiout(array(
      "result"=>false,
      "type"=>"error",
      "data"=>$msg
    ));

  }
  static function customError($errno, $errstr, $errfile, $errline){
   echo "<b>Custom error:</b> [$errno] $errstr<br />";
   echo " Error on line $errline in $errfile<br />";
   echo "Ending Script";
   die();
  }
  static function apiout($data){

    header('Cache-Control: no-cache, must-revalidate');
		header("Pragma: no-cache");
    header('Content-type: application/json');

    echo json_encode($data);
    die();
  }
  static function strout($data){
    return json_encode($data);
  }
  static function getAPI(){
    return self::getVar("EC_api","");
  }
  static function server($dir="",$stop=false){
    $_hash=self::getAPI();

    if (empty($_hash)){
      if ($stop){
        self::error('没有指定API');
      }else{
        return;
      }
    }

    $_file=strtr($_hash,array('.' => '/')).'.php';
    $_file=rtrim($dir,'/').$_file;

    if (file_exists($_file)) {
    	require $_file;
    }else{
    	EasyChart::error('找不到API');
    }
  }
  static function getVar($name,$default=""){
    return (isset($_REQUEST[$name]))?$_REQUEST[$name]:$default;
  }
  static function getP($parmstr){
		$str=is_array($parmstr)?$parmstr:explode(',',trim($parmstr,','));
		foreach ($str as $ks){
			$k=trim($ks);
			global ${$k};
			${$k}=self::getVar($k);
		}

	}
  function out($to_str=false){
    $this->data->build();<commit_msg>完善调整大小函数<commit_after><?php
/**
 *
 */
 // function customError($errno, $errstr, $errfile, $errline){
 //  echo "<b>Custom error:</b> [$errno] $errstr<br />";
 //  echo " Error on line $errline in $errfile<br />";
 //  echo "Ending Script";
 //  die();
 // }
 // set_error_handler("customError");

class EasyChart
{
  protected $typename;
  public $data=false;
  public $option=false;
  public $config;


  function __construct($type=""){
    global $EC_config;

    $this->config=(empty($EC_config))?array():$EC_config;

    if (!empty($this->config['debug'])){
      if ($this->config['debug']){
        set_error_handler("EasyChart::customError");
      }
    }
    if (empty($type)){
      if (empty($this->config['type'])){
        $type="none";
      }else{
        $type=$this->config['type'];
      }
    }
    $this->type($type);

    if (!empty($this->config['default'])){
      foreach ($this->config['default'] as $key => $value) {
        $this->option->set($key,$value);
      }
    }

  }
  function title($title='',$subtitle='',$x="left"){
    $this->option->set("title","
    {
            text: '$title',
            subtext: '$subtitle',
            x: '$x',
            align: 'left'
        }
     ");
  }
  function zoom($enable=true){
    $en=($enable)?"true":"false";
    $this->option->set("dataZoom","
    {
        show: $en,
        start : 0
    }
     ");
  }
  function size($left="60",$right="60",$top="60",$bottom="60"){
    $this->option->set("grid","
    {
        left: '$left',
        right: '$right',
        top: '$top',
        bottom: '$bottom',
        containLabel: true
    }
     ");
  }
  function toolbox($conf=""){
    $this->option->set("toolbox","
    {
          show : true,
          feature : {
              mark : {show: true},
              dataView : {show: true, readOnly: false},
            //  magicType : {show: true, type: ['line', 'bar']},
              restore : {show: true},
              saveAsImage : {show: true},
              $conf
          }
      }
     ");
  }
  function type($type='none'){
    $this->typename=ucfirst($type);
    if (!empty($this->typename)){
      $classname='Chart_'.$this->typename;
      $this->option=new ECOption();
      $this->data=new $classname($this->option);
    }

  }

  function add(){
    $args = func_get_args();
    $this->data->add($args);
  }
  function add_data($data){
    $this->data->add_data($data);
  }
  function clean($d){
    $this->data->clean();
  }
  function right2left(){
    $this->data->right2left();
  }
  static function error($msg){
    self::apiout(array(
      "result"=>false,
      "type"=>"error",
      "data"=>$msg
    ));

  }
  static function customError($errno, $errstr, $errfile, $errline){
   echo "<b>Custom error:</b> [$errno] $errstr<br />";
   echo " Error on line $errline in $errfile<br />";
   echo "Ending Script";
   die();
  }
  static function apiout($data){

    header('Cache-Control: no-cache, must-revalidate');
		header("Pragma: no-cache");
    header('Content-type: application/json');

    echo json_encode($data);
    die();
  }
  static function strout($data){
    return json_encode($data);
  }
  static function getAPI(){
    return self::getVar("EC_api","");
  }
  static function server($dir="",$stop=false){
    $_hash=self::getAPI();

    if (empty($_hash)){
      if ($stop){
        self::error('没有指定API');
      }else{
        return;
      }
    }

    $_file=strtr($_hash,array('.' => '/')).'.php';
    $_file=rtrim($dir,'/').$_file;

    if (file_exists($_file)) {
    	require $_file;
    }else{
    	EasyChart::error('找不到API'.$_file);
    }
  }
  static function getVar($name,$default=""){
    return (isset($_REQUEST[$name]))?$_REQUEST[$name]:$default;
  }
  static function getP($parmstr){
		$str=is_array($parmstr)?$parmstr:explode(',',trim($parmstr,','));
		foreach ($str as $ks){
			$k=trim($ks);
			global ${$k};
			${$k}=self::getVar($k);
		}

	}
  function out($to_str=false){
    $this->data->build();
{'fraction_non_alphanumeric': 0.21607411116675013, 'fraction_numerical': 0.002754131196795193, 'mean_word_length': 2.6018935978358884, 'pattern_counts': {'":': 2, '<': 21, '<?xml version=': 0, '>': 97, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4714847', 'n_tokens_mistral': 2782, 'n_tokens_neox': 2715, 'n_words': 467}