Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add 2019/2020 data + year navigation (via Page.js) #6

Draft
wants to merge 9 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions css/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,17 @@ td, th{
stroke: black;
}

g.SchoolName path {
g.Counties path {
stroke: #eee;
}
g.Districts path {
stroke: #870d17;
}
g.SchoolName.selected path {
g.Districts.selected path {
stroke: #870d17;
stroke-width: 2px;
}
g.SchoolName.deselected path {
g.Districts.deselected path {
stroke: #870d17;
fill: white;
}
666 changes: 333 additions & 333 deletions data/2018/districts.geo.json

Large diffs are not rendered by default.

666 changes: 333 additions & 333 deletions data/2018/districts.simple.geo.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion data/2018/districts.simple.topo.json

Large diffs are not rendered by default.

666 changes: 333 additions & 333 deletions data/2018/districts.simple1.geo.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion data/2018/districts.simple1.topo.json

Large diffs are not rendered by default.

666 changes: 333 additions & 333 deletions data/2018/districts.simple2.geo.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion data/2018/districts.simple2.topo.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion data/2018/districts.topo.json

Large diffs are not rendered by default.

332 changes: 332 additions & 0 deletions data/2019/districts.simple2.geo.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions data/2019/districts.simple2.topo.json

Large diffs are not rendered by default.

1,435 changes: 1,435 additions & 0 deletions data/2019/gradeLevelData.csv

Large diffs are not rendered by default.

329 changes: 329 additions & 0 deletions data/2020/districts.simple2.geo.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions data/2020/districts.simple2.topo.json

Large diffs are not rendered by default.

1,435 changes: 1,435 additions & 0 deletions data/2020/gradeLevelData.csv

Large diffs are not rendered by default.

101 changes: 101 additions & 0 deletions data/common/counties.simple2.geo.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions data/common/counties.simple2.topo.json

Large diffs are not rendered by default.

9 changes: 8 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@
<h1 class="cs4ia">Computer Science <span>for</span> Iowa</h1>
</div>
<div><p class="buyline">A joint project with NewBoCo &amp; DeltaV Code School</p></div>
<nav>
<ul>
<li><a href="/2018">2018</a></li>
<li><a href="/2019">2019</a></li>
<li><a href="/2020">2020</a></li>
</ul>
</nav>
</header>
<div class="iowa">
<article>
Expand All @@ -40,7 +47,7 @@ <h3>School Offers Computer Science?</h3>
<footer>
&copy; 2018 NewBoCo
</footer>

<script src="https://unpkg.com/page@1/page.js"></script>
<script src="https://unpkg.com/d3@5/dist/d3.js"></script>
<script src="https://unpkg.com/crossfilter2@1.4/crossfilter.js"></script>
<script src="https://unpkg.com/dc@3/dc.js"></script>
Expand Down
158 changes: 98 additions & 60 deletions js/viz.js
Original file line number Diff line number Diff line change
@@ -1,69 +1,77 @@
/* globals d3, crossfilter, dc, topojson */
/* globals page, d3, crossfilter, dc, topojson */

var dims;
var groups;
var schoolData;
var districtShapes;

(function(d3, crossfilter, dc, topojson) {
(function(page, d3, crossfilter, dc, topojson) {
var charts = {
gradeBands: dc.rowChart('#gradeBands'),
csResponses: dc.pieChart('#csResponses'),
map: dc.geoChoroplethChart('#map'),
table: dc.dataTable('#districts')
};

d3.json('./data/2018/districts.simple2.topo.json')
.then(function (shapes) {
districtShapes = shapes;
if (schoolData) render(schoolData, districtShapes);
});
d3.csv('./data/2018/gradeLevelData.csv', function (school) {
var gradeBands = [];

if (school['Stage El'] === '1')
gradeBands.push('Elementary');
if (school['Stage Mi'] === '1')
gradeBands.push('Middle');
if (school['Stage Hi'] === '1')
gradeBands.push('High');

if (!gradeBands.length || !+school.Students)
return;

function normalizeDistrict(district){
switch (district) {
case 'A-H-S-T COMM SCHOOL DISTRICT':
case 'WALNUT COMM SCHOOL DISTRICT':
return 'AHSTW COMM SCHOOL DISTRICT';
case 'COLO-NESCO SCHOOL COMM SCHOOL DISTRICT':
return 'COLO-NESCO COMM SCHOOL DISTRICT';
case 'EDDYVILLE-BLAKESBURG- FREMONT CSD':
return 'EDDYVILLE-BLAKESBURG-FREMONT CSD';
case 'ELK HORN-KIMBALLTON COMM SCHOOL DISTRICT':
case 'EXIRA-ELK HORN-KIMBALLTON COMM SCHOOL DISTRICT':
return 'EXIRA-ELK HORN-KIMBALLTON COMM SCH DIST';
case 'GARNER-HAYFIELD COMM SCHOOL DISTRICT':
case 'VENTURA COMM SCHOOL DISTRICT':
return 'GARNER-HAYFIELD-VENTURA COMM SCHOOL DISTRICT';
case 'SOUTH TAMA COUNTY COMM SCHOOL DISTRICT':
return 'SOUTH TAMA COUNTY';
default:
return district;
}
d3.json('./data/common/counties.simple2.topo.json')
.then(init);

function load(year) {
if (!year) {
year = 2018;
}

return {
district: normalizeDistrict(school['School District Name']),
school: school['School Name'],
population: +school.Students,
gradeBands: gradeBands,
csResponse: school['Teaches CS?'] || 'Unknown',
};
}).then(function (schools) {
schoolData = schools;
if (districtShapes) render(schoolData, districtShapes);
});
return Promise.all([
d3.json(`./data/${year}/districts.simple2.topo.json`),
d3.csv(`./data/${year}/gradeLevelData.csv`, function (school) {
var gradeBands = [];

if (school['Stage El'] === '1')
gradeBands.push('Elementary');
if (school['Stage Mi'] === '1')
gradeBands.push('Middle');
if (school['Stage Hi'] === '1')
gradeBands.push('High');

if (!gradeBands.length || !+school.Students)
return;

function normalizeDistrict(district){
switch (district) {
case 'A-H-S-T COMM SCHOOL DISTRICT':
case 'WALNUT COMM SCHOOL DISTRICT':
return 'AHSTW COMM SCHOOL DISTRICT';
case 'COLO-NESCO SCHOOL COMM SCHOOL DISTRICT':
return 'COLO-NESCO COMM SCHOOL DISTRICT';
case 'EDDYVILLE-BLAKESBURG- FREMONT CSD':
return 'EDDYVILLE-BLAKESBURG-FREMONT CSD';
case 'ELK HORN-KIMBALLTON COMM SCHOOL DISTRICT':
case 'EXIRA-ELK HORN-KIMBALLTON COMM SCHOOL DISTRICT':
return 'EXIRA-ELK HORN-KIMBALLTON COMM SCH DIST';
case 'GARNER-HAYFIELD COMM SCHOOL DISTRICT':
case 'VENTURA COMM SCHOOL DISTRICT':
return 'GARNER-HAYFIELD-VENTURA COMM SCHOOL DISTRICT';
case 'SOUTH TAMA COUNTY COMM SCHOOL DISTRICT':
return 'SOUTH TAMA COUNTY';
default:
return district;
}
}

return {
year: year,
district: normalizeDistrict(school['School District Name']),
school: school['School Name'],
population: +school.Students,
gradeBands: gradeBands,
csResponse: school['Teaches CS?'] || 'Unknown',
};
}),
]).then(([districts, schools]) => {
render(year, schools, districts);
}).catch(err => {
console.warn(err);
alert(`Error loading data for ${year}`);
});
}

var good = '#00aeef'; // NewBoCo Blue
var bad = d3.hsl(good);
Expand All @@ -79,9 +87,28 @@ var districtShapes;
return res;
}

function render(schools, districts) {
var ndx = crossfilter(schools);
var ndx = crossfilter();
var loadedYears = [];

function render(year, schools, districts) {
var geojson = topojson.feature(districts, Object.values(districts.objects)[0]);
charts.map
.overlayGeoJson(geojson.features, 'Districts', function (d) {
return d.properties.COUNTY || d.properties.DistrictNa.replace(/([ -]) +/g, '$1').toUpperCase();
});

if (!loadedYears.includes(year)){
ndx.add(schools);
loadedYears.push(year);
}

dims.years.filter(year);
dc.renderAll();
}

function init(counties) {
dims = {
years: ndx.dimension(dc.pluck('year')),
districtMap: ndx.dimension(dc.pluck('district')),
district: ndx.dimension(dc.pluck('district')),
school: ndx.dimension(dc.pluck('school')),
Expand Down Expand Up @@ -159,7 +186,7 @@ var districtShapes;
.externalRadiusPadding(10)
;

var geojson = topojson.feature(districts, districts.objects.IowaSchoolDistrictsFY18);
var geojson = topojson.feature(counties, counties.objects.county);
var projection = d3.geoAlbersUsa()
.fitSize([990,500], geojson);

Expand All @@ -168,10 +195,10 @@ var districtShapes;
.dimension(dims.districtMap)
.group(groups.districtMap)
.colorCalculator(function (d) {
return d ? districtColor(d.count, d.responses, d.cs) : '#ccc';
return d ? districtColor(d.count, d.responses, d.cs) : '#fff';
})
.overlayGeoJson(geojson.features, 'SchoolName', function (d) {
return d.properties.SchoolName.replace(/([ -]) +/g, '$1').toUpperCase();
.overlayGeoJson(geojson.features, 'Counties', function (d) {
return d.properties.COUNTY;
})
.projection(projection)
.valueAccessor(function(kv) {
Expand Down Expand Up @@ -233,4 +260,15 @@ var districtShapes;

dc.renderAll();
}
})(d3, crossfilter, dc, topojson);

page('/', () => load());

page('/:year', function(ctx) {
const { year } = ctx.params;
load(parseInt(year));
});

page({
hashbang: true
});
})(page, d3, crossfilter, dc, topojson);