// Function to redraw line, needs to be refactored. should be passed only index of button
function drawLine(table, canvas, button, ctx) {
ctx.clearRect(0, 0, canvas.width, canvas.height);
ctx.beginPath();
ctx.moveTo((button.offsetLeft + button.offsetWidth), (button.offsetTop + button.offsetHeight));
ctx.lineTo(table.offsetLeft, (table.offsetTop + table.offsetHeight));
ctx.stroke();
};
// TMP function to move button and check redrawing
function moveButton(table, canvas, button, ctx) {
button.style.left = 200 + "px";
button.style.top = 200 + "px";
drawLine(table, canvas, button, ctx);
}
// Array of all lines, should be array of all data by index
var lines = [];
var body = document.body,
html = document.documentElement;
var height = Math.max(body.scrollHeight, body.offsetHeight,
html.clientHeight, html.scrollHeight, html.offsetHeight);
var width = Math.max(body.scrollWidth, body.offsetWidth,
html.clientWidth, html.scrollWidth, html.offsetHeight);
// Loop through tables
var tables = document.getElementsByTagName("table");
for(var i = 0; i < tables.length; i++) {
var table = tables[i];
// Create button element
var button = document.createElement("button");
button.innerHTML = "Visualize on Blowchart!";
button.className = "visualize-on-blowchart";
// Add canvase after table
table.parentNode.insertBefore(button, table.nextSibling);
// Create canvas
var canvas = document.createElement("canvas");
canvas.className = "visualize-on-blowchart-line";
canvas.setAttribute("width", width);
canvas.setAttribute("height", height);
var ctx = canvas.getContext("2d");
// Should be addedd all elements to specific index
lines.push(ctx);
drawLine(table, canvas, button, ctx);
// TMP move line
setTimeout(function () {
moveButton(table, canvas, button, ctx);
}, 2000);
// Add canvase after table
table.parentNode.insertBefore(canvas, table.nextSibling);
};
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.