New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Selection.data(function(d){...}) Not working #8
Comments
Thanks for the bug report. Are you sure on this one? My straight port of your first version worked fine for me: (ns testmatrix
(:require [strokes :refer [d3]]))
(strokes/bootstrap)
(def matrix [
[11975 5871 8916 2868]
[ 1951 10048 2060 6171]
[ 8010 16145 8090 8045]
[ 1013 990 940 6907]
])
(def tr (-> d3 (.select "body")
(.append "table")
(.selectAll "tr")
(.data matrix)
(.enter)
(.append "tr")))
(def td (-> tr
(.selectAll "td")
(.data (fn [d] d))
(.enter)
(.append "td")
(.text (fn [d] d)))) I can try the more complicated one and throw this up on a gist - can you provide me sample (for reference, the original js snippet equivalent to the cljs above is...) var matrix = [
[11975, 5871, 8916, 2868],
[ 1951, 10048, 2060, 6171],
[ 8010, 16145, 8090, 8045],
[ 1013, 990, 940, 6907]
];
var tr = d3.select("body").append("table").selectAll("tr")
.data(matrix)
.enter().append("tr");
var td = tr.selectAll("td")
.data(function(d) { return d; })
.enter().append("td")
.text(function(d) { return d; }); |
It could be that it occurs when using a map instead of a 2D array for the data. Maybe something to do with the nested anonymous functions in conjunction with (.map ...) ? Here are the examples of the input parameters
And here is a jsFiddle with the example I was trying to implement for the whole implementation |
My version below seems to be working, so closing for now. But please let me know if this is still a problem for you and will reopen if need be. Also a live version posted on s.trokes.org. (ns testmatrix
(:require [strokes :refer [d3]]))
(strokes/bootstrap)
(defn tablulate [data]
(let [columns (vec (keys (first data)))
table (-> d3 (.select "body") (.append "table"))
thead (-> table (.append "thead"))
tbody (-> table (.append "tbody"))]
(-> thead (.append "tr")
(.selectAll "th")
(.data columns)
(.enter)
(.append "th")
(.text name))
(-> tbody (.selectAll "tr")
(.data data)
(.enter)
(.append "tr")
(.selectAll "td")
(.data (fn [row]
(map (fn [c] {:column c :value (get row c)}) columns)))
(.enter)
(.append "td")
(.html #(:value %)))
table))
(tablulate [
{:name "Jill" :age 30}
{:name "Bob" :age 32}
{:name "George" :age 29}
{:name "Sally" :age 31}
]) |
using the usual seems to work fine
but if passing only a function to the (.data) call, the parameter seems to not properly be recognized
For an example try to implement this table
The text was updated successfully, but these errors were encountered: