Skip to content

Commit

Permalink
Use adjusted numeric axis instead of forced_assoc.
Browse files Browse the repository at this point in the history
  • Loading branch information
goat1000 committed Jul 15, 2015
1 parent e1dac28 commit 165341a
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions SVGGraphHistogram.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
class Histogram extends BarGraph {

protected $label_centre = FALSE;
protected $force_assoc = TRUE;
protected $minimum_units_y = 1;
protected $repeated_keys = 'accept'; // allow repeated keys

protected $increment = NULL;
Expand Down Expand Up @@ -79,12 +77,12 @@ public function Values($values)
Graph::SetNumStringOptions($this->settings['decimal'],
$this->settings['thousands']);
for($i = $start; $i < $end; $i += $this->increment) {
$key = Graph::NumString($i);
$key = (int)$i;
$map[$key] = null;
}

foreach($values as $val) {
$k = Graph::NumString($this->Interval($val));
$k = (int)$this->Interval($val);
if(!array_key_exists($k, $map))
$map[$k] = 1;
else
Expand All @@ -104,6 +102,15 @@ public function Values($values)
// turn off structured data
$this->structure = NULL;
$this->structured_data = FALSE;

// set up options to make bar graph class draw the histogram properly
$this->minimum_units_y = 1;
$this->subdivision_h = $this->increment; // no subdiv below bar size
$this->grid_division_h = max($this->increment, $this->grid_division_h);

$amh = $this->axis_min_h;
if(empty($amh))
$this->axis_min_h = $start;
}
parent::Values($values);
}
Expand Down Expand Up @@ -136,12 +143,23 @@ protected function GridPosition($key, $ikey)
$position = null;
$zero = -0.01; // catch values close to 0
$axis = $this->x_axes[$this->main_x_axis];
$offset = $axis->Zero() + ($axis->Unit() * $ikey);
$offset = $axis->Zero() + ($axis->Unit() * $key);
$g_limit = $this->g_width - ($axis->Unit() / 2);
if($offset >= $zero && floor($offset) <= $g_limit)
$position = $this->pad_left + $offset;

return $position;
}

/**
* Returns the width of a bar
*/
protected function BarWidth()
{
if(is_numeric($this->bar_width) && $this->bar_width >= 1)
return $this->bar_width;
$unit_w = $this->x_axes[$this->main_x_axis]->Unit();
return $unit_w * $this->increment;
}
}

0 comments on commit 165341a

Please sign in to comment.