From a2c8168a21e2abf79f05bbb2e6d8ec61cb1ddca9 Mon Sep 17 00:00:00 2001 From: schneefux Date: Tue, 29 Mar 2016 20:52:48 +0200 Subject: fit network layout to data [WIP] --- index.js | 241 ++++++++++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 177 insertions(+), 64 deletions(-) diff --git a/index.js b/index.js index 8c6f14e..56b2e5d 100644 --- a/index.js +++ b/index.js @@ -1,20 +1,76 @@ -function drawNodes(nodes, netSpec, designSpec, env) { +/* custom d3 widgets */ + +// slider +function makeSlider(labelName, x, y, scale, cb) { + var brush = d3.svg.brush() + .x(scale) + .extent([0, 0]) + .on("brush", brushed); + + var label = svg.append("text") + .attr("x", x-5) + .attr("y", y) + .text(labelName); + + var brushg = svg.append("g") + .attr("transform", "translate(" + x + "," + (y+10) + ")"); + + brushg.append("g") + .attr("class", "x axis") + .call(d3.svg.axis() + .scale(scale) + .ticks(5) + .tickSize(1) + .tickFormat(function(d) { return Math.floor(d*100) + "%"; }) + .tickPadding(10) + .orient("bottom")); + + var slider = brushg.append("g") + .attr("class", "slider") + .call(brush); + + var handle = slider.append("circle") + .attr("r", 5) + .attr("cx", 0) + .attr("cy", 0) + .attr("stroke", "#000") + .attr("fill", "#DDD"); + + slider.call(brush); + + function brushed() { + var value = brush.extent()[0]; + + if (d3.event.sourceEvent) { // not a programmatic event + value = scale.invert(d3.mouse(this)[0]); + brush.extent([value, value]); + } + + handle.attr("cx", scale(value)); + cb(value); + } +} + + +/* network construction */ + +function drawNodes(nodes, layout, env) { var cnt = 0; var biasLayers = 0; - for (layer=0; layer