Best method to update json file on server

This is my first post in here so hope you can help me 🙂

Im currently working on Hierarchical Edge Bundling ( http://bl.ocks.org/mbostock/7607999 ) It’s loaded in a JSON file through javascript( d3.json("readme-flare-importsFULL.json", function(error, classes) {} ).

I was wondering, whats the best method for me to make this dynamic so that anybody (even for someone who doesent know about computers) can add/edit/delete the file on a server if possible.

This is my JSON file: http://www.epdmi.co.nf/readme-flare-importsFULL.json

And this is my JS:

var diameter = 1100,
radius = diameter / 2,
innerRadius = radius - 300;

var cluster = d3.layout.cluster()
.size([360, innerRadius])
.sort(null)
.separation(function(a, b) { return (a.parent == b.parent ? 1 : 3 ) })
.value(function(d) { return d.size; });

var bundle = d3.layout.bundle();

var line = d3.svg.line.radial()
.interpolate("bundle")
.tension(0.100)
.radius(function(d) { return d.y; })
.angle(function(d) { return d.x / 180 * Math.PI; });

var svg = d3.select("body").append("svg")
.attr("width", diameter)
.attr("height", diameter)
.append("g")
.attr("transform", "translate(" + radius + "," + radius + ")");

var link = svg.append("g").selectAll(".link"),
node = svg.append("g").selectAll(".node");

d3.json("readme-flare-importsFULL.json", function(error, classes) {
if (error) throw error;

var nodes = cluster.nodes(packageHierarchy(classes)),
  links = packageImports(nodes);

link = link
  .data(bundle(links))
.enter().append("path")
  .each(function(d) { d.source = d[0], d.target = d[d.length - 1]; })
  .attr("class", "link")
  .attr("d", line);

  node = node
  .data(nodes.filter(function(n) { return !n.children; }))
.enter()
.append('a')
.attr("xlink:href", function(d){return d.url;})
.attr( 'target','_blank' )
.append("text")
.attr("class", "node")
  .attr("dy", ".31em")
  .attr("transform", function(d) { return "rotate(" + (d.x - 90) + ")translate(" + (d.y + 8) + ",0)" + (d.x < 180 ? "" : "rotate(180)"); })
  .style("text-anchor", function(d) { return d.x < 180 ? "start" : "end"; })
  .text(function(d) { return d.key; })
  .on("mouseover", mouseovered)
  .on("mouseout", mouseouted);
  });

 function mouseovered(d) {
 node
  .each(function(n) { n.target = n.source = false; });

 link
  .classed("link--target", function(l) { if (l.target === d) return l.source.source = true; })
  .classed("link--source", function(l) { if (l.source === d) return l.target.target = true; })
.filter(function(l) { return l.target === d || l.source === d; })
  .each(function() { this.parentNode.appendChild(this); });

 node
  .classed("node--target", function(n) { return n.target; })
  .classed("node--source", function(n) { return n.source; });
 }

 function mouseouted(d) {
 link
  .classed("link--target", false)
  .classed("link--source", false);

  node
  .classed("node--target", false)
  .classed("node--source", false);
  }

  d3.select(self.frameElement).style("height", diameter + "px");

  function packageHierarchy(classes) {
  var map = {};

  function find(name, data) {
  var node = map[name], i;
  if (!node) {
  node = map[name] = data || {name: name, children: []};
  if (name.length) {
    node.parent = find(name.substring(0, i = name.lastIndexOf(".")));
    node.parent.children.push(node);
    node.key = name.substring(i + 1);
  }
}
return node;
}

classes.forEach(function(d) {
find(d.name, d);
});

return map[""];
}

function packageImports(nodes) {
var map = {},
  imports = [];

nodes.forEach(function(d) {
map[d.name] = d;
});

nodes.forEach(function(d) {
if (d.imports) d.imports.forEach(function(i) {
  imports.push({source: map[d.name], target: map[i]});
});
});

return imports;

}

And this is where i load my javascript file in my HTML:

div id="test">
        <script type="text/javascript" src="heb.js"></script>
    </div>

I can use both C# and MSSQL if required, but if there is another easier method than using textboxes and databases, please let me know.

Mind that my JSON is complex and i need to add/edit several places at the same time. Thank You!


Source: json

Leave a Reply