Mike
Can you transition between them?
(Unlike text, which you can only 'replace'.)
--
Rick Otten
rot...@windfish.net
O=='=+
console.log( "unicode = " + this.getAttributeNode("unicode").nodeValue );
You can't use selectors as the value of an attribute; selectors are
used in the select and selectAll methods. So, you can select the glyph
you want to inspect, and then use the attr method to retrieve the
value of the "d' attribute. For example:
d3.select("#foo").attr("d") // returns the string attribute value
It looks like you'd need to select the glyph based on the unicode
attribute. You could try doing something like this:
chart.selectAll("path")
.data("LED14".split(""))
.enter().append("svg:path")
.attr("d", function(d) { return d3.select("#font
glyph[unicode='" + d + "']").attr("d"); });
This assumes that you've embedded the font svg:svg element using the
id "font" elsewhere on the page.
(BTW, you were passing an invalid selector to selectAll. And, using a
string for the data is a bit magical, since it normally expects an
array.)
Mike
SVG_from_file[x] = d3.xml("sample_font_" + file_nums[x] + ".svg", "image/svg+xml", function(svg){
chart[x] = d3.select(".content")
.append("svg:svg")
.attr("class", "chart")
.attr("width", "100%")
.attr("height", 100)
.append("svg:g");
var cumulative_horiz_adv_x = 50;
d3.selectAll(svg.getElementsByTagName("defs"))
.selectAll("font")
.each(function(d, i) {
d3.selectAll(this)
.selectAll("glyph").each(function(d, i) {
// picking up each glyph - but ONLY from first font file
var glyph_name = this.getAttributeNode("glyph-name").nodeValue;var path = this.getAttributeNode("d").nodeValue;console.log( "horiz-adv-x = " + this.getAttributeNode("horiz-adv-x").nodeValue );chart[x].selectAll("path").data(glyph_name).enter().append("svg:path").attr("class", glyph_name).attr("d", path );});
});
});
for (var i = 0; i < n; i++) {
array[i] = d3.xml("path/to/file.xml", function(svg) {
… some code that refers to `i` …
});
}
The problem is your callback function (the second argument to xml) is
called asynchronously. Typically, they'll be called after the loop
terminates. And so, the value of `i` (or `x` in your code) in the
callback function will usually be `n`, because that's the value of `i`
when the loop terminates. To fix this, you'll need to capture a
reference to the current value of `i` in your callback, rather than
referring to the global value. You can do that with closures:
for (var i = 0; i < n; i++) {
array[i] = d3.xml("path/to/file.xml", callback(i));
}
Where:
function callback(i) {
return function(svg) {
… some code that refers to `i` …
};
}
Now, `callback` is a function which generates your callback, capturing
a reference to the current value of `i`.
Mike
svg_a[x]=svg;font_a[x]=d3.selectAll(svg_a[x].getElementsByTagName("defs"))
.selectAll("font").each(function(d, i) {
.......
}