Skip to content

Commit e22098f

Browse files
committed
Add hover tooltip to graph
1 parent 82bc31f commit e22098f

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

public/assets/js/picoreflow.js

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,8 @@ function getOptions()
442442
color: 'rgba(216, 211, 197, 0.55)',
443443
borderWidth: 1,
444444
labelMargin: 10,
445-
mouseActiveRadius: 50
445+
mouseActiveRadius: 50,
446+
hoverable: true
446447
},
447448

448449
legend:
@@ -487,6 +488,33 @@ $(document).ready(function()
487488
// });
488489
};
489490

491+
$("<div id='tooltip'></div>").css({
492+
position: "absolute",
493+
display: "none",
494+
border: "1px solid #fdd",
495+
padding: "2px",
496+
"background-color": "#fee",
497+
opacity: 0.80
498+
}).appendTo("body");
499+
500+
$("#graph_container").bind("plothover", function (event, pos, item) {
501+
if (!pos.x || !pos.y) {
502+
return;
503+
}
504+
505+
if (item) {
506+
const x = item.datapoint[0]
507+
const y = item.datapoint[1].toFixed(0);
508+
509+
$("#tooltip").html(item.series.label + " at " +
510+
new Date(x * 1000).toISOString().substring(11, 16) + " = " + y + "º" + temp_scale_display)
511+
.css({top: item.pageY+5, left: item.pageX+5})
512+
.fadeIn(200);
513+
} else {
514+
$("#tooltip").stop().hide();
515+
}
516+
})
517+
490518
ws_status.onclose = function()
491519
{
492520
$.bootstrapGrowl("<span class=\"glyphicon glyphicon-exclamation-sign\"></span> <b>ERROR 1:</b><br/>Status Websocket not available", {

0 commit comments

Comments
 (0)