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}]
<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="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>
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 d.Attack
}
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":48,"color":"red"},{"x":0,"y":20,"width":104,"color":"red"},{"x":0,"y":40,"width":52,"color":"red"},{"x":0,"y":60,"width":100,"color":"red"},{"x":0,"y":80,"width":82,"color":"red"},{"x":0,"y":100,"width":62,"color":"red"},{"x":0,"y":120,"width":49,"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
Squirtle
Mega Charizard Y
Charmander
Mega Venusaur
Venusaur
Ivysaur
Bulbasaur
<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="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>
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)" />
<text transform="translate(0 15)">
${d.label}
</text>
</g>
Solution: Javascript
function computeX(d, i) {
return 0
}
function computeWidth(d, i) {
return d.Attack
}
function computeY(d, i) {
return i * 20
}
function computeColor(d, i) {
return 'red'
}
function computeLabel(d, i) {
return d.Name
}
var viz = _.map(data, function(d, i){
return {
x: computeX(d, i),
y: computeY(d, i),
width: computeWidth(d, i),
color: computeColor(d, i),
label: computeLabel(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":"red","label":"Squirtle"},{"x":0,"y":20,"width":104,"color":"red","label":"Mega Charizard Y"},{"x":0,"y":40,"width":52,"color":"red","label":"Charmander"},{"x":0,"y":60,"width":100,"color":"red","label":"Mega Venusaur"},{"x":0,"y":80,"width":82,"color":"red","label":"Venusaur"},{"x":0,"y":100,"width":62,"color":"red","label":"Ivysaur"},{"x":0,"y":120,"width":49,"color":"red","label":"Bulbasaur"}]
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
Squirtle
Mega Charizard Y
Charmander
Mega Venusaur
Venusaur
Ivysaur
Bulbasaur
<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
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>
Solution: SVG Template
<g transform="translate(0 ${d.y})">
<rect
x="${d.x}"
width="${d.width}"
height="20"
style="fill:${d.color};
stroke-width:3;
stroke:rgb(0,0,0)" />
<text transform="translate(0 15)">
${d.label}
</text>
</g>
Solution: Javascript
function computeX(d, i) {
return 120
}
function computeWidth(d, i) {
return d.Attack
}
function computeY(d, i) {
return i * 20
}
function computeColor(d, i) {
return 'red'
}
function computeLabel(d, i) {
return d.Name
}
var viz = _.map(data, function(d, i){
return {
x: computeX(d, i),
y: computeY(d, i),
width: computeWidth(d, i),
color: computeColor(d, i),
label: computeLabel(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":120,"y":0,"width":48,"color":"red","label":"Squirtle"},{"x":120,"y":20,"width":104,"color":"red","label":"Mega Charizard Y"},{"x":120,"y":40,"width":52,"color":"red","label":"Charmander"},{"x":120,"y":60,"width":100,"color":"red","label":"Mega Venusaur"},{"x":120,"y":80,"width":82,"color":"red","label":"Venusaur"},{"x":120,"y":100,"width":62,"color":"red","label":"Ivysaur"},{"x":120,"y":120,"width":49,"color":"red","label":"Bulbasaur"}]
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
Squirtle
Mega Charizard Y
Charmander
Mega Venusaur
Venusaur
Ivysaur
Bulbasaur
<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="-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>
Solution: SVG Template
<g transform="translate(120 ${d.y})">
<rect
x="-${d.attackwidth}"
width="${d.attackwidth}"
height="20"
style="fill:${d.attackcolor};
stroke-width:1;
stroke:rgb(0,0,0)" />
<rect
x=0
width="${d.defensewidth}"
height="20"
style="fill:${d.defensecolor};
stroke-width:1;
stroke:rgb(0,0,0)" />
<text transform="translate(0 15)">
${d.label}
</text>
</g>
Solution: Javascript
function computeX(d, i) {
return 120
}
function computeAttackWidth(d, i) {
return d.Attack
}
function computeDefenseWidth(d, i) {
return d.Defense
}
function computeY(d, i) {
return i * 20
}
function computeAttackColor(d, i) {
return 'red'
}
function computeDefenseColor(d, i) {
return 'blue'
}
function computeLabel(d, i) {
return d.Name
}
var viz = _.map(data, function(d, i){
return {
x: computeX(d, i),
y: computeY(d, i),
attackwidth: computeAttackWidth(d, i),
defensewidth: computeDefenseWidth(d, i),
attackcolor: computeAttackColor(d, i),
defensecolor: computeDefenseColor(d, i),
label: computeLabel(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":120,"y":0,"attackwidth":48,"defensewidth":65,"attackcolor":"red","defensecolor":"blue","label":"Squirtle"},{"x":120,"y":20,"attackwidth":104,"defensewidth":78,"attackcolor":"red","defensecolor":"blue","label":"Mega Charizard Y"},{"x":120,"y":40,"attackwidth":52,"defensewidth":43,"attackcolor":"red","defensecolor":"blue","label":"Charmander"},{"x":120,"y":60,"attackwidth":100,"defensewidth":123,"attackcolor":"red","defensecolor":"blue","label":"Mega Venusaur"},{"x":120,"y":80,"attackwidth":82,"defensewidth":83,"attackcolor":"red","defensecolor":"blue","label":"Venusaur"},{"x":120,"y":100,"attackwidth":62,"defensewidth":63,"attackcolor":"red","defensecolor":"blue","label":"Ivysaur"},{"x":120,"y":120,"attackwidth":49,"defensewidth":49,"attackcolor":"red","defensecolor":"blue","label":"Bulbasaur"}]
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
Squirtle
Mega Charizard Y
Charmander
Mega Venusaur
Venusaur
Ivysaur
Bulbasaur
<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="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>
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)" />
<text transform="translate(0 15)">
${d.label}
</text>
</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
}
function computeX(d, i) {
return 0
}
function computeWidth(d, i) {
return d.Attack
}
function computeHeight(d, i) {
return d.Defense
}
function computeY(d, i) {
var height = 0
var defense_list = _.pluck(data, 'Defense')
for (j = 0; j < i; j++) { height += defense_list[j] }
return height
}
function computeColor(d, i) {
return 'red'
}
function computeLabel(d, i) {
return d.Name
}
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),
label: computeLabel(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":65,"width":48,"color":"red","label":"Squirtle"},{"x":0,"y":65,"height":78,"width":104,"color":"red","label":"Mega Charizard Y"},{"x":0,"y":143,"height":43,"width":52,"color":"red","label":"Charmander"},{"x":0,"y":186,"height":123,"width":100,"color":"red","label":"Mega Venusaur"},{"x":0,"y":309,"height":83,"width":82,"color":"red","label":"Venusaur"},{"x":0,"y":392,"height":63,"width":62,"color":"red","label":"Ivysaur"},{"x":0,"y":455,"height":49,"width":49,"color":"red","label":"Bulbasaur"}]
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
Squirtle
Mega Charizard Y
Charmander
Mega Venusaur
Venusaur
Ivysaur
Bulbasaur
<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(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>
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)" />
<text transform="translate(0 15)">
${d.label}
</text>
</g>
Solution: Javascript
function computeX(d, i) {
return 0
}
function computeWidth(d, i) {
return d.Attack
}
function computeY(d, i) {
return i * 20
}
function computeLabel(d, i) {
return d.Name
}
function computeColor(d, i) {
var val = _.round((255 * d.Defense)/(_.max(_.pluck(data, 'Defense'))))
var str = 'rgb(' + val + ',0,0)'
return str
}
var viz = _.map(data, function(d, i){
return {
x: computeX(d, i),
y: computeY(d, i),
width: computeWidth(d, i),
color: computeColor(d, i),
label: computeLabel(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(135,0,0)","label":"Squirtle"},{"x":0,"y":20,"width":104,"color":"rgb(162,0,0)","label":"Mega Charizard Y"},{"x":0,"y":40,"width":52,"color":"rgb(89,0,0)","label":"Charmander"},{"x":0,"y":60,"width":100,"color":"rgb(255,0,0)","label":"Mega Venusaur"},{"x":0,"y":80,"width":82,"color":"rgb(172,0,0)","label":"Venusaur"},{"x":0,"y":100,"width":62,"color":"rgb(131,0,0)","label":"Ivysaur"},{"x":0,"y":120,"width":49,"color":"rgb(102,0,0)","label":"Bulbasaur"}]