Created
June 12, 2012 00:27
-
-
Save cpudney/2913621 to your computer and use it in GitHub Desktop.
Australian Car Value History Visualization
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Make | Model | Id | 2011 Model | 2011 Sticker | 2011 Min Private | 2011 Max Private | 2011 Min Dealer | 2011 Max Dealer | 2010 Model | 2010 Sticker | 2010 Min Private | 2010 Max Private | 2010 Min Dealer | 2010 Max Dealer | 2009 Model | 2009 Sticker | 2009 Min Private | 2009 Max Private | 2009 Min Dealer | 2009 Max Dealer | 2008 Model | 2008 Sticker | 2008 Min Private | 2008 Max Private | 2008 Min Dealer | 2008 Max Dealer | 2007 Model | 2007 Sticker | 2007 Min Private | 2007 Max Private | 2007 Min Dealer | 2007 Max Dealer | 2006 Model | 2006 Sticker | 2006 Min Private | 2006 Max Private | 2006 Min Dealer | 2006 Max Dealer | 2005 Model | 2005 Sticker | 2005 Min Private | 2005 Max Private | 2005 Min Dealer | 2005 Max Dealer | 2004 Model | 2004 Sticker | 2004 Min Private | 2004 Max Private | 2004 Min Dealer | 2004 Max Dealer | 2003 Model | 2003 Sticker | 2003 Min Private | 2003 Max Private | 2003 Min Dealer | 2003 Max Dealer | 2002 Model | 2002 Sticker | 2002 Min Private | 2002 Max Private | 2002 Min Dealer | 2002 Max Dealer | 2001 Model | 2001 Sticker | 2001 Min Private | 2001 Max Private | 2001 Min Dealer | 2001 Max Dealer | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Holden | Barina | holden_barina | Barina TM | 15900 | 11900 | 13600 | 9600 | 11300 | Barina TK | 14790 | 8600 | 10100 | 6500 | 8000 | Barina TK | 14790 | 7900 | 9300 | 5800 | 7200 | Barina TK | 13690 | 6200 | 7500 | 4300 | 5600 | Barina TK | 13690 | 5200 | 7100 | 3100 | 5700 | Barina TK | 13490 | 4900 | 6300 | 3100 | 4500 | Barina TK | 12990 | 4800 | 6100 | 3000 | 4300 | Barina XC | 14990 | 3900 | 6100 | 1400 | 3600 | Barina SXi XC | 16990 | 3100 | 4500 | 1100 | 2500 | Barina XC | 15590 | 2500 | 3800 | 700 | 2000 | Barina XC | 14400 | 1700 | 3700 | 0 | 0 | |
Holden | Commodore | holden_commodore | Equipe VE Series II (Sep) | 36990 | 25400 | 28100 | 20900 | 23600 | International VE | 36490 | 19700 | 22000 | 15700 | 18000 | International VE | 33990 | 16800 | 19000 | 13200 | 15400 | 60th Anniversary VE (Mar) | 33490 | 15000 | 17100 | 11700 | 13800 | Lumina VE | 32990 | 12300 | 14200 | 9500 | 11400 | SVZ VZ | 32990 | 9500 | 11300 | 6800 | 8600 | Lumina Executive VZ | 32990 | 8800 | 10600 | 6200 | 8000 | Executive VY II | 31970 | 4900 | 6300 | 2800 | 4200 | Executive VY | 31330 | 4200 | 5600 | 2200 | 3600 | Executive VX II | 30880 | 3200 | 4700 | 1200 | 2700 | Executive VX | 29490 | 2900 | 4400 | 900 | 2400 | |
Mazda | 3 / 323 | mazda_3 | Neo BL Series 2 | 20330 | 15700 | 17700 | 12400 | 14400 | Neo BL Series 1 | 21330 | 13800 | 15800 | 10700 | 12700 | Neo BL Series 1 | 21330 | 13200 | 15100 | 10300 | 12200 | Neo BK Series 2 | 20990 | 11100 | 12900 | 8400 | 10200 | Neo BK Series 2 | 20990 | 10400 | 12100 | 7700 | 9400 | Neo BK Series 1 | 20790 | 9700 | 11400 | 7100 | 8800 | Neo BK Series 1 | 20790 | 9200 | 11000 | 6600 | 8400 | Neo BK Series 1 | 20690 | 8700 | 10500 | 6100 | 7900 | Astina BJ II-J48 | 19990 | 5500 | 7100 | 3300 | 4900 | Astina BJ II-J48 | 19990 | 4200 | 5700 | 2100 | 3600 | Astina BJ | 19715 | 3200 | 4700 | 1200 | 2700 | |
Mazda | 6 / 626 | mazda_6 | Limited GH Series 2 | 27310 | 19200 | 21500 | 15200 | 17500 | Limited GH Series 2 | 27310 | 18000 | 20200 | 14200 | 16400 | Limited GH Series 1 | 28485 | 14700 | 16700 | 11500 | 13500 | Limited GH Series 1 | 27990 | 13400 | 15300 | 10400 | 12300 | Limited GG Series 2 | 28285 | 10300 | 12000 | 7600 | 9300 | Limited GG Series 2 | 28285 | 9000 | 10700 | 6400 | 8100 | Limited GG Series 1 | 27690 | 7200 | 8800 | 4900 | 6500 | Limited GG Series 1 | 27690 | 6600 | 8200 | 4300 | 5900 | Limited GG Series 1 | 28270 | 5800 | 7400 | 3500 | 5100 | Limited GG Series 1 | 28270 | 5100 | 6800 | 2900 | 4600 | Limited GF | 25960 | 2200 | 3600 | 400 | 1800 | |
Toyota | Corolla | toyota_corolla | Ascent ZRE152R | 20990 | 15400 | 17400 | 12600 | 14600 | Ascent ZRE152R | 20990 | 14900 | 16900 | 12100 | 14100 | Ascent ZRE152R | 21490 | 12400 | 14300 | 10000 | 11900 | Ascent ZRE152R | 20990 | 10500 | 12200 | 8300 | 10000 | Ascent ZZE122R 5Y | 19990 | 9000 | 10700 | 6800 | 8500 | Ascent ZZE122R 5Y | 19850 | 8400 | 10000 | 6200 | 7800 | Ascent ZZE122R 5Y | 19750 | 8300 | 10000 | 6100 | 7800 | Ascent ZZE122R | 19990 | 5600 | 7100 | 3700 | 5200 | Ascent ZZE122R | 19990 | 5100 | 6600 | 3300 | 4800 | Ascent ZZE122R | 19990 | 4500 | 6000 | 2700 | 4200 | Ascent ZZE122R | 19990 | 3800 | 5300 | 2100 | 3600 | |
Toyota | Camry | toyota_camry | Altise ACV40R | 30490 | 18600 | 20800 | 14700 | 16900 | Altise ACV40R | 29990 | 16100 | 18200 | 12700 | 14800 | Altise ACV40R | 28490 | 13300 | 15200 | 10300 | 12200 | Altise ACV40R | 28490 | 11500 | 13300 | 8800 | 10600 | Altise ACV40R | 28000 | 10200 | 11900 | 7500 | 9200 | Altise ACV36R | 27650 | 7800 | 9400 | 5400 | 7000 | Altise ACV36R | 27500 | 7200 | 8800 | 4900 | 6500 | Altise ACV36R | 26990 | 5900 | 7500 | 3600 | 5200 | Altise ACV36R | 26990 | 5300 | 6900 | 3100 | 4700 | CSi SXV20R | 26280 | 3600 | 5100 | 1600 | 3100 | CSi SXV20R | 26280 | 3100 | 4600 | 1100 | 2600 | |
Ford | Falcon | ford_falcon | XR6 Limited Edition FG | 36990 | 24800 | 27500 | 19600 | 22300 | G6 Limited Edition FG | 36490 | 17800 | 20000 | 14000 | 16200 | G6 Limited Edition FG | 36490 | 16700 | 18900 | 13100 | 15300 | SR BF Mk II | 32888 | 10400 | 12100 | 7800 | 9500 | XT BF Mk II | 34990 | 7300 | 8800 | 5000 | 6500 | SR BF | 33490 | 7500 | 9000 | 5200 | 6700 | XT BA Mk II | 34555 | 5100 | 6500 | 3000 | 4400 | XT BA | 33860 | 4100 | 5400 | 2100 | 3400 | XT BA | 33740 | 3600 | 5000 | 1600 | 3000 | SR Forte AU III | 32885 | 3600 | 5100 | 1600 | 3100 | SR Forte AU II | 30970 | 3100 | 4600 | 1100 | 2600 | |
Nissan | Maxima | nissan_maxima | 250 ST-L J32 | 33990 | 22700 | 25300 | 18400 | 21000 | 250 ST-L J32 | 33990 | 20100 | 22500 | 15900 | 18300 | 250 ST-L J32 | 33990 | 18700 | 21000 | 14700 | 17100 | ST-L J31 | 34990 | 13900 | 15900 | 10800 | 12800 | ST-L J31 | 34990 | 12300 | 14200 | 9500 | 11400 | ST-L J31 | 38990 | 10900 | 12800 | 8200 | 10100 | ST-L J31 | 39990 | 9300 | 11100 | 6700 | 8500 | ST-L J31 | 39990 | 7500 | 9200 | 5100 | 6800 | ST A33 | 39990 | 5600 | 7200 | 3400 | 5000 | S A33 | 36990 | 4000 | 5500 | 1900 | 3400 | S A33 | 36990 | 3300 | 4800 | 1300 | 2800 | |
Honda | Civic | honda_civic | VTi 8th Gen | 22490 | 14400 | 16200 | 11800 | 13600 | VTi 8th Gen | 22490 | 13100 | 14900 | 10700 | 12500 | VTi 8th Gen | 22990 | 11700 | 13500 | 9400 | 11200 | VTi 8th Gen | 21790 | 10000 | 11700 | 7800 | 9500 | VTi 8th Gen | 21490 | 9300 | 10900 | 7100 | 8700 | VTi 8th Gen | 21490 | 8800 | 10500 | 6600 | 8300 | GLi 7th Gen | 19990 | 7200 | 8800 | 4800 | 6400 | GLi 7th Gen | 20950 | 6800 | 8400 | 4400 | 6000 | GLi 7th Gen | 22950 | 5500 | 7000 | 3400 | 4900 | GLi 7th Gen | 22950 | 4700 | 6200 | 2600 | 4100 | GLi 7th Gen | 26209 | 3700 | 5300 | 1600 | 3200 | |
Honda | Accord | honda_accord | VTi 8th Gen | 28199 | 20100 | 22500 | 15900 | 18300 | VTi 8th Gen | 32490 | 19000 | 21300 | 15000 | 17300 | 40th Anniversary 8th Gen | 31440 | 16600 | 18700 | 13100 | 15200 | VTi 8th Gen | 32490 | 15700 | 17900 | 12200 | 14400 | VTi | 30490 | 11700 | 13600 | 9000 | 10900 | VTi | 29990 | 9200 | 10900 | 6600 | 8300 | VTi | 29990 | 8500 | 10200 | 6000 | 7700 | VTi | 34250 | 7800 | 9600 | 5300 | 7100 | VTi | 34250 | 7300 | 9000 | 5000 | 6700 | VTi-L | 40900 | 6500 | 8300 | 4100 | 5900 | VTi-L | 36750 | 3100 | 4600 | 1200 | 2700 | |
Subaru | Liberty | subaru_liberty | 5GEN | 32990 | 22300 | 24800 | 1800 | 20500 | 5GEN | 33990 | 21500 | 23900 | 17300 | 19700 | 4GEN | 33990 | 17800 | 20000 | 14000 | 16200 | 4GEN | 32490 | 16400 | 18600 | 12800 | 15000 | 4GEN | 31990 | 13100 | 15100 | 10200 | 12200 | 4GEN | 31990 | 11800 | 13700 | 9100 | 11000 | 4GEN | 30990 | 9000 | 10800 | 6400 | 8200 | 4GEN | 30990 | 8300 | 10100 | 5800 | 7600 | GX 3GEN | 29990 | 5500 | 7100 | 3300 | 4900 | GX 3GEN | 29990 | 4800 | 6400 | 2700 | 4300 | GX 3GEN | 29930 | 3900 | 5500 | 1800 | 3400 | |
Subaru | Impreza | subaru_impreza | 2.0i G4 | 23990 | 16700 | 18800 | 13200 | 15300 | R G3 | 23990 | 14100 | 16100 | 11000 | 13000 | R G3 | 22990 | 12700 | 14500 | 9900 | 11700 | R G3 | 24490 | 11800 | 13600 | 9100 | 10900 | S | 23990 | 11200 | 13000 | 8600 | 10400 | S | 23990 | 9800 | 11600 | 7100 | 8900 | GX S | 23990 | 8700 | 10400 | 6100 | 7800 | GX S | 23990 | 8000 | 7900 | 5500 | 7200 | GX S | 23990 | 6600 | 8200 | 4300 | 5900 | GX S | 25990 | 5300 | 7000 | 3100 | 4800 | GX S | 25970 | 5000 | 6600 | 2900 | 4500 | |
Volkswagen | Golf | vw_golf | 77TSI VI | 21990 | 16500 | 18600 | 12900 | 15000 | 77TSI VI | 21990 | 14700 | 16700 | 11500 | 13500 | 90TSI Trendline VI | 25990 | 15000 | 17000 | 11700 | 13700 | Edition V | 25490 | 12900 | 14900 | 10000 | 12000 | Trendline V | 25490 | 11400 | 13200 | 8700 | 10500 | Trendline V | 25490 | 9400 | 11200 | 6800 | 8600 | Trendline V | 25490 | 8700 | 10500 | 6100 | 7900 | Trendline V | 25490 | 8100 | 9900 | 5600 | 7400 | Generation 4th Gen | 25990 | 6200 | 7900 | 3900 | 5600 | GL 4th Gen | 25990 | 4200 | 5800 | 2100 | 3700 | GL 4th Gen | 25990 | 3900 | 5500 | 1800 | 3400 | |
Volkswagen | Passat | vw_passat | 118TSI Type 3C | 38990 | 29100 | 32000 | 24200 | 27100 | 118TSI Type 3C | 38990 | 25600 | 28400 | 21000 | 23900 | 103TDI Type 3C | 42990 | 24600 | 27400 | 20200 | 23000 | 103TDI Type 3C | 42490 | 20400 | 22900 | 16200 | 18700 | TDI Type 3C | 42490 | 16400 | 18700 | 12800 | 15100 | TDI Type 3C | 42990 | 13500 | 15500 | 10500 | 12500 | V5 GP | 39990 | 9300 | 11100 | 6700 | 8500 | S V5 GP | 49990 | 7600 | 9300 | 5200 | 6900 | S V5 GP | 49990 | 6400 | 8100 | 4100 | 5800 | GP | 45990 | 4200 | 5700 | 2100 | 3600 | GP | 45990 | 3800 | 5400 | 1700 | 3300 | |
BMW | 320i | bmw_320i | Lifestyle E90 | 56100 | 43100 | 47100 | 30600 | 40600 | Executive E90 | 54500 | 35000 | 38400 | 29300 | 32700 | Executive E90 | 54500 | 33100 | 36500 | 27600 | 31000 | E90 | 51000 | 22400 | 25000 | 18000 | 20700 | E90 | 51000 | 21000 | 23700 | 16900 | 19500 | E90 | 50800 | 17400 | 19800 | 13700 | 16100 | E90 | 49900 | 16100 | 18600 | 12500 | 15000 | E46 | 62900 | 13100 | 15300 | 10100 | 12300 | E46 | 62900 | 9900 | 12000 | 7200 | 9300 | E46 | 61600 | 9300 | 11400 | 6600 | 8700 | E46 | 61400 | 8400 | 10500 | 5900 | 8000 | |
Audi | A4 | audi_a3 | B8 | 52100 | 31700 | 39000 | 26400 | 29600 | B8 | 50600 | 27800 | 30700 | 23000 | 25900 | B8 | 50900 | 25600 | 28500 | 21000 | 23900 | B7 | 47800 | 18700 | 21000 | 14700 | 17100 | SE B7 | 45900 | 16500 | 18700 | 13300 | 15200 | B7 | 47300 | 14200 | 16400 | 11000 | 13200 | B6 | 45600 | 10800 | 12700 | 8100 | 10000 | B6 | 47400 | 8800 | 10600 | 6100 | 8100 | B6 | 47400 | 8000 | 9800 | 5500 | 7300 | B6 | 47400 | 7500 | 9300 | 5100 | 6900 | B5 | 45950 | 5200 | 6900 | 3000 | 4700 | |
Audi | A3 | audi_a4 | Attraction 8P | 36400 | 26400 | 29200 | 21800 | 24600 | Attraction 8P | 35500 | 22000 | 24500 | 17700 | 20200 | Attraction 8P | 35400 | 19300 | 21700 | 15300 | 17700 | Attraction 8P | 33950 | 15200 | 17300 | 11900 | 14000 | Attraction 8P | 33950 | 13200 | 15200 | 10200 | 12200 | Attraction 8P | 33950 | 11900 | 13900 | 9100 | 11100 | Attraction 8P | 33950 | 9700 | 11600 | 7000 | 8900 | Attraction 8P | 34900 | 9000 | 10900 | 6400 | 8300 | A3 | 35400 | 6300 | 7900 | 4000 | 5600 | A3 | 35400 | 5600 | 7200 | 3400 | 5000 | A4 | 35400 | 5100 | 6800 | 2900 | 4600 | |
Mercedes | C220 CDI | mercedes_c220_cdi | Classic W204 | 62170 | 43200 | 47200 | 36700 | 40700 | Classic W204 | 62170 | 38500 | 42200 | 32500 | 36200 | Classic W204 | 61400 | 33000 | 36400 | 27500 | 30900 | Classic W204 | 60526 | 30000 | 33300 | 24800 | 28100 | Classic W204 | 60300 | 29300 | 32600 | 24300 | 27600 | Classic W204 | 68990 | 23900 | 26800 | 19500 | 22400 | Classic W204 | 68400 | 20100 | 22900 | 15900 | 18700 | Classic W203 | 64600 | 16400 | 19000 | 12800 | 15400 | Classic W203 | 64600 | 15100 | 17600 | 11800 | 14300 | Classic W203 | 63800 | 13000 | 15500 | 10000 | 12500 | Classic W203 | 63800 | 11700 | 14200 | 8900 | 11400 | |
Kia | Rio | kia_rio | S JB | 14990 | 8800 | 10400 | 5300 | 6900 | S JB | 14990 | 8100 | 9600 | 4800 | 6300 | LX JB | 14990 | 7800 | 9300 | 4600 | 6100 | LX JB | 14990 | 6700 | 8200 | 3800 | 5300 | LX JB | 14990 | 6400 | 7800 | 3600 | 5000 | JB | 15990 | 5900 | 7300 | 3300 | 4700 | Rio | 14990 | 4500 | 5800 | 3100 | 3400 | Rio | 14990 | 3900 | 5200 | 1500 | 2900 | Rio | 14990 | 3500 | 5000 | 1200 | 2700 | Rio | 14990 | 1600 | 3600 | 0 | 0 | Rio | 14990 | 1400 | 3100 | 0 | 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Dimensions. | |
const WIDTH = 1024; | |
const HEIGHT = 480; | |
// Insets. | |
const INSETS = {"left": 100, | |
"right": 200, | |
"top": 10, | |
"bottom": 50}; | |
// Year extents. | |
const MIN_YEAR = 2001; | |
const MAX_YEAR = 2011; | |
// Axes. | |
const AXES = {}; | |
// Scales. | |
const SCALES = {}; | |
// Paths. | |
const PATHS = {}; | |
// Keys used in data, SCALES and PATHS. | |
const YEAR_KEY = "year"; | |
const STICKER_KEY = "sticker"; | |
const PERCENT_KEY = "percent"; | |
const RESALE_KEY = "resale"; | |
// Transition duration (ms). | |
const DURATION = 1000; | |
// Visualize when document has loaded. | |
window.onload = function() { | |
// Read the data set. | |
d3.csv("cardata.csv", function(d) { | |
// Parse the data and chart it. | |
chart(parseData(d)); | |
}); | |
}; | |
// Parse the data set. | |
// | |
// data: array of data records. | |
// | |
function parseData(data) { | |
var results = []; | |
// Process each data record.. | |
for (var row = 0; | |
row < data.length; | |
row++) { | |
var record = data[row]; | |
var history = []; | |
// Process each year. | |
for (var year = MIN_YEAR; | |
year <= MAX_YEAR; | |
year++) { | |
var sticker = parseInt(record[year + " Sticker"]); | |
var resale = calculateMedianPrice(record, year, "Private"); | |
var items = {}; | |
items[YEAR_KEY] = year; | |
items[STICKER_KEY] = sticker; | |
items[RESALE_KEY] = resale; | |
items[PERCENT_KEY] = 100.0 * resale / sticker; | |
history.push(items); | |
} | |
results.push({ | |
'prices' : history, | |
'name' : record.Make + " " + record.Model, | |
'id' : record.Id}); | |
} | |
return results; | |
} | |
// Calculate median price for a specific year. | |
// | |
// record: array containing price data. | |
// year: year of price data. | |
// type: Private || Dealer | |
// | |
function calculateMedianPrice(record, year, type) { | |
var minP = parseInt(record[year + " Min " + type]); | |
var maxP = parseInt(record[year + " Max " + type]); | |
return d3.median([minP, maxP]); | |
} | |
// Plot the chart. | |
// | |
// data: the data set. | |
// | |
function chart(data) { | |
// Set radio button. | |
var key = STICKER_KEY; | |
document.getElementById(key).checked = true; | |
// Set up the scales. | |
configureScales(data); | |
// Line chart paths.. | |
calculatePaths(); | |
// Chart root. | |
var chart = d3.select("#chart") | |
.append("svg:svg") | |
.attr("width", WIDTH) | |
.attr("height", HEIGHT); | |
// Draw chart. | |
appendPaths(chart, data, key); | |
appendLabels(chart, data, key); | |
appendAxes(chart, key); | |
highlight(); | |
} | |
// Draw path lines for each car's price data. | |
// | |
// chart: element to append to. | |
// data: holds price data. | |
// key: determines y-axis mapping. | |
// | |
function appendPaths(chart, data, key) { | |
chart.selectAll("path.price") | |
.data(data, function(d) { | |
return d.id; | |
}) | |
.enter() | |
.append("svg:path") | |
.attr("class", "price") | |
.attr("d", function(d) { | |
return PATHS[key](d.prices); | |
}) | |
.on("mouseover", function(d, i) { | |
// Highlight line. | |
d3.select(this) | |
.style("stroke", SCALES.clr(i)) | |
.style("stroke-width", 2); | |
// Highlight label. | |
d3.selectAll("text.label") | |
.filter(function(d1, i1) { | |
return i1 == i; | |
}) | |
.style("opacity", 1.0) | |
}) | |
.on("mouseout", function () { | |
highlight(); // reset highlights. | |
}); | |
} | |
// Append labels for each car. | |
// | |
// chart: element to append to. | |
// data: holds price data. | |
// key: determines y-axis mapping. | |
// | |
function appendLabels(chart, data, key) { | |
chart.selectAll("text.label") | |
.data(data, function(d) { | |
return d.id; | |
}) | |
.enter() | |
.append("svg:text") | |
.attr("class", "label") | |
.attr("text-anchor", "left") | |
.attr("opacity", 0.0) | |
.attr("dx", "1.0em") | |
.attr("dy", "0.3em") | |
.attr("x", SCALES.x.range()[1]) | |
.attr("y", function (d) { | |
return SCALES[key](d.prices[0][key]); | |
}) | |
.attr("fill", function(d, i) { | |
return SCALES.clr(i); | |
}) | |
.text(function(d) { | |
return d.name; | |
}); | |
} | |
// Append x- and y-axes. | |
// | |
// chart: element to append to. | |
// key: determines y-axis mapping. | |
// | |
function appendAxes(chart, key) { | |
// X-axis. | |
var xAxis = d3.svg.axis().scale(SCALES.x).tickFormat(d3.format(".0f")).orient("bottom"); | |
chart.append("g") | |
.attr("class", "xaxis") | |
.attr("width", SCALES.x.range()[1] - SCALES.x.range()[0]) | |
.attr("height", INSETS.bottom) | |
.attr("transform", "translate(0, " + SCALES[key].range()[1] + ")") | |
.call(xAxis); | |
// Y-axes. | |
chart.append("g") | |
.attr("class", "yaxis") | |
.attr("width", INSETS.left) | |
.attr("height", SCALES[key].range()[1] - SCALES[key].range()[0]) | |
.attr("transform", "translate(" + SCALES.x.range()[0] + ", 0)") | |
.attr("transform", "translate(100,0)") | |
.call(AXES[key]); | |
} | |
// Highlight elements. | |
// | |
function highlight() { | |
// Highlight line. | |
d3.selectAll("path.price") | |
.style("stroke", function(d, i) { | |
return document.getElementById(d.id).checked ? SCALES.clr(i) : null; | |
}) | |
.style("stroke-width", function(d) { | |
return document.getElementById(d.id).checked ? 2 : 1; | |
}); | |
// Highlight label. | |
d3.selectAll("text.label") | |
.style("opacity", function(d) { | |
return document.getElementById(d.id).checked ? 1.0 : 0.0; | |
}); | |
} | |
// Configure the scales. | |
// | |
// data: data set. | |
// | |
function configureScales(data) { | |
var prices = data.map(function(d) { | |
return d.prices; | |
}); | |
var sticker = prices.map(function(d) { | |
return d3.max(d, function(e) { | |
return e[STICKER_KEY]; | |
}); | |
}); | |
var resale = prices.map(function(d) { | |
return d3.max(d, function(e) { | |
return e[RESALE_KEY]; | |
}); | |
}); | |
// Colour scale. | |
SCALES.clr = d3.scale.category20b(); | |
// X-axis scale. | |
SCALES.x = d3.scale.linear() | |
.domain([MAX_YEAR, MIN_YEAR]) | |
.range([INSETS.left, WIDTH - INSETS.right]); | |
// Y-axis scale: sticker price. | |
SCALES[STICKER_KEY] = d3.scale.linear() | |
.domain([d3.max(sticker), 0]) | |
.range([INSETS.top, HEIGHT - INSETS.bottom]) | |
.nice(); | |
// Y-axis scale: resale price. | |
SCALES[RESALE_KEY] = d3.scale.linear() | |
.domain([d3.max(resale), 0]) | |
.range([INSETS.top, HEIGHT - INSETS.bottom]) | |
.nice(); | |
// Y-axis scale: percentage (resale of sticker). | |
SCALES[PERCENT_KEY] = d3.scale.linear() | |
.domain([100, 0]) | |
.range([INSETS.top, HEIGHT - INSETS.bottom]); | |
// Configure scales. | |
AXES[STICKER_KEY] = d3.svg.axis().scale(SCALES[STICKER_KEY]).orient("left"); | |
AXES[RESALE_KEY] = d3.svg.axis().scale(SCALES[RESALE_KEY]).orient("left"); | |
AXES[PERCENT_KEY] = d3.svg.axis().scale(SCALES[PERCENT_KEY]).orient("left"); | |
} | |
// Calculate the paths for line charts. | |
// | |
function calculatePaths() { | |
PATHS[STICKER_KEY] = d3.svg.line() | |
.x(function(d) { | |
return SCALES.x(d[YEAR_KEY]); | |
}) | |
.y(function(d) { | |
return SCALES[STICKER_KEY](d[STICKER_KEY]); | |
}) | |
.interpolate("linear"); | |
PATHS[RESALE_KEY] = d3.svg.line() | |
.x(function(d) { | |
return SCALES.x(d[YEAR_KEY]); | |
}) | |
.y(function(d) { | |
return SCALES[RESALE_KEY](d[RESALE_KEY]); | |
}) | |
.interpolate("linear"); | |
PATHS[PERCENT_KEY] = d3.svg.line() | |
.x(function(d) { | |
return SCALES.x(d[YEAR_KEY]); | |
}) | |
.y(function(d) { | |
return SCALES[PERCENT_KEY](d[PERCENT_KEY]); | |
}) | |
.interpolate("linear"); | |
} | |
// Sets the y-axis using a transition. | |
function setYAxis(key) { | |
d3.selectAll("path.price") | |
.transition(DURATION) | |
.attr("d", function (d) { | |
return PATHS[key](d.prices); | |
}); | |
d3.selectAll("text.label") | |
.transition(DURATION) | |
.attr("y", function (d) { | |
return SCALES[key](d.prices[0][key]); | |
}); | |
d3.selectAll("g.yaxis") | |
.call(AXES[key]); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<title>Australian Car Value History</title> | |
<meta http-equiv="X-UA-Compatible" content="chrome=1"> | |
<link href="style.css" media="screen" rel="stylesheet" type="text/css"/> | |
<script type="text/javascript" src="http://d3js.org/d3.v2.min.js"></script> | |
</head> | |
<body> | |
<h2>Australian Car Value History</h2> | |
<h3> | |
By <a href="http://vislives.com/" target="_blank">Chris Pudney</a> | |
<a href="http://creativecommons.org/licenses/by-sa/3.0/" target="_blank"><img align="top" | |
alt="Creative Commons License" | |
src="http://i.creativecommons.org/l/by-sa/3.0/80x15.png"/></a> | |
</h3> | |
<div style="float: left"> | |
<label title="Sticker price when new"> | |
<input type="radio" name="yAxis" id="sticker" onclick="setYAxis('sticker');"/> | |
Sticker Price | |
</label><br/> | |
<label title="Resale value"> | |
<input type="radio" name="yAxis" id="resale" onclick="setYAxis('resale');"/> | |
Resale Value | |
</label><br/> | |
<label title="Resale value as a percentage of sticker price"> | |
<input type="radio" name="yAxis" id="percent" onclick="setYAxis('percent');"/> | |
Resale Value (%) | |
</label><br/> | |
<br/> | |
<label><input id="audi_a3" type="checkbox" name="Audi A3" onclick="highlight();">Audi A3</label><br/> | |
<label><input id="audi_a4" type="checkbox" name="Audi A4" onclick="highlight();">Audi A4</label><br/> | |
<label><input id="bmw_320i" type="checkbox" name="BMW 320i" onclick="highlight();">BMW 320i</label><br/> | |
<label><input id="ford_falcon" type="checkbox" name="Ford Falcon" onclick="highlight();">Ford | |
Falcon</label><br/> | |
<label><input id="holden_barina" type="checkbox" name="Holden Barina" onclick="highlight();">Holden | |
Barina</label><br/> | |
<label><input id="holden_commodore" type="checkbox" name="Holden Commodore" onclick="highlight();">Holden | |
Commodore</label><br/> | |
<label><input id="honda_accord" type="checkbox" name="Honda Accord" onclick="highlight();">Honda | |
Accord</label><br/> | |
<label><input id="honda_civic" type="checkbox" name="Honda Civic" onclick="highlight();">Honda | |
Civic</label><br/> | |
<label><input id="kia_rio" type="checkbox" name="Kia Rio" onclick="highlight();">Kia Rio</label><br/> | |
<label><input id="mazda_3" type="checkbox" name="Mazda 3 / 323" onclick="highlight();">Mazda 3/323</label><br/> | |
<label><input id="mazda_6" type="checkbox" name="Mazda 6 / 626" onclick="highlight();">Mazda 6/626</label><br/> | |
<label><input id="mercedes_c220_cdi" type="checkbox" name="Mercedes C220 CDI" onclick="highlight();">Mercedes | |
C220 CDI</label><br/> | |
<label><input id="nissan_maxima" type="checkbox" name="Nissan Maxima" onclick="highlight();">Nissan | |
Maxima</label><br/> | |
<label><input id="subaru_impreza" type="checkbox" name="Subaru Impreza" onclick="highlight();">Subuaru | |
Impreza</label><br/> | |
<label><input id="subaru_liberty" type="checkbox" name="Subaru Liberty" onclick="highlight();">Subaru | |
Liberty</label><br/> | |
<label><input id="toyota_camry" type="checkbox" name="Toyota Camry" onclick="highlight();">Toyota | |
Camry</label><br/> | |
<label><input id="toyota_corolla" type="checkbox" name="Toyota Corolla" onclick="highlight();">Toyota | |
Corolla</label><br/> | |
<label><input id="vw_golf" type="checkbox" name="Volkswagen Golf" onclick="highlight();">Volkswagen Golf</label><br/> | |
<label><input id="vw_passat" type="checkbox" name="Volkswagen Passat" onclick="highlight();">Volkswagen | |
Passat</label><br/> | |
</div> | |
<span id="chart"></span> | |
<div class="legend">To highlight a car, select its checkbox or mouse-over its line.<br/> | |
Sources: <a href="http://redbook.com.au/" target="_blank">RedBook.com.au</a> and <a | |
href="http://www.carsales.com.au/" target="_blank">carsales.com.au</a></div> | |
<script src="chart.js" type="text/javascript"></script> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
body { | |
margin: 0; | |
padding: 10px; | |
background-color: #ffffff; | |
font-family: sans-serif; | |
font-size: 12px; | |
color: #666666; | |
overflow: hidden; | |
} | |
a:link { | |
color: #ccccff; | |
} | |
a:visited { | |
color: #cccccc; | |
} | |
a:active { | |
color: #ffccff; | |
} | |
a.hover { | |
color: #ffcccc; | |
} | |
path { | |
fill: none; | |
stroke: #cccccc; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment