Skip to content

Instantly share code, notes, and snippets.

@bycoffe
Created January 23, 2013 21:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bycoffe/4614122 to your computer and use it in GitHub Desktop.
Save bycoffe/4614122 to your computer and use it in GitHub Desktop.
<!doctype html>
<html>
<head>
</head>
<body>
<button id="animate">Animate</button>
<div id="map"></div>
<script type="text/javascript" src="http://code.jquery.com/jquery.min.js"></script>
<script type="text/javascript" src="http://jsplumb.googlecode.com/svn-history/r859/trunk/js/lib/raphael-1.5.2-min.js"></script>
<script type="text/javascript">
;(function() {
var counties = {"55029":{"name":"Door","path":"M 1017.88 -38.07 L 1026.7 -38.13 1028.9 -41.32 1031.15 -39.3 1022.85 -23.09 1017.26 -29.22 Z M 945.69 62.92 L 957.16 40.82 969.67 37.03 973.51 32.98 978.64 36.48 976.5 30.3 989.13 7.0 991.27 -4.66 1002.43 -8.27 1003.17 -17.19 1007.86 -22.2 1014.91 -22.8 1015.07 -12.08 1009.86 -11.3 1009.77 5.22 1002.96 9.62 999.17 16.97 996.87 21.94 998.74 26.89 994.62 30.39 995.87 34.53 986.58 44.43 980.59 62.04 Z"},"55033":{"name":"Dunn","path":"M 523.02 38.89 L 522.38 -8.57 569.15 -7.24 569.13 63.48 522.5 62.27 Z"},"55039":{"name":"Fond du Lac","path":"M 877.37 170.27 L 883.65 170.2 883.43 164.11 907.07 163.66 908.37 216.9 884.87 217.33 884.57 205.54 837.05 206.0 836.58 170.71 Z"},"55045":{"name":"Green","path":"M 743.97 311.49 L 790.55 311.38 791.24 359.46 744.12 358.99 Z"},"55063":{"name":"La Crosse","path":"M 615.9 145.78 L 639.12 147.18 638.82 193.87 603.83 193.23 602.54 176.95 589.59 158.22 599.13 158.36 597.78 151.18 Z"},"55069":{"name":"Lincoln","path":"M 723.78 -52.37 L 782.05 -52.6 782.69 6.22 723.72 6.26 Z"},"55073":{"name":"Marathon","path":"M 697.47 64.87 L 697.77 17.85 709.01 17.91 709.02 6.19 801.96 6.12 802.58 65.07 Z"},"55081":{"name":"Monroe","path":"M 633.3 147.21 L 639.91 135.48 697.54 136.33 697.36 193.52 638.82 193.87 639.12 147.18 Z"},"55095":{"name":"Polk","path":"M 467.94 -23.02 L 474.85 -34.8 473.64 -44.43 469.59 -53.57 454.89 -60.08 455.04 -69.34 488.74 -67.92 489.19 -79.58 524.46 -78.13 522.38 -8.57 464.33 -10.46 Z"},"55103":{"name":"Richland","path":"M 685.46 265.02 L 674.06 263.53 662.04 268.8 661.99 217.36 709.06 217.34 708.75 270.04 699.02 264.28 Z"},"55115":{"name":"Shawano","path":"M 802.11 18.17 L 825.26 17.95 825.44 29.56 848.98 29.17 849.1 40.88 895.91 40.48 897.0 76.6 862.21 76.51 862.09 64.67 802.58 65.07 Z"},"55129":{"name":"Washburn","path":"M 582.21 -64.91 L 535.78 -66.27 535.86 -136.09 582.54 -134.96 Z"},"55141":{"name":"Wood","path":"M 737.34 123.68 L 697.64 123.72 697.47 64.87 742.81 64.94 742.91 88.33 754.28 88.34 754.58 123.88 Z"},"55003":{"name":"Ashland","path":"M 685.77 -249.59 L 686.51 -256.24 691.47 -257.71 689.76 -249.09 685.07 -246.62 Z M 668.99 -228.75 L 672.17 -230.26 675.26 -226.8 665.3 -223.07 667.02 -218.98 654.81 -214.31 654.69 -218.73 Z M 674.34 -236.38 L 667.39 -236.57 669.29 -239.75 680.65 -242.16 677.45 -236.15 Z M 641.67 -191.77 L 656.35 -198.49 659.48 -206.03 676.79 -191.31 676.23 -145.02 688.04 -144.89 687.95 -133.24 699.49 -133.3 699.5 -109.9 640.93 -110.31 Z"},"55005":{"name":"Barron","path":"M 569.15 -7.24 L 522.38 -8.57 524.11 -66.55 582.21 -64.91 580.9 -6.8 Z"},"55007":{"name":"Bayfield","path":"M 650.96 -241.51 L 658.45 -232.43 645.87 -214.81 648.67 -206.3 643.29 -202.26 639.45 -193.88 641.67 -191.77 641.26 -133.71 582.54 -134.96 584.11 -215.67 601.12 -220.5 614.42 -229.7 618.86 -227.02 622.45 -230.87 625.62 -228.72 638.45 -240.2 642.73 -238.45 647.46 -242.41 Z"},"55017":{"name":"Chippewa","path":"M 639.61 17.76 L 639.44 41.2 569.61 40.25 569.15 -7.24 580.9 -6.8 581.21 -18.32 639.84 -17.41 Z"},"55025":{"name":"Dane","path":"M 790.56 312.92 L 743.97 311.49 743.87 264.43 755.46 252.67 825.57 253.21 825.88 312.25 Z"},"55101":{"name":"Racine","path":"M 943.72 310.6 L 949.93 318.17 946.48 334.03 908.37 334.78 908.56 342.64 896.83 342.99 896.11 311.77 Z"},"55107":{"name":"Rusk","path":"M 663.7 -63.86 L 663.4 -28.74 639.98 -29.19 639.84 -17.41 581.21 -18.32 582.21 -64.91 Z"},"55111":{"name":"Sauk","path":"M 755.8 248.78 L 755.46 252.67 743.87 264.43 708.75 270.04 709.06 217.34 697.37 217.44 697.29 205.7 748.88 205.73 754.16 215.05 767.2 216.85 767.19 240.87 Z"},"55113":{"name":"Sawyer","path":"M 641.26 -133.71 L 640.93 -110.31 664.26 -110.15 663.7 -63.86 582.21 -64.91 582.54 -134.96 Z"},"55119":{"name":"Taylor","path":"M 663.4 -28.74 L 723.88 -29.02 723.72 6.26 709.02 6.19 709.01 17.91 639.61 17.76 639.98 -29.19 Z"},"55123":{"name":"Vernon","path":"M 697.29 205.7 L 697.37 217.44 661.99 217.36 662.15 234.9 609.34 234.28 603.54 208.23 603.83 193.23 697.36 193.52 Z"},"55125":{"name":"Vilas","path":"M 822.56 -126.08 L 828.07 -122.96 828.14 -110.62 817.42 -110.49 817.57 -98.79 805.25 -99.2 805.6 -93.43 793.76 -93.9 793.73 -99.37 723.86 -98.5 723.76 -109.93 734.58 -109.93 734.52 -152.83 809.89 -132.3 Z"},"55133":{"name":"Waukesha","path":"M 872.49 300.25 L 872.45 264.46 919.1 264.0 919.59 311.07 872.76 312.12 Z"},"55139":{"name":"Winnebago","path":"M 882.66 125.17 L 883.65 170.2 836.58 170.71 835.83 123.85 882.61 122.85 Z"},"55011":{"name":"Buffalo","path":"M 580.57 75.51 L 579.6 122.62 571.33 132.46 578.77 142.94 576.16 152.61 545.97 128.13 541.52 110.09 526.45 99.9 532.36 75.76 Z"},"55013":{"name":"Burnett","path":"M 455.04 -69.34 L 456.96 -79.17 465.16 -85.17 471.7 -101.08 512.64 -125.5 513.0 -136.68 535.86 -136.09 535.78 -66.27 524.11 -66.55 524.46 -78.13 489.19 -79.58 488.74 -67.92 Z"},"55019":{"name":"Clark","path":"M 697.59 43.42 L 697.35 100.0 650.39 99.98 650.52 88.22 638.82 88.05 639.61 17.76 697.77 17.85 Z"},"55021":{"name":"Columbia","path":"M 755.46 252.67 L 755.8 248.78 767.19 240.87 767.2 216.85 754.16 215.05 748.88 205.73 825.21 206.22 825.57 253.21 Z"},"55023":{"name":"Crawford","path":"M 662.04 268.8 L 622.35 292.62 612.65 293.2 611.74 273.22 623.55 257.1 618.8 249.17 608.77 241.14 609.34 234.28 662.15 234.9 Z"},"55015":{"name":"Calumet","path":"M 882.61 122.85 L 917.6 122.49 918.9 169.59 907.15 169.89 907.07 163.66 883.43 164.11 Z"},"55027":{"name":"Dodge","path":"M 843.2 264.7 L 825.74 264.96 825.21 206.22 884.57 205.54 884.08 264.42 Z"},"55053":{"name":"Jackson","path":"M 615.9 145.78 L 615.59 75.99 639.03 76.4 638.82 88.05 650.52 88.22 650.39 99.98 697.35 100.0 697.54 136.33 639.91 135.48 633.3 147.21 Z"},"55067":{"name":"Langlade","path":"M 825.26 17.95 L 802.11 18.17 801.96 6.12 782.69 6.22 782.46 -40.73 830.07 -40.94 829.95 -29.27 853.53 -29.63 853.71 -6.21 857.62 5.54 825.06 5.98 Z"},"55078":{"name":"Menominee","path":"M 857.62 5.54 L 872.64 5.33 872.8 40.59 849.1 40.88 848.98 29.17 825.44 29.56 825.06 5.98 Z"},"55087":{"name":"Outagamie","path":"M 888.21 122.79 L 850.07 123.55 849.62 76.71 902.25 76.21 903.12 122.71 Z"},"55099":{"name":"Price","path":"M 723.81 -75.97 L 723.88 -29.02 663.4 -28.74 664.26 -110.15 723.76 -109.93 Z"},"55109":{"name":"St. Croix","path":"M 464.33 -10.46 L 522.38 -8.57 523.02 38.89 463.1 36.47 464.51 26.37 461.13 7.2 Z"},"55121":{"name":"Trempealeau","path":"M 615.59 75.99 L 615.9 145.78 597.78 151.18 599.13 158.36 589.59 158.22 576.16 152.61 578.77 142.94 571.33 132.46 579.6 122.62 580.57 75.51 Z"},"55135":{"name":"Waupaca","path":"M 862.21 76.51 L 849.62 76.71 850.07 123.55 803.04 124.12 802.58 65.07 862.09 64.67 Z"},"55035":{"name":"Eau Claire","path":"M 615.59 75.99 L 568.9 75.21 569.61 40.25 639.44 41.2 639.03 76.4 Z"},"55037":{"name":"Florence","path":"M 876.6 -76.41 L 852.93 -76.03 851.6 -115.35 855.96 -111.43 868.12 -116.15 869.84 -112.55 880.48 -112.5 888.19 -107.54 892.43 -109.21 906.47 -102.35 909.36 -97.3 903.6 -90.02 911.07 -85.03 911.2 -75.91 Z"},"55041":{"name":"Forest","path":"M 818.38 -40.74 L 817.42 -110.49 828.14 -110.62 828.07 -122.96 839.14 -116.2 851.6 -115.35 852.93 -76.03 876.6 -76.41 877.26 -29.84 829.95 -29.27 830.07 -40.94 Z"},"55043":{"name":"Grant","path":"M 633.36 334.13 L 623.04 326.89 612.65 293.2 622.35 292.62 674.06 263.53 685.46 265.02 685.3 358.68 663.87 358.37 657.2 341.06 Z"},"55047":{"name":"Green Lake","path":"M 825.21 206.22 L 801.82 205.13 801.66 188.49 806.21 182.21 808.87 159.22 836.37 158.83 837.05 206.0 Z"},"55049":{"name":"Iowa","path":"M 743.95 317.37 L 685.47 317.4 685.46 265.02 699.02 264.28 708.75 270.04 743.87 264.43 Z"},"55055":{"name":"Jefferson","path":"M 872.29 276.4 L 872.76 312.12 825.88 312.25 825.74 264.96 872.45 264.46 Z"},"55057":{"name":"Juneau","path":"M 748.88 205.73 L 697.29 205.7 697.64 123.72 737.34 123.68 735.09 131.34 737.28 133.22 725.09 145.16 730.92 158.13 731.98 176.23 741.04 186.57 Z"},"55059":{"name":"Kenosha","path":"M 946.24 350.32 L 947.66 357.8 897.28 358.65 896.83 342.99 908.56 342.64 908.37 334.78 946.48 334.03 Z"},"55065":{"name":"Lafayette","path":"M 685.47 317.4 L 743.95 317.37 744.12 358.99 685.3 358.68 Z"},"55075":{"name":"Marinette","path":"M 966.76 10.47 L 967.2 10.52 967.73 11.26 966.18 10.7 Z M 958.01 6.14 L 954.66 22.21 942.04 24.07 924.55 20.86 924.59 17.17 907.55 17.17 907.49 5.49 900.77 5.42 900.78 -6.18 889.07 -6.42 888.88 -29.76 877.26 -29.84 876.6 -76.41 911.2 -75.91 911.07 -85.03 917.32 -87.17 935.02 -75.85 937.61 -72.19 933.64 -69.31 936.79 -63.59 937.16 -47.85 928.65 -28.02 941.64 -27.98 946.95 -33.28 950.51 -30.53 951.51 -26.6 943.15 -7.31 951.3 4.69 Z"},"55077":{"name":"Marquette","path":"M 767.09 205.45 L 767.05 159.65 808.87 159.22 806.21 182.21 801.66 188.49 801.82 205.13 Z"},"55083":{"name":"Oconto","path":"M 942.04 24.07 L 934.86 28.86 935.64 35.69 929.28 43.09 921.28 63.5 896.96 63.8 895.91 40.48 872.8 40.59 872.64 5.33 857.62 5.54 853.71 -6.21 853.53 -29.63 888.88 -29.76 889.07 -6.42 900.78 -6.18 900.77 5.42 907.49 5.49 907.55 17.17 924.59 17.17 924.55 20.86 Z"},"55085":{"name":"Oneida","path":"M 723.78 -52.37 L 723.86 -98.5 793.73 -99.37 793.76 -93.9 805.6 -93.43 805.25 -99.2 817.57 -98.79 818.38 -40.74 782.46 -40.73 782.05 -52.6 Z"},"55091":{"name":"Pepin","path":"M 569.13 63.48 L 568.9 75.21 532.36 75.76 526.45 99.9 513.33 94.94 505.72 86.64 504.51 81.14 521.97 81.79 522.5 62.27 Z"},"55093":{"name":"Pierce","path":"M 462.61 39.94 L 463.1 36.47 523.02 38.89 521.97 81.79 504.51 81.14 482.18 75.7 458.64 52.09 Z"},"55097":{"name":"Portage","path":"M 766.87 124.09 L 754.58 123.88 754.28 88.34 742.91 88.33 742.81 64.94 802.58 65.07 803.04 124.12 Z"},"55061":{"name":"Kewaunee","path":"M 980.59 62.04 L 972.0 79.0 965.72 109.48 944.12 110.16 944.54 64.29 Z"},"55031":{"name":"Douglas","path":"M 522.46 -202.87 L 524.88 -211.92 531.71 -215.93 547.57 -206.26 561.8 -207.91 584.11 -215.67 582.54 -134.96 513.0 -136.68 515.11 -204.87 Z"},"55051":{"name":"Iron","path":"M 676.79 -191.31 L 680.86 -192.02 701.41 -182.36 712.33 -171.69 716.64 -157.79 734.52 -152.83 734.58 -109.93 699.5 -109.9 699.49 -133.3 687.95 -133.24 688.04 -144.89 676.23 -145.02 Z"},"55071":{"name":"Manitowoc","path":"M 965.72 109.48 L 969.2 127.55 956.59 139.82 949.17 168.71 918.9 169.59 917.6 122.49 932.64 122.18 932.38 110.43 Z"},"55079":{"name":"Milwaukee","path":"M 936.0 263.58 L 935.41 272.52 938.96 279.38 935.93 285.61 941.47 294.48 943.72 310.6 919.59 311.07 919.1 264.0 Z"},"55089":{"name":"Ozaukee","path":"M 933.89 256.07 L 936.0 263.58 919.1 264.0 920.18 216.7 944.34 215.97 944.63 222.75 937.26 238.15 Z"},"55131":{"name":"Washington","path":"M 920.18 216.7 L 919.1 264.0 884.08 264.42 884.87 217.33 Z"},"55001":{"name":"Adams","path":"M 737.34 123.68 L 766.87 124.09 767.09 205.45 748.88 205.73 741.04 186.57 731.98 176.23 730.92 158.13 725.09 145.16 737.28 133.22 735.09 131.34 Z"},"55105":{"name":"Rock","path":"M 849.38 313.66 L 850.15 359.62 791.24 359.46 790.56 312.92 Z"},"55117":{"name":"Sheboygan","path":"M 949.17 168.71 L 952.76 196.22 944.34 215.97 908.37 216.9 907.15 169.89 Z"},"55127":{"name":"Walworth","path":"M 856.23 312.45 L 896.11 311.77 897.28 358.65 850.15 359.62 849.37 312.55 Z"},"55009":{"name":"Brown","path":"M 921.28 63.5 L 920.66 72.73 916.59 78.59 923.63 83.31 927.63 82.44 933.36 72.52 943.29 67.38 944.12 110.16 932.38 110.43 932.64 122.18 903.12 122.71 902.25 76.21 897.0 76.6 896.96 63.8 Z"},"55137":{"name":"Waushara","path":"M 835.83 123.85 L 836.37 158.83 767.05 159.65 766.87 124.09 Z"}},
paper = Raphael('map', 600, 650),
set = paper.set(),
colors = ['#bc5c5c', '#5c6b95'],
county,
countyObj,
box,
translateX,
translateY,
x,
y,
r
;
// Loop through the counties and draw each one.
for (fips in counties) {
county = counties[fips];
countyObj = paper.path(county.path).attr({
'fill': colors[Math.floor(Math.random()*2)],
'stroke': '#fff',
'stroke-width': 1
});
countyObj['fips'] = fips;
set.push(countyObj);
}
// Center the map in the div
box = set.getBBox();
translateX = -box.x;
translateY = -box.y+1;
set.translate(translateX, translateY);
// We can't animate a path to a circle;
// only to another path. But we can fake it
// by making a path of a circle.
var circleToPath = function (x, y, r) {
return "M"+x+","+(y-r)+"A"+r+","+r+",0,1,1,"+(x-0.1)+","+(y-r)+"z";
}
$("#animate").bind('click', function(e) {
for (i=0; i<set.length; i++) {
x = Math.random()*550;
y = Math.random()*550;
r = Math.random()*20;
set[i].animate({'path': circleToPath(x+r, y+r, r)}, 500);
}
});
}())
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment