(network: nn.Node[][])
| 536 | |
| 537 | // Draw network |
| 538 | function drawNetwork(network: nn.Node[][]): void { |
| 539 | let svg = d3.select("#svg"); |
| 540 | // Remove all svg elements. |
| 541 | svg.select("g.core").remove(); |
| 542 | // Remove all div elements. |
| 543 | d3.select("#network").selectAll("div.canvas").remove(); |
| 544 | d3.select("#network").selectAll("div.plus-minus-neurons").remove(); |
| 545 | |
| 546 | // Get the width of the svg container. |
| 547 | let padding = 3; |
| 548 | let co = d3.select(".column.output").node() as HTMLDivElement; |
| 549 | let cf = d3.select(".column.features").node() as HTMLDivElement; |
| 550 | let width = co.offsetLeft - cf.offsetLeft; |
| 551 | svg.attr("width", width); |
| 552 | |
| 553 | // Map of all node coordinates. |
| 554 | let node2coord: {[id: string]: {cx: number, cy: number}} = {}; |
| 555 | let container = svg.append("g") |
| 556 | .classed("core", true) |
| 557 | .attr("transform", `translate(${padding},${padding})`); |
| 558 | // Draw the network layer by layer. |
| 559 | let numLayers = network.length; |
| 560 | let featureWidth = 118; |
| 561 | let layerScale = d3.scale.ordinal<number, number>() |
| 562 | .domain(d3.range(1, numLayers - 1)) |
| 563 | .rangePoints([featureWidth, width - RECT_SIZE], 0.7); |
| 564 | let nodeIndexScale = (nodeIndex: number) => nodeIndex * (RECT_SIZE + 25); |
| 565 | |
| 566 | |
| 567 | let calloutThumb = d3.select(".callout.thumbnail").style("display", "none"); |
| 568 | let calloutWeights = d3.select(".callout.weights").style("display", "none"); |
| 569 | let idWithCallout = null; |
| 570 | let targetIdWithCallout = null; |
| 571 | |
| 572 | // Draw the input layer separately. |
| 573 | let cx = RECT_SIZE / 2 + 50; |
| 574 | let nodeIds = Object.keys(INPUTS); |
| 575 | let maxY = nodeIndexScale(nodeIds.length); |
| 576 | nodeIds.forEach((nodeId, i) => { |
| 577 | let cy = nodeIndexScale(i) + RECT_SIZE / 2; |
| 578 | node2coord[nodeId] = {cx, cy}; |
| 579 | drawNode(cx, cy, nodeId, true, container); |
| 580 | }); |
| 581 | |
| 582 | // Draw the intermediate layers. |
| 583 | for (let layerIdx = 1; layerIdx < numLayers - 1; layerIdx++) { |
| 584 | let numNodes = network[layerIdx].length; |
| 585 | let cx = layerScale(layerIdx) + RECT_SIZE / 2; |
| 586 | maxY = Math.max(maxY, nodeIndexScale(numNodes)); |
| 587 | addPlusMinusControl(layerScale(layerIdx), layerIdx); |
| 588 | for (let i = 0; i < numNodes; i++) { |
| 589 | let node = network[layerIdx][i]; |
| 590 | let cy = nodeIndexScale(i) + RECT_SIZE / 2; |
| 591 | node2coord[node.id] = {cx, cy}; |
| 592 | drawNode(cx, cy, node.id, false, container, node); |
| 593 | |
| 594 | // Show callout to thumbnails. |
| 595 | let numNodes = network[layerIdx].length; |
no test coverage detected
searching dependent graphs…