Skip to content

Commit

Permalink
Fix updating of layer dimension labels. (alexlenail#5)
Browse files Browse the repository at this point in the history
* Fix updating of layer dimension labels.

When using the numeric range controls to alter the width of the
layers, the input labels weren't being updated in the diagram.

Address by creating the corresponding d3.js elements initially, but
then updating their dynamic properties on change.

Also fix a rendering glitch when superscripting dimensions with
repeated digits, e.g., "11".

* Limit scope, update text label elements only.
  • Loading branch information
sof authored and alexlenail committed May 24, 2018
1 parent 641b7ff commit f134a44
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,9 @@ <h4>Architecture:</h4>
var showBias = false;

var showLabels = true;
let sup = (s) => s.replace('0','⁰').replace('1','¹').replace('2','²').replace('3','³').replace('4','⁴').replace('5','⁵').replace('6','⁶').replace('7','⁷').replace('8','⁸').replace('9','⁹')
let sup_map = {'0': '⁰', '1': '¹', '2': '²', '3': '³', '4': '⁴', '5': '⁵', '6': '⁶', '7': '⁷', '8': '⁸', '9': '⁹'};
let sup = (s) => Array.prototype.map.call(s, (d) => (d in sup_map && sup_map[d]) || d).join('');

let textFn = (layer_index, layer_width) => ((layer_index === 0 ? "Input" : (layer_index === architecture.length-1 ? "Output" : "Hidden")) + " Layer ∈ ℝ" + sup(layer_width.toString()));
var nominal_text_size = 12;
var textWidth = 70;
Expand Down Expand Up @@ -365,16 +367,13 @@ <h4>Architecture:</h4>
.merge(node);

text = text.data(label);
text.exit().remove();
text = text.enter()
.append("text")
.text(function (d) { return (showLabels ? d.text : ""); })
.attr("class", "text")
if (text.empty())
text = text.enter().append("text").attr("class", "text");
text = text.text(function (d) { return (showLabels ? d.text : ""); })
.attr("dy", ".35em")
.style("font-size", nominal_text_size+"px")
.merge(text);


$('#count span:first').text(graph.nodes.length+" nodes, "+graph.links.length+" edges you don't need to draw yourself! ")
redistribute();
}
Expand Down

0 comments on commit f134a44

Please sign in to comment.