function find_range($data, $min, $max, $resolution) {
      if (sizeof($data) == 0 ) return array('min' => 0, 'max' => 0);
      foreach ($data as $key => $value) {
        if ($value=='none') continue;
        if ($value > $max) $max = $value;
        if ($value < $min) $min = $value;
      }

      if ($max == 0) {
        $factor = 1;
      } else {
        if ($max < 0) $factor = - pow(10, (floor(log10(abs($max))) + $resolution) );
        else $factor = pow(10, (floor(log10(abs($max))) - $resolution) );
      }
      if ($factor > 0.1) { // To avoid some wierd rounding errors (Moodle)
        $factor = round($factor * 1000.0) / 1000.0; // To avoid some wierd rounding errors (Moodle)
      } // To avoid some wierd rounding errors (Moodle)

      $max = $factor * @ceil($max / $factor);
      $min = $factor * @floor($min / $factor);

      //print "max=$max, min=$min<br />";

      return array('min' => $min, 'max' => $max);
    }