Merge pull request #1036 from hgiesel/graphsaslib
Source graphs.js as library in the HTML head
This commit is contained in:
commit
e99deedbd8
@ -4,12 +4,12 @@
|
|||||||
<meta charset="utf-8" />
|
<meta charset="utf-8" />
|
||||||
<meta name="viewport" id="viewport" content="width=device-width" />
|
<meta name="viewport" id="viewport" content="width=device-width" />
|
||||||
<link href="graphs.css" rel="stylesheet" />
|
<link href="graphs.css" rel="stylesheet" />
|
||||||
|
<script src="../js/vendor/protobuf.min.js"></script>
|
||||||
|
<script src="graphs.js"></script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div id="main"></div>
|
<div id="main"></div>
|
||||||
</body>
|
|
||||||
<script src="../js/vendor/protobuf.min.js"></script>
|
|
||||||
<script src="graphs.js"></script>
|
|
||||||
<script>
|
<script>
|
||||||
anki.graphs(
|
anki.graphs(
|
||||||
document.getElementById("main"),
|
document.getElementById("main"),
|
||||||
@ -30,4 +30,5 @@
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
</script>
|
</script>
|
||||||
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
@ -3,11 +3,24 @@
|
|||||||
|
|
||||||
import throttle from "lodash.throttle";
|
import throttle from "lodash.throttle";
|
||||||
|
|
||||||
const tooltipDiv: HTMLDivElement = document.createElement("div");
|
function getOrCreateTooltipDiv(): HTMLDivElement {
|
||||||
tooltipDiv.className = "graph-tooltip";
|
const existingTooltip = document.getElementById("graphTooltip") as HTMLDivElement;
|
||||||
document.body.appendChild(tooltipDiv);
|
|
||||||
|
if (existingTooltip) {
|
||||||
|
return existingTooltip;
|
||||||
|
}
|
||||||
|
|
||||||
|
const tooltipDiv: HTMLDivElement = document.createElement("div");
|
||||||
|
tooltipDiv.id = "graphTooltip";
|
||||||
|
tooltipDiv.className = "graph-tooltip";
|
||||||
|
document.body.appendChild(tooltipDiv);
|
||||||
|
|
||||||
|
return tooltipDiv;
|
||||||
|
}
|
||||||
|
|
||||||
function showTooltipInner(msg: string, x: number, y: number): void {
|
function showTooltipInner(msg: string, x: number, y: number): void {
|
||||||
|
const tooltipDiv = getOrCreateTooltipDiv();
|
||||||
|
|
||||||
tooltipDiv.innerHTML = msg;
|
tooltipDiv.innerHTML = msg;
|
||||||
|
|
||||||
// move tooltip away from edge as user approaches right side
|
// move tooltip away from edge as user approaches right side
|
||||||
@ -26,6 +39,8 @@ function showTooltipInner(msg: string, x: number, y: number): void {
|
|||||||
export const showTooltip = throttle(showTooltipInner, 16);
|
export const showTooltip = throttle(showTooltipInner, 16);
|
||||||
|
|
||||||
export function hideTooltip(): void {
|
export function hideTooltip(): void {
|
||||||
|
const tooltipDiv = getOrCreateTooltipDiv();
|
||||||
|
|
||||||
showTooltip.cancel();
|
showTooltip.cancel();
|
||||||
tooltipDiv.style.opacity = "0";
|
tooltipDiv.style.opacity = "0";
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user