Created by Ryan Whitley / @apollolm
Throughout this exercise I'd like to explain some of the thought process behind building a site like this.
Knowing what to do regardless of the technology/language is key.
You can always look up a language's syntax.
"The Boss" wants to see which Seattle police beats have the highest crime rates in the last 24 hours.
She'll share it with her executive team.
She wants a dashboard.
First, need to see if the data exists to support this request.
Try data.seattle.gov -
http://data.seattle.gov/resource/3k2p-39jp.json
Let's go looking.
Let's find free-to-use .js libraries for
Let's use Leaflet (leafletjs.com)
Let's use Highcharts
We could use HTML Tables
But a library would allow for nicer viz
Bootstrap
A User Interface (UI) Library
Helps you make better looking sites
Time for a whiteboard!
This is a great time to interact with client
Use their input and ideas for design, mix with yours
If you work with a designer, this is where they create mockups/wireframes
At some point, you need to just start building
Helps to have a mockup to build against
Clone the repo in Git (if you know how/prefer)
or
Download a .zip file of it and open it on your machine.
https://github.com/tech-diversified/resources
Folder is called dashboard-workshop
Such as Sublime, Brackets, Visual Studio, Eclipse, Webstorm, etc.
You can reference the various completed stages of this project here.
(Click on Dashboard Workshop)
Type or copy the bare bones step1.html into your index.html.
It contains basic HTML framework, plus jQuery and Boostrap references.
(You may often start a project by copying pieces of older projects you've worked on)
Let's create a rough layout
Just get the broad strokes out on the page.
Think in terms of squares or rectangles (everything is a box!)
Let's do it.
Pull in leaflet library.
Let's go to Leaflet's site to see how to do it.
I Googled and then downloaded the police beats map file.
Go to my gist and copy/download Seattle-Police-Beats.geojson. Put it in your data folder.
Time: 10 mins.
Using step3.html/dashboard3.css, modify the header to have a dark background. Also, experiment with padding so the title isn't so crammed in there.
CSS Hints:
#header{
background-color: black;
color: white;
padding: 10px;
}
(By default, div elements are 100% the width of their parent box)
Find the data URL for the API. (data.seattle.gov)
Let's use jQuery to $.getJSON and pull back the results.
Show them in a div for now, just to make sure we're connecting
Yuck. Ugly. Let's clean up the UI.
The list is supposed to be on the right.
Let's add CSS to do that.
Also, let's summarize the crimes by beat and add a real table.
We already have the counts by beat
Loop thru the map layer dataset and add in the counts
Next, create a style function that decides what color to use based on the crime count
Lastly, tell the map layer to update its style
Time: 10 mins.
In step6.html, alter the getColorByNumberOfCrimes function to add a new 'orange' color.
Try Changing the colors and/or ranges (0 - 15, 15 - 30, > 30)
Check out the Highcharts Examples.
Turns out, they have an example of building a chart based on an HTML table...
Looks like our main components are in place, but spacing is off.
Let's use CSS to move stuff around
Drop down for crime type.
Click on map boundary to highlight chart and table row.
Click district to filter all data by.
Highlight highest crime areas with a border, or a glow.
...to some of the pages that helped me make the demo.
http://jsfiddle.net/gh/get/jquery/1.9.1/highslide-software/highcharts.com/tree/master/samples/highcharts/demo/column-parsed/ http://www.tutorialrepublic.com/twitter-bootstrap-tutorial/bootstrap-tables.php http://leafletjs.com/reference.html#geojson-style http://www.seattle.gov/police/maps/precinct_map.htm http://catalog.data.gov/dataset/seattle-police-department-beats/resource/9e6eaf04-7b6a-4959-9417-f7292848c444We just covered a lot.
To keep learning more about any of these libaries, read the docs and try examples!
This presentation can be found at http://tech-diversified.github.io/Workshops/CreateADashboard