Skip to content

Commit

Permalink
add logic to derive from via URL params to GraphiteGraph
Browse files Browse the repository at this point in the history
  • Loading branch information
mrtazz committed Jun 21, 2016
1 parent 6d13feb commit f7b7ce4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 5 additions & 1 deletion phplib/GraphiteGraph.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class GraphiteGraph
{

private $stacked = false;
protected $defaultTime = "4h";

public function __construct(
$graphitehost,
Expand All @@ -14,7 +15,10 @@ public function __construct(
$hideLegend = null,
$width = null
) {
$this->from = $from ?: "-4h";
$this->from = filter_input(INPUT_GET, 'from');
if (!isset($this->from)) {
$this->from = "-" . $this->defaultTime;
}
$this->width = $width ?: "400";
$this->graphitehost = $graphitehost;
$this->baseurl = $graphitehost . "/render?width={$this->width}&from={$this->from}&target={{THETARGET}}";
Expand Down
2 changes: 1 addition & 1 deletion tests/Page_tests.php
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ public function testGetHeaderWithoutSelectBox() {
}

public function testBuildPageForMetrics() {
$expct = '<div class="row"><div class="col-md-4"><img src="http://grpht.exmpl.com/render?width=400&from=-4hours&target=foo&hideLegend=true"></img></div><div class="col-md-4"><img src="http://grpht.exmpl.com/render?width=400&from=-4hours&target=bla&hideLegend=true"></img></div></div>';
$expct = '<div class="row"><div class="col-md-4"><img src="http://grpht.exmpl.com/render?width=400&from=-4h&target=foo&hideLegend=true"></img></div><div class="col-md-4"><img src="http://grpht.exmpl.com/render?width=400&from=-4h&target=bla&hideLegend=true"></img></div></div>';
$ret = $this->page->buildPageForMetrics(["foo", "bla"]);
$this->assertEquals($expct, $ret);
}
Expand Down

0 comments on commit f7b7ce4

Please sign in to comment.