These are chat archives for FreeCodeCamp/DataScience

27th
Nov 2017
Matthew Barlowe
@mcbarlowe
Nov 27 2017 18:53
anybody know about drawing maps with d3?
evaristoc
@evaristoc
Nov 27 2017 19:37
I think @becausealice2 might help. There is also a challenge in FCC that goes through making a map. I would suggest to check what other people have done.
@mcbarlowe
Matthew Barlowe
@mcbarlowe
Nov 27 2017 19:40
oh i've looked at plenty of examples but d3 doesn't make any sense to me
Alice Jiang
@becausealice2
Nov 27 2017 19:41
Sounds about right
What do you need help with @mcbarlowe
Matthew Barlowe
@mcbarlowe
Nov 27 2017 19:49
I'm trying to build something like this https://bl.ocks.org/mbostock/4060606 but just a state level not county and its mainly the last function where he calls the function that draws the map. I just wish he commented his code since he has tons of examples
so does javascript run in order like python or R inside the script tags?
Because it looks like he defines that function but never calls it so it just feels weird to me
@becausealice2
Alice Jiang
@becausealice2
Nov 27 2017 19:55
No, JavaScript is Asynchronous and also goes through a process called hoisting so it's possible that things are a bit out of order, but still functioning
If you look at his code, he has a line with d3.queue() with some .defer() and an .await() method chained on. That's where he calls the methods.
Then at the data join inside the ready function, he has us.objects.counties I happen to know that his topojson file for the US has stated level as well, just change it from us.objects.counties to us.objects.states
Alice Jiang
@becausealice2
Nov 27 2017 20:01
And the very last four lines of code... Where he appends paths with the class "states" you can delete all four of those lines as well as the CSS styling for them up at the top. @mcbarlowe
Matthew Barlowe
@mcbarlowe
Nov 27 2017 20:01
how come ?
Alice Jiang
@becausealice2
Nov 27 2017 20:02
How come to which?
Matthew Barlowe
@mcbarlowe
Nov 27 2017 20:02
I can delete those last lines
Alice Jiang
@becausealice2
Nov 27 2017 20:03
Because they render the shapes of the states, and you won't need that since you're rendering them for the choropleth
He does it for styling reasons, it won't serve you any purpose.
Matthew Barlowe
@mcbarlowe
Nov 27 2017 20:13
okay thanks that makes it make a little bit more sense let me get home and fool around with it and see what i can do
thanks @becausealice2
CamperBot
@camperbot
Nov 27 2017 20:16
mcbarlowe sends brownie points to @becausealice2 :sparkles: :thumbsup: :sparkles:
api offline
Alice Jiang
@becausealice2
Nov 27 2017 20:24
Don't forget, all the methods after the data join (.data(...)) are referencing his data. Make sure to adjust column names
Matthew Barlowe
@mcbarlowe
Nov 27 2017 21:35
Yeah I got that it’s just the intricacies of the syntax that just throws me for a loop
One other question how do you what features are in your geojson data?
Alice Jiang
@becausealice2
Nov 27 2017 22:37
You can load the data into a new tab and look through it, or log it to the console
Keep in mind that when Mike Bostock makes map blocks he uses topojson files, not geojson. They're very different in how you interact with them, and will look different before and after converting to geojson (with bostock's topojson API)
Matthew Barlowe
@mcbarlowe
Nov 27 2017 23:11
Yeah sorry I meant topojson I’m just trying to stick with one to make this easier