book

Pokemon Viz

Compare attacks as a horizontal barchart[top]

Data [{"Name":"Squirtle","Type":"WATER","HP":44,"Attack":48,"Defense":65,"Special Attack":50,"Special Defense":64,"Speed":43},{"Name":"Mega Charizard Y","Type":"FLYING","HP":78,"Attack":104,"Defense":78,"Special Attack":159,"Special Defense":115,"Speed":100},{"Name":"Charmander","Type":"FIRE","HP":39,"Attack":52,"Defense":43,"Special Attack":60,"Special Defense":50,"Speed":65},{"Name":"Mega Venusaur","Type":"GRASS","HP":80,"Attack":100,"Defense":123,"Special Attack":122,"Special Defense":120,"Speed":80},{"Name":"Venusaur","Type":"GRASS","HP":80,"Attack":82,"Defense":83,"Special Attack":100,"Special Defense":100,"Speed":80},{"Name":"Ivysaur","Type":"GRASS","HP":60,"Attack":62,"Defense":63,"Special Attack":80,"Special Defense":80,"Speed":60},{"Name":"Bulbasaur","Type":"GRASS","HP":45,"Attack":49,"Defense":49,"Special Attack":65,"Special Defense":65,"Speed":45}]
Desired Viz
Actual Viz
<g transform="translate(0 0)">
    <rect
         width="48"
         height="20"
         style="fill:red;
                stroke-width:3;
                stroke:rgb(0,0,0)" />
</g>
<g transform="translate(0 20)">
    <rect
         width="104"
         height="20"
         style="fill:red;
                stroke-width:3;
                stroke:rgb(0,0,0)" />
</g>
<g transform="translate(0 40)">
    <rect
         width="52"
         height="20"
         style="fill:red;
                stroke-width:3;
                stroke:rgb(0,0,0)" />
</g>
<g transform="translate(0 60)">
    <rect
         width="100"
         height="20"
         style="fill:red;
                stroke-width:3;
                stroke:rgb(0,0,0)" />
</g>
<g transform="translate(0 80)">
    <rect
         width="82"
         height="20"
         style="fill:red;
                stroke-width:3;
                stroke:rgb(0,0,0)" />
</g>
<g transform="translate(0 100)">
    <rect
         width="62"
         height="20"
         style="fill:red;
                stroke-width:3;
                stroke:rgb(0,0,0)" />
</g>
<g transform="translate(0 120)">
    <rect
         width="49"
         height="20"
         style="fill:red;
                stroke-width:3;
                stroke:rgb(0,0,0)" />
</g>
<g transform="translate(0 0)">
    <rect
         width="50"
         height="20"
         style="fill:red;
                stroke-width:3;
                stroke:rgb(0,0,0)" />
</g>
<g transform="translate(0 20)">
    <rect
         width="70"
         height="20"
         style="fill:red;
                stroke-width:3;
                stroke:rgb(0,0,0)" />
</g>
<g transform="translate(0 40)">
    <rect
         width="90"
         height="20"
         style="fill:red;
                stroke-width:3;
                stroke:rgb(0,0,0)" />
</g>
<g transform="translate(0 60)">
    <rect
         width="110"
         height="20"
         style="fill:red;
                stroke-width:3;
                stroke:rgb(0,0,0)" />
</g>
<g transform="translate(0 80)">
    <rect
         width="130"
         height="20"
         style="fill:red;
                stroke-width:3;
                stroke:rgb(0,0,0)" />
</g>
<g transform="translate(0 100)">
    <rect
         width="150"
         height="20"
         style="fill:red;
                stroke-width:3;
                stroke:rgb(0,0,0)" />
</g>
<g transform="translate(0 120)">
    <rect
         width="170"
         height="20"
         style="fill:red;
                stroke-width:3;
                stroke:rgb(0,0,0)" />
</g>
Solution: SVG Template
<g transform="translate(0 ${d.y})">
    <rect
         width="${d.width}"
         height="20"
         style="fill:${d.color};
                stroke-width:3;
                stroke:rgb(0,0,0)" />
</g>
Solution: Javascript
function computeX(d, i) {
    return 0
}

function computeWidth(d, i) {
    return i * 20 + 50
}

function computeY(d, i) {
    return i * 20
}

function computeColor(d, i) {
    return 'red'
}

var viz = _.map(data, function(d, i){
            return {
                x: computeX(d, i),
                y: computeY(d, i),
                width: computeWidth(d, i),
                color: computeColor(d, i)
            }
         })
console.log(viz)

var result = _.map(viz, function(d){
         // invoke the compiled template function on each viz data
         return template({d: d})
     })
return result.join('\n')
Console
[{"x":0,"y":0,"width":50,"color":"red"},{"x":0,"y":20,"width":70,"color":"red"},{"x":0,"y":40,"width":90,"color":"red"},{"x":0,"y":60,"width":110,"color":"red"},{"x":0,"y":80,"width":130,"color":"red"},{"x":0,"y":100,"width":150,"color":"red"},{"x":0,"y":120,"width":170,"color":"red"}]

Place a label over each bar[top]

Data [{"Name":"Squirtle","Type":"WATER","HP":44,"Attack":48,"Defense":65,"Special Attack":50,"Special Defense":64,"Speed":43},{"Name":"Mega Charizard Y","Type":"FLYING","HP":78,"Attack":104,"Defense":78,"Special Attack":159,"Special Defense":115,"Speed":100},{"Name":"Charmander","Type":"FIRE","HP":39,"Attack":52,"Defense":43,"Special Attack":60,"Special Defense":50,"Speed":65},{"Name":"Mega Venusaur","Type":"GRASS","HP":80,"Attack":100,"Defense":123,"Special Attack":122,"Special Defense":120,"Speed":80},{"Name":"Venusaur","Type":"GRASS","HP":80,"Attack":82,"Defense":83,"Special Attack":100,"Special Defense":100,"Speed":80},{"Name":"Ivysaur","Type":"GRASS","HP":60,"Attack":62,"Defense":63,"Special Attack":80,"Special Defense":80,"Speed":60},{"Name":"Bulbasaur","Type":"GRASS","HP":45,"Attack":49,"Defense":49,"Special Attack":65,"Special Defense":65,"Speed":45}]
Desired Viz Squirtle Mega Charizard Y Charmander Mega Venusaur Venusaur Ivysaur Bulbasaur
Actual Viz
<g transform="translate(0 0)">
    <rect         
         width="48"
         height="20"
         style="fill:red;
                stroke-width:3;
                stroke:rgb(0,0,0)" />
    <text transform="translate(0 15)">
        Squirtle
    </text>
</g>
<g transform="translate(0 20)">
    <rect         
         width="104"
         height="20"
         style="fill:red;
                stroke-width:3;
                stroke:rgb(0,0,0)" />
    <text transform="translate(0 15)">
        Mega Charizard Y
    </text>
</g>
<g transform="translate(0 40)">
    <rect         
         width="52"
         height="20"
         style="fill:red;
                stroke-width:3;
                stroke:rgb(0,0,0)" />
    <text transform="translate(0 15)">
        Charmander
    </text>
</g>
<g transform="translate(0 60)">
    <rect         
         width="100"
         height="20"
         style="fill:red;
                stroke-width:3;
                stroke:rgb(0,0,0)" />
    <text transform="translate(0 15)">
        Mega Venusaur
    </text>
</g>
<g transform="translate(0 80)">
    <rect         
         width="82"
         height="20"
         style="fill:red;
                stroke-width:3;
                stroke:rgb(0,0,0)" />
    <text transform="translate(0 15)">
        Venusaur
    </text>
</g>
<g transform="translate(0 100)">
    <rect         
         width="62"
         height="20"
         style="fill:red;
                stroke-width:3;
                stroke:rgb(0,0,0)" />
    <text transform="translate(0 15)">
        Ivysaur
    </text>
</g>
<g transform="translate(0 120)">
    <rect         
         width="49"
         height="20"
         style="fill:red;
                stroke-width:3;
                stroke:rgb(0,0,0)" />
    <text transform="translate(0 15)">
        Bulbasaur
    </text>
</g>
<g transform="translate(0 0)">
    <rect         
         width="50"
         height="20"
         style="fill:red;
                stroke-width:3;
                stroke:rgb(0,0,0)" />
</g>
<g transform="translate(0 20)">
    <rect         
         width="70"
         height="20"
         style="fill:red;
                stroke-width:3;
                stroke:rgb(0,0,0)" />
</g>
<g transform="translate(0 40)">
    <rect         
         width="90"
         height="20"
         style="fill:red;
                stroke-width:3;
                stroke:rgb(0,0,0)" />
</g>
<g transform="translate(0 60)">
    <rect         
         width="110"
         height="20"
         style="fill:red;
                stroke-width:3;
                stroke:rgb(0,0,0)" />
</g>
<g transform="translate(0 80)">
    <rect         
         width="130"
         height="20"
         style="fill:red;
                stroke-width:3;
                stroke:rgb(0,0,0)" />
</g>
<g transform="translate(0 100)">
    <rect         
         width="150"
         height="20"
         style="fill:red;
                stroke-width:3;
                stroke:rgb(0,0,0)" />
</g>
<g transform="translate(0 120)">
    <rect         
         width="170"
         height="20"
         style="fill:red;
                stroke-width:3;
                stroke:rgb(0,0,0)" />
</g>
Solution: SVG Template
<g transform="translate(0 ${d.y})">
    <rect         
         width="${d.width}"
         height="20"
         style="fill:${d.color};
                stroke-width:3;
                stroke:rgb(0,0,0)" />
</g>
Solution: Javascript
function computeX(d, i) {
    return 0
}

function computeWidth(d, i) {
    return i * 20 + 50
}

function computeY(d, i) {
    return i * 20
}

function computeColor(d, i) {
    return 'red'
}

var viz = _.map(data, function(d, i){
            return {
                x: computeX(d, i),
                y: computeY(d, i),
                width: computeWidth(d, i),
                color: computeColor(d, i)
            }
         })
console.log(viz)

var result = _.map(viz, function(d){
         // invoke the compiled template function on each viz data
         return template({d: d})
     })
return result.join('\n')
Console
[{"x":0,"y":0,"width":50,"color":"red"},{"x":0,"y":20,"width":70,"color":"red"},{"x":0,"y":40,"width":90,"color":"red"},{"x":0,"y":60,"width":110,"color":"red"},{"x":0,"y":80,"width":130,"color":"red"},{"x":0,"y":100,"width":150,"color":"red"},{"x":0,"y":120,"width":170,"color":"red"}]

Place a label to the left of each bar[top]

Data [{"Name":"Squirtle","Type":"WATER","HP":44,"Attack":48,"Defense":65,"Special Attack":50,"Special Defense":64,"Speed":43},{"Name":"Mega Charizard Y","Type":"FLYING","HP":78,"Attack":104,"Defense":78,"Special Attack":159,"Special Defense":115,"Speed":100},{"Name":"Charmander","Type":"FIRE","HP":39,"Attack":52,"Defense":43,"Special Attack":60,"Special Defense":50,"Speed":65},{"Name":"Mega Venusaur","Type":"GRASS","HP":80,"Attack":100,"Defense":123,"Special Attack":122,"Special Defense":120,"Speed":80},{"Name":"Venusaur","Type":"GRASS","HP":80,"Attack":82,"Defense":83,"Special Attack":100,"Special Defense":100,"Speed":80},{"Name":"Ivysaur","Type":"GRASS","HP":60,"Attack":62,"Defense":63,"Special Attack":80,"Special Defense":80,"Speed":60},{"Name":"Bulbasaur","Type":"GRASS","HP":45,"Attack":49,"Defense":49,"Special Attack":65,"Special Defense":65,"Speed":45}]
Desired Viz Squirtle Mega Charizard Y Charmander Mega Venusaur Venusaur Ivysaur Bulbasaur
Actual Viz
<g transform="translate(0 0)">
    <rect
         x="120"
         width="48"
         height="20"
         style="fill:red;
                stroke-width:3;
                stroke:rgb(0,0,0)" />
    <text transform="translate(0 15)">
        Squirtle
    </text>
</g>
<g transform="translate(0 20)">
    <rect
         x="120"
         width="104"
         height="20"
         style="fill:red;
                stroke-width:3;
                stroke:rgb(0,0,0)" />
    <text transform="translate(0 15)">
        Mega Charizard Y
    </text>
</g>
<g transform="translate(0 40)">
    <rect
         x="120"
         width="52"
         height="20"
         style="fill:red;
                stroke-width:3;
                stroke:rgb(0,0,0)" />
    <text transform="translate(0 15)">
        Charmander
    </text>
</g>
<g transform="translate(0 60)">
    <rect
         x="120"
         width="100"
         height="20"
         style="fill:red;
                stroke-width:3;
                stroke:rgb(0,0,0)" />
    <text transform="translate(0 15)">
        Mega Venusaur
    </text>
</g>
<g transform="translate(0 80)">
    <rect
         x="120"
         width="82"
         height="20"
         style="fill:red;
                stroke-width:3;
                stroke:rgb(0,0,0)" />
    <text transform="translate(0 15)">
        Venusaur
    </text>
</g>
<g transform="translate(0 100)">
    <rect
         x="120"
         width="62"
         height="20"
         style="fill:red;
                stroke-width:3;
                stroke:rgb(0,0,0)" />
    <text transform="translate(0 15)">
        Ivysaur
    </text>
</g>
<g transform="translate(0 120)">
    <rect
         x="120"
         width="49"
         height="20"
         style="fill:red;
                stroke-width:3;
                stroke:rgb(0,0,0)" />
    <text transform="translate(0 15)">
        Bulbasaur
    </text>
</g>
<g transform="translate(0 0)">
    <rect         
         width="50"
         height="20"
         style="fill:red;
                stroke-width:3;
                stroke:rgb(0,0,0)" />
</g>
<g transform="translate(0 20)">
    <rect         
         width="70"
         height="20"
         style="fill:red;
                stroke-width:3;
                stroke:rgb(0,0,0)" />
</g>
<g transform="translate(0 40)">
    <rect         
         width="90"
         height="20"
         style="fill:red;
                stroke-width:3;
                stroke:rgb(0,0,0)" />
</g>
<g transform="translate(0 60)">
    <rect         
         width="110"
         height="20"
         style="fill:red;
                stroke-width:3;
                stroke:rgb(0,0,0)" />
</g>
<g transform="translate(0 80)">
    <rect         
         width="130"
         height="20"
         style="fill:red;
                stroke-width:3;
                stroke:rgb(0,0,0)" />
</g>
<g transform="translate(0 100)">
    <rect         
         width="150"
         height="20"
         style="fill:red;
                stroke-width:3;
                stroke:rgb(0,0,0)" />
</g>
<g transform="translate(0 120)">
    <rect         
         width="170"
         height="20"
         style="fill:red;
                stroke-width:3;
                stroke:rgb(0,0,0)" />
</g>
Solution: SVG Template
<g transform="translate(0 ${d.y})">
    <rect         
         width="${d.width}"
         height="20"
         style="fill:${d.color};
                stroke-width:3;
                stroke:rgb(0,0,0)" />
</g>
Solution: Javascript
function computeX(d, i) {
    return 0
}

function computeWidth(d, i) {
    return i * 20 + 50
}

function computeY(d, i) {
    return i * 20
}

function computeColor(d, i) {
    return 'red'
}

var viz = _.map(data, function(d, i){
            return {
                x: computeX(d, i),
                y: computeY(d, i),
                width: computeWidth(d, i),
                color: computeColor(d, i)
            }
         })
console.log(viz)

var result = _.map(viz, function(d){
         // invoke the compiled template function on each viz data
         return template({d: d})
     })
return result.join('\n')
Console
[{"x":0,"y":0,"width":50,"color":"red"},{"x":0,"y":20,"width":70,"color":"red"},{"x":0,"y":40,"width":90,"color":"red"},{"x":0,"y":60,"width":110,"color":"red"},{"x":0,"y":80,"width":130,"color":"red"},{"x":0,"y":100,"width":150,"color":"red"},{"x":0,"y":120,"width":170,"color":"red"}]

Compare attack and defense points side by side[top]

Data [{"Name":"Squirtle","Type":"WATER","HP":44,"Attack":48,"Defense":65,"Special Attack":50,"Special Defense":64,"Speed":43},{"Name":"Mega Charizard Y","Type":"FLYING","HP":78,"Attack":104,"Defense":78,"Special Attack":159,"Special Defense":115,"Speed":100},{"Name":"Charmander","Type":"FIRE","HP":39,"Attack":52,"Defense":43,"Special Attack":60,"Special Defense":50,"Speed":65},{"Name":"Mega Venusaur","Type":"GRASS","HP":80,"Attack":100,"Defense":123,"Special Attack":122,"Special Defense":120,"Speed":80},{"Name":"Venusaur","Type":"GRASS","HP":80,"Attack":82,"Defense":83,"Special Attack":100,"Special Defense":100,"Speed":80},{"Name":"Ivysaur","Type":"GRASS","HP":60,"Attack":62,"Defense":63,"Special Attack":80,"Special Defense":80,"Speed":60},{"Name":"Bulbasaur","Type":"GRASS","HP":45,"Attack":49,"Defense":49,"Special Attack":65,"Special Defense":65,"Speed":45}]
Desired Viz Squirtle Mega Charizard Y Charmander Mega Venusaur Venusaur Ivysaur Bulbasaur
Actual Viz
<g transform="translate(120 0)">
    <rect
         x="-48"
         width="48"
         height="20"
         style="fill:red;
                stroke-width:1;
                stroke:rgb(0,0,0)" />
    <rect
         x="0"
         width="65"
         height="20"
         style="fill:blue;
                stroke-width:1;
                stroke:rgb(0,0,0)" />

    <text transform="translate(0 15)">
        Squirtle
    </text>
</g>
<g transform="translate(120 20)">
    <rect
         x="-104"
         width="104"
         height="20"
         style="fill:red;
                stroke-width:1;
                stroke:rgb(0,0,0)" />
    <rect
         x="0"
         width="78"
         height="20"
         style="fill:blue;
                stroke-width:1;
                stroke:rgb(0,0,0)" />

    <text transform="translate(0 15)">
        Mega Charizard Y
    </text>
</g>
<g transform="translate(120 40)">
    <rect
         x="-52"
         width="52"
         height="20"
         style="fill:red;
                stroke-width:1;
                stroke:rgb(0,0,0)" />
    <rect
         x="0"
         width="43"
         height="20"
         style="fill:blue;
                stroke-width:1;
                stroke:rgb(0,0,0)" />

    <text transform="translate(0 15)">
        Charmander
    </text>
</g>
<g transform="translate(120 60)">
    <rect
         x="-100"
         width="100"
         height="20"
         style="fill:red;
                stroke-width:1;
                stroke:rgb(0,0,0)" />
    <rect
         x="0"
         width="123"
         height="20"
         style="fill:blue;
                stroke-width:1;
                stroke:rgb(0,0,0)" />

    <text transform="translate(0 15)">
        Mega Venusaur
    </text>
</g>
<g transform="translate(120 80)">
    <rect
         x="-82"
         width="82"
         height="20"
         style="fill:red;
                stroke-width:1;
                stroke:rgb(0,0,0)" />
    <rect
         x="0"
         width="83"
         height="20"
         style="fill:blue;
                stroke-width:1;
                stroke:rgb(0,0,0)" />

    <text transform="translate(0 15)">
        Venusaur
    </text>
</g>
<g transform="translate(120 100)">
    <rect
         x="-62"
         width="62"
         height="20"
         style="fill:red;
                stroke-width:1;
                stroke:rgb(0,0,0)" />
    <rect
         x="0"
         width="63"
         height="20"
         style="fill:blue;
                stroke-width:1;
                stroke:rgb(0,0,0)" />

    <text transform="translate(0 15)">
        Ivysaur
    </text>
</g>
<g transform="translate(120 120)">
    <rect
         x="-49"
         width="49"
         height="20"
         style="fill:red;
                stroke-width:1;
                stroke:rgb(0,0,0)" />
    <rect
         x="0"
         width="49"
         height="20"
         style="fill:blue;
                stroke-width:1;
                stroke:rgb(0,0,0)" />

    <text transform="translate(0 15)">
        Bulbasaur
    </text>
</g>
<g transform="translate(120 0)">
    <rect
         x="-10"
         width="10"
         height="20"
         style="fill:red;
                stroke-width:1;
                stroke:rgb(0,0,0)" />
</g>
<g transform="translate(120 20)">
    <rect
         x="-20"
         width="20"
         height="20"
         style="fill:red;
                stroke-width:1;
                stroke:rgb(0,0,0)" />
</g>
<g transform="translate(120 40)">
    <rect
         x="-30"
         width="30"
         height="20"
         style="fill:red;
                stroke-width:1;
                stroke:rgb(0,0,0)" />
</g>
<g transform="translate(120 60)">
    <rect
         x="-40"
         width="40"
         height="20"
         style="fill:red;
                stroke-width:1;
                stroke:rgb(0,0,0)" />
</g>
<g transform="translate(120 80)">
    <rect
         x="-50"
         width="50"
         height="20"
         style="fill:red;
                stroke-width:1;
                stroke:rgb(0,0,0)" />
</g>
<g transform="translate(120 100)">
    <rect
         x="-60"
         width="60"
         height="20"
         style="fill:red;
                stroke-width:1;
                stroke:rgb(0,0,0)" />
</g>
<g transform="translate(120 120)">
    <rect
         x="-70"
         width="70"
         height="20"
         style="fill:red;
                stroke-width:1;
                stroke:rgb(0,0,0)" />
</g>
Solution: SVG Template
<g transform="translate(120 ${d.y})">
    <rect
         x="-${d.width}"
         width="${d.width}"
         height="20"
         style="fill:${d.color};
                stroke-width:1;
                stroke:rgb(0,0,0)" />
</g>
Solution: Javascript
function computeX(d, i) {
    return 0
}

function computeWidth(d, i) {
    return i * 10 + 10
}

function computeY(d, i) {
    return i * 20
}

function computeColor(d, i) {
    return 'red'
}

var viz = _.map(data, function(d, i){
            return {
                x: computeX(d, i),
                y: computeY(d, i),
                width: computeWidth(d, i),
                color: computeColor(d, i)
            }
         })
console.log(viz)

var result = _.map(viz, function(d){
         // invoke the compiled template function on each viz data
         return template({d: d})
     })
return result.join('\n')
Console
[{"x":0,"y":0,"width":10,"color":"red"},{"x":0,"y":20,"width":20,"color":"red"},{"x":0,"y":40,"width":30,"color":"red"},{"x":0,"y":60,"width":40,"color":"red"},{"x":0,"y":80,"width":50,"color":"red"},{"x":0,"y":100,"width":60,"color":"red"},{"x":0,"y":120,"width":70,"color":"red"}]

Compare attack points and represent defense points using bar heights[top]

Data [{"Name":"Squirtle","Type":"WATER","HP":44,"Attack":48,"Defense":65,"Special Attack":50,"Special Defense":64,"Speed":43},{"Name":"Mega Charizard Y","Type":"FLYING","HP":78,"Attack":104,"Defense":78,"Special Attack":159,"Special Defense":115,"Speed":100},{"Name":"Charmander","Type":"FIRE","HP":39,"Attack":52,"Defense":43,"Special Attack":60,"Special Defense":50,"Speed":65},{"Name":"Mega Venusaur","Type":"GRASS","HP":80,"Attack":100,"Defense":123,"Special Attack":122,"Special Defense":120,"Speed":80},{"Name":"Venusaur","Type":"GRASS","HP":80,"Attack":82,"Defense":83,"Special Attack":100,"Special Defense":100,"Speed":80},{"Name":"Ivysaur","Type":"GRASS","HP":60,"Attack":62,"Defense":63,"Special Attack":80,"Special Defense":80,"Speed":60},{"Name":"Bulbasaur","Type":"GRASS","HP":45,"Attack":49,"Defense":49,"Special Attack":65,"Special Defense":65,"Speed":45}]
Desired Viz Squirtle Mega Charizard Y Charmander Mega Venusaur Venusaur Ivysaur Bulbasaur
Actual Viz
<g transform="translate(0 0)">
    <rect width="48"
         height="65"
         style="fill:red;
                stroke-width:1;
                stroke:rgb(0,0,0)" />
    <text transform="translate(0 15)">
        Squirtle
    </text>
</g>
<g transform="translate(0 65)">
    <rect width="104"
         height="78"
         style="fill:red;
                stroke-width:1;
                stroke:rgb(0,0,0)" />
    <text transform="translate(0 15)">
        Mega Charizard Y
    </text>
</g>
<g transform="translate(0 143)">
    <rect width="52"
         height="43"
         style="fill:red;
                stroke-width:1;
                stroke:rgb(0,0,0)" />
    <text transform="translate(0 15)">
        Charmander
    </text>
</g>
<g transform="translate(0 186)">
    <rect width="100"
         height="123"
         style="fill:red;
                stroke-width:1;
                stroke:rgb(0,0,0)" />
    <text transform="translate(0 15)">
        Mega Venusaur
    </text>
</g>
<g transform="translate(0 309)">
    <rect width="82"
         height="83"
         style="fill:red;
                stroke-width:1;
                stroke:rgb(0,0,0)" />
    <text transform="translate(0 15)">
        Venusaur
    </text>
</g>
<g transform="translate(0 392)">
    <rect width="62"
         height="63"
         style="fill:red;
                stroke-width:1;
                stroke:rgb(0,0,0)" />
    <text transform="translate(0 15)">
        Ivysaur
    </text>
</g>
<g transform="translate(0 455)">
    <rect width="49"
         height="49"
         style="fill:red;
                stroke-width:1;
                stroke:rgb(0,0,0)" />
    <text transform="translate(0 15)">
        Bulbasaur
    </text>
</g>
<g transform="translate(0 0)">
    <rect width="10"
         height="10"
         style="fill:red;
                stroke-width:1;
                stroke:rgb(0,0,0)" />
</g>
<g transform="translate(0 20)">
    <rect width="20"
         height="20"
         style="fill:red;
                stroke-width:1;
                stroke:rgb(0,0,0)" />
</g>
<g transform="translate(0 40)">
    <rect width="30"
         height="30"
         style="fill:red;
                stroke-width:1;
                stroke:rgb(0,0,0)" />
</g>
<g transform="translate(0 60)">
    <rect width="40"
         height="40"
         style="fill:red;
                stroke-width:1;
                stroke:rgb(0,0,0)" />
</g>
<g transform="translate(0 80)">
    <rect width="50"
         height="50"
         style="fill:red;
                stroke-width:1;
                stroke:rgb(0,0,0)" />
</g>
<g transform="translate(0 100)">
    <rect width="60"
         height="60"
         style="fill:red;
                stroke-width:1;
                stroke:rgb(0,0,0)" />
</g>
<g transform="translate(0 120)">
    <rect width="70"
         height="70"
         style="fill:red;
                stroke-width:1;
                stroke:rgb(0,0,0)" />
</g>
Solution: SVG Template
<g transform="translate(0 ${d.y})">
    <rect width="${d.width}"
         height="${d.height}"
         style="fill:${d.color};
                stroke-width:1;
                stroke:rgb(0,0,0)" />
</g>
Solution: Javascript
function computeX(d, i) {
    return 0
}

function computeWidth(d, i) {
    return i * 10 + 10
}

function computeHeight(d, i) {
    return i * 10 + 10
}

// HINT: figure out a way to compute a Y offset on each call to return the sum of of the heights
// of all previous bars
function computeY(d, i) {
    return i * 20
}

function computeColor(d, i) {
    return 'red'
}

var viz = _.map(data, function(d, i){
            return {
                x: computeX(d, i),
                y: computeY(d, i),
                height: computeHeight(d, i),
                width: computeWidth(d, i),
                color: computeColor(d, i)
            }
         })
console.log(viz)

var result = _.map(viz, function(d){
         // invoke the compiled template function on each viz data
         return template({d: d})
     })
return result.join('\n')
Console
[{"x":0,"y":0,"height":10,"width":10,"color":"red"},{"x":0,"y":20,"height":20,"width":20,"color":"red"},{"x":0,"y":40,"height":30,"width":30,"color":"red"},{"x":0,"y":60,"height":40,"width":40,"color":"red"},{"x":0,"y":80,"height":50,"width":50,"color":"red"},{"x":0,"y":100,"height":60,"width":60,"color":"red"},{"x":0,"y":120,"height":70,"width":70,"color":"red"}]

Compare attack points and represent defense points using colors[top]

Data [{"Name":"Squirtle","Type":"WATER","HP":44,"Attack":48,"Defense":65,"Special Attack":50,"Special Defense":64,"Speed":43},{"Name":"Mega Charizard Y","Type":"FLYING","HP":78,"Attack":104,"Defense":78,"Special Attack":159,"Special Defense":115,"Speed":100},{"Name":"Charmander","Type":"FIRE","HP":39,"Attack":52,"Defense":43,"Special Attack":60,"Special Defense":50,"Speed":65},{"Name":"Mega Venusaur","Type":"GRASS","HP":80,"Attack":100,"Defense":123,"Special Attack":122,"Special Defense":120,"Speed":80},{"Name":"Venusaur","Type":"GRASS","HP":80,"Attack":82,"Defense":83,"Special Attack":100,"Special Defense":100,"Speed":80},{"Name":"Ivysaur","Type":"GRASS","HP":60,"Attack":62,"Defense":63,"Special Attack":80,"Special Defense":80,"Speed":60},{"Name":"Bulbasaur","Type":"GRASS","HP":45,"Attack":49,"Defense":49,"Special Attack":65,"Special Defense":65,"Speed":45}]
Desired Viz Squirtle Mega Charizard Y Charmander Mega Venusaur Venusaur Ivysaur Bulbasaur
Actual Viz
<g transform="translate(0 0)">
    <rect width="48"
         height="20"
         style="fill:rgb(135,0,0);
                stroke-width:1;
                stroke:rgb(0,0,0)" />    

    <text transform="translate(0 15)">
        Squirtle
    </text>
</g>
<g transform="translate(0 20)">
    <rect width="104"
         height="20"
         style="fill:rgb(162,0,0);
                stroke-width:1;
                stroke:rgb(0,0,0)" />    

    <text transform="translate(0 15)">
        Mega Charizard Y
    </text>
</g>
<g transform="translate(0 40)">
    <rect width="52"
         height="20"
         style="fill:rgb(89,0,0);
                stroke-width:1;
                stroke:rgb(0,0,0)" />    

    <text transform="translate(0 15)">
        Charmander
    </text>
</g>
<g transform="translate(0 60)">
    <rect width="100"
         height="20"
         style="fill:rgb(255,0,0);
                stroke-width:1;
                stroke:rgb(0,0,0)" />    

    <text transform="translate(0 15)">
        Mega Venusaur
    </text>
</g>
<g transform="translate(0 80)">
    <rect width="82"
         height="20"
         style="fill:rgb(172,0,0);
                stroke-width:1;
                stroke:rgb(0,0,0)" />    

    <text transform="translate(0 15)">
        Venusaur
    </text>
</g>
<g transform="translate(0 100)">
    <rect width="62"
         height="20"
         style="fill:rgb(131,0,0);
                stroke-width:1;
                stroke:rgb(0,0,0)" />    

    <text transform="translate(0 15)">
        Ivysaur
    </text>
</g>
<g transform="translate(0 120)">
    <rect width="49"
         height="20"
         style="fill:rgb(102,0,0);
                stroke-width:1;
                stroke:rgb(0,0,0)" />    

    <text transform="translate(0 15)">
        Bulbasaur
    </text>
</g>
<g transform="translate(0 0)">
    <rect width="48"
         height="20"
         style="fill:rgb(200,0,0);
                stroke-width:1;
                stroke:rgb(0,0,0)" />    
</g>
<g transform="translate(0 20)">
    <rect width="104"
         height="20"
         style="fill:rgb(200,0,0);
                stroke-width:1;
                stroke:rgb(0,0,0)" />    
</g>
<g transform="translate(0 40)">
    <rect width="52"
         height="20"
         style="fill:rgb(200,0,0);
                stroke-width:1;
                stroke:rgb(0,0,0)" />    
</g>
<g transform="translate(0 60)">
    <rect width="100"
         height="20"
         style="fill:rgb(200,0,0);
                stroke-width:1;
                stroke:rgb(0,0,0)" />    
</g>
<g transform="translate(0 80)">
    <rect width="82"
         height="20"
         style="fill:rgb(200,0,0);
                stroke-width:1;
                stroke:rgb(0,0,0)" />    
</g>
<g transform="translate(0 100)">
    <rect width="62"
         height="20"
         style="fill:rgb(200,0,0);
                stroke-width:1;
                stroke:rgb(0,0,0)" />    
</g>
<g transform="translate(0 120)">
    <rect width="49"
         height="20"
         style="fill:rgb(200,0,0);
                stroke-width:1;
                stroke:rgb(0,0,0)" />    
</g>
Solution: SVG Template
<g transform="translate(0 ${d.y})">
    <rect width="${d.width}"
         height="20"
         style="fill:${d.color};
                stroke-width:1;
                stroke:rgb(0,0,0)" />    
</g>
Solution: Javascript
function computeX(d, i) {
    return 0
}

function computeWidth(d, i) {
    return d['Attack']
}

function computeY(d, i) {
    return i * 20
}

// HINT: find the max Defense point (_.max, _.pluck) so that you can scale
//       each Pokemon's defense point with respect to it to obtain a value 'r'
//       between 0 and 255. Generate a different rgb(r,0,0) string
function computeColor(d, i) {
    return 'rgb(200,0,0)'
}

var viz = _.map(data, function(d, i){
            return {
                x: computeX(d, i),
                y: computeY(d, i),
                width: computeWidth(d, i),
                color: computeColor(d, i)                
            }
         })
console.log(viz)

var result = _.map(viz, function(d){
         // invoke the compiled template function on each viz data
         return template({d: d})
     })
return result.join('\n')
Console
[{"x":0,"y":0,"width":48,"color":"rgb(200,0,0)"},{"x":0,"y":20,"width":104,"color":"rgb(200,0,0)"},{"x":0,"y":40,"width":52,"color":"rgb(200,0,0)"},{"x":0,"y":60,"width":100,"color":"rgb(200,0,0)"},{"x":0,"y":80,"width":82,"color":"rgb(200,0,0)"},{"x":0,"y":100,"width":62,"color":"rgb(200,0,0)"},{"x":0,"y":120,"width":49,"color":"rgb(200,0,0)"}]