You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
154 lines
4.1 KiB
154 lines
4.1 KiB
/**
|
|
* Initializes variables and event listeners after the DOM content is loaded.
|
|
*/
|
|
let canvas, parent, legend, dataDiv, table
|
|
|
|
let rcTarget = {}
|
|
|
|
$(document).ready( function () {
|
|
canvas = document.getElementById("graphCanvas")
|
|
parent = document.getElementById("graphDiv")
|
|
legend = document.getElementById("graphLegend")
|
|
dataDiv = document.getElementById("dataDiv")
|
|
table = new Table(document.getElementById("dataTable"))
|
|
|
|
document.getElementById('upload').addEventListener('change', handleFileSelect, false)
|
|
|
|
load_data()
|
|
table.reloadEvLi()
|
|
reloadShares()
|
|
|
|
//Click
|
|
document.addEventListener('mousemove', (e) => {
|
|
const pos = {
|
|
x: e.clientX - canvas.offsetLeft,
|
|
y: e.clientY - canvas.offsetTop
|
|
}
|
|
let obj = checkHit(pos)
|
|
|
|
//show point value
|
|
if (obj !== null) {
|
|
dataDiv.style.left = pos.x + canvas.offsetLeft + "px"
|
|
dataDiv.style.top = pos.y + canvas.offsetTop + "px"
|
|
dataDiv.style.display = "block"
|
|
dataDiv.innerHTML = "<b>" + obj.name + "</b><br><p>" + obj.value + "</p>"
|
|
} else {
|
|
dataDiv.style.display = "none"
|
|
}
|
|
})
|
|
|
|
/*$("#exportBtn").on('click', function (e) {
|
|
table.reloadData()
|
|
exportData('tableData')
|
|
})
|
|
|
|
$("#saveBtn").on('click', function (e) {
|
|
table.reloadData()
|
|
save_data()
|
|
})
|
|
|
|
$("#drawBtn").on('click', function (e) {
|
|
table.reloadData()
|
|
submitData()
|
|
})
|
|
|
|
//RIGHT CLICK menu
|
|
$(document).bind("click", function(event) {
|
|
document.getElementById("rcMenu").style.display = "none"
|
|
})
|
|
|
|
//odebere řádek
|
|
$("#rcDelRow").on('click', function (e) {
|
|
e.preventDefault()
|
|
if (rcTarget.parentElement.parentElement.tagName === "THEAD")
|
|
return
|
|
table.removeRow(rcTarget.parentElement)
|
|
})
|
|
|
|
//přidá řádek
|
|
$("#rcAddRow").on('click', function (e) {
|
|
e.preventDefault()
|
|
table.addRow(table, rcTarget)
|
|
})
|
|
|
|
//odebere sloupec
|
|
$('#rcDelCol').on('click', function (e) {
|
|
e.preventDefault()
|
|
|
|
table.removeCol(getCellIndex(rcTarget))
|
|
})
|
|
|
|
//přidá sloupec
|
|
$('#rcAddCol').on('click', function (e) {
|
|
e.preventDefault()
|
|
|
|
table.addCol(getCellIndex(rcTarget))
|
|
})
|
|
|
|
//Sharing
|
|
$('#shareBtn').on('click', function (e) {
|
|
e.preventDefault()
|
|
|
|
let username = document.getElementById("shareUsername").value
|
|
addShare(username)
|
|
})*/
|
|
})
|
|
|
|
/*function handleFileSelect(evt) {
|
|
let files = evt.target.files
|
|
table.importData(files[0], table)
|
|
}
|
|
|
|
function submitData() {
|
|
table.reloadData()
|
|
drawChart(getSettings(), table.data)
|
|
}
|
|
|
|
function save_data() {
|
|
table.reloadData()
|
|
let settings = getSettings()
|
|
$.ajax({
|
|
url: "php/save_data.php",
|
|
type: "post",
|
|
dataType: "text",
|
|
data: {code: graph_code, data: JSON.stringify(table.data), settings: JSON.stringify(settings), name:settings.title},
|
|
success: function (result) {
|
|
//alert("Saved successfully " + result)
|
|
}
|
|
})
|
|
}
|
|
|
|
function load_data() {
|
|
$.ajax({
|
|
url: "php/load_data.php",
|
|
type: "post",
|
|
dataType: "json",
|
|
data: {code: graph_code},
|
|
success: function (result) {
|
|
if (result.data == null) {
|
|
alert("Error: no data found")
|
|
return
|
|
}
|
|
table.data = JSON.parse(result.data)
|
|
table.updateTable()
|
|
if (result.settings == null) {
|
|
alert("Error: no graph settings found")
|
|
} else {
|
|
loadSettings(JSON.parse(result.settings))
|
|
}
|
|
drawChart(getSettings(), table.data)
|
|
}
|
|
})
|
|
}
|
|
|
|
function getCellIndex(cell) {
|
|
let parent = cell.parentElement
|
|
|
|
let children = Array.from(parent.children)
|
|
for (let i = 0; i < children.length; i++){
|
|
if (children[i] === cell) {
|
|
return i
|
|
}
|
|
}
|
|
}*/
|