add zooming to graph
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -2,10 +2,7 @@
<project version="4">
<component name="ChangeListManager">
<list default="true" id="f90ee5b5-97e4-47ec-9b14-d4f4e896f100" name="Default" comment="">
- <change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/.idea/dictionaries/Madoka.xml" />
- <change type="MODIFICATION" beforePath="$PROJECT_DIR$/.idea/workspace.xml" afterPath="$PROJECT_DIR$/.idea/workspace.xml" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/calls.json.php" afterPath="$PROJECT_DIR$/calls.json.php" />
- <change type="MODIFICATION" beforePath="$PROJECT_DIR$/common.inc.php" afterPath="$PROJECT_DIR$/common.inc.php" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/output.txt" afterPath="$PROJECT_DIR$/output.txt" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/viewcalls.php" afterPath="$PROJECT_DIR$/viewcalls.php" />
</list>
@@ -27,11 +24,13 @@
<component name="ExecutionTargetManager" SELECTED_TARGET="default_target" />
<component name="FileEditorManager">
<leaf>
- <file leaf-file-name="viewcalls.php" pinned="false" current="false" current-in-tab="false">
+ <file leaf-file-name="viewcalls.php" pinned="false" current="true" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/viewcalls.php">
<provider selected="true" editor-type-id="text-editor">
- <state line="63" column="25" selection-start="2268" selection-end="2268" vertical-scroll-proportion="-3.7307692">
- <folding />
+ <state line="38" column="0" selection-start="1277" selection-end="1277" vertical-scroll-proportion="0.5823699">
+ <folding>
+ <element signature="e#255#287#0" expanded="true" />
+ </folding>
</state>
</provider>
</entry>
@@ -39,16 +38,16 @@
<file leaf-file-name="common.inc.php" pinned="false" current="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/common.inc.php">
<provider selected="true" editor-type-id="text-editor">
- <state line="60" column="117" selection-start="2262" selection-end="2262" vertical-scroll-proportion="-1.1153846">
+ <state line="60" column="117" selection-start="2262" selection-end="2262" vertical-scroll-proportion="-39.23077">
<folding />
</state>
</provider>
</entry>
</file>
- <file leaf-file-name="calls.json.php" pinned="false" current="true" current-in-tab="true">
+ <file leaf-file-name="calls.json.php" pinned="false" current="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/calls.json.php">
<provider selected="true" editor-type-id="text-editor">
- <state line="69" column="33" selection-start="2628" selection-end="2628" vertical-scroll-proportion="1.6950867">
+ <state line="72" column="41" selection-start="2843" selection-end="2843" vertical-scroll-proportion="-43.153847">
<folding />
</state>
</provider>
@@ -68,8 +67,8 @@
<option name="changedFiles">
<list>
<option value="$PROJECT_DIR$/scannr.py" />
+ <option value="$PROJECT_DIR$/common.inc.php" />
<option value="$PROJECT_DIR$/calls.json.php" />
- <option value="$PROJECT_DIR$/common.inc.php" />
<option value="$PROJECT_DIR$/viewcalls.php" />
</list>
</option>
@@ -261,7 +260,9 @@
<entry file="file://$PROJECT_DIR$/viewcalls.php">
<provider selected="true" editor-type-id="text-editor">
<state line="2" column="13" selection-start="46" selection-end="46" vertical-scroll-proportion="0.0">
- <folding />
+ <folding>
+ <element signature="e#255#287#0" expanded="true" />
+ </folding>
</state>
</provider>
</entry>
@@ -314,24 +315,26 @@
<state line="0" column="0" selection-start="0" selection-end="0" vertical-scroll-proportion="0.0" />
</provider>
</entry>
+ <entry file="file://$PROJECT_DIR$/common.inc.php">
+ <provider selected="true" editor-type-id="text-editor">
+ <state line="60" column="117" selection-start="2262" selection-end="2262" vertical-scroll-proportion="-39.23077">
+ <folding />
+ </state>
+ </provider>
+ </entry>
+ <entry file="file://$PROJECT_DIR$/calls.json.php">
+ <provider selected="true" editor-type-id="text-editor">
+ <state line="72" column="41" selection-start="2843" selection-end="2843" vertical-scroll-proportion="-43.153847">
+ <folding />
+ </state>
+ </provider>
+ </entry>
<entry file="file://$PROJECT_DIR$/viewcalls.php">
<provider selected="true" editor-type-id="text-editor">
- <state line="63" column="25" selection-start="2268" selection-end="2268" vertical-scroll-proportion="-3.7307692">
- <folding />
- </state>
- </provider>
- </entry>
- <entry file="file://$PROJECT_DIR$/common.inc.php">
- <provider selected="true" editor-type-id="text-editor">
- <state line="60" column="117" selection-start="2262" selection-end="2262" vertical-scroll-proportion="-1.1153846">
- <folding />
- </state>
- </provider>
- </entry>
- <entry file="file://$PROJECT_DIR$/calls.json.php">
- <provider selected="true" editor-type-id="text-editor">
- <state line="69" column="33" selection-start="2628" selection-end="2628" vertical-scroll-proportion="1.6950867">
- <folding />
+ <state line="38" column="0" selection-start="1277" selection-end="1277" vertical-scroll-proportion="0.5823699">
+ <folding>
+ <element signature="e#255#287#0" expanded="true" />
+ </folding>
</state>
</provider>
</entry>
--- a/calls.json.php
+++ b/calls.json.php
@@ -2,7 +2,7 @@
include('common.inc.php');
function getTGIDValuesByHour($TGID, $timeFrom, $timeTo) {
global $conn;
- $sth = $conn->prepare( 'select min(call_timestamp) as time, count(*), min(length), max(length), avg(length), stddev(length) from recordings
+ $sth = $conn->prepare( 'select tgid, min(call_timestamp) as time, count(*), min(length), max(length), avg(length), stddev(length) from recordings
group by tgid, date_trunc(\'hour\', call_timestamp) order by time');
$sth->execute( );
@@ -62,13 +62,17 @@
}
-if ($action == "graph") {
+if (strpos($action,"graph") !== false) {
$values = getTGIDValuesByHour($TGID, $timefrom, $timeto);
$label = $TGID;
$data = Array();
$tzoffset = get_timezone_offset("UTC");
foreach ($values as $value) {
- $data[] = Array((strtotime($value['time']) + $tzoffset) * 1000, intval($value['avg']));
+ if ($action == "graphlength") {
+ $data[$value['tgid']][] = Array((strtotime($value['time']) + $tzoffset) * 1000, intval($value['avg']));
+ } else if ($action == "graphcount") {
+ $data[$value['tgid']][] = Array((strtotime($value['time']) + $tzoffset) * 1000, intval($value['count']));
+ }
}
echo json_encode(Array("label" => $label, "data" => $data,
"previous" => Array(
@@ -82,5 +86,7 @@
);
}
+
+
?>
--- a/viewcalls.php
+++ b/viewcalls.php
@@ -5,7 +5,7 @@
?>
<div class="span12">
-<table width="100%" height="375px"><tr><td valign="middle"><span class="arrow-w" style="font-size:2em;"><</span></td><td width="95%"><div id="placeholder" style="width:100%;height:375px;"></div></td><td valign="middle"><span class="arrow-e" style="font-size:2em;">></span></td></tr></table>
+<table width="100%" height="775px"><tr><td valign="middle"><span class="arrow-w" style="font-size:2em;"><</span></td><td width="95%"><div id="placeholder" style="width:100%;height:575px;"></div></td><td valign="middle"><span class="arrow-e" style="font-size:2em;">></span></td></tr></table>
<script>
var data = [];
var plot;
@@ -13,77 +13,70 @@
lines: { show: true },
points: { show: true },
xaxis: { mode: "time" },
- crosshair: { mode: "x" },
+ selection : { mode : 'x', fps : 30 },
series: {
lines: { show: true },
points: { show: true }
- },
- grid: { hoverable: true, clickable: true }
+ }
};
$(function () {
// graph
var placeholder = document.getElementById("placeholder");
-
- var plot = Flotr.draw(placeholder, data, options);
- $("#placeholder").bind("plothover", function (event, pos, item) {
-
- if (item) {
- if (previousPoint != item.dataIndex) {
- previousPoint = item.dataIndex;
-
- $("#tooltip").remove();
- var x = item.datapoint[0].toFixed(2),
- y = item.datapoint[1].toFixed(2);
- var d = new Date();
- d.setTime(x);
- var time = d.getDate() + "-" + (d.getMonth()+1) + "-" + d.getFullYear()
- + " " + d.getUTCHours() + ':'+ (d.getUTCMinutes().toString().length == 1 ? '0'+ d.getMinutes(): d.getUTCMinutes());
+ drawGraph (options);
- showTooltip(item.pageX, item.pageY,
- item.series.label + " at " + time + " = " + y);
- }
- }
- else {
- $("#tooltip").remove();
- previousPoint = null;
- }
-
- });
+ // Hook into the 'flotr:select' event.
+ Flotr.EventAdapter.observe(placeholder, 'flotr:select', function (area) {
+
+ // Draw graph with new area
+ graph = drawGraph({
+ xaxis: {min:area.x1, max:area.x2},
+ yaxis: {min:area.y1, max:area.y2}
+ });
+ });
+
+ // When graph is clicked, draw the graph with default area.
+ Flotr.EventAdapter.observe(placeholder, 'flotr:click', function () { drawGraph(); });
+
- getData('<?php echo $tgid; ?>','<?php echo strtotime("10/10/2012") ?>','<?php echo strtotime("10/21/2012") ?>');
+ getData('<?php echo $tgid; ?>','<?php echo strtotime("10/09/2012") ?>','<?php echo strtotime("10/11/2012") ?>');
});
-
+
+ // Draw graph with default options, overwriting with passed options
+ function drawGraph (opts) {
+
+ // Clone the options, so the 'options' variable always keeps intact.
+ var o = Flotr._.extend(Flotr._.clone(options), opts || {});
+
+ // Return a new graph.
+ return Flotr.draw(
+ placeholder,
+ data,
+ o
+ );
+ }
+
+
function onDataReceived(series) {
data =[]
- data[data.length] = series;
-
- plot =Flotr.draw(placeholder, data, options);
+ for (var key in series.data) {
+ data[data.length] = {label: key, data: series.data[key]};
+ }
+ drawGraph (options);
}
function getData(sensorID,from,to) {
$.ajax({
- url: "<?php echo $basePath; ?>calls.json.php?action=graph&tgid="+sensorID+"&from="+from+"&to="+to,
+ url: "<?php echo $basePath; ?>calls.json.php?action=graphcount&tgid="+sensorID+"&from="+from+"&to="+to,
method: 'GET',
dataType: 'json',
success: onDataReceived
});
}
- function showTooltip(x, y, contents) {
- $('<div id="tooltip">' + contents + '</div>').css( {
- position: 'absolute',
- display: 'none',
- top: y + 5,
- left: x + 5,
- border: '1px solid #fdd',
- padding: '2px',
- 'background-color': '#fee',
- opacity: 0.80
- }).appendTo("body").fadeIn(200);
- }
+
</script>