diff --git a/assets/img/background-image.jpg b/assets/img/background-image.jpg new file mode 100644 index 0000000..09d4fd1 Binary files /dev/null and b/assets/img/background-image.jpg differ diff --git a/css/styles.css b/css/styles.css new file mode 100644 index 0000000..9b5cad3 --- /dev/null +++ b/css/styles.css @@ -0,0 +1,104 @@ +.google-visualization-tooltip{ + width:50% !important; + border: 1px solid lightgrey !important; + +} + +body { + margin: 0; + padding: 0; +} + +span { + display: block;; +} + +#hero { + background: linear-gradient( + rgba(255,255,255,.5), + rgba(255,255,255,.9)), + url(../assets/img/background-image.jpg); + background-attachment: fixed; + background-position: center; + background-repeat: no-repeat; + background-size: cover; + display: flex; + align-items: center; + justify-content: center; + height: 70vh; + width: 100%; +} + +hr { +width: 25%; +margin: 45px auto; +} + +h2 > span, h4 > span { + display: block; +} + + .highcharts-button { + visibility: hidden !important; +} + +.nav-link.active { + background-color: #e95122!important ; +} + +.nav-link { + background-color: lightgrey; +} + +/* for D# charts styling */ + +.arc text { + font: 10px sans-serif; + text-anchor: middle; +} + +.arc path { + stroke: #fff; +} + +.arc2 text { + font: 10px sans-serif; + text-anchor: middle; +} + +.arc2 path { + stroke: #fff; +} + +#men_pieChart1, #men_pieChart2, #women_pieChart1, #women_pieChart2 { + height: 360px; + margin: 0 auto; + position: relative; + width: 360px; +} + +.tooltipMen1, .tooltipMen2, .tooltipWomen1, .tooltipWomen2 { + background: #eee; + box-shadow: 0 0 5px #999999; + color: #333; + display: none; + font-size: 12px; + left: 130px; + padding: 10px; + position: absolute; + text-align: center; + top: 95px; + width: 80px; + z-index: 10; +} +.legend { + font-size: 12px; +} +rect { + cursor: pointer; + stroke-width: 2; +} +rect.disabled { + fill: transparent !important; +} + diff --git a/data/data-gender-age.csv b/data/data-gender-age.csv new file mode 100755 index 0000000..9b84c7e --- /dev/null +++ b/data/data-gender-age.csv @@ -0,0 +1,13 @@ +Preparedness,Age,Gender,Percent Value +ready,19 to 27,men,0.04 +somewhat ready,19 to 27,men,0.33 +not ready,19 to 27,men,0.63 +ready,28 to 36,men,0.12 +somewhat ready,28 to 36,men,0.36 +not ready,28 to 36,men,0.52 +ready,19 to 27,women,0.08 +somewhat ready,19 to 27,women,0.33 +not ready,19 to 27,women,0.59 +ready,28 to 36,women,0.18 +somewhat ready,28 to 36,women,0.53 +not ready,28 to 36,women,0.29 \ No newline at end of file diff --git a/data/data-state.json b/data/data-state.json new file mode 100644 index 0000000..d1bea35 --- /dev/null +++ b/data/data-state.json @@ -0,0 +1,361 @@ +{ +"states": [ +{ +"StateAbbv": "AK", +"State": "alaska", +"Percent of Population": 46, +"Median Household Income": "$75,723", +"Percent of Income": "2%" +}, +{ +"StateAbbv": "AL", +"State": "alabama", +"Percent of Population": 47, +"Median Household Income": "$47,221", +"Percent of Income": "3%" +}, +{ +"StateAbbv": "AR", +"State": "arkansas", +"Percent of Population": 44, +"Median Household Income": "$45,907", +"Percent of Income": "3%" +}, +{ +"StateAbbv": "AZ", +"State": "arizona", +"Percent of Population": 44, +"Median Household Income": "$57,100", +"Percent of Income": "2%" +}, +{ +"StateAbbv": "CA", +"State": "california", +"Percent of Population": 46, +"Median Household Income": "$66,637", +"Percent of Income": "2%" +}, +{ +"StateAbbv": "CO", +"State": "colorado", +"Percent of Population": 52, +"Median Household Income": "$70,566", +"Percent of Income": "2%" +}, +{ +"StateAbbv": "CT", +"State": "connecticut", +"Percent of Population": 54, +"Median Household Income": "$75,923", +"Percent of Income": "2%" +}, +{ +"StateAbbv": "DC", +"State": "district of columbia", +"Percent of Population": 51, +"Median Household Income": "$70,982", +"Percent of Income": "2%" +}, +{ +"StateAbbv": "DE", +"State": "delaware", +"Percent of Population": 47, +"Median Household Income": "$58,046", +"Percent of Income": "2%" +}, +{ +"StateAbbv": "FL", +"State": "florida", +"Percent of Population": 42, +"Median Household Income": "$51,176", +"Percent of Income": "3%" +}, +{ +"StateAbbv": "GA", +"State": "georgia", +"Percent of Population": 49, +"Median Household Income": "$53,527", +"Percent of Income": "3%" +}, +{ +"StateAbbv": "HI", +"State": "hawaii", +"Percent of Population": 55, +"Median Household Income": "$72,133", +"Percent of Income": "1%" +}, +{ +"StateAbbv": "IA", +"State": "iowa", +"Percent of Population": 54, +"Median Household Income": "$59,094", +"Percent of Income": "2%" +}, +{ +"StateAbbv": "ID", +"State": "idaho", +"Percent of Population": 48, +"Median Household Income": "$56,564", +"Percent of Income": "2%" +}, +{ +"StateAbbv": "IL", +"State": "illinois", +"Percent of Population": 51, +"Median Household Income": "$61,386", +"Percent of Income": "2%" +}, +{ +"StateAbbv": "IN", +"State": "indiana", +"Percent of Population": 52, +"Median Household Income": "$56,094", +"Percent of Income": "2%" +}, +{ +"StateAbbv": "KS", +"State": "kansas", +"Percent of Population": 53, +"Median Household Income": "$56,810", +"Percent of Income": "2%" +}, +{ +"StateAbbv": "KY", +"State": "kentucky", +"Percent of Population": 44, +"Median Household Income": "$45,369", +"Percent of Income": "3%" +}, +{ +"StateAbbv": "LA", +"State": "louisiana", +"Percent of Population": 42, +"Median Household Income": "$42,196", +"Percent of Income": "3%" +}, +{ +"StateAbbv": "MA", +"State": "massachusetts", +"Percent of Population": 54, +"Median Household Income": "$72,266", +"Percent of Income": "2%" +}, +{ +"StateAbbv": "MD", +"State": "maryland", +"Percent of Population": 54, +"Median Household Income": "$73,760", +"Percent of Income": "2%" +}, +{ +"StateAbbv": "ME", +"State": "maine", +"Percent of Population": 49, +"Median Household Income": "$50,856", +"Percent of Income": "3%" +}, +{ +"StateAbbv": "MI", +"State": "michigan", +"Percent of Population": 51, +"Median Household Income": "$57,091", +"Percent of Income": "2%" +}, +{ +"StateAbbv": "MN", +"State": "minnesota", +"Percent of Population": 55, +"Median Household Income": "$70,218", +"Percent of Income": "2%" +}, +{ +"StateAbbv": "MO", +"State": "missouri", +"Percent of Population": 51, +"Median Household Income": "$55,016", +"Percent of Income": "2%" +}, +{ +"StateAbbv": "MS", +"State": "mississippi", +"Percent of Population": 42, +"Median Household Income": "$41,099", +"Percent of Income": "3%" +}, +{ +"StateAbbv": "MT", +"State": "montana", +"Percent of Population": 43, +"Median Household Income": "$57,075", +"Percent of Income": "2%" +}, +{ +"StateAbbv": "NC", +"State": "north carolina", +"Percent of Population": 45, +"Median Household Income": "$53,764", +"Percent of Income": "2%" +}, +{ +"StateAbbv": "ND", +"State": "north dakota", +"Percent of Population": 55, +"Median Household Income": "$60,184", +"Percent of Income": "2%" +}, +{ +"StateAbbv": "NE", +"State": "nebraska", +"Percent of Population": 55, +"Median Household Income": "$59,374", +"Percent of Income": "2%" +}, +{ +"StateAbbv": "NH", +"State": "new hampshire", +"Percent of Population": 58, +"Median Household Income": "$76,260", +"Percent of Income": "2%" +}, +{ +"StateAbbv": "NJ", +"State": "new jersey", +"Percent of Population": 55, +"Median Household Income": "$68,468", +"Percent of Income": "3%" +}, +{ +"StateAbbv": "NM", +"State": "new mexico", +"Percent of Population": 36, +"Median Household Income": "$48,451", +"Percent of Income": "3%" +}, +{ +"StateAbbv": "NV", +"State": "nevada", +"Percent of Population": 50, +"Median Household Income": "$55,431", +"Percent of Income": "2%" +}, +{ +"StateAbbv": "NY", +"State": "new york", +"Percent of Population": 50, +"Median Household Income": "$61,437", +"Percent of Income": "2%" +}, +{ +"StateAbbv": "OH", +"State": "ohio", +"Percent of Population": 51, +"Median Household Income": "$53,985", +"Percent of Income": "3%" +}, +{ +"StateAbbv": "OK", +"State": "oklahoma", +"Percent of Population": 48, +"Median Household Income": "$50,943", +"Percent of Income": "2%" +}, +{ +"StateAbbv": "OR", +"State": "oregon", +"Percent of Population": 46, +"Median Household Income": "$59,135", +"Percent of Income": "2%" +}, +{ +"StateAbbv": "PA", +"State": "pennsylvania", +"Percent of Population": 53, +"Median Household Income": "$60,979", +"Percent of Income": "2%" +}, +{ +"StateAbbv": "RI", +"State": "rhode island", +"Percent of Population": 51, +"Median Household Income": "$61,528", +"Percent of Income": "3%" +}, +{ +"StateAbbv": "SC", +"State": "south carolina", +"Percent of Population": 46, +"Median Household Income": "$54,336", +"Percent of Income": "3%" +}, +{ +"StateAbbv": "SD", +"State": "south dakota", +"Percent of Population": 49, +"Median Household Income": "$57,450", +"Percent of Income": "2%" +}, +{ +"StateAbbv": "TN", +"State": "tennessee", +"Percent of Population": 46, +"Median Household Income": "$51,344", +"Percent of Income": "2%" +}, +{ +"StateAbbv": "TX", +"State": "texas", +"Percent of Population": 49, +"Median Household Income": "$58,146", +"Percent of Income": "2%" +}, +{ +"StateAbbv": "UT", +"State": "utah", +"Percent of Population": 60, +"Median Household Income": "$67,481", +"Percent of Income": "2%" +}, +{ +"StateAbbv": "VA", +"State": "virginia", +"Percent of Population": 55, +"Median Household Income": "$66,451", +"Percent of Income": "2%" +}, +{ +"StateAbbv": "VT", +"State": "vermont", +"Percent of Population": 47, +"Median Household Income": "$60,837", +"Percent of Income": "2%" +}, +{ +"StateAbbv": "WA", +"State": "washington", +"Percent of Population": 49, +"Median Household Income": "$70,310", +"Percent of Income": "1%" +}, +{ +"StateAbbv": "WI", +"State": "wisconsin", +"Percent of Population": 56, +"Median Household Income": "$59,817", +"Percent of Income": "2%" +}, +{ +"StateAbbv": "WV", +"State": "west virginia", +"Percent of Population": 43, +"Median Household Income": "$44,354", +"Percent of Income": "3%" +}, +{ +"StateAbbv": "WY", +"State": "wyoming", +"Percent of Population": 55, +"Median Household Income": "$57,829", +"Percent of Income": "2%" +} +] +} \ No newline at end of file diff --git a/data/data-states.csv b/data/data-states.csv new file mode 100755 index 0000000..2bb4c4d --- /dev/null +++ b/data/data-states.csv @@ -0,0 +1,52 @@ +State Abbv,State,Percent of Population,Median Household Income,Percent of Income +AK,ALASKA,46,"$75,723",2% +AL,ALABAMA,47,"$47,221",3% +AR,ARKANSAS,44,"$45,907",3% +AZ,ARIZONA,44,"$57,100",2% +CA,CALIFORNIA,46,"$66,637",2% +CO,COLORADO,52,"$70,566",2% +CT,CONNECTICUT,54,"$75,923",2% +DC,DISTRICT OF COLUMBIA,51,"$70,982",2% +DE,DELAWARE,47,"$58,046",2% +FL,FLORIDA,42,"$51,176",3% +GA,GEORGIA,49,"$53,527",3% +HI,HAWAII,55,"$72,133",1% +IA,IOWA,54,"$59,094",2% +ID,IDAHO,48,"$56,564",2% +IL,ILLINOIS,51,"$61,386",2% +IN,INDIANA,52,"$56,094",2% +KS,KANSAS,53,"$56,810",2% +KY,KENTUCKY,44,"$45,369",3% +LA,LOUISIANA,42,"$42,196",3% +MA,MASSACHUSETTS,54,"$72,266",2% +MD,MARYLAND,54,"$73,760",2% +ME,MAINE,49,"$50,856",3% +MI,MICHIGAN,51,"$57,091",2% +MN,MINNESOTA,55,"$70,218",2% +MO,MISSOURI,51,"$55,016",2% +MS,MISSISSIPPI,42,"$41,099",3% +MT,MONTANA,43,"$57,075",2% +NC,NORTH CAROLINA,45,"$53,764",2% +ND,NORTH DAKOTA,55,"$60,184",2% +NE,NEBRASKA,55,"$59,374",2% +NH,NEW HAMPSHIRE,58,"$76,260",2% +NJ,NEW JERSEY,55,"$68,468",3% +NM,NEW MEXICO,36,"$48,451",3% +NV,NEVADA,50,"$55,431",2% +NY,NEW YORK,50,"$61,437",2% +OH,OHIO,51,"$53,985",3% +OK,OKLAHOMA,48,"$50,943",2% +OR,OREGON,46,"$59,135",2% +PA,PENNSYLVANIA,53,"$60,979",2% +RI,RHODE ISLAND,51,"$61,528",3% +SC,SOUTH CAROLINA,46,"$54,336",3% +SD,SOUTH DAKOTA,49,"$57,450",2% +TN,TENNESSEE,46,"$51,344",2% +TX,TEXAS,49,"$58,146",2% +UT,UTAH,60,"$67,481",2% +VA,VIRGINIA,55,"$66,451",2% +VT,VERMONT,47,"$60,837",2% +WA,WASHINGTON,49,"$70,310",1% +WI,WISCONSIN,56,"$59,817",2% +WV,WEST VIRGINIA,43,"$44,354",3% +WY,WYOMING,55,"$57,829",2% \ No newline at end of file diff --git a/data/men19to27.csv b/data/men19to27.csv new file mode 100644 index 0000000..f3ed008 --- /dev/null +++ b/data/men19to27.csv @@ -0,0 +1,4 @@ +Preparedness,PercentValue +ready,4 +somewhat ready,33 +not ready,63 \ No newline at end of file diff --git a/data/men28to36.csv b/data/men28to36.csv new file mode 100644 index 0000000..6abe520 --- /dev/null +++ b/data/men28to36.csv @@ -0,0 +1,4 @@ +Preparedness,PercentValue +ready,12 +somewhat ready,36 +not ready,52 \ No newline at end of file diff --git a/data/state.json b/data/state.json new file mode 100644 index 0000000..f4c9fb6 --- /dev/null +++ b/data/state.json @@ -0,0 +1,362 @@ +{"states": + + [ + { + "StateAbbv": "AK", + "State": "Alaska", + "Percent of Population": 46, + "Median Household Income": "$75,723", + "Percent of Income": "2%" + }, + { + "StateAbbv": "AL", + "State": "Alabama", + "Percent of Population": 47, + "Median Household Income": "$47,221", + "Percent of Income": "3%" + }, + { + "StateAbbv": "AR", + "State": "Arkansas", + "Percent of Population": 44, + "Median Household Income": "$45,907", + "Percent of Income": "3%" + }, + { + "StateAbbv": "AZ", + "State": "arizona", + "Percent of Population": 44, + "Median Household Income": "$57,100", + "Percent of Income": "2%" + }, + { + "StateAbbv": "CA", + "State": "California", + "Percent of Population": 46, + "Median Household Income": "$66,637", + "Percent of Income": "2%" + }, + { + "StateAbbv": "CO", + "State": "Colorado", + "Percent of Population": 52, + "Median Household Income": "$70,566", + "Percent of Income": "2%" + }, + { + "StateAbbv": "CT", + "State": "Connecticut", + "Percent of Population": 54, + "Median Household Income": "$75,923", + "Percent of Income": "2%" + }, + { + "StateAbbv": "DC", + "State": "District of Columbia", + "Percent of Population": 51, + "Median Household Income": "$70,982", + "Percent of Income": "2%" + }, + { + "StateAbbv": "DE", + "State": "Delaware", + "Percent of Population": 47, + "Median Household Income": "$58,046", + "Percent of Income": "2%" + }, + { + "StateAbbv": "FL", + "State": "Florida", + "Percent of Population": 42, + "Median Household Income": "$51,176", + "Percent of Income": "3%" + }, + { + "StateAbbv": "GA", + "State": "Georgia", + "Percent of Population": 49, + "Median Household Income": "$53,527", + "Percent of Income": "3%" + }, + { + "StateAbbv": "HI", + "State": "Hawaii", + "Percent of Population": 55, + "Median Household Income": "$72,133", + "Percent of Income": "1%" + }, + { + "StateAbbv": "IA", + "State": "Iowa", + "Percent of Population": 54, + "Median Household Income": "$59,094", + "Percent of Income": "2%" + }, + { + "StateAbbv": "ID", + "State": "Idaho", + "Percent of Population": 48, + "Median Household Income": "$56,564", + "Percent of Income": "2%" + }, + { + "StateAbbv": "IL", + "State": "Illinois", + "Percent of Population": 51, + "Median Household Income": "$61,386", + "Percent of Income": "2%" + }, + { + "StateAbbv": "IN", + "State": "Indiana", + "Percent of Population": 52, + "Median Household Income": "$56,094", + "Percent of Income": "2%" + }, + { + "StateAbbv": "KS", + "State": "Kansas", + "Percent of Population": 53, + "Median Household Income": "$56,810", + "Percent of Income": "2%" + }, + { + "StateAbbv": "KY", + "State": "Kentucky", + "Percent of Population": 44, + "Median Household Income": "$45,369", + "Percent of Income": "3%" + }, + { + "StateAbbv": "LA", + "State": "Louisiana", + "Percent of Population": 42, + "Median Household Income": "$42,196", + "Percent of Income": "3%" + }, + { + "StateAbbv": "MA", + "State": "Massachusetts", + "Percent of Population": 54, + "Median Household Income": "$72,266", + "Percent of Income": "2%" + }, + { + "StateAbbv": "MD", + "State": "Maryland", + "Percent of Population": 54, + "Median Household Income": "$73,760", + "Percent of Income": "2%" + }, + { + "StateAbbv": "ME", + "State": "Maine", + "Percent of Population": 49, + "Median Household Income": "$50,856", + "Percent of Income": "3%" + }, + { + "StateAbbv": "MI", + "State": "Michigan", + "Percent of Population": 51, + "Median Household Income": "$57,091", + "Percent of Income": "2%" + }, + { + "StateAbbv": "MN", + "State": "Minnesota", + "Percent of Population": 55, + "Median Household Income": "$70,218", + "Percent of Income": "2%" + }, + { + "StateAbbv": "MO", + "State": "Missouri", + "Percent of Population": 51, + "Median Household Income": "$55,016", + "Percent of Income": "2%" + }, + { + "StateAbbv": "MS", + "State": "Mississippi", + "Percent of Population": 42, + "Median Household Income": "$41,099", + "Percent of Income": "3%" + }, + { + "StateAbbv": "MT", + "State": "Montana", + "Percent of Population": 43, + "Median Household Income": "$57,075", + "Percent of Income": "2%" + }, + { + "StateAbbv": "NC", + "State": "North Carolina", + "Percent of Population": 45, + "Median Household Income": "$53,764", + "Percent of Income": "2%" + }, + { + "StateAbbv": "ND", + "State": "North Dakota", + "Percent of Population": 55, + "Median Household Income": "$60,184", + "Percent of Income": "2%" + }, + { + "StateAbbv": "NE", + "State": "Nebraska", + "Percent of Population": 55, + "Median Household Income": "$59,374", + "Percent of Income": "2%" + }, + { + "StateAbbv": "NH", + "State": "New Hampshire", + "Percent of Population": 58, + "Median Household Income": "$76,260", + "Percent of Income": "2%" + }, + { + "StateAbbv": "NJ", + "State": "New Jersey", + "Percent of Population": 55, + "Median Household Income": "$68,468", + "Percent of Income": "3%" + }, + { + "StateAbbv": "NM", + "State": "New Mexico", + "Percent of Population": 36, + "Median Household Income": "$48,451", + "Percent of Income": "3%" + }, + { + "StateAbbv": "NV", + "State": "Nevada", + "Percent of Population": 50, + "Median Household Income": "$55,431", + "Percent of Income": "2%" + }, + { + "StateAbbv": "NY", + "State": "New York", + "Percent of Population": 50, + "Median Household Income": "$61,437", + "Percent of Income": "2%" + }, + { + "StateAbbv": "OH", + "State": "Ohio", + "Percent of Population": 51, + "Median Household Income": "$53,985", + "Percent of Income": "3%" + }, + { + "StateAbbv": "OK", + "State": "Oklahoma", + "Percent of Population": 48, + "Median Household Income": "$50,943", + "Percent of Income": "2%" + }, + { + "StateAbbv": "OR", + "State": "Oregon", + "Percent of Population": 46, + "Median Household Income": "$59,135", + "Percent of Income": "2%" + }, + { + "StateAbbv": "PA", + "State": "Pennsylvania", + "Percent of Population": 53, + "Median Household Income": "$60,979", + "Percent of Income": "2%" + }, + { + "StateAbbv": "RI", + "State": "Rhode Island", + "Percent of Population": 51, + "Median Household Income": "$61,528", + "Percent of Income": "3%" + }, + { + "StateAbbv": "SC", + "State": "South Carolina", + "Percent of Population": 46, + "Median Household Income": "$54,336", + "Percent of Income": "3%" + }, + { + "StateAbbv": "SD", + "State": "South Dakota", + "Percent of Population": 49, + "Median Household Income": "$57,450", + "Percent of Income": "2%" + }, + { + "StateAbbv": "TN", + "State": "Tennessee", + "Percent of Population": 46, + "Median Household Income": "$51,344", + "Percent of Income": "2%" + }, + { + "StateAbbv": "TX", + "State": "Texas", + "Percent of Population": 49, + "Median Household Income": "$58,146", + "Percent of Income": "2%" + }, + { + "StateAbbv": "UT", + "State": "Utah", + "Percent of Population": 60, + "Median Household Income": "$67,481", + "Percent of Income": "2%" + }, + { + "StateAbbv": "VA", + "State": "Virginia", + "Percent of Population": 55, + "Median Household Income": "$66,451", + "Percent of Income": "2%" + }, + { + "StateAbbv": "VT", + "State": "Vermont", + "Percent of Population": 47, + "Median Household Income": "$60,837", + "Percent of Income": "2%" + }, + { + "StateAbbv": "WA", + "State": "Washington", + "Percent of Population": 49, + "Median Household Income": "$70,310", + "Percent of Income": "1%" + }, + { + "StateAbbv": "WI", + "State": "Wisconsin", + "Percent of Population": 56, + "Median Household Income": "$59,817", + "Percent of Income": "2%" + }, + { + "StateAbbv": "WV", + "State": "West Virginia", + "Percent of Population": 43, + "Median Household Income": "$44,354", + "Percent of Income": "3%" + }, + { + "StateAbbv": "WY", + "State": "Wyoming", + "Percent of Population": 55, + "Median Household Income": "$57,829", + "Percent of Income": "2%" + } + ] +} \ No newline at end of file diff --git a/data/women19to27.csv b/data/women19to27.csv new file mode 100644 index 0000000..5417b4c --- /dev/null +++ b/data/women19to27.csv @@ -0,0 +1,4 @@ +Preparedness,PercentValue +ready,8 +somewhat ready,33 +not ready,59 \ No newline at end of file diff --git a/data/women28to36.csv b/data/women28to36.csv new file mode 100644 index 0000000..b4e0278 --- /dev/null +++ b/data/women28to36.csv @@ -0,0 +1,4 @@ +Preparedness,PercentValue +ready,18 +somewhat ready,53 +not ready,29 \ No newline at end of file diff --git a/index.html b/index.html new file mode 100644 index 0000000..f20a3ae --- /dev/null +++ b/index.html @@ -0,0 +1,177 @@ + + + + + + + + + + + + GeoCharts and D3 Pie Charts + + + +
+
+
+

