Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into stable
Browse files Browse the repository at this point in the history
  • Loading branch information
TrystanLea committed May 17, 2021
2 parents 442390e + 160d830 commit bb358fb
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 13 deletions.
41 changes: 35 additions & 6 deletions graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ var current_graph_name = "";
var previousPoint = 0;
var active_histogram_feed = 0;

var panning = false;

//----------------------------------------------------------------------------------------
// Events shared by both view and embed mode
//----------------------------------------------------------------------------------------
Expand All @@ -52,12 +54,15 @@ $('.graph_time_refresh').click(function () {
view.calc_interval();
graph_reload();
});
// Graph zooming
$('#placeholder').bind("plotselected", function (event, ranges) {
floatingtime=0;
view.start = ranges.xaxis.from;
view.end = ranges.xaxis.to;
view.calc_interval();
timeWindowChanged = 1;
graph_reload();
panning = true; setTimeout(function() {panning = false; }, 100);
});
$('#placeholder').bind("plothover", function (event, pos, item) {
var item_value;
Expand Down Expand Up @@ -85,6 +90,23 @@ $('#placeholder').bind("plothover", function (event, pos, item) {
} else $("#tooltip").remove();
});

// Graph click
//$("#placeholder").bind("touchstarted", function (event, pos) {
// $("#legend").hide();
// showlegend = false;
//});

$("#placeholder").bind("touchended", function (event, ranges) {
view.start = ranges.xaxis.from;
view.end = ranges.xaxis.to;
view.calc_interval();
timeWindowChanged = 1;
// showlegend = $("#showlegend")[0].checked;
// $("#legend").show();
graph_reload();
panning = true; setTimeout(function() {panning = false; }, 100);
});

// on finish sidebar hide/show
$(document).on('window.resized hidden.sidebar.collapse shown.sidebar.collapse', function() {
graph_resize();
Expand Down Expand Up @@ -843,7 +865,7 @@ function graph_draw()
toggle: { scale: "visible" },
touch: { pan: "x", scale: "x" },
hooks: {
bindEvents: [group_legend_values]
// bindEvents: [group_legend_values] // CHAVEIRO: this is breaking the touch function with the label overlapping the default flot one. Maybe a flot bug, maybe my lack of knowledge
}
}

Expand All @@ -864,7 +886,7 @@ function graph_draw()
mins = "";
}

if (!embed) $("#window-info").html("<b>"+_lang['Window']+":</b> "+printdate(view.start)+" > "+printdate(view.end)+", <b>"+_lang['Length']+":</b> "+hours+"h"+mins+" ("+time_in_window+" seconds)");
if (!embed) $("#window-info").html("<b>"+_lang['Window']+":</b> "+printdate(view.start)+" <b>→</b> "+printdate(view.end)+"<br><b>"+_lang['Length']+":</b> "+hours+"h"+mins+" ("+time_in_window+" seconds)");

plotdata = [];
for (var z in feedlist) {
Expand Down Expand Up @@ -1670,6 +1692,7 @@ function graph_create(data) {
delete data.feedlist[i].data
delete data.feedlist[i].stats;
}
data.name = encodeURIComponent(data.name)
// Save
var ajax = $.ajax({
method: "POST",
Expand Down Expand Up @@ -1750,19 +1773,25 @@ function load_feed_selector() {
function printdate(timestamp)
{
var date = new Date();
var thisyear = date.getFullYear()-2000;
var thisyear = date.getFullYear();

var date = new Date(timestamp);
var months = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'];
var year = date.getFullYear()-2000;
var year = date.getFullYear();
var month = months[date.getMonth()];
var day = date.getDate();

var minutes = date.getMinutes();
if (minutes<10) minutes = "0"+minutes;

var datestr = date.getHours()+":"+minutes+" "+day+" "+month;
if (thisyear!=year) datestr +=" "+year;
var secs = date.getSeconds();
if (secs<10) secs = "0"+secs;

var datestr = "";
// date.getHours()+":"+minutes+" "+day+" "+month;
datestr += day+"/"+month;
if (thisyear!=year) datestr += "/"+year;
datestr += " " + date.getHours()+":"+minutes+":"+secs;
return datestr;
};

Expand Down
8 changes: 4 additions & 4 deletions graph_model.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function __construct($mysqli, $group)
public function create($userid,$data)
{
$userid = (int) $userid;
$data = preg_replace('/[^\w\s\-.",:#{}\[\]]/','',$data);
$data = preg_replace('/[^\w\s\-.",:#&{}\[\]]/','',$data);

$stmt = $this->mysqli->prepare("INSERT INTO graph ( userid, data, groupid ) VALUES (?,?,0)");
$stmt->bind_param("is", $userid, $data);
Expand All @@ -41,7 +41,7 @@ public function update($userid,$id,$data)
{
$userid = (int) $userid;
$id = (int) $id;
$data = preg_replace('/[^\w\s\-.",:#{}\[\]]/','',$data);
$data = preg_replace('/[^\w\s\-.",:#&{}\[\]]/','',$data);

$result = $this->mysqli->query("SELECT data FROM graph WHERE `id`='$id' AND `userid`='$userid'");
if ($result->num_rows) {
Expand Down Expand Up @@ -127,7 +127,7 @@ public function getall($userid)

public function creategroupgraph($userid, $data, $groupid) {
$userid = (int) $userid;
$data = preg_replace('/[^\w\s\-.",:#{}\[\]]/', '', $data);
$data = preg_replace('/[^\w\s\-.",:#&{}\[\]]/', '', $data);
$groupid = (int) $groupid;
$user_role = $this->group->get_user_role($userid, $userid, $groupid);

Expand All @@ -147,7 +147,7 @@ public function creategroupgraph($userid, $data, $groupid) {
public function updategroupgraph($userid, $id, $data, $groupid) {
$userid = (int) $userid;
$id = (int) $id;
$data = preg_replace('/[^\w\s\-.",:#{}\[\]]/', '', $data);
$data = preg_replace('/[^\w\s\-.",:#&{}\[\]]/', '', $data);
$groupid = (int) $groupid;
$user_role = $this->group->get_user_role($userid, $userid, $groupid);

Expand Down
4 changes: 3 additions & 1 deletion module.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{
"name" : "Graph",
"version" : "2.0.10"
"version" : "2.0.11",
"location" : "/var/www/emoncms/Modules",
"branches_available": ["stable","master","menu_v3"]
}
6 changes: 4 additions & 2 deletions view.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

global $path, $embed;
$userid = 0;
$v = 9;
$v = 10;

if (isset($_GET['userid'])) $userid = (int) $_GET['userid'];

Expand All @@ -38,13 +38,15 @@
<link href="<?php echo $path; ?>Lib/bootstrap-datetimepicker-0.0.11/css/bootstrap-datetimepicker.min.css" rel="stylesheet">
<link href="<?php echo $path; ?>Modules/graph/graph.css?v=<?php echo $v; ?>" rel="stylesheet">

<script src="<?php echo $path;?>Lib/flot/jquery.flot.min.js"></script>
<script src="<?php echo $path;?>Lib/flot/jquery.flot.merged.js"></script>
<!-- <script src="<?php echo $path;?>Lib/flot/jquery.flot.min.js"></script>
<script src="<?php echo $path;?>Lib/flot/jquery.flot.time.min.js"></script>
<script src="<?php echo $path;?>Lib/flot/jquery.flot.selection.min.js"></script>
<script src="<?php echo $path;?>Lib/flot/jquery.flot.touch.min.js"></script>
<script src="<?php echo $path;?>Lib/flot/jquery.flot.togglelegend.min.js"></script>
<script src="<?php echo $path;?>Lib/flot/jquery.flot.resize.min.js"></script>
<script src="<?php echo $path; ?>Lib/flot/jquery.flot.stack.min.js"></script>
-->
<script src="<?php echo $path;?>Modules/graph/vis.helper.js?v=<?php echo $v; ?>"></script>
<script src="<?php echo $path;?>Lib/misc/clipboard.js?v=<?php echo $v; ?>"></script>
<script src="<?php echo $path; ?>Lib/bootstrap-datetimepicker-0.0.11/js/bootstrap-datetimepicker.min.js"></script>
Expand Down

0 comments on commit bb358fb

Please sign in to comment.