You are here

function pDraw::validatePalette in Visitors 7

Same name and namespace in other branches
  1. 7.2 pChart/class/pDraw.class.php \pDraw::validatePalette()
1 call to pDraw::validatePalette()
pDraw::drawBarChart in pChart/class/pDraw.class.php

File

pChart/class/pDraw.class.php, line 5199

Class

pDraw

Code

function validatePalette($Colors, $Surrounding = NULL) {
  $Result = "";
  if (!is_array($Colors)) {
    return $this
      ->getRandomColor();
  }
  foreach ($Colors as $Key => $Values) {
    if (isset($Values["R"])) {
      $Result[$Key]["R"] = $Values["R"];
    }
    else {
      $Result[$Key]["R"] = rand(0, 255);
    }
    if (isset($Values["G"])) {
      $Result[$Key]["G"] = $Values["G"];
    }
    else {
      $Result[$Key]["G"] = rand(0, 255);
    }
    if (isset($Values["B"])) {
      $Result[$Key]["B"] = $Values["B"];
    }
    else {
      $Result[$Key]["B"] = rand(0, 255);
    }
    if (isset($Values["Alpha"])) {
      $Result[$Key]["Alpha"] = $Values["Alpha"];
    }
    else {
      $Result[$Key]["Alpha"] = 100;
    }
    if ($Surrounding != NULL) {
      $Result[$Key]["BorderR"] = $Result[$Key]["R"] + $Surrounding;
      $Result[$Key]["BorderG"] = $Result[$Key]["G"] + $Surrounding;
      $Result[$Key]["BorderB"] = $Result[$Key]["B"] + $Surrounding;
    }
    else {
      if (isset($Values["BorderR"])) {
        $Result[$Key]["BorderR"] = $Values["BorderR"];
      }
      else {
        $Result[$Key]["BorderR"] = $Result[$Key]["R"];
      }
      if (isset($Values["BorderG"])) {
        $Result[$Key]["BorderG"] = $Values["BorderG"];
      }
      else {
        $Result[$Key]["BorderG"] = $Result[$Key]["G"];
      }
      if (isset($Values["BorderB"])) {
        $Result[$Key]["BorderB"] = $Values["BorderB"];
      }
      else {
        $Result[$Key]["BorderB"] = $Result[$Key]["B"];
      }
      if (isset($Values["BorderAlpha"])) {
        $Result[$Key]["BorderAlpha"] = $Values["BorderAlpha"];
      }
      else {
        $Result[$Key]["BorderAlpha"] = $Result[$Key]["Alpha"];
      }
    }
  }
  return $Result;
}