Region GeoChart Stats + Method 1 +

+

(json file was pasted in an array to create the Geochart.
+ The json file was created using an online .cvs to .json tool)

+
+
+
+ +
+
+
+
+
+
+
+ +
+
+
+

Region GeoChart Stats + Method 2 +

+

(data pulled from json file on project folder.
+ The json file was created using an online .cvs to .json tool)

+
+
+
+ +
+
+
+
+
+
+
+ +
+
+
+

Region GeoChart Stats + Method 3 +

+

(data pulled from csv file
on project folder.

+
+
+
+ +
+
+
+
+
+
+
+ +
+ +
+
+
+

State of Preparedness by Gender + and Age Group +

+

(click button to toggle between stats)

+
+
+
+
+
+ +
+
+ + +
+
+ + + +
+

State of Preparedness of Women + Ages 19 to 27

+

(data visualization using D3 piecharts.Data from attached csv file on project folder)

+
+
+ +
+

State of Preparedness of Women + Ages 28 to 36

+

(data visualization using D3 piecharts.Data from attached csv file on project folder)

+ +
+
+
+
+
+ +
+ + +
+
+ + + +
+

State of Preparedness of Men + Ages 19 to 27

+

((data visualization using D3 piecharts.Data from attached csv file on project folder)

+
+
+ +
+

State of Preparedness of Men + Ages 28 to 36

+

(data visualization using D3 piecharts.Data from attached csv file on project folder)

+ +
+
+
+
+
+ +
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/js/jquery.csv.js b/js/jquery.csv.js new file mode 100755 index 0000000..944ae3f --- /dev/null +++ b/js/jquery.csv.js @@ -0,0 +1,980 @@ +/** + * jQuery-csv (jQuery Plugin) + * + * This document is licensed as free software under the terms of the + * MIT License: http://www.opensource.org/licenses/mit-license.php + * + * Acknowledgements: + * The original design and influence to implement this library as a jquery + * plugin is influenced by jquery-json (http://code.google.com/p/jquery-json/). + * If you're looking to use native JSON.Stringify but want additional backwards + * compatibility for browsers that don't support it, I highly recommend you + * check it out. + * + * A special thanks goes out to rwk@acm.org for providing a lot of valuable + * feedback to the project including the core for the new FSM + * (Finite State Machine) parsers. If you're looking for a stable TSV parser + * be sure to take a look at jquery-tsv (http://code.google.com/p/jquery-tsv/). + + * For legal purposes I'll include the "NO WARRANTY EXPRESSED OR IMPLIED. + * USE AT YOUR OWN RISK.". Which, in 'layman's terms' means, by using this + * library you are accepting responsibility if it breaks your code. + * + * Legal jargon aside, I will do my best to provide a useful and stable core + * that can effectively be built on. + * + * Copyrighted 2012 by Evan Plaice. + */ + +RegExp.escape = function (s) { + return s.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&'); +}; + +(function () { + 'use strict'; + + var $; + + // to keep backwards compatibility + if (typeof jQuery !== 'undefined' && jQuery) { + $ = jQuery; + } else { + $ = {}; + } + + /** + * jQuery.csv.defaults + * Encapsulates the method paramater defaults for the CSV plugin module. + */ + + $.csv = { + defaults: { + separator: ',', + delimiter: '"', + headers: true + }, + + hooks: { + castToScalar: function (value, state) { + var hasDot = /\./; + if (isNaN(value)) { + return value; + } else { + if (hasDot.test(value)) { + return parseFloat(value); + } else { + var integer = parseInt(value); + if (isNaN(integer)) { + return null; + } else { + return integer; + } + } + } + } + }, + + parsers: { + parse: function (csv, options) { + // cache settings + var separator = options.separator; + var delimiter = options.delimiter; + + // set initial state if it's missing + if (!options.state.rowNum) { + options.state.rowNum = 1; + } + if (!options.state.colNum) { + options.state.colNum = 1; + } + + // clear initial state + var data = []; + var entry = []; + var state = 0; + var value = ''; + var exit = false; + + function endOfEntry () { + // reset the state + state = 0; + value = ''; + + // if 'start' hasn't been met, don't output + if (options.start && options.state.rowNum < options.start) { + // update global state + entry = []; + options.state.rowNum++; + options.state.colNum = 1; + return; + } + + if (options.onParseEntry === undefined) { + // onParseEntry hook not set + data.push(entry); + } else { + var hookVal = options.onParseEntry(entry, options.state); // onParseEntry Hook + // false skips the row, configurable through a hook + if (hookVal !== false) { + data.push(hookVal); + } + } + // console.log('entry:' + entry); + + // cleanup + entry = []; + + // if 'end' is met, stop parsing + if (options.end && options.state.rowNum >= options.end) { + exit = true; + } + + // update global state + options.state.rowNum++; + options.state.colNum = 1; + } + + function endOfValue () { + if (options.onParseValue === undefined) { + // onParseValue hook not set + entry.push(value); + } else { + var hook = options.onParseValue(value, options.state); // onParseValue Hook + // false skips the row, configurable through a hook + if (hook !== false) { + entry.push(hook); + } + } + // console.log('value:' + value); + // reset the state + value = ''; + state = 0; + // update global state + options.state.colNum++; + } + + // escape regex-specific control chars + var escSeparator = RegExp.escape(separator); + var escDelimiter = RegExp.escape(delimiter); + + // compile the regEx str using the custom delimiter/separator + var match = /(D|S|\r\n|\n|\r|[^DS\r\n]+)/; + var matchSrc = match.source; + matchSrc = matchSrc.replace(/S/g, escSeparator); + matchSrc = matchSrc.replace(/D/g, escDelimiter); + match = new RegExp(matchSrc, 'gm'); + + // put on your fancy pants... + // process control chars individually, use look-ahead on non-control chars + csv.replace(match, function (m0) { + if (exit) { + return; + } + switch (state) { + // the start of a value + case 0: + // null last value + if (m0 === separator) { + value += ''; + endOfValue(); + break; + } + // opening delimiter + if (m0 === delimiter) { + state = 1; + break; + } + // null last value + if (/^(\r\n|\n|\r)$/.test(m0)) { + endOfValue(); + endOfEntry(); + break; + } + // un-delimited value + value += m0; + state = 3; + break; + + // delimited input + case 1: + // second delimiter? check further + if (m0 === delimiter) { + state = 2; + break; + } + // delimited data + value += m0; + state = 1; + break; + + // delimiter found in delimited input + case 2: + // escaped delimiter? + if (m0 === delimiter) { + value += m0; + state = 1; + break; + } + // null value + if (m0 === separator) { + endOfValue(); + break; + } + // end of entry + if (/^(\r\n|\n|\r)$/.test(m0)) { + endOfValue(); + endOfEntry(); + break; + } + // broken paser? + throw new Error('CSVDataError: Illegal State [Row:' + options.state.rowNum + '][Col:' + options.state.colNum + ']'); + + // un-delimited input + case 3: + // null last value + if (m0 === separator) { + endOfValue(); + break; + } + // end of entry + if (/^(\r\n|\n|\r)$/.test(m0)) { + endOfValue(); + endOfEntry(); + break; + } + if (m0 === delimiter) { + // non-compliant data + throw new Error('CSVDataError: Illegal Quote [Row:' + options.state.rowNum + '][Col:' + options.state.colNum + ']'); + } + // broken parser? + throw new Error('CSVDataError: Illegal Data [Row:' + options.state.rowNum + '][Col:' + options.state.colNum + ']'); + default: + // shenanigans + throw new Error('CSVDataError: Unknown State [Row:' + options.state.rowNum + '][Col:' + options.state.colNum + ']'); + } + // console.log('val:' + m0 + ' state:' + state); + }); + + // submit the last entry + // ignore null last line + if (entry.length !== 0) { + endOfValue(); + endOfEntry(); + } + + return data; + }, + + // a csv-specific line splitter + splitLines: function (csv, options) { + if (!csv) { + return undefined; + } + + options = options || {}; + + // cache settings + var separator = options.separator || $.csv.defaults.separator; + var delimiter = options.delimiter || $.csv.defaults.delimiter; + + // set initial state if it's missing + options.state = options.state || {}; + if (!options.state.rowNum) { + options.state.rowNum = 1; + } + + // clear initial state + var entries = []; + var state = 0; + var entry = ''; + var exit = false; + + function endOfLine () { + // reset the state + state = 0; + + // if 'start' hasn't been met, don't output + if (options.start && options.state.rowNum < options.start) { + // update global state + entry = ''; + options.state.rowNum++; + return; + } + + if (options.onParseEntry === undefined) { + // onParseEntry hook not set + entries.push(entry); + } else { + var hookVal = options.onParseEntry(entry, options.state); // onParseEntry Hook + // false skips the row, configurable through a hook + if (hookVal !== false) { + entries.push(hookVal); + } + } + + // cleanup + entry = ''; + + // if 'end' is met, stop parsing + if (options.end && options.state.rowNum >= options.end) { + exit = true; + } + + // update global state + options.state.rowNum++; + } + + // escape regex-specific control chars + var escSeparator = RegExp.escape(separator); + var escDelimiter = RegExp.escape(delimiter); + + // compile the regEx str using the custom delimiter/separator + var match = /(D|S|\n|\r|[^DS\r\n]+)/; + var matchSrc = match.source; + matchSrc = matchSrc.replace(/S/g, escSeparator); + matchSrc = matchSrc.replace(/D/g, escDelimiter); + match = new RegExp(matchSrc, 'gm'); + + // put on your fancy pants... + // process control chars individually, use look-ahead on non-control chars + csv.replace(match, function (m0) { + if (exit) { + return; + } + switch (state) { + // the start of a value/entry + case 0: + // null value + if (m0 === separator) { + entry += m0; + state = 0; + break; + } + // opening delimiter + if (m0 === delimiter) { + entry += m0; + state = 1; + break; + } + // end of line + if (m0 === '\n') { + endOfLine(); + break; + } + // phantom carriage return + if (/^\r$/.test(m0)) { + break; + } + // un-delimit value + entry += m0; + state = 3; + break; + + // delimited input + case 1: + // second delimiter? check further + if (m0 === delimiter) { + entry += m0; + state = 2; + break; + } + // delimited data + entry += m0; + state = 1; + break; + + // delimiter found in delimited input + case 2: + // escaped delimiter? + var prevChar = entry.substr(entry.length - 1); + if (m0 === delimiter && prevChar === delimiter) { + entry += m0; + state = 1; + break; + } + // end of value + if (m0 === separator) { + entry += m0; + state = 0; + break; + } + // end of line + if (m0 === '\n') { + endOfLine(); + break; + } + // phantom carriage return + if (m0 === '\r') { + break; + } + // broken paser? + throw new Error('CSVDataError: Illegal state [Row:' + options.state.rowNum + ']'); + + // un-delimited input + case 3: + // null value + if (m0 === separator) { + entry += m0; + state = 0; + break; + } + // end of line + if (m0 === '\n') { + endOfLine(); + break; + } + // phantom carriage return + if (m0 === '\r') { + break; + } + // non-compliant data + if (m0 === delimiter) { + throw new Error('CSVDataError: Illegal quote [Row:' + options.state.rowNum + ']'); + } + // broken parser? + throw new Error('CSVDataError: Illegal state [Row:' + options.state.rowNum + ']'); + default: + // shenanigans + throw new Error('CSVDataError: Unknown state [Row:' + options.state.rowNum + ']'); + } + // console.log('val:' + m0 + ' state:' + state); + }); + + // submit the last entry + // ignore null last line + if (entry !== '') { + endOfLine(); + } + + return entries; + }, + + // a csv entry parser + parseEntry: function (csv, options) { + // cache settings + var separator = options.separator; + var delimiter = options.delimiter; + + // set initial state if it's missing + if (!options.state.rowNum) { + options.state.rowNum = 1; + } + if (!options.state.colNum) { + options.state.colNum = 1; + } + + // clear initial state + var entry = []; + var state = 0; + var value = ''; + + function endOfValue () { + if (options.onParseValue === undefined) { + // onParseValue hook not set + entry.push(value); + } else { + var hook = options.onParseValue(value, options.state); // onParseValue Hook + // false skips the value, configurable through a hook + if (hook !== false) { + entry.push(hook); + } + } + // reset the state + value = ''; + state = 0; + // update global state + options.state.colNum++; + } + + // checked for a cached regEx first + if (!options.match) { + // escape regex-specific control chars + var escSeparator = RegExp.escape(separator); + var escDelimiter = RegExp.escape(delimiter); + + // compile the regEx str using the custom delimiter/separator + var match = /(D|S|\n|\r|[^DS\r\n]+)/; + var matchSrc = match.source; + matchSrc = matchSrc.replace(/S/g, escSeparator); + matchSrc = matchSrc.replace(/D/g, escDelimiter); + options.match = new RegExp(matchSrc, 'gm'); + } + + // put on your fancy pants... + // process control chars individually, use look-ahead on non-control chars + csv.replace(options.match, function (m0) { + switch (state) { + // the start of a value + case 0: + // null last value + if (m0 === separator) { + value += ''; + endOfValue(); + break; + } + // opening delimiter + if (m0 === delimiter) { + state = 1; + break; + } + // skip un-delimited new-lines + if (m0 === '\n' || m0 === '\r') { + break; + } + // un-delimited value + value += m0; + state = 3; + break; + + // delimited input + case 1: + // second delimiter? check further + if (m0 === delimiter) { + state = 2; + break; + } + // delimited data + value += m0; + state = 1; + break; + + // delimiter found in delimited input + case 2: + // escaped delimiter? + if (m0 === delimiter) { + value += m0; + state = 1; + break; + } + // null value + if (m0 === separator) { + endOfValue(); + break; + } + // skip un-delimited new-lines + if (m0 === '\n' || m0 === '\r') { + break; + } + // broken paser? + throw new Error('CSVDataError: Illegal State [Row:' + options.state.rowNum + '][Col:' + options.state.colNum + ']'); + + // un-delimited input + case 3: + // null last value + if (m0 === separator) { + endOfValue(); + break; + } + // skip un-delimited new-lines + if (m0 === '\n' || m0 === '\r') { + break; + } + // non-compliant data + if (m0 === delimiter) { + throw new Error('CSVDataError: Illegal Quote [Row:' + options.state.rowNum + '][Col:' + options.state.colNum + ']'); + } + // broken parser? + throw new Error('CSVDataError: Illegal Data [Row:' + options.state.rowNum + '][Col:' + options.state.colNum + ']'); + default: + // shenanigans + throw new Error('CSVDataError: Unknown State [Row:' + options.state.rowNum + '][Col:' + options.state.colNum + ']'); + } + // console.log('val:' + m0 + ' state:' + state); + }); + + // submit the last value + endOfValue(); + + return entry; + } + }, + + helpers: { + + /** + * $.csv.helpers.collectPropertyNames(objectsArray) + * Collects all unique property names from all passed objects. + * + * @param {Array} objects Objects to collect properties from. + * + * Returns an array of property names (array will be empty, + * if objects have no own properties). + */ + collectPropertyNames: function (objects) { + var o = []; + var propName = []; + var props = []; + for (o in objects) { + for (propName in objects[o]) { + if ((objects[o].hasOwnProperty(propName)) && + (props.indexOf(propName) < 0) && + (typeof objects[o][propName] !== 'function')) { + props.push(propName); + } + } + } + return props; + } + }, + + /** + * $.csv.toArray(csv) + * Converts a CSV entry string to a javascript array. + * + * @param {Array} csv The string containing the CSV data. + * @param {Object} [options] An object containing user-defined options. + * @param {Character} [separator] An override for the separator character. Defaults to a comma(,). + * @param {Character} [delimiter] An override for the delimiter character. Defaults to a double-quote("). + * + * This method deals with simple CSV strings only. It's useful if you only + * need to parse a single entry. If you need to parse more than one line, + * use $.csv2Array instead. + */ + toArray: function (csv, options, callback) { + options = (options !== undefined ? options : {}); + var config = {}; + config.callback = ((callback !== undefined && typeof (callback) === 'function') ? callback : false); + config.separator = 'separator' in options ? options.separator : $.csv.defaults.separator; + config.delimiter = 'delimiter' in options ? options.delimiter : $.csv.defaults.delimiter; + var state = (options.state !== undefined ? options.state : {}); + + // setup + options = { + delimiter: config.delimiter, + separator: config.separator, + onParseEntry: options.onParseEntry, + onParseValue: options.onParseValue, + state: state + }; + + var entry = $.csv.parsers.parseEntry(csv, options); + + // push the value to a callback if one is defined + if (!config.callback) { + return entry; + } else { + config.callback('', entry); + } + }, + + /** + * $.csv.toArrays(csv) + * Converts a CSV string to a javascript array. + * + * @param {String} csv The string containing the raw CSV data. + * @param {Object} [options] An object containing user-defined options. + * @param {Character} [separator] An override for the separator character. Defaults to a comma(,). + * @param {Character} [delimiter] An override for the delimiter character. Defaults to a double-quote("). + * + * This method deals with multi-line CSV. The breakdown is simple. The first + * dimension of the array represents the line (or entry/row) while the second + * dimension contains the values (or values/columns). + */ + toArrays: function (csv, options, callback) { + options = (options !== undefined ? options : {}); + var config = {}; + config.callback = ((callback !== undefined && typeof (callback) === 'function') ? callback : false); + config.separator = 'separator' in options ? options.separator : $.csv.defaults.separator; + config.delimiter = 'delimiter' in options ? options.delimiter : $.csv.defaults.delimiter; + + // setup + var data = []; + options = { + delimiter: config.delimiter, + separator: config.separator, + onPreParse: options.onPreParse, + onParseEntry: options.onParseEntry, + onParseValue: options.onParseValue, + onPostParse: options.onPostParse, + start: options.start, + end: options.end, + state: { + rowNum: 1, + colNum: 1 + } + }; + + // onPreParse hook + if (options.onPreParse !== undefined) { + options.onPreParse(csv, options.state); + } + + // parse the data + data = $.csv.parsers.parse(csv, options); + + // onPostParse hook + if (options.onPostParse !== undefined) { + options.onPostParse(data, options.state); + } + + // push the value to a callback if one is defined + if (!config.callback) { + return data; + } else { + config.callback('', data); + } + }, + + /** + * $.csv.toObjects(csv) + * Converts a CSV string to a javascript object. + * @param {String} csv The string containing the raw CSV data. + * @param {Object} [options] An object containing user-defined options. + * @param {Character} [separator] An override for the separator character. Defaults to a comma(,). + * @param {Character} [delimiter] An override for the delimiter character. Defaults to a double-quote("). + * @param {Boolean} [headers] Indicates whether the data contains a header line. Defaults to true. + * + * This method deals with multi-line CSV strings. Where the headers line is + * used as the key for each value per entry. + */ + toObjects: function (csv, options, callback) { + options = (options !== undefined ? options : {}); + var config = {}; + config.callback = ((callback !== undefined && typeof (callback) === 'function') ? callback : false); + config.separator = 'separator' in options ? options.separator : $.csv.defaults.separator; + config.delimiter = 'delimiter' in options ? options.delimiter : $.csv.defaults.delimiter; + config.headers = 'headers' in options ? options.headers : $.csv.defaults.headers; + options.start = 'start' in options ? options.start : 1; + + // account for headers + if (config.headers) { + options.start++; + } + if (options.end && config.headers) { + options.end++; + } + + // setup + var lines = []; + var data = []; + + options = { + delimiter: config.delimiter, + separator: config.separator, + onPreParse: options.onPreParse, + onParseEntry: options.onParseEntry, + onParseValue: options.onParseValue, + onPostParse: options.onPostParse, + start: options.start, + end: options.end, + state: { + rowNum: 1, + colNum: 1 + }, + match: false, + transform: options.transform + }; + + // fetch the headers + var headerOptions = { + delimiter: config.delimiter, + separator: config.separator, + start: 1, + end: 1, + state: { + rowNum: 1, + colNum: 1 + } + }; + + // onPreParse hook + if (options.onPreParse !== undefined) { + options.onPreParse(csv, options.state); + } + + // parse the csv + var headerLine = $.csv.parsers.splitLines(csv, headerOptions); + var headers = $.csv.toArray(headerLine[0], options); + + // fetch the data + lines = $.csv.parsers.splitLines(csv, options); + + // reset the state for re-use + options.state.colNum = 1; + if (headers) { + options.state.rowNum = 2; + } else { + options.state.rowNum = 1; + } + + // convert data to objects + for (var i = 0, len = lines.length; i < len; i++) { + var entry = $.csv.toArray(lines[i], options); + var object = {}; + for (var j = 0; j < headers.length; j++) { + object[headers[j]] = entry[j]; + } + if (options.transform !== undefined) { + data.push(options.transform.call(undefined, object)); + } else { + data.push(object); + } + + // update row state + options.state.rowNum++; + } + + // onPostParse hook + if (options.onPostParse !== undefined) { + options.onPostParse(data, options.state); + } + + // push the value to a callback if one is defined + if (!config.callback) { + return data; + } else { + config.callback('', data); + } + }, + + /** + * $.csv.fromArrays(arrays) + * Converts a javascript array to a CSV String. + * + * @param {Array} arrays An array containing an array of CSV entries. + * @param {Object} [options] An object containing user-defined options. + * @param {Character} [separator] An override for the separator character. Defaults to a comma(,). + * @param {Character} [delimiter] An override for the delimiter character. Defaults to a double-quote("). + * + * This method generates a CSV file from an array of arrays (representing entries). + */ + fromArrays: function (arrays, options, callback) { + options = (options !== undefined ? options : {}); + var config = {}; + config.callback = ((callback !== undefined && typeof (callback) === 'function') ? callback : false); + config.separator = 'separator' in options ? options.separator : $.csv.defaults.separator; + config.delimiter = 'delimiter' in options ? options.delimiter : $.csv.defaults.delimiter; + + var output = ''; + var line; + var lineValues; + var i; + var j; + + for (i = 0; i < arrays.length; i++) { + line = arrays[i]; + lineValues = []; + for (j = 0; j < line.length; j++) { + var strValue = (line[j] === undefined || line[j] === null) ? '' : line[j].toString(); + if (strValue.indexOf(config.delimiter) > -1) { + strValue = strValue.replace(new RegExp(config.delimiter, 'g'), config.delimiter + config.delimiter); + } + + var escMatcher = '\n|\r|S|D'; + escMatcher = escMatcher.replace('S', config.separator); + escMatcher = escMatcher.replace('D', config.delimiter); + + if (strValue.search(escMatcher) > -1) { + strValue = config.delimiter + strValue + config.delimiter; + } + lineValues.push(strValue); + } + output += lineValues.join(config.separator) + '\n'; + } + + // push the value to a callback if one is defined + if (!config.callback) { + return output; + } else { + config.callback('', output); + } + }, + + /** + * $.csv.fromObjects(objects) + * Converts a javascript dictionary to a CSV string. + * + * @param {Object} objects An array of objects containing the data. + * @param {Object} [options] An object containing user-defined options. + * @param {Character} [separator] An override for the separator character. Defaults to a comma(,). + * @param {Character} [delimiter] An override for the delimiter character. Defaults to a double-quote("). + * @param {Character} [sortOrder] Sort order of columns (named after + * object properties). Use 'alpha' for alphabetic. Default is 'declare', + * which means, that properties will _probably_ appear in order they were + * declared for the object. But without any guarantee. + * @param {Character or Array} [manualOrder] Manually order columns. May be + * a strin in a same csv format as an output or an array of header names + * (array items won't be parsed). All the properties, not present in + * `manualOrder` will be appended to the end in accordance with `sortOrder` + * option. So the `manualOrder` always takes preference, if present. + * + * This method generates a CSV file from an array of objects (name:value pairs). + * It starts by detecting the headers and adding them as the first line of + * the CSV file, followed by a structured dump of the data. + */ + fromObjects: function (objects, options, callback) { + options = (options !== undefined ? options : {}); + var config = {}; + config.callback = ((callback !== undefined && typeof (callback) === 'function') ? callback : false); + config.separator = 'separator' in options ? options.separator : $.csv.defaults.separator; + config.delimiter = 'delimiter' in options ? options.delimiter : $.csv.defaults.delimiter; + config.headers = 'headers' in options ? options.headers : $.csv.defaults.headers; + config.sortOrder = 'sortOrder' in options ? options.sortOrder : 'declare'; + config.manualOrder = 'manualOrder' in options ? options.manualOrder : []; + config.transform = options.transform; + + if (typeof config.manualOrder === 'string') { + config.manualOrder = $.csv.toArray(config.manualOrder, config); + } + + if (config.transform !== undefined) { + var origObjects = objects; + objects = []; + + var i; + for (i = 0; i < origObjects.length; i++) { + objects.push(config.transform.call(undefined, origObjects[i])); + } + } + + var props = $.csv.helpers.collectPropertyNames(objects); + + if (config.sortOrder === 'alpha') { + props.sort(); + } // else {} - nothing to do for 'declare' order + + if (config.manualOrder.length > 0) { + var propsManual = [].concat(config.manualOrder); + let p; + for (p = 0; p < props.length; p++) { + if (propsManual.indexOf(props[p]) < 0) { + propsManual.push(props[p]); + } + } + props = propsManual; + } + + var o, p, line, output, propName; + if (config.headers) { + output.push(props); + } + + for (o = 0; o < objects.length; o++) { + line = []; + for (p = 0; p < props.length; p++) { + propName = props[p]; + if (propName in objects[o] && typeof objects[o][propName] !== 'function') { + line.push(objects[o][propName]); + } else { + line.push(''); + } + } + output.push(line); + } + + // push the value to a callback if one is defined + return $.csv.fromArrays(output, options, config.callback); + } + }; + + // Maintenance code to maintain backward-compatibility + // Will be removed in release 1.0 + $.csvEntry2Array = $.csv.toArray; + $.csv2Array = $.csv.toArrays; + $.csv2Dictionary = $.csv.toObjects; + + // CommonJS module is defined + if (typeof module !== 'undefined' && module.exports) { + module.exports = $.csv; + } +}).call(this); diff --git a/js/jquery.csv.min.js b/js/jquery.csv.min.js new file mode 100755 index 0000000..1655680 --- /dev/null +++ b/js/jquery.csv.min.js @@ -0,0 +1 @@ +RegExp.escape=function(r){return r.replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&")},function(){"use strict";var r;(r="undefined"!=typeof jQuery&&jQuery?jQuery:{}).csv={defaults:{separator:",",delimiter:'"',headers:!0},hooks:{castToScalar:function(r,e){if(isNaN(r))return r;if(/\./.test(r))return parseFloat(r);var a=parseInt(r);return isNaN(a)?null:a}},parsers:{parse:function(r,e){var a=e.separator,t=e.delimiter;e.state.rowNum||(e.state.rowNum=1),e.state.colNum||(e.state.colNum=1);var s=[],o=[],n=0,i="",l=!1;function c(){if(n=0,i="",e.start&&e.state.rowNum=e.end&&(l=!0),e.state.rowNum++,e.state.colNum=1}function u(){if(void 0===e.onParseValue)o.push(i);else{var r=e.onParseValue(i,e.state);!1!==r&&o.push(r)}i="",n=0,e.state.colNum++}var f=RegExp.escape(a),d=RegExp.escape(t),m=/(D|S|\r\n|\n|\r|[^DS\r\n]+)/,p=m.source;return p=(p=p.replace(/S/g,f)).replace(/D/g,d),m=new RegExp(p,"gm"),r.replace(m,function(r){if(!l)switch(n){case 0:if(r===a){i+="",u();break}if(r===t){n=1;break}if(/^(\r\n|\n|\r)$/.test(r)){u(),c();break}i+=r,n=3;break;case 1:if(r===t){n=2;break}i+=r,n=1;break;case 2:if(r===t){i+=r,n=1;break}if(r===a){u();break}if(/^(\r\n|\n|\r)$/.test(r)){u(),c();break}throw new Error("CSVDataError: Illegal State [Row:"+e.state.rowNum+"][Col:"+e.state.colNum+"]");case 3:if(r===a){u();break}if(/^(\r\n|\n|\r)$/.test(r)){u(),c();break}if(r===t)throw new Error("CSVDataError: Illegal Quote [Row:"+e.state.rowNum+"][Col:"+e.state.colNum+"]");throw new Error("CSVDataError: Illegal Data [Row:"+e.state.rowNum+"][Col:"+e.state.colNum+"]");default:throw new Error("CSVDataError: Unknown State [Row:"+e.state.rowNum+"][Col:"+e.state.colNum+"]")}}),0!==o.length&&(u(),c()),s},splitLines:function(e,a){if(e){var t=(a=a||{}).separator||r.csv.defaults.separator,s=a.delimiter||r.csv.defaults.delimiter;a.state=a.state||{},a.state.rowNum||(a.state.rowNum=1);var o=[],n=0,i="",l=!1,c=RegExp.escape(t),u=RegExp.escape(s),f=/(D|S|\n|\r|[^DS\r\n]+)/,d=f.source;return d=(d=d.replace(/S/g,c)).replace(/D/g,u),f=new RegExp(d,"gm"),e.replace(f,function(r){if(!l)switch(n){case 0:if(r===t){i+=r,n=0;break}if(r===s){i+=r,n=1;break}if("\n"===r){m();break}if(/^\r$/.test(r))break;i+=r,n=3;break;case 1:if(r===s){i+=r,n=2;break}i+=r,n=1;break;case 2:var e=i.substr(i.length-1);if(r===s&&e===s){i+=r,n=1;break}if(r===t){i+=r,n=0;break}if("\n"===r){m();break}if("\r"===r)break;throw new Error("CSVDataError: Illegal state [Row:"+a.state.rowNum+"]");case 3:if(r===t){i+=r,n=0;break}if("\n"===r){m();break}if("\r"===r)break;if(r===s)throw new Error("CSVDataError: Illegal quote [Row:"+a.state.rowNum+"]");throw new Error("CSVDataError: Illegal state [Row:"+a.state.rowNum+"]");default:throw new Error("CSVDataError: Unknown state [Row:"+a.state.rowNum+"]")}}),""!==i&&m(),o}function m(){if(n=0,a.start&&a.state.rowNum=a.end&&(l=!0),a.state.rowNum++}},parseEntry:function(r,e){var a=e.separator,t=e.delimiter;e.state.rowNum||(e.state.rowNum=1),e.state.colNum||(e.state.colNum=1);var s=[],o=0,n="";function i(){if(void 0===e.onParseValue)s.push(n);else{var r=e.onParseValue(n,e.state);!1!==r&&s.push(r)}n="",o=0,e.state.colNum++}if(!e.match){var l=RegExp.escape(a),c=RegExp.escape(t),u=/(D|S|\n|\r|[^DS\r\n]+)/.source;u=(u=u.replace(/S/g,l)).replace(/D/g,c),e.match=new RegExp(u,"gm")}return r.replace(e.match,function(r){switch(o){case 0:if(r===a){n+="",i();break}if(r===t){o=1;break}if("\n"===r||"\r"===r)break;n+=r,o=3;break;case 1:if(r===t){o=2;break}n+=r,o=1;break;case 2:if(r===t){n+=r,o=1;break}if(r===a){i();break}if("\n"===r||"\r"===r)break;throw new Error("CSVDataError: Illegal State [Row:"+e.state.rowNum+"][Col:"+e.state.colNum+"]");case 3:if(r===a){i();break}if("\n"===r||"\r"===r)break;if(r===t)throw new Error("CSVDataError: Illegal Quote [Row:"+e.state.rowNum+"][Col:"+e.state.colNum+"]");throw new Error("CSVDataError: Illegal Data [Row:"+e.state.rowNum+"][Col:"+e.state.colNum+"]");default:throw new Error("CSVDataError: Unknown State [Row:"+e.state.rowNum+"][Col:"+e.state.colNum+"]")}}),i(),s}},helpers:{collectPropertyNames:function(r){var e=[],a=[],t=[];for(e in r)for(a in r[e])r[e].hasOwnProperty(a)&&t.indexOf(a)<0&&"function"!=typeof r[e][a]&&t.push(a);return t}},toArray:function(e,a,t){a=void 0!==a?a:{};var s={};s.callback=void 0!==t&&"function"==typeof t&&t,s.separator="separator"in a?a.separator:r.csv.defaults.separator,s.delimiter="delimiter"in a?a.delimiter:r.csv.defaults.delimiter;var o=void 0!==a.state?a.state:{};a={delimiter:s.delimiter,separator:s.separator,onParseEntry:a.onParseEntry,onParseValue:a.onParseValue,state:o};var n=r.csv.parsers.parseEntry(e,a);if(!s.callback)return n;s.callback("",n)},toArrays:function(e,a,t){a=void 0!==a?a:{};var s={};s.callback=void 0!==t&&"function"==typeof t&&t,s.separator="separator"in a?a.separator:r.csv.defaults.separator,s.delimiter="delimiter"in a?a.delimiter:r.csv.defaults.delimiter;var o;if(void 0!==(a={delimiter:s.delimiter,separator:s.separator,onPreParse:a.onPreParse,onParseEntry:a.onParseEntry,onParseValue:a.onParseValue,onPostParse:a.onPostParse,start:a.start,end:a.end,state:{rowNum:1,colNum:1}}).onPreParse&&a.onPreParse(e,a.state),o=r.csv.parsers.parse(e,a),void 0!==a.onPostParse&&a.onPostParse(o,a.state),!s.callback)return o;s.callback("",o)},toObjects:function(e,a,t){a=void 0!==a?a:{};var s={};s.callback=void 0!==t&&"function"==typeof t&&t,s.separator="separator"in a?a.separator:r.csv.defaults.separator,s.delimiter="delimiter"in a?a.delimiter:r.csv.defaults.delimiter,s.headers="headers"in a?a.headers:r.csv.defaults.headers,a.start="start"in a?a.start:1,s.headers&&a.start++,a.end&&s.headers&&a.end++;var o,n=[];a={delimiter:s.delimiter,separator:s.separator,onPreParse:a.onPreParse,onParseEntry:a.onParseEntry,onParseValue:a.onParseValue,onPostParse:a.onPostParse,start:a.start,end:a.end,state:{rowNum:1,colNum:1},match:!1,transform:a.transform};var i={delimiter:s.delimiter,separator:s.separator,start:1,end:1,state:{rowNum:1,colNum:1}};void 0!==a.onPreParse&&a.onPreParse(e,a.state);var l=r.csv.parsers.splitLines(e,i),c=r.csv.toArray(l[0],a);o=r.csv.parsers.splitLines(e,a),a.state.colNum=1,a.state.rowNum=c?2:1;for(var u=0,f=o.length;u-1&&(u=u.replace(new RegExp(s.delimiter,"g"),s.delimiter+s.delimiter));var f="\n|\r|S|D";f=(f=f.replace("S",s.separator)).replace("D",s.delimiter),u.search(f)>-1&&(u=s.delimiter+u+s.delimiter),n.push(u)}c+=n.join(s.separator)+"\r\n"}if(!s.callback)return c;s.callback("",c)},fromObjects:function(e,a,t){a=void 0!==a?a:{};var s={};if(s.callback=void 0!==t&&"function"==typeof t&&t,s.separator="separator"in a?a.separator:r.csv.defaults.separator,s.delimiter="delimiter"in a?a.delimiter:r.csv.defaults.delimiter,s.headers="headers"in a?a.headers:r.csv.defaults.headers,s.sortOrder="sortOrder"in a?a.sortOrder:"declare",s.manualOrder="manualOrder"in a?a.manualOrder:[],s.transform=a.transform,"string"==typeof s.manualOrder&&(s.manualOrder=r.csv.toArray(s.manualOrder,s)),void 0!==s.transform){var o,n=e;for(e=[],o=0;o0){var l=[].concat(s.manualOrder);for(u=0;uPercent of Income:2%'], + ['Alabama',47,'Median Household Income:$47221
Percent of Income:3%'], + ['Arkansas',44,'Median Household Income $45907
Percent of Income:3%'], + ['Arizona',44,'Median Household Income:$57100
Percent of Income:2%'], + ['California',46,'Median Household Income:$66637
Percent of Income:2%'], + ['Colorado',52,'Median Household Income:$70566
Percent of Income:2%'], + ['Connecticut',54,'Median Household Income:$75923
Percent of Income:2%'], + ['Distric of Columbia',51,'Median Household Income:$70982
Percent of Income:2%'], + ['Delaware',47,'Median Household Income:$58046
Percent of Income:3%'], + ['Florida',42,'Median Household Income:$51176
Percent of Income:3%'], + ['Georgia',49,'Median Household Income:$53527
Percent of Income:3%'], + ['Hawaii',55,'Median Household Income:$53527
Percent of Income:1%'], + ['Iowa',54,'Median Household Income:$53527
Percent of Income:2%'], + ['Idaho',48,'Median Household Income:$56564
Percent of Income:2%'], + ['Illinois',51,'Median Household Income:$56564
Percent of Income:2%'], + ['Indiana', 52,'Median Household Income:$56094
Percent of Income:2%'], + ['Kansas',53,'Median Household Income:$56810
Percent of Income:2%'], + ['Kentucky',44,'Median Household Income:$45369
Percent of Income:3%'], + ['Lousiana',42,'Median Household Income:$42196
Percent of Income:3%'], + ['Massachussetts',54,'Median Household Income:$72266
Percent of Income:2%'], + ['Maryland',54,'Median Household Income:$73760
Percent of Income:2%'], + ['Maine',49,'Median Household Income:$50856
Percent of Income:3%'], + ['Michigan',51,'Median Household Income:$57091
Percent of Income:2%'], + ['Minnesota',55,'Median Household Income:$70218
Percent of Income:2%'], + ['Missouri',51,'Median Household Income:$70218
Percent of Income:2%'], + ['Mississippi',42,'Median Household Income:$41099
Percent of Income:2%'], + ['Montana',43,'Median Household Income:$57075
Percent of Income:2%'], + ['North Carolina',45,'Median Household Income:$53764
Percent of Income:2%'], + ['North Dakota',55,'Median Household Income:$60184
Percent of Income:2%'], + ['Nebraska',55,'Median Household Income:$59374
Percent of Income:2%'], + ['New Hampshire',58,'Median Household Income:$76260
Percent of Income:2%'], + ['New Jersey',55,'Median Household Income:$68468
Percent of Income:3%'], + ['New Mexico',36,'Median Household Income:$48451
Percent of Income:3%'], + ['Nevada',50,'Median Household Income:$55431
Percent of Income:2%'], + ['New York',50,'Median Household Income:$61437
Percent of Income:2%'], + ['Ohio',51,'Median Household Income:$53985
Percent of Income:2%'], + ['Oklahoma',48,'Median Household Income:$50943
Percent of Income:2%'], + ['Oregon',46,'Median Household Income:$59135
Percent of Income:2%'], + ['Pennsylvania',53,'Median Household Income:$60979
Percent of Income:2%'], + ['Rhode Island',51,'Median Household Income:$61528
Percent of Income:3%'], + ['South Carolina',46,'Median Household Income:$54336
Percent of Income:3%'], + ['South Dakota',49,'Median Household Income:$57450
Percent of Income:2%'], + ['Tennessee',46,'Median Household Income:$51344
Percent of Income:2%'], + ['Texas',49,'Median Household Income:$58146
Percent of Income:2%'], + ['Utah',60,'Median Household Income:$67481
Percent of Income:2%'], + ['Virginia',55,'Median Household Income:$66451
Percent of Income:2%'], + ['Vermont',47,'Median Household Income:$60837
Percent of Income:2%'], + ['Washington',49,'Median Household Income:$60837
Percent of Income:1%'], + ['Wisconsin',56,'Median Household Income:$59817
Percent of Income:2%'], + ['West Virginia',43,'Median Household Income:$44354
Percent of Income:3%'], + ['Wyoming',55,'Median Household Income:$57829
Percent of Income:3%'], + + + ]); + + var options = { + region: 'US', + resolution:'provinces', + tooltip: { + isHtml: true}, + }; + + var chart = new google.visualization.GeoChart(document.getElementById('regions_div2')); + + chart.draw(data, options); + } + diff --git a/js/men19to27.js b/js/men19to27.js new file mode 100644 index 0000000..bf18cc1 --- /dev/null +++ b/js/men19to27.js @@ -0,0 +1,140 @@ + +(function(d3) { +'use strict'; + +var width = 360; +var height = 360; +var radius = Math.min(width, height) / 2; +var donutWidth = 75; +var legendRectSize = 18; +var legendSpacing = 4; + +var color = d3.scaleOrdinal(d3.schemeCategory10); + +var svg = d3.select('#men_pieChart1') + .append('svg') + .attr('width', width) + .attr('height', height) + .append('g') + .attr('transform', 'translate(' + (width / 2) + + ',' + (height / 2) + ')'); + +var arc = d3.arc() + .innerRadius(radius - donutWidth) + .outerRadius(radius); + +var pie = d3.pie() + .value(function(d) { return d.PercentValue; }) + .sort(null); + +var tooltip = d3.select('#men_pieChart1') + .append('div') + .attr('class', 'tooltipMen1'); + +tooltip.append('div') + .attr('class', 'Preparedness'); + +// tooltip.append('div') +// .attr('class', 'PercentValue'); + +tooltip.append('div') + .attr('class', 'percent'); + +d3.csv('data/men19to27.csv', function(error, dataset) { + dataset.forEach(function(d) { + d.PercentValue = +d.PercentValue; + d.enabled = true; // NEW + }); + + var path = svg.selectAll('path') + .data(pie(dataset)) + .enter() + .append('path') + .attr('d', arc) + .attr('fill', function(d, i) { + return color(d.data.Preparedness); + }) // UPDATED (removed semicolon) + .each(function(d) { this._current = d; }); // NEW + + path.on('mouseover', function(d) { + var total = d3.sum(dataset.map(function(d) { + return (d.enabled) ? d.PercentValue : 0; // UPDATED + })); + var percent = Math.round(1000 * d.data.PercentValue / total) / 10; + tooltip.select('.Preparedness').html(d.data.Preparedness); + tooltip.select('.PercentValue').html(d.data.PercentValue); + tooltip.select('.percent').html(percent + '%'); + tooltip.style('display', 'block'); + }); + + path.on('mouseout', function() { + tooltip.style('display', 'none'); + }); + + // OPTIONAL + // path.on('mousemove', function(d) { + // tooltip.style('top', (d3.event.pageY + 10) + 'px') + // .style('left', (d3.event.pageX + 10) + 'px'); + // }); + + + var legend = svg.selectAll('.legend') + .data(color.domain()) + .enter() + .append('g') + .attr('class', 'legend') + .attr('transform', function(d, i) { + var height = legendRectSize + legendSpacing; + var offset = height * color.domain().length / 2; + var horz = -2 * legendRectSize; + var vert = i * height - offset; + return 'translate(' + horz + ',' + vert + ')'; + }); + + legend.append('rect') + .attr('width', legendRectSize) + .attr('height', legendRectSize) + .style('fill', color) + .style('stroke', color) // UPDATED (removed semicolon) + .on('click', function(Preparedness) { // NEW + var rect = d3.select(this); // NEW + var enabled = true; // NEW + var totalEnabled = d3.sum(dataset.map(function(d) { // NEW + return (d.enabled) ? 1 : 0; // NEW + })); // NEW + + if (rect.attr('class') === 'disabled') { // NEW + rect.attr('class', ''); // NEW + } else { // NEW + if (totalEnabled < 2) return; // NEW + rect.attr('class', 'disabled'); // NEW + enabled = false; // NEW + } // NEW + + pie.value(function(d) { // NEW + if (d.Preparedness === Preparedness) d.enabled = enabled; // NEW + return (d.enabled) ? d.PercentValue : 0; // NEW + }); // NEW + + path = path.data(pie(dataset)); // NEW + + path.transition() // NEW + .duration(750) // NEW + .attrTween('d', function(d) { // NEW + var interpolate = d3.interpolate(this._current, d); // NEW + this._current = interpolate(0); // NEW + return function(t) { // NEW + return arc(interpolate(t)); // NEW + }; // NEW + }); // NEW + }); // NEW + + legend.append('text') + .attr('x', legendRectSize + legendSpacing) + .attr('y', legendRectSize - legendSpacing) + .text(function(d) { return d; }); + +}); + +})(window.d3); + \ No newline at end of file diff --git a/js/men28to36.js b/js/men28to36.js new file mode 100644 index 0000000..71ba47e --- /dev/null +++ b/js/men28to36.js @@ -0,0 +1,139 @@ + + (function(d3) { + 'use strict'; + + var width = 360; + var height = 360; + var radius = Math.min(width, height) / 2; + var donutWidth = 75; + var legendRectSize = 18; + var legendSpacing = 4; + + var color = d3.scaleOrdinal(d3.schemeCategory10); + + var svg = d3.select('#men_pieChart2') + .append('svg') + .attr('width', width) + .attr('height', height) + .append('g') + .attr('transform', 'translate(' + (width / 2) + + ',' + (height / 2) + ')'); + + var arc = d3.arc() + .innerRadius(radius - donutWidth) + .outerRadius(radius); + + var pie = d3.pie() + .value(function(d) { return d.PercentValue; }) + .sort(null); + + var tooltip = d3.select('#men_pieChart2') + .append('div') + .attr('class', 'tooltipMen2'); + + tooltip.append('div') + .attr('class', 'Preparedness'); + + // tooltip.append('div') + // .attr('class', 'PercentValue'); + + tooltip.append('div') + .attr('class', 'percent'); + + d3.csv('data/men28to36.csv', function(error, dataset) { + dataset.forEach(function(d) { + d.PercentValue = +d.PercentValue; + d.enabled = true; // NEW + }); + + var path = svg.selectAll('path') + .data(pie(dataset)) + .enter() + .append('path') + .attr('d', arc) + .attr('fill', function(d, i) { + return color(d.data.Preparedness); + }) // UPDATED (removed semicolon) + .each(function(d) { this._current = d; }); // NEW + + path.on('mouseover', function(d) { + var total = d3.sum(dataset.map(function(d) { + return (d.enabled) ? d.PercentValue : 0; // UPDATED + })); + var percent = Math.round(1000 * d.data.PercentValue / total) / 10; + tooltip.select('.Preparedness').html(d.data.Preparedness); + tooltip.select('.PercentValue').html(d.data.PercentValue); + tooltip.select('.percent').html(percent + '%'); + tooltip.style('display', 'block'); + }); + + path.on('mouseout', function() { + tooltip.style('display', 'none'); + }); + + /* OPTIONAL + path.on('mousemove', function(d) { + tooltip.style('top', (d3.event.pageY + 10) + 'px') + .style('left', (d3.event.pageX + 10) + 'px'); + }); + */ + + var legend = svg.selectAll('.legend') + .data(color.domain()) + .enter() + .append('g') + .attr('class', 'legend') + .attr('transform', function(d, i) { + var height = legendRectSize + legendSpacing; + var offset = height * color.domain().length / 2; + var horz = -2 * legendRectSize; + var vert = i * height - offset; + return 'translate(' + horz + ',' + vert + ')'; + }); + + legend.append('rect') + .attr('width', legendRectSize) + .attr('height', legendRectSize) + .style('fill', color) + .style('stroke', color) // UPDATED (removed semicolon) + .on('click', function(Preparedness) { // NEW + var rect = d3.select(this); // NEW + var enabled = true; // NEW + var totalEnabled = d3.sum(dataset.map(function(d) { // NEW + return (d.enabled) ? 1 : 0; // NEW + })); // NEW + + if (rect.attr('class') === 'disabled') { // NEW + rect.attr('class', ''); // NEW + } else { // NEW + if (totalEnabled < 2) return; // NEW + rect.attr('class', 'disabled'); // NEW + enabled = false; // NEW + } // NEW + + pie.value(function(d) { // NEW + if (d.Preparedness === Preparedness) d.enabled = enabled; // NEW + return (d.enabled) ? d.PercentValue : 0; // NEW + }); // NEW + + path = path.data(pie(dataset)); // NEW + + path.transition() // NEW + .duration(750) // NEW + .attrTween('d', function(d) { // NEW + var interpolate = d3.interpolate(this._current, d); // NEW + this._current = interpolate(0); // NEW + return function(t) { // NEW + return arc(interpolate(t)); // NEW + }; // NEW + }); // NEW + }); // NEW + + legend.append('text') + .attr('x', legendRectSize + legendSpacing) + .attr('y', legendRectSize - legendSpacing) + .text(function(d) { return d; }); + + }); + + })(window.d3); diff --git a/js/women19to27.js b/js/women19to27.js new file mode 100644 index 0000000..8980bef --- /dev/null +++ b/js/women19to27.js @@ -0,0 +1,139 @@ + +(function(d3) { + 'use strict'; + + var width = 360; + var height = 360; + var radius = Math.min(width, height) / 2; + var donutWidth = 75; + var legendRectSize = 18; + var legendSpacing = 4; + + var color = d3.scaleOrdinal(d3.schemeCategory20); + + var svg = d3.select('#women_pieChart1') + .append('svg') + .attr('width', width) + .attr('height', height) + .append('g') + .attr('transform', 'translate(' + (width / 2) + + ',' + (height / 2) + ')'); + + var arc = d3.arc() + .innerRadius(radius - donutWidth) + .outerRadius(radius); + + var pie = d3.pie() + .value(function(d) { return d.PercentValue; }) + .sort(null); + + var tooltip = d3.select('#women_pieChart1') + .append('div') + .attr('class', 'tooltipWomen1'); + + tooltip.append('div') + .attr('class', 'Preparedness'); + + // tooltip.append('div') + // .attr('class', 'PercentValue'); + + tooltip.append('div') + .attr('class', 'percent'); + + d3.csv('data/women19to27.csv', function(error, dataset) { + dataset.forEach(function(d) { + d.PercentValue = +d.PercentValue; + d.enabled = true; // NEW + }); + + var path = svg.selectAll('path') + .data(pie(dataset)) + .enter() + .append('path') + .attr('d', arc) + .attr('fill', function(d, i) { + return color(d.data.Preparedness); + }) // UPDATED (removed semicolon) + .each(function(d) { this._current = d; }); // NEW + + path.on('mouseover', function(d) { + var total = d3.sum(dataset.map(function(d) { + return (d.enabled) ? d.PercentValue : 0; // UPDATED + })); + var percent = Math.round(1000 * d.data.PercentValue / total) / 10; + tooltip.select('.Preparedness').html(d.data.Preparedness); + tooltip.select('.PercentValue').html(d.data.PercentValue); + tooltip.select('.percent').html(percent + '%'); + tooltip.style('display', 'block'); + }); + + path.on('mouseout', function() { + tooltip.style('display', 'none'); + }); + + // OPTIONAL + // path.on('mousemove', function(d) { + // tooltip.style('top', (d3.event.pageY + 10) + 'px') + // .style('left', (d3.event.pageX + 10) + 'px'); + // }); + + + var legend = svg.selectAll('.legend') + .data(color.domain()) + .enter() + .append('g') + .attr('class', 'legend') + .attr('transform', function(d, i) { + var height = legendRectSize + legendSpacing; + var offset = height * color.domain().length / 2; + var horz = -2 * legendRectSize; + var vert = i * height - offset; + return 'translate(' + horz + ',' + vert + ')'; + }); + + legend.append('rect') + .attr('width', legendRectSize) + .attr('height', legendRectSize) + .style('fill', color) + .style('stroke', color) // UPDATED (removed semicolon) + .on('click', function(Preparedness) { // NEW + var rect = d3.select(this); // NEW + var enabled = true; // NEW + var totalEnabled = d3.sum(dataset.map(function(d) { // NEW + return (d.enabled) ? 1 : 0; // NEW + })); // NEW + + if (rect.attr('class') === 'disabled') { // NEW + rect.attr('class', ''); // NEW + } else { // NEW + if (totalEnabled < 2) return; // NEW + rect.attr('class', 'disabled'); // NEW + enabled = false; // NEW + } // NEW + + pie.value(function(d) { // NEW + if (d.Preparedness === Preparedness) d.enabled = enabled; // NEW + return (d.enabled) ? d.PercentValue : 0; // NEW + }); // NEW + + path = path.data(pie(dataset)); // NEW + + path.transition() // NEW + .duration(750) // NEW + .attrTween('d', function(d) { // NEW + var interpolate = d3.interpolate(this._current, d); // NEW + this._current = interpolate(0); // NEW + return function(t) { // NEW + return arc(interpolate(t)); // NEW + }; // NEW + }); // NEW + }); // NEW + + legend.append('text') + .attr('x', legendRectSize + legendSpacing) + .attr('y', legendRectSize - legendSpacing) + .text(function(d) { return d; }); + + }); + +})(window.d3); diff --git a/js/women28to36.js b/js/women28to36.js new file mode 100644 index 0000000..8ccda87 --- /dev/null +++ b/js/women28to36.js @@ -0,0 +1,139 @@ + + (function(d3) { + 'use strict'; + + var width = 360; + var height = 360; + var radius = Math.min(width, height) / 2; + var donutWidth = 75; + var legendRectSize = 18; + var legendSpacing = 4; + + var color = d3.scaleOrdinal(d3.schemeCategory20); + + var svg = d3.select('#women_pieChart2') + .append('svg') + .attr('width', width) + .attr('height', height) + .append('g') + .attr('transform', 'translate(' + (width / 2) + + ',' + (height / 2) + ')'); + + var arc = d3.arc() + .innerRadius(radius - donutWidth) + .outerRadius(radius); + + var pie = d3.pie() + .value(function(d) { return d.PercentValue; }) + .sort(null); + + var tooltip = d3.select('#women_pieChart2') + .append('div') + .attr('class', 'tooltipWomen2'); + + tooltip.append('div') + .attr('class', 'Preparedness'); + + // tooltip.append('div') + // .attr('class', 'PercentValue'); + + tooltip.append('div') + .attr('class', 'percent'); + + d3.csv('data/women28to36.csv', function(error, dataset) { + dataset.forEach(function(d) { + d.PercentValue = +d.PercentValue; + d.enabled = true; // NEW + }); + + var path = svg.selectAll('path') + .data(pie(dataset)) + .enter() + .append('path') + .attr('d', arc) + .attr('fill', function(d, i) { + return color(d.data.Preparedness); + }) // UPDATED (removed semicolon) + .each(function(d) { this._current = d; }); // NEW + + path.on('mouseover', function(d) { + var total = d3.sum(dataset.map(function(d) { + return (d.enabled) ? d.PercentValue : 0; // UPDATED + })); + var percent = Math.round(1000 * d.data.PercentValue / total) / 10; + tooltip.select('.Preparedness').html(d.data.Preparedness); + tooltip.select('.PercentValue').html(d.data.PercentValue); + tooltip.select('.percent').html(percent + '%'); + tooltip.style('display', 'block'); + }); + + path.on('mouseout', function() { + tooltip.style('display', 'none'); + }); + + /* OPTIONAL + path.on('mousemove', function(d) { + tooltip.style('top', (d3.event.pageY + 10) + 'px') + .style('left', (d3.event.pageX + 10) + 'px'); + }); + */ + + var legend = svg.selectAll('.legend') + .data(color.domain()) + .enter() + .append('g') + .attr('class', 'legend') + .attr('transform', function(d, i) { + var height = legendRectSize + legendSpacing; + var offset = height * color.domain().length / 2; + var horz = -2 * legendRectSize; + var vert = i * height - offset; + return 'translate(' + horz + ',' + vert + ')'; + }); + + legend.append('rect') + .attr('width', legendRectSize) + .attr('height', legendRectSize) + .style('fill', color) + .style('stroke', color) // UPDATED (removed semicolon) + .on('click', function(Preparedness) { // NEW + var rect = d3.select(this); // NEW + var enabled = true; // NEW + var totalEnabled = d3.sum(dataset.map(function(d) { // NEW + return (d.enabled) ? 1 : 0; // NEW + })); // NEW + + if (rect.attr('class') === 'disabled') { // NEW + rect.attr('class', ''); // NEW + } else { // NEW + if (totalEnabled < 2) return; // NEW + rect.attr('class', 'disabled'); // NEW + enabled = false; // NEW + } // NEW + + pie.value(function(d) { // NEW + if (d.Preparedness === Preparedness) d.enabled = enabled; // NEW + return (d.enabled) ? d.PercentValue : 0; // NEW + }); // NEW + + path = path.data(pie(dataset)); // NEW + + path.transition() // NEW + .duration(750) // NEW + .attrTween('d', function(d) { // NEW + var interpolate = d3.interpolate(this._current, d); // NEW + this._current = interpolate(0); // NEW + return function(t) { // NEW + return arc(interpolate(t)); // NEW + }; // NEW + }); // NEW + }); // NEW + + legend.append('text') + .attr('x', legendRectSize + legendSpacing) + .attr('y', legendRectSize - legendSpacing) + .text(function(d) { return d; }); + + }); + + })(window.d3);