Skip to content
Snippets Groups Projects
Commit 3eab582d authored by Stahl, Merle's avatar Stahl, Merle
Browse files

Funktionsnamen angepasst

parent dd9db1d9
No related branches found
No related tags found
1 merge request!29Main
/** /**
* creates a new zoom behavior * creates a new zoom behavior
*/ */
var zoom = d3.zoom().on("zoom", handle_zoom); var zoom = d3.zoom().on("zoom", handle_transformation);
/** /**
* creates svg object and associated attributes * creates svg object and associated attributes
...@@ -48,7 +48,7 @@ var rect = svg.append("rect") ...@@ -48,7 +48,7 @@ var rect = svg.append("rect")
.attr("height", height) .attr("height", height)
.attr("width", width) .attr("width", width)
.style("fill", 'white') .style("fill", 'white')
.on('click', click_rect); .on('click', click_background);
/** /**
* creates svg object (legend) with text, circles and arrows * creates svg object (legend) with text, circles and arrows
...@@ -154,7 +154,8 @@ function failure(graph) { ...@@ -154,7 +154,8 @@ function failure(graph) {
* checks at a fixed interval whether the contents of the JSON file have changed * checks at a fixed interval whether the contents of the JSON file have changed
and reloads the program if necessary and reloads the program if necessary
*/ */
var intervalId=window.setInterval(function() { var intervalId=window.setInterval(check_if_json_changed, 5000)
function check_if_json_changed() {
d3.json("json_text.json").then(function(graph) { d3.json("json_text.json").then(function(graph) {
newjson_string=JSON.stringify(graph) newjson_string=JSON.stringify(graph)
var newjson = CryptoJS.MD5(newjson_string).toString(); var newjson = CryptoJS.MD5(newjson_string).toString();
...@@ -164,7 +165,7 @@ var intervalId=window.setInterval(function() { ...@@ -164,7 +165,7 @@ var intervalId=window.setInterval(function() {
window.location.reload() window.location.reload()
} }
}) })
},5000); }
/** /**
* calls update functions for links and nodes * calls update functions for links and nodes
...@@ -213,8 +214,8 @@ function update_nodes(nodes) { ...@@ -213,8 +214,8 @@ function update_nodes(nodes) {
.append("g") .append("g")
.attr("class", "node") .attr("class", "node")
.call(d3.drag() .call(d3.drag()
.on("start", start_drag) .on("start", start_drag_node)
.on("drag", dragged) .on("drag", dragged_node)
); );
node.append("circle") node.append("circle")
...@@ -277,7 +278,7 @@ function click_node(node) { ...@@ -277,7 +278,7 @@ function click_node(node) {
/** /**
* removes the highlights of the circles and their links * removes the highlights of the circles and their links
*/ */
function click_rect() { function click_background() {
fix_nodes(node); fix_nodes(node);
d3.selectAll(".circle").style("stroke", "none") d3.selectAll(".circle").style("stroke", "none")
d3.selectAll(".link") d3.selectAll(".link")
...@@ -389,7 +390,7 @@ function handle_tick() { ...@@ -389,7 +390,7 @@ function handle_tick() {
* initializes dragging of the node * initializes dragging of the node
* @param {object} node - node * @param {object} node - node
*/ */
function start_drag(node) { function start_drag_node(node) {
d3.select(this).raise(); d3.select(this).raise();
if (!d3.event.active) if (!d3.event.active)
simulation.alphaTarget(0.3).restart() simulation.alphaTarget(0.3).restart()
...@@ -402,7 +403,7 @@ function start_drag(node) { ...@@ -402,7 +403,7 @@ function start_drag(node) {
* applies dragging to the node * applies dragging to the node
* @param {object} node - node * @param {object} node - node
*/ */
function dragged(node) { function dragged_node(node) {
node.fx = d3.event.x; node.fx = d3.event.x;
node.fy = d3.event.y; node.fy = d3.event.y;
fix_nodes(node); fix_nodes(node);
...@@ -424,7 +425,7 @@ function fix_nodes(this_node) { ...@@ -424,7 +425,7 @@ function fix_nodes(this_node) {
/** /**
* applies the transformation (zooming or dragging) to the g element * applies the transformation (zooming or dragging) to the g element
*/ */
function handle_zoom() { function handle_transformation() {
d3.select('g').attr("transform", d3.event.transform); d3.select('g').attr("transform", d3.event.transform);
} }
......
/** /**
* creates a new zoom behavior * creates a new zoom behavior
*/ */
var zoom = d3.zoom().on("zoom", handle_zoom); var zoom = d3.zoom().on("zoom", handle_transformation);
/** /**
* creates svg object and associated attributes * creates svg object and associated attributes
...@@ -48,7 +48,7 @@ var rect = svg.append("rect") ...@@ -48,7 +48,7 @@ var rect = svg.append("rect")
.attr("height", height) .attr("height", height)
.attr("width", width) .attr("width", width)
.style("fill", 'white') .style("fill", 'white')
.on('click', click_rect); .on('click', click_background);
/** /**
* creates svg object (legend) with text, circles and arrows * creates svg object (legend) with text, circles and arrows
...@@ -171,7 +171,8 @@ function failure(graph) { ...@@ -171,7 +171,8 @@ function failure(graph) {
* checks at a fixed interval whether the contents of the JSON file have changed * checks at a fixed interval whether the contents of the JSON file have changed
and reloads the program if necessary and reloads the program if necessary
*/ */
var intervalId=window.setInterval(function() { var intervalId=window.setInterval(check_if_json_changed, 5000)
function check_if_json_changed() {
d3.json("json_text.json").then(function(graph) { d3.json("json_text.json").then(function(graph) {
newjson_string=JSON.stringify(graph) newjson_string=JSON.stringify(graph)
var newjson = CryptoJS.MD5(newjson_string).toString(); var newjson = CryptoJS.MD5(newjson_string).toString();
...@@ -181,7 +182,7 @@ var intervalId=window.setInterval(function() { ...@@ -181,7 +182,7 @@ var intervalId=window.setInterval(function() {
window.location.reload() window.location.reload()
} }
}) })
},5000); }
/** /**
* calls update functions for links, nodes and x-axis * calls update functions for links, nodes and x-axis
...@@ -190,7 +191,7 @@ var intervalId=window.setInterval(function() { ...@@ -190,7 +191,7 @@ var intervalId=window.setInterval(function() {
* @param {object} links - links * @param {object} links - links
*/ */
function update(links, nodes) { function update(links, nodes) {
updateXAxis(nodes); update_xaxis(nodes);
update_links(links); update_links(links);
update_nodes(nodes); update_nodes(nodes);
...@@ -208,7 +209,7 @@ function update(links, nodes) { ...@@ -208,7 +209,7 @@ function update(links, nodes) {
* initializes and shows x-axis * initializes and shows x-axis
* @param {object} nodes - nodes * @param {object} nodes - nodes
*/ */
function updateXAxis(nodes) { function update_xaxis(nodes) {
years = []; years = [];
for (i = 0; i < nodes.length; i++) { for (i = 0; i < nodes.length; i++) {
years.push(parseInt(parseInt(/\d{4}\s*$/.exec(nodes[i]["year"])))); years.push(parseInt(parseInt(/\d{4}\s*$/.exec(nodes[i]["year"]))));
...@@ -249,8 +250,8 @@ function update_nodes(nodes) { ...@@ -249,8 +250,8 @@ function update_nodes(nodes) {
.append("g") .append("g")
.attr("class", "node") .attr("class", "node")
.call(d3.drag() .call(d3.drag()
.on("start", start_drag) .on("start", start_drag_node)
.on("drag", dragged) .on("drag", dragged_node)
); );
node.append("circle") node.append("circle")
...@@ -314,7 +315,7 @@ function click_node(node) { ...@@ -314,7 +315,7 @@ function click_node(node) {
/** /**
* removes the highlights of the circles and their links * removes the highlights of the circles and their links
*/ */
function click_rect() { function click_background() {
fix_nodes(node); fix_nodes(node);
d3.selectAll(".circle").style("stroke", "none") d3.selectAll(".circle").style("stroke", "none")
d3.selectAll(".link") d3.selectAll(".link")
...@@ -426,11 +427,10 @@ function handle_tick() { ...@@ -426,11 +427,10 @@ function handle_tick() {
* initializes the dragging of the node * initializes the dragging of the node
* @param {object} node - node * @param {object} node - node
*/ */
function start_drag(node) { function start_drag_node(node) {
d3.select(this).raise(); d3.select(this).raise();
if (!d3.event.active) if (!d3.event.active)
simulation.alphaTarget(0.3).restart() simulation.alphaTarget(0.3).restart()
//node.fx = node.x;
node.fy = node.y; node.fy = node.y;
fix_nodes(node); fix_nodes(node);
} }
...@@ -439,8 +439,7 @@ function start_drag(node) { ...@@ -439,8 +439,7 @@ function start_drag(node) {
* applies the dragging to the node * applies the dragging to the node
* @param {object} node - node * @param {object} node - node
*/ */
function dragged(node) { function dragged_node(node) {
//node.fx = d3.event.x;
node.fy = d3.event.y; node.fy = d3.event.y;
fix_nodes(node); fix_nodes(node);
} }
...@@ -461,7 +460,7 @@ function fix_nodes(this_node) { ...@@ -461,7 +460,7 @@ function fix_nodes(this_node) {
/** /**
* applies the transformation (zooming or dragging) to the g element * applies the transformation (zooming or dragging) to the g element
*/ */
function handle_zoom() { function handle_transformation() {
d3.select('g').attr("transform", d3.event.transform); d3.select('g').attr("transform", d3.event.transform);
var new_xScale = d3.event.transform.rescaleX(xscale) var new_xScale = d3.event.transform.rescaleX(xscale)
gX.call(xAxis.scale(new_xScale)); gX.call(xAxis.scale(new_xScale));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment