Skip to content
Merged
30 changes: 19 additions & 11 deletions graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,22 @@ $('#placeholder').bind("plotselected", function (event, ranges)

graph_reloaddraw();
});

function getFeedUnit(id){
let unit = ''
for(let key in feeds) {
if (feeds[key].id == id){
unit = feeds[key].unit || ''
}
}
return unit
}
$('#placeholder').bind("plothover", function (event, pos, item) {
var item_value;
if (item) {
var z = item.dataIndex;
if (previousPoint != item.datapoint) {
var dp=feedlist[item.seriesIndex].dp;
var feedid = feedlist[item.seriesIndex].id;
previousPoint = item.datapoint;

$("#tooltip").remove();
Expand All @@ -71,14 +80,12 @@ $('#placeholder').bind("plothover", function (event, pos, item) {
} else {
item_value=(item.datapoint[1]-item.datapoint[2]).toFixed(dp);
}

var d = new Date(item_time);
var days = ["Sun","Mon","Tue","Wed","Thu","Fri","Sat"];
var months = ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];
var minutes = d.getMinutes();
if (minutes<10) minutes = "0"+minutes;
var date = d.getHours()+":"+minutes+" "+days[d.getDay()]+", "+months[d.getMonth()]+" "+d.getDate();
tooltip(item.pageX, item.pageY, "<span style='font-size:11px'>"+item.series.label+"</span><br>"+item_value+"<br><span style='font-size:11px'>"+date+"</span>", "#fff");
item_value+=' '+getFeedUnit(feedid);
var date = moment(item_time).format('llll')
tooltip(item.pageX, item.pageY, "<span style='font-size:11px'>"+item.series.label+"</span>"+
"<br>"+item_value +
"<br><span style='font-size:11px'>"+date+"</span>"+
"<br><span style='font-size:11px'>("+(item_time/1000)+")</span>", "#fff");
}
} else $("#tooltip").remove();
});
Expand Down Expand Up @@ -508,7 +515,7 @@ function graph_init_editor()

$('body').on("click",".legendColorBox",function(d){
var country = $(this).html().toLowerCase();
console.log(country);
// console.log(country);
});

$(".feed-options-show-stats").click(function(){
Expand Down Expand Up @@ -674,6 +681,7 @@ function graph_draw()
var label = "";
if (showtag) label += feedlist[z].tag+": ";
label += feedlist[z].name;
label += ' '+getFeedUnit(feedlist[z].id);
var stacked = (typeof(feedlist[z].stack) !== "undefined" && feedlist[z].stack);
var plot = {label:label, data:data, yaxis:feedlist[z].yaxis, color: feedlist[z].color, stack: stacked};

Expand Down Expand Up @@ -707,7 +715,7 @@ function graph_draw()
}
out += "</td>";

out += "<td>"+feedlist[z].id+":"+feedlist[z].tag+":"+feedlist[z].name+"</td>";
out += "<td>"+feedlist[z].id+":"+feedlist[z].tag+":"+feedlist[z].name + getFeedUnit(feedlist[z].id)+"</td>";
out += "<td><select class='plottype' feedid="+feedlist[z].id+" style='width:80px'>";

var selected = "";
Expand Down
3 changes: 1 addition & 2 deletions graph_controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ function graph_controller()

// Check if group module is installed
$group = false;
$result = $mysqli->query("SHOW TABLES LIKE 'groups'");
if ($result->num_rows > 0) {
if (file_exists("Modules/group/group_model.php")) {
require_once "Modules/group/group_model.php";
$group = new Group($mysqli, $redis, null, null, null);
}
Expand Down
13 changes: 13 additions & 0 deletions group_view.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
<script language="javascript" type="text/javascript" src="<?php echo $path;?>Lib/flot/flot.min.js"></script>
-->
<script language="javascript" type="text/javascript" src="<?php echo $path;?>Modules/graph/vis.helper.js"></script>
<script language="javascript" type="text/javascript" src="<?php echo $path;?>Lib/misc/clipboard.js"></script>

<!-- toggle button to choose User or Group. Documentation: http://bootstrapswitch.com/options.html -->
<link href="<?php echo $path; ?>Modules/graph/Lib/bootstrap-switch.css" rel="stylesheet">
Expand Down Expand Up @@ -204,6 +205,10 @@
<option value="lastvalue">Replace with last value</option>
<option value="remove">Remove whole line</option>
</select>
<div class="input-append"><!-- just to match the styling of the other items -->
<button onclick="copyToClipboardCustomMsg(document.getElementById('csv'), 'copy-csv-feedback','Copied')" class="csvoptions btn" id="copy-csv" type="button">Copy <i class="icon-share-alt"></i></button>
</div>
<span id="copy-csv-feedback" class="csvoptions"></span>
</div>


Expand Down Expand Up @@ -341,6 +346,14 @@
}
});

// stops a part upgrade error - this change requires emoncms/emoncms repo to also be updated
// keep button hidden if new version of clipboard.js is not available
if (typeof copyToClipboardCustomMsg === 'function') {
document.getElementById('copy-csv').classList.remove('hidden');
} else {
copyToClipboardCustomMsg = function () {}
}

/******************************************
Functions
******************************************/
Expand Down
2 changes: 1 addition & 1 deletion module.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"name" : "Graph",
"version" : "1.2.0"
"version" : "1.2.1"
}
19 changes: 16 additions & 3 deletions view.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
-->
<script language="javascript" type="text/javascript" src="<?php echo $path; ?>Lib/flot/jquery.flot.stack.min.js"></script>
<script language="javascript" type="text/javascript" src="<?php echo $path;?>Modules/graph/vis.helper.js"></script>
<script language="javascript" type="text/javascript" src="<?php echo $path;?>Lib/misc/clipboard.js"></script>
<link href="<?php echo $path; ?>Lib/bootstrap-datetimepicker-0.0.11/css/bootstrap-datetimepicker.min.css" rel="stylesheet">
<script language="javascript" type="text/javascript" src="<?php echo $path; ?>Lib/bootstrap-datetimepicker-0.0.11/js/bootstrap-datetimepicker.min.js"></script>
<link href="<?php echo $path; ?>Modules/graph/graph.css" rel="stylesheet">
Expand Down Expand Up @@ -204,15 +205,20 @@
<option value="showName">Show name</option>
<option value="hide">Hide</option>
</select>
</div>

</div>

<div class="input-append"><!-- just to match the styling of the other items -->
<button onclick="copyToClipboardCustomMsg(document.getElementById('csv'), 'copy-csv-feedback','Copied')" class="csvoptions btn hidden" id="copy-csv" type="button">Copy <i class="icon-share-alt"></i></button>
</div>
<span id="copy-csv-feedback" class="csvoptions"></span>

<textarea id="csv" style="width:98%; height:500px; display:none; margin-top:10px"></textarea>
</div>
</div>
</div>

<script language="javascript" type="text/javascript" src="<?php echo $path;?>Modules/graph/graph.js?v=1"></script>
<script language="javascript" type="text/javascript" src="<?php echo $path;?>Lib/moment.min.js"></script>

<script>
var path = "<?php echo $path; ?>";
Expand All @@ -235,8 +241,15 @@
});
}

// stops a part upgrade error - this change requires emoncms/emoncms repo to also be updated
// keep button hidden if new version of clipboard.js is not available
if (typeof copyToClipboardCustomMsg === 'function') {
document.getElementById('copy-csv').classList.remove('hidden');
} else {
copyToClipboardCustomMsg = function () {}
}

// Assign active feedid from URL
console.log(window.location.pathname);
var urlparts = window.location.pathname.split("graph/");
if (urlparts.length==2) {
var feedids = urlparts[1].split(",");
Expand Down