add zooming to graph
--- a/.gitmodules
+++ b/.gitmodules
@@ -3,5 +3,5 @@
url = git://github.com/uskr/pynma.git
[submodule "js/flotr2"]
path = js/flotr2
- url = git://github.com/HumbleSoftware/Flotr2.git
+ url = https://github.com/HumbleSoftware/Flotr2.git
--- /dev/null
+++ b/.idea/dictionaries/Madoka.xml
@@ -1,1 +1,10 @@
-
+<component name="ProjectDictionaryState">
+ <dictionary name="Madoka">
+ <words>
+ <w>tgid</w>
+ <w>timefrom</w>
+ <w>timeto</w>
+ <w>tzoffset</w>
+ </words>
+ </dictionary>
+</component>
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -2,10 +2,8 @@
<project version="4">
<component name="ChangeListManager">
<list default="true" id="f90ee5b5-97e4-47ec-9b14-d4f4e896f100" name="Default" comment="">
- <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$/db.sql" afterPath="$PROJECT_DIR$/db.sql" />
+ <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>
<ignored path="scannr.iws" />
@@ -26,13 +24,12 @@
<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="2" column="13" selection-start="46" selection-end="46" vertical-scroll-proportion="36.153847">
+ <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" />
- <element signature="e#341#363#0" expanded="true" />
</folding>
</state>
</provider>
@@ -41,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="34" column="0" selection-start="1179" selection-end="1179" vertical-scroll-proportion="-22.23077">
+ <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="2" column="9" selection-start="42" selection-end="42" vertical-scroll-proportion="-1.2507788">
+ <state line="72" column="41" selection-start="2843" selection-end="2843" vertical-scroll-proportion="-43.153847">
<folding />
</state>
</provider>
@@ -109,7 +106,6 @@
<sortByType />
</navigator>
<panes>
- <pane id="Scope" />
<pane id="ProjectPane">
<subPane>
<PATH>
@@ -130,6 +126,7 @@
</PATH>
</subPane>
</pane>
+ <pane id="Scope" />
</panes>
</component>
<component name="PropertiesComponent">
@@ -137,8 +134,8 @@
<property name="WebServerToolWindowFactoryState" value="false" />
<property name="options.lastSelected" value="project.propVCSSupport.Mappings" />
<property name="last_opened_file_path" value="$PROJECT_DIR$/../busui/myway/myway_timeliness.php" />
+ <property name="options.splitter.details.proportions" value="0.2" />
<property name="options.searchVisible" value="true" />
- <property name="options.splitter.details.proportions" value="0.2" />
</component>
<component name="RunManager">
<configuration default="true" type="PHPUnitRunConfigurationType" factoryName="PHPUnit">
@@ -150,7 +147,7 @@
</configuration>
<configuration default="true" type="JavascriptDebugSession" factoryName="Local">
<JSDebuggerConfigurationSettings>
- <option name="engineId" />
+ <option name="engineId" value="embedded" />
<option name="fileUrl" />
</JSDebuggerConfigurationSettings>
<method />
@@ -178,6 +175,7 @@
</component>
<component name="TaskManager">
<task active="true" id="Default" summary="Default task">
+ <changelist id="f90ee5b5-97e4-47ec-9b14-d4f4e896f100" name="Default" comment="" />
<created>1350026709905</created>
<updated>1350026709905</updated>
</task>
@@ -187,23 +185,23 @@
<frame x="57" y="-8" width="1391" height="916" extended-state="6" />
<editor active="true" />
<layout>
- <window_info id="Changes" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="-1" side_tool="false" content_ui="tabs" />
+ <window_info id="Changes" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="7" side_tool="false" content_ui="tabs" />
<window_info id="TODO" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="6" side_tool="false" content_ui="tabs" />
- <window_info id="Database" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="-1" side_tool="false" content_ui="tabs" />
+ <window_info id="Database" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="3" side_tool="false" content_ui="tabs" />
<window_info id="Structure" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.25" sideWeight="0.5" order="1" side_tool="true" content_ui="tabs" />
- <window_info id="Project" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" weight="0.24981189" sideWeight="0.6706349" order="0" side_tool="false" content_ui="combo" />
+ <window_info id="Project" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" weight="0.2535741" sideWeight="0.6706349" order="0" side_tool="false" content_ui="combo" />
<window_info id="Debug" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.4" sideWeight="0.5" order="3" side_tool="false" content_ui="tabs" />
- <window_info id="Favorites" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="-1" side_tool="true" content_ui="tabs" />
- <window_info id="Event Log" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.32936507" sideWeight="0.5" order="-1" side_tool="true" content_ui="tabs" />
+ <window_info id="Favorites" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="2" side_tool="true" content_ui="tabs" />
+ <window_info id="Event Log" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.32936507" sideWeight="0.5" order="7" side_tool="true" content_ui="tabs" />
<window_info id="Run" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="2" side_tool="false" content_ui="tabs" />
- <window_info id="Version Control" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="-1" side_tool="false" content_ui="tabs" />
+ <window_info id="Version Control" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="7" side_tool="false" content_ui="tabs" />
<window_info id="Cvs" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.25" sideWeight="0.5" order="4" side_tool="false" content_ui="tabs" />
<window_info id="Message" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="0" side_tool="false" content_ui="tabs" />
+ <window_info id="Ant Build" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.25" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" />
<window_info id="Find" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" />
- <window_info id="Ant Build" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.25" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" />
<window_info id="Commander" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.4" sideWeight="0.5" order="0" side_tool="false" content_ui="tabs" />
+ <window_info id="Hierarchy" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.25" sideWeight="0.5" order="2" side_tool="false" content_ui="combo" />
<window_info id="Inspection" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.4" sideWeight="0.5" order="5" side_tool="false" content_ui="tabs" />
- <window_info id="Hierarchy" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.25" sideWeight="0.5" order="2" side_tool="false" content_ui="combo" />
</layout>
</component>
<component name="VcsContentAnnotationSettings">
@@ -259,76 +257,84 @@
<breakpoint-manager />
</component>
<component name="editorHistoryManager">
- <entry file="file://$PROJECT_DIR$/trunklog.php">
- <provider selected="true" editor-type-id="text-editor">
- <state line="0" column="0" selection-start="0" selection-end="0" vertical-scroll-proportion="0.0">
- <folding />
- </state>
- </provider>
- </entry>
- <entry file="file://$PROJECT_DIR$/../disclosr/include/template.inc.php">
- <provider selected="true" editor-type-id="text-editor">
- <state line="72" column="93" selection-start="2545" selection-end="2635" vertical-scroll-proportion="0.43404254">
- <folding />
- </state>
- </provider>
- </entry>
- <entry file="file://$PROJECT_DIR$/../disclosr/include/common.inc.php">
- <provider selected="true" editor-type-id="text-editor">
- <state line="0" column="0" selection-start="0" selection-end="0" vertical-scroll-proportion="0.0">
- <folding />
- </state>
- </provider>
- </entry>
- <entry file="file://C:/tmp/h5bp-html5-boilerplate-2279296/index.html">
- <provider selected="true" editor-type-id="text-editor">
- <state line="38" column="11" selection-start="1245" selection-end="1982" vertical-scroll-proportion="0.93352604">
- <folding />
- </state>
- </provider>
- </entry>
- <entry file="file://$PROJECT_DIR$/../busui/myway/myway_timeliness.php">
- <provider selected="true" editor-type-id="text-editor">
- <state line="27" column="5" selection-start="1003" selection-end="1018" vertical-scroll-proportion="26.346153">
- <folding />
- </state>
- </provider>
- </entry>
- <entry file="file://$PROJECT_DIR$/scannr.py">
- <provider selected="true" editor-type-id="text-editor">
- <state line="66" column="23" selection-start="2084" selection-end="2084" vertical-scroll-proportion="0.0">
- <folding />
- </state>
- </provider>
- </entry>
- <entry file="file://$PROJECT_DIR$/snd.py">
- <provider selected="true" editor-type-id="text-editor">
- <state line="0" column="0" selection-start="0" selection-end="0" vertical-scroll-proportion="0.0">
- <folding />
- </state>
- </provider>
- </entry>
<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="36.153847">
+ <state line="2" column="13" selection-start="46" selection-end="46" vertical-scroll-proportion="0.0">
<folding>
<element signature="e#255#287#0" expanded="true" />
- <element signature="e#341#363#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/common.inc.php">
<provider selected="true" editor-type-id="text-editor">
- <state line="34" column="0" selection-start="1179" selection-end="1179" vertical-scroll-proportion="-22.23077">
+ <state line="34" column="0" selection-start="1179" selection-end="1179" vertical-scroll-proportion="0.0">
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/calls.json.php">
<provider selected="true" editor-type-id="text-editor">
- <state line="2" column="9" selection-start="42" selection-end="42" vertical-scroll-proportion="-1.2507788">
+ <state line="2" column="9" selection-start="42" selection-end="42" vertical-scroll-proportion="0.0">
<folding />
+ </state>
+ </provider>
+ </entry>
+ <entry file="file://$PROJECT_DIR$/trunklog.php">
+ <provider selected="true" editor-type-id="text-editor">
+ <state line="0" column="0" selection-start="0" selection-end="0" vertical-scroll-proportion="0.0" />
+ </provider>
+ </entry>
+ <entry file="file://$PROJECT_DIR$/../disclosr/include/template.inc.php">
+ <provider selected="true" editor-type-id="text-editor">
+ <state line="72" column="93" selection-start="2545" selection-end="2635" vertical-scroll-proportion="0.43404254" />
+ </provider>
+ </entry>
+ <entry file="file://$PROJECT_DIR$/../disclosr/include/common.inc.php">
+ <provider selected="true" editor-type-id="text-editor">
+ <state line="0" column="0" selection-start="0" selection-end="0" vertical-scroll-proportion="0.0" />
+ </provider>
+ </entry>
+ <entry file="file://C:/tmp/h5bp-html5-boilerplate-2279296/index.html">
+ <provider selected="true" editor-type-id="text-editor">
+ <state line="38" column="11" selection-start="1245" selection-end="1982" vertical-scroll-proportion="0.93352604" />
+ </provider>
+ </entry>
+ <entry file="file://$PROJECT_DIR$/../busui/myway/myway_timeliness.php">
+ <provider selected="true" editor-type-id="text-editor">
+ <state line="27" column="5" selection-start="1003" selection-end="1018" vertical-scroll-proportion="26.346153" />
+ </provider>
+ </entry>
+ <entry file="file://$PROJECT_DIR$/scannr.py">
+ <provider selected="true" editor-type-id="text-editor">
+ <state line="66" column="23" selection-start="2084" selection-end="2084" vertical-scroll-proportion="0.0" />
+ </provider>
+ </entry>
+ <entry file="file://$PROJECT_DIR$/snd.py">
+ <provider selected="true" editor-type-id="text-editor">
+ <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="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>
--- /dev/null
+++ b/calllog.php
@@ -1,1 +1,22 @@
+<?php
+include ('common.inc.php');
+ $sth = $conn->prepare( 'select * from recordings
+ order by call_timestamp desc limit 10');
+ $sth->execute(Array());
+
+$row = 0;
+echo "<table>";
+foreach ($sth->fetchAll() as $data) {
+
+
+ echo "<tr>";
+ for ($c=0; $c < count($data); $c++) {
+ echo '<td>'.$data[$c] . "</td>\n";
+ }
+ echo "</tr>";
+ }
+ $row++;
+echo "</table>";
+?>
+
--- a/calls.json.php
+++ b/calls.json.php
@@ -1,70 +1,78 @@
<?php
include('common.inc.php');
-function getSensorValuesByHour($sensorID, $timeFrom, $timeTo) {
+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( Array($sensorID, $timeFrom, $timeTo));
- return $sth->fetchAll();
+ $sth->execute( );
+ //Array($TGID, $timeFrom, $timeTo)
+ return $sth->fetchAll();
+
+
}
-function getSensorValuesByDay($sensorID, $dayFrom, $dayTo) {
+function getTGIDValuesByDay($TGID, $dayFrom, $dayTo) {
global $conn;
$sth = $conn->prepare('select min(time) as time, min(value), max(value), avg(value), stddev(value) from sensor_values where sensor_id = ?
group by sensor_id, date_trunc(\'day\', time) order by time');
- $sth->execute( Array($sensorID));
+ $sth->execute( Array($TGID));
return $sth->fetchAll();
}
-function getSensorDataYears($sensorID, $timeFrom, $timeTo) {
+function getTGIDDataYears($TGID, $timeFrom, $timeTo) {
global $conn;
$sth = $conn->prepare("select distinct extract('year' from call_timestamp) as year from recordings where tgid = ? order by year");
- $sth->execute(Array($sensorID));
+ $sth->execute(Array($TGID));
return $sth->fetchAll();
}
-function getSensorDataMonths($sensorID, $timeFrom, $timeTo) {
+function getTGIDDataMonths($TGID, $timeFrom, $timeTo) {
global $conn;
$sth = $conn->prepare("select distinct extract('month' from call_timestamp) as month, extract('year' from call_timestamp) as year from recordings where tgid = ? order by year, month");
- $sth->execute(Array($sensorID));
+ $sth->execute(Array($TGID));
return $sth->fetchAll();
}
-function getSensorDataDays($sensorID, $timeFrom, $timeTo) {
+function getTGIDDataDays($TGID, $timeFrom, $timeTo) {
global $conn;
$sth = $conn->prepare("select distinct extract('day' from call_timestamp) as day, extract('month' from call_timestamp) as month, extract('year' from call_timestamp) as year from recordings where tgid = ? order by year,month,day");
- $sth->execute(Array($sensorID));
+ $sth->execute(Array($TGID));
return $sth->fetchAll();
}
-$action = $_REQUEST['action'];
- $sensorID = $_REQUEST['tgid'];
-$timefrom = $_REQUEST['from'];
-$timeto = $_REQUEST['to'];
-if ($action = "data_description") {
+$action = (isset($_REQUEST['action']) ? $_REQUEST['action'] : '');
+$TGID = (isset($_REQUEST['tgid']) ? $_REQUEST['tgid'] : '');
+$timefrom = (isset($_REQUEST['from']) ? $_REQUEST['from'] : '');
+$timeto = (isset($_REQUEST['to']) ? $_REQUEST['to'] : '');
+
+if ($action == "data_description") {
$timefrom = strtotime($timefrom);
$timeto = strtotime($timeto);
- $years = getSensorDataYears($sensorID, $timefrom, $timeto);
+ $years = getTGIDDataYears($TGID, $timefrom, $timeto);
- $months = getSensorDataMonths($sensorID, $timefrom, $timeto);
- $days = getSensorDataDays($sensorID, $timefrom, $timeto);
+ $months = getTGIDDataMonths($TGID, $timefrom, $timeto);
+ $days = getTGIDDataDays($TGID, $timefrom, $timeto);
echo json_encode(Array("years" => $years, "months" => $months, "days" => $days
));
}
-if ($action = "graph") {
- $values = getSensorValuesByHour($sensorID, $timefrom, $timeto);
- $label = $sensorID;
+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(
@@ -78,5 +86,7 @@
);
}
+
+
?>
--- a/common.inc.php
+++ b/common.inc.php
@@ -10,6 +10,7 @@
catch(Exception $e) {
die('Unknown error in ' . __FILE__ . '.');
}
+$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
$basePath = "";
$DATA_DIR = "./data";
@@ -57,7 +58,7 @@
<link rel="stylesheet" href="css/main.css">
<script src="js/vendor/modernizr-2.6.1.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script>
- <script>window.jQuery || document.write('<script src="js/vendor/jquery-1.8.0.min.js"><\/script>')</script>
+ <!--<script>window.jQuery || document.write('<script src="js/vendor/jquery-1.8.0.min.js"><\/script>')</script>-->
<script type="text/javascript" src="<?php echo $basePath ?>js/flotr2/flotr2.js"></script>
<script src="js/plugins.js"></script>
<script src="js/main.js"></script>
--- 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("12/10/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 = $.plot($("#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>