function pData::loadPalette

5.x pData.class.php pData::loadPalette($FileName, $Overwrite = FALSE)

File

inc/pchart/pchart/class/pData.class.php, line 528

Class

pData

Code

function loadPalette($FileName, $Overwrite = FALSE) 
 {
  if (!file_exists($FileName)) {
    return (-1);
  }
  if ($Overwrite) {
    $this->Palette = "";
  }

  $fileHandle = @fopen($FileName, "r");
  if (!$fileHandle) {
    return (-1);
  }
  while (!feof($fileHandle)) 
   {
    $buffer = fgets($fileHandle, 4096);
    if (preg_match("/,/", $buffer)) 
     {
      list($R, $G, $B, $Alpha) = preg_split("/,/", $buffer);
      if ($this->Palette == "") {
        $ID = 0;
      }
      else {
        $ID = count($this->Palette);
      }
      $this->Palette [$ID] = array("R" => $R, "G" => $G, "B" => $B, "Alpha" => $Alpha);
    }
  }
  fclose($fileHandle);

  /* Apply changes to current series */
  $ID = 0;
  if (isset($this->Data ["Series"])) 
   {
    foreach ($this->Data ["Series"] as $Key => $Value) 
     {
      if (!isset($this->Palette [$ID])) {
        $this->Data ["Series"][$Key]["Color"] = array("R" => 0, "G" => 0, "B" => 0, "Alpha" => 0);
      }
      else {
        $this->Data ["Series"][$Key]["Color"] = $this->Palette [$ID];
      }
      $ID++;
    }
  }
}