Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save kingkool68/e483e29afef8fdaa9681 to your computer and use it in GitHub Desktop.
Save kingkool68/e483e29afef8fdaa9681 to your computer and use it in GitHub Desktop.
The code that powers http://www.pewhispanic.org/interactives/unauthorized-immigrants-2012/ a hybrid (frontend + backend) interactive data visualization.
<?php
function unauthorized_immigrants_enqueue_scripts() {
wp_enqueue_script( 'highmaps-us' );
if( !is_iframe() ) {
wp_enqueue_script( 'pew-sortable-tables' );
}
pew_interactives_enqueue_style( 'interactive-unauthorized-immigrants-2012' ); //Two interactives share the same CSS file.
}
add_action( 'pew_interactive_styles', 'unauthorized_immigrants_enqueue_scripts', 11 );
function unauthorized_immigrants_body() {
global $post;
?>
<div id="interactive">
<?php echo wpautop( $post->post_content ); ?>
<form method="get" action="<?= get_permalink(); ?>" id="unauthorized-immigration-form" target="_top">
<label for="map-options">Show data for</label>
<select name="redirect-unauthorized-immigrant-map" id="map-options">
<?php
$labels = array(
// slug => Proper Label
'population' => (object) array(
'title' => 'Unauthorized Immigrant Population, by State, 2012',
'label' => 'Unauthorized Immigrant Total',
'blurb' => 'California has by far the largest number of unauthorized immigrants, more than 2.4 million in 2012. Six-in-ten unauthorized immigrants live in the six states with the largest populations of unauthorized immigrants—California, Florida, Illinois, New Jersey, New York and Texas.',
'note' => 'Note: Population figures are rounded.',
'source' => 'Source: Pew Research Center estimates for 2012 based on augmented American Community Survey data from Integrated Public Use Microdata Series (IPUMS)',
'column' => 1
),
'population-share' => (object) array(
'title' => 'Unauthorized Immigrant Share of Population, by State, 2012',
'label' => 'Share of State Population',
'blurb' => 'In four states—California, Nevada, Texas and New Jersey—unauthorized immigrants make up more than 5% of the total population. States with the highest shares of unauthorized immigrants are concentrated along the coasts or U.S. border with Mexico.',
'note' => 'Note: Percentages calculated from unrounded numbers.',
'source' => 'Source: Pew Research Center estimates for 2012 based on augmented American Community Survey data from Integrated Public Use Microdata Series (IPUMS)',
'column' => 2
),
'all-immigrant-share' => (object) array(
'title' => 'Unauthorized Immigrants as a Share of All Immigrants, by State, 2012',
'label' => 'Share of Immigrants',
'blurb' => 'About a quarter of all U.S. immigrants (26%) were unauthorized in 2012, but the share varies widely by state. Generally, states with the highest share of unauthorized immigrants among the foreign-born population are in the South and Mountain West.',
'note' => 'Note: Percentages calculated from unrounded numbers.',
'source' => 'Source: Pew Research Center estimates for 2012 based on augmented American Community Survey data from Integrated Public Use Microdata Series (IPUMS)',
'column' => 3
),
'labor-force-share' => (object) array(
'title' => 'Unauthorized Immigrants as Share of Labor Force, by State, 2012',
'label' => 'Share of Labor Force',
'blurb' => 'Nationally, unauthorized immigrants were 5.1% of the 2012 labor force, which includes anyone ages 16 and older who is working or looking for work. But the share is higher in some states, especially those with relatively large shares of unauthorized immigrants in the total population.',
'note' => 'Note: Percentages calculated from unrounded numbers.',
'source' => 'Source: Pew Research Center estimates for 2012 based on augmented American Community Survey data from Integrated Public Use Microdata Series (IPUMS)',
'column' => 4
),
'k-12-share' => (object) array(
'title' => 'Share of K-12 Students with Unauthorized Immigrant Parent(s), by State, 2012',
'label' => 'K-12 with Unauthorized Immigrant Parent(s)',
'blurb' => 'Children of unauthorized immigrants made up 6.9% of U.S. students enrolled in kindergarten through 12th grade in 2012, though the share varies by state. Most (5.5%) are U.S.-born children who are U.S. citizens at birth. The rest (1.4%) are unauthorized immigrants themselves.',
'note' => 'Note: Percentages calculated from unrounded numbers.',
'source' => 'Source: Pew Research Center estimates for 2012 based on augmented American Community Survey data from Integrated Public Use Microdata Series (IPUMS)',
'column' => 5
),
'mexican-share' => (object) array(
'title' => 'Mexicans as Share of Unauthorized Immigrants, by State, 2012',
'label' => 'Share from Mexico',
'blurb' => 'Mexico is the country of birth of most unauthorized immigrants in the nation overall and in at least half the states. Nationally, the share and number of Mexican-born unauthorized immigrants peaked in 2007 and has declined since then.',
'note' => 'Note: Percentages calculated from unrounded numbers.',
'source' => 'Source: Pew Research Center estimates for 2012 based on augmented American Community Survey data from Integrated Public Use Microdata Series (IPUMS)',
'column' => 6
),
'population-change' => (object) array(
'title' => 'Change in Unauthorized Immigrant Population, by State, 2009 to 2012',
'label' => 'Change in Unauthorized Immigrant Population',
'blurb' => 'Although the unauthorized immigrant population was statistically unchanged at the national level from 2009 to 2012, numbers rose in seven states and declined in 14 states over that period. Most of the states with increases are on the East Coast.',
'note' => 'Note: Changes shown are significant based on 90% confidence interval.',
'source' => 'Source: Pew Research Center estimates for 2009 and 2012 based on augmented American Community Survey data from Integrated Public Use Microdata Series (IPUMS)',
'column' => 7
)
);
$active_map = 'population';
foreach( $labels as $slug => $obj ) {
if( $slug == get_query_var( 'unauthorized-immigrant-map' ) ) {
$active_map = $slug;
}
}
foreach( $labels as $slug => $obj ) {
?>
<option value="<?=$slug?>" <?php selected( $slug, $active_map ); ?> data-column="<?=$obj->column;?>"><?=$obj->label;?></option>
<?php
}
?>
<input type="submit" value="Go" class="go-button">
</select>
</form>
<?php foreach( $labels as $slug => $obj ):
$classes = array( 'group' );
if( $slug != $active_map ) {
$classes[] = 'hide';
}
$obj->blurb .= ' See our report: <a href="http://www.pewhispanic.org/2014/11/18/unauthorized-immigrant-totals-rise-in-7-states-fall-in-14/" target="_top">Unauthorized Immigrant Totals Rise in 7 States, Fall in 14</a>';
?>
<div id="<?=$slug?>" class="<?=implode( ' ', $classes );?>">
<h2><?=$obj->title;?></h2>
<div class="info">
<?= wpautop( wptexturize( $obj->blurb ) ); ?>
</div>
<div class="map"></div>
<p class="source">
<?=$obj->note?><br>
<?=$obj->source?>
</p>
</div>
<?php endforeach; ?>
<!-- Container/PHP for embed footer -->
<div class="interactive-footer-container">
<?php
$iframe_src = get_permalink();
$slug = get_query_var( 'unauthorized-immigrant-map' );
if( $slug && $slug != 'population' ) {
$iframe_src .= 'map/' . $slug . '/';
}
$args = array (
'report_link' => 'http://www.pewhispanic.org/2014/11/18/unauthorized-immigrant-totals-rise-in-7-states-fall-in-14/',
'data_link' => '/2014/11/2014-11_interactive-maps-spreadsheet-for-public-release.xlsx',
'allow_iframe' => true,
'iframe_height' => '800px',
'iframe_width' => '100%',
'iframe_src' => $iframe_src . 'iframe/'
);
interactiveFooter( $args ); ?>
</div>
<?php
/*
Table clean up script. Run in the browsers console() and copy the resulting HTML.
jQuery( document ).ready(function($) {
$table = $('#map-data');
var th = [];
$( 'thead th', $table ).each(function(i, el) {
th.push( $.trim( $(el).text() ) );
});
$( 'tbody tr', $table ).each(function(i , row) {
$( 'td', row ).each(function(j, cell) {
$(cell).attr('title', th[j]);
});
});
$( 'tbody tr td:nth-child(7)' ).each(function(i, td) {
$td = $(td);
var val = parseInt( $td.text().replace(/%/, '') );
if( isNaN(val) ) {
val = 0;
}
$td.attr('data-sort', val);
});
});
*/
?>
<table class="sortable adaptive" id="map-data">
<thead class="right-aligned">
<tr>
<th class="left-aligned">State</th>
<th data-additional-sort-column="0">Unauthorized Immigrant Population, 2012</th>
<th data-additional-sort-column="0">Unauthorized Immigrant Share of Population, 2012</th>
<th data-additional-sort-column="0">Unauthorized Share of Immigrant Population, 2012</th>
<th data-additional-sort-column="0">Unauthorized Immigrant Share of Labor Force, 2012</th>
<th data-additional-sort-column="0">Share of K-12 Students with Unauthorized Immigrant Parent(s), 2012</th>
<th data-additional-sort-column="0">Share Mexican of Unauthorized Immigrants, 2012</th>
<th data-additional-sort-column="0">Change in Unauthorized Immigrant Population, 2009-2012</th>
</tr>
</thead>
<tfoot>
<tr>
<td class="left-aligned">Total</td>
<td title="Unauthorized Immigrant Population, 2012">11,200,000</td>
<td title="Unauthorized Immigrant Share of Population, 2012">3.5%</td>
<td title="Unauthorized Share of Immigrant Population, 2012">26%</td>
<td title="Unauthorized Immigrant Share of Labor Force, 2012">5.1%</td>
<td title="Share of K-12 Students with Unauthorized Immigrant Parent(s), 2012">6.9%</td>
<td title="Share Mexican of Unauthorized Immigrants, 2012">52%</td>
<td title="Change in Unauthorized Immigrant Population, 2009-2012"><abbr title="Not statistically significant">n.s.</abbr></td>
</tr>
</tfoot>
<tbody>
<tr id="us-al">
<td class="left-aligned" title="State">Alabama</td>
<td title="Unauthorized Immigrant Population, 2012">65,000</td>
<td title="Unauthorized Immigrant Share of Population, 2012">1.4%</td>
<td title="Unauthorized Share of Immigrant Population, 2012">38%</td>
<td title="Unauthorized Immigrant Share of Labor Force, 2012">2.0%</td>
<td title="Share of K-12 Students with Unauthorized Immigrant Parent(s), 2012">2.8%</td>
<td title="Share Mexican of Unauthorized Immigrants, 2012" data-sort="66">66%</td>
<td title="Change in Unauthorized Immigrant Population, 2009-2012" class="negative">-10,000</td>
</tr>
<tr id="us-ak">
<td class="left-aligned" title="State">Alaska</td>
<td title="Unauthorized Immigrant Population, 2012">15,000</td>
<td title="Unauthorized Immigrant Share of Population, 2012">1.8%</td>
<td title="Unauthorized Share of Immigrant Population, 2012">25%</td>
<td title="Unauthorized Immigrant Share of Labor Force, 2012">2.4%</td>
<td title="Share of K-12 Students with Unauthorized Immigrant Parent(s), 2012">1.2%</td>
<td title="Share Mexican of Unauthorized Immigrants, 2012" data-sort="12">12%</td>
<td title="Change in Unauthorized Immigrant Population, 2009-2012"><abbr title="Not statistically significant">n.s.</abbr></td>
</tr>
<tr id="us-az">
<td class="left-aligned" title="State">Arizona</td>
<td title="Unauthorized Immigrant Population, 2012">300,000</td>
<td title="Unauthorized Immigrant Share of Population, 2012">4.6%</td>
<td title="Unauthorized Share of Immigrant Population, 2012">33%</td>
<td title="Unauthorized Immigrant Share of Labor Force, 2012">6.0%</td>
<td title="Share of K-12 Students with Unauthorized Immigrant Parent(s), 2012">11.0%</td>
<td title="Share Mexican of Unauthorized Immigrants, 2012" data-sort="84">84%</td>
<td title="Change in Unauthorized Immigrant Population, 2009-2012" class="negative">-40,000</td>
</tr>
<tr id="us-ar">
<td class="left-aligned" title="State">Arkansas</td>
<td title="Unauthorized Immigrant Population, 2012">60,000</td>
<td title="Unauthorized Immigrant Share of Population, 2012">2.1%</td>
<td title="Unauthorized Share of Immigrant Population, 2012">45%</td>
<td title="Unauthorized Immigrant Share of Labor Force, 2012">3.2%</td>
<td title="Share of K-12 Students with Unauthorized Immigrant Parent(s), 2012">5.4%</td>
<td title="Share Mexican of Unauthorized Immigrants, 2012" data-sort="68">68%</td>
<td title="Change in Unauthorized Immigrant Population, 2009-2012"><abbr title="Not statistically significant">n.s.</abbr></td>
</tr>
<tr id="us-ca">
<td class="left-aligned" title="State">California</td>
<td title="Unauthorized Immigrant Population, 2012">2,450,000</td>
<td title="Unauthorized Immigrant Share of Population, 2012">6.3%</td>
<td title="Unauthorized Share of Immigrant Population, 2012">23%</td>
<td title="Unauthorized Immigrant Share of Labor Force, 2012">9.4%</td>
<td title="Share of K-12 Students with Unauthorized Immigrant Parent(s), 2012">13.2%</td>
<td title="Share Mexican of Unauthorized Immigrants, 2012" data-sort="68">68%</td>
<td title="Change in Unauthorized Immigrant Population, 2009-2012" class="negative">-90,000</td>
</tr>
<tr id="us-co">
<td class="left-aligned" title="State">Colorado</td>
<td title="Unauthorized Immigrant Population, 2012">180,000</td>
<td title="Unauthorized Immigrant Share of Population, 2012">3.5%</td>
<td title="Unauthorized Share of Immigrant Population, 2012">34%</td>
<td title="Unauthorized Immigrant Share of Labor Force, 2012">4.7%</td>
<td title="Share of K-12 Students with Unauthorized Immigrant Parent(s), 2012">8.1%</td>
<td title="Share Mexican of Unauthorized Immigrants, 2012" data-sort="78">78%</td>
<td title="Change in Unauthorized Immigrant Population, 2009-2012" class="negative">-30,000</td>
</tr>
<tr id="us-ct">
<td class="left-aligned" title="State">Connecticut</td>
<td title="Unauthorized Immigrant Population, 2012">130,000</td>
<td title="Unauthorized Immigrant Share of Population, 2012">3.5%</td>
<td title="Unauthorized Share of Immigrant Population, 2012">25%</td>
<td title="Unauthorized Immigrant Share of Labor Force, 2012">5.1%</td>
<td title="Share of K-12 Students with Unauthorized Immigrant Parent(s), 2012">4.2%</td>
<td title="Share Mexican of Unauthorized Immigrants, 2012" data-sort="15">15%</td>
<td title="Change in Unauthorized Immigrant Population, 2009-2012"><abbr title="Not statistically significant">n.s.</abbr></td>
</tr>
<tr id="us-de">
<td class="left-aligned" title="State">Delaware</td>
<td title="Unauthorized Immigrant Population, 2012">20,000</td>
<td title="Unauthorized Immigrant Share of Population, 2012">2.4%</td>
<td title="Unauthorized Share of Immigrant Population, 2012">26%</td>
<td title="Unauthorized Immigrant Share of Labor Force, 2012">3.8%</td>
<td title="Share of K-12 Students with Unauthorized Immigrant Parent(s), 2012">5.4%</td>
<td title="Share Mexican of Unauthorized Immigrants, 2012" data-sort="47">47%</td>
<td title="Change in Unauthorized Immigrant Population, 2009-2012"><abbr title="Not statistically significant">n.s.</abbr></td>
</tr>
<tr id="us-dc">
<td class="left-aligned" title="State">District of Columbia</td>
<td title="Unauthorized Immigrant Population, 2012">20,000</td>
<td title="Unauthorized Immigrant Share of Population, 2012">3.1%</td>
<td title="Unauthorized Share of Immigrant Population, 2012">20%</td>
<td title="Unauthorized Immigrant Share of Labor Force, 2012">4.1%</td>
<td title="Share of K-12 Students with Unauthorized Immigrant Parent(s), 2012">4.9%</td>
<td title="Share Mexican of Unauthorized Immigrants, 2012" data-sort="12">12%</td>
<td title="Change in Unauthorized Immigrant Population, 2009-2012"><abbr title="Not statistically significant">n.s.</abbr></td>
</tr>
<tr id="us-fl">
<td class="left-aligned" title="State">Florida</td>
<td title="Unauthorized Immigrant Population, 2012">925,000</td>
<td title="Unauthorized Immigrant Share of Population, 2012">4.8%</td>
<td title="Unauthorized Share of Immigrant Population, 2012">24%</td>
<td title="Unauthorized Immigrant Share of Labor Force, 2012">6.9%</td>
<td title="Share of K-12 Students with Unauthorized Immigrant Parent(s), 2012">7.5%</td>
<td title="Share Mexican of Unauthorized Immigrants, 2012" data-sort="13">13%</td>
<td title="Change in Unauthorized Immigrant Population, 2009-2012">55,000</td>
</tr>
<tr id="us-ga">
<td class="left-aligned" title="State">Georgia</td>
<td title="Unauthorized Immigrant Population, 2012">400,000</td>
<td title="Unauthorized Immigrant Share of Population, 2012">3.9%</td>
<td title="Unauthorized Share of Immigrant Population, 2012">39%</td>
<td title="Unauthorized Immigrant Share of Labor Force, 2012">5.6%</td>
<td title="Share of K-12 Students with Unauthorized Immigrant Parent(s), 2012">7.5%</td>
<td title="Share Mexican of Unauthorized Immigrants, 2012" data-sort="54">54%</td>
<td title="Change in Unauthorized Immigrant Population, 2009-2012" class="negative">-35,000</td>
</tr>
<tr id="us-hi">
<td class="left-aligned" title="State">Hawaii</td>
<td title="Unauthorized Immigrant Population, 2012">35,000</td>
<td title="Unauthorized Immigrant Share of Population, 2012">2.4%</td>
<td title="Unauthorized Share of Immigrant Population, 2012">13%</td>
<td title="Unauthorized Immigrant Share of Labor Force, 2012">3.7%</td>
<td title="Share of K-12 Students with Unauthorized Immigrant Parent(s), 2012">2.5%</td>
<td title="Share Mexican of Unauthorized Immigrants, 2012" data-sort="7">7%</td>
<td title="Change in Unauthorized Immigrant Population, 2009-2012"><abbr title="Not statistically significant">n.s.</abbr></td>
</tr>
<tr id="us-id">
<td class="left-aligned" title="State">Idaho</td>
<td title="Unauthorized Immigrant Population, 2012">50,000</td>
<td title="Unauthorized Immigrant Share of Population, 2012">3.0%</td>
<td title="Unauthorized Share of Immigrant Population, 2012">43%</td>
<td title="Unauthorized Immigrant Share of Labor Force, 2012">4.6%</td>
<td title="Share of K-12 Students with Unauthorized Immigrant Parent(s), 2012">5.5%</td>
<td title="Share Mexican of Unauthorized Immigrants, 2012" data-sort="83">83%</td>
<td title="Change in Unauthorized Immigrant Population, 2009-2012">10,000</td>
</tr>
<tr id="us-il">
<td class="left-aligned" title="State">Illinois</td>
<td title="Unauthorized Immigrant Population, 2012">475,000</td>
<td title="Unauthorized Immigrant Share of Population, 2012">3.7%</td>
<td title="Unauthorized Share of Immigrant Population, 2012">26%</td>
<td title="Unauthorized Immigrant Share of Labor Force, 2012">5.2%</td>
<td title="Share of K-12 Students with Unauthorized Immigrant Parent(s), 2012">8.2%</td>
<td title="Share Mexican of Unauthorized Immigrants, 2012" data-sort="72">72%</td>
<td title="Change in Unauthorized Immigrant Population, 2009-2012" class="negative">-30,000</td>
</tr>
<tr id="us-in">
<td class="left-aligned" title="State">Indiana</td>
<td title="Unauthorized Immigrant Population, 2012">85,000</td>
<td title="Unauthorized Immigrant Share of Population, 2012">1.3%</td>
<td title="Unauthorized Share of Immigrant Population, 2012">27%</td>
<td title="Unauthorized Immigrant Share of Labor Force, 2012">1.9%</td>
<td title="Share of K-12 Students with Unauthorized Immigrant Parent(s), 2012">2.8%</td>
<td title="Share Mexican of Unauthorized Immigrants, 2012" data-sort="68">68%</td>
<td title="Change in Unauthorized Immigrant Population, 2009-2012" class="negative">-15,000</td>
</tr>
<tr id="us-ia">
<td class="left-aligned" title="State">Iowa</td>
<td title="Unauthorized Immigrant Population, 2012">40,000</td>
<td title="Unauthorized Immigrant Share of Population, 2012">1.4%</td>
<td title="Unauthorized Share of Immigrant Population, 2012">30%</td>
<td title="Unauthorized Immigrant Share of Labor Force, 2012">2.0%</td>
<td title="Share of K-12 Students with Unauthorized Immigrant Parent(s), 2012">2.7%</td>
<td title="Share Mexican of Unauthorized Immigrants, 2012" data-sort="65">65%</td>
<td title="Change in Unauthorized Immigrant Population, 2009-2012"><abbr title="Not statistically significant">n.s.</abbr></td>
</tr>
<tr id="us-ks">
<td class="left-aligned" title="State">Kansas</td>
<td title="Unauthorized Immigrant Population, 2012">75,000</td>
<td title="Unauthorized Immigrant Share of Population, 2012">2.6%</td>
<td title="Unauthorized Share of Immigrant Population, 2012">38%</td>
<td title="Unauthorized Immigrant Share of Labor Force, 2012">3.5%</td>
<td title="Share of K-12 Students with Unauthorized Immigrant Parent(s), 2012">7.0%</td>
<td title="Share Mexican of Unauthorized Immigrants, 2012" data-sort="75">75%</td>
<td title="Change in Unauthorized Immigrant Population, 2009-2012" class="negative">-20,000</td>
</tr>
<tr id="us-ky">
<td class="left-aligned" title="State">Kentucky</td>
<td title="Unauthorized Immigrant Population, 2012">35,000</td>
<td title="Unauthorized Immigrant Share of Population, 2012">0.8%</td>
<td title="Unauthorized Share of Immigrant Population, 2012">26%</td>
<td title="Unauthorized Immigrant Share of Labor Force, 2012">1.2%</td>
<td title="Share of K-12 Students with Unauthorized Immigrant Parent(s), 2012">1.8%</td>
<td title="Share Mexican of Unauthorized Immigrants, 2012" data-sort="48">48%</td>
<td title="Change in Unauthorized Immigrant Population, 2009-2012" class="negative">-15,000</td>
</tr>
<tr id="us-la">
<td class="left-aligned" title="State">Louisiana</td>
<td title="Unauthorized Immigrant Population, 2012">55,000</td>
<td title="Unauthorized Immigrant Share of Population, 2012">1.2%</td>
<td title="Unauthorized Share of Immigrant Population, 2012">31%</td>
<td title="Unauthorized Immigrant Share of Labor Force, 2012">1.8%</td>
<td title="Share of K-12 Students with Unauthorized Immigrant Parent(s), 2012">1.7%</td>
<td title="Share Mexican of Unauthorized Immigrants, 2012" data-sort="29">29%</td>
<td title="Change in Unauthorized Immigrant Population, 2009-2012"><abbr title="Not statistically significant">n.s.</abbr></td>
</tr>
<tr id="us-me">
<td class="left-aligned" title="State">Maine</td>
<td title="Unauthorized Immigrant Population, 2012">&lt;5,000</td>
<td title="Unauthorized Immigrant Share of Population, 2012">0.2%</td>
<td title="Unauthorized Share of Immigrant Population, 2012">6%</td>
<td title="Unauthorized Immigrant Share of Labor Force, 2012">0.3%</td>
<td title="Share of K-12 Students with Unauthorized Immigrant Parent(s), 2012">0.2%</td>
<td title="Share Mexican of Unauthorized Immigrants, 2012" data-sort="0">B</td>
<td title="Change in Unauthorized Immigrant Population, 2009-2012"><abbr title="Not statistically significant">n.s.</abbr></td>
</tr>
<tr id="us-md">
<td class="left-aligned" title="State">Maryland</td>
<td title="Unauthorized Immigrant Population, 2012">250,000</td>
<td title="Unauthorized Immigrant Share of Population, 2012">4.3%</td>
<td title="Unauthorized Share of Immigrant Population, 2012">29%</td>
<td title="Unauthorized Immigrant Share of Labor Force, 2012">6.2%</td>
<td title="Share of K-12 Students with Unauthorized Immigrant Parent(s), 2012">5.7%</td>
<td title="Share Mexican of Unauthorized Immigrants, 2012" data-sort="12">12%</td>
<td title="Change in Unauthorized Immigrant Population, 2009-2012">25,000</td>
</tr>
<tr id="us-ma">
<td class="left-aligned" title="State">Massachusetts</td>
<td title="Unauthorized Immigrant Population, 2012">150,000</td>
<td title="Unauthorized Immigrant Share of Population, 2012">2.3%</td>
<td title="Unauthorized Share of Immigrant Population, 2012">15%</td>
<td title="Unauthorized Immigrant Share of Labor Force, 2012">3.4%</td>
<td title="Share of K-12 Students with Unauthorized Immigrant Parent(s), 2012">2.2%</td>
<td title="Share Mexican of Unauthorized Immigrants, 2012" data-sort="3">3%</td>
<td title="Change in Unauthorized Immigrant Population, 2009-2012" class="negative">-25,000</td>
</tr>
<tr id="us-mi">
<td class="left-aligned" title="State">Michigan</td>
<td title="Unauthorized Immigrant Population, 2012">120,000</td>
<td title="Unauthorized Immigrant Share of Population, 2012">1.2%</td>
<td title="Unauthorized Share of Immigrant Population, 2012">18%</td>
<td title="Unauthorized Immigrant Share of Labor Force, 2012">1.6%</td>
<td title="Share of K-12 Students with Unauthorized Immigrant Parent(s), 2012">1.9%</td>
<td title="Share Mexican of Unauthorized Immigrants, 2012" data-sort="36">36%</td>
<td title="Change in Unauthorized Immigrant Population, 2009-2012"><abbr title="Not statistically significant">n.s.</abbr></td>
</tr>
<tr id="us-mn">
<td class="left-aligned" title="State">Minnesota</td>
<td title="Unauthorized Immigrant Population, 2012">95,000</td>
<td title="Unauthorized Immigrant Share of Population, 2012">1.8%</td>
<td title="Unauthorized Share of Immigrant Population, 2012">22%</td>
<td title="Unauthorized Immigrant Share of Labor Force, 2012">2.5%</td>
<td title="Share of K-12 Students with Unauthorized Immigrant Parent(s), 2012">3.0%</td>
<td title="Share Mexican of Unauthorized Immigrants, 2012" data-sort="53">53%</td>
<td title="Change in Unauthorized Immigrant Population, 2009-2012"><abbr title="Not statistically significant">n.s.</abbr></td>
</tr>
<tr id="us-ms">
<td class="left-aligned" title="State">Mississippi</td>
<td title="Unauthorized Immigrant Population, 2012">25,000</td>
<td title="Unauthorized Immigrant Share of Population, 2012">0.9%</td>
<td title="Unauthorized Share of Immigrant Population, 2012">44%</td>
<td title="Unauthorized Immigrant Share of Labor Force, 2012">1.2%</td>
<td title="Share of K-12 Students with Unauthorized Immigrant Parent(s), 2012">1.0%</td>
<td title="Share Mexican of Unauthorized Immigrants, 2012" data-sort="57">57%</td>
<td title="Change in Unauthorized Immigrant Population, 2009-2012"><abbr title="Not statistically significant">n.s.</abbr></td>
</tr>
<tr id="us-mo">
<td class="left-aligned" title="State">Missouri</td>
<td title="Unauthorized Immigrant Population, 2012">65,000</td>
<td title="Unauthorized Immigrant Share of Population, 2012">1.1%</td>
<td title="Unauthorized Share of Immigrant Population, 2012">27%</td>
<td title="Unauthorized Immigrant Share of Labor Force, 2012">1.4%</td>
<td title="Share of K-12 Students with Unauthorized Immigrant Parent(s), 2012">2.0%</td>
<td title="Share Mexican of Unauthorized Immigrants, 2012" data-sort="35">35%</td>
<td title="Change in Unauthorized Immigrant Population, 2009-2012"><abbr title="Not statistically significant">n.s.</abbr></td>
</tr>
<tr id="us-mt">
<td class="left-aligned" title="State">Montana</td>
<td title="Unauthorized Immigrant Population, 2012">&lt;5,000</td>
<td title="Unauthorized Immigrant Share of Population, 2012">0.3%</td>
<td title="Unauthorized Share of Immigrant Population, 2012">14%</td>
<td title="Unauthorized Immigrant Share of Labor Force, 2012">0.4%</td>
<td title="Share of K-12 Students with Unauthorized Immigrant Parent(s), 2012">0.4%</td>
<td title="Share Mexican of Unauthorized Immigrants, 2012" data-sort="0">B</td>
<td title="Change in Unauthorized Immigrant Population, 2009-2012"><abbr title="Not statistically significant">n.s.</abbr></td>
</tr>
<tr id="us-ne">
<td class="left-aligned" title="State">Nebraska</td>
<td title="Unauthorized Immigrant Population, 2012">55,000</td>
<td title="Unauthorized Immigrant Share of Population, 2012">2.8%</td>
<td title="Unauthorized Share of Immigrant Population, 2012">41%</td>
<td title="Unauthorized Immigrant Share of Labor Force, 2012">3.7%</td>
<td title="Share of K-12 Students with Unauthorized Immigrant Parent(s), 2012">7.1%</td>
<td title="Share Mexican of Unauthorized Immigrants, 2012" data-sort="67">67%</td>
<td title="Change in Unauthorized Immigrant Population, 2009-2012">10,000</td>
</tr>
<tr id="us-nv">
<td class="left-aligned" title="State">Nevada</td>
<td title="Unauthorized Immigrant Population, 2012">210,000</td>
<td title="Unauthorized Immigrant Share of Population, 2012">7.6%</td>
<td title="Unauthorized Share of Immigrant Population, 2012">39%</td>
<td title="Unauthorized Immigrant Share of Labor Force, 2012">10.2%</td>
<td title="Share of K-12 Students with Unauthorized Immigrant Parent(s), 2012">17.7%</td>
<td title="Share Mexican of Unauthorized Immigrants, 2012" data-sort="69">69%</td>
<td title="Change in Unauthorized Immigrant Population, 2009-2012" class="negative">-20,000</td>
</tr>
<tr id="us-nh">
<td class="left-aligned" title="State">New Hampshire</td>
<td title="Unauthorized Immigrant Population, 2012">10,000</td>
<td title="Unauthorized Immigrant Share of Population, 2012">0.9%</td>
<td title="Unauthorized Share of Immigrant Population, 2012">15%</td>
<td title="Unauthorized Immigrant Share of Labor Force, 2012">1.2%</td>
<td title="Share of K-12 Students with Unauthorized Immigrant Parent(s), 2012">0.7%</td>
<td title="Share Mexican of Unauthorized Immigrants, 2012" data-sort="7">7%</td>
<td title="Change in Unauthorized Immigrant Population, 2009-2012"><abbr title="Not statistically significant">n.s.</abbr></td>
</tr>
<tr id="us-nj">
<td class="left-aligned" title="State">New Jersey</td>
<td title="Unauthorized Immigrant Population, 2012">525,000</td>
<td title="Unauthorized Immigrant Share of Population, 2012">5.8%</td>
<td title="Unauthorized Share of Immigrant Population, 2012">26%</td>
<td title="Unauthorized Immigrant Share of Labor Force, 2012">8.2%</td>
<td title="Share of K-12 Students with Unauthorized Immigrant Parent(s), 2012">7.7%</td>
<td title="Share Mexican of Unauthorized Immigrants, 2012" data-sort="19">19%</td>
<td title="Change in Unauthorized Immigrant Population, 2009-2012">75,000</td>
</tr>
<tr id="us-nm">
<td class="left-aligned" title="State">New Mexico</td>
<td title="Unauthorized Immigrant Population, 2012">70,000</td>
<td title="Unauthorized Immigrant Share of Population, 2012">3.4%</td>
<td title="Unauthorized Share of Immigrant Population, 2012">35%</td>
<td title="Unauthorized Immigrant Share of Labor Force, 2012">4.7%</td>
<td title="Share of K-12 Students with Unauthorized Immigrant Parent(s), 2012">7.1%</td>
<td title="Share Mexican of Unauthorized Immigrants, 2012" data-sort="89">89%</td>
<td title="Change in Unauthorized Immigrant Population, 2009-2012" class="negative">-20,000</td>
</tr>
<tr id="us-ny">
<td class="left-aligned" title="State">New York</td>
<td title="Unauthorized Immigrant Population, 2012">750,000</td>
<td title="Unauthorized Immigrant Share of Population, 2012">3.8%</td>
<td title="Unauthorized Share of Immigrant Population, 2012">16%</td>
<td title="Unauthorized Immigrant Share of Labor Force, 2012">5.7%</td>
<td title="Share of K-12 Students with Unauthorized Immigrant Parent(s), 2012">5.5%</td>
<td title="Share Mexican of Unauthorized Immigrants, 2012" data-sort="20">20%</td>
<td title="Change in Unauthorized Immigrant Population, 2009-2012" class="negative">-60,000</td>
</tr>
<tr id="us-nc">
<td class="left-aligned" title="State">North Carolina</td>
<td title="Unauthorized Immigrant Population, 2012">350,000</td>
<td title="Unauthorized Immigrant Share of Population, 2012">3.6%</td>
<td title="Unauthorized Share of Immigrant Population, 2012">44%</td>
<td title="Unauthorized Immigrant Share of Labor Force, 2012">5.2%</td>
<td title="Share of K-12 Students with Unauthorized Immigrant Parent(s), 2012">7.6%</td>
<td title="Share Mexican of Unauthorized Immigrants, 2012" data-sort="62">62%</td>
<td title="Change in Unauthorized Immigrant Population, 2009-2012"><abbr title="Not statistically significant">n.s.</abbr></td>
</tr>
<tr id="us-nd">
<td class="left-aligned" title="State">North Dakota</td>
<td title="Unauthorized Immigrant Population, 2012">&lt;5,000</td>
<td title="Unauthorized Immigrant Share of Population, 2012">0.3%</td>
<td title="Unauthorized Share of Immigrant Population, 2012">10%</td>
<td title="Unauthorized Immigrant Share of Labor Force, 2012">0.5%</td>
<td title="Share of K-12 Students with Unauthorized Immigrant Parent(s), 2012">0.1%</td>
<td title="Share Mexican of Unauthorized Immigrants, 2012" data-sort="0">B</td>
<td title="Change in Unauthorized Immigrant Population, 2009-2012"><abbr title="Not statistically significant">n.s.</abbr></td>
</tr>
<tr id="us-oh">
<td class="left-aligned" title="State">Ohio</td>
<td title="Unauthorized Immigrant Population, 2012">95,000</td>
<td title="Unauthorized Immigrant Share of Population, 2012">0.8%</td>
<td title="Unauthorized Share of Immigrant Population, 2012">20%</td>
<td title="Unauthorized Immigrant Share of Labor Force, 2012">1.1%</td>
<td title="Share of K-12 Students with Unauthorized Immigrant Parent(s), 2012">1.3%</td>
<td title="Share Mexican of Unauthorized Immigrants, 2012" data-sort="34">34%</td>
<td title="Change in Unauthorized Immigrant Population, 2009-2012"><abbr title="Not statistically significant">n.s.</abbr></td>
</tr>
<tr id="us-ok">
<td class="left-aligned" title="State">Oklahoma</td>
<td title="Unauthorized Immigrant Population, 2012">100,000</td>
<td title="Unauthorized Immigrant Share of Population, 2012">2.6%</td>
<td title="Unauthorized Share of Immigrant Population, 2012">43%</td>
<td title="Unauthorized Immigrant Share of Labor Force, 2012">3.7%</td>
<td title="Share of K-12 Students with Unauthorized Immigrant Parent(s), 2012">5.5%</td>
<td title="Share Mexican of Unauthorized Immigrants, 2012" data-sort="76">76%</td>
<td title="Change in Unauthorized Immigrant Population, 2009-2012"><abbr title="Not statistically significant">n.s.</abbr></td>
</tr>
<tr id="us-or">
<td class="left-aligned" title="State">Oregon</td>
<td title="Unauthorized Immigrant Population, 2012">120,000</td>
<td title="Unauthorized Immigrant Share of Population, 2012">3.1%</td>
<td title="Unauthorized Share of Immigrant Population, 2012">31%</td>
<td title="Unauthorized Immigrant Share of Labor Force, 2012">4.6%</td>
<td title="Share of K-12 Students with Unauthorized Immigrant Parent(s), 2012">7.5%</td>
<td title="Share Mexican of Unauthorized Immigrants, 2012" data-sort="75">75%</td>
<td title="Change in Unauthorized Immigrant Population, 2009-2012" class="negative">-20,000</td>
</tr>
<tr id="us-pa">
<td class="left-aligned" title="State">Pennsylvania</td>
<td title="Unauthorized Immigrant Population, 2012">170,000</td>
<td title="Unauthorized Immigrant Share of Population, 2012">1.3%</td>
<td title="Unauthorized Share of Immigrant Population, 2012">21%</td>
<td title="Unauthorized Immigrant Share of Labor Force, 2012">1.7%</td>
<td title="Share of K-12 Students with Unauthorized Immigrant Parent(s), 2012">2.0%</td>
<td title="Share Mexican of Unauthorized Immigrants, 2012" data-sort="23">23%</td>
<td title="Change in Unauthorized Immigrant Population, 2009-2012">30,000</td>
</tr>
<tr id="us-ri">
<td class="left-aligned" title="State">Rhode Island</td>
<td title="Unauthorized Immigrant Population, 2012">35,000</td>
<td title="Unauthorized Immigrant Share of Population, 2012">3.3%</td>
<td title="Unauthorized Share of Immigrant Population, 2012">23%</td>
<td title="Unauthorized Immigrant Share of Labor Force, 2012">4.6%</td>
<td title="Share of K-12 Students with Unauthorized Immigrant Parent(s), 2012">5.4%</td>
<td title="Share Mexican of Unauthorized Immigrants, 2012" data-sort="6">6%</td>
<td title="Change in Unauthorized Immigrant Population, 2009-2012"><abbr title="Not statistically significant">n.s.</abbr></td>
</tr>
<tr id="us-sc">
<td class="left-aligned" title="State">South Carolina</td>
<td title="Unauthorized Immigrant Population, 2012">95,000</td>
<td title="Unauthorized Immigrant Share of Population, 2012">2.0%</td>
<td title="Unauthorized Share of Immigrant Population, 2012">41%</td>
<td title="Unauthorized Immigrant Share of Labor Force, 2012">3.0%</td>
<td title="Share of K-12 Students with Unauthorized Immigrant Parent(s), 2012">3.8%</td>
<td title="Share Mexican of Unauthorized Immigrants, 2012" data-sort="61">61%</td>
<td title="Change in Unauthorized Immigrant Population, 2009-2012"><abbr title="Not statistically significant">n.s.</abbr></td>
</tr>
<tr id="us-sd">
<td class="left-aligned" title="State">South Dakota</td>
<td title="Unauthorized Immigrant Population, 2012">&lt;5,000</td>
<td title="Unauthorized Immigrant Share of Population, 2012">0.4%</td>
<td title="Unauthorized Share of Immigrant Population, 2012">14%</td>
<td title="Unauthorized Immigrant Share of Labor Force, 2012">0.6%</td>
<td title="Share of K-12 Students with Unauthorized Immigrant Parent(s), 2012">0.7%</td>
<td title="Share Mexican of Unauthorized Immigrants, 2012" data-sort="0">B</td>
<td title="Change in Unauthorized Immigrant Population, 2009-2012"><abbr title="Not statistically significant">n.s.</abbr></td>
</tr>
<tr id="us-tn">
<td class="left-aligned" title="State">Tennessee</td>
<td title="Unauthorized Immigrant Population, 2012">130,000</td>
<td title="Unauthorized Immigrant Share of Population, 2012">2.0%</td>
<td title="Unauthorized Share of Immigrant Population, 2012">40%</td>
<td title="Unauthorized Immigrant Share of Labor Force, 2012">2.8%</td>
<td title="Share of K-12 Students with Unauthorized Immigrant Parent(s), 2012">3.4%</td>
<td title="Share Mexican of Unauthorized Immigrants, 2012" data-sort="59">59%</td>
<td title="Change in Unauthorized Immigrant Population, 2009-2012"><abbr title="Not statistically significant">n.s.</abbr></td>
</tr>
<tr id="us-tx">
<td class="left-aligned" title="State">Texas</td>
<td title="Unauthorized Immigrant Population, 2012">1,650,000</td>
<td title="Unauthorized Immigrant Share of Population, 2012">6.3%</td>
<td title="Unauthorized Share of Immigrant Population, 2012">37%</td>
<td title="Unauthorized Immigrant Share of Labor Force, 2012">8.9%</td>
<td title="Share of K-12 Students with Unauthorized Immigrant Parent(s), 2012">13.1%</td>
<td title="Share Mexican of Unauthorized Immigrants, 2012" data-sort="75">75%</td>
<td title="Change in Unauthorized Immigrant Population, 2009-2012"><abbr title="Not statistically significant">n.s.</abbr></td>
</tr>
<tr id="us-ut">
<td class="left-aligned" title="State">Utah</td>
<td title="Unauthorized Immigrant Population, 2012">100,000</td>
<td title="Unauthorized Immigrant Share of Population, 2012">3.6%</td>
<td title="Unauthorized Share of Immigrant Population, 2012">41%</td>
<td title="Unauthorized Immigrant Share of Labor Force, 2012">5.1%</td>
<td title="Share of K-12 Students with Unauthorized Immigrant Parent(s), 2012">7.1%</td>
<td title="Share Mexican of Unauthorized Immigrants, 2012" data-sort="69">69%</td>
<td title="Change in Unauthorized Immigrant Population, 2009-2012"><abbr title="Not statistically significant">n.s.</abbr></td>
</tr>
<tr id="us-vt">
<td class="left-aligned" title="State">Vermont</td>
<td title="Unauthorized Immigrant Population, 2012">&lt;5,000</td>
<td title="Unauthorized Immigrant Share of Population, 2012">0.4%</td>
<td title="Unauthorized Share of Immigrant Population, 2012">9%</td>
<td title="Unauthorized Immigrant Share of Labor Force, 2012">0.5%</td>
<td title="Share of K-12 Students with Unauthorized Immigrant Parent(s), 2012">0.2%</td>
<td title="Share Mexican of Unauthorized Immigrants, 2012" data-sort="0">B</td>
<td title="Change in Unauthorized Immigrant Population, 2009-2012"><abbr title="Not statistically significant">n.s.</abbr></td>
</tr>
<tr id="us-va">
<td class="left-aligned" title="State">Virginia</td>
<td title="Unauthorized Immigrant Population, 2012">275,000</td>
<td title="Unauthorized Immigrant Share of Population, 2012">3.5%</td>
<td title="Unauthorized Share of Immigrant Population, 2012">28%</td>
<td title="Unauthorized Immigrant Share of Labor Force, 2012">5.1%</td>
<td title="Share of K-12 Students with Unauthorized Immigrant Parent(s), 2012">5.5%</td>
<td title="Share Mexican of Unauthorized Immigrants, 2012" data-sort="15">15%</td>
<td title="Change in Unauthorized Immigrant Population, 2009-2012">25,000</td>
</tr>
<tr id="us-wa">
<td class="left-aligned" title="State">Washington</td>
<td title="Unauthorized Immigrant Population, 2012">230,000</td>
<td title="Unauthorized Immigrant Share of Population, 2012">3.3%</td>
<td title="Unauthorized Share of Immigrant Population, 2012">24%</td>
<td title="Unauthorized Immigrant Share of Labor Force, 2012">4.9%</td>
<td title="Share of K-12 Students with Unauthorized Immigrant Parent(s), 2012">7.1%</td>
<td title="Share Mexican of Unauthorized Immigrants, 2012" data-sort="62">62%</td>
<td title="Change in Unauthorized Immigrant Population, 2009-2012"><abbr title="Not statistically significant">n.s.</abbr></td>
</tr>
<tr id="us-wv">
<td class="left-aligned" title="State">West Virginia</td>
<td title="Unauthorized Immigrant Population, 2012">&lt;5,000</td>
<td title="Unauthorized Immigrant Share of Population, 2012">0.2%</td>
<td title="Unauthorized Share of Immigrant Population, 2012">13%</td>
<td title="Unauthorized Immigrant Share of Labor Force, 2012">0.2%</td>
<td title="Share of K-12 Students with Unauthorized Immigrant Parent(s), 2012">0.1%</td>
<td title="Share Mexican of Unauthorized Immigrants, 2012" data-sort="0">B</td>
<td title="Change in Unauthorized Immigrant Population, 2009-2012"><abbr title="Not statistically significant">n.s.</abbr></td>
</tr>
<tr id="us-wi">
<td class="left-aligned" title="State">Wisconsin</td>
<td title="Unauthorized Immigrant Population, 2012">85,000</td>
<td title="Unauthorized Immigrant Share of Population, 2012">1.5%</td>
<td title="Unauthorized Share of Immigrant Population, 2012">30%</td>
<td title="Unauthorized Immigrant Share of Labor Force, 2012">1.8%</td>
<td title="Share of K-12 Students with Unauthorized Immigrant Parent(s), 2012">3.3%</td>
<td title="Share Mexican of Unauthorized Immigrants, 2012" data-sort="76">76%</td>
<td title="Change in Unauthorized Immigrant Population, 2009-2012"><abbr title="Not statistically significant">n.s.</abbr></td>
</tr>
<tr id="us-wy">
<td class="left-aligned" title="State">Wyoming</td>
<td title="Unauthorized Immigrant Population, 2012">5,000</td>
<td title="Unauthorized Immigrant Share of Population, 2012">1.0%</td>
<td title="Unauthorized Share of Immigrant Population, 2012">31%</td>
<td title="Unauthorized Immigrant Share of Labor Force, 2012">1.3%</td>
<td title="Share of K-12 Students with Unauthorized Immigrant Parent(s), 2012">2.1%</td>
<td title="Share Mexican of Unauthorized Immigrants, 2012" data-sort="82">82%</td>
<td title="Change in Unauthorized Immigrant Population, 2009-2012"><abbr title="Not statistically significant">n.s.</abbr></td>
</tr>
</tbody>
</table>
<p class="source">Note: All numbers are rounded independently and are not adjusted to sum to the total U.S. figure or other totals. Percents and Change calculated from unrounded numbers. See <a href="http://www.pewhispanic.org/2014/11/18/appendix-c-methodology-4/" target="_top">Methodology</a> for rounding rules. Significant changes are based on 90% confidence interval. When ranked, states with the same numbers or shares within the column that is ranked are shown alphabetically.<br>
"B" &ndash; Base of percent is too small to produce a reliable estimate.<br>
"n.s." &ndash; Change is not statistically significant.</p>
<p class="source">Source: Pew Research Center estimates for 2009 and 2012 based on augmented American Community Survey data from Integrated Public Use Microdata Series (IPUMS)</p>
</div>
<?php
}
add_action( 'pew_interactive_unauthorized-immigrants-2012', 'unauthorized_immigrants_body' );
function unauthorized_immigrants_wp_footer() {
?>
<script>
jQuery(document).ready(function($) {
/*
* Helpers
*
*/
//Turn 123456789 into 123,456,789
function numberWithCommas(x) {
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
}
//Given a URL with /map/ in it, return the slug. http://example.com/sometihng/map/this-is-the-slug/ --> this-is-the-slug
function urlToSlug( url ) {
return url.split('/map/')[1].replace(/\//, '');
}
function slugToURL( slug ) {
var permalink = '<?=get_permalink();?>';
if( slug && slug != 'population' ) {
permalink += 'map/' + slug + '/';
}
return permalink;
}
//Transform the rows to set the 'value' property to whatever column we want to show.
function setTableDataTo( key ) {
var ourData = rows;
if( !key || typeof rows[0][key] == 'undefined') {
return ourData;
}
for( i=0; i<ourData.length; i++ ) {
ourData[i].value = ourData[i][key];
}
return ourData
}
function getColumnForSelectedMap() {
columnNum = $('#map-options :selected').data('column');
return columns[ columnNum ];
}
function splitLongText( text ) {
var words = text.split(' ');
if( words.length < 3 ) {
return text;
}
var limit = Math.floor( words.length / 2 );
if( words[ limit ] ) {
words[ limit ] += '<br/>';
}
return words.join(' ');
}
//Colors for the map legend going from darkest to lightest
var mapColors = ['#9e7f2d', '#d1a730', '#e4cb83', '#ecdbac', '#f6eed6', '#f1f1f1'];
/*
* Map Options <select>
*
*/
//Just in case the form gets submitted somewhow...
$('#unauthorized-immigration-form').submit(function(e) {
e.preventDefault();
});
$('#map-options').change(function() {
$this = $(this);
var slug = $this.val();
var url = slugToURL( slug );
if(
history.pushState &&
url != window.location &&
!$('body').is('.iframe')
) {
history.pushState({ slug: slug }, null, url);
}
$('.group:not(.hide)').addClass('hide');
$('#' + slug + '.group').removeClass('hide');
//Update the iframe code
$iframeEmbed = $('.interactive-footer-container .code');
$iframeEmbed.text( $iframeEmbed.text().replace(/src="(.+?)"/ig, 'src="' + url + 'iframe/"') );
$('.group .map').html('');
drawTheMap( slug );
});
//Update the map when the back button is clicked
$(window).bind('popstate', function(e) {
var slug = urlToSlug( window.location.href );
$('#map-options').val( slug ).change();
});
/*
* Scrape the table data.
*
*/
$table = $('#map-data');
var columnMapping = {};
var columns = [];
$( 'thead th', $table).each(function(count) {
$this = $(this);
//Get the text value of the table header which will be used as the columns name.
var text = $.trim( $this.text() );
var slug = $this.id;
columns[count] = {
'name': text
};
});
var rows = [];
var tableRows = $( 'tbody tr', $table );
var tableRowsLength = tableRows.length;
for( r = 0; r < tableRowsLength; r++ ) {
var row = tableRows[r];
var cellData = [];
var cellDisplayData = [];
var cells = $( 'td', row );
for( c = 0; c < cells.length; c++ ) {
var column = columns[c];
var cell = $.trim( $(cells[c]).text() );
cellDisplayData[c] = cell;
//Remove any of that icky number prefixes and suffixes
cell = cell.replace(/[>%,<\$¢£#!@^&*\+\(\)]/g, '');
cell = parseFloat(cell);
if ( isNaN(cell) ) {
cell = null;
}
//We can't have nulls where state data isn't available.
if( (c == 6 || c == 7) && !cell ) {
cell = 0;
}
cellData[c] = cell;
}
rows.push({
'hc-key': row.id,
'state': cellData[0],
'population': cellData[1],
'population-share': cellData[2],
'all-immigrant-share': cellData[3],
'labor-force-share': cellData[4],
'k-12-share': cellData[5],
'mexican-share': cellData[6],
'population-change': cellData[7],
'population-display': cellDisplayData[1],
'population-share-display': cellDisplayData[2],
'all-immigrant-share-display': cellDisplayData[3],
'labor-force-share-display': cellDisplayData[4],
'k-12-share-display': cellDisplayData[5],
'mexican-share-display': cellDisplayData[6],
'population-change-display': cellDisplayData[7]
});
}
//Redraws the map. 'slug' maps to what column from the data table that we are mapping.
function drawTheMap( slug ) {
var col = getColumnForSelectedMap();
var narrowScreen = false;
if( $(window).width() < 560 ) {
narrowScreen = true;
}
var dataClasses = [];
var legendTitleText = '';
switch( slug ) {
case 'population':
dataClasses = [{
from: 750000,
color: mapColors[0]
}, {
from: 170000,
to: 725000,
color: mapColors[1]
}, {
from: 75000,
to: 160000,
color: mapColors[2]
}, {
from: 25000,
to: 70000,
color: mapColors[3]
}, {
to: 25000,
color: mapColors[4]
}];
legendTitleText = 'U.S. Total: <strong>11,200,000</strong>';
break;
case 'population-share':
dataClasses = [{
from: 5.0,
name: '5.0% or more',
color: mapColors[0]
}, {
from: 3.5,
to: 4.9,
name: '3.5 to 4.9%',
color: mapColors[1]
}, {
from: 2.5,
to: 3.4,
name: '2.5 to 3.4%',
color: mapColors[2]
}, {
from: 1.6,
to: 2.4,
name: '1.6 to 2.4%',
color: mapColors[3]
}, {
to: 1.5,
name: '1.5% or less',
color: mapColors[4]
}];
legendTitleText = 'U.S. Average: <strong>3.5%</strong>';
break;
case 'all-immigrant-share':
dataClasses = [{
from: 33,
to: 45,
name: '33 to 45%',
color: mapColors[0]
}, {
from: 25,
to: 32,
name: '25 to 32%',
color: mapColors[1]
}, {
from: 15,
to: 24,
name: '15 to 24%',
color: mapColors[2]
}, {
to: 15,
name: '14% or less',
color: mapColors[3]
}];
legendTitleText = 'U.S. Average: <strong>26%</strong>';
break;
case 'labor-force-share':
dataClasses = [{
from: 6.0,
name: '6.0% or more',
color: mapColors[0]
}, {
from: 4.5,
to: 5.9,
name: '4.5 to 5.9%',
color: mapColors[1]
}, {
from: 3.0,
to: 4.4,
name: '3.0 to 4.4%',
color: mapColors[2]
}, {
from: 1.5,
to: 2.9,
name: '1.5 to 2.9%',
color: mapColors[3]
}, {
to: 1.5,
name: '1.4% or less',
color: mapColors[4]
}];
legendTitleText = 'U.S. Average: <strong>5.1%</strong>';
break;
case 'k-12-share':
dataClasses = [{
from: 10.0,
name: '10.0% or more',
color: mapColors[0]
}, {
from: 7.0,
to: 9.9,
name: '7.0 to 9.9%',
color: mapColors[1]
}, {
from: 3.5,
to: 6.9,
name: '3.5 to 6.9%',
color: mapColors[2]
}, {
from: 1.5,
to: 3.4,
name: '1.5 to 3.4%',
color: mapColors[3]
}, {
to: 1.5,
name: '1.4% or less',
color: mapColors[4]
}];
legendTitleText = 'U.S. Average: <strong>6.9%</strong>';
break;
case 'mexican-share':
dataClasses = [{
from: 70,
name: '70% or more',
color: mapColors[0]
}, {
from: 60,
to: 69,
name: '60 to 69%',
color: mapColors[1]
}, {
from: 45,
to: 59,
name: '45 to 59%',
color: mapColors[2]
}, {
from: 16,
to: 44,
name: '16 to 44%',
color: mapColors[3]
}, {
to: 15,
name: '15% or less',
color: mapColors[4]
}, {
to: 0,
name: 'Not Available',
color: mapColors[5]
}];
legendTitleText = 'U.S. Average: <strong>52%</strong>';
break;
case 'population-change':
dataClasses = [{
from: 1,
name: 'Statistically Significant Increase',
color: mapColors[0]
}, {
from: -0.1,
to: 0,
name: 'Change Is Not Statistically Significant',
color: mapColors[5]
}, {
from: -100000,
to: -1,
name: 'Statistically Significant Decrease',
color: mapColors[4]
}];
break;
}
var chartWidth = $( '#' + slug ).width();
var HighmapsOptions = {
chart: {
height: chartWidth / 1.5,
},
title: {
text : ''
},
colorAxis: {
dataClasses: dataClasses
},
legend: {
title: {
text: legendTitleText,
style: {
fontWeight: 'normal'
}
},
backgroundColor: 'rgba(255, 255, 255, 0.5)',
layout: 'vertical',
align: 'right',
floating: true,
valueDecimals: 0,
useHTML: true,
symbolRadius: 0,
symbolHeight: 14
},
mapNavigation: {
enableButtons: true
},
credits: {
enabled: false
},
series : [{
data : setTableDataTo( slug ),
mapData: Highcharts.maps['countries/us/us-all'],
joinBy: 'hc-key',
name: col.name,
//allowPointSelect: true,
cursor: 'pointer',
states: {
hover: {
color:'#585858'
}
},
dataLabels: {
enabled: false
}
}],
tooltip: {
useHTML: true,
style: {
fontFamily: '"franklin-gothic-urw",Verdana,Geneva,sans-serif'
},
formatter: function() {
var displayValue = this.point[ slug + '-display' ];
if( displayValue == 'n.s.' ) {
displayValue = 'Change Is Not Statistically Significant';
}
if( displayValue == 'B' ) {
displayValue = 'Not Available'
}
var headline = this.series.name;
var desc = this.point.name + ': ' + displayValue;
if( narrowScreen ) {
headline = splitLongText( headline );
desc = this.point.name + ': ' + splitLongText( displayValue );
}
var output = [];
output.push( '<strong>' + headline + '</strong>' );
output.push( desc );
return output.join( '<br>' );
}
}
};
//If we need to adjust the options based on the data we're mapping we can do that here...
if( chartWidth < 780 ) {
HighmapsOptions.chart.height = 400;
}
$( '#' + slug + ' .map' ).highcharts('Map', HighmapsOptions );
}
//Kick it off by drawing the map for the 'active' tab as determined by the PHP logic when the page was served.
slug = $('#map-options').val();
drawTheMap( slug );
});
</script>
<?php
}
add_action( 'wp_footer', 'unauthorized_immigrants_wp_footer' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment