I am sure this is a silly problem, but I need to understand how to work two things out.
I have a large table with song/Film/Year/Composer/Lyricist/Singers. The link is Giitaayan Archive
Problem 1: The first graph shows each song as a line, and the title on hover works fine. I can modify it as showing the film, composer, singers etc.
Now I want to be able to show one or more of those PLUS the COUNT when I change the bins into films, composers, year, etc. For example, when I modify the graph to show each ārectā as a composer, I want to be able to show <composer: count> in title on hover. I can accomplish either count or composer, (or year/lyricist etc.), but not both. Would please someone modify the code attached and show me?
Problem 2: Is it possible to create a graph based on x = values in two rows? Like in the code below, x: āYearā, if I want to do x: āComposerā PLUS āSingersā, to show the same person who appears both as composer and singer? Is it possible?
Thanks a ton and sorry for posting problems with obvious solutions,
Rini
if the title reducer is given only as an output, it gets passed the whole list of data for each group (i.e. all the films by each composer), and can return the name (taken from the first element), and the length of the group (number of films).
Iām less sure about the second question. Grouping is exclusive (each film will belong to only one group). You should be able to create a new list where each song appears once for its composer and once for each of its singers, then group from that, but it means a bit of ādata wranglingā before you send it to plot. A good tool to do this is Array.flatMap(), for example:
Thanks so much, @Fil !
The first solution works perfectly (I will try the second problem soon). A follow-up on the first solution. Why canāt I stack the Composers in descending order, by having the biggest rect at the bottom, then thinning out as I go up?
Ordering for the stackY transform can be done by adding an order: "value" option. But it will stack from smaller to larger, and what you want is the opposite.
To reverse the order, you can use reverse: true, however if you call this from within the Plot.binX transform, reverse will be consumed by Plot.binX, and not passed up to Plot.stackY (which, in your case, doesnāt appear in the code because it is implicitly called by Plot.rectY). So, to make reverse reach the stack transform, we need to write a destructured options object.
I would also encourage you to test order: "sum" instead of order: "value"; it will make the ordering identical in each pile, making it easier to follow a composer across the years.
I have tried out the solution to my second issue in the original posting, and am now able to just map one singer, Lata, from the singers column. This is the last chart on the page.
I have a follow-up question/issue here. I am happy with the chart, but people without coding interests/skills who will be just looking at the graph will try to find the logic of binning and want information on a yearly basis. For instance, the years 1940-1945 share 3 columns. How, if I can at all, plot rects by year or (5 year or 10 years) and include the years in title on hover? Like, the most prolific singer in the chart, Lata, has columns with 99, 173 etc. songsā¦ What are the year(s) for 99 songs? For 173 songs etc.?
Apologize for all these questions. I am a latecomer to the world of computing; my PhD was in Comparative Literature.
One more newbie question: where can I read more about the significance of the three dots (ā¦) in so many of the code snippets that I see?
You can also use an explicit stack transform, rather than relying on the implicit one, so that you can pass the order and reverse options to the stack transform explicitly.
Thanks so much, @mbostock ! I now know two ways of doing the stack transform.
Do you have any suggestions for making it clear what year does each rect represent? This is form the last query that I asked:
āpeople without coding interests/skills who will be just looking at the graph will try to find the logic of binning and want information on a yearly basis. For instance, the years 1940-1945 share 3 columns. How, if I can at all, plot rects by year or (5 year or 10 years) and include the years in title on hover? Like, the most prolific singer in the chart, Lata, has columns with 99, 173 etc. songsā¦ What are the year(s) for 99 songs? For 173 songs etc.?ā
You could presumably do something like d3.extent(v, d => d.Year) to compute the years represented by each bin, but thatās not ideal because it could be a subset of the binās extent. Youād probably have to call d3.bin yourself if you want this, rather than relying on Plotās bin transform. Hereās the related issue in the Plot repo: