ndarville / d3-charts

Collection of small, reusable charts created with d3.js
7 stars 1 forks source link

Relative Budgets Chart #9

Open ndarville opened 11 years ago

ndarville commented 11 years ago

relative-budgets

Chart inspiration 1 Chart inspiration 2 Chart inspiration 3

http://upwithsteve.tumblr.com/post/45700087207/how-the-center-gets-defined-in-the-budget-debate

ndarville commented 11 years ago

Data Example

value,A,B,C,F,I,K,O,V,Ø
%,29,9,4,6,4,0,13,22,9
$,29,9,4,6,4,0,13,22,9
#,29,9,4,6,4,0,13,22,9
ndarville commented 11 years ago

To do:

Similar to bill votes chart:

Dissimilar:

ndarville commented 11 years ago

Labelling Text Labels

Symbols

ndarville commented 11 years ago
ndarville commented 11 years ago

How to render the text labels?

Where to place the legend: below or to the side?

ndarville commented 11 years ago
ndarville commented 11 years ago

This is the current code:

// Display text labels
var keys = Object.keys(jsonData);
g.selectAll(".name")
    .data(domain)
    .enter().append("text")
    .attr("class", "name")
    .attr({
        "text-anchor": function(d) {
            return (x(d) > (x.range()[0] + x.range()[1])/2) ? "end" : "start";
        },  // Revise
        "x": x,
        "y": 0 // Revise
    })
    .text(function(d, i) {  // fetch string
        return keys[i];
    });

And this is the data:

var jsonData = {
    "Ryan Budget": {
        "percentage": 0,
        "money": 0
    },
    "Senate Democrats": {
        "percentage": 2.3,
        "money": 975000000000
    },
    "Progressive Caucus": {
        "percentage": 14.1,
        "money": 3900000000000
    }
};

And this is what it ends up looking like:

screen shot 2013-10-15 at 22 35 42

It’s going to be a royal pain to handle this programmatically—not to imply that it won’t be a pain to handle manually either.

So perhaps the primary visualization should be with symbols and a legend, while I wait for an idea for how to go about the text labels, until someone hands a solution down to me a dream.

ndarville commented 11 years ago

Need to find out a way to define vertical positioning for the value and legend text:

screen shot 2013-10-18 at 01 59 14

These are the two values:

var xPos = (x.range()[0] + x.range()[1])/2 - 25;  // <-

///

g.selectAll(".name")
    .data(domain)
    .enter().append("text")
    .attr("class", "name")
    .attr({
        "text-anchor": function(d) {
            return (x(d) > (x.range()[0] + x.range()[1])/2) ? "end" : "start";
        },  // Revise
        "x": x,
        "y": 0 // Revise
    })
    .text(function(d, i) {  // fetch string
        return keys[i];
    });
ndarville commented 11 years ago

Better to group the chart into three <g> elements:

  1. Title + bar
  2. Value text
  3. Legend (symbol + text)
ndarville commented 11 years ago

Perhaps a good way of going about many or adjacent values is to either include an option that only displays values at the minimum, average, and maximum.