Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
1 change: 1 addition & 0 deletions view.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@
</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 Down